Re: Looping over parameters without EXECUTE() [message #43800] |
Mon, 02 May 2005 14:17 |
Wayne Landsman
Messages: 117 Registered: January 1997
|
Senior Member |
|
|
Reimar Bauer wrote:
> Dear Wayne
>
> you should have a look on this. Probably you need to add an error handler by
> catch if not all arguments are used. Or you write a CASE with all tested
> against n_elements.
>
> pro doit,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11
> v=ROUTINE_info('doit',/param)
> for i=0,v.num_args do $
> print,scope_varfetch(v.args[i])
> end
>
> The scop_varfetch routine was new in 6.1.
>
> cheers
>
> Reimar
>
Thanks, Reimar. I think that will do the trick. Cheers, --Wayne
|
|
|
Re: Looping over parameters without EXECUTE() [message #43801 is a reply to message #43800] |
Mon, 02 May 2005 13:19  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
Dear Wayne
you should have a look on this. Probably you need to add an error handler by
catch if not all arguments are used. Or you write a CASE with all tested
against n_elements.
pro doit,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11
v=ROUTINE_info('doit',/param)
for i=0,v.num_args do $
print,scope_varfetch(v.args[i])
end
The scop_varfetch routine was new in 6.1.
cheers
Reimar
Wayne Landsman wrote:
> The one case where I haven't figured out how to remove EXECUTE() from a
> program (to allow use with the Virtual Machine) is where one wants to
> loop over supplied parameters. For example, to apply the procedure
> 'myproc' to each supplied parameter (which may have different data
> types) one can use EXECUTE() to write each parameter to a temporary
> variable:
>
> ************************************************
>
> pro doit,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11
>
> ;Loop over input parameters
> Np = N_params()
> colname = 'p' + strtrim(indgen(Np)+1,2)
>
> for i=0,Np-1 do begin
> result = execute('p=' + colname[i] )
> myproc,p
> endfor
> **********************************************
> Is there a way to avoid EXECUTE() here -- say to identify the 4th
> parameter as e.g., $4 ? Of course, one can always avoid the loop and
> explicitly write out the call for each parameter:
>
> myproc,p1
> myproc,p2
> ....
> but this probably becomes unreasonable at around 20 parameters.
>
> One solution is to have the program read an array of pointers rather
> than multiple parameters. But this has the disadvantages of losing
> backwards compatibility, as well as making the program somewhat more
> complicated to use. My current default solution is to make a pointer
> keyword available and say that data must be passed this way instead of
> via parameters, if the user wants to use the VM.
>
> Thanks, --Wayne
--
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg-i/
============================================================ ======
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html
|
|
|