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: aips2-request@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 0 : VLACDA::VLACDA()
35 : :itsRecord(),
36 : itsOffset(0),
37 : itsBaselineSize(0),
38 : itsNant(0),
39 : itsNchan(0),
40 : itsACorr(0),
41 0 : itsXCorr(0)
42 : {
43 : // cout << "VLACDA::VLACDA()" << endl;
44 0 : }
45 :
46 0 : VLACDA::VLACDA(ByteSource& record, uInt offset, uInt baselineSize,
47 0 : uInt nant, uInt nchan)
48 : :itsRecord(record),
49 : itsOffset(offset),
50 : itsBaselineSize(baselineSize),
51 : itsNant(nant),
52 : 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 0 : VLACDA::VLACDA(const VLACDA& other)
62 : :itsRecord(),
63 : itsOffset(0),
64 : itsBaselineSize(0),
65 : itsNant(0),
66 : itsNchan(0),
67 : itsACorr(0),
68 0 : itsXCorr(0)
69 : {
70 : // cout << "VLACDA::VLACDA(const VLACDA& other)" << endl;
71 0 : DebugAssert(other.itsRecord.isNull() ||
72 : other.itsRecord.isReadable(), AipsError);
73 0 : DebugAssert(other.itsRecord.isNull() ||
74 : other.itsRecord.isSeekable(), AipsError);
75 0 : attach(other.itsRecord, other.itsOffset, other.itsBaselineSize,
76 0 : other.itsNant, other.itsNchan);
77 0 : }
78 :
79 0 : VLACDA::~VLACDA() {
80 : // cout << "~VLACDA::VLACDA()" << endl;
81 0 : deleteACorr(0);
82 0 : deleteXCorr(0);
83 0 : }
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 0 : void VLACDA::deleteACorr(uInt start) {
99 0 : for (uInt a = start; a < itsNant; a++) {
100 0 : VLABaselineRecord*& ptr = itsACorr[a];
101 0 : if (ptr != 0) {
102 0 : delete ptr;
103 0 : ptr = 0;
104 : }
105 : }
106 0 : }
107 :
108 0 : void VLACDA::deleteXCorr(uInt start) {
109 0 : const uInt nCorr = itsNant*(itsNant-1)/2;
110 0 : for (uInt a = start; a < nCorr; a++) {
111 0 : VLABaselineRecord*& ptr = itsXCorr[a];
112 0 : if (ptr != 0) {
113 0 : delete ptr;
114 0 : ptr = 0;
115 : }
116 : }
117 0 : }
118 :
119 0 : void VLACDA::attach(ByteSource& newRecord, uInt newOffset,
120 : uInt newBaselineSize, uInt newNant, uInt newChan) {
121 : // cout << "VLACDA::attach(...)" << endl;
122 0 : DebugAssert(newRecord.isNull() || newRecord.isReadable(), AipsError);
123 0 : DebugAssert(newRecord.isNull() || newRecord.isSeekable(), AipsError);
124 0 : itsRecord = newRecord;
125 0 : itsOffset = newOffset;
126 0 : itsBaselineSize = newBaselineSize;
127 : // pointers are only deleted if newNant < itsNant;
128 0 : deleteACorr(newNant);
129 0 : const uInt newNcorr = (newNant*(newNant-1))/2;
130 0 : deleteXCorr(newNcorr);
131 0 : itsACorr.resize(newNant, false, true);
132 0 : itsXCorr.resize(newNcorr, false, true);
133 0 : for (uInt a = itsNant; a < newNant; a++) { // only done if newNant > itsNant
134 0 : itsACorr[a] = 0;
135 : }
136 0 : for (uInt a = itsNant*(itsNant-1)/2; a < newNcorr; a++) {
137 0 : itsXCorr[a] = 0;
138 : }
139 0 : itsNant = newNant;
140 :
141 0 : const uInt xCorrOffset = itsOffset + itsBaselineSize*itsNant;
142 0 : if (newChan == 1 && itsNchan == 1) {
143 0 : for (uInt a = 0; a < itsNant; a++) {
144 0 : DebugAssert(itsACorr[a] == 0 ||
145 : itsACorr[a]->type() == VLABaselineRecord::CONTINUUM,
146 : AipsError);
147 0 : VLAContinuumRecord*& ptr = (VLAContinuumRecord*&) itsACorr[a];
148 0 : if (ptr != 0) {
149 0 : ptr->attach(itsRecord, itsOffset+itsBaselineSize*a);
150 : }
151 : }
152 0 : for (uInt a = 0; a < newNcorr; a++) {
153 0 : DebugAssert(itsXCorr[a] == 0 ||
154 : itsXCorr[a]->type() == VLABaselineRecord::CONTINUUM,
155 : AipsError);
156 0 : VLAContinuumRecord*& ptr = (VLAContinuumRecord*&) itsXCorr[a];
157 0 : if (ptr != 0) {
158 0 : ptr->attach(newRecord, xCorrOffset+itsBaselineSize*a);
159 : }
160 0 : }
161 0 : } else if (newChan > 1 && itsNchan > 1) {
162 0 : for (uInt a = 0; a < itsNant; a++) {
163 0 : DebugAssert(itsACorr[a] == 0 ||
164 : itsACorr[a]->type() == VLABaselineRecord::SPECTRALLINE,
165 : AipsError);
166 0 : VLASpectralLineRecord*& ptr = (VLASpectralLineRecord*&) itsACorr[a];
167 0 : if (ptr != 0) {
168 0 : ptr->attach(itsRecord, itsOffset+itsBaselineSize*a, newChan);
169 : }
170 : }
171 0 : for (uInt a = 0; a < newNcorr; a++) {
172 0 : DebugAssert(itsXCorr[a] == 0 ||
173 : itsXCorr[a]->type() == VLABaselineRecord::SPECTRALLINE,
174 : AipsError);
175 0 : VLASpectralLineRecord*& ptr = (VLASpectralLineRecord*&) itsXCorr[a];
176 0 : if (ptr != 0) {
177 0 : ptr->attach(newRecord, xCorrOffset+itsBaselineSize*a, newChan);
178 : }
179 0 : }
180 : } else { // delete the Baseline records. They get recreated when needed.
181 0 : deleteACorr(0);
182 0 : deleteXCorr(0);
183 : }
184 0 : itsNchan = newChan;
185 0 : }
186 :
187 0 : Bool VLACDA::isValid() const {
188 0 : return (itsOffset != 0);
189 : }
190 :
191 0 : const VLABaselineRecord& VLACDA::autoCorr(uInt which) const {
192 0 : DebugAssert(which < itsACorr.nelements(), AipsError);
193 0 : if (itsACorr[which] == 0) {
194 0 : if (itsNchan == 1) {
195 0 : itsACorr[which] =
196 0 : new VLAContinuumRecord(itsRecord, itsOffset+itsBaselineSize*which);
197 : } else {
198 0 : itsACorr[which] =
199 0 : new VLASpectralLineRecord(itsRecord, itsOffset+itsBaselineSize*which,
200 0 : itsNchan);
201 : }
202 : }
203 0 : return *itsACorr[which];
204 : }
205 :
206 0 : const VLABaselineRecord& VLACDA::crossCorr(uInt which) const {
207 0 : DebugAssert(which < itsXCorr.nelements(), AipsError);
208 0 : if (itsXCorr[which] == 0) {
209 0 : const uInt xCorrOffset = itsBaselineSize*itsNant + itsOffset;
210 0 : if (itsNchan == 1) {
211 0 : itsXCorr[which] =
212 0 : new VLAContinuumRecord(itsRecord, xCorrOffset+itsBaselineSize*which);
213 : } else {
214 0 : itsXCorr[which] =
215 0 : new VLASpectralLineRecord(itsRecord, xCorrOffset+itsBaselineSize*which,
216 0 : itsNchan);
217 : }
218 : }
219 0 : return *itsXCorr[which];
220 : }
221 : // Local Variables:
222 : // compile-command: "gmake VLACDA"
223 : // End:
|