pro OPEN_an, file,header,dir, times, error = error, rtia=rtia, close=close, image=image, help=help IF KEYWORD_SET(help) THEN BEGIN PRINT,'pro OPEN_an, file,header,dir, times, error = error, rtia=rtia, close=close, image=image, help=help PRINT,' PRINT,'USAGE: OPEN_an, file,header,dir, times PRINT,'Help: OPEN_an, /help prints this message PRINT,' PRINT,'file A string containing the filename to read. If empty then DIALOG_PICKFILE is called. PRINT,' PRINT,'header A structure with data necessary to read the frames Used by get_an PRINT,' header = {marker1:0UL, marker2:0UL, blocksize:0UL, version:0UL, nframes:0UL, width:0UL, Height:0UL, $ PRINT,' bits:0UL, eType:0L, eFormat:0L, infoblocksize:0UL, datablocksize:0UL, frameheadersize:0UL, $ PRINT,' frameblocksize:0UL, diroffset:0LL, dirsize:0UL, roibuff:0UL, timestampsize:0UL, packed:0L, lun:lun } PRINT,' PRINT,'dir A long64 array of pointers for each frame PRINT,' PRINT,'times An array of structures with time information for each frame. PRINT,' times(n) = { year:0, month:0, day:0, hr:0L, minute:0, sec:0, msec:0, usec:0, dhr:0.0} PRINT,' PRINT,'error If non-zero something bad happened. PRINT,' PRINT,'rtia A string(2) describing the image type and format. Ex: ["RTIA_MONOCHROME","RTIA_SHORT"] PRINT,' PRINT,'close If set, the file is closed and the LUN is closed and free after returning the optional image. PRINT,' PRINT,'image If set to a non-zero named varable then the first image in the file is returned. RETURN ENDIF IF N_ELEMENTS(file) EQ 0 THEN file = '' IF file EQ '' THEN BEGIN fname = DIALOG_PICKFILE(file='*.an', /read) IF fname EQ '' THEN RETURN file = fname ENDIF IF file EQ '' THEN BEGIN PRINT,'OPEN_an: No file specified' error = 'OPEN_an: No file specified' RETURN ENDIF error = '' err = 0 rtia = STRARR(2) OPENR,lun,file, /GET_LUN, error=err IF (err NE 0) THEN BEGIN PRINT, !ERROR_STATE.MSG error = !ERROR_STATE.MSG IF N_ELEMENTS(lun) NE 0 THEN BEGIN close, lun FREE_LUN, lun ENDIF lun = 0 RETURN ENDIF header = {marker1:0UL, marker2:0UL, blocksize:0UL, version:0UL, nframes:0UL, width:0UL, Height:0UL, $ bits:0UL, eType:0L, eFormat:0L, infoblocksize:0UL, datablocksize:0UL, frameheadersize:0UL, $ frameblocksize:0UL, diroffset:0LL, dirsize:0UL, roibuff:0UL, timestampsize:0UL, packed:0L, lun:lun } READU, lun, header header.lun = lun help,/str, header ;PRINT, 'File Markers' ;PRINT, header.marker1, header.marker2, FORMAT='(4z)' PRINT,'' IF (header.marker1 NE 'af1ab90d'x ) OR (header.marker2 NE 'ba1ab91d'x ) THEN BEGIN PRINT,'OPEN_an: File marker unrecognised' PRINT,header.marker1, header.marker2, FORMAT='(4z)' error = 'OPEN_an: File marker unrecognised' close, lun FREE_LUN, lun lun = 0 RETURN ENDIF IF (header.version EQ 4) THEN BEGIN PRINT,'OPEN_an: Version 4, ROI, not supported' error = 'OPEN_an: Version 4, ROI, not supported' close, lun FREE_LUN, lun lun = 0 RETURN ENDIF etype = ['monochrome','packed_rgb','monochrome_roi','packed_rgb_roi','roi','planar_rgb', $ 'planar_rgb_roi','bayer_rgb'] rtia(0) = etype(header.eType) eformat =['unsigned_byte','byte','unsigned_short','short','long','float'] rtia(1) = eformat(header.eformat) Dirhead = READ_BINARY(lun, DATA_TYPE=13, DATA_DIMS= 4, DATA_START=header.diroffset) ;print,'Dir markers ' ;print, dirhead(0:1), FORMAT='(4z)' ;PRINT,'Version, Num : ',dirhead(2), dirhead(3) dir = READ_BINARY(lun, DATA_TYPE=14, DATA_DIMS= dirhead(3), DATA_START=header.diroffset+16) ;PRINT,' First Dir: ',DIR(0:4) IF (dirhead(0) NE 'af18e678'x ) OR (dirhead(1) NE 'ab18e679'x ) THEN BEGIN PRINT,'OPEN_an: Dir marker unrecognised ' PRINT,dirhead, FORMAT='(4z)' error = 'OPEN_an: Dir marker unrecognised ' close, lun FREE_LUN, lun lun = 0 RETURN ENDIF time = { year:0, month:0, day:0, hr:0L, minute:0, sec:0, msec:0, usec:0, dhr:0.0} times = REPLICATE(time,dirhead(3)) FOR i=0, dirhead(3)-1 DO BEGIN t = READ_BINARY(lun, data_type=2, data_dims= 13, data_start=dir(i)+4 ) dhr = t(8)+ t(9)/60d0 + t(10)/3600.0 + t(11)/3.6e6 + T(12)/3.6E9 ;print, i, t(4), t(5), t(7), t(8), t(9), t(10),t(11), T(12), dhr times(i).year = t(4) times(i).month = t(5) times(i).day = t(7) times(i).hr = t(8) times(i).minute = t(9) times(i).sec = t(10) times(i).msec = t(11) times(i).usec = t(12) times(i).dhr = dhr + FIX(t(7) - times(0).day)*24 ENDFOR ;stop IF KEYWORD_SET(image) THEN BEGIN framemark = READ_BINARY(lun, data_type=13, data_dims=2, datastart = dir(0)+ header.timestampsize) IF (framemark(0) NE 'af128945'x ) OR (framemark(1) NE 'ab12a946'x ) THEN BEGIN PRINT,'OPEN_an: Frame marker unrecognised ' error = 'OPEN_an: Frame marker unrecognised ' PRINT,framemark, FORMAT='(4z)' close, lun FREE_LUN, lun lun = 0 RETURN ENDIF; framemark offset = header.timestampsize + header.frameheadersize chunks = header.frameblocksize / 3 ; rawdata = READ_BINARY(lun, data_type=1, data_dims=[3,chunks], datastart = dir(0)+ offset) rawdata = BYTARR(3, chunks) point_lun, lun, dir(0)+ offset readu, lun, rawdata image = INTARR(2, chunks) image(0,*) = 16*FIX(rawdata(0,*)) + FIX( rawdata(1,*) AND 'f0'x )/16 image(1,*) = FIX(rawdata(2,*)) + 256*FIX((rawdata(1,*) AND '0f'x )) image = REFORM(image, header.width, header.height) ENDIF; KEYWORD_SET(image) endframe: ;------------------- print info ---------------- month = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'] PRINT,' Opened file ',file date = month(times(0).month)+' '+ STRTRIM(times(0).day,2)+' '+STRTRIM(times(0).year,2) sec = times(0).sec + times(0).msec/1000.0 + times(0).usec/1.0e6 time = STRTRIM(times(0).hr,2)+':'+STRTRIM(times(0).minute,2)+':'+STRING(sec,FORMAT='(f9.6)') timestamp = 'First Frame: '+date + ' '+time PRINT,timestamp nframe = header.nframes -1 date = month(times(nframe).month)+' '+ STRTRIM(times(nframe).day,2)+' '+STRTRIM(times(nframe).year,2) sec = times(nframe).sec + times(nframe).msec/1000.0 + times(nframe).usec/1.0e6 time = STRTRIM(times(nframe).hr,2)+':'+STRTRIM(times(nframe).minute,2)+':'+STRING(sec,FORMAT='(f9.6)') timestamp = 'Last Frame# '+STRTRIM(nframe,2)+': '+date + ' '+time PRINT,timestamp IF keyword_set(close) THEN BEGIN close, lun free_lun, lun lun=0 ENDIF ELSE PRINT,' Assigned to unit '+STRTRIM(lun) END ; pro OPEN_an, file,header,dir, times, error = error, rtia=rtia, close=close, frame=frame