;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Lance Simms, Stanford University 2009 ;function return_file_list_xrg ; ;PURPOSE: ; To return a list of files that match the desired specification in ; object, filter, number of reads, etc. Not every file was recorded ; with the proper parameters in the filename, but the header contains ; the correct information. So the header is used to filter out the files ; that do not match. ; ;INPUTS: ; InitFileArray - An array of filenames that might potentially match ; the desired configuration. ;KEYWORDS: ; THISFILTER - The filter used in the exposure ; ; THISNDROPS - The number of drop frames in the exposure ; ; TIMES - The time of the exposures ; ; WINDOWMODE - A boolean stating whether or not the exposures were ; taken in windowmode. No exposures were taken in ; windowmode with the LEACH ; 0 - indicates full frame modee ; 1 - indicates window mode ; TwoD: int ; 0 - We are dealing with 2-d image ; 1 - We are dealing with a 3-d datacube ; TEMPERATURE: int ; The temperature at which the files were recorded. This keyword ; remains at zero in most instances; only used when the darks ; were recorded at different temps. ; ;OUTPUS: ; FinFileArray - The filtered array of filenames that remove the ; errant filenames ; function Return_File_List_xRG, InitFileArray, $ ThisNAxis3 = ThisNAxis3, ThisFilter = ThisFilter, $ ThisNDrops = ThisNDrops, $ Times = Times, WindowMode = WindowMode, TwoD = TwoD, $ Temperature = Temperature If N_Elements(ThisNDrops) eq 0 then ThisNDrops = 0 If N_Elements(TwoD) eq 0 then TwoD = 0 If N_Elements(Temperature) eq 0 then Temperature = 0 Common KeyParams ;Set up initial indices and arrays for the files that match ValidIndices = 0 Times = Fltarr(N_elements(InitFileArray)) ThisFilter = strtrim(ThisFilter, 2) ;DEAL WITH LEACH, H1RG combo separately since those files have a header ;in a separate file. Only use the images that have the filter we want For i = 0., n_elements(InitFileArray) - 1 do begin If KeyStr.DetStr eq 'H1RG-022' and KeyStr.ElecStr eq 'LEACH' and $ KeyStr.Date ne '05May08' and $ not stregex(InitFileArray(i), 'Reduced', /boolean) and $ not stregex(InitFileArray(i), 'Flat', /boolean) then begin FileDir = File_DirName(InitFileArray(i)) FileBaseName = File_BaseName(InitFileArray(i)) Fits_Read, InitFileArray(i), NoData, FitsHeader, /header_only Naxis3 = long(SxPar(FitsHeader, 'NAXIS3')) TotalReads = long(SxPar(FitsHeader, 'NAXIS3')) HeaderName = FileDir+KeyStr.PathDelim+'Header_'+FileBaseName Fits_Read, HeaderName, NoData, FitsHeader, /header_only EndIf else begin Fits_Read, InitFileArray(i), NoData, FitsHeader, /header_only Naxis3 = long(SxPar(FitsHeader, 'NAXIS3')) TotalReads = long(SxPar(FitsHeader, 'NAXIS3')) EndElse ;Deal with 2-d images such as the slopefits If NAxis3 eq 0 and TwoD then ThisNAxis3 = 0 ;Try to get these keywords if possible if KeyStr.Date eq '05May08' then begin Filter = strtrim(SxPar(FitsHeader ,'WHEEL1'),2) endif else if (KeyStr.Date eq '2007Nov18' and $ stregex(InitFileArray(i), 'Flat', /boolean) and $ Not (stregex(InitFileArray(i), 'Slope', /boolean))) then begin Filter = strmid(InitFileArray(i), stregex(InitFileArray(i), 'Flats')+6,1) endif else if (KeyStr.Date eq '2007Nov13_2') and $ stregex(InitFileArray(i), 'Flat', /boolean) and $ not stregex(InitFileArray(i), 'Fielded', /boolean) then begin FileBaseName = File_BaseName(InitFileArray(i)) Filter = strmid(FileBaseName, 0, 1) stop endif else begin Filter = strtrim(SxPar(FitsHeader ,'FILTER'),2) endelse NDrops = long(SxPar(FitsHeader ,'NDROPS')) NReads = long(SxPar(FitsHeader ,'NREADS')) NGroups = long(SxPar(FitsHeader ,'NGROUPS')) Time = SxPar(FitsHeader, 'TIME') WindowM = long(SxPar(FitsHeader, 'WINDOWM')) Temp = round(long(SxPar(FitsHeader, 'DETTEMP'))) ;Get the time If Time ne '' then begin FirstColon = stregex(Time,':') Hour = long(strmid(Time,FirstColon-2,2)) Minute = long(strmid(Time,FirstColon+1,2)) Second = long(strmid(Time,FirstColon+4,2)) Seconds = Hour*3600.+Minute*60.+Second EndIf Else Begin Seconds = 0 EndElse ;Print out Some Info print, strtrim(string(i),2)+ string(9B)+ strtrim(InitFileArray(i), 2) print, 'Filter:'+ string(9B)+ strtrim(Filter,2) print, 'NDrops:'+ string(9B)+ strtrim(NDrops,2) If N_Elements(WindowMode) eq 0 then WindowMode = 0 ;If we are not concerned with temperature, take all the files matching other keys if Temperature eq 0 then begin If stregex(Filter, ThisFilter ,/boolean) and $ NDrops eq ThisNDrops and $ WindowM eq WindowMode and $ NAxis3 eq ThisNAxis3 then $ ValidIndices = [ValidIndices, i] endif else begin If NDrops eq ThisNDrops and $ WindowM eq WindowMode and $ NAxis3 eq ThisNAxis3 and $ Temp eq Temperature then $ ValidIndices = [ValidIndices, i] endelse ;Keep the times in an array Times(i) = Seconds Endfor ;Only keep the files that match FinFileArray = InitFileArray[ValidIndices(1:N_elements(ValidIndices)-1)] Times = Times[ValidIndices(1:N_elements(ValidIndices)-1)] return, FinFileArray end