/* * SEEDSNIFF - print out name, length, and first part of each blockette. * - does not see blockettes within data records * - only prints out changes during data/timespan regions * * seedsniff lrecl precl maybe < input * seedsniff 4096 32768 < /dev/rmt0, for example. * written by Tim Ahern, IRIS 9-26-89 started from Mark Wiedersphan prgram bprint */ #include #define min(a,b) ((a)<(b)?(a):(b)) #define SPACE 32 char *malloc(); int lrecl; /* logical record number */ int p_flag; main( argc,argv ) int argc; char* argv[]; { int precl; /* physical record size */ int neof; /* number of eofs seen so far */ char* buf; /* point to io buffer */ int nb; /* bytes read */ char *lptr; /* logical record pointer */ if( argc == 2 ) { p_flag=1; lrecl = 4096; precl = 32768; } else if( argc < 3 ) { printf( "usage: %s logrecsize physrecsize print_flag\n", argv[0] ); printf( "where print_flag 1= print data summary records \n"); printf( " 2= print each data record \n"); printf( " 3= print both types of records \n"); exit(1); } /* * eventually, sanity checks of all args should go here */ else { sscanf( argv[1],"%d",&lrecl ); /* 4096 only at present */ sscanf( argv[2],"%d",&precl ); /* >= 4096, <= 65536 */ if(argc >3 )sscanf( argv[3],"%d",&p_flag ); } if( (buf=malloc( precl )) == NULL ) { perror( "malloc:" ); exit(1); } /* * read the volume until: * a) two eofs seen * b) a second volume is seen [ NOT IMPLEMENTED YET ] */ neof = 0; /* count of number of consecutive eofs seen */ while( neof < 2 ) /* until end of medium */ { nb = read( fileno(stdin), buf, precl ); if( nb == 0 ) { if( neof == 0 ) logrec( NULL ); neof++; } else if( nb < 0 ) { perror( "read:" ); exit(1); } else if( nb > 0 ) { neof = 0; for( lptr=buf; lptr < (buf + nb); lptr=lptr+lrecl ) { logrec( lptr ); } } } } /* * logrec.c */ static int n = 0; /* number of bytes left in blockette */ static int was_blk = 1; /* was b printed ? controls logrec print*/ static int l_lrecno; /* logical record number */ static char l_rectype; /* type of the record: VASTspaceD */ static char l_cont; /* continuation ? */ logrec( lptr ) char *lptr; /* logical record pointer */ { int lrecno; /* logical record number */ char clrecno[7]; /* character version of same */ char rectype; /* type of the record: VASTspaceD */ char cont; /* continuation ? */ char *top; /* top of logrec */ char *bptr; /* blockette pointer */ int btype, blen; /* blockette type and size */ int blen_left, blen_org, num_out, bint; char ctype[4], clen[5]; /* character versions of btype, blen */ char buf[1007]; /* text of blockette */ int icount; double f_sam_rate, prev_f_sam_rate, t_next_sam; int t_next_fs, t_next_sec, t_next_min, t_next_hour, t_next_day; int sum_num_sam, sum_num_bytes, sum_flags, st_year, st_day, st_hour, st_min, st_sec, st_fs; char *prev_ptr, prev_buf[48]; short int prev_sample_rate, prev_sample_rate_multiplier; long d1, d2, d3, d4; struct s_id /* DEVICE ID */ { /*--------------------------------*/ char station[5]; /* Station id */ char location[2]; /* Location id */ char channel[3]; /* Channel id */ char res[2]; /* reserved */ }; struct s_time /* RAW TIME FROM BLOCKETTE */ { /*--------------------------------*/ unsigned short int year; /* year (ie 1987) */ unsigned short int day; /* day of the year (Jan 1, is 1) */ char hour; /* hour of the day (0-23) */ char minute; /* minute of day (0-59) */ char seconds; /* seconds of day (0-59,60 for */ /* leap seconds) */ char unused; /* get on word boundry */ unsigned short int frac_sec; /* .0001 seconds (0-9999) */ }; /* * The following union is used to parse long integers that are misaligned. */ union mixed { long longvar; unsigned short int shortvar; struct { char a; char b; char c; char d; } bytes; } x; struct s_raw_data /* RAW UNFORMATTED INPUT DATA */ { /*--------------------------------*/ unsigned short int num_samples; /* Number of samples in record */ short int sample_rate; /* Sample rate factor */ short int sample_rate_multiplier; /* Sample rate multiplier factor */ long flags; /* all the flags together */ long int num_frac_sec_corr; /* Number of .0001 sec time correction */ unsigned short int begin_data; /* Byte number of beginning of */ /* correction (first byte of */ /* rec is 0) */ unsigned short int begin_blockette;/* Byte number of beginning of */ /* first blockette (0 if none) */ }; struct s_data /* FORMATTED INPUT DATA */ { /*--------------------------------*/ int num_samples; /* Number of samples in record */ int sample_rate; /* Sample rate factor */ int multiplier; /* Sample rate multiplier */ long flags; /* All the flags + num blockettes */ long int num_frac_sec_corr; /* Number of .0001 sec time */ /* correction */ unsigned short int begin_data; /* Byte number of beginning of */ /* correction (first byte of */ /* rec is 0) */ unsigned short int begin_blockette;/* Byte number of beginning of */ /* first blockette (0 if none) */ }; struct s_id *id, *prev_id; struct s_time *time; struct s_raw_data *sdata; struct s_data data ; clrecno[6] = '\0'; ctype[3] = '\0'; clen[4] = '\0'; if( lptr == NULL ) { printf( "\nlogrec %d type %c%c (last record)\n", l_lrecno, l_rectype, l_cont ); } else { /* * wont work for non-leading zero data (maybe) if( sscanf( lptr, "%6d%c%c", &lrecno, &rectype, &cont ) < 3 ) */ if( sscanf( lptr, "%6c%c%c", clrecno, &rectype, &cont ) < 3 ) { strcpy( clrecno, "0" ); rectype = SPACE; cont = SPACE; } lrecno = atoi( clrecno ); if( !was_blk && strchr( "VAST", rectype ) != NULL ) printf( "\nlogrec %d type %c%c\n", l_lrecno, l_rectype, l_cont ); /* if( was_blk || strchr( "VAST", rectype ) != NULL ) */ if( strchr( "VAST", rectype ) != NULL ) printf( "\nlogrec %d type %c%c\n", lrecno, rectype, cont ); was_blk = 0; l_lrecno = lrecno; /* last of each , to print last D before VT */ l_rectype = rectype; l_cont = cont; if( strchr( "VAST", rectype ) != NULL ) { prev_id = NULL; was_blk = 1; bptr = lptr+8; top = bptr + lrecl - 8; while( bptr < top ) { if( cont == '*' && n > 0 ) bptr += min( n, lrecl-8 ); while( bptr < top && *bptr == SPACE ) bptr++; if( bptr < top ) { /* * will not work with leading spaces (scripps seed) sscanf( bptr, "%3d%4d%32c", &btype, &blen, buf ); */ sscanf( bptr, "%3c%4c%1007c", ctype, clen, buf ); btype = atoi( ctype ); blen = atoi( clen ) -7; blen_left = blen_org = min(1007,blen); num_out = min(100,blen); /* header print */ printf( "\n type %.3d len %.4d : %.*s", btype, blen+7, num_out, buf ); blen_left -= num_out; while (blen_left > 0){ num_out = min(100,blen_left); bint =blen_org-blen_left; printf( "\n : %.*s", num_out, &buf[bint]); blen_left -= num_out; } bptr += (blen +7); n = bptr-top; } } } if( strchr( "D", rectype ) != NULL ) { was_blk = 1; bptr = lptr+8; top = bptr + lrecl - 8; while( bptr < top ) { if( cont == '*' && n > 0 ) bptr += min( n, lrecl-8 ); while( bptr < top && *bptr == SPACE ) bptr++; if( bptr < top ) { id = (struct s_id *) bptr; time = (struct s_time *) (bptr+12); /* point to time structure */ sdata = (struct s_raw_data *) (bptr+22); /* point to rest of fixed section*/ data.num_samples = (int)sdata->num_samples; data.sample_rate = (short int)sdata->sample_rate; data.multiplier = (short int)sdata->sample_rate_multiplier; /* * Since there are an odd number of short integers preceding these two * long integers, they become misaligned on the sun4 computers. */ x.bytes.a = *(bptr+28); x.bytes.b = *(bptr+29); x.bytes.c = *(bptr+30); x.bytes.d = *(bptr+31); data.flags = (long int) x.longvar; x.bytes.a = *(bptr+32); x.bytes.b = *(bptr+33); x.bytes.c = *(bptr+34); x.bytes.d = *(bptr+35); data.num_frac_sec_corr = (long int) x.longvar; data.begin_data = (unsigned short int)sdata->begin_data; data.begin_blockette = (unsigned short int)sdata->begin_blockette; if (data.sample_rate > 0 && data.multiplier > 0) f_sam_rate = data.sample_rate * data.multiplier; if (data.sample_rate > 0 && data.multiplier < 0) f_sam_rate = (-1) * data.sample_rate / data.multiplier; if (data.sample_rate < 0 && data.multiplier > 0) f_sam_rate = (-1) * data.multiplier/ (float)(data.sample_rate); if (data.sample_rate < 0 && data.multiplier < 0) f_sam_rate = 1./( (float)(data.sample_rate)/ ( (float)data.multiplier) ); /* ????? */ if( time->frac_sec == t_next_fs && (int)(time->seconds) == t_next_sec && (int)(time->minute) == t_next_min && (int)(time->hour) == t_next_hour && (int)(time->day) == t_next_day){ sum_num_sam += data. num_samples; sum_num_bytes += lrecl; sum_flags = sum_flags | data.flags; }else{ if( (prev_id!= NULL ) ){ if(p_flag ==1 || p_flag==3){ printf ("\n %.5s %.2s %.3s %4d %3d_%2d:%2d:%2d.%4d", prev_id->station, prev_id->location, prev_id->channel, st_year, st_day, st_hour, st_min, st_sec,st_fs); printf(" %3d_%2d:%2d:%2d.%4d ", t_next_day, t_next_hour,t_next_min,t_next_sec, t_next_fs); d1 = sum_flags & 0xff000000; d1 >>= 24; d2 = sum_flags & 0x00ff0000; d2 >>= 16; d3 = sum_flags & 0x0000ff00; d3 >>= 8; d4 = sum_flags & 0x000000ff; printf ("%8d %.6g %8d %2x %2x %2x %4d #%4d",sum_num_sam, prev_f_sam_rate, sum_num_bytes, d1,d2,d3,d4, sum_num_bytes/lrecl); } }else{ printf ("\n=====> DATA ENCOUNTERED "); if (p_flag ==2 || p_flag==3)printf ("\n STA LOC CH YEAR START TIME SAMPLES SRF SRMF A I Q #B #TC B#D B#BLK "); if (p_flag ==1 || p_flag==3)printf ("\n STA LOC CH YEAR START TIME END TIME #SAMPLES RATE BYTES A I Q #B # PIECES"); } st_year = time->year; st_day = time->day; st_hour = time->hour; st_min = time->minute; st_sec = time->seconds; st_fs = time->frac_sec; sum_num_sam = data.num_samples; sum_num_bytes = lrecl; sum_flags=data.flags; } prev_ptr = &prev_buf[0]; /* save this data header */ strncpy(prev_ptr,bptr,48); prev_id = (struct s_id *) prev_ptr; prev_sample_rate = data.sample_rate; prev_sample_rate_multiplier = data.multiplier; prev_f_sam_rate = f_sam_rate; t_next_sam = data.num_samples / f_sam_rate; /* calc. time of last sample */ t_next_sam += 0.00005; /* handle rounding */ t_next_fs = time->frac_sec + 10000 * t_next_sam ; /* should be the time of next */ t_next_sec = t_next_fs/10000 + (int)(time->seconds); /* block also if continuous */ t_next_fs = (t_next_fs ) % 10000; t_next_min = t_next_sec/60 + (int)(time->minute); t_next_sec = t_next_sec % 60; t_next_hour = t_next_min/60 + (int)(time->hour); t_next_min = t_next_min % 60; t_next_day = t_next_hour/24 + (int)(time->day); t_next_hour = t_next_hour % 24; /* This won't handle year breaks quite right */ /* The following is for SEED docmentation purposes and gives faithful SEED data header values */ if(p_flag ==2 || p_flag==3){ printf ("\n %.5s %.2s %.3s %4d %3d_%2d:%2d:%2d.%4d", id->station, id->location, id->channel, time->year, time->day, time->hour, time->minute, time->seconds,time->frac_sec); d1 = data.flags & 0xff000000; d1 >>= 24; d2 = data.flags & 0x00ff0000; d2 >>= 16; d3 = data.flags & 0x0000ff00; d3 >>= 8; d4 = data.flags & 0x000000ff; if(p_flag == 2 || p_flag==3)printf ("%8d %5d %5d %2x %2x %2x %3d %6d %6d %6d",data.num_samples, data.sample_rate, data.multiplier, d1, d2, d3, d4, data.num_frac_sec_corr, data.begin_data, data.begin_blockette); } bptr += 4096; n = bptr-top; } } } } }