;+ ; NAME: ; smei_hdr_make ; PURPOSE: ; Writes Fits binary tables containing all SMEI frame headers ; CATEGORY: ; ucsd/camera/idl/frm ; CALLING SEQUENCE: PRO smei_hdr_make, tt, $ overwrite = overwrite , $ source = source , $ destination = destination , $ camera = camera , $ get = get , $ count = count , $ remote = remote , $ silent = silent ;_extra = _extra ; INPUTS: ; tt array[2]; standard time structure ; indicates time range for which SMEI frame are to ; be processed ; OPTIONAL INPUT PARAMETERS: ; /overwrite if SET a binary Fits table is overwritten if it exists ; By default existing files are NOT overwritten. ; The file name will have the form c#hdr_YYYY_DOY_hhmmss.fts ; where #=1,2,3 is the camera number. ; Existing files are overwritten ; source scalar; type: string ; source of SMEI frame files (passed to href=smei_getfile=) ; (usually set to SMEIDB? or SMEIDC?) ; destination scalar; type: string ; destination directory for Fits binary table file ; 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) ; camera scalar; type: integer (1,2,3) ; only camera one frames are processed. By default all three ; cameras are processed and headers are written into three ; separate files, one for each camera. ; OPTIONAL OUTPUT PARAMETERS: ; count=count scalar; type: integer ; number of headers written into Fits binary table (all cameras ; combined, if more than one camera was processed). ; INCLUDE: @compile_opt.pro ; On error, return to caller ; EXTERNAL: ; smei_frm_hdr ; CALLS: ; InitVar, IsType, CheckDir, IsTime, TimeGet, TimeSet, TimeUnit ; TimeOp, smei_property, smei_getfile ; SEE ALSO: ; smei_hdr_get ; PROCEDURE: ; MODIFICATION HISTORY: ; JUN-2005, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ;- InitVar, overwrite, /key InitVar, silent , /key uday = TimeUnit(/day) usec = TimeUnit(/sec) empty_hdr = {smei_frm_hdr} InitVar, destination, getenv('TUB') IF NOT CheckDir(destination) THEN BEGIN message, /info, 'destination does not exist: '+hide_env(destination) RETURN ENDIF tags = tag_names(empty_hdr) ntag = n_elements(tags) col = lonarr(ntag) InitVar, camera, [1,2,3] CASE 1 OF IsType(tt,/undefined): BEGIN message, /info, 'no time range specified' RETURN END IsType(tt,/string ): tt = TimeSet(tt) ELSE: ENDCASE IF n_elements(tt) EQ 1 THEN $ ut = [tt, TimeOp(/add, tt, TimeSet(/diff,day=1))] ELSE ut = tt[0:1] tmp = TimeGet(ut, /bot, uday) n = TimeOp(/subtract,tmp[1],tmp[0],uday) tmp = TimeOp(/subtract,ut,tmp,usec) whole_day = n EQ 1 AND tmp[0] EQ 0 AND tmp[1] EQ 0 base_filename = TimeGet(ut[0],/_ydoy,upto=([usec,uday])[whole_day],/scalar) base_filename = 'hdr_'+base_filename+'.fts' FOR icam=0,n_elements(camera)-1 DO BEGIN filename = filepath(root=destination, 'c'+strcompress(camera[icam],/rem)+base_filename) refresh = overwrite IF NOT refresh THEN refresh = (file_search(filename))[0] EQ '' CASE refresh OF 0: message, /info, 'file exists: '+hide_env(filename) 1: BEGIN hdr = smei_getfile(ut, /get_hdr, source=source, camera=camera[icam], count=count);, _extra=_extra) CASE count GT 0 OF 0: message, /info, 'no frames in '+strjoin(TimeGet(ut,/_ydoy,upto=usec),' - ')+' for cam'+strcompress(camera[icam]) 1: BEGIN fxbhmake, hdr_table, count, 'SMEI_FRM_HDRTABLE','SMEI frame header summary' FOR i=0,ntag-1 DO BEGIN tmp = hdr[0].(i) IF IsTime(tmp) THEN tmp = TimeGet(tmp,/_ydoy,upto=usec,/scalar) IF tags[i] EQ 'TLM_FILE' THEN IF strlen(strtrim(tmp)) EQ 0 THEN tmp = 'COR_FBKS0_2000_001_00_00_VCID5' IF tags[i] EQ 'L1A_FILE' THEN IF strlen(strtrim(tmp)) EQ 0 THEN tmp = 'l1a_2000_001_000000_000000' IF tags[i] EQ 'CAL_PATTERN' THEN IF strlen(strtrim(tmp)) EQ 0 THEN tmp = 'c0cal_2000_001_000000' IF tags[i] EQ 'ORB_PATTERN' THEN IF strlen(strtrim(tmp)) EQ 0 THEN tmp = 'c0orb_2000_001_000000' fxbaddcol, j, hdr_table, tmp, tags[i] col[i] = j ENDFOR fxhmake , hdr_main, /initialize, /extend, /date fxaddpar, hdr_main, 'CAMERA' , camera[icam],' Camera number' fxaddpar, hdr_main, 'START_UT', TimeGet(ut[0],/_ydoy,upto=usec,/scalar),' Start time' fxaddpar, hdr_main, 'STOP_UT' , TimeGet(ut[1],/_ydoy,upto=usec,/scalar),' Stop time' fxaddpar, hdr_main, 'NFRAME ' , count ,' Number of frames' FOR i=0,2 DO BEGIN tmp = where( smei_property(hdr,/mode) EQ i, n ) fxaddpar, hdr_main, 'NMODE'+strcompress(i,/rem), n,' Number of mode '+strcompress(i,/rem)+' frames' ENDFOR IF silent LE 0 THEN message, /info, hide_env(filename) IF IsType(remote,/defined) THEN $ filename = filepath(root=getenv('TUB'),GetFileSpec(filename,from='name')) fxwrite, filename, hdr_main fxbcreate, iu, filename, hdr_table tmp = ptrarr(ntag,/allocate) FOR i=0,ntag-1 DO BEGIN CASE IsTime(hdr[0].(i)) OF 0: *tmp[i] = hdr.(i) 1: *tmp[i] = TimeGet(hdr.(i),/_ydoy,upto=usec,/scalar) ENDCASE ENDFOR fxbwritm, iu, col, pass_method='POINTER', pointers=tmp ptr_free, tmp ;FOR j=0,count-1 DO BEGIN ; FOR i=0,ntag-1 DO BEGIN ; tmp = hdr[j].(i) ; IF IsTime(tmp) THEN tmp = TimeGet(tmp,/_ydoy,upto=usec,/scalar) ; fxbwrite, iu, tmp, col[i], j+1 ; ENDFOR ;ENDFOR fxbfinish, iu IF IsType(remote,/defined) THEN BEGIN tmp = 'scp '+filename+' '+remote+':'+destination print, tmp spawn, tmp tmp = do_file(filename, /delete) ENDIF END ENDCASE END ENDCASE ENDFOR RETURN & END