function fiss_calfile, datafiles, cal_dir, type=type ;+ ; Name: fiss_calfile ; Find the name of calib file(s) suited for ; given data file(s) ; ; Syntax: result=fiss_calfile (datafiles) ; ; Returned values: ; ; the full name of calibration files ; Arguments: ; datafiles the full name of data file ; ; Keywords: None ; ; Remarks: The calib file should be in the calib directory ; Required routines: ; ; History: ; 2010 July, first coded (J. Chae) ; ;- if !version.os_family eq 'Windows' then delim='\' else delim='/' nf=n_elements(datafiles) calfiles=strarr(nf) file=file_basename(datafiles) tstr=strmid(file, 5, 15) if n_elements(type) eq 0 then type='cal' for k=0, nf-1 do begin detector=strmid(file[k], 25, 1) case type of 'cal' : id='FISS_*'+detector+'_Cal.fts' 'flat': id='FISS_FLAT_*'+detector+'.fts' 'slit': id='FISS_SLIT_*'+detector+'.fts' endcase dfiles=file_search(cal_dir+id, count=count) stop if count eq 0 then begin print, 'no files of type: '+type+' are found! ..returning from fiss_calfile.' return, '' endif dfbase=file_basename(dfiles) case type of 'cal': dtstr = strmid(dfbase, 5, 15) 'flat': dtstr=strmid(dfbase, 10, 15) 'slit': dtstr=strmid(dfbase, 10, 15) endcase dt=julday(strmid(dtstr, 4,2), strmid(dtstr, 6,2), strmid(dtstr, 0, 4), $ strmid(dtstr, 9,2), strmid(dtstr, 11, 2), strmid(dtstr,13, 2)) $ -julday(strmid(tstr[k], 4,2), strmid(tstr[k], 6,2), strmid(tstr[k], 0, 4), $ strmid(tstr[k], 9,2), strmid(tstr[k], 11, 2), strmid(tstr[k],13, 2)) s=(where(abs(dt) eq min(abs(dt))))[0] calfiles[k]=cal_dir+delim+dfbase[s] endfor return, calfiles end