function eve_read_dat, filename, status=status, silent=silent, quiet=quiet
status = -1
data = -1
if n_params(0) lt 1 then begin
filename = ' '
read, 'Enter filename to read ? ', filename
if filename eq '' then return, data
endif
get_lun, lun
openit = 0
on_ioerror, openerror
openr,lun, filename
numbers = '0123456789'
silent=keyword_set(silent) or keyword_set(quiet)
on_ioerror, readerror
openit = 1
incomments = 1
sinput = ''
form = ''
struct = ''
while incomments do begin
readf,lun,sinput
sinput = strtrim(sinput,1)
sinputcaps = strupcase(sinput)
if strpos( sinputcaps, 'STRUCT' ) eq 0 then begin
startpos = strpos( sinputcaps, '{' )
endpos = strpos( sinputcaps, '}' )
if (startpos lt 0) or (endpos lt 0) or $
(endpos lt startpos) then begin
if (not(keyword_set(silent))) then print, 'read_dat: Error in STRUCT keyword definition !'
endif else begin
struct = strmid( sinput, startpos, endpos-startpos+1 )
endelse
endif
if strpos( sinputcaps, 'FORMAT' ) eq 0 then begin
startpos = strpos( sinputcaps, '(' )
endpos = strpos( sinputcaps, ')' )
if (startpos lt 0) or (endpos lt 0) or $
(endpos lt startpos) then begin
if (not(keyword_set(silent))) then print, 'read_dat: Error in FORMAT keyword definition !'
endif else begin
form = strmid( sinput, startpos, endpos-startpos+1 )
endelse
endif
if strpos( numbers, strmid(sinput,0,1) ) ge 0 then $
incomments = 0
endwhile
nlines = long( sinput )
n = strlen(sinput)
k = 1
innumber = 1
numberstr = '0123456789 /.,<>?;:\|=+-_)(*&^%$#@!~'
while innumber do begin
if strpos( numberstr, strmid(sinput,k,1) ) lt 0 then begin
if (k lt n-1) and (not(keyword_set(silent))) then begin
print, ' ', filename, ' : ', strmid(sinput,k,n-k)
endif
innumber = 0
endif else begin
k = k + 1
if k ge n-2 then innumber = 0
endelse
endwhile
readf,lun,sinput
sinput = strtrim(sinput,1)
ncolumns = long( sinput )
n = strlen(sinput)
k = 1
innumber = 1
while innumber do begin
if strpos( numberstr, strmid(sinput,k,1) ) lt 0 then begin
if (k lt n-1) and (not(keyword_set(silent))) then begin
print, ' ', filename, ' : ', strmid(sinput,k,n-k)
endif
innumber = 0
endif else begin
k = k + 1
if k ge n-2 then innumber = 0
endelse
endwhile
form = '$' + form
if strlen(struct) le 2 then begin
data = dblarr(ncolumns, nlines)
if strlen(form) le 2 then readf,lun,data else $
readf,lun,form,data
status = 0
data=reform(data)
tmp=where(data mod 1ULL gt 0,n_float)
if n_float eq 0 then begin
datamax=max(data,min=datamin)
if datamin ge 0 then begin
if datamax gt 2UL^32-1 then data=ulong64(data) else $
if datamax gt 2UL^16-1 then data=ulong(data) else $
if datamax gt 255 then data=uint(data) else $
data=byte(data)
endif else begin
if datamax gt 2UL^32-1 then data=long64(data) else $
if datamax gt 2UL^16-1 then data=long(data) else $
data=fix(data)
endelse
endif
goto, cleanup
endif else begin
acmd = execute( 'temp = ' + struct )
data = replicate( temp, nlines )
if strlen(form) le 2 then readf,lun,data else $
readf,lun,form,data
ntags = n_tags(data)
tnames = tag_names(data)
for i=0,ntags-1 do begin
asize = size( data.(i) )
if (asize(asize(0)+1) eq 7) then begin
if (not(keyword_set(silent))) then print, 'read_dat: Compressing strings for DATA.' + tnames(i)
data.(i) = strtrim( data.(i), 2 )
endif
endfor
status = 0
goto, cleanup
endelse
openerror:
print, 'ERROR: READ_DAT() could not open ' + filename
goto,cleanup
readerror:
print, 'ERROR: READ_DAT() had a read error for ' + filename
cleanup:
if (not(keyword_set(silent))) then print, ' '
on_ioerror, NULL
if openit then close,lun
free_lun, lun
return, data
end