📄 create_v.c
字号:
/*===========================================================================*//* | | *//*===========================================================================*//* Name: Purpose: Usage: Input: Output: Externals: Warnings: Errors: Fatals: Called by: Calls to: Algorithm: Notes: Problems: end_volume not set properly if volume_break is zero. References: Language: Revisions: mm/dd/yy pgmr name change bugfix 04/13/90 mw make holy tspans come out right print fatal error if zero volume_break bugfix 09nov90 mw ignore timespans with count=0 mod 20nov90 mw use SEED_Version, not SEED_DEFAULT version change calculation for buffersize extensions to reduce non-necessary big_buffer calls. 21apr91 mw clarification of code replace all calls to big_buffer with calls to make_room; it reads better. 03dec91 mw two new fields for blockette 10 volume time (field 7) comes from now. SEED_Version is *10; 2.2 is 22 05/16/95 CL changed the volume timespan entry to something useful.*/#include <stdlib.h>#include "output.h"#include <time.h>void find_vol_tspan_end();void find_vol_tspan_start();void find_first();void find_last();static struct input_time timespan_end;static struct input_time timespan_start;extern int Write_Data;/* ------------------------------------------------------------------------- */int create_V( count, ntspan, tspan_head, volume_break, tspan_break, volume_start, volume_end, nstations, sl_head, v_count )int count; /* count of records before station hdrs */int ntspan; /* number of tspans */struct tspan_list *tspan_head; /* linked list of tspans */struct input_time volume_break; /* delta time of volume */struct input_time tspan_break; /* delta time of tspan */struct input_time volume_start; /* first time (of various things) */struct input_time volume_end; /* last time (of various things) */int nstations; /* number of stations in this volume */struct station_list *sl_head; /* station list */int *v_count; /* how many records we are */{ char *bottom; /* blockette buffer pointers */ char *top; /* ditto */ struct tspan_list *tp; /* local pointer to tspan nodes */ struct station_list *sp; /* pointer to station nodes */ int log_base2; /* log base 2 ( Lrecl ) */ int n; /* counter */ int err; /* local error */ int length; /* current size of buffer */ struct input_time tspan_start; /* start time of tspan */ struct input_time tspan_end; /* end time of tspan */ struct input_time test; /* test time */ struct lvol *xx; struct input_scan yy; struct tm *tm_now, *gmtime(); /* time now */ long now; /* time now */ int len010; /* length of blockette 010 */ char *tape_label; if( Debug >= D_MIN ) fprintf( D_OUT,"[create_V] start\n" ); err = FALSE; bottom = top = NULL; /* they don't exist */ tspan_start = volume_start;/* * make blockette 010, volume ID for Network tape * the time of the end of the last timespan is used (if available) * since the "volume_end" time may be "forever" - a pragmatic * solution which has worked fine until now. If the tspan_break * happens to be 0, meaning make one big tspan, then we * are forced to use the volume_end time anyway. * * THIS CODE IS BROKEN - * it assumes that end_vol = start_vol + ntspan*tspan_break */ log_base2 = 0; n = Lrecl; while(n >>= 1) log_base2++; /* just count the zero bits */ if( cmp_longtime( add_inputtime( volume_start, volume_break ), volume_start ) == 0 ) { volume_end = volume_start; n = ntspan; while( n-- ) volume_end = add_inputtime( volume_end, tspan_break ); error_handler( FATAL,"create_V end volume is wrong" ); }/* * only used for version 2.2 or greater */ n = strlen( Organization ); /* the length has been pre-qualified! */ if( n > 80 ) { error_handler( FATAL,"create_V Organization name too long" ); } len010 = 59; /* old blockette 010 size */ if( SEED_Version >= 22 ) { tape_label = getenv("SEED_LABEL"); if (tape_label == NULL) tape_label = ""; if (strlen(tape_label) > 80) *(tape_label + 80) = 0; len010 = 59 + 23 + n + 1 + strlen(tape_label) + 1; /* newer blockette size - add one for the ~ */ } (void)make_room( 0, 13+23+23, &bottom, &top ); sprintf( top, "010%.4d%04.1f%.2d", len010, (float)SEED_Version/10.0, log_base2 ); /* find earliest timespan */ find_vol_tspan_start(×pan_start, tspan_head); top = top + 13; sprintf( top, "%s", input_time_to_asc(timespan_start)); /* find last timespan */ find_vol_tspan_end(×pan_end, tspan_head); top = top + 23; sprintf( top, "%s", input_time_to_asc(timespan_end)); top = top + 23; length = (int)(top - bottom);/* * if we are writing seed version 2.2 or greater, then blockette 10 * has 8 fields. */ if( SEED_Version >= 22 ) { (void)make_room(length, 22+80+80, /*Vol Time, Organization and Label */ &bottom, &top ); now = time(NULL); /* seconds since 1970 */ tm_now = localtime(&now); /* split it up */ test.fracsec = 0; test.second = 0; test.minute = tm_now->tm_min; test.hour = tm_now->tm_hour; test.day = tm_now->tm_yday + 1; /* jan 1 = 0 in unix-speak */ test.year = tm_now->tm_year + 1900; sprintf( top, "%s", input_time_to_asc( test ) ); top = top + 23; sprintf( top, "%s~", Organization ); top = top + n+1; sprintf(top, "%s~", tape_label); top += strlen(tape_label) + 1; /* plus one for the ~ */ length = (int)(top - bottom); }/* * fixed part of blockette 11, station header index, then variable part * remember that the station list was set up with record number relative * to the first station header = 0. */ (void)make_room(length,10, &bottom, &top); sprintf(top, "011%.4d%.3d", (nstations*11)+10, nstations); top += 10; count++; /* record number next to write */ sp = sl_head; /* traverse the station list */ length = top-bottom; while( sp != NULL ) { (void)make_room( length, 11, &bottom, &top ); sprintf( top,"%.5s%.6d", sp->name, (sp->seqno)+count ); top += 11; length = top-bottom; sp = sp->next; }/* * fixed part of blockette 12, time span index, then variable part * the sequence numbers here are absolute. */ if (Write_Data) { (void)make_room( length, 11, &bottom, &top ); sprintf( top, "012%.4d%.4d", (ntspan*52)+11, ntspan ); top += 11; length = top-bottom; tp = tspan_head; while( tp != NULL ) { /* find earliest timespan */ timespan_start.year = 99999; find_first(×pan_start, tp->start); /* find last timespan */ timespan_end.year = 0; find_last(×pan_end, tp->start); (void)make_room(length, 23+23+6, &bottom, &top); tspan_end = add_inputtime(tspan_start, tspan_break); sprintf(top,"%s", input_time_to_asc(timespan_start)); top = top + 23; sprintf(top,"%s", input_time_to_asc(timespan_end)); top = top + 23; sprintf(top,"%.6d", tp->seqno); top = top + 6; length = top-bottom; tp = tp->next; if( tp != NULL && tp->count > 0 ) { xx = tp->start; /* there must */ yy = xx->scan; /* be a better */ test = yy.time; /* way for this! */ do { /* next timespan (may be empty) */ tspan_start = tspan_end; tspan_end = add_inputtime(tspan_end, tspan_break); } while( cmp_longtime( tspan_end, test ) <= 0 ); if(cmp_longtime(tspan_start, test) > 0) { err=error_handler(FATAL,"Create_V holy tspan start>data" ); } } } } /* if (write_data) *//* * now make volume control logical records */ err = make_lrec( bottom, 'V', length, v_count ); if( err ) if( err=error_handler( err,"[create_V] make_lrec failed" ) ) return( err ); if( Debug >= D_MIN ) fprintf( D_OUT,"[create_V] end\n" ); return( err );}/* ------------------------------------------------------------------------ */void find_vol_tspan_start(start, tspan)struct input_time *start;struct tspan_list *tspan;{ static struct input_time first; start->year = 9999; while (tspan) { first.year = 9999; find_first(&first, tspan->start); if (cmp_time(first, *start, 0) < 0) *start = first; tspan = tspan->next; } }/* ------------------------------------------------------------------------ */void find_vol_tspan_end(end, tspan)struct input_time *end;struct tspan_list *tspan;{ static struct input_time last; end->year = 0; while (tspan) { last.year = 0; find_last(&last, tspan->start); if (cmp_time(last, *end, 0) > 0) *end = last; tspan = tspan->next; } } /* ------------------------------------------------------------------------ */void find_first(first, tspans)struct input_time *first;struct lvol *tspans;{ while (tspans) { if (cmp_time(tspans->scan.time, *first, 0) < 0) *first = tspans->scan.time; tspans = tspans->next; }}/* ----------------------------------------------------------------------- */void find_last(last, tspans) struct input_time *last; struct lvol *tspans; { last->year = 0; while (tspans) { if (cmp_time(tspans->endtime, *last, 0) > 0) { *last = tspans->endtime; } tspans = tspans->next; } }/* ------------------------------------------------------------------------ */void dump_tspans(tspan)struct tspan_list *tspan;{ while (tspan) { dump_tspan_list(tspan->start); tspan = tspan->next; } }/* ------------------------------------------------------------------------ */dump_tspan_list(tspan)struct lvol *tspan;{ FILE *fptr; fptr = fopen("tspans.tmp", "w+"); while (tspan) { fprintf(fptr, "scan = %5.5s, %3.3s : %d,%d %d:%d:%d - %d,%d %d:%d:%d\n", tspan->scan.station, tspan->scan.channel, tspan->scan.time.year, tspan->scan.time.day, tspan->scan.time.hour, tspan->scan.time.minute, tspan->scan.time.second, tspan->endtime.year, tspan->endtime.day, tspan->endtime.hour, tspan->endtime.minute, tspan->endtime.second); tspan = tspan->next; } fclose(fptr); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -