;+ ; NAME: ; smei_mkcal_auto ; PURPOSE: ; CALLING SEQUENCE: PRO smei_mkcal_auto, $ camera = camera , $ lastpat = lastpat , $ ignore_block=ignore_block, $ force = force ; OPTIONAL INPUTS: ; camera = camera scalar or array; type: integer; default [1,2,3] ; camera number(s): 1, 2 and/or 3 ; lastpat = lastpat scalar; type: integer; default: 0 ; indicates the number of status files to be ; checked starting from the most recent one. ; Special values: ; lastpat = -1: check all status files ; lastpat = 0: check all status files, starting ; with the status file matching the doy ; for the most recent cal pattern available ; (used in SMEI data pipeline) ; /ignore_block passed to href=smei_blocked ; INCLUDE: @compile_opt.pro ; CALLS: ; smei_blocked, smei_filepath, TimeUnit, TimeGet, smei_last_tle ; FindAllFiles, txt_read, hide_env, smei_filename, CheckDir ; smei_filepath, smei_mkcal ; RESTRICTIONS: ; Can only be run on smei.ucsd.edu and smeidb.smei.ucsd.edu ; PROCEDURE: ; Sets "cal = 1" field in status file if cal pattern is successfully generated. ; The "cal" field is always zero if the "mode 0" frame count is zero. ; ; If the "mode 0" count is non-zero then "cal=0" means that the calibration ; pattern for the set of mode 0 frames on this doy has not been created ; yet. "cal=1" means that the cal patterns already exists. ; ; This routine is usually run as a cronjob with keyword ; lastpat=0. This looks for the most recent status file with ; "cal=1" (pointing to the most recent existing cal pattern). It then ; processes status files from that doy onward looking for status files ; with a non-zero "mode 0" frame count and "cal=0". It the creates the ; calibration pattern, and updates the status file by setting "cal=1". ; MODIFICATION HISTORY: ; MAR-2009, Paul Hick (UCSD/CASS) ; DEC-2009, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; Also allow execution from smeidb. ; Added documentation. ;- InitVar, camera, [1,2,3] InitVar, lastpat, 0 hostname = getenv("HOSTNAME") is_remote = hostname NE 'smei.ucsd.edu' IF smei_blocked(ignore_block=ignore_block) THEN $ RETURN ; Set directories for status files in $SSWDB_SMEI cat_dir = smei_filepath(mode='cat') sts_dir = smei_filepath(mode='sts') cal_dir = smei_filepath(mode='cal') uday = TimeUnit(/day) usec = TimeUnit(/sec) last_tle = TimeGet(/_ydoy, smei_last_tle(), upto=uday) FOR icam=0,n_elements(camera)-1 DO BEGIN cam_int = camera[icam] cam_str = strcompress(cam_int,/rem) sts_files = FindAllFiles('c'+cam_str+'sts_*.txt',paths=sts_dir, count=count) IF count EQ 0 THEN $ ; No files; do next camera continue CASE 1 OF lastpat LT 0: last = count ; Check all status files lastpat EQ 0: BEGIN ; Check from last cal pattern forward ; (this is used in the smei pipeline) last = count ; Search for most recent calibration patterns FOR ists=count-1,0,-1 DO BEGIN ; Reverse chronological sts_file = sts_files[ists] ; If read fails, stop. Probably no read access of something equally disastrous IF txt_read(sts_file,txt,/silent) NE 1 THEN BEGIN last = 0 break ENDIF ; Are there "mode 0" frames available. If not, skip to next file cstr = 'mode 0 :' nframes = long(strmid(txt[where(strpos(txt,cstr) EQ 0)],strlen(cstr))) IF nframes EQ 0 THEN $ continue ; No mode 0 frames ; There are "mode 0" frames in this doy. ; The "cal" field indicates whether the cal pattern for this set of ; "mode 0" frames has been created yet. ; We are looking for a doy with "cal=1". This indicates the most ; recent cal pattern. cstr = 'cal :' cal_ok = fix(strmid(txt[where(strpos(txt,cstr) EQ 0)],strlen(cstr))) ; If cal=0, then the cal pattern for this set of "mode 0" ; frames has not been created yet. Skip to next file; keep looking ; "cal=1" IF NOT cal_ok THEN $ continue ; Found "cal=1". This is the doy with the most recent cal pattern. last = count-ists-1 message, /info, hide_env(sts_file)+', last cal pattern' break ENDFOR message, /info, 'process '+strjoin(strcompress([last,count],/rem),'/')+' sts files' END ELSE: last = lastpat < count ENDCASE ; Create cal patterns FOR ists=(count-last) > 0,count-1 DO BEGIN sts_file = sts_files[ists] sts_hide = hide_env(sts_file) sts_time = smei_filename(sts_file) ; PPH: Can't think of any reason why the TLE matters for the calibration patterns, ; so commented out ; Make sure not to move past the time of the most recent tle. ;IF TimeGet(/_ydoy,sts_time,upto=uday) GE last_tle THEN BEGIN ; message, /info, sts_hide+', last tle is on '+last_tle+' -> skip' ; continue ;ENDIF ; Read the status file in $SSWDB_SMEI/cat/sts IF txt_read(sts_file,txt,/silent) NE 1 THEN $ continue ; Check the field for total frame count cstr = 'frames :' nframes = long(strmid(txt[where(strpos(txt,cstr) EQ 0)],strlen(cstr))) IF nframes EQ 0 THEN BEGIN ; Total frame count of zero. ; If the subdirectory c (n=1,2,3) does not exist, then there probably ; are no data for this camera on this doy. If the subdirectory does exist, ; then this doy is not completed yet (l1a.py sets the frame counts when ; it completes the doy, i.e. when it finds the first frame for the next doy). CASE CheckDir(smei_filepath(smei_filename(sts_file),camera=cam_int),/silent) OF 0: message, /info, sts_hide+', no frames' 1: message, /info, sts_hide+', no frames (still unpacking?)' ENDCASE continue ; No frames ENDIF ; Pick up number of mode 0 frames cstr = 'mode 0 :' nframes = long(strmid(txt[where(strpos(txt,cstr) EQ 0)],strlen(cstr))) IF nframes EQ 0 THEN BEGIN message, /info, sts_hide+', no mode 0 frames' continue ; No mode 0 frames ENDIF cstr = 'cal :' cal_ok = fix(strmid(txt[where(strpos(txt,cstr) EQ 0)],strlen(cstr))) IF cal_ok THEN BEGIN message, /info, sts_hide+', cal pattern exists' continue ; Pattern exists already ENDIF ; Generate the cal pattern smei_mkcal, sts_time, /generate, camera=cam_int, name=cal_pat, force=force IF cal_pat NE '' THEN BEGIN ; Pattern generated successfully ; Set 'cal' flag in sts_file cstr = 'cal :' txt[where(strpos(txt,cstr) EQ 0)] = 'cal : 1' ; Update the status file in $SSWDB_SMEI/cat/sts message, /info, sts_hide+', set "cal" field' CASE is_remote OF 0: BEGIN openw, /get_lun, iu, sts_file FOR i=0,n_elements(txt)-1 DO printf, iu, txt[i] free_lun, iu END 1: BEGIN ; smeidb.smei.ucsd.edu txt = strjoin(txt,string(10B)) ; 10B = new line spawn, 'echo "'+txt+'" | ssh soft@smei "cat - > '+sts_file+'"' END ENDCASE ENDIF ENDFOR ENDFOR RETURN & END