Line data Source code
1 : //# VLACDA.cc:
2 : //# Copyright (C) 1999,2000,2001,2002
3 : //# Associated Universities, Inc. Washington DC, USA.
4 : //#
5 : //# This library is free software; you can redistribute it and/or modify it
6 : //# under the terms of the GNU Library General Public License as published by
7 : //# the Free Software Foundation; either version 2 of the License, or (at your
8 : //# option) any later version.
9 : //#
10 : //# This library is distributed in the hope that it will be useful, but WITHOUT
11 : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 : //# License for more details.
14 : //#
15 : //# You should have received a copy of the GNU Library General Public License
16 : //# along with this library; if not, write to the Free Software Foundation,
17 : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 : //#
19 : //# Correspondence concerning AIPS++ should be addressed as follows:
20 : //# Internet email: casa-feedback@nrao.edu.
21 : //# Postal address: AIPS++ Project Office
22 : //# National Radio Astronomy Observatory
23 : //# 520 Edgemont Road
24 : //# Charlottesville, VA 22903-2475 USA
25 : //#
26 : //# $Id$
27 :
28 : #include <nrao/VLA/VLACDA.h>
29 : #include <nrao/VLA/VLAContinuumRecord.h>
30 : #include <nrao/VLA/VLASpectralLineRecord.h>
31 : #include <casacore/casa/Exceptions/Error.h>
32 : #include <casacore/casa/Utilities/Assert.h>
33 :
34 64 : VLACDA::VLACDA()
35 64 : :itsRecord(),
36 64 : itsOffset(0),
37 64 : itsBaselineSize(0),
38 64 : itsNant(0),
39 64 : itsNchan(0),
40 64 : itsACorr(0),
41 64 : itsXCorr(0)
42 : {
43 : // cout << "VLACDA::VLACDA()" << endl;
44 64 : }
45 :
46 0 : VLACDA::VLACDA(ByteSource& record, uInt offset, uInt baselineSize,
47 0 : uInt nant, uInt nchan)
48 0 : :itsRecord(record),
49 0 : itsOffset(offset),
50 0 : itsBaselineSize(baselineSize),
51 0 : itsNant(nant),
52 0 : itsNchan(nchan),
53 0 : itsACorr(itsNant, (VLABaselineRecord*)0),
54 0 : itsXCorr(itsNant*(itsNant-1)/2, (VLABaselineRecord*)0)
55 : {
56 : // cout << "VLACDA::VLACDA(...)" << endl;
57 0 : DebugAssert(record.isNull() || record.isReadable(), AipsError);
58 0 : DebugAssert(record.isNull() || record.isSeekable(), AipsError);
59 0 : }
60 :
61 64 : VLACDA::VLACDA(const VLACDA& other)
62 64 : :itsRecord(),
63 64 : itsOffset(0),
64 64 : itsBaselineSize(0),
65 64 : itsNant(0),
66 64 : itsNchan(0),
67 64 : itsACorr(0),
68 64 : itsXCorr(0)
69 : {
70 : // cout << "VLACDA::VLACDA(const VLACDA& other)" << endl;
71 64 : DebugAssert(other.itsRecord.isNull() ||
72 : other.itsRecord.isReadable(), AipsError);
73 64 : DebugAssert(other.itsRecord.isNull() ||
74 : other.itsRecord.isSeekable(), AipsError);
75 64 : attach(other.itsRecord, other.itsOffset, other.itsBaselineSize,
76 64 : other.itsNant, other.itsNchan);
77 64 : }
78 :
79 128 : VLACDA::~VLACDA() {
80 : // cout << "~VLACDA::VLACDA()" << endl;
81 128 : deleteACorr(0);
82 128 : deleteXCorr(0);
83 128 : }
84 :
85 0 : VLACDA& VLACDA::operator=(const VLACDA& other) {
86 : // cout << "VLACDA::operator=(const VLACDA& other)" << endl;
87 0 : if (this != &other) {
88 0 : DebugAssert(other.itsRecord.isNull() ||
89 : other.itsRecord.isReadable(), AipsError);
90 0 : DebugAssert(other.itsRecord.isNull() ||
91 : other.itsRecord.isSeekable(), AipsError);
92 0 : attach(other.itsRecord, other.itsOffset, other.itsBaselineSize,
93 0 : other.itsNant, other.itsNchan);
94 : }
95 0 : return *this;
96 : }
97 :
98 82604 : void VLACDA::deleteACorr(uInt start) {
99 86254 : for (uInt a = start; a < itsNant; a++) {
100 3650 : VLABaselineRecord*& ptr = itsACorr[a];
101 3650 : if (ptr != 0) {
102 27 : delete ptr;
103 27 : ptr = 0;
104 : }
105 : }
106 82604 : }
107 :
108 82604 : void VLACDA::deleteXCorr(uInt start) {
109 82604 : const uInt nCorr = itsNant*(itsNant-1)/2;
110 129768 : for (uInt a = start; a < nCorr; a++) {
111 47164 : VLABaselineRecord*& ptr = itsXCorr[a];
112 47164 : if (ptr != 0) {
113 6916 : delete ptr;
114 6916 : ptr = 0;
115 : }
116 : }
117 82604 : }
118 :
119 82340 : void VLACDA::attach(ByteSource& newRecord, uInt newOffset,
120 : uInt newBaselineSize, uInt newNant, uInt newChan) {
121 : // cout << "VLACDA::attach(...)" << endl;
122 82340 : DebugAssert(newRecord.isNull() || newRecord.isReadable(), AipsError);
123 82340 : DebugAssert(newRecord.isNull() || newRecord.isSeekable(), AipsError);
124 82340 : itsRecord = newRecord;
125 82340 : itsOffset = newOffset;
126 82340 : itsBaselineSize = newBaselineSize;
127 : // pointers are only deleted if newNant < itsNant;
128 82340 : deleteACorr(newNant);
129 82340 : const uInt newNcorr = (newNant*(newNant-1))/2;
130 82340 : deleteXCorr(newNcorr);
131 82340 : itsACorr.resize(newNant, false, true);
132 82340 : itsXCorr.resize(newNcorr, false, true);
133 84060 : for (uInt a = itsNant; a < newNant; a++) { // only done if newNant > itsNant
134 1720 : itsACorr[a] = 0;
135 : }
136 104596 : for (uInt a = itsNant*(itsNant-1)/2; a < newNcorr; a++) {
137 22256 : itsXCorr[a] = 0;
138 : }
139 82340 : itsNant = newNant;
140 :
141 82340 : const uInt xCorrOffset = itsOffset + itsBaselineSize*itsNant;
142 82340 : if (newChan == 1 && itsNchan == 1) {
143 2253300 : for (uInt a = 0; a < itsNant; a++) {
144 2172668 : DebugAssert(itsACorr[a] == 0 ||
145 : itsACorr[a]->type() == VLABaselineRecord::CONTINUUM,
146 : AipsError);
147 2172668 : VLAContinuumRecord*& ptr = (VLAContinuumRecord*&) itsACorr[a];
148 2172668 : if (ptr != 0) {
149 0 : ptr->attach(itsRecord, itsOffset+itsBaselineSize*a);
150 : }
151 : }
152 28268168 : for (uInt a = 0; a < newNcorr; a++) {
153 28187536 : DebugAssert(itsXCorr[a] == 0 ||
154 : itsXCorr[a]->type() == VLABaselineRecord::CONTINUUM,
155 : AipsError);
156 28187536 : VLAContinuumRecord*& ptr = (VLAContinuumRecord*&) itsXCorr[a];
157 28187536 : if (ptr != 0) {
158 4025970 : ptr->attach(newRecord, xCorrOffset+itsBaselineSize*a);
159 : }
160 : }
161 82340 : } else if (newChan > 1 && itsNchan > 1) {
162 42698 : for (uInt a = 0; a < itsNant; a++) {
163 41126 : DebugAssert(itsACorr[a] == 0 ||
164 : itsACorr[a]->type() == VLABaselineRecord::SPECTRALLINE,
165 : AipsError);
166 41126 : VLASpectralLineRecord*& ptr = (VLASpectralLineRecord*&) itsACorr[a];
167 41126 : if (ptr != 0) {
168 3429 : ptr->attach(itsRecord, itsOffset+itsBaselineSize*a, newChan);
169 : }
170 : }
171 519076 : for (uInt a = 0; a < newNcorr; a++) {
172 517504 : DebugAssert(itsXCorr[a] == 0 ||
173 : itsXCorr[a]->type() == VLABaselineRecord::SPECTRALLINE,
174 : AipsError);
175 517504 : VLASpectralLineRecord*& ptr = (VLASpectralLineRecord*&) itsXCorr[a];
176 517504 : if (ptr != 0) {
177 517504 : ptr->attach(newRecord, xCorrOffset+itsBaselineSize*a, newChan);
178 : }
179 : }
180 1572 : } else { // delete the Baseline records. They get recreated when needed.
181 136 : deleteACorr(0);
182 136 : deleteXCorr(0);
183 : }
184 82340 : itsNchan = newChan;
185 82340 : }
186 :
187 53327 : Bool VLACDA::isValid() const {
188 53327 : return (itsOffset != 0);
189 : }
190 :
191 3456 : const VLABaselineRecord& VLACDA::autoCorr(uInt which) const {
192 3456 : DebugAssert(which < itsACorr.nelements(), AipsError);
193 3456 : if (itsACorr[which] == 0) {
194 27 : if (itsNchan == 1) {
195 0 : itsACorr[which] =
196 0 : new VLAContinuumRecord(itsRecord, itsOffset+itsBaselineSize*which);
197 : } else {
198 27 : itsACorr[which] =
199 27 : new VLASpectralLineRecord(itsRecord, itsOffset+itsBaselineSize*which,
200 27 : itsNchan);
201 : }
202 : }
203 3456 : return *itsACorr[which];
204 : }
205 :
206 2619890 : const VLABaselineRecord& VLACDA::crossCorr(uInt which) const {
207 2619890 : DebugAssert(which < itsXCorr.nelements(), AipsError);
208 2619890 : if (itsXCorr[which] == 0) {
209 6916 : const uInt xCorrOffset = itsBaselineSize*itsNant + itsOffset;
210 6916 : if (itsNchan == 1) {
211 4914 : itsXCorr[which] =
212 4914 : new VLAContinuumRecord(itsRecord, xCorrOffset+itsBaselineSize*which);
213 : } else {
214 2002 : itsXCorr[which] =
215 2002 : new VLASpectralLineRecord(itsRecord, xCorrOffset+itsBaselineSize*which,
216 2002 : itsNchan);
217 : }
218 : }
219 2619890 : return *itsXCorr[which];
220 : }
221 : // Local Variables:
222 : // compile-command: "gmake VLACDA"
223 : // End:
|