Re: passing multiple keywords to subroutines [message #14078] |
Mon, 25 January 1999 00:00  |
Liam Gumley
Messages: 473 Registered: November 1994
|
Senior Member |
|
|
David Ritscher wrote:
> It's often desirable to redefine a function, and then have this new
> function behave almost like the original function. To cook up an
> example, let's say I need a new plot function, that plots the x-axis
> as .001 units:
>
> pro myplot, x
> plot, findgen(n_elements(x) * 0.001), x
> return
> end
>
> It would now be great to be able to pass any and all possible keywords
> into this new plotting function, so I might call it as:
> myplot, x, title='test', linestyle=3
>
> In IDL, this can be done by including all possible keywords (rather
> tedious!)
It can be done this way, and it is tedious indeed.
Alternatively, you can exploit the keyword inheritance features offered
by the _EXTRA keyword, e.g.
pro myplot, x, _extra = extra_keywords
plot, findgen(n_elements(x) * 0.001), x, _extra = extra_keywords
end
Now all keywords which go unrecognized by your routine MYPLOT are passed
into (but not out of) the PLOT procedure, so that
myplot, x, title='test', linestyle=3
will work the way you intended. In the online help, click the Contents
button, select 'Building IDL Applications', 'Defining Procedures and
Programs', 'Keyword Inheritance'.
Cheers,
Liam.
---
Liam E. Gumley
Space Science and Engineering Center, UW-Madison
1225 W. Dayton St., Madison WI 53706, USA
Phone (608) 265-5358, Fax (608) 262-5974
http://cimss.ssec.wisc.edu/~gumley
|
|
|