Re: not sure what to call this request [message #30420] |
Wed, 24 April 2002 16:48 |
Robert Stockwell
Messages: 74 Registered: October 2001
|
Member |
|
|
starr=['yes','you','can'] & result = execute('print,"'+starr[0]+' '+starr[1]+' '+starr[2]+'"')
Chad Bahrmann wrote:
> I am not sure what to call this request:
>
> Is this possible in IDL...I can not seem to make it work...If not any work
> arounds?
>
> IDL> vars=['tsoil_W']
> IDL> data={vars[0]:{attname:STRARR(6)}}
>
> data={vars[0]:{attname:STRARR(6)}}
> ^
> % Syntax error.
>
> without having to do
> data={tsoil_W:{attname:STRARR(6)}}
> because ultimately I will have a 26 vars that I would like to build
> structures for
>
>
>
|
|
|
Re: not sure what to call this request [message #30421 is a reply to message #30420] |
Wed, 24 April 2002 15:18  |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
Chad Bahrmann wrote:
>
> I am not sure what to call this request:
>
> Is this possible in IDL...I can not seem to make it work...If not any work
> arounds?
>
> IDL> vars=['tsoil_W']
> IDL> data={vars[0]:{attname:STRARR(6)}}
>
> data={vars[0]:{attname:STRARR(6)}}
> ^
> % Syntax error.
>
> without having to do
> data={tsoil_W:{attname:STRARR(6)}}
> because ultimately I will have a 26 vars that I would like to build
> structures for
What exactly do you want to do? Be able to access structures components without referencing the
tag name?
Off the top of me head, you could try:
IDL> vars = [ 'tsoil_W', 'tsoil_X', 'tsoil_Y', 'tsoil_Z' ]
First create the structure with the first component:
IDL> data = CREATE_STRUCT( vars[0], {attname:STRARR(6)} )
IDL> HELP, data.tsol_w, /STRUCT
** Structure <823df34>, 1 tags, length=72, data length=72, refs=2:
ATTNAME STRING Array[6]
Now you've got yer structure started, concatenate away.....
IDL> FOR i = 1, N_ELEMENTS( vars ) - 1 DO data = CREATE_STRUCT( data, vars[i],
{attname:STRARR(6)} )
IDL> HELP, data, /STRUCT
** Structure <823f38c>, 4 tags, length=288, data length=288, refs=1:
TSOIL_W STRUCT -> <Anonymous> Array[1]
TSOIL_X STRUCT -> <Anonymous> Array[1]
TSOIL_Y STRUCT -> <Anonymous> Array[1]
TSOIL_Z STRUCT -> <Anonymous> Array[1]
So now if you want to know what the attributes of, say, tsoil_X are:
IDL> loc = WHERE( vars EQ 'tsoil_X' )
IDL> HELP, data.(loc[0]), /STRUCT
** Structure <823e91c>, 1 tags, length=72, data length=72, refs=2:
ATTNAME STRING Array[6]
Pretty cool I reckon. And the above way is probably one of the more brain dead ways of doing
it. I mean, it uses concatenation *and* a loop..... sheesh :o)
paulv
--
Paul van Delst Religious and cultural
CIMSS @ NOAA/NCEP purity is a fundamentalist
Ph: (301)763-8000 x7274 fantasy
Fax:(301)763-8545 V.S.Naipaul
|
|
|