[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>
|
---|
[2756] | 16 | #include <casa/Utilities/Assert.h>
|
---|
[2720] | 17 |
|
---|
| 18 | #include "Calibrator.h"
|
---|
| 19 |
|
---|
[3106] | 20 | using namespace casacore;
|
---|
[2720] | 21 |
|
---|
| 22 | namespace asap {
|
---|
| 23 |
|
---|
| 24 | Calibrator::Calibrator()
|
---|
| 25 | : nchan_(0),
|
---|
| 26 | nchanS_(0),
|
---|
| 27 | source_(0),
|
---|
| 28 | ref_(0),
|
---|
| 29 | ref2_(0),
|
---|
| 30 | scaler_(0),
|
---|
| 31 | calibrated_(0)
|
---|
| 32 | {}
|
---|
| 33 |
|
---|
| 34 | Calibrator::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 |
|
---|
| 44 | Calibrator::~Calibrator()
|
---|
| 45 | {
|
---|
| 46 | freeStorage();
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | void 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 |
|
---|
| 63 | void 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 |
|
---|
| 72 | void Calibrator::setReference(Vector<Float> &v)
|
---|
| 73 | {
|
---|
[2756] | 74 | //assert(v.nelements() == nchan_);
|
---|
| 75 | assert_<AipsError>(v.nelements() == nchan_, "Reference spectrum shape mismatch.");
|
---|
[2720] | 76 | set(ref_, v);
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | void Calibrator::setReference2(Vector<Float> &v)
|
---|
| 80 | {
|
---|
[2756] | 81 | //assert(v.nelements() == nchan_);
|
---|
| 82 | assert_<AipsError>(v.nelements() == nchan_, "Second reference spectrum shape mismatch.");
|
---|
[2720] | 83 | if (!ref2_)
|
---|
| 84 | ref2_ = new Float[nchan_];
|
---|
| 85 | set(ref2_, v);
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | void Calibrator::setScaler(Vector<Float> &v)
|
---|
| 89 | {
|
---|
[2756] | 90 | //assert(v.nelements() == nchan_ || v.nelements() == 1);
|
---|
| 91 | assert_<AipsError>(v.nelements() == nchan_ || v.nelements() == 1,
|
---|
| 92 | "Scaling factor shape mismatch.");
|
---|
[2720] | 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 |
|
---|
| 107 | void Calibrator::initStorage()
|
---|
| 108 | {
|
---|
| 109 | freeStorage();
|
---|
| 110 | source_ = new Float[nchan_];
|
---|
| 111 | ref_ = new Float[nchan_];
|
---|
| 112 | calibrated_ = new Float[nchan_];
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | void 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 |
|
---|
| 139 | const Vector<Float> Calibrator::getCalibrated()
|
---|
| 140 | {
|
---|
| 141 | return Vector<Float>(IPosition(1,nchan_), calibrated_, SHARE);
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | }
|
---|