;+ ; NAME: ; TMBKGRD ; PURPOSE: ; To produce a minimum image ( from images in the .ray files) ; produced from an interval that the user supplies. This ; routine is called by TSAV_BKGRDS.PRO. ; CATEGORY: ; ; CALLING SEQUENCE: ; TMBKGRD,YEAR,MONTH,DAY,CAM,FILT,HH,MM,SS,SPAN,MINIM,PIXCHG,RUTSEC ; [,EXP=EXP] ; INPUTS: ; YEAR, MONTH, DAY: Date that the images were produced. ; HH, MM, SS: The start time (hour, minute, and second (UT)). ; CAM: The camera number. ; FILT: The filter number. ; SPAN: The length of time (in hours from the start ; time) over which the minimum image will be ; produced. ; KEYWORD PARAMETERS: ; EXP: Specifies the image exposure times of interest. If ; it is not set then by default 60 seconds will be ; chosen. ; OUTPUTS: ; MINIM: The minimum image ; PIXCHG: The number of pixels that change from one image to ; the next in the sequence used to produce MINIM. ; RUTSEC: The startimes of all the images used to produce MINIM. ; ; If, for any reason, MINIM cannot be produced then the MINIM, ; PIXCHG, and RUTSEC will all be set to -1. ; ; COMMON BLOCKS: ; HEADER,FNAME,HBYTES,NIMAGES,UTSEC,EXPTIMES,KEEP ; FNAME: Stores the name of the .ray file that has been last ; used. It will only change when a new .ray file has ; been opened. ; NIMAGES: The number of images in the .ray file. ; HBYTES: Stores the 512 header bytes of all the images in ; the .ray file. ; UTSEC: Stores the start time in UT seconds of all the ; images in the .ray file. ; EXPTIMES: Stores all the exposure time of the images in ; the .ray file. ; KEEP: Holds the indices into the HBYTES, EXPTIMES, and ; UTSEC, arrays of all the images with exposure times ; specified by the user. ; SIDE EFFECTS: ; None. ; RESTRICTIONS: ; This routine is intended to be called by TSAV_BKGRDS. It ; is not intended to stand on its own. ; PROCEDURE: ; The .ray file corresponding to the camera number, filter ; number, and date is opened. The images from the start time, ; through the interval given by SPAN, are used to produce ; the minimum image. By minimum image it is meant that each ; pixel in the minimum image is set to the lowest value of ; all the images. ; MODIFICATION HISTORY: ; Written July 1994, by T A Oliynyk. ;- PRO tmbkgrd,year,month,day,cam,filt,hh,mm,ss,span,minim,pixchg,rutsec,exp=exp COMMON header,fname,hbytes,nimages,utsec,exptimes,keep ; COMMON headbytes,oldfname,hbytes,utsec,exptimes,fwtemps,bad_image ; If some silly user tries to run this routine, set him straight. IF N_PARAMS() LT 12 THEN BEGIN doc_library,'tmbkgrd' minim=-1 pixchg=-1 rutsec=-1 RETURN ENDIF syear=STRING(year,FORMAT='(I2.2)') smonth=STRING(month,FORMAT='(I2.2)') sday=STRING(day,FORMAT='(I2.2)') scam=STRTRIM(cam,2) sfilt=STRTRIM(filt,2) path='/jasper/cnsr3_data1/save/' filename=syear+smonth+sday+scam+sfilt+'.ray' filename=path+filename f=FINDFILE(filename,count=exist) IF exist NE 0 THEN BEGIN ; default to exposure time of 60 seconds if keyword exp not set. IF NOT KEYWORD_SET(exp) THEN exp=60. ELSE exp=FLOAT(exp) ; set fname to the .ray filename. IF (N_ELEMENTS(fname) EQ 0) THEN fname='' ; if a different .ray file is opended or a .ray file is opened for ; the first time then change the information in the COMMON block. IF (N_ELEMENTS(utsec) EQ 0) OR (fname NE filename) THEN BEGIN ; Open the file as a series of small (header-size) units and get ; the header information fname=filename OPENR,hbunit,filename,/GET_LUN hbfile=ASSOC(hbunit,BYTARR(512)) hbstat=FSTAT(hbunit) hbbytes=hbstat.SIZE nimages=hbbytes/66048L PRINT,'There are '+STRTRIM(nimages,2)+' images' hbytes=BYTARR(512,nimages) utsec=LONARR(nimages) exptimes=FLTARR(nimages) FOR i=0L,nimages-1 DO BEGIN hbytes(0,i)=hbfile(129*i) header=gethd(hbytes(*,i)) utsec(i)=3600L*header.misc.tm.hour $ + 60L*header.misc.tm.minute $ + 1L*header.misc.tm.second exptimes(i)=header.misc.exp_scale*header.exp.exposure/1000. IF (i GT 0) AND (i MOD 20 EQ 0) THEN PRINT,i,FORMAT='(I4,$)' IF (i GT 0) AND (i MOD 400 EQ 0) THEN PRINT,FORMAT='()' ENDFOR ; (i=0L,nimages-1) PRINT,FORMAT='()' FREE_LUN,hbunit ENDIF ; (N_ELEMENTS(utsec) EQ 0) OR ... minim=INTARR(256,256)+16383 ; convert the interval to a start and stop time in UT seconds. butsec=3600L*hh+60L*mm+1L*ss ; start time (UT secs) eutsec=ROUND(butsec+FLOAT(span)*3600L) ; stop time (UT secs) OPENR,unit,filename,/GET_LUN files=ASSOC(unit,BYTARR(66048)) keep=WHERE(exptimes EQ exp) IF keep(0) EQ -1 THEN BEGIN exp=STRTRIM(exp,2) MESSAGE,'This file does not contain any '+exp+' second ' $ +'exposure images!' $ ,/INFORMATIONAL minim=-1 pixchg=-1 rutsec=-1 FREE_LUN,unit RETURN ENDIF ELSE BEGIN rutsec=utsec(keep) nimages=N_ELEMENTS(rutsec) nhh=hh & nmm=mm & nss=ss start=MIN(WHERE(rutsec GE butsec,any_images)) note=butsec-MIN(rutsec) flag=eutsec-MAX(rutsec) ; If the .ray file does not contain images from the start ; time requested, then notify the user, and use the smallest ; possible image time as the start time. IF any_images NE 0 THEN BEGIN finish=MAX(WHERE(rutsec LE eutsec,number)) IF note LT 0 THEN BEGIN start=0 nhh=rutsec(0)/3600L nmm=(rutsec(0)-nhh*3600L)/60L nss=(rutsec(0)-nhh*3600L-nmm*60L) MESSAGE,'The file chosen does not contain the start ' $ +'time requested.' $ ,/INFORMATIONAL MESSAGE,STRING(nhh,nmm,nss $ ,FORMAT='("The actual start time is "' $ +',I2.2,":",I2.2,":",I2.2,1X,"UT.")') $ ,/INFORMATIONAL ENDIF ; (note LT 0) ; If the .ray file does not span the interval requested, ; then notify the user, and use the all the images. IF flag GT 0 THEN BEGIN finish=nimages PRINT,'The file chosen does not span the time interval requested.' ehh=rutsec(finish-1)/3600L emm=(rutsec(finish-1)-ehh*3600L)/60L ess=(rutsec(finish-1)-ehh*3600L-emm*60L) PRINT,nhh,nmm,nss,ehh,emm,ess $ ,FORMAT='("The file spans ",2(I2.2,":"),I2.2," to ",' $ +'2(I2.2,":"),I2.2," UT.")' ENDIF ; (flag GT 0) IF start NE finish THEN BEGIN pixchg=FLTARR(finish-start) ; calculate the MINIM, over all images possible. FOR i=start,finish-1 DO BEGIN file=files(keep(i)) im=BYTE(file,512,256,256) ; If file was renormalized to fit 8 bits, reverse this. IF file(290) GT 0 THEN BEGIN IF file(291) EQ 1 THEN im=LONG(im)*(2L^file(290)) IF file(291) EQ 0 THEN im=LONG(im)*file(290) ENDIF ; (file(290) GT 0) wless=WHERE(im LT minim,count) IF wless(0) GE 0 THEN minim(wless)=im(wless) ; keep track of the number of pixels that changed in ; minim over each new image. pixchg(i-start)=count ENDFOR ; (i=start,finish-1) rutsec=rutsec(start:finish-1) rutsec(0)=butsec ENDIF ELSE BEGIN pixchg=0 file=files(keep(start)) minim=BYTE(file,512,256,256) IF file(290) GT 0 THEN BEGIN IF file(291) EQ 1 THEN minim=LONG(minim)*(2L^file(290)) IF file(291) EQ 0 THEN minim=LONG(minim)*file(290) ENDIF rutsec=rutsec(start) ENDELSE ; (start NE finish) ENDIF ELSE BEGIN MESSAGE,'The file chosen does not contain any images from' $ +'the time requested.' $ ,/INFORMATIONAL minim=-1 rutsec=-1 pixchg=-1 FREE_LUN,unit RETURN ENDELSE ; (any_images NE 0) FREE_LUN,unit ENDELSE ; (keep(0) EQ -1) ENDIF ELSE BEGIN warning='The .ray file for camera '+scam+' , filter '+sfilt $ +' ,on the date '+syear+'/'+smonth+'/'+sday+' does not exist.' MESSAGE,warning,/INFORMATIONAL minim=-1 pixchg=-1 rutsec=-1 ENDELSE ; (exist NE 0) RETURN END