//RwL 1-14-2008 // // TraceOutputs.c // for 8000 Hz input daa //This is the second of two programs derived from awk scripts of approximately 1 year // ago. // //The scheme is fairly straightforward. In the program TraceStarts.c, which evolved // from TraceStarts.txt, an awk script on the PC, a table of trace start times was // generated based on a threshold detection scheme. An exclusion window of about 3.8 // s attempted to allow recognizing of only real seismic traces and not noise // bursts. // //The plan is to read a record from the Starts.dat file that was generated with // the TraceStarts script. This record will have the tape time for the start of the // each trace. The Track2_*_all2.dat file will then be read until the pointer // position is found. From the pointer position in the seismic data file, 8000 // samples, 1 s, of data will be read and output. // // // When this is compiled, you need to compile with large file support. The // following command seems to work. // // gcc -o TraceOutputs -D_FILE_OFFSET_BITS=64 TraceOutputs.c // #include #include #include #include int main() { FILE *fileIn, *fileOut, *fileStarts; double startTime; // the trace start time read from Starts.dat double inTime; // the input time from the seismic file float inAmp; // the input amplitude from the seismic file int i, j=0; // counters // Open the input and output files fileStarts = fopen("Starts.dat","r"); //Trace starts file fileIn = fopen("Track4_8_all2.dat","r"); //Seismic data file fileOut = fopen("T4-8kHz.dat","w"); //Trace otput file //Using multiple files in awk is difficult. Consquently, the following code may // not match the original awk code very well. // Set up a do-while loop for reading in the trace start values do { //Read a start time fscanf (fileStarts, "%lf", &startTime); //Set up a loop to read until startTime is encoutered do { fscanf (fileIn, "%lf %f", &inTime, &inAmp); } while (inTime < startTime); //We are now at the trace start time in the input seismic file //Read and output the next second of data (8000 samples) for (i=1; i<=8000; ++i) { fscanf (fileIn, "%lf %e", &inTime, &inAmp); fprintf (fileOut, "%f\n", inAmp); } printf ("Trace: %d\n", ++j); } while (!feof(fileStarts)); fclose (fileIn); fclose (fileOut); fclose (fileStarts); return 0; } // end of main()