source: trunk/src/BisectionLocator.cpp@ 2720

Last change on this file since 2720 was 2720, checked in by Takeshi Nakazato, 12 years ago

New Development: Yes

JIRA Issue: Yes CAS-4770 and its sub-tickets

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

First version of applycal for single dish calibration.
Added new classes for the operation (STApplyCal, Calibrator, PSAlmaCalibrator,
Locator, BisectionLocator, Interpolator1D, NearestInterpolator1D).
Also, modified existing classes to fit with implementation of applycal.


File size: 1.0 KB
Line 
1//
2// C++ Implementation: BisectionLocator
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/Arrays/Vector.h>
15#include <casa/Arrays/ArrayIO.h>
16#include <casa/Exceptions/Error.h>
17
18#include "BisectionLocator.h"
19
20using namespace casa;
21
22namespace asap {
23
24BisectionLocator::BisectionLocator(double *v, unsigned int n)
25 : Locator(v, n)
26{}
27
28BisectionLocator::~BisectionLocator()
29{}
30
31unsigned int BisectionLocator::locate(double x)
32{
33 if (n_ == 1)
34 return 0;
35 bool ascending = (x_[n_-1] >= x_[0]);
36 if (ascending) {
37 if (x <= x_[0])
38 return 0;
39 else if (x > x_[n_-1])
40 return n_;
41 }
42 else {
43 if (x > x_[0])
44 return 0;
45 else if (x <= x_[n_-1])
46 return n_;
47 }
48 unsigned int jl = 0;
49 unsigned int ju = n_;
50 unsigned int jm;
51
52 while (ju - jl > 1) {
53 jm = (ju + jl) >> 1;
54 if ((x >= x_[jm]) == ascending)
55 jl = jm;
56 else
57 ju = jm;
58 }
59 return ju;
60}
61
62}
Note: See TracBrowser for help on using the repository browser.