[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: keyword question



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