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 |
|
---|
19 | using namespace casa;
|
---|
20 |
|
---|
21 | namespace asap {
|
---|
22 |
|
---|
23 | Calibrator::Calibrator()
|
---|
24 | : nchan_(0),
|
---|
25 | nchanS_(0),
|
---|
26 | source_(0),
|
---|
27 | ref_(0),
|
---|
28 | ref2_(0),
|
---|
29 | scaler_(0),
|
---|
30 | calibrated_(0)
|
---|
31 | {}
|
---|
32 |
|
---|
33 | Calibrator::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 |
|
---|
43 | Calibrator::~Calibrator()
|
---|
44 | {
|
---|
45 | freeStorage();
|
---|
46 | }
|
---|
47 |
|
---|
48 | void 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 |
|
---|
62 | void 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 |
|
---|
71 | void Calibrator::setReference(Vector<Float> &v)
|
---|
72 | {
|
---|
73 | assert(v.nelements() == nchan_);
|
---|
74 | set(ref_, v);
|
---|
75 | }
|
---|
76 |
|
---|
77 | void 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 |
|
---|
85 | void 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 |
|
---|
102 | void Calibrator::initStorage()
|
---|
103 | {
|
---|
104 | freeStorage();
|
---|
105 | source_ = new Float[nchan_];
|
---|
106 | ref_ = new Float[nchan_];
|
---|
107 | calibrated_ = new Float[nchan_];
|
---|
108 | }
|
---|
109 |
|
---|
110 | void 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 |
|
---|
134 | const Vector<Float> Calibrator::getCalibrated()
|
---|
135 | {
|
---|
136 | return Vector<Float>(IPosition(1,nchan_), calibrated_, SHARE);
|
---|
137 | }
|
---|
138 |
|
---|
139 | }
|
---|