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 #66271] Thu, 07 May 2009 15:02 Go to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
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

Use N_ELEMENTS to determine if a particular parameter is omitted. I
usually do something like the following:

function RectArea, a, b
compile_opt strictarr

_a = n_elements(a) eq 0L ? 1.0 : a
_b = n_elements(a) eq 0L ? 1.0 : b

return, _a * _b
end

I don't do:

if (n_elements(a) eq 0L) then a = 1.0

because I don't want change an input variable from the user.

Mike
--
www.michaelgalloy.com
Associate Research Scientist
Tech-X Corporation
[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: Thu Oct 09 21:15:34 PDT 2025

Total time taken to generate the page: 0.80171 seconds