source: trunk/src/BufferedBisectionLocator.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: 1.4 KB
Line 
1//
2// C++ Implementation: BufferedBisectionLocator
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 "BufferedBisectionLocator.h"
15
16namespace asap {
17
18BufferedBisectionLocator::BufferedBisectionLocator(double *v, unsigned int n)
19  : Locator(v, n),
20    prev_(0)
21{}
22
23BufferedBisectionLocator::~BufferedBisectionLocator()
24{}
25
26unsigned int BufferedBisectionLocator::locate(double x)
27{
28  if (n_ == 1)
29    return 0;
30  bool ascending = (x_[n_-1] >= x_[0]);
31  if (ascending) {
32    if (x <= x_[0])
33      return 0;
34    else if (x > x_[n_-1])
35      return n_;
36
37    unsigned int jl = 0;
38    unsigned int ju = n_;
39    unsigned int jm;
40
41    if (x < x_[prev_]) {
42      ju = prev_;
43      prev_ = 0;
44    }
45    else
46      jl = prev_;
47
48    while (ju - jl > 1) {
49      jm = (ju + jl) >> 1;
50      if (x > x_[jm])
51        jl = jm;
52      else
53        ju = jm;
54    }
55    prev_ = jl;
56    return ju;
57  }
58  else {
59    if (x >= x_[0])
60      return 0;
61    else if (x < x_[n_-1])
62      return n_;
63
64    unsigned int jl = 0;
65    unsigned int ju = n_;
66    unsigned int jm;
67
68    if (x > x_[prev_]) {
69      ju = prev_;
70      prev_ = 0;
71    }
72    else
73      jl = prev_;
74
75    while (ju - jl > 1) {
76      jm = (ju + jl) >> 1;
77      if (x < x_[jm])
78        jl = jm;
79      else
80        ju = jm;
81    }
82    prev_ = jl;
83    return ju;
84  }
85}
86
87}
Note: See TracBrowser for help on using the repository browser.