📄 create_s.c
字号:
/*===========================================================================*//* DMC Interim | create_S | Header_phase *//*===========================================================================*//* Name: create_S.c Purpose: build SEED station control headers in memory Usage: Input: Output: Externals: Warnings: Errors: Fatals: Called by: Calls to: Algorithm: for each station, make a concatenated buffer of all blockettes which are needed. These are the 050, 051 blockettes returned by get_stn_hdr, and the 052-059,060 blockettes returned by the get_chnl_hdr. For each such buffer, make logical records out of them, and remember where (relative to the first) each of these is. This will be used later to make the volume directory. Notes: Assumes all header files are in desired output order. Problems:If the data request spans two versions (e.g., a & b) of a station header, this routine will assemble all of the correct blockettes but in the following order (e.g., for channels 1-3): 50a, 50b, 51a, 51b, 52-59a1, 52-59b1, 52-59a2, 52-59b2, 52-59a3, 52-59b3 rather than in the strictly legal order: 50a, 51a, 52-59a1, 52-59a2, 52-59a3, 50b, 51b, 52-59b1, 52-59b2, 52-59b3 References: Language: Author: Mark Wiederspahn, 03/13/89 Revisions: mm/dd/yy pgmr name change 05/03/89 Kevin MacKenzie revised get_stn_hdr and get_chnl_hdr calling arg list 05/08/89 Kevin MacKenzie added patching of blockette 050 with output channel count 06/22/89 mw sort the station channel list to avoid duplications when multiple timespans occur in a volume. change the maxlen count for patch_field 05/16/95 CL - usage of location code for the network code 08/25/97 CL - changed location to network*/#include "output.h"#define SUBSTR(str,xch,ch) \ { char *c; \ while (c = strchr(str, xch)) \ *c = ch; \ }int strcmp();void print_file_name(); int create_S( nlvol, lvol_head, start, end, sl_head, sl_tail, s_count, nstations )int nlvol; /* number of elements on list */struct lvol *lvol_head; /* singly linked list of segments */struct input_time start; /* volume start time */struct input_time end; /* volume end time */struct station_list **sl_head; /* list of stations head */struct station_list **sl_tail; /* tail */int *s_count; /* count of records in all station hdrs */int *nstations; /* count of nodes in station list */{ int err; /* return error status */ struct lvol *p; /* ptr to each time segment node */ struct lvol *save_p;/* save previous node for error rpting */ struct station_list *sp; /* ptr to each station info */ char station_net[20]; /* current station/network */ char channel_loc[5+1]; /* current channel/loc */ int nchans; /* count of channels in current station */ char *bottom; /* bottom of scratch area */ char *top; /* top of scratch area */ int n; /* general purpose */ char *scp; /* pointer to sorted station-channels */ char *base; /* base of sort table */ int nscp; /* count of stations */ int i; if( Debug >= D_MIN ) fprintf( D_OUT,"[create_S] start\n" );#ifdef MALLOC_DEBUG if( !malloc_verify() ) fprintf( D_OUT,"[create_S] verify entry failed\n" );#endif err = FALSE; *s_count = 0; /* count of logical records made */ *nstations = 0; /* count of stations seen */ *sl_head = *sl_tail = NULL; bottom = top = NULL; strcpy(station_net, " "); if( (base = (char *)calloc(nlvol, 5+2+3+2+1)) == NULL ) { if( err = error_handler( FATAL,"[create_S] calloc failed\n" ) ) return( err ); } scp = base; /* pointer to unsorted station-channels */ p = lvol_head; while( p != NULL ) /* copy all to a table */ { strncpy(scp, p->scan.station, 5); /* scp += 5; */ strncpy(scp + 5, p->scan.network, 2); /* scp += 2; */ strncpy(scp + 7, p->scan.channel, 3); strncpy(scp + 10, p->scan.location, 2); /* make sure all nulls are blanks, until terminating null */ for (i = 0; i < 12; i++) if (scp[i] == '\0') scp[i] = ' '; scp[12] = 0; /* sizeof stn, chn, net, loc */ scp += 13; /* move past null */ p = p->next; if( Debug >= D_SOME ) fprintf( D_OUT,"[create_S] unsorted: %s\n", scp-(5+3+1) ); } qsort(base, nlvol,5+3+2+2+1, strcmp); /* sort station channels */ scp = base; /* point to sorted station channels */ nscp = nlvol; /* count to examine */ while( nscp-- ) { if( Debug >= D_SOME ) fprintf( D_OUT,"[create_S] sorted: %s\n", scp ); if (strncmp(scp, station_net, 7) != 0) { if( bottom != NULL ) { patch_field ( bottom, 0, 40, 0, nchans, "%4.4d" ); nchans = 0; err = make_lrec( bottom, 'S', (int)(top-bottom), &n ); if( err ) if( err=error_handler( err,"[create_S] make_lrec err.\n") ) return( err ); free( bottom );#ifdef MALLOC_DEBUG if( !malloc_verify() ) fprintf( D_OUT,"[create_S] verify middle failed\n" );#endif bottom = top = NULL; sp = make_station( sl_head, sl_tail ); strncpy(sp->name, station_net, 5); sp->name[5] = '\0'; strncpy(sp->network, &station_net[5], 2); /* relative block number of start */ sp->seqno = *s_count; /* update count of total LR's */ *s_count += n; } (*nstations)++; strncpy(station_net, scp, 7); station_net[7] = '\0'; if( err = get_stn_hdr(station_net, start, end, &bottom, &top ) ) { /* filter out those times when * we didn't find a station, due * to time contraints. */ if (err == STN_NOT_FOUND_WARNING) { fprintf(stderr, "Warning! [create_S] - station info not found for station/channel %s\n", scp); scp += 13; /* point past station+network+channel+null */ strcpy(station_net, " "); free(bottom); bottom = top = NULL; (*nstations)--; err = 0; continue; } if( err=error_handler( err,"[create_S] get_stn_hdr error.\n") ) { print_file_name(station_net, lvol_head); return( err ); } } strcpy(channel_loc, " "); nchans = 0;/* count of channels in current station */ if( Debug >= D_SOME ) fprintf( D_OUT,"[create_S] station %s\n", station_net); } scp += 7; /* point past station/network */ if (strncmp(channel_loc, scp, 5) != 0) { strncpy(channel_loc, scp, 5); channel_loc[5] = 0; if( err=get_chnl_hdr(station_net, channel_loc, start, end, &bottom, &top )) if( err=error_handler( err,"[create_S] get_chnl_hdr error.\n") ) return( err ); if( Debug >= D_SOME ) fprintf(D_OUT,"[create_S] channel %s\n", channel_loc ); nchans++; /* increment station's channel count */ } scp += 5+1; /* point past channel + loc + null */ } /* while */ if( bottom != NULL ) { patch_field ( bottom, 0, 40, 108, nchans, "%4.4d" ); nchans = 0; if( err = make_lrec( bottom, 'S', (int)(top-bottom), &n ) ) if( err=error_handler( err,"[create_S] make_lrec err.\n") ) return( err ); free( bottom );#ifdef MALLOC_DEBUG if( !malloc_verify() ) fprintf( D_OUT,"[create_S] verify exit failed\n" );#endif sp = make_station(sl_head, sl_tail); strncpy(sp->name, station_net, 5); sp->name[5] = '\0'; strncpy(sp->network, &station_net[5], 2); sp->seqno = *s_count; /* relative block number of start */ *s_count += n; /* update count of total LR's */ } free( base ); if( Debug >= D_MIN ) fprintf( D_OUT,"[create_S] end\n" ); return( err );}/* ------------------------------------------------------------------------ */void print_file_name(station, lvol_head)char *station;struct lvol *lvol_head;{ while (lvol_head) { if (strcmp(station, lvol_head->scan.station) == 0) { fprintf(stderr, "Data file name:%s\n", lvol_head->name); return; } lvol_head = lvol_head->next; } return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -