//RwL 1-14-2008 // // TraceStarts.c //This program is based on the January-February 2007 awk script with a similar name. // It has been modified for c and also to account for the 8000 Hz sampling in the // Trace2_8_all2.dat file // //The plan is to recognize bundles of energy, basically Bill Menger's approach // but to review the locations of the bundles making decisions as to // which are actually trace starts. The traces start times from the summer // 2006 Excel effort seemed to be a little more than 4 s apart, perhaps // averaging somewhere in the 4.1 to 4.2 range. Energy bundles not separated // by this much will be deemed to be on the same trace. // //After the starts of the bundles are highgraded,then will be used as pointers // to recover the actual traces in a separate program. // // When this is compiled, you need to compile with large file support. The // following command seems to work. // // gcc -o TraceStarts -D_FILE_OFFSET_BITS=64 TraceStarts.c // #include #include #include #include int main() { FILE *fileIn, *fileOut; int i, j=0; float value[250]; //value is the input signal amplitude double time[250]; //sample time on the tape. double lastStart=0.; //this is the time of the start of the last trace. // The next trace must be 3+ seconds later than this time. float sum; //this is the energy accumulater // Open the data file and the output start times file fileOut = fopen ("Starts.dat","w"); fileIn = fopen ("Track4_8_all2.dat","r"); // Read in 30*8 (240) samples. This is scaled up from the 1000 Hz that was // the basis of the awk script. for (i=1; i<=240; ++i) { fscanf (fileIn, "%lf %e", &time[i], &value[i]); } // Set up a do-while loop to step through the data file one time sample in // each pass through the loop. do { // Calculate the energy sum = 0.; for (i=1; i<=240; ++i) { sum = sum + fabsf(value[i]); } // Test the energy level. In the awk script for 1000 Hz sampling, the magic // threshold value was 0.85. This was for 30 samples. Increasing the number // of samples by 8x might suggest the threshold for the 8000 Hz sampling // should be 6.8. Other values might be usable. if (sum >= 8.3 && time[1]>lastStart) { fprintf (fileOut, "%lf\n", time[1]); lastStart = time[1] + 3.8; printf ("Trace %d Time %lf Energy %f Last %lf\n", ++j, time[1], sum, lastStart); } // Slide the time and value elements up 1 in the arrays and // read in a new value for the end of the array. for (i=1; i<=239; ++i) { time[i] = time[i+1]; value[i] = value[i+1]; } fscanf (fileIn, "%lf %e", &time[i], &value[i]); } while (!feof(fileIn)); fclose (fileIn); fclose (fileOut); return 0; } //end of main()