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

Home » Public Forums » archive » Re: readf and structures
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: readf and structures [message #53482 is a reply to message #53481] Tue, 10 April 2007 08:34 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Wox writes:

> Is there an easy way of printing arrays of structures to a file and
> read them in again, without reading the fields separate?
>
> This doesn't work (also tried with specifying formats):
>
> tout={a:0.,b:'name'}
> tin={a:0.,b:''}
>
> openw,lun,'c:\test.txt',/get_lun
> printf,lun,tout
> close,lun
> free_lun,lun
>
> openr,lun,'c:\test.txt',/get_lun
> readf,lun,tin
> close,lun
> free_lun,lun

This basically doesn't work because you have a string field.
All variables in IDL have a defined length, EXCEPT strings.
Thus, unless you can tell IDL how long your strings are,
it just keeps reading until it gets to the end of an input
line.

One way to tell IDL how long your strings are is to use
the XDR format for input/output. Thus, these commands would
work for you:

tout={a:0.,b:'name'}
tin={a:0.,b:''}

openw,lun,'test.txt',/get_lun, /xdr
writeu,lun,tout
free_lun,lun

openr,lun,'test.txt',/get_lun, /xdr
readu,lun,tin
free_lun,lun

Note that there is no need to have a CLOSE statement in your
code. FREE_LUN both closes the logical unit and frees it up
for future use.

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: basic question about graphic devices
Next Topic: Variable sized bins in histogram, or find a bounding lat/lon box

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

Current Time: Wed Oct 08 19:24:26 PDT 2025

Total time taken to generate the page: 0.00394 seconds