source: trunk/src/LinearInterpolator1D.cpp @ 2727

Last change on this file since 2727 was 2727, checked in by Takeshi Nakazato, 11 years ago

New Development: No

JIRA Issue: Yes CAS-4770, CAS-4774

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...

Updated STApplyCal to be able to specify interpolation method.
The method can be specified in time and frequency axes independently.
Possible options are nearest, linear (default), (natural) cubic spline,
and polynomial with arbitrary order.

File size: 794 bytes
Line 
1//
2// C++ Implementation: LinearInterpolator1D
3//
4// Description:
5//
6//
7// Author: Takeshi Nakazato <takeshi.nakazato@nao.ac.jp>, (C) 2012
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#include <assert.h>
13
14#include "LinearInterpolator1D.h"
15
16namespace asap {
17
18LinearInterpolator1D::LinearInterpolator1D()
19  : Interpolator1D()
20{}
21
22LinearInterpolator1D::~LinearInterpolator1D()
23{}
24
25float LinearInterpolator1D::interpolate(double x)
26{
27  assert(isready());
28  if (n_ == 1)
29    return y_[0];
30
31  unsigned int i = locator_->locate(x);
32
33  // do not perform extrapolation
34  if (i == 0) {
35    return y_[i];
36  }
37  else if (i == n_) {
38    return y_[i-1];
39  }
40
41  // linear interpolation
42  float y = y_[i-1] + (y_[i] - y_[i-1]) * (x - x_[i-1]) / (x_[i] - x_[i-1]);
43  return y;
44}
45
46}
Note: See TracBrowser for help on using the repository browser.