|
|
|
|
Re: structure references [message #86757 is a reply to message #86751] |
Sun, 01 December 2013 11:52   |
wlandsman
Messages: 743 Registered: June 2000
|
Senior Member |
|
|
On Sunday, December 1, 2013 1:33:03 PM UTC-5, Sebastian Luque wrote:
> Hi,
>
In general, a structure contains elements of different types (e.g. string types) so
x.(*)=20
isn't allowed. Instead of a structure, you might look at the HASH() syntax which allows one to specify multiple hashes in a single call:
IDL> a = hash('a',double(0),'b',double(0), c:'string' )
IDL> a[['a','b']] = 20.0d
IDL> print,a
c: string field
a: 20.000000
b: 20.000000
>
> While trying to set all elements of a structure to a value, I read
>
> http://www.exelisvis.com/docs/Structure_References.html and it seems
>
> this is not possible with a simple operation like:
>
>
>
> x={a:double(0), b:double(0)}
>
> x.(*)=20
>
|
|
|
Re: structure references [message #86761 is a reply to message #86757] |
Sun, 01 December 2013 17:18   |
spluque
Messages: 33 Registered: September 2013
|
Member |
|
|
On Sun, 1 Dec 2013 11:52:25 -0800 (PST),
wlandsman <wlandsman@gmail.com> wrote:
> On Sunday, December 1, 2013 1:33:03 PM UTC-5, Sebastian Luque wrote:
>> Hi,
> In general, a structure contains elements of different types
> (e.g. string types) so
> x.(*)=20
> isn't allowed. Instead of a structure, you might look at the HASH()
> syntax which allows one to specify multiple hashes in a single call:
IDL> a = hash('a',double(0),'b',double(0), c:'string' ) a[['a','b']] =
IDL> 20.0d print,a
> c: string field a: 20.000000 b: 20.000000
Thanks, hashes do seem attractive for these purposes, however it's a
relatively new data type, so would require major changes in other parts
of the code. I might have to bite the bullet and stick to arrays, and
having code that looks like this:
FUNCTION FOO, A
return, [A*2, A^2, A^0.5]
END
;; Option 1
PRO BAR, B
x=foo(b)
x_dbl=x[0]
x_sqr=x[1]
x_sqrt=x[2]
... LOTS OF OPERATIONS WITH x_dbl, x_sqr, x_sqrt, x[*]
END
;; Option 2
PRO BAR, B
x=foo(b)
... LOTS OF OPERATIONS WITH x[0], x[1], x[2], x[*]
END
No problem, I personally prefer something like the latter but with a
little more meaningful nomenclature.
--
Seb
|
|
|
|
Re: structure references [message #86824 is a reply to message #86763] |
Thu, 05 December 2013 11:20  |
spluque
Messages: 33 Registered: September 2013
|
Member |
|
|
On Sunday, December 1, 2013 10:44:14 PM UTC-6, Matthew Argall wrote:
>> FUNCTION FOO, A
>
>>
>
>> return, [A*2, A^2, A^0.5]
>
>>
>
>> END
>
>
>
>
>
> Why not this?
>
>
>
> PRO FOO, A, TwoA, ASquare, ASqrt
>
> TwoA = 2*A
>
> ASquare = A^2
>
> ASqrt = Sqrt(A)
>
> END
Thanks, this is probably the best thing to do. I have about 25 variables that would be output from FOO, so it would require a lengthy call.
Cheers,
Seb
|
|
|