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 #40113 is a reply to message #40103] Wed, 21 July 2004 21:58 Go to previous messageGo to previous message
Mark Hadfield is currently offline  Mark Hadfield
Messages: 783
Registered: May 1995
Senior Member
Michael Wallace wrote:
>> 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.
>
>
> Ah, I see. I think I can work with this. I don't expect to ever have
> more than eight or so argu-- positional parameters. I have used SIZE
> and N_ELEMENTS in the past, but I had never run across N_PARAMS until
> now. That greatly simplifies things. It's a good thing you mentioned
> it or I probably would have written my own. ;-) I say that because one
> time I got part of the way through writing my own KEYWORD_SET type of
> function before realizing that IDL already had it's own handy
> KEYWORD_SET function.

Actually, I don't expect you'll want to use N_PARAMS all that much. All
it tells you is how many positional parameters there are. So it's useful
when you want to pass these parameters on to another routine, without
knowing *anything* about them, as in the example I included. More
usually, you'll want to know if each parameter is currently associated
with data; you can use N_ELEMENTS for that, eg:

function add, p0, p1, p2, p3
if n_elements(p0) eq 0 then message, 'Nothing to add'
result = p0
if n_elements(p1) gt 0 then result = result + p1
if n_elements(p2) gt 0 then result = result + p2
if n_elements(p3) gt 0 then result = result + p3
return, result
end

Sometimes you'll want to know if changes you make to parameter data will
be retained when you exit. If not you may be able to save time by not
computing it. You can use ARG_PRESENT for that, eg

pro set, p0, p1, p2, p3
if arg_present(p0) then p0 = <expensive operation>
if arg_present(p1) then p1 = <expensive operation>
if arg_present(p2) then p2 = <expensive operation>
if arg_present(p2) then p3 = <expensive operation>
end


--
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: Sun Nov 30 07:04:20 PST 2025

Total time taken to generate the page: 0.15449 seconds