;+ ; NAME: ; RDHBYTES ; PURPOSE: ; Read and save the header bytes (not decoded headers!) from ; all images in a .ray or .bgs file (a large file containing ; processed Polar Camera images, which is used by IDL as an ; associated file variable). ; CATEGORY: ; Secondary image processing; image display ; CALLING SEQUENCE: ; n_images = RDHBYTES( PATHNAME ) ; INPUTS: ; PATHNAME: The full pathname of the .ray or .bgs file. ; OPTIONAL INPUTS: ; None. ; KEYWORD PARAMETERS: ; None. ; OUTPUTS: ; n_images: The number of images stored in the specified file. ; OPTIONAL OUTPUTS: ; None. ; COMMON BLOCKS: ; HEADBYTES: Contains the header bytes from all images in ; the specified file, as well as certain useful ; parameters extracted from the file. The contents ; are: ; OLDFNAME: The file name part of PATHNAME from the ; _previous_ invocation of RDHBYTES; ; HBYTES: BYTARR(512,n_images) in which each row ; contains the 512-byte header from the ; corresponding image in the specified file; ; UTSEC: LONARR(n_images) containing the Universal ; Time, in seconds from midnight, of the ; start of each image; ; EXPTIMES: FLTARR(n_images) containing the exposure ; time (sec) of each image; ; FWTEMPS: FLTARR(n_images) containing the filter ; wheel temperature (degrees C) during each ; image in the file. Some (or all) values ; may be 0, for an as yet unknown reason; ; BAD_IMAGE: LONARR(>1) containing the index values ; of any images in the file which generated ; I/O errors while being read. If no errors ; occurred, BAD_IMAGE is returned as [-1]. ; SIDE EFFECTS: ; The specified file is opened and read. ; RESTRICTIONS: ; The specified file must exist. ; PROCEDURE: ; Straightforward. Each image in the file is 66048 bytes ; long. All temperatures T in the header are stored as ; integers expressing 10*T. If the HBYTES variable is already ; defined and the file name (OLDFNAME) for those headers is ; the same as the current one (FNAME), the file is not read. ; ; NOTE: If all values in FWTEMPS are 0, extraordinary measures ; are taken to get hold of filter wheel temperatures: the ; ASCIIized temperature log file is expanded using 'gzip', ; the mean tfw parameters are extracted with 'awk', and values ; appropriate to the image start times are interpolated. ; EXAMPLE: ; n_images=rdhbytes('/jasper/cnsr3_data1/save/93120202.bgs') ; SEE ALSO: ; SHOWRAY.PRO, POCAFLIC.PRO, VIDEO.PRO ; MODIFICATION HISTORY: ; Written by: D P Steele, early 1994. ; Documented by: D P Steele, April 10, 1995. ;- FUNCTION rdhbytes,template COMMON headbytes,oldfname,hbytes,utsec,exptimes,fwtemps,bad_image ; If no argument supplied, show the documentation IF N_PARAMS() NE 1 THEN BEGIN doc_library,'rdhbytes' RETURN,-1 ENDIF ; Load OS-dependent parameters. @isitdos ; Extract the file name from the full path name. Find the last ; directory separator in the path name and copy the characters ; after that point. pathbyte=BYTE(template) ddb=BYTE(dd) ddb=ddb(0) wdd=WHERE(pathbyte EQ ddb,nwdd) fname=STRMID(template,wdd(nwdd-1)+1,STRLEN(template)-wdd(nwdd-1)) IF N_ELEMENTS(oldfname) EQ 0 THEN oldfname='' ; Have these data already been loaded? IF ((fname NE oldfname) AND (template NE oldfname)) $ OR (N_ELEMENTS(hbytes) EQ 0) THEN BEGIN ; If not, then load them. ON_IOERROR,go_on OPENR,hbunit,template,/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) fwtemps=exptimes 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. fwtemps(i)=header.misc.temp.tfw.mean/10. 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='()' GOTO,endloop go_on: IF N_ELEMENTS(bad_image) GT 0 $ THEN bad_image=[bad_image,i] $ ELSE bad_image=[i] endloop: ENDFOR PRINT,FORMAT='()' FREE_LUN,hbunit ; If all filter wheel temperatures are 0, get them from another ; source. Most of the following block of code is taken straight ; from PLOTTLOG.PRO. IF MAX(ABS(fwtemps)) EQ 0 THEN BEGIN MESSAGE,'Getting filter wheel temperatures from temperature log.' $ ,/INFORMATIONAL ; Go to appropriate subdirectory of ~cnsr3/log yd=STRMID(fname,0,2) ; These four lines are new; month=FIX(STRMID(fname,2,2)) ; year, month, and day are day=FIX(STRMID(fname,4,2)) ; not passed in as arguments, cam=FIX(STRMID(fname,6,1)) ; nor is cam. ; Copied code starts here. IF month LT 10 THEN mchar=STRTRIM(month,2) $ ELSE mchar=STRING(BYTE(month-10)+BYTE('a')) suffix=STRING(mchar,day,FORMAT='(A1,I2.2)') path=logroot+dd+yd+dd+suffix CD,path,CURRENT=old_dir ; save the current directory ; Locate the correct file fpath=path+dd+'asctemp*.*' f=rfindfile(fpath,count=nf) IF nf GE 1 THEN f=f(0) ELSE BEGIN MESSAGE,'Cannot find '+fpath,/INFORMATIONAL RETURN,-1 ENDELSE ; If the temperature log file has been gzipped, gunzip it IF STRPOS(f,'z') NE -1 THEN SPAWN,gzipcmd+'-d '+f ; Does the temperature log file actually exist? tlog=rfindfile(fpath,count=ntlog) IF ntlog EQ 1 THEN BEGIN OPENR,logunit,tlog(0),/GET_LUN loginfo=FSTAT(logunit) FREE_LUN,logunit goodfile=(loginfo.SIZE GT 1000) ENDIF ELSE goodfile=0B ; Use 'awk' to extract individual parameter records IF goodfile THEN BEGIN SPAWN,rmcmd+'t*' ; remove any remnants of previous runs SPAWN,rmcmd+'h*' ; breakout_command=awk_cmd+' -f '+awk_src+' '+path ; SPAWN,breakout_command ; run 'awk' to create files for ; ; individual parameters year=header.misc.dt.year month=header.misc.dt.month day=header.misc.dt.day rdtlog,year,month,day,infile=tlog(0),/showtime ; Copied code ends here. ENDIF ELSE MESSAGE,'Something wrong with'+fpath $ ,/INFORMATIONAL SPAWN,gzipcmd+fpath ; recompress temperature log file ; Locate 'tfw?' files produced. tfw=rfindfile(path+dd+'tfw?',count=ntfw) IF ntfw GT 0 THEN tfw=tfw(cam) tmp=ddread(tfw,/formatted) uth=TRANSPOSE(tmp(0,*)) meantfw=TRANSPOSE(tmp(1,*))/10. ; Interpolate with UTSEC in MEANTFW. fwtemps=interpol(meantfw,3600.*uth,utsec) CD,old_dir ENDIF ELSE BEGIN ; Header-derived filter wheel temperatures may have gaps that need ; to be interpolated through. wnz=WHERE(fwtemps,wnz) fwtemps=interpol(fwtemps(wnz),utsec(wnz),utsec) ENDELSE ; Update OLDFNAME. oldfname=fname IF N_ELEMENTS(bad_image) EQ 0 THEN bad_image=[-1] ENDIF ELSE nimages=N_ELEMENTS(utsec) RETURN,nimages END