Below is a data file generated by a FORTRAN program. The following is the hexadecimal dump of the FORTRAN binary data file:
0000000 0000 0048 4920 616d 2061 2067 656e 6975 0000020 7320 6772 6f75 6e64 686f 6721 2020 5275 0000040 6e21 2020 5275 6e21 2020 5275 6e21 2020 0000060 2020 2020 2020 2020 2020 2020 2020 2020 0000100 2020 2020 2020 2020 2020 2020 0000 0048 0000120 0000 000c 3f8c cccd 400c cccd 4053 3333 0000140 0000 000c 0000 0008 0000 0004 0000 0005 0000160 0000 0008
A similar data file from C (flat binary file) is attached to this solution. Below is the code that was used to generate the binary data file.
program wrt_bincharacter*72 namereal*4 xsource, zsource, dtinteger*4 ntrace, ntname='I am a genius groundhog! Run! Run! Run!'xsource=1.1zsource=2.2dt=3.3ntrace=4nt=5open(unit=11, file='wrt_bin.bin', form='unformatted', + status='new') WRITE(11) NAME WRITE(11) XSOURCE,ZSOURCE,DT WRITE(11) NTRACE,NTclose(11)end
Here is the C code that was used to generate the flat binary data file:
#include<stdio.h>#include<stdlib.h>void main(){ char name[72]; int ntrace, nt; double xsource, zsource, dt; FILE *fp; sprintf(name," I am a genius groundhog! Run! Run! Run!"); xsource=1.1; zsource=2.2; dt=3.3; ntrace=4; nt=5;fp=fopen("wrt_binc.bin", "wb"); fwrite(name, sizeof(char), 72, fp); fwrite(&xsource, sizeof(double), 1, fp); fwrite(&zsource, sizeof(double), 1, fp); fwrite(&dt, sizeof(double), 1, fp); fwrite(&ntrace, sizeof(int), 1, fp); fwrite(&nt, sizeof(int), 1, fp); fclose(fp);}
Best Answer