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

Home » Public Forums » archive » Keyword checking
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Keyword checking [message #31015] Wed, 29 May 2002 06:20
Randall Skelton is currently offline  Randall Skelton
Messages: 169
Registered: October 2000
Senior Member
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 ;)

Cheers,
Randall
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: accessing reverse_indices
Next Topic: Re: accessing reverse_indices

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

Current Time: Fri Oct 10 14:05:12 PDT 2025

Total time taken to generate the page: 0.15832 seconds