Re: keyword question [message #25216] |
Wed, 23 May 2001 09:35 |
John-David T. Smith
Messages: 384 Registered: January 2000
|
Senior Member |
|
|
David Fanning wrote:
>
> Randall Skelton (rhskelto@atm.ox.ac.uk) writes:
>
>> I am trying to have an array *optionally* returned using a keyword
>> and I don't know the dimension of the array prior to the call. Why is
>> it that the passed keyword needs to be defined in IDL prior to being used
>> as a keyword?
>>
>> What am I doing wrong here?
>
> You are using the wrong function to check the keyword.
> KEYWORD_SET should *only* be used to test keywords that
> have a binary function. That is, they are either on or off,
> true or false, 0 or 1, etc.
>
> What you want to know is if you keyword is *defined* or
> not. You use N_ELEMENTS to tell you this:
>
> IF N_Elements(b) EQ 0 THEN b = FltArr(10)
Actually, since he's trying to return something, he should use
arg_present() (which really should be called by_reference() or
something). This doesn't check if the keyword is defined or note
(presumably you don't care), but just whether its value at the main
level can be altered:
if arg_present(b) then b = fltarr(10)
Arg_present() was added some time ago to solve just this type of problem
(which RSI did internally with IDL functions quite a bit).
JD
|
|
|
Re: keyword question [message #25217 is a reply to message #25216] |
Wed, 23 May 2001 09:18  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Randall Skelton (rhskelto@atm.ox.ac.uk) writes:
> I am trying to have an array *optionally* returned using a keyword
> and I don't know the dimension of the array prior to the call. Why is
> it that the passed keyword needs to be defined in IDL prior to being used
> as a keyword?
>
> What am I doing wrong here?
You are using the wrong function to check the keyword.
KEYWORD_SET should *only* be used to test keywords that
have a binary function. That is, they are either on or off,
true or false, 0 or 1, etc.
What you want to know is if you keyword is *defined* or
not. You use N_ELEMENTS to tell you this:
IF N_Elements(b) EQ 0 THEN b = FltArr(10)
Here is an article containing more information on this
topic:
http://www.dfanning.com/tips/keyword_check.html
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|