;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; DIcal_IrFarnhamFlatAsfCheck.pro ;;; ;;; Check for HRIIR Tony Farnham Master Flat with ASF profile ;;; - see ./Data/IR_Flats/tony_farnham_asf_flat/ ;;; ;;; INPUTS: ;;; FLAT - Flat field input, may be changed by this routine ;;; FITFNARG - Path to FITS file for which FLAT is PDU image data ;;; CALHDR - FITFN PDU Header function DIcal_IrFarnhamFlatAsfCheck, flatArg, fitFnArg, calHdr $ , dataFitHdr=dataFitHdr $ , debug=debugArg noDebug = keyword_set(debugArg) ? 0b : 1b fitFn = strtrim(fitFnArg[0],2) rtn = { success:0b } ;;; Assume this is not a Farnham HRIIR UBFF flat w/ASF profile ;;; Check if keyword PDUNAME exists is set correctly pduName = strtrim(sxpar( calHdr, 'PDUNAME', count=ct),2) if ct ne 1L then return, rtn ;;; Check for keyword PDUNAME version ;;; - Use CASE pduName as there might be later versions of this kind of flat CASE pduName of 'IR_FARNHAM_MASTER_FLAT_V201009': $ begin asfExtName = 'IR_FARNHAM_ASF_PROFILE_10240' idlProName = 'DICAL_MAKE_IR_FLAT_V201009.PRO' ;;; After this point, any missing components will exit in error opened=0b catcher=0L if noDebug then catch,catcher if catcher ne 0L then begin catch,/cancel msg=!error_state.msg if opened then FITS_CLOSE,fcb,/NO_ABORT message,msg,/NONAME return, 0b endif ;;; - Bench temperature and image mode from data file FITS header optbent = sxpar( dataFitHdr, 'SMOBENT', count=ct) if ct ne 1L or optbent le 0.0 then $ optbent = sxpar( dataFitHdr, 'OPTBENT', count=ct) if ct ne 1L or optbent le 0.0 then $ message,'Could not get bench temperature from FITS header' imgmode = sxpar( dataFitHdr, 'imgmode', count=ct) if ct ne 1L or imgmode lt 1 or imgmode gt 7 then $ message,'Could not get image mode from FITS header' ;;; - Open FITS file for multiple reads FITS_OPEN,fitFn,fcb,/NO_ABORT,MESSAGE=msg if msg ne '' then message,'FITS_OPEN failed on file '+fitFn+'; '+msg opened = 1b ;;; - Get ASF Transmission profile FLOAT[10240] FITS_READ,fcb,asfprof_os,asfHdr,EXTNAME=asfExtName,/NO_ABORT,MESSAGE=msg if msg ne '' then $ message,'FITS_READ failed on file '+fitFn+'('+asfExtName+'); '+msg IF n_elements(asfprof_os) NE 10240L THEN $ message, 'Invalid ASF profile (#elements='+strtrim(n_elements(asfprof_os),2)+'!=10240) in file '+fitFn $ , /NONAME ;;; - Compile routine DIcal_IrProCheck, idlProName, fcb, /is_function, debug=debugArg ;;; - Close calibration FITS file opened = 0b FITS_CLOSE,fcb,/NO_ABORT ;;; - Change flat argument ubffFlat = flatArg lName = strlen(idlProName) sfx4 = strupcase(strmid(idlProName,(lName-4L)>0L)) funcName = strmid( idlProName, 0, lName-(sfx4 eq '.PRO' ? 4 : 0L)) newFlat = call_function( funcName,ubffFlat,asfprof_os,optbent,imgmode) flatArg = newFlat rtn = create_struct( rtn $ , 'FITS_KEYWORDS' $ , { FASFCORR: 'T' $ , FLATTYPE: pduName $ , FLAT_PRO: idlProName $ } ) rtn.success = 1b end else: endcase return, rtn end