PRO vu_update_hours, kind, filter=filter, nday_future=nday_future, nday_past=nday_past, $ hour_step=hour_step, triangle=triangle, setbad=setbad, silent=silent, rounds=rounds, $ gzip=gzip ;+ ; NAME: ; vu_update_hours ; PURPOSE: ; Update the set of available final tomography files ; (usually called when a new raw tomography files has been created) ; CATEGORY: ; WWW ; CALLING SEQUENCE: ; vu_update_hours, kind, nday=nday ; INPUTS: ; kind scalar; type: string; default: 'slow' ; 'slow' or 'fast' ; OPTIONAL INPUT PARAMETERS: ; filter=filter scalar; type: string; default: 'nv3d' ; type of tomography files ('nv3d' or 'wson') ; (*.* is appended if not present yet) ; hour_step scalar; type: integer; default: 2 ; time step between averaged output files in hours ; nday_past=nday_past ; scalar; type: integer; default: 2 ; nday_future=nday_future ; scalar; type: integer; default: 2 ; final (averaged) files are created up to nday_future days ; after the time of the last raw tomography file ; ; /gzip compresses output files with gzip ; /silent suppresses messages from vu_new_time ; Keywords passed to href=vu_new_time=: ; ; triangle=triangle ; /setbad ; OUTPUTS: ; (updated and new final tomography files) ; INCLUDE: @compile_opt.pro ; On error return to caller ; CALLS: ; vu_select, vu_new_time, TimeOp, TimeSet, TimeUnit, CarringtonT ; InitVar, IsBadTime, vu_prefix ; PROCEDURE: ; > The last raw tomography file is identified by looking for all ; filter+*.* files in directory root = $NAGOYA/kind ; The list of files is sorted, and the last file on the sorted list is ; assumed to be the most recent raw tomography file. ; > The final (averaged) tomography files are assumed to be located in ; dest = filepath(root=root, subdir='final', '') ; > First all final (averaged) tomography files that are affected by the new tomography ; file are updated (by overwriting them). Then a number of new final files are ; created by extending the range of final files to at most 3 days beyond the time of ; the new tomography file. ; MODIFICATION HISTORY: ; APR-2000, Paul Hick (UCSD/CASS) ; SEP-2001, Paul Hick (UCSD/CASS) ; The max # of new files was limited to cover nday=nday_past+nday_future days, ; starting from the last final file found in directory 'dest'. ; This prevented automatic recovery from a big gap in the production of raw ; tomography files (as happened in August 2001). Problem was fixed by centering ; the range of 'nday' days on the time of the last raw tomography file found in 'root'. ; SEP-2002, Paul Hick (UCSD/CASS) ; Fixed bug which prevented processing of anything other than 'nv3d' files ; NOV-2003, Paul Hick (UCSD/CASS) ; Added /gzip keyword. ; NOV-2005, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; Made sure that the start time for a new sequence of final files ; always starts at a multiple of hour_step hours into the day. ;- ; Number of hours between averaged files, i.e. to write hourly final files set hour_step=1; ; for bi-hourly files set hour_step=2 InitVar, hour_step , 2 InitVar, nday_past , 2 InitVar, nday_future, 2 InitVar, kind , 'slow' InitVar, filter , vu_prefix(/silent,fast=kind EQ 'fast') uhour = TimeUnit(/hour) IF strpos(filter,'*.*') EQ -1 THEN filter = filter+'*.*' root = filepath(root=getenv('NAGOYA'), kind) dest = filepath(root=root, subdir='final', '') ; Location of final files ; Get list of raw tomography files tmp = filepath(root=root, subdir='raw', filter) file = file_search(tmp, count=count) IF file[0] EQ '' THEN BEGIN message, /info, 'no raw files '+tmp RETURN ENDIF file = (file[sort(file)])[count-1] ; Last (most recent) raw tomography file ut_raw = vu_select(file,/nohdr,rounds=rounds) ; Extract time from file name IF IsBadTime(ut_raw) THEN BEGIN message, /info, 'bad file name: '+file RETURN ENDIF ; Files within a certain time window from 'ut_raw' (as define by 'triangle') ; need to be updated or created fresh. ; Update existing final tomography files near time 'ut_raw' by overwriting them vu_new_time, ut_raw, /update, dest=dest, filter=filter, $ triangle=triangle, setbad=setbad, silent=silent, gzip=gzip file = file_search(filepath(root=dest, filter), count=count) ; If there are no final files yet we pretend there is one with a time that ; preceeds the new tomography by nday_past days. CASE file[0] OF '': BEGIN message, /info, 'no final files yet' ut_hr = TimeOp(/add, ut_raw, TimeSet(/diff,day=-nday_past)) ut_hr = TimeGet(ut_hr,roundt=hour_step,uhour) END ELSE: BEGIN file = (file[sort(file)])[count-1] ; Last (most recent) final tomography file ut_hr = vu_select(file, /nohdr, rounds=rounds) ; Extract time from file name END ENDCASE ; Create new final tomography files ; ut_raw is the time of the last raw t3d file, ut_hr is the time of the last ; final file. We want the final files to extend nday_future days past ut_raw, ; so we need to fill the gap between ut_hr and ut_raw = ut_raw + nday_future ut_raw = TimeOp(/add, ut_raw, TimeSet(/diff,day=nday_future)) ut_raw = TimeGet(ut_raw, /roundt, hour=hour_step) ; Round to nearest hour_step interval ; # new files needed nhr = round(TimeOp(/subtract,ut_raw,ut_hr,uhour)/hour_step) IF nhr GT 0 THEN BEGIN ; Set up the array of times 'ut' for which final files are needed. This array ; covers ut_hr+hour_step to ut_raw in steps of 'hour_step' hours. ; The # new files to be created is limited to nday_past days before to ; nday_future days past ut_raw. ut = nhr < (nday_past+nday_future)*(24/hour_step) ut = hour_step*( (0 > (nhr-ut))+1+indgen(ut) ) ut = TimeOp(/add, ut_hr, TimeSet(/diff,hour=ut)) ; Create the new averaged files vu_new_time, ut, dest=dest, filter=filter, $ triangle=triangle, setbad=setbad, silent=silent, gzip=gzip ENDIF RETURN & END