Re: Reverse interpolation?

```
Martin Schultz <martin.schultz@dkrz.de> writes:

> Simon de Vet wrote:
...
> > I want to get better results. Instead of finding that entry #5 is the
> > closest match to my known altitude, and using #5 as the subscript in my
> > data array, I'd like to find that, based on a linear interpolation,
> > entry #5.32850 is an exact match, and using this value in an
> > interpolation on my data array.
> >
> > I understand how to use a subscript to find an interpolated value. How
> > would I go in the opposite direction, using a value to find a subscript?
> >
> > Thanks. I hope this isn't too confusing. I'm having a bad brane day.
> >
> > Simon
>
>
> Hi Simon,
>
>    I have dealt with similar problems (vertical regridding, to
> give the kid a name), and I tend to resort on the spline routine
> in these instances. Please find attached a piece of code that I
> used to vertically regrid OH concentration fields. Just be
> careful about end effects. For this application I overwrote the
> topmostfour levels of the target grid with the values from the
> top level of the old grid.
>
...
>             newxx = Spline( oldy, oldx, newy, 5. )
...

If you are trying to match a lot of values, then I agree that the
spline interpolation is one of the best solutions.  However, I have
problems when the points are too far apart, and it's also pretty slow.
I found the Numerical Recipes version of spline interpolation to be
much better (built in functions SPL_INTERP and SPL_INIT).

If v1 is vector of values sampled at original altitudes a1, and you
want to resample at new altitudes a2, then you do something like this:

v2 = spl_interp(a1, v1, spl_init(a1, v1), a2)

Now v2 has the newly sampled values.  In principle a2 can be one value
so even if you want a single value the spline interpolation can be
useful, and even pretty fast.

IDL version 5.3 apparently has a new function called VALUE_LOCATE
which can do fast search of a reference array.  From there you can do
a linear interpolation.  The IDL Astronomy Library procedure called
TABINV may do what you want.  The versions that use VALUE_LOCATE and
don't use it are here, and here, respectively:

http://idlastro.gsfc.nasa.gov/ftp/v53/tabinv.pro
http://idlastro.gsfc.nasa.gov/ftp/pro/math/tabinv.pro

Craig

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

```