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

Home » Public Forums » archive » IDL XDR Problem
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
IDL XDR Problem [message #9444] Mon, 07 July 1997 00:00
Justin Baker is currently offline  Justin Baker
Messages: 16
Registered: May 1995
Junior Member
Hi there,

I've got a problem with IDL when reading XDR data generated by a C
program.
I can happily read in longs or floats, but IDL gives a strange error
when I try and read in strings.

i.e % READU: Error encountered reading from file. Unit: 1

My program is very simple, for example

...
max_recs = 1000
rec = {i:0, l:0L, f:0.0, s:''}
data = replicate(rec,max_recs)

openr, /XDR, 1, bin_file,ERROR=err

rec_count = 0

while ((rec_count lt max_recs) and (NOT EOF(1))) do begin

readu, 1, rec
data(rec_count) = rec
rec_count = rec_count + 1
endwhile

One clue (that hasn't really helped !) is the IDL v4 user's guide (p
17-33). It demonstrates all that is needed to read XDR data into an IDL
program, but the C code it provides shows strings being written out
using a routine called xdr_counted_string().

Our machine (running AIX) only has xdr_string() and I can't find a
reference to this other routine on any other platforms (such as Sun)
either.


Has anyone else had a similar problem to mine ?


Thanks in advance,
Justin.
Re: IDL XDR Problem [message #9534 is a reply to message #9444] Mon, 07 July 1997 00:00 Go to previous message
jackel[1] is currently offline  jackel[1]
Messages: 11
Registered: May 1997
Junior Member
In article <33C09104.41C6@bom.gov.au> Justin Baker <justinb@bom.gov.au> writes:

> I've got a problem with IDL when reading XDR data generated by a C
> program.
> I can happily read in longs or floats, but IDL gives a strange error
> when I try and read in strings.

Unfortunately, IDL seems to define XDR strings in a peculiar way.
According to the IRIX Network Communications Guide, a string should
have a 4-byte field which gives the length, followed by the string
contents, then enough padding zeros to give a length which is a multiple
of four bytes. Consequently, the string "abcde" would be written (in hex)
as

00 00 00 05 61 62 63 64 65 00 00 00

However, according to the IDL users guide "The length of strings is saved
and restored along with the string". What they seem to mean by this is that
the string length is written _twice_, so "abcde" would be

00 00 00 05 00 00 00 05 61 62 63 64 65 00 00 00

This means that you can't read a standard XDR string in as an IDL string.
You'll need to do some kludge like reading it in as a variable length
byte array (padded to a multiple of four bytes) , then converting it to a
string. Some longword swapping may be required, it's been a while
since I ran across this, and the details are a bit fuzzy. Good luck.

Brian Jackel
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: *writers/seeking/publication
Next Topic: IDL w/ netCDF files

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

Current Time: Thu Oct 09 08:26:58 PDT 2025

Total time taken to generate the page: 2.63858 seconds