📄 times_data.c
字号:
/*===========================================================================*//* SEED reader | times_data | subprocedure *//*===========================================================================*//* Name: times_data Purpose: determine and print station, channel, start time, number of samples, sample rate, and station/channel/time continutity flag for each data record on a SEED volume Usage: void times_data (); times_data (); Input: none Output: none (prints information to stdout) Externals: input.data - pointer to beginning of data block Warnings: none Errors: none Called by: snoop Calls to: none Algorithm: determine whether this record is time/station/channel continuous with the previous record; print the record number, station name, channel name, start time of record, and the continuity flag Notes: A continuity flag of 0 (FALSE) means that the record is time/station/channel discontinuous with the previous record, while a flag of 1 (TRUE) indicates continuity. A time/station/channel discontinuity means that a new seismogram has started. For ease of use with "grep", the symbol "<==" is appended to lines indicating beginnings of seismograms. Problems: none known References: Halbert et al, 1988; see main routine Language: C, hopefully ANSI standard Author: Dennis O'Neill Revisions: 11/21/88 Dennis O'Neill Initial version 11/21/88 Dennis O'Neill Production release 1.0*/#include "rdseed.h"struct data_blk_1000 *scan_for_blk_1000();long int total_samples;/* long int start_record; *//* added April 5, 1994 - CL - problem realizing when the previous station/ * channel had changed, then new time span by definition */char prev_station[14] = "XXXXX"; /* Must be big enough */char prev_channel[14] = "XXXXX"; /* Same here! */char prev_location[14] = "XXXXX";double sample_rate;static struct time newtime, first_time; /* start time of new seisgm */void times_data (call_type)int call_type;{ int i; /* counter */ char *input_data_ptr; /* pointer to input data */ struct input_data_hdr *input_data_hdr; /* input data header */ struct type50 *p_station;/* ptr to current station */ struct type52 *p_channel;/* ptr to current channel */ struct data_blk_1000 *p; int continuous; /* continuity flag */ int duration; /* length of seismogram */ int tempint; /* temporary integer */ short int temp_2byte; /* temp for byte swapping */ unsigned short int temp_u2byte; /* temp for byte swapping */ struct input_time temptime; /* temp for byte swapping */ char this_station[5+1]; /* name of station */ char this_channel[3+1]; /* name of channel */ char this_network[2+1]; /* name of channel */ char this_location[3]; struct time this_time; /* start time of this seisgm */ /* figure out current ending time of previous seismogram */ if (last_sample_rate != 0) { duration = (int)((double)(last_nsamples * 10000) / (double)last_sample_rate); } else { duration = 0; last_time.year = 0; last_time.day = 0; last_time.hour = 0; last_time.minute = 0; last_time.second = 0; last_time.fracsec = 0; } newtime = timeadd (last_time, duration);/* timeprt(last_time); printf (" l_samples %d, l_rate %f, dur %d ", last_nsamples, (double) last_sample_rate, duration); timeprt(newtime); printf("\n"); */ if (!call_type) {/* input_data_ptr = input.data; */ input_data_ptr = lrecord_ptr+8;/* +=======================================+ *//*=================| read the fixed part of data header |=================*//* +=======================================+ */ /* recover the fixed data header from the input record */ input_data_hdr = (struct input_data_hdr *) input_data_ptr;/* +=======================================+ *//*=================| obtain particulars for this data blk |=================*//* +=======================================+ */ /* recover station name */ for (i = 0; i < 5; i++) this_station[i] = input_data_hdr->station[i]; this_station[5] = '\0'; for (i = 4; this_station[i] == ' '; i--) this_station[i] = '\0'; /* recover channel name */ for (i = 0; i < 3; i++) this_channel[i] = input_data_hdr->channel[i]; this_channel[3] = '\0'; for (i = 2; this_channel[i] == ' '; i--) this_channel[i] = '\0'; /* recover network name */ for (i = 0; i < 2; i++) this_network[i] = input_data_hdr->network[i]; this_network[2] = '\0'; for (i = 1; this_network[i] == ' '; i--) this_network[i] = '\0'; /* recover location */ for (i = 0; i < 2; i++) this_location[i] = input_data_hdr->location[i]; this_location[2] = '\0'; if (this_location[1] == ' ') this_location[1] = 0; if (this_location[0] == ' ') this_location[0] = 0; current_station = NULL; /* find the current station information in the tables */ for (p_station = type50_head; p_station != NULL; p_station = p_station->next) if (strcmp (this_station, p_station->station) == 0) { current_station = p_station; current_channel = NULL; /* find the current channel within the current station */ for (p_channel = p_station->type52_head; p_channel != NULL; p_channel = p_channel->next) if ((strcmp(this_channel, p_channel->channel) == 0) && (strcmp(this_location, p_channel->location) == 0)) { current_channel = p_channel; break; } } if (current_station == NULL) /* station was not found */ { fprintf (stderr, "WARNING (times_data): "); fprintf (stderr, "station %s not found in station table.\n", this_station); fprintf (stderr, "\tData Record Skipped.\n"); return; } if (current_channel == NULL) /* channel was not found */ { fprintf (stderr, "WARNING (times_data): "); fprintf (stderr, "channel %s, ", this_channel); fprintf (stderr, "station %s not found in station table.\n", this_station); fprintf (stderr, "\tData Record Skipped.\n"); return; } /* check if byteswapping will be needed to recover data */ byteswap = 0; /* check if byteswapping will be needed to recover data */ /* hopefully, rdseed will not be around by 2010 */ if (input_data_hdr->time.year < 1950 || input_data_hdr->time.year > 2010) { byteswap = 1; input_data_hdr->time.year = swap_2byte(input_data_hdr->time.year); /* check for sanity */ if (input_data_hdr->time.year < 1950 || input_data_hdr->time.year > 2010) { fprintf(stderr, "ERROR - times_data(): Unknown word order for station %s, channel %s\n", this_station, this_channel); fprintf(stderr, "Skipping data record.\n"); return; } input_data_hdr->time.day = swap_2byte(input_data_hdr->time.day); input_data_hdr->time.fracsec = swap_2byte(input_data_hdr->time.fracsec); input_data_hdr->nsamples = swap_2byte(input_data_hdr->nsamples); input_data_hdr->sample_rate = swap_2byte(input_data_hdr->sample_rate); input_data_hdr->sample_rate_multiplier = swap_2byte(input_data_hdr->sample_rate_multiplier); input_data_hdr->number_time_corrections = swap_4byte(input_data_hdr->number_time_corrections); input_data_hdr->bod = swap_2byte(input_data_hdr->bod); input_data_hdr->bofb = swap_2byte(input_data_hdr->bofb); if (input_data_hdr->bofb) blockette_swap(input_data_ptr + input_data_hdr->bofb - 8, input_data_ptr - 8); } p = 0; if (input_data_hdr->number_blockettes > 0) { p = scan_for_blk_1000(input_data_ptr + input_data_hdr->bofb - 8, input_data_ptr - 8); } /* get start time of this data block */ temptime.year = input_data_hdr->time.year; temptime.day = input_data_hdr->time.day; temptime.hour = input_data_hdr->time.hour; temptime.minute = input_data_hdr->time.minute; temptime.second = input_data_hdr->time.second; temptime.fracsec = input_data_hdr->time.fracsec; this_time.year = (int) temptime.year; this_time.day = (int) temptime.day; this_time.hour = (int) temptime.hour; this_time.minute = (int) temptime.minute; this_time.second = (int) temptime.second; this_time.fracsec = (int) temptime.fracsec;/* Do time correction */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -