source: trunk/src/BufferedLinearInterpolator1D.tcc @ 2756

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

New Development: No

JIRA Issue: Yes CAS-4770

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: test_sdcal2

Put in Release Notes: No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Replace assert with casa::assert_ to avoid aborting casapy session.


File size: 1.7 KB
Line 
1//
2// C++ Implementation: BufferedLinearInterpolator1D
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 <casa/Exceptions/Error.h>
15#include <casa/Utilities/Assert.h>
16
17#include "BufferedLinearInterpolator1D.h"
18
19namespace asap {
20
21template <class T, class U>
22BufferedLinearInterpolator1D<T, U>::BufferedLinearInterpolator1D()
23  : Interpolator1D<T, U>(),
24    reusable_(false)
25{}
26
27template <class T, class U>
28BufferedLinearInterpolator1D<T, U>::~BufferedLinearInterpolator1D()
29{}
30
31template <class T, class U>
32void BufferedLinearInterpolator1D<T, U>::setData(T *x, U *y, unsigned int n)
33{
34  Interpolator1D<T, U>::setData(x, y, n);
35  reusable_ = false;
36}
37
38template <class T, class U>
39void BufferedLinearInterpolator1D<T, U>::setX(T *x, unsigned int n)
40{
41  Interpolator1D<T, U>::setX(x, n);
42  reusable_ = false;
43}
44
45template <class T, class U>
46U BufferedLinearInterpolator1D<T, U>::interpolate(T x)
47{
48  //assert(this->isready());
49  assert_<casa::AipsError>(this->isready(), "object is not ready to process.");
50  if (this->n_ == 1)
51    return this->y_[0];
52
53  unsigned int i;
54  bool b = (reusable_ && x == xold_);
55  if (b) {
56    i = prev_;
57  }
58  else {
59    i = this->locator_->locate(x);
60    prev_ = i;
61    xold_ = x;
62  }
63
64  // do not perform extrapolation
65  if (i == 0) {
66    return this->y_[i];
67  }
68  else if (i == this->n_) {
69    return this->y_[i-1];
70  }
71
72  // linear interpolation
73  if (!b)
74    factor_ = (x - this->x_[i-1]) / (this->x_[i] - this->x_[i-1]);
75  U y = this->y_[i-1] + (this->y_[i] - this->y_[i-1]) * factor_;
76  reusable_ = true;
77  return y;
78}
79
80}
Note: See TracBrowser for help on using the repository browser.