source: branches/casa-release-4_3/src/Calibrator.cpp@ 3090

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