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

Home » Public Forums » archive » Re: How to judge a Function's parameters ?
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: How to judge a Function's parameters ? [message #66272 is a reply to message #66271] Thu, 07 May 2009 15:01 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
Hu wrote:
> Hi,folks,
>
> I created a function 'RectArea' to calculate the rectangle area, and
> two parameters, side a and b, are needed when the function is
> employed.
>
> I want to do something like this: if a and b are omitted by the user,
> then the function will use the default values.
>
> But, How can I judge that the parameters are omitted?
>
> Thanks
>
> function RectArea,a,b
> return,a*b
> end

function RectArea,a,b
if ( n_elements(a) eq 0 ) then a = 1 ; or whatever default value
if ( n_elements(b) eq 0 ) then b = 1 ; or whatever default value
return,a*b
end

Although, I would rather an error be thrown if required arguments are missing.

cheers,

paulv
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: How to judge a Function's parameters ?
Next Topic: IDL 7.0 (Windows version) - widget_table does not generate expected event

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

Current Time: Tue Dec 02 22:16:31 PST 2025

Total time taken to generate the page: 2.72839 seconds