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 #66470 is a reply to message #66271] Thu, 07 May 2009 15:32 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
mgalloy wrote:
> 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.

Excellent point.

Being a Fortran programmer, I rely on the INTENT(IN) attribute for input-only dummy
arguments in my Fortran code. I'm much lazier in my IDL dabblings.

To the OP: do what Mike says. :o)


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: Sat Oct 11 06:27:57 PDT 2025

Total time taken to generate the page: 0.71978 seconds