Re: Discover the name (at calling level) of passed parameter [message #33969] |
Wed, 12 February 2003 04:22  |
Kristian Kjaer
Messages: 58 Registered: June 1998
|
Member |
|
|
Now what if I have a function instead of a procedure:
I don't suppose there is any hope with
IDL> p2=myfunction(p)
to discover, at myfunction's level, the name at the calling level
('p2'), of the variable where the function's returned value will end up?
I guess I need to convert the syntax to
IDL> p2=p & myprocedure,p ; or
IDL> myprocedure,p2,p
Or need I?
- Kristian
David Fanning wrote:
> Alright, here it is. But you didn't hear it from me. :-(
>
> pro test_par_name, p
> help,p
> name = Routine_Names(p, Arg_Name=(-1))
> print ,'Name of passed parameter was ',name,' and its value is',p
> end
>
> You can find more information here:
>
> http://www.dfanning.com/tips/access_main_vars.html
>
> Cheers,
> David
> Kristian.Kjaer@Risoe.DK writes:
>> I sometimes find myself wanting to know the name of a passed parameter:
>> At the called procedure level I need to know the name that the parameter
>> had at the calling level.
>> The code below illustrates what I can_not_ do by simple means.
>> Are there any dirty tricks I could emply to this end?
>>
>> Thanks for any pointers, Kristian
>>
>> ; --------- begin IDL code:
>> pro test_par_name, p =
>>
>> help,p
>> print ,'The name of the passed parameter was ','?',' and its value is
>> ',p
>> end
>>
>> ; --------- begin IDL command history:
>> IDL> q=3D5D
>> IDL> test_par_name,q
>> P DOUBLE =3D 5.0000000
>> The name of the passed parameter was ? and its value is 5.0000000
>>
>> ; --------- begin wish list:
>> ; I'd like somehow to be able to get:
>> Q DOUBLE =3D 5.0000000
>> The name of the passed parameter was Q and its value is 5.0000000
|
|
|
Re: Discover the name (at calling level) of passed parameter [message #33972 is a reply to message #33969] |
Wed, 12 February 2003 03:05   |
Kristian Kjaer
Messages: 58 Registered: June 1998
|
Member |
|
|
Well, you asked for it:
<longish_explanation>
I particularly like the "I" of IDL.
I have a function ctasrd() that will read one of my data files and
return a structure containing the data.
IDL> a = ctasrd('dagq1234')
IDL> b = ctasrd('dagq1235')
IDL> c = ctasrd('dagq1236')
This will read the files 'dagq1234.dat' etc. and the resulting
structures, stored in a, b and c, in fact contain a tag with the name
and path of the data file (as Pavel suggests).
Now as I work with a,b,c, and many other data structures I'd have to
either remember which was which, or, to remind myself, do
IDL> print,a.text[0]
I prefer
IDL> dagq1234 = ctasrd('dagq1234')
, except that here I have twice to type the name dagq1234 (that is
meaningfull to me because the log book refers to it.)
But now I can change the syntax so I only need to type the name once:
IDL> tasget,dagq1234
Hooray!
I also like that IDL is command-based and I journal everything so that I
can easily replay commands or extract a useful batch file (or the
sceleton of a new procedure) from the journal file.
Other people like GUIs, and indeed, sometimes GUIs can replace complex
typing.
I (almost) have a GUI, XsetP (widget programming by Frank Bringezu), and
a command-line equivalent, SetP, that will create or modify a fit
parameter structure as used by Craig Markwardt's lsfit machines
mpfit.pro and mpfitfun.pro
Let's say p40 is a fit parameter structure that I want to modify before
letting mpfitfun loose again.
IDL> XSetP ,p40 ; and click and type in the GUI
The trouble with the GUI is that the IDL log window and journal file
will not reflect the changes made inside the GUI. If I want to do the
same thing again the next day I have to click and type similarly in the
GUI, and I don't have a record of what was done.
But now I can make it so that, on exit, XSetP echoes to the log window
and to the journal file the equivalent command:
SetP ,ParName='PkHeight_0' ,Value=2500 ,/unFIXed ,p40 ; , say
, complete with the correct variable name (p40).
Hooray again!
</longish_explanation>
- Kristian
Mark Hadfield wrote:
> Just curious: Why?
> Kristian.Kjaer@Risoe.DK wrote in message
> news:3E48F599.E7B18502@Risoe.DK...
>> I sometimes find myself wanting to know the name of a passed
>> parameter: At the called procedure level I need to know the name
>> that the parameter had at the calling level.
|
|
|
|
|
Re: Discover the name (at calling level) of passed parameter [message #34001 is a reply to message #33996] |
Tue, 11 February 2003 07:00   |
Kristian Kjaer
Messages: 58 Registered: June 1998
|
Member |
|
|
Brilliant!
Thanks, David and Craig.
- Kristian
; final example code:
pro test_par_name, p
name = Routine_Names(p, Arg_Name=(-1))
print ,helpform(name[0],p)
print ,'The name of the passed parameter was ',name[0],' and its value
is ',p
end
David Fanning wrote:
> Alright, here it is. But you didn't hear it from me. :-(
>
> pro test_par_name, p
> help,p
> name = Routine_Names(p, Arg_Name=(-1))
> print ,'Name of passed parameter was ',name,' and its value is',p
> end
>
> You can find more information here:
>
> http://www.dfanning.com/tips/access_main_vars.html
> (Kristian.Kjaer@Risoe.DK) writes:
>> I sometimes find myself wanting to know the name of a passed parameter:
>> At the called procedure level I need to know the name that the parameter
>> had at the calling level.
|
|
|
Re: Discover the name (at calling level) of passed parameter [message #34004 is a reply to message #34001] |
Tue, 11 February 2003 06:15   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Kristian =?iso-8859-1?Q?Kj=E6r?= (Kristian.Kjaer@Risoe.DK) writes:
> I sometimes find myself wanting to know the name of a passed parameter:
> At the called procedure level I need to know the name that the parameter
> had at the calling level.
>
> The code below illustrates what I can_not_ do by simple means.
> Are there any dirty tricks I could emply to this end?
>
> Thanks for any pointers, Kristian
>
> ; --------- begin IDL code:
> pro test_par_name, p =
>
> help,p
> print ,'The name of the passed parameter was ','?',' and its value is
> ',p
> end
>
> ; --------- begin IDL command history:
> IDL> q=3D5D
> IDL> test_par_name,q
> P DOUBLE =3D 5.0000000
> The name of the passed parameter was ? and its value is 5.0000000
>
> ; --------- begin wish list:
> ; I'd like somehow to be able to get:
> Q DOUBLE =3D 5.0000000
> The name of the passed parameter was Q and its value is 5.0000000
Alright, here it is. But you didn't hear it from me. :-(
pro test_par_name, p
help,p
name = Routine_Names(p, Arg_Name=(-1))
print ,'Name of passed parameter was ',name,' and its value is',p
end
You can find more information here:
http://www.dfanning.com/tips/access_main_vars.html
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: Discover the name (at calling level) of passed parameter [message #34034 is a reply to message #33972] |
Thu, 13 February 2003 22:56  |
Wim Bouwman
Messages: 8 Registered: September 1997
|
Junior Member |
|
|
Hej Kristian,
When I saw your question I knew imediately why you asked it. It brings back
happy memories. Now I am again working along the same direction with my new
measurements.
Kristian Kjaer wrote:
> IDL> a = ctasrd('dagq1234')
How are things going with you? I hope that you found a good place in the
changing Risoe. I still meet so once in a while Jan Skov Pedersen and Kurt
Clausen at conferences.
The work here is going very well. Last year we got the SESANS instrument
working. We can now do SANS with particles up to a size of 2 micrometer.
The results are in real space. It turns out to work well with concentrated
systems.
A month ago we got our second child: Elias. He is doing well. He is easy,
happy and tall. Rebekka, who has now four years finds it more difficult,
even though she thinks he is very cute.
Mange hilsner til din familie,
Wim.
--
Dr. Wim G. Bouwman phone (++31) (0)15 27 86775
Interfacultair Reactor Instituut fax (++31) (0)15 27 88303
Technische universiteit Delft w.g.bouwman@iri.tudelft.nl
Mekelweg 15 http://www.iri.tudelft.nl/~bouwman
2629 JB Delft The Netherlands
|
|
|