comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Keyword discrimination
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Keyword discrimination [message #12518] Wed, 12 August 1998 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Imanol Echave (ccaeccai@sc.ehu.es) writes:

> The question is: How to discriminate between a keyword not set and a keyword
> set to an undefined variable? N_ELEMENTS returns 0 in the two cases.

Don't even get me started about IDL routines with misleading
names... :-)

You are correct. It is IMPOSSIBLE, using N_ELEMENTS (or
KEYWORD_SET, for that matter), to distinguish between
keywords that are unused and keywords that are set to
an undefined variable.

But sometimes you clearly want to. For example, you
would like an output keyword to contain the results of
some time-consuming calculation, but you don't want to
DO the calculation unless the caller of the routine requests
the result. You would like to know if the caller of the
function USED the keyword.

Neither N_ELEMENTS or KEYWORD_SET can furnish this information
reliably. To address this issue, RSI introduced the ARG_PRESENT
function, which *almost* does what you want it to do. It can
tell you if a "passed by reference" variable exists in a program.

To understand this, suppose I have a procedure defined like this:

PRO JUNK, DO_CALC=doit
IF ARG_PRESENT(doit) THEN doit = Big_Calculation()
END

This will work reliably if I call the function like this
(where XX is an undefined variable):

IDL> JUNK, DO_CALC=xx

It will fail if I call the function like this:

IDL> JUNK, /DO_IT

Here the variable argument "doit" is certainly *present*
in my procedure (it has the value of 1), but the ARG_PRESENT
function returns 0 because the variable exists in a "passed
by value" form, not a "passed by reference" form.

Given the limitations of each of these functions, it is usually
possible to work something out in your program, often by
using plenty of IF statements. :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438, Toll Free Book Orders: 1-888-461-0155
Coyote's Guide to IDL Programming: http://www.dfanning.com/
[Message index]
 
Read Message
Read Message
Previous Topic: Getting filename from PS device
Next Topic: problems with ENVI orthorectification

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 18:01:35 PDT 2025

Total time taken to generate the page: 2.40324 seconds