source: trunk/src/Calibrator.cpp@ 2735

Last change on this file since 2735 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: 2.3 KB
RevLine 
[2720]1//
2// C++ Implementation: Calibrator
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/Exceptions/Error.h>
16
17#include "Calibrator.h"
18
19using namespace casa;
20
21namespace asap {
22
23Calibrator::Calibrator()
24 : nchan_(0),
25 nchanS_(0),
26 source_(0),
27 ref_(0),
28 ref2_(0),
29 scaler_(0),
30 calibrated_(0)
31{}
32
33Calibrator::Calibrator(unsigned int nchan)
34 : nchan_(nchan),
35 nchanS_(0),
36 source_(0),
37 ref_(0),
38 ref2_(0),
39 scaler_(0),
40 calibrated_(0)
41{}
42
43Calibrator::~Calibrator()
44{
45 freeStorage();
46}
47
48void Calibrator::setSource(Vector<Float> &v)
49{
50 if (nchan_ == 0) {
51 nchan_ = v.nelements();
52 initStorage();
53 }
54 else if (nchan_ != v.nelements()) {
55 freeStorage();
56 nchan_ = v.nelements();
57 initStorage();
58 }
59 set(source_, v);
60}
61
62void Calibrator::set(Float *p, Vector<Float> &v)
63{
64 Float *work = p;
65 for (unsigned int i = 0; i < v.nelements(); i++) {
66 *work = v[i];
67 work++;
68 }
69}
70
71void Calibrator::setReference(Vector<Float> &v)
72{
73 assert(v.nelements() == nchan_);
74 set(ref_, v);
75}
76
77void Calibrator::setReference2(Vector<Float> &v)
78{
79 assert(v.nelements() == nchan_);
80 if (!ref2_)
81 ref2_ = new Float[nchan_];
82 set(ref2_, v);
83}
84
85void Calibrator::setScaler(Vector<Float> &v)
86{
87 assert(v.nelements() == nchan_ || v.nelements() == 1);
88 if (nchanS_ == 0) {
89 nchanS_ = v.nelements();
90 if (!scaler_)
91 scaler_ = new Float[nchanS_];
92 }
93 else if (v.nelements() != nchanS_) {
94 if (scaler_)
95 delete[] scaler_;
96 nchanS_ = v.nelements();
97 scaler_ = new Float[nchanS_];
98 }
99 set(scaler_, v);
100}
101
102void Calibrator::initStorage()
103{
104 freeStorage();
105 source_ = new Float[nchan_];
106 ref_ = new Float[nchan_];
107 calibrated_ = new Float[nchan_];
108}
109
110void Calibrator::freeStorage()
111{
112 if (source_) {
113 delete[] source_;
114 source_ = 0;
115 }
116 if (ref_) {
117 delete[] ref_;
118 ref_ = 0;
119 }
120 if (ref2_) {
121 delete[] ref2_;
122 ref2_ = 0;
123 }
124 if (scaler_) {
125 delete[] scaler_;
126 scaler_ = 0;
127 }
128 if (calibrated_) {
129 delete[] calibrated_;
130 calibrated_ = 0;
131 }
132}
133
134const Vector<Float> Calibrator::getCalibrated()
135{
136 return Vector<Float>(IPosition(1,nchan_), calibrated_, SHARE);
137}
138
139}
Note: See TracBrowser for help on using the repository browser.