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

Home » Public Forums » archive » Re: SPAWN + readU + strings
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: SPAWN + readU + strings [message #19727] Mon, 17 April 2000 00:00
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Ramji Digumarthi (ramji.digumarthi@lmco.com) writes:

\> I am having problem reading strings from spawned child process (a
> C-routine). I can read variables (using ReadU :: thanks to comment from
> David Fanning on pipes being binary). BUT if i read a string using
> readu, the reading variables from child process go haywire... WHY???
> HOW does the readU function treat the string variable??
> any suggestions???

You are probably having trouble because you don't know the
length of the string variables you are trying to read.
String variables are always problems in binary files (or
when reading from a binary pipe) because if you don't know
how many bytes to read, you can't read them properly.
And since a string can be virtually *any* length or number
of bytes in IDL (unlike a float which is always four bytes
in length), you *must* know if you want to read it.

The rule in IDL is that it reads the *current* number of
bytes in the string. So if I do this:

stringVar = 'Bob'
ReadU, lun, stringVar

I read 3 bytes. If I do this:

stringVar = 'Bobby'
ReadU, lun, stringVar

I read 5 bytes, etc.

What I recommend is that your C program write the length
of the string, followed by the string. Then you can read
it in IDL like this:

len = 0L
ReadU, lun, len
stringVar = String(BytArr(len))
ReadU, lun, stringVar

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
[Message index]
 
Read Message
Previous Topic: Happy ending: compiling libraries for call_external() on the Mac
Next Topic: Compressed 1-bit Tiff reader for IDL

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

Current Time: Thu Oct 09 07:19:24 PDT 2025

Total time taken to generate the page: 2.15797 seconds