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

Home » Public Forums » archive » Re: idlastro mrdfits and 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: idlastro mrdfits and strings [message #68608] Thu, 12 November 2009 17:58
Chris Thom is currently offline  Chris Thom
Messages: 2
Registered: November 2009
Junior Member
On Nov 12, 12:40 pm, wlandsman <wlands...@gmail.com> wrote:

> where IDL does not include a terminating null byte for the string tags
> when writing a structure to disk.     So to do this correctly, one has
> to convert the string tags in a structure to bytes, which means
> creating an entirely new structure (since one can't change data types
> of a structure element), greatly slowing things down and complicating
> the code.   It is a fix that I should do sometime, but I am not in a
> hurry to do so.  (But I will document this bug/feature better.)

Ahh, I see. Thanks for the info. Seems like a strange interaction
between the quirks of idl and the quirks of the FITS format.

> If you are sure that you don't care about leading/trailing spaces, you
> could apply the following function right after the call to mrdfits()
>
> function trimstruct,str
> ; Trim each string element of a structure, assume there are not
> substructures
> N= N_tags(str)
> for i=0,n-1 do $
>     if size(str.(i),/tname) EQ 'STRING' then str.(i) = strtrim(str.(i),
> 2)
> return
> end

HA! After I posted the first message, I wrote some code that is almost
identical to this. Well, ok...mine was a little less elegant, but it's
functionally identical.

> (Actually, it would be nice if one could apply strtrim() directly to a
> structure to do this.)   --Wayne

yup...I tried that too, just to see what would happen. :)

thanks
chris
Re: idlastro mrdfits and strings [message #68614 is a reply to message #68608] Thu, 12 November 2009 09:40 Go to previous message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Nov 11, 3:58 pm, Chris Thom <christ...@gmail.com> wrote:

> I'm not sure if these tags are being padded in the write or the read
> phase, but it'd be nice if there was a way to trim these tags on read.
> Or is there some reason this is a bad idea?

The tags are being padded in the write. The problem is related to
one I discussed earlier

http://groups.google.com/group/comp.lang.idl-pvwave/browse_f rm/thread/95e19b78119ab265/41b6775e8ae24ffe

where IDL does not include a terminating null byte for the string tags
when writing a structure to disk. So to do this correctly, one has
to convert the string tags in a structure to bytes, which means
creating an entirely new structure (since one can't change data types
of a structure element), greatly slowing things down and complicating
the code. It is a fix that I should do sometime, but I am not in a
hurry to do so. (But I will document this bug/feature better.)

> The work-around (sprinkling strtrim()s throughout the code) is
> functional if a little ugly.

If you are sure that you don't care about leading/trailing spaces, you
could apply the following function right after the call to mrdfits()

function trimstruct,str
; Trim each string element of a structure, assume there are not
substructures
N= N_tags(str)
for i=0,n-1 do $
if size(str.(i),/tname) EQ 'STRING' then str.(i) = strtrim(str.(i),
2)
return
end

(Actually, it would be nice if one could apply strtrim() directly to a
structure to do this.) --Wayne
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Use the device fonts for Ytitle on screen
Next Topic: Re: Savitzky-Golay filter

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

Current Time: Wed Oct 08 15:06:06 PDT 2025

Total time taken to generate the page: 0.00509 seconds