;+ ; NAME: ; smei_hdr_update ; PURPOSE: ; Update Fits binary tables containing SMEI frm headers or time series plots based ; on Fits binary tables. ; CATEGORY: ; camera/idl/frm ; CALLING SEQUENCE: PRO smei_hdr_update, tt , $ source = source , $ pscmd = pscmd , $ destination = destination , $ camera = camera , $ silent = silent , $ all = all , $ drive = drive , $ update = update , $ tplot = tplot , $ force = force , $ remote = remote ; INPUTS: ; tt array[2]; type: time structure ; time range to be updated ; OPTIONAL INPUT PARAMETERS: ; all=all if set the whole SMEI data base is updated (overrides 'tt') ; drive=drive scalar; type: integer ; if set the corresponding drive is processed (overrides 'tt' and /all) ; source=source scalar; type: string; default: SMEIDC? ; directory indicating source of SMEI data frames (parameter is ; passed to href=smei_filepath=) ; (usually SMEIDB? or SMEIDC?) ; destination=destination ; scalar; type: string; default: $SSWDB_SMEI/cat/hdr ; directory where Fits binary tables are stored ; remote=remote scalar; type: string; default: none ; if present, is combined with destination to build ; the destination as : ; (usually "remote" is set to the computer hosting ; the header database when this routine is executed ; on another computer; passed to smei_hdr_make and ; smei_hdr_plot) ; camera=camera scalar or array[n]; type: integer; default: [1,2,3] ; cameras to be updated ; /tplot if set the time series plots base on the Fits binary tables ; are updated ; /force will unconditionally update Fits tables or png files ; silent=silent suppresses informational messages if set to > 0 ; OUTPUTS: ; (updated Fits binary tables. ; OPTIONAL OUTPUT PARAMETERS: ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; InitVar, TimeUnit, TimeSet, TimeGet, TimeSystem, IsType, TimeOp ; FindAllFiles, smei_filepath, smei_hdr_make, hide_env, timeposn ; PROCEDURE: ; MODIFICATION HISTORY: ; AUG-2005, Paul Hick (UCSD/CASS) ; OCT-2006, Paul Hick (UCSD/CASS) ; Added pscmd keyword ; FEB-2007, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; Default destinations are now set through calls to ; smei_filepath instead of hardcoding them here. ;- IF IsType(pscmd,/string) THEN IF is_running(pscmd) THEN RETURN InitVar, tplot , /key InitVar, camera, [1,2,3] InitVar, force , /key InitVar, update, /key InitVar, silent, 0 uday = TimeUnit(/day) usec = TimeUnit(/sec) CASE tplot OF 0: BEGIN InitVar, source, 'SMEIDC?' InitVar, destination, smei_filepath(mode='hdr') END 1: BEGIN InitVar, source , smei_filepath(mode='hdr') InitVar, destination, smei_filepath(mode='png') END ENDCASE CASE 1 OF IsType(drive, /defined ): tt = smei_frm_drive(drive) IsType(all , /defined ): tt = [TimeSet('2003_033'),TimeGet(TimeSystem(/silent),/eot, uday)] IsType(tt , /string ): tt = TimeSet(tt) update: BEGIN tt = file_search( destination ) IF tt[0] EQ '' THEN BEGIN message, /info, 'no files in '+destination RETURN ENDIF tt = timeposn(tt,/extract,part='name') tt = TimeOp(/subtract,TimeLimits(tt,/max),TimeSet(/diff,3,uday)) tt = [tt,TimeGet(TimeSystem(/silent),/eot,uday)] END IsType(tt, /undefined): BEGIN message, /info, 'no time range specified' RETURN END ELSE: ENDCASE IF n_elements(tt) EQ 1 THEN trange = [tt, TimeOp(/add, tt, TimeSet(/diff,day=1))] ELSE trange = tt[0:1] t0 = TimeGet(trange[0], /bot, uday) t1 = TimeGet(trange[1], /bot, uday) ndays = TimeOp(/subtract,t1,t0,uday)+(TimeOp(/subtract,t1,trange[1],usec) NE 0) ncam = n_elements(camera) CASE tplot OF 0: BEGIN FOR iday=0L,ndays-1 DO BEGIN ; Loop over all requested days day = TimeOp(/add, t0, TimeSet(/diff, iday, uday)) FOR icam=0,ncam-1 DO BEGIN ; Loop over cameras cam = camera[icam] paths = smei_filepath(day,camera=cam,source=source) files = FindAllFiles(paths=paths,/forcecd, count=count) CASE count GT 0 OF 0: IF silent LE 0 THEN message, /info, 'no files in '+hide_env(paths) 1: BEGIN ; Check the binary Fits table. The file is refreshed if ; - it doesn't exist yet ; - it exists but there is a frame with modification time more ; recent than the binary table ; - if exists but the number of frames in the Fits header does not ; match the number of files in the SMEI data base hdr_file = filepath(root=destination,'c'+strcompress(cam,/rem)+ $ 'hdr_'+TimeGet(day,/_ydoy,upto=uday))+'.fts' refresh = force IF NOT refresh THEN refresh = (file_search(hdr_file)) EQ '' CASE refresh OF 0: BEGIN hdr_count = fxpar(headfits(hdr_file, silent=silent),'NFRAME',count=tmp) refresh = hdr_count NE count CASE refresh OF 0: BEGIN hdr_time = (file_info(hdr_file,/noexpand_path)).mtime frm_time = max( (file_info(files ,/noexpand_path)).mtime, frm_max ) refresh = hdr_time LT frm_time IF refresh THEN BEGIN hdr_time = TimeOp(/add, TimeSet('1970/01/01'),TimeSet(/diff,hdr_time,usec)) frm_time = TimeOp(/add, TimeSet('1970/01/01'),TimeSet(/diff,frm_time,usec)) IF silent LE 1 THEN message, /info, $ hide_env(files[frm_max])+'@'+TimeGet(frm_time,/_ydoy,upto=usec)+ $ ' more recent than '+hide_env(hdr_file)+'@'+TimeGet(hdr_time,/_ydoy,upto=usec) ENDIF END 1: IF silent LE 1 THEN message, /info, $ strcompress(count,/rem)+' frames in '+hide_env(paths )+', but'+ $ strcompress(hdr_count )+' frames in '+hide_env(hdr_file) ENDCASE END 1: IF silent LE 1 THEN message, /info, hide_env(hdr_file) ENDCASE CASE refresh OF 0: IF silent LE 0 THEN message, /info, 'not needed for '+hide_env(hdr_file) 1: smei_hdr_make, day, camera=cam, source=source, destination=destination, /overwrite, remote=remote ENDCASE END ENDCASE ENDFOR ENDFOR END 1: BEGIN FOR iday=0L,ndays-1 DO BEGIN ; Loop over all requested days day = TimeOp(/add, t0, TimeSet(/diff, iday, uday)) FOR icam=0,ncam-1 DO BEGIN ; Loop over cameras cam = camera[icam] hdr_file = filepath(root=source,'c'+strcompress(cam,/rem)+ $ 'hdr_'+TimeGet(day,/_ydoy,upto=uday))+'.fts' CASE (file_search(hdr_file)) NE '' OF 0: IF silent LE 0 THEN message, /info, hide_env(hdr_file)+' does not exist' 1: BEGIN png_file = filepath(root=destination,'c'+strcompress(cam,/rem)+ $ 'png_'+TimeGet(day,/_ydoy,upto=uday))+'.png' refresh = force IF NOT refresh THEN refresh = (file_search(png_file)) EQ '' CASE refresh OF 0: BEGIN hdr_time = (file_info(hdr_file,/noexpand_path)).mtime png_time = (file_info(png_file,/noexpand_path)).mtime refresh = png_time LT hdr_time IF refresh THEN BEGIN hdr_time = TimeOp(/add, TimeSet('1970/01/01'),TimeSet(/diff,hdr_time,usec)) png_time = TimeOp(/add, TimeSet('1970/01/01'),TimeSet(/diff,png_time,usec)) IF silent LE 1 THEN message, /info, $ hide_env(hdr_file)+'@'+TimeGet(hdr_time,/_ydoy,upto=usec)+ $ ' more recent than '+hide_env(png_file)+'@'+TimeGet(png_time,/_ydoy,upto=usec) ENDIF END 1: IF silent LE 1 THEN message, /info, hide_env(png_file) ENDCASE CASE refresh OF 0: IF silent LE 0 THEN message, /info, 'not needed for '+hide_env(png_file) 1: smei_hdr_plot, day, camera=cam, source=source, destination=destination, remote=remote ENDCASE END ENDCASE ENDFOR ENDFOR END ENDCASE RETURN & END