;+ ; NAME: ; smei_filename ; PURPOSE: ; Construct or deconstructs file name for SMEI data files from/into its ; components (time,camera,file extension, and map mode) ; CATEGORY: ; camera/idl/frm ; CALLING SEQUENCE: FUNCTION smei_filename, tt, $ camera = camera, $ mode = mode , $ postfix = postfix,$ upto = upto , $ pos_tt = pos_tt, $ type = type , $ dir = dir , $ ccd = ccd ; INPUTS: ; tt array[n]; type; time structure or string ; time or file name ; ; If tt is a file name, two conditions must ; be met for a successfull deconstruction: ; - it must contain a valid time string ; (see href=timeposn=). ; - the time must be preceeded by an ; underscore ; If these are not met then the 'camera' ; 'mode' and 'postfix' fields are not set ; (i.e. camera=-1, mode=postfix='') ; OPTIONAL INPUT PARAMETERS: ; If input 'tt' is a time structure, the file name is ; constructed using the following additional input: ; ; camera=camera scalar or array[n]; type: integer; default: 1 ; camera number (1,2, or 3) ; type=type scalar or array[n]; type: string; default: '.fts.gz' ; file type ; mode=mode scalar or array[n]; type: string or integer; default: 0 ; file mode, e.g. 'frm', 'cal','sky','equ' ; If an integer is specified it is assumed to be the ; frame binning mode 0 (1x1), 1 (2x2) or 2 (4x4), ; in which case the mode will be 'm'+mode ; upto=upto scalar; type: integer; default: TimeUnit(/sec) ; sets time unit where file name is truncated ; (only used if input 'tt' is time structure) ; OUTPUTS: ; If input 'tt' is time structure: ; ; result array[n]; type: string ; name of SMEI file ; ; If input 'tt' is a file name ; ; result array[n]; type: time structure ; time coded into SMEI file (e.g. time of ; frame or start time of orbit) ; OPTIONAL OUTPUT PARAMETERS: ; If input 'tt' is a filename several parameters coded into ; the file are extracted: ; ; camera=camera array[n]; type: integer ; camera number (1,2, or 3) ; mode=mode array[n]; type: string or integer; default: 0 ; file mode, e.g. 'frm', 'cal','sky','equ', ; 'l1a'. ; If ccd=1 then mode is return as integers ; If ccd=0 then the mode for CCD frames ; is returned as 'm0','m1','m2'. ; ccd=ccd set to 1 if all entries are CCD frames ; type=type array[n]; type: string ; file type (may be a double type ; e.g. .fts.gz) ; directory=directory ; array[n]; type: string ; directory (null-string if not present) ; postfix=postifx array[n]; type: string ; null-string, 'm0' or 's' ; Set to 'm0' (if the directory name ; ends in 'c#m0') or 's' (if the directory name ; ends in 'c#s' (where # is the camera ; number). ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; InitVar, IsType, TimeSet, TimeGet, TimeUnit ; SetFileSpec, GetFileSpec, timeposn ; PROCEDURE: ; Uses the standard SMEI template for file names: ; c1m0_2003_123_123456.fts.gz ; MODIFICATION HISTORY: ; MAY-2004, Paul Hick (UCSD/CASS) ; JUL-2004, Paul Hick (UCSD/CASS) ; Modified to deal with new frame name syntax with mode coded ; into the file name ; JUL-2004, Paul Hick (UCSD/CASS) ; Updated documentation ; MAR-2008, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; Substantial rewrite of deconstruction section. ; Added pos_tt and ccd keywords. ;- uu = tt ; Intercepts time specifications that could be smei orbits. ; Convert these to time IF IsTime(uu, /orbit ) OR $ IsType(uu, /generic_int ) OR $ IsType(uu, /generic_float) THEN uu = TimeSet(smei=uu) CASE IsTime(uu) OF 0: BEGIN ; Should be a filename type = GetFileSpec(uu,from='type',/strict); Return arg name = GetFileSpec(part='name' ) ; Return arg dir = GetFileSpec(upto='directory' ) camera = -1 postfix = '' SyncArgs, name, camera, postfix ; rtn : time coded into file names ; pos : position where encoded time starts ; mode: section preceeding the time pos_tt = timeposn(name, front=mode, time=rtn) kk = where(pos_tt NE -1, complement=mm) IF mm[0] NE -1 THEN mode[mm] = '' ; No time encoded IF kk[0] NE -1 THEN BEGIN ; Time encoded nn = kk ; Index into mode ; The last char in mode (preceeding the time) ; must be an underscore kk = strpos(mode[nn],'_',/reverse_search) kk = where(kk EQ strlen(mode[nn])-1, complement=mm) IF mm[0] NE -1 THEN mode[nn[mm]] = '' ; No trailing underscore IF kk[0] NE -1 THEN BEGIN ; Trailing underscore nn = nn[kk] ; Index into mode ; Strip trailing underscore mode[nn] = strreverse(strmid(strreverse(mode[nn]),1)) ; The mode extends back to the last underscore ; (if there is one). kk = strpos(mode[nn],'_',/reverse_search) ; Extract the mode by extracting substrings ; starting at kk+1. ; Usually kk will be the same for all entries in ; 'mode' (e.g. kk=-1 everywhere). IF n_elements(kk[uniq(kk,sort(kk))]) EQ 1 THEN BEGIN mode[nn] = strmid(mode[nn],kk[0]+1) ENDIF ELSE BEGIN mm = where(kk NE -1, n) IF n GT 0 THEN BEGIN kk = kk[mm] mm = nn[mm] FOR i=0L,n-1 DO $ mode[mm[i]] = strmid(mode[mm[i]],kk[i]+1) ENDIF ENDELSE ; If the mode starts with c0,c1,c2,c3 then ; extract the camera number. kk = strmid(mode[nn],0,2) kk = where( kk EQ 'c0' OR kk EQ 'c1' OR $ kk EQ 'c2' OR kk EQ 'c3' ) IF kk[0] NE -1 THEN BEGIN ; Camera encoded nn = nn[kk] ; Index into mode ; Get the name of the subdirectory ; If it is 'c#m0', or 'c#s' set return arg postfix subdir = GetFileSpec(upto='directory',/asfilename) subdir = GetFileSpec(subdir[nn],part='name') ; Check for engineering mode ('m0') subdir kk = where(subdir EQ strmid(mode[nn],0,2)+'m0') IF kk[0] NE -1 THEN postfix[nn[kk]] = 'm0' ; Check for subdir with science mode, smoothed dark current ('s') kk = where(subdir EQ strmid(mode[nn],0,2)+'s') IF kk[0] NE -1 THEN postfix[nn[kk]] = 's' camera[nn] = fix(strmid(mode[nn],1,1)) mode [nn] = strmid(mode[nn],2) ENDIF ENDIF ENDIF ccd = mode NE 'm0' AND mode NE 'm1' AND mode NE 'm2' ccd = round( total(ccd) ) EQ 0 IF ccd THEN mode = fix(strmid(mode,1)) END 1: BEGIN InitVar, camera , 1 InitVar, type , '.fts.gz' InitVar, upto , TimeUnit(/sec) InitVar, mode , 0 CASE IsType(mode,/generic_int) OF 0: rtn = mode 1: rtn = 'm'+strcompress(mode,/rem) ENDCASE rtn = 'c'+strcompress(camera,/rem)+rtn+'_'+TimeGet(uu, upto=upto, /_ydoy, /scalar)+type END ENDCASE RETURN, rtn & END