String array Read and Write [message #87151] |
Fri, 10 January 2014 21:09  |
Gompie
Messages: 76 Registered: August 2012
|
Member |
|
|
Hi,
I get garbage when I read in a array of strings that I had written using the following code
openw, lun, 'test.dat', /get_lun
afilename=bytarr(256,N)
read in N afilenames...
afilenames_temp=string(afilename(0:255,N) )
writeu, lun,afilenames_temp(0:N-1)
close,lun
* Here If I give pring afilenames_temp(0:10) I get first 11 file complete names
Looks like afilenames_temp has all the info that I needed to store in it and I should have written it into the binary file...
However when I read test.dat with the following code I get garbage.
openr, lun, 'test.dat', /get_lun
afile = string(lengths+1)
readu, lun,afile
Can anybody help...
GlanPlon !!
|
|
|
Re: String array Read and Write [message #87153 is a reply to message #87151] |
Fri, 10 January 2014 21:36  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Gompie writes:
> I get garbage when I read in a array of strings that I had written using the following code
>
> openw, lun, 'test.dat', /get_lun
>
> afilename=bytarr(256,N)
>
> read in N afilenames...
>
> afilenames_temp=string(afilename(0:255,N) )
>
>
> writeu, lun,afilenames_temp(0:N-1)
> close,lun
> * Here If I give pring afilenames_temp(0:10) I get first 11 file complete names
> Looks like afilenames_temp has all the info that I needed to store in it and I should have written it into the binary file...
>
> However when I read test.dat with the following code I get garbage.
>
>
> openr, lun, 'test.dat', /get_lun
> afile = string(lengths+1)
> readu, lun,afile
>
> Can anybody help...
Strings are difficult to write in a binary file since they have an
undefined length in IDL. Try setting the XDR keyword on your OPENW
command and giving them a defined length when reading them.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|