📄 flush_output_volume.c
字号:
/*===========================================================================*//* UTIG DMC | flush_output_volume.c | Output_phase *//*===========================================================================*//* Name: flush_output_volume.c Purpose: create a SEED logical volume from information in memory and by reading disk files. Usage: err = flush_output_volume( file, nlvol, ntspan, start, end ) Input: FILE file open output file int nlvol number of nodes in lvol number of time segements total in volume int ntspan number of nodes in tspan list == number of time spans in volume struct input_time volume_break struct input_time tspan_break Output: int err 0 if all ok, else error Externals: Tspan_head Headers_head Warnings: Errors: Fatals: Called by: main() Calls to: output_vas() output_tspan() output_data() error_handler Algorithm: Notes: Problems: References: Language: Sun OS 3.5 C Revisions: mm/dd/yy pgmr name change bugfix 09nov90 mw never reference timespans which have a count of zero. These may occur at the end of a volume if there were no data records within the search window.*/#include "output.h"/*temp*/extern struct tspan_list *Tspan_head;extern struct logrec_list *Headers_head;extern int Write_Data;int flush_output_volume( file, nlvol, ntspan, volume_break, tspan_break, start_volume, end_volume )FILE *file; /* open output file */int nlvol; /* number of nodes in lvol list */int ntspan; /* number of nodes in timespan list */struct input_time volume_break; /* time delta */struct input_time tspan_break; /* time delta */struct input_time start_volume; /* start time */struct input_time end_volume; /* end time */{register struct logrec_list *hp; /* header pointer */register struct tspan_list *tp; /* timespan pointer */int err;int n;int nt;struct lvol *lp;int count; /* count of all records expected */int junk; /* a dummy buffer */ /* * if there is anything to be done, then do it */ if( Debug >= D_MIN ) fprintf( D_OUT,"[flush_output_volume] start\n" ); if( nlvol > 0 ) { if( Debug >= D_MIN ) { fprintf( D_OUT, "[flush_output_volume] from: %.4d,%.3d,%.2d:%.2d:%.2d\n", start_volume.year, start_volume.day, start_volume.hour, start_volume.minute, start_volume.second ); fprintf( D_OUT, "[flush_output_volume] to: %.4d,%.3d,%.2d:%.2d:%.2d\n", end_volume.year, end_volume.day, end_volume.hour, end_volume.minute, end_volume.second ); fprintf( D_OUT, "[flush_output_volume] step: %.4d,%.3d,%.2d:%.2d:%.2d\n", volume_break.year, volume_break.day, volume_break.hour, volume_break.minute, volume_break.second ); fprintf( D_OUT, "[flush_output_volume] ts step: %.4d,%.3d,%.2d:%.2d:%.2d\n", tspan_break.year, tspan_break.day, tspan_break.hour, tspan_break.minute, tspan_break.second ); fprintf( D_OUT, "ntspan = %d, nlvol = %d\n", ntspan, nlvol ); n = nlvol; tp = Tspan_head; nt = ntspan; lp = tp->start; while( n-- ) { if( tp != NULL ) { if( tp->start == lp ) { nt--; fprintf( D_OUT,"tspan %d, %d nodes\n", ntspan-nt, tp->count ); tp = tp->next; } } fprintf( D_OUT, "%.5s %.3s %d %d", lp->scan.station, lp->scan.channel, lp->start_offset, lp->end_offset ); print_time( " ", &lp->scan.time ); print_time( " ", &lp->endtime ); lp = lp->next; } }/* * make all the control headers: volume, abbreviation, station, time span */ if( (err=make_headers( nlvol, ntspan, Lvol_head, Tspan_head, volume_break, tspan_break, start_volume, end_volume, &count )) ) if( (err=error_handler( FATAL, "[flush_output_volume] make_headers")) ) return( err ); hp = Headers_head; /* get headers listhead *//* * output the volume, abbreviation, station control headers */ hp = output_vas( file, hp, &err ); if( err ) if( (err=error_handler( FATAL, "[flush_output_volume] output_vas" )) ) return( err );/* * for SEED v2.0, timespan and data are interspersed, * for later versions, the timespans are all at the front. * * while more time-span headers to do, output tspan headers, * output data segments, advance both lists. Count the counters * down just as a consistency check; all lists and counts should * finish at the same place! */ tp = Tspan_head; /* get tspan hdrs listhead */ if((SEED_Version == 20) && Write_Data) { while( hp != NULL ) { hp = output_tspan( file, hp, &err ); if( err ) if( (err=error_handler( FATAL, "[flush_output_volume] output_tspan" )) ) return( err ); if( (err = output_data( file, tp->count, tp->start )) ) if( (err=error_handler( FATAL, "[flush_output_volume] output_data" )) ) return( err ); nlvol -= tp->count; ntspan--; tp = tp->next;/* * as a special case, there may be an empty tspan node at the end of * a volume. This can happen if data was requested, but not found in * the desired windows. tp->count == 0, and tp->start == NULL, so * such timespan nodes *must not* be referenced. */ while( tp != NULL && tp->count == 0 ) { tp = tp->next; ntspan--; } } } else if (Write_Data) /* tspans are at front, data at end of volume */ { nt = ntspan; while( hp != NULL ) /* for each tspan record */ { hp = output_tspan( file, hp, &err ); /* all at once */ if( err ) if( (err=error_handler( FATAL, "[flush_output_volume] output_tspan" )) ) return( err ); nt--; } if( nt != 0 ) if( (err=error_handler( FATAL, "[flush_output_volume] ntspan != no. of TS logrecs")) ) return( err ); while( tp != NULL ) { if( (err = output_data( file, tp->count, tp->start )) ) if( (err=error_handler( FATAL, "[flush_output_volume] output_data" )) ) return( err ); nlvol -= tp->count; ntspan--; tp = tp->next; while( tp != NULL && tp->count == 0 ) /* empty TS? */ { tp = tp->next; ntspan--; } } } if( (nlvol != 0) && Write_Data) if( (err=error_handler( FATAL, "[flush_output_volume] nlvol not zero")) ) return( err ); if( (ntspan != 0) && Write_Data) if( (err=error_handler( FATAL, "[flush_output_volume] ntspan not zero")) ) return( err ); }/* * all timespans have been output. Logical volume is finished. * flush to a physical record boundary, and (?) write eof's. */ (void) put_logrec( file, junk, 0, 2, &err ); if( err ) if( (err=error_handler( WARNING,"[flush_output_volume] flush volume")) ) return err; if( Debug >= D_MIN ) fprintf( D_OUT,"[flush_output_volume] end\n" ); return( INFO );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -