Ignore:
Timestamp:
01/16/13 16:00:28 (11 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: Yes CAS-4770

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No?

Module(s): Module Names change impacts.

Description: Describe your changes here...

Rewrite implementations for locator and interpolator.
Documentation (doxygen format) is added to header files.


File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/PolynomialInterpolator1D.cpp

    r2727 r2730  
    1212#include <assert.h>
    1313#include <math.h>
     14#include <iostream>
     15using namespace std;
     16
     17#include <casa/Exceptions/Error.h>
    1418
    1519#include "PolynomialInterpolator1D.h"
     
    4347  float y;
    4448  if (order_ >= n_ - 1) {
    45     y = polint(x, i, 0, n_);
     49    // use full region
     50    y = dopoly(x, 0, n_);
    4651  }
    4752  else {
     53    // use partial region
    4854    int j = i - 1 - order_ / 2;
    4955    unsigned int m = n_ - 1 - order_;
    5056    unsigned int k = (unsigned int)((j > 0) ? j : 0);
    5157    k = ((k > m) ? m : k);
    52     y = polint(x, i, k, order_ + 1);
     58    y = dopoly(x, k, order_ + 1);
    5359  }
    5460
     
    5662}
    5763
    58 float PolynomialInterpolator1D::polint(double x, unsigned int loc,
    59                                        unsigned int left, unsigned int n)
     64float PolynomialInterpolator1D::dopoly(double x, unsigned int left,
     65                                       unsigned int n)
    6066{
    61   int ns = loc - left;
    62   if (fabs(x - x_[loc]) >= fabs(x - x_[loc-1])) {
    63     ns--;
    64   }
    65 
    6667  double *xa = &x_[left];
    6768  float *ya = &y_[left];
    6869
    69   float y = ya[ns];
    70  
    71   // c stores C11, C21, C31, ..., C[n-1]1
    72   // d stores D11, D21, D31, ..., D[n-1]1
     70  // storage for C and D in Neville's algorithm
    7371  float *c = new float[n];
    7472  float *d = new float[n];
     
    7876  }
    7977
     78  // Neville's algorithm
     79  float y = c[0];
    8080  for (unsigned int m = 1; m < n; m++) {
     81    // Evaluate Cm1, Cm2, Cm3, ... Cm[n-m] and Dm1, Dm2, Dm3, ... Dm[n-m].
     82    // Those are stored to c[0], c[1], ..., c[n-m-1] and d[0], d[1], ...,
     83    // d[n-m-1].
    8184    for (unsigned int i = 0; i < n - m; i++) {
    82       double ho = xa[i] - x;
    83       double hp = xa[i+m] - x;
    84       float w = c[i+1] - d[i];
    85       double denom = ho - hp;
    86       if (denom == 0.0) {
     85      float cd = c[i+1] - d[i];
     86      double dx = xa[i] - xa[i+m];
     87      try {
     88        cd /= dx;
     89      }
     90      catch (...) {
    8791        delete[] c;
    8892        delete[] d;
    89         assert(denom != 0.0);
     93        throw casa::AipsError("x_ has duplicate elements");
    9094      }
    91       denom = w / denom;
    92      
    93       d[i] = hp * denom;
    94       c[i] = ho * denom;
     95      c[i] = (xa[i] - x) * cd;
     96      d[i] = (xa[i+m] - x) * cd;
    9597    }
    9698
    97     float dy;
    98     if (2 * ns < (int)(n - m)) {
    99       dy = c[ns];
    100     }
    101     else {
    102       dy = d[ns-1];
    103       ns--;
    104     }
    105     y += dy;
     99    // In each step, c[0] holds Cm1 which is a correction between
     100    // P12...m and P12...[m+1]. Thus, the following repeated update
     101    // corresponds to the route P1 -> P12 -> P123 ->...-> P123...n.
     102    y += c[0];
    106103  }
    107  
     104
    108105  delete[] c;
    109106  delete[] d;
Note: See TracChangeset for help on using the changeset viewer.