📄 create_t.c
字号:
/*===========================================================================*//* | | *//*===========================================================================*//* Name: Purpose: Usage: Input: Output: Externals: Warnings: Errors: Fatals: Called by: Calls to: Algorithm: A seed version 2.0 volume with 3 tspans looks like: V A S T D T D T D and can be constructed one tspan at a time, knowing the number oof the VAS logical records only. Each T contains pointers to the absolute record number of each D piece. Also the record number of each T ends up in the V, but as long as you know where the T's end up, this can be done later (by create_V). For seed version 2.1, the same volume looks like: V A S T T T D D D In order to determine the pointers to D's to include in each T, you MUST first know how many T logical recs you will end up with. Thus, for v2.1, an additional prior loop over the sizing code must be done to determine how many T logical records we will make so we can get the indexes right as we make them. Thus: if( seed v2.1 ) find sizes of all T log recs for each tspan find size of this log rec make all blockettes for this tspan make logical records from these blockettes Notes: Problems: References: Language: Author: Mark Wiederspahn, 03/13/89 (and chief chump) Revisions: mm/dd/yy pgmr name change 03/13/89 mw fix datapieces vs type 073's problem all data < 1apr89 has bad tspans 06/22/89 mw re-install fix for empty timespans - ignore them. 01/19/90 mw another stage of purgatory: sigh... fix two serious problems: 1) BEFORE EACH TIME a sprintf() writes to a logical record, it MUST test for logical record overrun - ie is current_len + sprintf len > next Lrecl boundary? If so, call big_buffer to get more buffer space. 2) just plain wrong: after test of length+19, if big_buffer called, top was incorrectly calculated. Top should only be updated after a sprintf call, not after allocation. How the old code EVER worked is a mystery - probably larger allocs shielded the smaller ones. 04/13/90 mw fix mis-alignment between the tspans emitted here and the tspan list. There may be tspan intervals where no data exists. See the comments at the end. 16jul90 mw hi, it's me again. BUGFIX 1) strncmp( scanstuff ) was using total of 5+7+3 chars length, when it should have been 5+2+3 = 10. 2) 2nd use of n=min(MAX_DP,ndp) was *not* inside the while( ndp>0 ) loop. how it snuck out is a mystery. 3) pointer to last use needs to have lr_count added to it (in %.6d01 sprintf) 09nov90 mw BUGFIX if there are no data records found in a timespan, just ignore the tspan. This only occurs when the last tspan in a volume finds no data in the request windows. whilst searching for same channels while building 073's, don't go past the number of nodes in this timespan. ntotal downcounted in loop. 20nov90 mw MOD add lots of if-then-elses to support SEED v2.1 blockette 074's and to permit placing all tspans before any data. 21apr91 mw clarification of code replace all calls to big_buffer() with calls to make_room(); it reads better. move local routine make_room to Utilities. 11/02/93 cl added 2.3 support for network code 05/16/95 CL usage of scan.location code for the network code in blk 74s.*/#include "output.h"static struct input_time timespan_start;static struct input_time timespan_end;extern int Write_Data;#define SIZE_070 8+23+23int create_T( count, ntspan, tspan_head, start_volume, tspan_break, t_count )int count; /* count of records before 1st time span */ /* used as "next record number" here */int ntspan; /* number of tspans */struct tspan_list *tspan_head; /* linked list of tspans */struct input_time start_volume;/* time of first tspan */struct input_time tspan_break; /* delta time of each tspan*/int *t_count; /* how many records of tspan we are */{struct tspan_list *tp; /* local pointer */struct lvol *p; /* local pointer */struct lvol *pdp; /* local pointer */struct input_time start, end; /* start and end of a tspan */char *bottom, *top; /* blockette buffer pointers */int length; /* of actual built blockette buffer */int n; /* counter of segments in Index blkette */int ndp; /* counter of segments */int ntotal; /* counter of total segments */int err; /* return status */int lr_count; /* computed lr_count for one timespan */int lr_actual; /* logical record actual count for tspan */int lr_tspan; /* logical record total for all tspans */int lr_data; /* logical record count for data ptrs */int padded_size; /* sum of padded blockette sizes */int blockette_type; /* type of index depends on seed version */int fixed; /* fixed size (bytes) of blockette_type */int peritem; /* variable size of blockette_type */int nacc_ptrs; /* number of accelerator pointers */int max_datapieces; /* number of datapieces which can be * described in one blockette of <= 9999 */int nrec; /* number of records in a data_piece */char endtime[30]; /* temp for input_time_to_asc */struct input_time test;struct lvol *xx;struct input_scan yy;int where_in_logrec; /* number within the logical record the data * span stops - if the data_rec size is less * than the logical rec size */#ifdef MALLOC_DEBUG if( !malloc_verify() ) fprintf( D_OUT,"[create_T] verify entry failed\n" );#endif if( SEED_Version == 20 ) { blockette_type = 73; fixed = 11+19; /* 11 header, 19 trailer */ peritem = 41; /* bytes per data piece */ } else if( SEED_Version >= 21 ) { blockette_type = 74; fixed = 7; /* 7 header, no trailer */ if (SEED_Version >= 23) peritem = 77; /* bytes per data piece */ else peritem = 75; } else { error_handler( FATAL,"[create_T] bad SEED_Version" ); } if( err = get_blk71_hdr() ) if( err=error_handler( err,"[create_T] get_blk71_hdr failed.\n")) return( err ); if( Debug >= D_MIN ) fprintf( D_OUT,"[create_T] start\n" ); err = FALSE; *t_count = 0; /* total number of tspan log recs */ count++; /* record number of record to write */ lr_tspan = 0; /* total count of T logrecs */ tp = tspan_head; start = start_volume; /* tspan starts at volume start */ end = add_inputtime( start, tspan_break );/* ends a start+delta *//* * first loop over all tspans - figure out their total sizes * this is only needed for non-v2.0 seed, but do it anyway. */ while( tp != NULL && tp->count > 0 ) /* for each tspan */ /* which has anything in it */ { max_datapieces = (9999-fixed) / peritem; padded_size = SIZE_070; /* fixed size of 070 */ add_event_lrecs(start, end, &padded_size); /* add in event info */ p = tp->start; /* 1st lvol node in tspan */ ntotal = tp->count; /* total number of nodes */ while( ntotal > 0 ) { pdp = p; ndp = 0; /* count datapieces */ if( pdp == NULL ) { err=error_handler(FATAL,"[create_T] ran out of dp's"); } if( blockette_type == 73 )/* glue datapieces together */ { while( pdp != NULL && ntotal > 0 && strncmp((char *)&p->scan, (char *)&pdp->scan, 5+2+3 ) == 0 ) { ndp++; /* count StationLocChannel same */ ntotal--; pdp = pdp->next; } } else if( blockette_type == 74 ) { ndp++; ntotal--; pdp = pdp->next; } while( ndp > 0 ) { n = min( max_datapieces, ndp ); /* do it in pieces */ ndp -= n; lr_count = size_logrec( fixed+(peritem*n), Lrecl, &padded_size ); } p = pdp; /* next chunk */ } lr_tspan += lr_count; /* total tspan size */ tp = tp->next; /* next tspan with data */ if( tp != NULL && tp->count > 0 ) { xx = tp->start; /* there must */ yy = xx->scan; /* be a better */ test = yy.time; /* way for this! */ do { start = end; /* next timespan (may be empty) */ end = add_inputtime( end, tspan_break ); } while( cmp_longtime( end, test ) <= 0 ); } }/* * lr_tspan is total number of logical records for T records in this volume * this must be added to the lr_data pointer to get the actual index. */ lr_data = count; /* record number of next data */ tp = tspan_head; start = start_volume; /* tspan starts at volume start */ end = add_inputtime( start, tspan_break ); /* ends a start+delta */ while( tp != NULL && tp->count > 0 ) /* for each tspan */ { /* which has anything in it *//* * the volume header needs to know where the tspan header will go */ if( blockette_type == 73 ) tp->seqno = lr_data; /* recno of time span start */ else tp->seqno = count + *t_count; /* recno of tspan start *//* * make blockette 70 */ /* find earliest timespan */ timespan_start.year = 9999; find_first(×pan_start, tp->start); timespan_end.year = 0; find_last(×pan_end, tp->start); bottom = top = NULL; (void)make_room( 0, 8+23+23, &bottom, &top ); sprintf( top,"0700054P" );/* avoid 2 calls to input_t... */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -