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

Home » Public Forums » archive » Re: Object programming with data...
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: Object programming with data... [message #30901 is a reply to message #30857] Wed, 22 May 2002 14:52 Go to previous messageGo to previous message
merlecorp is currently offline  merlecorp
Messages: 2
Registered: May 2002
Junior Member
Craig Markwardt <craigmnet@cow.physics.wisc.edu> wrote in message news:<onptzrj0zd.fsf@cow.physics.wisc.edu>...
> Randall Skelton <rhskelto@atm.ox.ac.uk> writes:
>> On a slightly different topic, is it possible to define a function that
>> takes an arbitrary number of parameters? i.e. how do I write a function
>> 'sum' that takes 'n' variables and sums them? (yes, in this case I could
>> use 'total' but that's not the point...)
>
> No fair slipping this at the end of an unrelated post! I usually
> don't read David's "gosh golly" articles :-)
>
> The answer to your question is no, and yes. No, there is no construct
> in IDL that makes handling an arbitrary number of arguments easy. On
> the other hand, yes, it is possible to parse them if you specify all
> the parameters explicitly, as in,
>
> PRO MYTOTAL, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10
>
> and so on up to the maximum of 64 (?). Then you access them using the
> EXECUTE() function.
>
> for i = 0, n_params()-1 do begin
> dummy = execute('x = x + x'+strtrim(i,2))
> endfor
>
>
> Craig

Hey,

Here's another approach using the _extra keyword. It's not my idea--I
pilfered it from R. Kling's InformationPanel--but I liked his approach
to arbitrary inputs & thought it was worth posting in this simplified
form.

One catch ... I'm not sure if there are limits on the number of
parameters accepted by the _extra keyword.


cheers,
merle


; ------------------------------------------------------------ -------
FUNCTION Sum, _extra=extra
; -- borrowed this approach from R. Kling's InformationPanel.pro

nNumEntries = N_Tags(extra)

nSum = 0
FOR i = 0, nNumEntries-1 DO nSum = nSum + extra.(i)

Return, nSum

END


; ------------------------------------------------------------ -------
PRO eg
; -- example calling program

x1 = 10
x2 = 20
x3 = 30
x4 = 40
x5 = 50

Print, Sum(x1=x1, x2=x2, x3=x3)
Print, Sum(x1=x1, x2=x2, x3=x3, x4=x4)
Print, Sum(x1=x1, x2=x2, x3=x3, x4=x4, x5=x5)

END
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Array Subscripting Puzzle
Next Topic: idl/idlde command line autocomplete

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

Current Time: Thu Oct 09 20:57:28 PDT 2025

Total time taken to generate the page: 0.64086 seconds