comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » String array Read and Write
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
String array Read and Write [message #87151] Fri, 10 January 2014 21:09 Go to next message
Gompie is currently offline  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 Go to previous message
David Fanning is currently offline  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.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Overplot cgplot on Function Graphic Plot
Next Topic: Active main program terminated by call to DELVAR when using Delvar

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:39:36 PDT 2025

Total time taken to generate the page: 0.00450 seconds