Thread: binary data file

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    4

    binary data file

    I have a binary data file that contains the following stucture and would like read it and then create an equivalent ascii file:

    ----begin of file------
    novar novar
    hdr1 hdr2 .... hdr(novar)
    data1 data2 ...data(novar)
    .
    .
    .
    ----end of file------

    The first line contains the number of variables
    The second line contains a variable name for each var
    The third line (to the eof) contains data for each var

    I would appreciate help in getting a C program to work that will create an ascii output file. I also attached a sample binary file to test with.

    Thanks.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    I find confusing the mixing of binary with lines. Is it like this?
    Code:
    [int][int][text][text][...][text][???][???][...][???]
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    4

    update

    Sorry for the confusion. What I listed was the ascii output file format that I am trying to produce based on the output of an old fortran program. I attached the binary file 'bindat.txt' to test with.

    Thanks.

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by tucker81
    I attached the binary file 'bindat.txt' to test with.
    No file is attached. And thanks for the clarification. Sometimes I'm a bit thick.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Jun 2006
    Posts
    4

    file attach retry

    Unfortuantely, my file is too large. The limit for this filetype is 195.3 KB and mine 1.4 MB.

    If you wish, send me an e-mail to '[email protected]' and I'll reply with the attachment.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Surely you can extract (by some means) say the first 5 or 10 records.
    We don't need MB's of data just to understand the record format, only a few examples.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Jun 2006
    Posts
    4
    See attached file 'bindata.doc'.

  8. #8
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    It looks like garbage to me.

    84 K is huge. Nobody's going to go through it with a hex editor to figure out what it means, I can tell you. Why don't you just post a VERY SMALL example file right here?


    Example:

    "I want to translate this
    Code:
    2$ foo bar$ bar baz$
    Into this
    Code:
    1 foo bar
    2 bar baz
    "
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    I meant something like this - clear, unamiguous text
    Code:
    000000 08 00 00 00 5e 00 00 00 5e 00 00 00 08 00 00 00  >....^...^.......<
    000010 f0 02 00 00 74 20 20 20 20 20 20 20 74 65 6d 70  >....t       temp<
    000020 5f 6d 6f 74 74 5f 66 6c 74 20 20 20 61 6c 74 20  >_mott_flt   alt <
    000030 20 20 20 20 79 61 77 20 20 20 20 20 70 69 74 63  >    yaw     pitc<
    000040 68 20 20 20 72 6f 6c 6c 20 20 20 20 61 78 5f 62  >h   roll    ax_b<
    000050 63 73 20 20 61 79 5f 62 63 73 20 20 61 7a 5f 62  >cs  ay_bcs  az_b<
    000060 63 73 20 20 70 20 20 20 20 20 20 20 71 20 20 20  >cs  p       q   <
    000070 20 20 20 20 72 20 20 20 20 20 20 20 78 5f 6c 74  >    r       x_lt<
    000080 66 20 20 20 79 5f 6c 74 66 20 20 20 7a 5f 6c 74  >f   y_ltf   z_lt<
    000090 66 20 20 20 78 76 5f 6c 74 66 20 20 79 76 5f 6c  >f   xv_ltf  yv_l<
    0000a0 74 66 20 20 7a 76 5f 6c 74 66 20 20 78 5f 65 63  >tf  zv_ltf  x_ec<
    0000b0 65 66 20 20 79 5f 65 63 65 66 20 20 7a 5f 65 63  >ef  y_ecef  z_ec<
    0000c0 65 66 20 20 78 76 5f 65 63 65 66 20 79 76 5f 65  >ef  xv_ecef yv_e<
    0000d0 63 65 66 20 7a 76 5f 65 63 65 66 20 78 61 5f 65  >cef zv_ecef xa_e<
    0000e0 63 65 66 20 79 61 5f 65 63 65 66 20 7a 61 5f 65  >cef ya_ecef za_e<
    0000f0 63 65 66 20 78 5f 65 63 65 66 32 20 79 5f 65 63  >cef x_ecef2 y_ec<
    000100 65 66 32 20 7a 5f 65 63 65 66 32 20 74 5f 67 70  >ef2 z_ecef2 t_gp<
    000110 73 20 20 20 78 67 65 5f 6c 74 66 20 79 67 65 5f  >s   xge_ltf yge_<
    000120 6c 74 66 20 7a 67 65 5f 6c 74 66 20 78 6e 65 5f  >ltf zge_ltf xne_<
    000130 6c 74 66 20 79 6e 65 5f 6c 74 66 20 7a 6e 65 5f  >ltf yne_ltf zne_<
    000140 6c 74 66 20 78 65 5f 6c 74 66 20 20 79 65 5f 6c  >ltf xe_ltf  ye_l<
    000150 74 66 20 20 7a 65 5f 6c 74 66 20 20 75 61 5f 73  >tf  ze_ltf  ua_s<
    000160 66 20 20 20 76 61 5f 73 66 20 20 20 77 61 5f 73  >f   va_sf   wa_s<
    000170 66 20 20 20 78 61 5f 62 69 61 73 20 79 61 5f 62  >f   xa_bias ya_b<
    000180 69 61 73 20 7a 61 5f 62 69 61 73 20 78 67 5f 62  >ias za_bias xg_b<
    000190 69 61 73 20 79 67 5f 62 69 61 73 20 7a 67 5f 62  >ias yg_bias zg_b<
    0001a0 69 61 73 20 74 67 70 73 76 61 6c 20 75 70 66 6c  >ias tgpsval upfl<
    0001b0 61 67 20 20 6e 75 6d 73 61 74 20 20 64 74 62 70  >ag  numsat  dtbp<
    0001c0 5f 65 73 74 74 67 6f 5f 65 73 74 20 78 5f 65 72  >_esttgo_est x_er<
    0001d0 72 20 20 20 78 5f 70 72 65 64 20 20 68 77 5f 70  >r   x_pred  hw_p<
    0001e0 6f 73 5f 31 68 77 5f 70 6f 73 5f 32 68 77 5f 70  >os_1hw_pos_2hw_p<
    0001f0 6f 73 5f 33 68 77 5f 70 6f 73 5f 34 66 5f 63 6d  >os_3hw_pos_4f_cm<
    000200 64 5f 31 20 66 5f 63 6d 64 5f 32 20 66 5f 63 6d  >d_1 f_cmd_2 f_cm<
    000210 64 5f 33 20 66 5f 63 6d 64 5f 34 20 66 5f 70 6f  >d_3 f_cmd_4 f_po<
    000220 73 5f 31 20 66 5f 70 6f 73 5f 32 20 66 5f 70 6f  >s_1 f_pos_2 f_po<
    000230 73 5f 33 20 66 5f 70 6f 73 5f 34 20 64 79 6e 5f  >s_3 f_pos_4 dyn_<
    000240 70 72 65 73 6d 61 63 68 20 20 20 20 61 63 69 20  >presmach    aci <
    000250 20 20 20 20 61 63 6f 20 20 20 20 20 6b 66 6d 65  >    aco     kfme<
    000260 61 73 31 20 6b 66 6d 65 61 73 32 20 6b 66 6d 65  >as1 kfmeas2 kfme<
    000270 61 73 33 20 6b 66 6d 65 61 73 34 20 6b 66 6d 65  >as3 kfmeas4 kfme<
    000280 61 73 35 20 6b 66 6d 65 61 73 36 20 6b 66 6d 65  >as5 kfmeas6 kfme<
    000290 61 73 37 20 6b 66 6d 65 61 73 38 20 6b 66 6d 65  >as7 kfmeas8 kfme<
    0002a0 61 73 39 20 6b 66 6d 65 61 73 31 30 6b 66 6d 65  >as9 kfmeas10kfme<
    0002b0 61 73 31 31 6b 66 6d 65 61 73 31 32 78 61 5f 62  >as11kfmeas12xa_b<
    0002c0 5f 74 72 75 79 61 5f 62 5f 74 72 75 7a 61 5f 62  >_truya_b_truza_b<
    0002d0 5f 74 72 75 75 61 5f 73 66 74 72 75 76 61 5f 73  >_truua_sftruva_s<
    0002e0 66 74 72 75 77 61 5f 73 66 74 72 75 78 67 5f 62  >ftruwa_sftruxg_b<
    0002f0 5f 74 72 75 79 67 5f 62 5f 74 72 75 7a 67 5f 62  >_truyg_b_truzg_b<
    000300 5f 74 72 75 f0 02 00 00 78 01 00 00 00 00 00 00  >_tru....x.......<
    000310 14 f1 81 42 00 00 00 00 ad 7d 96 3f 00 00 00 00  >...B.....}.?....<
    000320 00 00 00 00 00 00 00 00 71 06 b3 3d d2 8c 40 bd  >........q..=..@.<
    000330 d5 5e 7e bf c1 6d df 3a d3 5b 48 3b b6 89 15 bb  >.^~..m.:.[H;....<
    000340 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    000350 00 00 00 00 00 00 00 00 5f ed b9 c9 3e af 9c ca  >........_...>...<
    000360 9c db 52 4a 00 00 00 00 00 00 00 00 00 00 00 00  >..RJ............<
    000370 00 00 00 00 00 00 00 00 00 00 00 00 5f ed b9 c9  >............_...<
    000380 3e af 9c ca 9c db 52 4a 00 cb 59 48 00 00 00 00  >>.....RJ..YH....<
    000390 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    0003a0 00 00 00 00 e9 af 10 47 d3 42 94 40 93 62 1c 43  >[email protected]<
    0003b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    0003c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    0003d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    0003e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    0003f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    000400 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    000410 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    000420 3e 97 0e 41 49 cd 44 3c 00 00 00 00 00 00 00 00  >>..AI.D<........<
    000430 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    000440 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    000450 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    000460 f8 4c a0 44 0f d1 8b c4 50 54 52 43 7a 94 9b 41  >.L.D....PTRCz..A<
    000470 01 19 8d 43 63 05 87 c2 48 19 05 bf ee 47 00 bf  >...Cc...H....G..<
    000480 7e df 8e bd 78 01 00 00 78 01 00 00 cd cc cc 3d  >~...x...x......=<
    000490 14 f1 81 42 00 00 00 00 ad 7d 96 3f 00 00 00 00  >...B.....}.?....<
    0004a0 00 00 00 80 00 00 00 00 71 06 b3 3d d2 8c 40 bd  >........q..=..@.<
    0004b0 d5 5e 7e bf c1 6d df 3a d3 5b 48 3b b6 89 15 bb  >.^~..m.:.[H;....<
    0004c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    0004d0 00 00 00 00 00 00 00 00 5f ed b9 c9 3e af 9c ca  >........_...>...<
    0004e0 9c db 52 4a 8b 26 7b a4 3e 87 1f a5 13 12 e2 24  >..RJ.&{.>......$<
    0004f0 d7 f8 1c a6 e9 68 c7 a6 57 4b 8d 26 5f ed b9 c9  >.....h..WK.&_...<
    000500 3e af 9c ca 9c db 52 4a 06 cb 59 48 00 00 00 00  >>.....RJ..YH....<
    000510 00 00 00 00 00 00 00 00 a1 ad 05 ae fe 6e 21 2f  >.............n!/<
    000520 1d 7d c2 4a e9 af 10 47 d3 42 94 40 93 62 1c 43  >.}[email protected]<
    000530 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    000540 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    000550 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    000560 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    000570 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    000580 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    000590 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    0005a0 3e 97 0e 41 49 cd 44 3c 00 00 00 00 00 00 00 00  >>..AI.D<........<
    0005b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    0005c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    0005d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    0005e0 f8 4c a0 44 0f d1 8b c4 50 54 52 43 7a 94 9b 41  >.L.D....PTRCz..A<
    0005f0 01 19 8d 43 63 05 87 c2 48 19 05 bf ee 47 00 bf  >...Cc...H....G..<
    000600 7e df 8e bd 78 01 00 00 78 01 00 00 cd cc 4c 3e  >~...x...x.....L><
    000610 14 f1 81 42 00 00 00 00 ad 7d 96 3f 00 00 00 00  >...B.....}.?....<
    000620 00 00 00 80 00 00 00 00 71 06 b3 3d d2 8c 40 bd  >........q..=..@.<
    000630 d5 5e 7e bf c1 6d df 3a d3 5b 48 3b b6 89 15 bb  >.^~..m.:.[H;....<
    000640 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    000650 00 00 00 00 00 00 00 00 5f ed b9 c9 3e af 9c ca  >........_...>...<
    000660 9c db 52 4a c1 27 fb a4 24 87 9f a5 1c 12 62 25  >..RJ.'..$.....b%<
    000670 5e fa 1c a6 af 68 c7 a6 57 4b 8d 26 5f ed b9 c9  >^....h..WK.&_...<
    000680 3e af 9c ca 9c db 52 4a 0d cb 59 48 00 00 00 00  >>.....RJ..YH....<
    000690 00 00 00 00 00 00 00 00 a1 ad 05 ae fe 6e 21 2f  >.............n!/<
    0006a0 1d 7d c2 4a e9 af 10 47 d3 42 94 40 93 62 1c 43  >.}[email protected]<
    0006b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    0006c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    0006d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    0006e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    0006f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    000700 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    000710 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    000720 3e 97 0e 41 49 cd 44 3c 00 00 00 00 00 00 00 00  >>..AI.D<........<
    000730 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    000740 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    000750 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  >................<
    Using this command (any good linux / unix / cygwin will have this)
    Code:
    od -Ax -t x1z -v bindata.doc > bindata.txt
    There seems to be about 1K of some kind of string data, then the rest of the file seems to be fixed length (0x180 byte) records with the "L.D....PTR" bit at the start.

    Now, which bit do you want?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  3. reading binary file with different data types
    By larne in forum C Programming
    Replies: 8
    Last Post: 07-29-2008, 10:12 AM
  4. How to write image data to binary PGM file format(P5)?
    By tommy_chai in forum C Programming
    Replies: 6
    Last Post: 11-03-2007, 10:52 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM