📄 summary.c
字号:
(IS_BTW(req_end, *blk_start, *blk_end)) || (IS_BTW(*blk_start, req_start, req_end)) || (IS_BTW(*blk_end, req_start, req_end)))) { stn_ptr = stn_ptr->next; continue; } /* got here - everything checks out */ return stn_ptr->ts_head; } return 0; /* didn't find it */ }/* ----------------------------------------------------------------- */int reset_chn_name_generator();struct type74 *extract_74s();static struct stn_tspan *stn_ptr;static struct stn_tspan *now_stn;/* ----------------------------------------------------------------- */int process_summary_file(){ struct twindow *twin, *tw; struct type74 *b74_ptr; char *chn_ptr, **c_ptr; char **l_ptr; char channel[4]; int i, n, nn; stn_ptr = stn_listhead; while (stn_ptr) { /* 1st check to see if stn, net is in the contents */ if (!scan_74s(stn_ptr->stn, stn_ptr->net)) { stn_ptr = stn_ptr->next; continue; } /* make a check for non-null ts_head */ if (stn_ptr->ts_head == NULL) { stn_ptr = stn_ptr->next; continue; } n = split(stn_ptr->ts_head->chn_list, &c_ptr, ','); nn = split(stn_ptr->ts_head->loc_list, &l_ptr, ','); for (i = 0; i < n; i++) { b74_ptr = type74_head; while (b74_ptr != NULL) { /* Notice: only one twindow per stn node, no linked * list for now, each time window gets a separate node */ b74_ptr = extract_74s(b74_ptr, stn_ptr->stn, stn_ptr->net, c_ptr[i], nn == 0 ? "" : nn > i ? l_ptr[i] : l_ptr[nn-1], stn_ptr->ts_head->time_start, stn_ptr->ts_head->time_end); if (b74_ptr != NULL) { this_event = stn_ptr->this_event; /* save this stn's summary file line for later * comparisons. * See chk_summary() */ now_stn = stn_ptr; extract_this_timespan(b74_ptr); time_span_out(); /* funky process_data() flag */ output = 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; b74_ptr = b74_ptr->next; } } /* while chn_ptr */ } /* for */ fuse(&c_ptr, n); fuse(&l_ptr, nn); stn_ptr = stn_ptr->next; }}/* ----------------------------------------------------------------- */int chk_summary(blk_start, blk_end) struct time blk_start;struct time blk_end;{ struct time this_stn_start; struct time this_stn_end; timecvt(&this_stn_start, now_stn->ts_head->time_start); timecvt(&this_stn_end, now_stn->ts_head->time_end); return (timecmp(blk_start, this_stn_end) <= 0) && (timecmp(blk_end, this_stn_start) >= 0);}/* ----------------------------------------------------------------- */int scan_list(struct type74 *this_74, char *r_start, char *r_end){ /* this_74 holds a valid timespan as determined * from initial scan from blockette 74s. Now * rescan looking for blk 74s which lie outside * this_74s params, but within the sumfile request */ struct type74 *nother_74; struct time req_start, tspan_start; struct time req_end, tspan_end; nother_74 = this_74->next; if (nother_74 == NULL) nother_74 = type74_head; /* start at head of list */ while (nother_74 != this_74) { if (chk_s_n_c_l(this_74->station, this_74->network_code, this_74->channel, this_74->location, nother_74)) { /* see of times fall in btw request */ /* 1st check for overlap */ timecvt(&req_start, r_start); timecvt(&tspan_start, nother_74->starttime); timecvt(&req_end, r_end); timecvt(&tspan_end, nother_74->endtime); if (!((IS_BTW(req_start, tspan_start, tspan_end)) || (IS_BTW(req_end, tspan_start, tspan_end)) || (IS_BTW(tspan_start, req_start, req_end)) || (IS_BTW(tspan_end, req_start, req_end)))) { nother_74 = nother_74->next; if (nother_74 == NULL) nother_74 = type74_head; continue; } /* if it falls btw request span, check to * see that at least part of it lies outside * the already extracted blockette 74 * but not totally within it. Redundant */ /* req_start and req_end are handy variable */ timecvt(&req_start, this_74->starttime); timecvt(&req_end, this_74->endtime); if ((IS_BTW(req_start, tspan_start, tspan_end)) || (IS_BTW(req_end, tspan_start, tspan_end)) && !((timecmp(tspan_start, req_start) >= 0) && (timecmp(tspan_end, req_end) < 0))) { this_event = stn_ptr->this_event; extract_this_timespan(nother_74); time_span_out(); /* funky process_data() flag */ output = 0; } } nother_74 = nother_74->next; if (nother_74 == NULL) nother_74 = type74_head; /* start at head of list */ }}/* ----------------------------------------------------------------- */struct twindow *get_twin_from_summary(){ return stn_ptr->ts_head;}/* ----------------------------------------------------------------- */struct type74 *find_closest_b74();/* ----------------------------------------------------------------- */struct type74 *extract_74s(type74, stn, net, chn, locs, start, end)struct type74 *type74;char *stn, *net, *chn, *locs, *start, *end;{/* * We are looking at these possibilities * * Request from summary file totally lies within b74 start, end * stop here as we found it * * Search again for a B74 that overlaps it, or a B74 which lies * totally within the requested timespan. Determine which is * closer. */ int found_times, found_stn; struct type74 *sav_type74 = type74; found_times = found_stn = FALSE; while (type74 != NULL) { if (!chk_s_n_c_l(stn, net, chn, locs, type74)) { type74 = type74->next; continue; } if (chk_type74(type74, start, end)) return type74; type74 = type74->next; }#if 0 /* if encompassing 74 not found, look for best fit */ if (!found_times && found_stn) { type74 = find_closest_b74(net, stn, chn, locs, start, end, sav_type74); if (type74 == NULL) { fprintf(stderr, "Warning : scan_74s() - unable to locate matching blockette 74 for summary file requested entry\n"); fprintf(stderr, "Request: station/chn/net %s/%s/%s for :%s..to..%s\n", stn, chn, net, start, end); } }#endif return type74; }/* ----------------------------------------------------------------- */int chk_type74(struct type74 *type74, char *start, char *end){ struct time req_start, tspan_start; struct time req_end, tspan_end; timecvt(&req_start, start); timecvt(&tspan_start, type74->starttime); timecvt(&req_end, end); timecvt(&tspan_end, type74->endtime); return ((timecmp(tspan_start, req_end) <= 0) && (timecmp(tspan_end, req_start) >= 0));}/* ----------------------------------------------------------------- */struct type74 *find_closest_b74(net, stn, chn_list, locs, start, end, type74)char *net;char *stn;char *chn_list;char *locs;char *start, *end;struct type74 *type74;{ struct type74 *save_type74 = NULL; struct time req_start, tspan_start; struct time req_end, tspan_end; float diff_start, diff_end, this_diff; float smallest = 999999999; while (type74 != NULL) { if (!chk_s_n_c_l(stn, net, chn_list, locs, type74)) { type74 = type74->next; continue; } /* check B74's start end time pairs which * come closest to the request start/end times */ /* strategy is to add up the differences of the * corresponding endpoints, smallest wins */ /* 1st check for overlap */ timecvt(&req_start, start); timecvt(&tspan_start, type74->starttime); timecvt(&req_end, end); timecvt(&tspan_end, type74->endtime); if (!((IS_BTW(req_start, tspan_start, tspan_end)) || (IS_BTW(req_end, tspan_start, tspan_end)) || (IS_BTW(tspan_start, req_start, req_end)) || (IS_BTW(tspan_end, req_start, req_end)))) { type74 = type74->next; continue; } diff_start = timedif(req_start, tspan_start); diff_end = timedif(req_end, tspan_end); this_diff = fabs(diff_start) + fabs(diff_end); if (this_diff < smallest) { smallest = this_diff; save_type74 = type74; } type74 = type74->next; } return save_type74;}int chk_s_n_c_l(s, n, c, l, type74)char *s, *n, *c, *l; struct type74 *type74;{ if (strcmp(s, type74->station) != 0) return 0; if (strcmp(n, "??") == 0 ? 0 : (strcmp(n, type74->network_code) != 0)) { return 0; } if (chk_chn_list(c, type74->channel) == 0) return 0; if (!chk_locs(l, type74->location)) return 0; return 1;}/* ----------------------------------------------------------------- */int scan_74s(stn, net)char *stn, *net;{ struct type74 *type74; type74 = type74_head; while (type74 != NULL) { if (strcmp(stn, type74->station) != 0) { type74 = type74->next; continue; } if (strcmp(net, "??") == 0 ? 0 : (strcmp(net, type74->network_code) != 0)) { type74 = type74->next; continue; } return 1; } return 0;}/* ----------------------------------------------------------------- *//* check the start/end pair to see if it falls btw the summary file * station pointer's start stop end pair * * stn_ptr is static and points to the station currently being processed */int chk_sumfile_times(this_start, this_end)struct time this_start;struct time this_end;{ struct time req_start, req_end; struct twindow *twin = stn_ptr->ts_head; while (twin) { timecvt(&req_start, twin->time_start); timecvt(&req_end, twin->time_end); /* check for overlap of the B74 over the requested start/stop */ if ((timecmp(this_start, req_end) <= 0) && (timecmp(this_end, req_start) >= 0)) return 1; twin = twin->next; } return 0;}/* ----------------------------------------------------------------------- */int chk_chn_list(chn_list, channel)char *chn_list;char *channel;{ char **ch_ptr; int i, n; strupr(chn_list); strupr(channel); n = split(chn_list, &ch_ptr, ','); for (i = 0; i < n; i++) if (wstrcmp(channel, ch_ptr[i], 3) == 0) { fuse(&ch_ptr, n); return 1; } fuse(&ch_ptr, n); return 0; }/* ----------------------------------------------------------------------- */int chk_locs(l, location)char *l;char *location;{ char **l_ptr; int i, n; /* if locations as entered are null string, accept all */ if (strlen(l) == 0) return 1; strupr(l); strupr(location); n = split(l, &l_ptr, ':'); for (i = 0; i < n; i++) { /* map hypen (dash) '-' to space. * Since rdseed truncates locs at the first * space, we do the same. */ if (strchr(l_ptr[i], '-')) { char *p = strchr(l_ptr[i], '-'); *p = 0; } if (wstrcmp(location, l_ptr[i], 2) == 0) { fuse(&l_ptr, n); return 1; } } fuse(&l_ptr, n); return 0; }/* ----------------------------------------------------------------------- */char *summary_file_get_event() { return this_event;}/* ------------------------------------------------------------------------- */#if 0 int chk_tspans(start_1, end_1, start_2, end_2)char *start_1, *end_1, *start_2, *end_2;{ struct time blk_start, blk_end; struct time req_start, req_end; timecvt(&blk_start, start_1); timecvt(&blk_end, end_1); timecvt(&req_start, start_2); timecvt(&req_end, end_2); /* Look at 4 possibilities : * * 1: starts are equal i.e: * blk |----------------------| * req |---------------------------| * * 2. start of blk is greater than req start, * but not greater than req end, i.e: * blk |------------------------------| * req |-------------------------| * * 3. start of blk before req start, but end is before req end, i.e: * blk |--------------------------| * req |-----------------| * * 4. blk overlaps request * blk |--------------------------| * req |-----------------| * */ /* #4 */ if ((timecmp(req_start, blk_start) >= 0) && (timecmp(req_end, blk_end) <= 0)) return 4; /* # 1 - does start of block == request ? */ if (timecmp(blk_start, req_start) == 0) return 1; if (timecmp(blk_start, req_start) > 0) { /* #2 */ if (timecmp(blk_start, req_end) <= 0) return 1; } /* # 3*/ if ((timecmp(blk_end, req_start) > 0) && (timecmp(blk_end, req_end) <= 0)) return 1; /* Got here? didn't find it */ return 0; }#endif/* ------------------------------------------------------------ */int setup_tspan(tspan_start, tspan_end)char *tspan_start, *tspan_end;{ /* fake out computer into thinking this timespan was entered * at the computer. Add into holding array... */ start_time_count++; end_time_count++; if (start_time_count == 1) /* 1st time through */ start_time_point = (struct time *)malloc(sizeof(struct time)); else start_time_point = (struct time *)realloc(start_time_point, sizeof(struct time) * start_time_count); if (end_time_count == 1) end_time_point = (struct time *)malloc(sizeof(struct time)); else end_time_point = (struct time *)realloc(end_time_point, sizeof(struct time) * end_time_count); timecvt(&start_time_point[start_time_count - 1], tspan_start); timecvt(&end_time_point[end_time_count - 1], tspan_end);}/* ------------------------------------------------------------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -