Re: problem with arrays of structures [message #10599] |
Wed, 07 January 1998 00:00 |
Martin Schultz
Messages: 515 Registered: August 1997
|
Senior Member |
|
|
Theo Brauers wrote:
>
> Hi.
>
> I was trying to copy the contents of an array to an
> element of an array of structures:
>
> FUNCTION test2, str
> r = { a: '', b:1.}
> i=n_elements(str)
> r2 = replicate(r, i)
> help, r2, r2.a
> r2.a=str ; <----------
> r2.b=float(str)
> return, r2
> END
>
> works fine with
> x=test2('100')
> x=test2(['100', '101'])
>
> but fails with
> x=test2(['100'])
>
> Whats am I doing wrong? Or does IDL wrong with
> array of one element?
>
Hi Theo,
you have to use str(0) in the case of 1 element. Replace the marked
lines with
if (i gt 1) then r2.a=str else r2.a=str(0)
if (i gt 1) then r2.b=float(str) else r2.b=float(str(0))
BTW: you are here quite frequently now. Is Franz R. not around ? ;-)
Martin.
------------------------------------------------------------ -------
Dr. Martin Schultz
Department for Earth&Planetary Sciences, Harvard University
186 Pierce Hall, 29 Oxford St., Cambridge, MA-02138, USA
phone: (617)-496-8318
fax : (617)-495-4551
e-mail: mgs@io.harvard.edu
IDL-homepage: http://www-as.harvard.edu/people/staff/mgs/idl/
------------------------------------------------------------ -------
|
|
|
Re: problem with arrays of structures [message #10601 is a reply to message #10599] |
Wed, 07 January 1998 00:00  |
Michael Werger
Messages: 34 Registered: May 1997
|
Member |
|
|
Theo Brauers wrote:
> Hi.
>
> I was trying to copy the contents of an array to an
> element of an array of structures:
>
> FUNCTION test2, str
> r = { a: '', b:1.}
> i=n_elements(str)
> r2 = replicate(r, i)
> help, r2, r2.a
> r2.a=str
> r2.b=float(str)
> return, r2
> END
>
> works fine with
> x=test2('100')
> x=test2(['100', '101'])
>
> but fails with
> x=test2(['100'])
>
Replace
r= { a:'',b:1.}
with
r = { a:[''],b:[1.]}
Then you need not to worry about your input (but probably of your output
;-( )
Cheers,
--
Michael Werger ESA ESTEC & Praesepe B.V.
Astrophysics Division mwerger@estec.esa.nl
Postbus 299 http://astro.estec.esa.nl
2200 AG Noordwijk +31 71 565 3783 (Voice)
The Netherlands +31 71 565 4690 (FAX)
|
|
|