📄 process_data.c
字号:
{ struct type50 *p, *p2 = NULL; struct time start, end; /* response effective times */ char stn[10]; /* if we ever get more than 10 * for station and network sizes, * we need to upgrade */ char net[10]; strncpy(stn, s, 10); strncpy(net, n, 10); trim(stn); trim(net); if (end_time->year == 0) end_time->year = 9999; /* I will be retired by then */ for (p = type50_head; p != NULL;p = p->next) { if (strcmp(p->station, stn) != 0) continue; if (type10.version >= 2.3) { /* check to make sure there is network code, * as blank network code on disk, turns out as a NULL string */ if (p->network_code && (!ignore_net_codes)) if (strcmp( p->network_code, net) != 0) continue; } /* convert station time (YYYY,DDD,....) to struct */ timecvt(&start, p->start); timecvt(&end, p->end); if (p->end == 0) end.year = 9999; /* do time check */ if ((WITHIN((*beg_time), start, end)) && (WITHIN((*end_time), start, end))) p2 = p; } return p2; }/* ------------------------------------------------------------------------ */struct type52 *get_channel_rec(s, channel, l, rec_time) struct type50 *s; char *channel;char *l;struct time *rec_time; { struct time start, end; struct type52 *c, *p = NULL; char station[10], network[3], loc[3]; int finished = 0; int n = 3; /*## kludge alert, if multiplexed data, just look at * the 1st two chars of channel - return after finding * the 1st matching record - the output*.c routines will * loop through the next two, adding the last char */ n = strlen(channel); strcpy(loc, l); /* save original station/network so we know when to * stop scanning station list */ strcpy(station, s->station); if (type10.version >= 2.3) strcpy(network, s->network_code); do { for (c = s->type52_head; c != NULL; c = c->next) if ((strncmp (channel, c->channel, n) == 0) && strcmp(loc, c->location) == 0) { timecvt(&start, c->start); timecvt(&end, c->end); if (c->end == NULL) end.year = 9999; if (rec_time != NULL) { if (WITHIN((*rec_time), start, end)) { p = c; if (c->subchannel > 0) return(p); } } else { p = c; if (c->subchannel > 0) return(p); } } /* got here without finding channel record, check * the next station record, could be there */ s = s->next; finished = s == 0; } while (!finished && ((strcmp(s->station, station) == 0) && (type10.version >= 2.3 ? (strcmp(s->network_code, network) == 0) : 1))); return p;} /* ------------------------------------------------------------------- *//* actually sets the global variable current_station and current_channel * to point to the right station and channel */int get_stn_chn_rec(s, c, n, l, t)char *s, *c, *l, *n;struct time *t; /* station, channel, location, net, time */ { struct type50 *p, *p2 = NULL; struct type52 *c_rec = NULL, *crec2 = NULL; struct time start, end; /* response effective times */ char stn[10]; /* if we ever get more than 10 * for station and network sizes, * we need to upgrade */ char net[10]; strncpy(stn, s, 10); strncpy(net, n, 10); trim(stn); trim(net); /* check to see if a time epoch was requested */ if (t == NULL) { /* spin until you find a station record */ for (p = type50_head; p != NULL;p = p->next) { if (strcmp(stn, p->station) != 0) continue; if ((type10.version >= 2.3) && (!ignore_net_codes)) if (strcmp(net, p->network_code) != 0) continue; p2 = p; /* remember station rec */ /* spin until you find any channel record */ if (p->type52_head != NULL) { /* check channel */ c_rec = get_channel_rec(p, c, l, NULL); if (c_rec != NULL) crec2 = c_rec; /* remember channel */ } } /* for every station */ current_station = p2; current_channel = crec2; return 1; } /* if not time is requested */ /* else scan based on time */ for (p = type50_head; p != NULL;p = p->next) { if (strcmp(stn, p->station) != 0) continue; if ((type10.version >= 2.3) && (!ignore_net_codes)) if (strcmp(net, p->network_code) != 0) continue; timecvt(&start, p->start); timecvt(&end, p->end); if (p->end == NULL) end.year = 9999; if (WITHIN((*t), start, end)) p2 = p; /* remember station rec */ /* make check for channel records - * it is very possible that the chn records have * been tagged onto a stn rec outside of the * time bounds */ if (p->type52_head != NULL) { /* check channel */ c_rec = get_channel_rec(p, c, l, t); if (c_rec != NULL) crec2 = c_rec; /* ditto channel */ } } current_station = p2; current_channel = crec2; return 1;}/*--------------------------------------------------------------------- */int get_stn_chn_Lrecl(s, c, n, l, t)char *s, *c, *n, *l, *t; /* station, channel, net, time */{ struct time rec_time; timecvt(&rec_time, t); get_stn_chn_rec(s, c, n, l, &rec_time); if ((current_station == NULL) || (current_channel == NULL)) { fprintf (stderr, "WARNING (get_stn_chn_rec_Lrecl()): "); fprintf (stderr, "station/channel %s/%s not found in station/channel tables.\n", s, c); fprintf (stderr, "\tTrying again ignoring effective times.\n"); get_stn_chn_rec(s, c, n, l, NULL); if ((current_station == NULL) || (current_channel == NULL)) { fprintf (stderr, "WARNING (get_stn_chn_Lrecl()): "); fprintf (stderr, "station/channel %s/%s not found in station table.\n", s, c); fprintf(stderr, "Unable to determine the logical record length for station/channel %s/%s for location:\nDefaulting to 4096\n", s, c, l); return 4096; } else fprintf(stderr, "Found stn/chn record\n"); } return 2 << (current_channel->log2drecl - 1); }/* ------------------------------------------------------------------ */void dump_station_effective(s, n)char *s; /* station name */char *n; /* network */ { struct type50 *p = NULL; for (p = type50_head; p != NULL;p = p->next) { if ((strcmp(s, p->station) == 0) && (type10.version >= 2.3 ? (strcmp(n, p->network_code) == 0) : 1)) { fprintf(stderr, "\tStation %s, network %s, start/stop times:\n\t\t %s / %s\n", s, type10.version >= 2.3 ? n : "N/A", p->start, p->end); } } }/* ------------------------------------------------------------------------ */void do_time_correction(t)struct time *t;{ while ((t->fracsec >= 10000) || (t->fracsec < 0)) { if (t->fracsec >= 10000) { t->second += t->fracsec/10000; t->fracsec = t->fracsec%10000; if (t->second >= 60) { t->minute += t->second/60; t->second = t->second%60; if (t->minute >= 60) { t->hour += t->minute/60; t->minute = t->minute%60; if (t->hour >= 24) { t->day += t->hour/24; t->hour = t->hour%24; if (t->day > (isaleap(t->year) ? 366 : 365)) { t->year += 1; t->day = 1; } } } } } else if (t->fracsec < 0) { t->second -= 1; t->fracsec += 10000; if (t->second < 0) { t->minute -= 1; t->second += 60; if (t->minute < 0) { t->hour -= 1; t->minute += 60; if (t->hour < 0) { t->day -= 1; t->hour += 24; if (t->day == 0) { t->year -= 1; t->day = (isaleap(t->year) ? 366 : 365); } } } } } }}/* ------------------------------------------------------------------------- */void dump_seismic_buffer(){ /* make sure pointers are aligned with data that is in the data rec */ get_stn_chn_rec(data_hdr->station, data_hdr->channel, data_hdr->network, data_hdr->location, &(data_hdr->time)); if (current_station == NULL || current_channel == NULL) get_stn_chn_rec(data_hdr->station, data_hdr->channel, data_hdr->network, data_hdr->location, NULL); if (current_station == NULL || current_channel == NULL) { fprintf (stderr, "WARNING (process_data): "); fprintf (stderr, "station/channel %s/%s not found in station/channel tables for location: %s.\n", data_hdr->station, data_hdr->channel, data_hdr->location); fprintf (stderr, "\tSkipping this trace.\n"); return; } time_span_out ();}/* ------------------------------------------------------------------------ */char determine_orient_code(chan)struct type52 *chan;{ if ((ABS(ABS(chan->dip)-90.0) < 2.0) && (ABS(chan->azimuth) < 2.0)) return 'Z'; if ((ABS(chan->dip) < 2.0) && ((ABS(chan->azimuth-180.0) < 10.0) || (ABS(chan->azimuth) < 2.0))) return 'N'; if ((ABS(chan->dip) < 10.0) && ((ABS(chan->azimuth-90.0) < 2.0) || (ABS(chan->azimuth-270.0) < 2.0))) return 'E'; if ((ABS(ABS(chan->dip)-60.0) < 2.0) && ((ABS(chan->azimuth-0.0) < 2.0) || (ABS(chan->azimuth-180.0) < 2.0))) return 'A'; if ((ABS(ABS(chan->dip)-60.0) < 2.0) && ((ABS(chan->azimuth-120.0) < 2.0) || (ABS(chan->azimuth-300.0) < 2.0))) return 'B'; if ((ABS(ABS(chan->dip)-60.0) < 2.0) && ((ABS(chan->azimuth-240.0) < 2.0) || (ABS(chan->azimuth-60.0) < 2.0))) return 'C'; /* if got here flag warning - use subchannel id */ fprintf(stderr, "Warning... Azimuth and Dip out of Range on %s,%s\n", current_station->station, chan->channel); fprintf(stderr, "Defaulting to subchannel identifier (for multiplexed data only)\n"); return chan->subchannel + 48; /* int + '0' */ } /* ------------------------------------------------------------------------ */void swap_fsdh(input_data_hdr, input_data_ptr)struct input_data_hdr **input_data_hdr;char **input_data_ptr; { (*input_data_hdr)->time.year = swap_2byte((*input_data_hdr)->time.year); (*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);}/* ------------------------------------------------------------------ */int process_opaque(char *lrecord_ptr){ struct data_blk_hdr *db_hdr; struct data_blk_1000 *p; int rec, data_rec_length; int finished = FALSE; struct input_data_hdr *hdr = (struct input_data_hdr *)lrecord_ptr; if (hdr->bofb != 0) { db_hdr = (struct data_blk_hdr *) (lrecord_ptr + hdr->bofb); finished = FALSE; while (!finished) { if (db_hdr->type == 2000) { if (process_blk_2k(hdr, (char *)db_hdr + sizeof(struct data_blk_hdr)) ==0) return 0; } if (db_hdr->next_blk_byte == 0) finished = TRUE; db_hdr = (struct data_blk_hdr *) (lrecord_ptr + /* subtract the seq num chars */ (db_hdr->next_blk_byte - 8)); } } return 1;}/* ------------------------------------------------------------------ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -