;+ ; NAME: ; smei_mkorb_auto ; PURPOSE: ; Wrapper for smei_mkorb for creating "on-the-fly" orbital ; patterns. Used in real-time data pipeline only. ; CATEGORY: ; camera/idl/toolbox ; CALLING SEQUENCE: PRO smei_mkorb_auto, $ threshold = threshold , $ ignore_block= ignore_block , $ force = force ; OPTIONAL INPUT PARAMETERS: ; threshold passed to smei_mkorb ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; smei_filepath, TimeUnit, FindAllFiles, txt_read ; TimeGet, TimeOp, smei_filename, boost, smei_orbit_get ; smei_mkorb, smei_last_tle ; RESTRICTIONS: ; Can only be run on the SMEI servers (smei.ucsd.edu or smeidb.smei.ucsd.edu) ; PROCEDURE: ; MODIFICATION HISTORY: ; DEC-2008, Paul Hick (UCSD/CASS) ; DEC-2009, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; Allow for execution on smeidb ;- hostname = getenv('HOSTNAME') is_remote = hostname NE 'smei.ucsd.edu' IF smei_blocked(ignore_block=ignore_block) THEN $ RETURN sts_dir = smei_filepath(mode='sts') uday = TimeUnit(/day) last_tle = TimeGet(/_ydoy,smei_last_tle(),upto=uday) ; Time of last Coriolis TLE cam_int = 3 cam_str = strcompress(cam_int,/rem) ; Find all c3sts files in $SSWDB_SMEI/cat/sts sts_files = FindAllFiles('c'+cam_str+'sts_*.txt',paths=sts_dir, count=count) IF count EQ 0 THEN $ ; No files; do next camera RETURN istart = -1 istop = -1 FOR ists=count-1,0,-1 DO BEGIN ; Process reverse chronological sts_file = sts_files[ists] sts_hide = hide_env(sts_file) IF txt_read(sts_file,txt,/silent) NE 1 THEN $ continue ; Check "orb" field. If "orb=1", there already is an "on-the-fly" pattern. cstr = 'orb :' orb_ok = fix( strmid( txt[where( strpos(txt,cstr) EQ 0 )], strlen(cstr) ) ) ; Process status files (reverse chronological) until one is ; encountered where the "on-the-fly" pattern already exists. IF orb_ok THEN $ break cstr = 'frames :' nframes = fix(strmid(txt[where(strpos(txt,cstr) EQ 0)],strlen(cstr))) IF nframes EQ 0 THEN $ continue ; No frames; skip to next file cstr = 'base :' base_ok = fix(strmid(txt[where(strpos(txt,cstr) EQ 0)],strlen(cstr))) IF NOT base_ok THEN $ continue ; Ped/dark not available; skip cstr = 'summary :' summary_ok = fix(strmid(txt[where(strpos(txt,cstr) EQ 0)],strlen(cstr))) IF NOT summary_ok THEN $ continue ; Summary not available; skip IF TimeGet(/_ydoy,smei_filename(sts_file),upto=uday) GE last_tle THEN BEGIN message, /info, sts_hide+', TLE not yet past this day' continue ; TLE not yet past this day ENDIF message, /info, sts_hide ; Calculate "on-the-fly" patterns for all doys between istop and istart ; istop : most recent day already run through smei_base, but with ; no on-the-fly patterns available ; istart: most recent day already run through smei_base, bith with ; on-the-fly patterns available already. ; (this is the doy preceding the doy that forces a break ; out of the loop above IF istop EQ -1 THEN istop = ists istart = ists ; Check "cal" field. If cal=1 then there is a "closed-shutter" ; cal pattern available for this doy. ; Collect the names of the cal patterns in 'cal_pat'; and the ; integer orbit numbers for the time of the cal pattern ; in 'cal_orb'. cstr = 'cal :' cal_ok = fix(strmid(txt[where(strpos(txt,cstr) EQ 0)],strlen(cstr))) IF cal_ok THEN BEGIN tt = TimeGet(/_ydoy,smei_filename(sts_file),upto=uday) tt = filepath(root=smei_filepath(mode='cal'),'c3cal_'+tt+'*.fts.gz') cal_file = (file_search(tt))[0] IF cal_file EQ '' THEN $ message, 'should have found a calibration pattern '+tt message, /info, hide_env(cal_file) tt = smei_filename(cal_file) boost, cal_pat, cal_file ; File names of cal patterns boost, cal_orb, smei_orbit_get(TimeGet(/smei,tt),/number) ; Orbit nrs of cal patterns ENDIF ; Collect names of status files for the doys for which ; "on-the-fly" patterns need to be calculated. boost, sts_done, sts_file ENDFOR IF istop EQ -1 THEN BEGIN message, /info, 'no sts file with "base" and "summary" flags "on" found for cam '+cam_str RETURN ENDIF IF istart EQ -1 THEN BEGIN message, /info, 'no sts file with "base" and "summary" flags "on" and "orb" flag "off" found for cam '+cam_str RETURN ENDIF ; Time range from start of doy for status file istart, to ; end of doy for status file istop. tt = smei_filename(sts_files[[istart,istop]]) tt[1] = TimeOp(/add,tt[1],TimeSet(/diff,1,uday)) ; List of orbit numbers. ; Note that the first orbit starts before the start of the ; time range, and the last orbit ends after the end of ; the time range. orbs = smei_orbit_get(TimeGet(/smei,tt),/number) FOR i=0,n_elements(cal_orb)-1 DO BEGIN ; Loop over all "closed-shutter" cal patterns IF cal_orb[i] GT orbs[0] THEN BEGIN suborbs = [orbs[0],cal_orb[i]-1] message, /info, 'orbits '+strjoin(strcompress(suborbs,/rem),' - ') smei_mkorb, $ lastpat = 1 , $ firstorb = suborbs[0], $ lastorb = suborbs[1], $ truncpat = cal_pat[i], $ threshold = threshold , $ force = force , $ /filecmd , $ /generate ENDIF orbs = [cal_orb[i],orbs[1]] ENDFOR IF orbs[1] GE orbs[0] THEN BEGIN suborbs = orbs message, /info, 'orbits '+strjoin(strcompress(suborbs,/rem),' - ') smei_mkorb, $ lastpat = 0 , $ firstorb = suborbs[0], $ lastorb = suborbs[1], $ threshold = threshold , $ force = force , $ /generate ENDIF FOR i=0,n_elements(sts_done)-1 DO BEGIN sts_file = sts_done[i] sts_time = smei_filename(sts_file) ; No frames have been modified, so there is no need ; to recreate the hdr files. We do want to force a redraw ; of the png files to include the new "on-the-fly" info. smei_hdr_update, sts_time, camera=cam_int, /plot, /force ENDFOR ; Set "orb" flag in status files FOR i=0,n_elements(sts_done)-1 DO BEGIN sts_file = sts_done[i] sts_hide = hide_env(sts_file) IF NOT txt_read(sts_file,txt,/silent) THEN $ continue txt[where(strpos(txt,'orb :') EQ 0)] = 'orb : 1' message, /info, sts_hide+', set "orb" field' CASE is_remote OF 0: BEGIN openw, /get_lun, iu, sts_file FOR j=0,n_elements(txt)-1 DO printf, iu, txt[j] free_lun, iu END 1: BEGIN txt = strjoin(txt,string(10B)) ; 10B = new line spawn, 'echo "'+txt+'" | ssh soft@smei "cat - > '+sts_file+'"' END ENDCASE ENDFOR IF IsType(sts_done,/undefined) THEN $ message, /info, '"orb" field nowhere updated' RETURN & END