;+ ; NAME: ; GETFFIMG ; PURPOSE: ; Load Polar Camera flat-field images appropriate for a given ; date. ; CATEGORY: ; ; CALLING SEQUENCE: ; GETFFIMG, YEAR, MONTH, DAY ; INPUTS: ; YEAR, ; MONTH, ; DAY: Numeric parameters that specify the date (in ; Universal Time). ; OPTIONAL INPUTS: ; None. ; KEYWORD PARAMETERS: ; None. ; OUTPUTS: ; None. ; OPTIONAL OUTPUTS: ; None. ; COMMON BLOCKS: ; FFSTUFF: Contains one array named FFIMG, a 1280x512 element ; BYTE array. The COMMON block must also be defined ; by the calling routine. ; SIDE EFFECTS: ; Flat-field images appropriate to the specified date are ; read, and their contents are stored into array FFIMG. ; RESTRICTIONS: ; Dates before October 16, 1993 (start of operations at ; Eureka AStrO Lab) return a zero array, since the first ; flat-field images available are from October 19, 1993. ; PROCEDURE: ; The directory containing flat-field images is searched for ; all candidate flat-field images. The names of all Camera ; 0, Filter 0 images are returned, and the dates of creation ; are decoded. The latest set of flat-field images created ; before the specified date is returned in array FFIMG. ; EXAMPLE: ; ; SEE ALSO: ; ; MODIFICATION HISTORY: ; Written by: D P Steele, November 1993. ; Modified by: D P Steele, 941122, to accept date arguments ; and return the date-appropriate flat-field ; images. ; Modified by: D P Steele, 950612, to return arrays of ; 100B if the date supplied predates the ; earliest flat-field image. This value ; produces no effect on the raw images but ; avoids problems created by returning arrays ; of 0B. ;- PRO getffimg,year,month,day ; This routine is called by NEWQL.PRO and STARNIGHT.PRO, among ; (possibly) others. It reads in the flat-field images for all ; Polar Camera camera/filter combinations and returns them all in ; a 1280x512 byte array. If only one of the images is needed in ; an application, the remaining images should be deleted in the ; calling routine. COMMON ffstuff,ffimg @isitdos ffimg=BYTARR(5*256,2*256) ; Make sure year looks right. IF year LT 1900 THEN $ IF year LT 50 THEN year=year+2000 ELSE year=year+1900 ; Need to decide which set of flat-field files to use. ; Identify different sets by their camera 0, filter 0 entries. ff00=rfindfile(flatroot+dd+'f00?????.dat',count=nff00) ; Save Julian dates and date strings. jdate=LONARR(nff00) ds=LONARR(nff00) ; Locate filename beginnings in filepath strings. p=STRPOS(ff00,'f00') FOR i=0,nff00-1 DO BEGIN ; Extract date string. ds(i)=LONG(STRMID(ff00(i),p(i)+3,5)) ; Get year and day number of year. fyear=1900+ds(i)/1000 dn=ds(i) MOD 1000 ydn2md,fyear,dn,fmonth,fday ; Compute Julian date corresponding to date string. jdate(i)=julday(fmonth,fday,fyear) ENDFOR ; Julian date of observations. odate=julday(month,day,year) ; Time from flat-field date to observation date. diff=odate-jdate IF MAX(diff) LT 0 THEN BEGIN ; No good if obs. predate flat-field images! MESSAGE,'Observations earlier than first flat-field images!' $ ,/INFORMATIONAL ffimg=REPLICATE(100B,1280,512) RETURN ENDIF ELSE BEGIN ; Flag flat-field images taken after observations. IF MIN(diff) LT 0 THEN diff(WHERE(diff LT 0))=99999 ; Find last flat-field set taken before date of observations. mindiff=MIN(diff,n) ENDELSE ; Now we know the right flat-field image set, go get 'em. ffim=BYTARR(256,256) FOR j=0,1 DO BEGIN FOR i=0,4 DO BEGIN ffname=flatroot+dd+STRING(j,i,ds(n),FORMAT='("f",2I1,I5,".dat")') OPENR,ffunit,ffname,/GET_LUN READU,ffunit,ffim CLOSE,ffunit FREE_LUN,ffunit ffimg(i*256,j*256)=ffim ENDFOR ; (i) ENDFOR ; (j) RETURN END