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

Home » Public Forums » archive » Re: Bug in N_PARAMS?
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: Bug in N_PARAMS? [message #63974] Wed, 26 November 2008 07:49 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Carsten Lechte writes:

> Kenneth P. Bowman wrote:
>> to provide default values for optional parameters.
>
> I wrote this little procedure for setting default values
> that I use a zillion times a day:
>
>
> PRO defaultarg, arg, defval, VALUEGIVEN=valuegiven
>
> IF N_ELEMENTS( arg) EQ 0 THEN BEGIN
> arg = defval
> valuegiven = 0
> ENDIF ELSE valuegiven = 1
>
> END

This is a pretty good idea. I can see how it would
save some typing! :-)

Here is a slightly modified version. I'll add this,
with documentation, to the Coyote Library later today.

PRO SetDefaultValue, argument, defaultValue, BOOLEAN=boolean

; If BOOLEAN, we need just a 0 or a 1.
IF Keyword_Set(boolean) THEN BEGIN

argument = Keyword_Set(argument)

ENDIF ELSE BEGIN

; We only need assignment if the argument is undefined.
IF N_Elements(argument) EQ 0 THEN BEGIN

; If the default value is undefined, treat as BOOLEAN.
; Otherwise, assign default value to the argument.
IF N_Elements(defaultValue) EQ 0 THEN BEGIN
argument = Keyword_Set(argument)
ENDIF ELSE BEGIN
argument = defaultValue
ENDELSE

ENDIF

ENDELSE

END

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: areas with 'hatching' in plots?
Next Topic: Bug in N_PARAMS?

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

Current Time: Wed Oct 08 20:10:36 PDT 2025

Total time taken to generate the page: 0.01147 seconds