;+ ; NAME: ; vu_update_marker ; PURPOSE: ; Update set of 'best' tomography files at regular time intervals ; (at the same time cadence used by the Fortran tomography itself) ; by incorporating results of new tomography run. ; CATEGORY: ; Tomography I/O ; CALLING SEQUENCE: PRO vu_update_marker, prefix, $ silent = silent , $ rounds = rounds , $ gzip = gzip , $ final_destination = final_destination, $ last_is_best = last_is_best ; INPUTS: ; prefix scalar; type: character; default: 'nv3d' ; file name prefix for data files ; (typical values are 'nv3d','nv3f','wson','nson' ; OPTIONAL INPUTS: ; /last_is_best if set, the the last tomography run is taken ; as the best one, i.e. it is not combined with ; earlier runs using some weighted mean. ; final_destination=final_destination ; scalar; type: character; default: 'final' ; subdirectory in $NAGOYA where the 'best' ; files are written ; silent=silent suppresses messages from vu_write ; /gzip compresses output files with gzip (passed to vu_write) ; OUTPUTS: ; (written to new tomography data files) ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; InitVar, vu_mean, vu_select, vu_write, TimeOp, TimeGet, TimeUnit ; Carrington, forecast_cfg, vu_set, vu_prefix, say ; PROCEDURE: ; > Input files are picked up from directory $NAGOYA/fast/raw ; Output files are written to $NAGOYA/fast/final (or the subdirectory ; specified in keyword 'final_destination'. ; ; > The procedure is run after a new time-dependent forecast has been ; made. All output files from the last tomography (one for each time) ; are integrated with the averages from results from previous runs ; including the same times. ; ; > vu_select is called with keywords /marker and /nohdr set, i.e. ; only files with a rotation counter are picked up, and the file names ; are returned without actually reading the headers. ; MODIFICATION HISTORY: ; MAR-2001, Paul Hick (UCSD/CASS) ; NOV-2003, Paul Hick (UCSD/CASS) ; Added /gzip keyword. ; JUL-2011, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; Added keyword 'final_destination' ;- InitVar, silent, 0 InitVar, prefix, vu_prefix(/silent,/fast) filter = prefix+'*.*' uday = TimeUnit(/day) root = filepath(root=getenv('NAGOYA'),'fast') ; Get a list of all raw tomography files. ; Get all times from the file names (don't read the headers). ; The time-dependent raw files are produced exactly at integer hours. ; This precision gets lost when writing Carrington times into the header. ; We restore the precision here by rounding times to the nearest hour ; (using the rounds keyword). The correction could be as large as 8 minutes. raw_times = vu_select(raw_files, $ path = filepath(root=root, 'raw') , $ filter = filter , $ /marker , $ /nohdr , $ imark = imark , $ count = raw_cnt , $ rounds = rounds ) IF raw_cnt EQ 0 THEN BEGIN say, 'no raw tomography files', threshold=1, silent=silent RETURN ENDIF ; The last raw file should be the last time from the last tomography run. last_file = raw_files[raw_cnt-1] last_marker = imark[raw_cnt-1] say, 'last run: '+hide_env(last_file), threshold=1, silent=silent ; Find all files with the same marker. These are the files created during ; the last tomography run. These files need to be incorporated into the final ; averages. Get a list of times from the file names. last_run = where(imark EQ last_marker, cnt) files = raw_files[last_run] times = raw_times[last_run] ; For the time-dependent tomography final files are produced at the same ; cadence as the raw files. InitVar, last_is_best, /key InitVar, final_destination, 'final' destination = filepath(root=root, final_destination) FOR i=0,cnt-1 DO BEGIN ; Loop over all files with highest marker value time = times[i] ; Find all raw files with the same time (the markers will be ; different). These files need to be combined. ; If last_is_best is set then only use the file from the last run ; (this effectively makes the final file a copy of the raw file. CASE last_is_best OF 0: raw_mark = where(TimeOp(/subtract,raw_times,time,uday) EQ 0, mark_cnt) 1: BEGIN raw_mark = last_run[i] mark_cnt = 1 END ENDCASE IF mark_cnt NE 0 THEN BEGIN ; Read the files with the same time (and different markers) raw_hdr = vu_select(raw_files[raw_mark], $ /marker , $ /check , $ /read , $ silent = silent+1 , $ ff = ff , $ /get_full , $ count = mark_cnt , $ rounds = rounds ) say, 'got '+strcompress(mark_cnt, /rem)+' files @ '+ $ TimeGet(time, /ymd, upto=TimeUnit(/minute))+ $ ' ('+string(Carrington(time),format=forecast_cfg(/crformat))+')', threshold=1, silent=silent IF mark_cnt NE 0 THEN BEGIN ; For now give every file the same weight. ; This really should be something that tapers for earlier runs. ww = replicate(1, mark_cnt) ret_hdr = vu_mean(raw_hdr, ff, ww, /marker, ff_mean=ff_mean, userinfo=userinfo) ret_hdr = vu_set(ret_hdr, uttime=time) ; Ensure overwriting existing files ret_hdr = vu_set(ret_hdr, ntim=1) ret_hdr = vu_set(ret_hdr, time_index=1) vu_write, ret_hdr, ff_mean, $ userinfo = userinfo , $ destination = destination , $ silent = silent , $ gzip = gzip ENDIF ENDIF ENDFOR RETURN & END