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

Home » Public Forums » archive » How to create a varying variable?
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
How to create a varying variable? [message #89388] Mon, 06 October 2014 07:13 Go to next message
atmospheric physics is currently offline  atmospheric physics
Messages: 121
Registered: June 2010
Senior Member
Hello,

I want to create a varying variable, 'varJJJ' as below:

varJJJ = FLTARR(nc,nr)

Here JJJ = STRING(indgen(101),FORMAT='(I03)')

Is this possible? Can anyone have a better suggestion?

Thanks in advance,
Madhavan
Re: How to create a varying variable? [message #89389 is a reply to message #89388] Mon, 06 October 2014 07:25 Go to previous messageGo to next message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
This discussion ultimately ends with the Execute command, which most agree is a very bad option for naming variables. Instead, try using a list, structure, or concatenated array:

;List
myList = list()
myList(1) -> Add, fltarr(nc, nr)
myList(2) -> Add, fltarr(nc, nr)

;Array
myArr = [[[fltarr(nc, nr)]], [[fltarr(nc, nr)]]]

;Structure
myStruct = create_struct('Tag1', fltarr(nc, nr), 'Tag2', fltarr(nc, nr))
Re: How to create a varying variable? [message #89390 is a reply to message #89389] Mon, 06 October 2014 07:33 Go to previous messageGo to next message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
> ;List
> myList = list()
> myList(1) -> Add, fltarr(nc, nr)
> myList(2) -> Add, fltarr(nc, nr)

Typo. Should be

;List
myList = list()
myList -> Add, fltarr(nc, nr)
myList -> Add, fltarr(nc, nr)


I suppose you could also create a hash

;Hash
myHash = hash()
myHash('Key1') = fltarr(nc, nr)
myHash('Key2') = fltarr(nc, nr)
Re: How to create a varying variable? [message #89394 is a reply to message #89388] Mon, 06 October 2014 08:26 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
On 10/06/14 10:13, Madhavan Bomidi wrote:
> Hello,
>
> I want to create a varying variable, 'varJJJ' as below:
>
> varJJJ = FLTARR(nc,nr)
>
> Here JJJ = STRING(indgen(101),FORMAT='(I03)')
>
> Is this possible? Can anyone have a better suggestion?
>
> Thanks in advance,
> Madhavan

First thing that occurs to me is: why?

I'm not trying to be obstreperous, just asking for some context since
this sort of request is usually more of a design issue than a language one.

cheers,

paulv


p.s. And, FWIW, Matthew's suggestion using a hash is what I would
recommend since you can use the dynamic "JJJ" to access the particular
value that you want. E.g.

IDL> h=hash()

Use string of number:

IDL> jjj='101'
IDL> h[jjj] = findgen(20,10)
IDL> help, h['101']
<Expression> FLOAT = Array[20, 10]

Or use actual number (why convert to string?):

IDL> nnn=101
IDL> h[nnn] = dindgen(14)
IDL> help, h[101]
<Expression> DOUBLE = Array[14]

where, as you can see, h['101'] and h[101] reference different values in
the hash.

If you have an older version of IDL (i.e. no hashes) then you could put
together something similar using pointer arrays.

All of the plumbing (for either methodology) could then be wrapped up
into "Init", "Set" and "Get" functions so your code is protected from
the implementation details.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Problem with mpfit (possibly a string length issue)
Next Topic: How can i write Δ in Y axis

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

Current Time: Wed Oct 08 11:44:52 PDT 2025

Total time taken to generate the page: 0.00431 seconds