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

Home » Public Forums » archive » Re: Ellipsis in IDL?
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: Ellipsis in IDL? [message #40116 is a reply to message #40115] Wed, 21 July 2004 17:00 Go to previous messageGo to previous message
Mark Hadfield is currently offline  Mark Hadfield
Messages: 783
Registered: May 1995
Senior Member
Michael Wallace wrote:
> How do you define a procedure to take N number of arguments when you
> don't know what N is before the procedure call? For those of you who
> have worked with C, what I'm after is something similar to the ellipsis
> (...) which allows N many arguments to be specified for functions such
> as printf.
>
> In IDL, the print command is obvious example of what I'm trying to do.
> The signature of print is:
>
> print [, Expr1, Expr2, ... , ExprN]
>
> So, how can I write a procedure to take N many arguments?

You can't do exactly that, but you can write a routine to accept a large
number of arguments (better called positional parameters) and then use
the various inquiry functions (like N_PARAMS, SIZE, N_ELEMENTS &
ARG_PRESENT) in your code to handle the different cases.

For example, one of my general-purpose routines (MGH_NEW, a procedure
wrapper for OBJ_NEW) looks like this (simplified):

pro MGH_NEW, name, P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, $
RESULT=result

if size(name, /TYPE) ne 7 then $
message, 'The first parameter must be a class name.'

case n_params() of
1: result = obj_new(Name)
2: result = obj_new(Name, P1)
3: result = obj_new(Name, P1, P2)
4: result = obj_new(Name, P1, P2, P3)
5: result = obj_new(Name, P1, P2, P3, P4)
6: result = obj_new(Name, P1, P2, P3, P4, P5)
7: result = obj_new(Name, P1, P2, P3, P4, P5, P6)
8: result = obj_new(Name, P1, P2, P3, P4, P5, P6, P7)
9: result = obj_new(Name, P1, P2, P3, P4, P5, P6, P7, P8)
10: result = obj_new(Name, P1, P2, P3, P4, P5, P6, P7, $
P8, P9)
11: result = obj_new(Name, P1, P2, P3, P4, P5, P6, P7, $
P8, P9, P10)
else: message, 'Too many parameters'
endcase

end

It used to take 15 positional parameters, but I trimmed it down to 10,
which is still more than enough. I don't know the maximum number
supported by IDL, but it's way more than you would want to use in normal
circumstances.

Inquiring about the number and status of your parameters is a subtle
business. I'm sure David has some useful tutorials.



--
Mark Hadfield "Ka puwaha te tai nei, Hoea tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Keyboard Shortcuts
Next Topic: ActiveX events

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

Current Time: Sat Nov 29 05:16:31 PST 2025

Total time taken to generate the page: 1.20041 seconds