Keyword_Set vs N_Elements Re: Problems with CW_FSLIDER [message #12084] |
Sun, 28 June 1998 00:00 |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Alex Schuster (alex@rosa.mpin-koeln.mpg.de) writes:
> It works with any value except for 0.0. Looks like... right, again RSI
> uses KEYWORD_SET insteaf of N_ELEMENTS to check for parameters. Hello
> RSI, this sucks!!
>
> Our cw_fslider.pro of IDL 4 has this line in it:
> IF NOT (KEYWORD_SET(val)) THEN val =3D min
>
> In IDL 5, is is:
> IF N_ELEMENTS(val) EQ 0 THEN val =3D min
>
> We are using IDL 5.03, so I guess RSI fixed this in this update. Of
> course they don't tell us in the modification history of the source
> code.
Here is the portion of the code in CW_FSLIDER (IDL 5.1) that checks for
keywords:
IF NOT (KEYWORD_SET(drag)) THEN drag = 0
IF NOT (KEYWORD_SET(edit)) THEN edit = 0
IF NOT (KEYWORD_SET(frame)) THEN frame = 0
IF N_ELEMENTS(max) EQ 0 THEN max = 100.0
IF N_ELEMENTS(min) EQ 0 THEN min = 0.0
IF NOT (KEYWORD_SET(scroll)) THEN scroll = 10000 ELSE $
scroll = ABS(LONG((float(scroll) / (max - min)) * 1000000))
IF NOT (KEYWORD_SET(sup)) THEN sup = 0
IF NOT (KEYWORD_SET(title)) THEN title = ""
IF NOT (KEYWORD_SET(uval)) THEN uval = 0
IF N_ELEMENTS(val) EQ 0 THEN val = min
IF NOT KEYWORD_SET(format) THEN format='(G13.6)'
Only the frame, sup, title, uval, and format keyword are
incorrectly checked with KEYWORD_SET instead of N_ELEMENTS. :-)
But, to be fair, RSI is not alone in this. I would say
about 30 percent of the people I teach IDL to don't even
realize you *have* to check keyword parameters. And well
over half of the rest use KEYWORD_SET incorrectly.
My personal view of this is that it is a documentation
and routine naming problem more than anything else.
When you have a function named KEYWORD_SET, you think
you are suppose to use it to check keywords. The fact
that it doesn't (at least in the way the majority of
people *think* it does) is about as unfortunate as
the fact that the function ARG_PRESENT doesn't really
check for the presence of an argument.
And to be honest, who in their right mind would be
looking at the documentation for N_ELEMENTS to see if their
keyword was *defined* or not unless someone let them in
on this little secret?
In the spirit of helpfulness, I offer this IS_DEFINED function.
Perhaps we can get RSI to use it:
FUNCTION IS_DEFINED, variable
RETURN, Keyword_Set(N_Elements(variable))
END
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|