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

Home » Public Forums » archive » Re: Writing a structure containing empty strings
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
Re: Writing a structure containing empty strings [message #49595] Mon, 07 August 2006 15:15
Wayne Landsman is currently offline  Wayne Landsman
Messages: 117
Registered: January 1997
Senior Member
> Do FITS files really want non-zero terminated strings in all cases except
> for 0 length strings? Pretty strange.

Yeah, that's what it wants. A possible rationale is that this way it can
distinguish between a null string (0b) and a string column with zero values
(nothing written at all). --Wayne
Re: Writing a structure containing empty strings [message #49597 is a reply to message #49595] Mon, 07 August 2006 14:34 Go to previous message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Mon, 07 Aug 2006 08:12:58 -0700, Wayne Landsman wrote:

> This message and the next one address long-standing problems I've had
> with IDL software to handle the FITS data format used in astronomy.
>
> When writing an IDL structure, str, to FITS format, the following
> simple code *almost* works.
>
> openw,lun, 'output.dat',/get_lun
> writeu,lun, str
> free_lun, lun
>
> The only problem occurs if one of the structure tags contains an empty
> string. What I want is for IDL to write a zeroed byte (0b), but IDL
> simply ignores the tag and doesn't write anything. Note that IDL
> does understand 0b as the byte representation of an empty string:
>
> IDL> print,strlen(string(0b))
> 0
> IDL> print,byte('')
> 0
>
> but it simply skip over an empty string when performing I/O. So my
> first thought is to convert the string tags to bytes, but this has two
> problems: (1) one can't directly change the data type of a structure
> tag and (2) converting a string array to byte forces everything to a
> fixed length. So right now, I loop over every element and every tag
> of the structure and write it to disk:, if it is a string tag I test
> for the presence of an empty string, and then further loop over the
> string array to convert every element to a byte array before writing to
> disk. So simple code that *almost* works, requires a major revision
> to completely work. Or am I missing a simpler solution?

The manual has this to say:

When writing fields containing strings with the unformatted procedure
WRITEU, IDL writes each character of the string and does not append a
terminating null byte.

Since it's not appending \0 to any string, having it do so only in the
special case of a zero-length string would actually be surprising. It's
not ignoring the string, it's realizing it contains zero bytes and writing
out zero bytes. On input, it would read in those zero bytes again ;).

Do FITS files really want non-zero terminated strings in all cases except
for 0 length strings? Pretty strange.

JD
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: CXFORM on WinXP
Next Topic: A smarter way to do this...

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

Current Time: Wed Oct 08 10:57:07 PDT 2025

Total time taken to generate the page: 0.00489 seconds