[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
writeu, printf, readu/f 2 file
- Subject: writeu, printf, readu/f 2 file
- From: "Sean Heukels" <sean77=cuthere=(at)dds.nl>
- Date: Tue, 13 Mar 2001 16:56:35 +0100
- Newsgroups: comp.lang.idl-pvwave
- Organization: Academic Computer Centre Utrecht, (ACCU)
- Xref: news.doit.wisc.edu comp.lang.idl-pvwave:23962
Can writeu, and printf be combined ?? in one write action.
Or is it the one or the other ?
I've been trying everything. The whole day and it still doesn't work.
What I want to do is write some txt and variables, that define
the following data block and ofcourse the time and location, etc
In the header. But somehow, the firt line reads fine, but after that
everything is garbled.
I think it has something to do with the different write/read statements
See sample code that is not working
I save a file with :
PRO SAVE_FILE, img, struct, outfile
if (NOT KEYWORD_SET(outfile) OR (outfile eq '')) then RETURN
if (NOT KEYWORD_SET(img)) then MESSAGE, 'Structure must be added :img'
if (NOT(STRMID(outfile, STRLEN(outfile)-3, 3) eq 'dif')) then
outfile=outfile+'.dif'
temp=string(systime())
tiepe = "dif";
versie = 1.0;
HEADERSTRUCT = {HEADERSTRUCT, filename:struct.filename, file:struct.file,
description:struct.description, date:temp, Location:"Invivonmr Utrecht"}
TXTSTRUCT = {TXTSTRUCT, orient:struct.orient, view:struct.view,
plot:struct.plot}
VARSTRUCT = {VARSTRUCT, ft:struct.ft, lro:struct.lro, lpe:struct.lpe,
te:struct.te, tr:struct.tr, ti:struct.ti, nro:struct.nro, npe:struct.npe, $
ns:struct.ns, nt:struct.nt, zf:struct.zf, zff_nro:struct.zff_nro,
zff_npe:struct.zff_npe, pss:struct.pss, thk:struct.thk, raw:struct.raw}
openw, unit, outfile, /get_lun ; Open file
point_lun, unit, 0L
; Point it at the start
printf, unit, tiepe
printf, unit, HEADERSTRUCT
printf, unit, versie
printf, unit, TXTSTRUCT
printf, unit, VARSTRUCT
for slice=0, struct.ns-1 do begin ; Slice loop
for tp=0, struct.nt-1 do begin ; Time-point loop
for np=0,struct.npe-1 do begin ; Multi-slice loop
writeu, unit, struct.data(*, np, tp, slice) ; Write the block header
endfor
endfor
endfor
free_lun, unit
UNDEFINE, TYPE
UNDEFINE, VERSION
UNDEFINE, HEADERSTRUCT
UNDEFINE, TXTSTRUCT
UNDEFINE, VARSTRUCT
struct.raw=0
img.saved=1
img.filename=outfile
RETURN
END
AND READ WITH :
PRO READ_FILE, img, struct, infile
if (NOT KEYWORD_SET(infile) OR (infile eq '')) then RETURN
if (NOT KEYWORD_SET(img)) then MESSAGE, 'Structure must be added :img'
tiepe = ''
versie = 0.0
HEADERSTRUCT = {HEADERSTRUCT, filename:'', file:'', description:'', date:'',
Location:''}
TXTSTRUCT = {TXTSTRUCT, orient:'', view:'', plot:''}
VARSTRUCT = {VARSTRUCT, ft:0, lro:0.0, lpe:0.0, te:0.0, tr:0.0, ti:0.0,
nro:0, npe:0, ns:0, nt:0, zf:0, zff_nro:0, zff_npe:0, pss:0.0, thk:0.0,
raw:0}
openr, unit, infile, /get_lun
point_lun, unit, 0L
readf, unit, tiepe
readf, unit, HEADERSTRUCT
readf, unit, versie
if (NOT (tiepe eq 'dif')) then begin
img.error='Sorry, only .dif files can be opened. .fids must be imported'
free_lun, unit
RETURN
endif
if (versie gt 1.0) then begin
img.error='File version exceeds this modules read capatibilty.
Version:'+format(TYPE)
free_lun, unit
RETURN
ENDIF
help, tiepe, versie
help, HEADERSTRUCT, /st
readf, unit, TXTSTRUCT
readf, unit, VARSTRUCT
NEW_FID, struct, VARSTRUCT.nro, VARSTRUCT.npe, VARSTRUCT.nt, VARSTRUCT.ns
all_tags = TAG_NAMES(HEADERSTRUCT)
for w=0, N_ELEMENTS(all_tags)-1 do begin
if (all_tags[w] ne 'data') then struct.(w) = HEADERSTRUCT.(w)
endfor
all_tags = TAG_NAMES(TXTSTRUCT)
for w=0, N_ELEMENTS(all_tags)-1 do begin
if (all_tags[w] ne 'data') then struct.(w) = TXTSTRUCT.(w)
endfor
all_tags = TAG_NAMES(HEADERSTRUCT)
for w=0, N_ELEMENTS(all_tags)-1 do begin
if (all_tags[w] ne 'data') then struct.(w) = VARSTRUCT.(w)
endfor
for slice=0, struct.ns-1 do begin ; Slice loop
for tp=0, struct.nt-1 do begin ; Time-point loop
for np=0,struct.npe-1 do begin ; Multi-slice loop
readu, unit, struct.data(*, np, tp, slice); Write the block header
endfor
endfor
endfor
free_lun, unit
img.filename=infile ; Set for the img structure
img.slice=1
img.timepoint=1
img.saved=1
END
BUt its not working
Any help appreciated
greets Sean