Re: STRING(structure) curiosity [message #66065] |
Fri, 10 April 2009 14:15 |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
> No need to use STRING, either. PRINT will take the structure (with a
> format statement or not).
>
That is good to point out, and sufficient for most cases. In my
particular case, though, I am writing the structure to a binary file
(a "FITS ASCII table") using writeu, and so I still need to use the
STRING() function.
--Wayne
|
|
|
Re: STRING(structure) curiosity [message #66066 is a reply to message #66065] |
Fri, 10 April 2009 13:46  |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
wlandsman wrote:
> I am using some old code that applies the STRING function to a
> structure. This surprised me because I didn't think it was possible.
>
> IDL> a = { v1:bindgen(5), v2:!dpi, v3:['idl','structure'] }
> IDL> print,string(a)
> % STRING: Struct expression not allowed in this context: A.
>
> The reason it works in the old code is that it used a format statement
>
> IDL> print,string(a,f='( 5i3, f10.6, 2a10) ')
> 0 1 2 3 4 3.141593 idl structure
>
> So it appears you can apply the STRING function to a structure but you
> *must* then supply a format statement. I actually like this
> behavior, but I can't find it documented anywhere. Applying STRING
> to a structure allows one to efficiently write the structure to an
> ASCII file, but I would think that one would always want to specify
> the format in such a case. --Wayne
No need to use STRING, either. PRINT will take the structure (with a
format statement or not).
IDL> s = replicate({ a: 0.0, b: 0.0, c: 0L}, 10)
IDL> s.a = findgen(10)
IDL> s.b = 10. - findgen(10)
IDL> s.c = indgen(10)
IDL> print, s, format='(%"%f, %f, %d")'
0.000000, 10.000000, 0
1.000000, 9.000000, 1
2.000000, 8.000000, 2
3.000000, 7.000000, 3
4.000000, 6.000000, 4
5.000000, 5.000000, 5
6.000000, 4.000000, 6
7.000000, 3.000000, 7
8.000000, 2.000000, 8
9.000000, 1.000000, 9
Mike
--
www.michaelgalloy.com
Associate Research Scientist
Tech-X Corporation
|
|
|