;+ ; NAME: ; forecast_ice ; PURPOSE: ; Moves old output files from the tomography to a backup ; directory to avoid problems with the IDL findfile functions ; when lots of file accumulate in a directory. ; CATEGORY: ; pro/tool ; CALLING SEQUENCE: PRO forecast_ice, kind, ut=ut, delta_ut=delta_ut, create_dir=create_dir, silent=silent ; INPUTS: ; kind scalar; type: string ; 'slow' or 'fast' for corotating and time- ; dependent tomography only ; OPTIONAL INPUT PARAMETERS: ; ut=ut scalar; type: float; default: TimeSystem(7) ; array[1]; type: time structure ; current time as float Carrington time ; or time structure ; delta_ut=delta_ut ; scalar; type: float ; array[1]; type: time difference structure ; time difference with 'ut' in days ; or specified as time difference structure. ; files older than ut+delta_ut are ; moved out of the way. Note that ; delta_ut is a negative offset. ; /create_dir files are moved to a subdirectory 'ice'. ; If this directory does not exist and this keyword ; is set then the directory is created. ; OUTPUTS: ; (none) ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; InitVar, TimeSystem, TimeSet, forecast_cfg, CheckDir, boost ; Carrington, destroyvar, FindAllFiles, vu_select, do_file, TimeOp ; Carrington ; RESTRICTIONS: ; File times are determined from their file names by running the ; file name through vu_select. This procedure expects to find ; a Carrington time in the file name in format '(F9.4)'. ; PROCEDURE: ; Subdirectories 'raw' and 'final' are checked. ; MODIFICATION HISTORY: ; SEP-2002, Paul Hick (UCSD/CASS) ; NOV-2002, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; Added keyword /forcecd to FindAllFiles calls ;- InitVar, kind , 'slow' InitVar, ut , TimeSystem( forecast_cfg(/local2ut), /silent ) InitVar, delta_ut , -28;-7 InitVar, create_dir , /key InitVar, silent , /key IF NOT IsTime(delta_ut) THEN delta_ut = TimeSet(day=delta_ut) ut_cutoff = Carrington( TimeOp(/add, Carrington(ut,/get_time), delta_ut )) InitVar, root, forecast_cfg(kind, /root) boost, src_dir, filepath(root=root, subdir=[kind, 'raw' ], '') boost, src_dir, filepath(root=root, subdir=[kind, 'final'], '') filter4 = ['nv3d','nv3f','wson','nson'] filter3 = ['ea_','e3_'] ice_subdir = 'ice' FOR i=0, n_elements(src_dir)-1 DO BEGIN path = src_dir[i] ; Make sure the destination directory exists dest_path = filepath(root=src_dir[i], subdir=ice_subdir,'') dir_exists = CheckDir(dest_path) IF NOT dir_exists AND create_dir THEN BEGIN ; Try to create the directory if it doesn't exist spawn, 'mkdir '+dest_path dir_exists = CheckDir(dest_path) CASE dir_exists OF 0: message, /info, 'failed to create directory: '+dest_path 1: message, /info, 'directory created: '+dest_path ENDCASE ENDIF CASE dir_exists OF 0: message, /info, 'directory does not exist: '+dest_path 1: BEGIN ; Find all files earlier than ut_cutoff files4 = FindAllFiles(filter4+'*.*', path=path, count=cnt4,/forcecd) IF cnt4 GT 0 THEN early4 = vu_select(files4, /nohdr, count=cnt4) files3 = FindAllFiles(filter3+'*.*', path=path, count=cnt3,/forcecd) IF cnt3 GT 0 THEN early3 = vu_select(files3, /nohdr, count=cnt3, prefix=3) cnt = cnt4+cnt3 destroyvar, early, files IF cnt4 GT 0 THEN BEGIN boost, early, Carrington(early4) boost, files, files4 ENDIF IF cnt3 GT 0 THEN BEGIN boost, early, Carrington(early3) boost, files, files3 ENDIF IF cnt GT 0 THEN early = where(early LT ut_cutoff, cnt) IF cnt GT 0 THEN BEGIN files = files[early] FOR f=0,cnt*dir_exists-1 DO stat = do_file(/move, files[f], dest_path, silent=silent) ENDIF END ENDCASE ENDFOR RETURN & END