;+ ; NAME: SAVBKGRD ; ; PURPOSE: ; To save minimum (background) images produced from images ; stored in .ray files. ; ; CATEGORY: ; ; CALLING SEQUENCE: ; SAVBKGRD,YEAR,MONTH,DAY,CAM,FILT,HH,MM,SS,SPAN,INT,EMIS_HT[,EXP=EXP] ; ; INPUTS: ; YEAR, ; MONTH, ; DAY: The year, month, day that the images used to generate ; the minimum images were produced. ; ; CAM: The camera number of the images used to generate ; the minimum images. ; ; FILT: The filter number of the images used to ... ; ; HH, ; MM, ; SS: The start time (in UT, hour, minute, second format) ; of images in the .ray files that will be used to ; generate the minimum images. ; ; SPAN: The total period, in hours, over which minimum ; images will be produced. ; ; INT: The interval, in hours, over which individual ; minimum images will be produced. E.g., if HH=0, ; MM=0, SS=0, SPAN=24, & INT=1, then the minimum ; images stored in the .bkg file by this procedure ; will be generated from one hour intervals of images ; in the corresponding .ray file starting at 00:00:00 ; UT, and continuing for 24 hours. ; ; EMIS_HT: The emision height of the feature corresponding to ; the filter. Note that this information will only ; be used in constructing a van Rhijn layer. Since ; the van Rhijn layer is always stored as the first ; image, the emision height will only be used when ; a .bkg file is first created. ; ; KEYWORD PARAMETERS: ; EXP: One or more exposure times for the images to be ; used in generating minimum background images. ; ; OUTPUTS: ; None. ; ; COMMON BLOCKS: ; None. ; ; SIDE EFFECTS: ; The file ~cnsr3/bkgrd/yearmonthdaycamfilt.bkg is created ; or updated depending on whether it previously existed. ; ; The structure of the file is as follows. The header takes ; up the first 24 bytes. First, the year, month, day, camera ; number, filter number, and the number of images (used to ; produce the minimum image) are stored as INTEGER type. ; Next, the starting time (in UT secs), ending time (in UT ; secs), and the interval (in secs), are stored as LONG ; integers. Finally, the minimum image is Lee-filtered and ; stored as a FLOAT type array. It is worth noting that the ; first image in any .bkg file will be a van Rhijn layer. ; This header will contain the same information except that ; the number of images, the start time, and end time will be ; set to zero, while the interval will contain the emission ; height of the layer in kilometers. ; ; RESTRICTIONS: ; The only files with the extension .bkg in the directory ; ~cnsr3/bkgrd, must be the ones produced by this procedure. ; ; PROCEDURE: ; .... ; ; MODIFICATION HISTORY: ; Written July 1994, by T A Oliynyk. ; Modified October 1994 by D P Steele. ; Modified August 25, 1995 by D P Steele to work under Windows. ;- PRO savbkgrd,year,month,day,cam,filt,hh,mm,ss,span,int,emis_ht,exp=exp IF N_PARAMS() LT 11 THEN BEGIN doc_library,'savbkgrd' RETURN ENDIF ; Set up OS-specific parameters. @isitdos ; check for starting times that make sense. WHILE (hh GE 24) OR (mm GE 60) OR (ss GE 60) DO BEGIN PRINT, 'Starting time entered is invalid. The number of hours, minutes ' $ +'and seconds,' PRINT, 'must be less that 24, 60 and 60 respectively.' PRINT, 'Enter new starting time. (Separate hours, minutes and seconds by ' $ +'a space.)' PRINT, FORMAT='($,"Enter new values here")' READ,hh,mm,ss PRINT, ' ' ENDWHILE ; restrict the images used from the .ray file to one day. IF (hh+span) GT 24 THEN span=FLOAT(24-hh) IF int GT span THEN int=span fin=ROUND(FLOAT(span)/int) syear=STRING(year MOD 100,FORMAT='(I2.2)') smonth=STRING(month,FORMAT='(I2.2)') sday=STRING(day,FORMAT='(I2.2)') scam=STRTRIM(cam,2) sfilt=STRTRIM(filt,2) ifile=syear+smonth+sday+scam+sfilt ; filename=ifile ; bpath='/jasper/cnsr3_data1/bkgrd/' bpath=iroot+dd+'bkgrd'+dd ifile=bpath+ifile+'.bkg' ; cpath='/jasper/cnsr3_data1/save/' ; cpath=saveroot+dd ; filename=cpath+filename+'.ray' filename=FiLocate(year,month,day,cam,filt,/ray) ; see if the .ray and/or the corresponding .bkg file exists. fb=FINDFILE(ifile,count=existb) fc=FINDFILE(filename,count=existc) IF existc EQ 0 THEN BEGIN MESSAGE,'The image file for the date and camera requested does not exist!' $ ,/INFORMATIONAL RETURN ENDIF ELSE BEGIN ; if the .bkg file does exist, the use the procedure GET_BKGHDS, to ; return the header infromation of all the images that already exist in the file. IF existb NE 0 THEN get_bkghds,year,month,day,cam,filt,header ; if the .bkg file does not exist, then created it, and store the appropriate ; van Rhijn layer in the first image position. IF existb EQ 0 THEN BEGIN OPENW,iunit,ifile,/GET_LUN vr=FLOAT(v_rhijn(emis_ht,year,month,day,cam,filt,/small)) WRITEU,iunit,year,month,day,cam,filt,0,0L,0L,LONG(emis_ht),vr ENDIF ELSE BEGIN OPENU,iunit,ifile,/APPEND,/GET_LUN ENDELSE ; convert the starting time to seconds. strtsecs=hh*3600L+mm*60L+ss ; convert the interval to seconds. intsecs=LONG(int*3600L) FOR i=0,fin-1 DO BEGIN ; convert the sequence of image intervals to UT. IF i NE 0 THEN seconds=seconds+intsecs ELSE seconds=strtsecs hour=seconds/3600L minute=(seconds-hour*3600L)/60 secs=(seconds-hour*3600L-minute*60) ; make the minimum background image. tmbkgrd,year,month,day,cam,filt,hour,minute,secs,int,mim,pxch,rutsec,exp=exp sut=MIN(rutsec,MAX=eut) mint=LONG(ROUND(int*3600)) ; only store images that are new IF ((rutsec(0) NE -1) AND (pxch(0) NE -1))THEN BEGIN IF existb NE 0 THEN BEGIN srt=WHERE(ABS(header.utsec.sut- sut) LT 1) fsh=WHERE(ABS(header.utsec.eut-eut) LT 1) ENDIF ELSE BEGIN srt=-1 & fsh=-1 & no_incld=-1 ENDELSE IF ((srt(0) NE -1) AND (fsh(0) NE -1)) THEN BEGIN no_incld=where_array(srt,fsh) ENDIF ELSE no_incld=-1 IF ((srt(0) EQ -1) OR (fsh(0) EQ -1) OR (no_incld(0) EQ -1)) THEN BEGIN nimgs=FIX(N_ELEMENTS(rutsec)) ; Lee-filter and smooth the minimum images before storing them. lmim=SMOOTH(FLOAT(LEEFILT(mim,5,6)),3) WRITEU,iunit,year,month,day,cam,filt,nimgs,sut,eut,mint,lmim ENDIF ENDIF ENDFOR FREE_LUN,iunit ENDELSE RETURN END