wtr
Full Member level 5
Hello all,
I have a binary file that consists of two datatypes.
datatype 1 has the identifier AAAA AAAA 1234 8000 {UTC timestamp} [data]
datatype 2 has the identifier AAAA AAAA 4321 8000 {UTC timestamp} [data]
Consider the binary file to be concatenated together randomly such that
datatype 1 & datatype 1 & datatype 2 & datatype 1 & etc
I want to know how I can extract the data into two separate files datatype 1 & datatype 2.
I have the following C code that strips the UTC timestamps from a datatype block. The problem is this is all based on a text file. I would love to know how i can keep this all binary to speed up the whole process.
Thanks in advance.
I have a binary file that consists of two datatypes.
datatype 1 has the identifier AAAA AAAA 1234 8000 {UTC timestamp} [data]
datatype 2 has the identifier AAAA AAAA 4321 8000 {UTC timestamp} [data]
Consider the binary file to be concatenated together randomly such that
datatype 1 & datatype 1 & datatype 2 & datatype 1 & etc
I want to know how I can extract the data into two separate files datatype 1 & datatype 2.
I have the following C code that strips the UTC timestamps from a datatype block. The problem is this is all based on a text file. I would love to know how i can keep this all binary to speed up the whole process.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 #include <stdio.h> #include <stdlib.h> #include <string.h> // strip_vme_utc_data.c WDST 16/04/2015 // this program is used to remove UTCs from the vme log data // so the file may be used for simple file comparison. int main(int argc, char *argv[]){ FILE *fp1; // vme log file FILE *fp2; // sanitised vme log file char str1[16]; // vector from IP file char str2[16]; // vector to OP file char word_value[4]; // data value char utc_token[] = "8000"; // utc token char same; // unsigned long l; // vector counter // int j; // loop counter if(argc!=3){ printf("Usage: strip_vme_utc_data <vme input file> <vme output file>\n"); exit(1); } // open first file if((fp1 = fopen(argv[1],"rb"))==NULL){ printf("Cannot open first file.\n"); exit(1); } // open second file if((fp2 = fopen(argv[2],"wb"))==NULL){ printf("Cannot open second file.\n"); exit(1); } // write header // fprintf(fp2,"Reference Data \n"); // compare the files while(!feof(fp1)) { fscanf (fp1, "%s", &str1); //get time if(ferror(fp1)) { printf("Error reading first file. \n"); break; } fscanf (fp1, "%s", &str1); //get data strncpy(word_value, str1,sizeof(str1)); // strncpy(word_value, str1, sizeof(str1)); printf("Data is %s\n",word_value); if(strcmp(word_value,utc_token) == 0){ // it is a utc token fscanf (fp1, "%s", &str1); //get time fscanf (fp1, "%s", &str1); //get UTC data 1 fscanf (fp1, "%s", &str1); //get time fscanf (fp1, "%s", &str1); //get UTC data 2 fscanf (fp1, "%s", &str1); //get time fscanf (fp1, "%s", &str1); //get UTC data 3 fscanf (fp1, "%s", &str1); //get time fscanf (fp1, "%s", &str1); //get UTC data 4 fscanf (fp1, "%s", &str1); //get time fscanf (fp1, "%s", &str1); //get UTC data 5 fscanf (fp1, "%s", &str1); //get time fscanf (fp1, "%s", &str1); //get Lost vme count fscanf (fp1, "%s", &str1); //get time fscanf (fp1, "%s", &str1); //get Lost vme count2 fscanf (fp1, "%s", &str1); //get time fscanf (fp1, "%s", &str1); //get vme data // strncpy(word_value, str1,4); strncpy(word_value, str1, sizeof(str1)); } fprintf(fp2,"%s\n",word_value); } // end of while if(fclose(fp1)==EOF){ printf("Error closing first file.\n"); exit(1); } if(fclose(fp2)==EOF){ printf("Error closing second file.\n"); exit(1); } return(0); }
Thanks in advance.