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

Home » Public Forums » archive » Re: accessing variables with their string names
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
Re: accessing variables with their string names [message #10664] Fri, 19 December 1997 00:00
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
Natalie Rooney wrote:
>
> Hello. I'm trying to create a graphical user interface to do analysis
> and plotting of research data. My widget contains a list widget where I
> display the names of the data the user has read in.
>
> The problem is: I wanted the user to be able to read in a dat file of
> saved variables. I don't know what the names of the variables will
> necessarily be. I figured out a way to get the STRING names of the
> restored variables into an array. But, I still need a way to access the
> data that the variables contain for plots, etc. Is there any way to
> access the variables' data if all you have is a string array of the
> variables' names? I'd appreciate any help.
>
> Thanks,
> Natalie Rooney


If I understand you correctly, all you need is something like
timeind = where(names eq 'TIME')
ind = where(names eq VARNAME)
if (ind(0) ge 0) then plot,data(timeind,*),data(ind,*)

Here data is the data array, and names stores the variable name strings.
In the example above, data has the dimension (M,N), with M variable
names and N observations.

You can get the VARNAME from the widget via the following procedure:
; get names and selection of x or y list
widget_control,widget_id,get_value=names
; determine selection in x or y list
; (requires knowledge of the structure of cw_xysel !!)
widget_control,widget_info(widget_id,/child),get_uvalue=xyst ate
sel = widget_info(xystate.listID,/list_select)
This is actually a piece of code from my EXPLORE widget application.
You may want to check my web page for this, and if you like the general
idea, I am sure you can find a handful of information with respect to
what you are trying to do if you take a look at the sources.

Regards,
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: accessing variables with their string names [message #10667 is a reply to message #10664] Fri, 19 December 1997 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Natalie Rooney (natalie@arlut.utexas.edu) writes:

> Hello. I'm trying to create a graphical user interface to do analysis
> and plotting of research data. My widget contains a list widget where I
> display the names of the data the user has read in.
>
> The problem is: I wanted the user to be able to read in a dat file of
> saved variables. I don't know what the names of the variables will
> necessarily be. I figured out a way to get the STRING names of the
> restored variables into an array. But, I still need a way to access the
> data that the variables contain for plots, etc. Is there any way to
> access the variables' data if all you have is a string array of the
> variables' names? I'd appreciate any help.

Uuggh. It is *possible*, maybe, but you will probably run
into limitations. For example, you will have to name
all the "variables" something else in your program to use
them. Here is a short example of how I might approach the
problem using the EXECUTE command. I don't know any other
way that this could be accomplished, really.

Pro Example, varNames
Restore, 'example.sav'
ok = Execute('Plot, ' + varNames[0])
ok = Execute('var2 = ' + varNames[1])
Help, var2
END

a = Findgen(11)
b = 3.5
Save, a, b, File='example.sav'
Example, ['a', 'b']
END

How are you getting the "string" names of the restored
variables?

Happy Holidays,

David

-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: accessing variables with their string names [message #10669 is a reply to message #10664] Fri, 19 December 1997 00:00 Go to previous message
Aviv Gladman is currently offline  Aviv Gladman
Messages: 8
Registered: August 1997
Junior Member
Well, i'm probably not the only one to respond to this message, but here
goes:

You can use the execute function to perform operations on string
variables. Eg:

varlist=['var1','var2','var3']

for i=0, 2 do r=execute('print,'+varlist[i])


will print the contents of var1, var2, and var3. I find this a convenient
way to add callbacks to widgets on the fly, using a linked list of
string callback function names which are executed by the event handler.

Aviv S. Gladman

On Fri, 19 Dec 1997, Natalie
Rooney wrote:

> Hello. I'm trying to create a graphical user interface to do analysis
> and plotting of research data. My widget contains a list widget where I
> display the names of the data the user has read in.
>
> The problem is: I wanted the user to be able to read in a dat file of
> saved variables. I don't know what the names of the variables will
> necessarily be. I figured out a way to get the STRING names of the
> restored variables into an array. But, I still need a way to access the
> data that the variables contain for plots, etc. Is there any way to
> access the variables' data if all you have is a string array of the
> variables' names? I'd appreciate any help.
>
> Thanks,
> Natalie Rooney
>
>
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Vim 5 language syntax file for IDL wanted
Next Topic: bits from bytes

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

Current Time: Wed Oct 08 13:33:11 PDT 2025

Total time taken to generate the page: 0.00727 seconds