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

Home » Public Forums » archive » structure references
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
structure references [message #86751] Sun, 01 December 2013 10:33 Go to next message
spluque is currently offline  spluque
Messages: 33
Registered: September 2013
Member
Hi,

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

Is writing a loop over the tags the only way?

Cheers,

--
Seb
Re: structure references [message #86752 is a reply to message #86751] Sun, 01 December 2013 11:38 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Seb writes:

> 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
>
> Is writing a loop over the tags the only way?

If all elements of your structure are the same data type, why aren't you
using an array?

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: structure references [message #86754 is a reply to message #86752] Sun, 01 December 2013 11:46 Go to previous messageGo to next message
spluque is currently offline  spluque
Messages: 33
Registered: September 2013
Member
On Sun, 1 Dec 2013 12:38:34 -0700,
David Fanning <news@idlcoyote.com> wrote:

> Seb writes:
>> 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

>> Is writing a loop over the tags the only way?

> If all elements of your structure are the same data type, why aren't
> you using an array?

I'd like to have easier access to the elements of such array. It would
make life much simpler to be able to call a particular element by name
(e.g. tag) than by array index. Several routines need to access to
these data, so using an array index for each element soon makes code
hard to read.

Thanks,

--
Seb
Re: structure references [message #86756 is a reply to message #86754] Sun, 01 December 2013 11:49 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Seb writes:

> I'd like to have easier access to the elements of such array. It would
> make life much simpler to be able to call a particular element by name
> (e.g. tag) than by array index. Several routines need to access to
> these data, so using an array index for each element soon makes code
> hard to read.

"Ah," he says, as he shakes his head.

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: structure references [message #86757 is a reply to message #86751] Sun, 01 December 2013 11:52 Go to previous messageGo to next message
wlandsman is currently offline  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 Go to previous messageGo to next message
spluque is currently offline  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 #86763 is a reply to message #86761] Sun, 01 December 2013 20:44 Go to previous messageGo to next message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
> 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
Re: structure references [message #86824 is a reply to message #86763] Thu, 05 December 2013 11:20 Go to previous message
spluque is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Reading ERDAS IMAGINE
Next Topic: Multiple color plots, same color bar

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

Current Time: Wed Oct 08 09:20:45 PDT 2025

Total time taken to generate the page: 0.00504 seconds