Re: keyword params in HISTOGRAM [message #7609 is a reply to message #7546] |
Tue, 03 December 1996 00:00  |
Robert Moss
Messages: 74 Registered: February 1996
|
Member |
|
|
Mark Fardal wrote:
>
> Hi,
>
> I'm sure this is a stupid question, but I can't figure it out.
> Normally when you pass keyword parameters, you can pass something
> that's undefined, right? As in this example
>
> pro junk1, a, test=test
> help,test,t
> ;junk2, a, test=test ; either one of
> junk2, a, test=t ; these works
> return
> end
>
> pro junk2, a, test=test
>
> a = 3.
> return
> end
>
> IDL> junk1, a
> TEST UNDEFINED = <Undefined>
> T UNDEFINED = <Undefined>
> IDL>
>
> However, when I try to pass HISTOGRAM a keyword parameter that's
> undefined, I get an error message. The routine here is just a
> wrapper function for HISTOGRAM, so I want to pass a number of
> keyword parameters through to it.
>
> function histomake, array, binsize=binsize, xpoints=xpoints, $
> input=input, min=min, max=max, omin=omin, omax=omax, reverse=reverse
> [...stuff deleted...]
>
> n = histogram(array, binsize=binsize, min=min, max=max, $
> omin=omin, omax=omax, reverse=reverse)
>
> [...stuff deleted...]
> return
> end
>
> IDL> h = histomake(array, bins=10, xpoints=xpoints)
> % HISTOGRAM: Variable is undefined: MAX.
> % Execution halted at: HISTOMAKE 52
> /users1/casa/fardal/comp/idl/histomake.pro
> % $MAIN$
>
> Why is the behavior different here?
>
> Thanks,
> Mark
Your junk example "works" because you are not trying to actually do
anything with the test variable in the junk2 routine... hence no error
occurs.
The HISTOGRAM routine _is_ trying to do something with its keywords, so
you get an error. I see two reasonable solutions:
1) If you are not using the min, max, etc keywords in the histomake
function itself, rather than making them explicit keywords, use keyword
inheritance ( the _EXTRA keyword) to pass them to HISTOGRAM. (See EXTRA
in the online help).
2) Use the CALL_FUNCTION (faster) or EXECUTE (slower) method to call
HISTOGRAM inside your makeohist function so that it is called with only
the relevant and proper keywords.
At a guess, I'd say that solution 1) is the way to go in general...
keyword inheritance is a Good Thing.
--
Robert M. Moss, Ph.D. - mossrm@texaco.com - FAX (713)954-6911
------------------------------------------------------------ -----
This does not necessarily reflect the opinions of Texaco Inc.
|
|
|