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

Home » Public Forums » archive » Re: reading unformatted data into a structure
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: reading unformatted data into a structure [message #29723] Wed, 20 March 2002 02:20 Go to previous message
Nigel Wade is currently offline  Nigel Wade
Messages: 286
Registered: March 1998
Senior Member
David Fanning wrote:

> Rick Towler (tsehai@attbi.com) writes:
>
>> I actually want the ASCII characters that the char array refers to.
>> Interestingly, when I do use the string function I get a blank line. I
>> have tried different format statements to no avail.
>>
>> IDL> print,header.datum
>> 0 0 87 71 83 56 52 0 0 0 0 0 0 0 0 0 0 0
>> 0
>> 0 0 0 0 0 0 0 0 0 0 0 0 0
>> IDL> print,string(header.datum)
>>
>
> It's hard to know what this should be. I agree with
> previous posters that you may have structure alignment
> problems. But, typically, if a string were set to bytes
> then blank characters would have the value 32, not 0.
> (I don't know what the ASCII character is for 0B.)
>
> But, if you do this:
>
> IDL> indices = Where(header.datum EQ 0, count)
> IDL> IF count GT 0 THEN header.datum[indices] = 32B
> IDL> Print, String(header.datum)
> WGS84
>
> I don't know why this works, exactly. :-)
>
> Cheers,
>
> David

I think the problem is to do with the way C handles strings. I presume,
from working with DLMs that internally in IDL strings are handled in C.

A string in C is terminated by a null (0) character. So, the above sequence
of bytes would be interpreted as an empty string because of the initial 0,
regardless of what followed it. I am guessing that the actual string begins
in the third element, and the first two bytes are padding. The 8th element,
the next 0, is the string terminator put in by C, and the rest are
unitialised elements in the char array which just happen to be 0s.

If the padding is removed, so the byte array doesn't begin with a 0, then
the converstion to a string should be ok, eg.

IDL> print,a
0 0 87 71 83 56 52 0 0 0 0 0 0 0 0 0 0 0
0 0
IDL> print,string(a(2:*))
WGS84

--
-----------------------------------------------------------
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523568, Fax : +44 (0)116 2523555
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Image editing with IDL?
Next Topic: days of the week

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

Current Time: Fri Oct 10 07:42:55 PDT 2025

Total time taken to generate the page: 1.35780 seconds