IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 30, 2023, 9:45:29 AM (3 years ago)
Author:
eugene
Message:

adding option to spline1d to specify boundary 1st derivatives (default is 2nd derive = 0.0)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/lib.data/spline.c

    r41341 r42332  
    22
    33/* construct the natural spline for x, y in y2 */
    4 void spline_construct_flt (float *x, float *y, int N, float *y2) {
     4void spline_construct_flt (float *x, float *y, int N, float *y2, float dyLower, float dyUpper) {
    55
    66  int i;
     
    6767
    6868/* construct the natural spline for x, y in y2 */
    69 void spline_construct_dbl (opihi_flt *x, opihi_flt *y, int N, opihi_flt *y2) {
     69void spline_construct_dbl (opihi_flt *x, opihi_flt *y, int N, opihi_flt *y2, opihi_flt dyLower, opihi_flt dyUpper) {
    7070
    7171  int i;
     
    7777  ALLOCATE (tmp, opihi_flt, N);
    7878
    79   y2[0] = tmp[0] = 0.0;
     79  if (isnan(dyLower)) {
     80    y2[0] = tmp[0] = 0.0;
     81  } else {
     82    y2[0] = -0.5;
     83    tmp[0]   = (3.0/(x[1]-x[0])) * ((y[1]-y[0])/(x[1]-x[0]) - dyLower);
     84  }
    8085 
    8186  for (i = 1; i < N-1; i++) {
     
    8691    tmp[i] = (6.0 * tmp[i] / (x[i+1] - x[i-1]) - dx*tmp[i-1]) / dy;
    8792  }
     93
     94  if (isfinite(dyUpper)) {
     95    opihi_flt qn = 0.5;
     96    tmp[N-1] = (3.0/(x[N-1]-x[N-2])) * (dyUpper - (y[N-1]-y[N-2])/(x[N-1]-x[N-2]));
     97    y2[N-1] = (tmp[N-1] - (qn * tmp[N-2])) / ((qn * y2[N-2]) + 1.0);
     98  } else {
     99    y2[N-1] = 0;
     100  }
    88101 
    89   y2[N-1] = 0;
    90   for (i = N-2; i >= 1; i--)
     102  for (i = N-2; i >= 0; i--) {
    91103    y2[i] = y2[i]*y2[i+1] + tmp[i];
     104  }
    92105
    93106  free (tmp);
Note: See TracChangeset for help on using the changeset viewer.