NASA Logo
Ocean Color Science Software

ocssw V2022
axis_interp.c
Go to the documentation of this file.
1 #include "get_ctht.h"
2 
3 /*
4 axis_interp - emulate the idl interpolate function with all its drawbacks
5 
6  Returns - float - the interpolate on the axis values
7 
8  Parameters: (in calling order)
9  Type Name I/O Description
10  ---- ---- --- -----------
11  float * axis_arr_vals I the axis values
12  int32_t n_ax I # of values in axis
13  float ind_frac I axis index and fraction to the
14  next index
15 
16  W. Robinson, SAIC, 8 Sep 2023
17  */
18 
19 float axis_interp( float *axis_arr_vals, int32_t n_ax, float ind_frac )
20  {
21  float retval, fr;
22  int32_t indx;
23 
24  // first, just return min or max if we're outside
25  if( ind_frac <= 0 )
26  {
27  retval = axis_arr_vals[0];
28  }
29  else if( ind_frac >= n_ax - 1 )
30  {
31  retval = (float) n_ax - 1;
32  retval = axis_arr_vals[ n_ax - 1 ];
33  }
34  else
35  {
36  indx = (int32_t) ind_frac;
37  fr = ind_frac - indx;
38  retval = fr * axis_arr_vals[ indx + 1 ] + ( 1. - fr ) * axis_arr_vals[indx];
39  }
40  return retval;
41  }
42 
float axis_interp(float *axis_arr_vals, int32_t n_ax, float ind_frac)
Definition: axis_interp.c:19