Re: Is n_params() supposed to behave this way? [message #16841] |
Mon, 23 August 1999 00:00 |
Mirko Vukovic
Messages: 124 Registered: January 1996
|
Senior Member |
|
|
In article <37C1B09A.704A7DC@ssec.wisc.edu>,
Liam Gumley <Liam.Gumley@ssec.wisc.edu> wrote:
> Mirko Vukovic wrote:
>
>> Consider the following code:
>>
>> pro sub1,arg1,arg2,arg3,arg4,arg5
>> message,/info,string(n_params())
>> return
>> end
>>
>> pro sub,arg1,arg2,arg3,arg4,arg5
>> message,/info,string(n_params())
>> sub1,arg1,arg2,arg3,arg4,arg5
>> end
>>
>> If at the command prompt I do
>>
>> sub,4
>>
>> IDL will print out
>> IDL> sub,4
>> % SUB: 1
>> % SUB1: 5
>>
>> In sub1 all arguments except the first one are still undefined.
>
> n_params() returns the number of non-keyword arguments passed (defined
> or not) to a procedure or function.
> n_elements(arg) will tell you if arg is defined.
>
> I think a case statement is your best bet.
>
> Cheers,
> Liam.
>
Ouch.
Thanks.
Mirko
>
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
|
|
|
Re: Is n_params() supposed to behave this way? [message #16842 is a reply to message #16841] |
Mon, 23 August 1999 00:00  |
Liam Gumley
Messages: 473 Registered: November 1994
|
Senior Member |
|
|
Mirko Vukovic wrote:
> Consider the following code:
>
> pro sub1,arg1,arg2,arg3,arg4,arg5
> message,/info,string(n_params())
> return
> end
>
> pro sub,arg1,arg2,arg3,arg4,arg5
> message,/info,string(n_params())
> sub1,arg1,arg2,arg3,arg4,arg5
> end
>
> If at the command prompt I do
>
> sub,4
>
> IDL will print out
> IDL> sub,4
> % SUB: 1
> % SUB1: 5
>
> In sub1 all arguments except the first one are still undefined.
n_params() returns the number of non-keyword arguments passed (defined
or not) to a procedure or function.
n_elements(arg) will tell you if arg is defined.
I think a case statement is your best bet.
Cheers,
Liam.
|
|
|
Re: Is n_params() supposed to behave this way? [message #16843 is a reply to message #16841] |
Mon, 23 August 1999 00:00  |
mallors
Messages: 76 Registered: November 1997
|
Member |
|
|
In article <7ps7r7$i9p$1@nnrp1.deja.com>,
Mirko Vukovic <mvukovic@taz.telusa.com> writes:
> Consider the following code:
>
> pro sub1,arg1,arg2,arg3,arg4,arg5
>
> message,/info,string(n_params())
>
> return
>
> end
>
> pro sub,arg1,arg2,arg3,arg4,arg5
>
> message,/info,string(n_params())
>
> sub1,arg1,arg2,arg3,arg4,arg5
>
> return
> end
>
> If at the command prompt I do
>
> sub,4
>
> IDL will print out
> IDL> sub,4
> % SUB: 1
> % SUB1: 5
>
> In sub1 all arguments except the first one are still undefined.
Interesting, I ran across this same behavior today. I
fixed my code by switching to N_ELEMENTS instead of
N_PARAMS. The code is a little messier, but it works :-)
The N_PARAMS documentation is not totally clear, but
I suppose it passes for being correct:
"This function always returns the number of parameters
that were used in calling the procedure or function
from which N_PARAMS is called."
Add the caveat "even if those parameters are undefined" !
-bob
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~
Robert S. Mallozzi 256-544-0887
Mail Code SD 50
Work: http://gammaray.msfc.nasa.gov/ Marshall Space Flight Center
Play: http://cspar.uah.edu/~mallozzir/ Huntsville, AL 35812
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~
|
|
|