[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multiple values from a function?




Simon de Vet <simon@mathstat.dal.ca> writes:

> I have a function that does a whole lot (it started out as an
> independent program). It works very well when returning one of it's
> calculated arrays.
> 
> It also produces a number of other arrays which I'd like to have access
> to.  Unfortunately, I have discovered that a function can only return
> one value.
> 
> How can I get the other arrays out of it? The code is intertwined, so it
> would be hard to break into 2 or 3 independent functions.
> ...

The first and simple answer is, "no," you can't RETURN multiple values
like you desire.

However, the second and more useful answer is that you CAN return
values in positional or keyword parameters.  IDL is pass-by-reference
in most cases, so you can simply set the parameter value to whatever
you want.  I do this all the time to return subsidiary values, and it
works for both procedures and functions.  

function example, in, out
  out = in^2   ;; calling routine will have new value of OUT upon return
  return in^3
end

Good luck,
Craig

-- 
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D.         EMAIL:    craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------