#include #include #include #include #include #include "coords.h" #include "tr.h" #include "db.h" #include "stock.h" #define ARGC 8 #define BUFSIZE 256 typedef struct CTable { double calib; char chan[16]; } CTable; // Filter function int rerange( Dbptr *tr, float *data , void *private ); int rerange( Dbptr *tr, float *data, void *private ) { int found; long i, nsamp, nrecords; double time, endtime, samprate, calib; char sta[7], chan[9], chanb[9]; Dbptr *db = private; dbgetv( *tr, 0, "sta", sta, "chan", chan, "time", &time, "endtime", &endtime, "samprate", &samprate, "nsamp", &nsamp, 0 ); //fprintf( stderr, "\n%-5s %-3s %10.3f sps %5ld %f\n", sta, chan, samprate, nsamp, time ); if ( !dbquery( *db, dbRECORD_COUNT, &nrecords ) ) { register_error( 1, "Can't get record_count\n" ); } // Find the original calib: found = -1; for ( (*db).record=0; (*db).record 0 ) { complain( 0, "WARNING: some channels not rotated.\n" ) ; } // Only save the zne channels to the new db tr = dbsubset( tr, "chan =~ /^..[ZNE].*/", 0 ); // Recalibrate the range so that the trace values are // effectively returned to counts. This reduces the peak // Values so they are in range of STEIM2 trapply( tr, rerange, (void*)&db ); //trdisp( tr, "Test" ); for( int i = 0; i < 3; i++) { //printf( "newchan[%i]:%s\n", i, newchan[i] ); strncpy( fchan, newchan[i], 3 ); fchan[3] = '\0'; strncpy( loc, newchan[i]+4, 2 ); loc[2] = '\0'; map_seed_chanloc( sta, fchan, loc, newchan[i] ); //printf("%s\t%s\t%s\t%s\n", sta, fchan, loc, newchan[i]); } // Specify a filename string char *fmt_str; fmt_str = calloc(BUFSIZE,sizeof(char)); strcat( fmt_str, "%Y/%j/%{sta}_%{chan}_" ); strcat( fmt_str, file_name ); strcat( fmt_str, ".msd" ); //printf( "fmt_str: |%s|\n", fmt_str ); result = trsave_wf ( tr, dbout, "sd", fmt_str, trOVERWRITE ) ; if ( result < 0 ) { die ( 1, "trsave_wf fails\n" ) ; } else if ( result > 0 ) { if ( result & TR_CLIPPED ) { complain ( 0, "TR_CLIPPED - waveforms clipped." ) ; } if ( result & TR_TRUNCATED ) { complain ( 0, "TR_TRUNCATED - waveforms truncated." ) ; } } dbclose(db); dbclose(dbout); dbclose(tr); //trfree(tr); //trfree(db); //trfree(dbout); //printf( "COMPLETE: %s\n", select ); return result; }