Hello, all.
I'm trying to create binary data files that have an ascii header followed by a
string(12b) (a control-L, so that I can use 'more' to view just the headers), a
string(10b) (a return character), and then the binary data. For example,
pro test_write
arr=bytarr(256,256,36) ; thirty-six 256x256 images
openw,unit,'test.dat',/get_lun
printf,unit,'header'
printf,unit,'information'
printf,unit,'here...'
printf,unit,string(12b)
writeu,unit,arr
close,unit
free_lun,unit
return
end
Creating them seems to present no problem; it's in reading them that I get hosed:
function test_read
openr,unit,'test.dat',/get_lun
str=''
readf,unit,str ; read string 'header'
readf,unit,str ; read string 'information'
readf,unit,str ; read string 'here...'
; now skip over the ^L and return characters...
char=0b
if not (eof(unit)) then repeat readu,unit,char until ((char eq 10b) or (eof(unit))
; file pointer should now be pointing to first byte of binary data...
if (eof(unit)) then begin
print,'premature eof.'
close,unit
free_lun,unit
return,-1
endif else begin
arr=bytarr(256,256,36)
readu,unit,arr
close,unit
free_lun,unit
return,arr
endelse
end
There is often no eof() error; all data seems to be read ok, until I step through
my 36 images. Each image is column shifted by some amount (the same for each
image).
Any help? Is my error in combining printf & writeu or readf & readu?
thanks,
matthew
____________________
mtadams@columbine.hsc.colorado.edu
Matthew T. Adams
University of Colorado Health Sciences Center
4200 E 9th Ave, C268-68
Denver, CO 80262
|