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

Home » Public Forums » archive » Default values for keywords
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
Default values for keywords [message #90780] Wed, 15 April 2015 11:21 Go to next message
Gordon Farquharson is currently offline  Gordon Farquharson
Messages: 48
Registered: December 2010
Member
I have been a long time IDL user, but it has only just occurred to me to ask whether there is a more elegant way to set default values for keyword parameters than

if n_elements(foo) then foo = !pi

I suspect there isn't, but this makes the start of most IDL routines very cluttered. It would be cool if there was a way to set the default value, like in C++ constructor calls. Maybe something like,

pro bar, AKP=akp

DEFAULT_BLOCK
apk = 1.0
END_DEFAULT_BLOCK

...

END

I'm sure somebody could come up with a more elegant syntax.

Just a thought.

Gordon
Re: Default values for keywords [message #90781 is a reply to message #90780] Wed, 15 April 2015 11:30 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Gordon Farquharson writes:

> I'm sure somebody could come up with a more elegant syntax.

I use SetDefaultValue from the Coyote Library. It only sets the value if
needed, can check the range of values, can set Boolean values, etc.

http://www.idlcoyote.com/programs/setdefaultvalue.pro

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: Default values for keywords [message #90782 is a reply to message #90781] Wed, 15 April 2015 11:36 Go to previous message
Gordon Farquharson is currently offline  Gordon Farquharson
Messages: 48
Registered: December 2010
Member
On Wednesday, April 15, 2015 at 11:30:41 AM UTC-7, David Fanning wrote:

> I use SetDefaultValue from the Coyote Library. It only sets the value if
> needed, can check the range of values, can set Boolean values, etc.

How could I doubt that you would not have a solution. Very useful looking routine!

I imagine that very decade or so, some bright spark suggests this idea :-)

Written by: David W. Fanning, November 26, 2008, from suggestion by Carsten Lechte on IDL newsgroup on this date.

Gordon
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: contour and LABEL_FORMAT not playing nicely
Next Topic: Regridding NCEP Data

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

Current Time: Wed Oct 08 14:00:18 PDT 2025

Total time taken to generate the page: 0.00478 seconds