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

Home » Public Forums » archive » Re: Keyword checking
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 checking [message #31011 is a reply to message #31009] Wed, 29 May 2002 07:15 Go to previous messageGo to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
Randall Skelton wrote:
>
> I have run into a great deal of trouble checking keywords in IDL and I
> thought I would relay my thoughts and frustrations. I am trying to
> prevent a user from passing an undefined variable in a keyword...
>
> Imagine,
>
> pro test, A=a, B=b
> print, n_params()
> print, arg_present(a), keyword_set(a), n_elements(a), size(a,/type)
> print, arg_present(b), keyword_set(b), n_elements(b), size(b,/type)
> end
>
> If I call this routine as:
>
> IDL> .reset
> IDL> test, a=1, b=undefvar
> % Compiled module: TEST.
> 0
> 0 1 1 2
> 1 0 0 0
>
> So, in order to prevent a user from passing junk in a keyword, I have:
>
> pro test, B=b
> if n_elements(b) eq 0 and arg_present(b) eq 1 then $
> message, 'You passed an undefined variable as a keyword'
> if n_elements(b) gt 0 then b = 'passed'
> end
>
> Now,
>
> IDL> .reset
> IDL> test, b=junk
> % Compiled module: TEST.
> % TEST: You passed an undefined variable as a keyword
>
> Surely there must be something simpiler than my 2-step approach ;)

Why the arg_present? Do you specifically want to tell the user that what they passed was
undefined? I thought arg_present was for using when you wanted to return something in the
variable? If the data is for input only, won't n_elements() suffice?

me confused.

paulv

--
Paul van Delst Religious and cultural
CIMSS @ NOAA/NCEP/EMC purity is a fundamentalist
Ph: (301)763-8000 x7274 fantasy
Fax:(301)763-8545 V.S.Naipaul
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: accessing reverse_indices
Next Topic: Re: color in widgets

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

Current Time: Mon Apr 27 00:02:03 PDT 2026

Total time taken to generate the page: 1.19570 seconds