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

Re: Can this be done using CALL_FUNCTION?



edward.s.meinel@aero.org wrote:
> 
> OK, here's one for the IDL gurus (since I'm only a little guru would
> that make me a gu-gu?)...
> 
> I am working with spectral images. Unfortunately, IDL is geared toward
> multidimensional data in which all of the dimensions are the same type
> (i.e. spatial, spectral, frequency...) but it doesn't like to operate on
> data with mixed dimensions, such as a multispectral image (unless I'm
> missing something really obvious).
> 
> Rather than having to rewrite every bloody function/procedure for
> spectral imagery, I was hoping it would be possible to write a generic
> wrapper function along the lines of:
> 
> FUNCTION spatial_function, name, image, other_stuff
> im_size = SIZE(image)
> CASE im_size[0] OF
> [... rest of code snipped]

Ed,

   in a perfect world you could do this, although you should add
_EXTRA=e to your wrapper to allow for keywords. Unfortunately, 
several of the built-in (or library) functions are not forgiving 
when it comes to the wrong number of parameters and keywords. Therefore,
you will probably not get around doing something (ugly) like:

function spatial_function, name, image, arg1, arg2, arg3, arg4, _EXTRA=e

   im_size = SIZE(image)
   CASE im_size OF
     ...
     CASE n_params() OF
      2 : CALL_FUNCTION(name,image)
      3 : CALL_FUNCTION(name,image,arg1)
      4 : CALL_FUNCTION(name,image,arg1,arg2)
      ...
     ENDCASE
   ...


A way around this? Well, you could rewrite all the functions you would
potentially call from such a wrapper and give them extra arguments which
are simply ignored if they are not needed.
Example:
change
FUNCTION Correlate, X, Y, Covariance = Covariance, Double = Double   
into
FUNCTION Correlate, X, Y, DUM1, DUM2, DUM3, DUM4, DUM5, DUM6, $   
Covariance = Covariance, Double = Double   

And if the function doesn't have keywords, add _EXTRA=e to it.

Good luck,
Martin

-- 
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
[[ Dr. Martin Schultz   Max-Planck-Institut fuer Meteorologie    [[
[[                      Bundesstr. 55, 20146 Hamburg             [[
[[                      phone: +49 40 41173-308                  [[
[[                      fax:   +49 40 41173-298                  [[
[[ martin.schultz@dkrz.de                                        [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[