reading binary file problem

This is a discussion on reading binary file problem within the C Programming forums, part of the General Programming Boards category; Hi I want to make parser to binary file (file.c3d) i shwo his content in visual c++ i see like ...

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    57

    reading binary file problem

    Hi
    I want to make parser to binary file (file.c3d)
    i shwo his content in visual c++ i see like this picture

    Name:  interface.jpg
Views: 794
Size:  98.3 KB

    i show the content too with software VB c3d file editor
    i see that
    Name:  vb.jpg
Views: 352
Size:  76.5 KB

    now to make my parser i must see what i see with visual or with the other software?(because i did not understand what i see in visual)

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Try this C3Dformat
    Kurt

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    57
    yes, i read some pages, but i can't understanding?
    i can't understand the lines (the numbers ) in this picture (i must understand the meaning of those numbers to mkae my parser)
    Name:  11599d1334658521-reading-binary-file-problem-interface.jpg
Views: 350
Size:  98.3 KB
    i found this code to read header
    Code:
    /**************************************************************/
    /***                        Read C3D Header 3.c                             ***/
    /**************************************************************/
    
    /**************************************************************/
    /***    Reads in header information from C3D file passed        ***/
    /***    in "infile" (files should be opened before calling.    ***/
    /***    DEPENDENCIES: Binconvert.c                                        ***/
    /**************************************************************/
    
    
    #include<stdio.h>
    #include<stdlib.h>
    #include"c3dutil.c"
    //#include "F:\BMacWilliams\Source\gait\binconvert.c"
    
    void Read_C3D_Header(
        unsigned short    *num_markers, 
        unsigned short    *num_channels,
        unsigned short    *first_field,
        unsigned short    *last_field,
        float                *scale_factor,
        unsigned short    *start_record_num,
        unsigned short    *frames_per_field,
        float                *video_rate,
        FILE                *infile)
    
    { /* Begin Read_C3D_Header */
    
    
    /* Function prototypes */
    float                    ConvertDecToFloat(char bytes[4]);
    
    unsigned short        key1,max_gap;
    char                    DEC_float[3];
    
    /* Read in Header */
    
    // Key1, byte = 1,2; word = 1
    fread(&key1, sizeof key1, 1, infile); 
    //printf("key1 = %d\n",key1);
     
    // Number of 3D points per field, byte = 3,4; word = 2
    fread(num_markers, sizeof *num_markers, 1, infile); 
    //printf("num_markers = %d\n",*num_markers);
    
    // Number of analog channels per field byte = 5,6; word = 3
    fread(num_channels, sizeof *num_channels, 1, infile); 
    //printf("num_channels = %d\n",*num_channels);
    
    // Field number of first field of video data, byte = 7,8; word = 4
    fread(first_field, sizeof *first_field, 1, infile); 
    //printf("first_field = %d\n",*first_field);
    
    // Field number of last field of video data, byte = 9,10; word = 5    
    fread(last_field, sizeof *last_field, 1, infile); 
    //printf("last_field = %d\n",*last_field);
    
    // Maximum interpolation gap in fields, byte = 11,12; word = 6
    fread(&max_gap, sizeof max_gap, 1, infile); 
    //printf("max_gap = %d\n",max_gap);
    
    // Scaling Factor, bytes = 13,14,15,16; word = 7,8
    fread(&DEC_float[0], sizeof(char), 1, infile); // 1st byte
    fread(&DEC_float[1], sizeof(char), 1, infile); // 2nd byte
    fread(&DEC_float[2], sizeof(char), 1, infile); // 3rd byte
    fread(&DEC_float[3], sizeof(char), 1, infile); // 4th byte
    //DEC_float[2] = 0;                // 3rd byte
    //DEC_float[3] = 0;                // 4th byte
    
    //*scale_factor = ConvertDecToFloat(DEC_float); 
    *scale_factor = ConvertDecToFloat(DEC_float);
    //printf("scale_factor = %f\n",*scale_factor);
    
    // Starting record number, byte = 17,18; word = 9
    fread(start_record_num, sizeof *start_record_num, 1, infile);
    //printf("start_record_num = %d\n",*start_record_num);
    
    // Number of analog frames per video field, byte = 19,20; word = 10
    fread(frames_per_field, sizeof *frames_per_field, 1, infile);
    //printf("frames_per_field = %d\n",*frames_per_field);
    
    // Analog channels sampled
    if (*frames_per_field != 0) 
        *num_channels /= *frames_per_field;
    //printf("num_channels reset to = %d\n",*num_channels);
    
    // Video rate in Hz, bytes = 21,22; word = 11
    fread(&DEC_float[0], sizeof DEC_float[0], 1, infile); // 1st byte
    fread(&DEC_float[1], sizeof DEC_float[0], 1, infile); // 2nd byte
    DEC_float[2] = 0;
    DEC_float[3] = 0;
    
    *video_rate = ConvertDecToFloat(DEC_float); 
    //printf("video_rate = %6.2f\n",*video_rate);
    
    // 370 does not use the rest of the header
    
    // Words 12 - 148 unused; position file pointer at byte 149*2=298
    
    //for (i=12;i<=148;i++) 
    //    fread(&cdum, sizeof cdum, 1, infile);
    //fseek(infile,298,0);
    
    // Key2, byte = 297,298; word = 149
    //fread(&key2, sizeof key2, 1, infile);
    //printf("key2 = %d\n",key2);
    
    // Number of defined time events, byte = 299,300; word = 150
    //fread(num_time_events, sizeof *num_time_events, 1, infile);
    //printf("num_time_events = %d\n",*num_time_events);
    
    // Skip byte 301,302; word = 151
    //fread(&cdum, sizeof cdum, 1, infile);
    //fseek(infile,302,0);
    
    // Event times, bytes 303-374;words = 152-187: 9 events (0-8) of 4 bytes
    //for (i=0;i<9;i++) 
    //{
    //fread(&DEC_float[0], sizeof DEC_float[0], 1, infile); // 1st byte
    //fread(&DEC_float[1], sizeof DEC_float[0], 1, infile); // 2nd byte
    //fread(&DEC_float[2], sizeof DEC_float[0], 1, infile); // 3rd byte
    //fread(&DEC_float[3], sizeof DEC_float[0], 1, infile); // 4th byte
    //    event_time[i] = ConvertDecToFloat(DEC_float); 
    //    printf("event_time[%d] = %f\n",i,event_time[i]);
    //}
    
    // Event switches, bytes = 375-394; words 188-197
    //for (i=0;i<9;i++) 
    //{
    //    fread(&event_switch[i], sizeof event_switch[i], 1, infile);
    //    printf("event_switch[%d] = %d\n",i,event_switch[i]);
    //}
    
    // Event Labels, bytes = 395-466; words 198-233: 9 labels (0-8) of 4 unsigned chars
    //for (i=0;i<9;i++) 
    //{
    //    fread(&event_label[i], sizeof event_label[i], 1, infile);
    //    printf("event_label[%d] = %s\n",i,event_label[i]);
    //}
    
    // Bytes 234 - 255 unused
    //for (i=234;i<=255;i++)     fread(&cdum, sizeof cdum, 1, infile);
    
    
    } /* End Read_C3D_Header */
    but i can't understand it because i do not know where is the header when i open the file .c3d in visual (where it stoped), where is the markers, all is numbers

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,535
    > i can't understand the lines (the numbers ) in this picture
    The left hand side, beginning with 000000f0 is the offset into the file - written in hexadecimal (note that there are 16 bytes per line).
    Hex editors display EVERYTHING in hex.

    So you could write fseek(fp,0x200,SEEK_SET); and be really close to reading "POINT"
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Apr 2012
    Posts
    57
    sorry , can you more explane ?
    because i still do not understand (sorry again i never see binary file)
    and what represent "0x200"?
    "POINT"
    how i nknow that is point ? or where is here x,y,z?

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,535
    Look down the left column - do you see 00000200 ?
    Look along that row - do you see "POINT" starting at the 6th byte?

    So if you have
    char buff[5];
    fseek(fp,0x206,SEEK_SET);
    fread(buff,1,5,fp);


    Then buff will contain the (not \0 terminated) string "POINT"

    > how i nknow that is point ? or where is here x,y,z?
    I've no idea.
    But I would begin with a google search for "file format xxx" where xxx is the extension of the file you're trying to read.

    But I thought you already knew it was a "C3D file" and were on top of this.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Apr 2012
    Posts
    57
    ok i understand now thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need Help! reading a binary file
    By d4rksid3 in forum C++ Programming
    Replies: 28
    Last Post: 10-17-2008, 03:37 PM
  2. Problem reading a delimited file into a binary tree
    By neolyn in forum C++ Programming
    Replies: 10
    Last Post: 12-09-2004, 06:51 PM
  3. Reading in a binary file
    By Bri Rock in forum C++ Programming
    Replies: 3
    Last Post: 07-08-2004, 03:54 PM
  4. reading binary file
    By Tozilla in forum C Programming
    Replies: 5
    Last Post: 10-25-2003, 07:17 AM
  5. Reading a binary file
    By Cyber Kitten in forum C Programming
    Replies: 2
    Last Post: 11-23-2001, 04:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21