source: trunk/external/atnf/PKSIO/MBrecord.cc@ 1771

Last change on this file since 1771 was 1720, checked in by Malte Marquarding, 15 years ago

Update from livedata CVS repository

File size: 10.8 KB
Line 
1//#---------------------------------------------------------------------------
2//# MBrecord.cc: Class to store an MBFITS single-dish data record.
3//#---------------------------------------------------------------------------
4//# livedata - processing pipeline for single-dish, multibeam spectral data.
5//# Copyright (C) 2000-2009, Australia Telescope National Facility, CSIRO
6//#
7//# This file is part of livedata.
8//#
9//# livedata is free software: you can redistribute it and/or modify it under
10//# the terms of the GNU General Public License as published by the Free
11//# Software Foundation, either version 3 of the License, or (at your option)
12//# any later version.
13//#
14//# livedata is distributed in the hope that it will be useful, but WITHOUT
15//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17//# more details.
18//#
19//# You should have received a copy of the GNU General Public License along
20//# with livedata. If not, see <http://www.gnu.org/licenses/>.
21//#
22//# Correspondence concerning livedata may be directed to:
23//# Internet email: mcalabre@atnf.csiro.au
24//# Postal address: Dr. Mark Calabretta
25//# Australia Telescope National Facility, CSIRO
26//# PO Box 76
27//# Epping NSW 1710
28//# AUSTRALIA
29//#
30//# http://www.atnf.csiro.au/computing/software/livedata.html
31//# $Id: MBrecord.cc,v 19.14 2009-09-29 07:33:38 cal103 Exp $
32//#---------------------------------------------------------------------------
33//# The MBrecord class stores an MBFITS single-dish data record.
34//#
35//# Original: 2000/08/01 Mark Calabretta, ATNF
36//#---------------------------------------------------------------------------
37
38#include <atnf/PKSIO/MBrecord.h>
39
40#include <string.h>
41
42//--------------------------------------------------------- MBrecord::MBrecord
43
44// Default constructor.
45
46MBrecord::MBrecord(int nif)
47{
48 // Construct arrays for the required number of IFs.
49 cNIF = 0;
50 setNIFs(nif);
51
52 scanNo = 0;
53 cycleNo = 0;
54 beamNo = 0;
55 pCode = 0;
56 rateAge = 0.0f;
57 raRate = 0.0f;
58 decRate = 0.0f;
59 nIF = 0;
60}
61
62//-------------------------------------------------------- MBrecord::~MBrecord
63
64// Destructor.
65
66MBrecord::~MBrecord()
67{
68 free();
69}
70
71//---------------------------------------------------------- MBrecord::setNIFs
72
73// Expand arrays if necessary to accomodate the required number of IFs; never
74// contracts them.
75
76void MBrecord::setNIFs(int nif)
77{
78 if (nif < 1) return;
79
80 if (cNIF < nif) {
81 // Too few IFs, free everything.
82 if (cNIF) free();
83 }
84
85 if (cNIF == 0) {
86 IFno = new short[nif];
87 nChan = new int[nif];
88 nPol = new int[nif];
89 fqRefPix = new float[nif];
90 fqRefVal = new double[nif];
91 fqDelt = new double[nif];
92
93 tsys = new float[nif][2];
94 calfctr = new float[nif][2];
95 xcalfctr = new float[nif][2];
96 baseLin = new float[nif][2][2];
97 baseSub = new float[nif][2][24];
98 spectra = new float*[nif];
99 flagged = new unsigned char*[nif];
100 xpol = new float*[nif];
101 tcal = new float[nif][2];
102
103 cNProd = new int[nif];
104 cNXPol = new int[nif];
105
106 for (int iIF = 0; iIF < nif; iIF++) {
107 spectra[iIF] = 0x0;
108 flagged[iIF] = 0x0;
109 xpol[iIF] = 0x0;
110
111 cNProd[iIF] = 0;
112 cNXPol[iIF] = 0;
113 }
114
115 // The number we can accomodate, may exceed the number we have.
116 cNIF = nif;
117 }
118}
119
120//--------------------------------------------------------- MBrecord::allocate
121
122// Ensure there is enough storage for the specified number of spectral
123// products (channels x polarizations) for IF with array index iIF (i.e.
124// the actual IF number is IFno[iIF]). Expands arrays if necessary but
125// never contracts.
126
127void MBrecord::allocate(
128 int iIF,
129 int nprod,
130 int nxpol)
131{
132 // Don't mess with storage we didn't allocate.
133 if (cNProd[iIF] || spectra[iIF] == 0x0) {
134 if (cNProd[iIF] < nprod) {
135 if (cNProd[iIF]) {
136 // Free storage previously allocated.
137 delete [] spectra[iIF];
138 delete [] flagged[iIF];
139 }
140
141 // Reallocate data storage.
142 cNProd[iIF] = nprod;
143 spectra[iIF] = new float[nprod];
144 flagged[iIF] = new unsigned char[nprod];
145 }
146 }
147
148 if (cNXPol[iIF] || xpol[iIF] == 0x0) {
149 if (cNXPol[iIF] < nxpol) {
150 if (cNXPol[iIF]) {
151 // Free storage previously allocated.
152 delete [] xpol[iIF];
153 }
154
155 // Reallocate xpol storage.
156 cNXPol[iIF] = nxpol;
157 xpol[iIF] = new float[nxpol];
158 }
159 }
160}
161
162//------------------------------------------------------------- MBrecord::free
163
164// Free all allocated storage.
165
166void MBrecord::free()
167{
168 if (cNIF) {
169 for (int iIF = 0; iIF < cNIF; iIF++) {
170 // Don't free storage we didn't allocate.
171 if (cNProd[iIF]) {
172 delete [] spectra[iIF];
173 delete [] flagged[iIF];
174 }
175
176 if (cNXPol[iIF]) {
177 delete [] xpol[iIF];
178 }
179 }
180
181 delete [] IFno;
182 delete [] nChan;
183 delete [] nPol;
184 delete [] fqRefPix;
185 delete [] fqRefVal;
186 delete [] fqDelt;
187
188 delete [] tsys;
189 delete [] calfctr;
190 delete [] xcalfctr;
191 delete [] baseLin;
192 delete [] baseSub;
193
194 delete [] spectra;
195 delete [] flagged;
196 delete [] xpol;
197
198 delete [] tcal;
199
200 delete [] cNProd;
201 delete [] cNXPol;
202
203 cNIF = 0;
204 }
205}
206
207//-------------------------------------------------------- MBrecord::operator=
208
209// Do a deep copy of one MBrecord to another.
210
211MBrecord &MBrecord::operator=(const MBrecord &other)
212{
213 if (this == &other) {
214 return *this;
215 }
216
217 setNIFs(other.nIF);
218
219 scanNo = other.scanNo;
220 cycleNo = other.cycleNo;
221 strcpy(datobs, other.datobs);
222 utc = other.utc;
223
224 exposure = other.exposure;
225 strcpy(srcName, other.srcName);
226 srcRA = other.srcRA;
227 srcDec = other.srcDec;
228 restFreq = other.restFreq;
229 strcpy(obsType, other.obsType);
230
231 // Beam-dependent parameters.
232 beamNo = other.beamNo;
233 ra = other.ra;
234 dec = other.dec;
235 pCode = other.pCode;
236 rateAge = other.rateAge;
237 raRate = other.raRate;
238 decRate = other.decRate;
239
240 // IF-dependent parameters.
241 nIF = other.nIF;
242 for (int iIF = 0; iIF < nIF; iIF++) {
243 IFno[iIF] = other.IFno[iIF];
244 nChan[iIF] = other.nChan[iIF];
245 nPol[iIF] = other.nPol[iIF];
246 fqRefPix[iIF] = other.fqRefPix[iIF];
247 fqRefVal[iIF] = other.fqRefVal[iIF];
248 fqDelt[iIF] = other.fqDelt[iIF];
249
250 for (int j = 0; j < 2; j++) {
251 tsys[iIF][j] = other.tsys[iIF][j];
252 }
253
254 for (int j = 0; j < 2; j++) {
255 calfctr[iIF][j] = other.calfctr[iIF][j];
256 xcalfctr[iIF][j] = other.xcalfctr[iIF][j];
257 }
258
259 haveBase = other.haveBase;
260 for (int ipol = 0; ipol < nPol[iIF]; ipol++) {
261 baseLin[iIF][ipol][0] = other.baseLin[iIF][ipol][0];
262 baseLin[iIF][ipol][1] = other.baseLin[iIF][ipol][1];
263
264 for (int j = 0; j < 24; j++) {
265 baseSub[iIF][ipol][j] = other.baseSub[iIF][ipol][j];
266 }
267 }
268
269 for (int j = 0; j < 2; j++) {
270 tcal[iIF][j] = other.tcal[iIF][j];
271 }
272 }
273
274 haveSpectra = other.haveSpectra;
275 if (haveSpectra) {
276 for (int iIF = 0; iIF < nIF; iIF++) {
277 int nprod = nChan[iIF] * nPol[iIF];
278 int nxpol = other.xpol[iIF] ? nChan[iIF] * 2 : 0;
279 allocate(iIF, nprod, nxpol);
280 }
281
282 // Copy data.
283 for (int iIF = 0; iIF < nIF; iIF++) {
284 float *specp = spectra[iIF];
285 float *ospecp = other.spectra[iIF];
286 unsigned char *flagp = flagged[iIF];
287 unsigned char *oflagp = other.flagged[iIF];
288 for (int j = 0; j < nChan[iIF]*nPol[iIF]; j++) {
289 *(specp++) = *(ospecp++);
290 *(flagp++) = *(oflagp++);
291 }
292
293 if (xpol[iIF]) {
294 float *xpolp = xpol[iIF];
295 float *oxpolp = other.xpol[iIF];
296 for (int j = 0; j < 2*nChan[iIF]; j++) {
297 *(xpolp++) = *(oxpolp++);
298 }
299 }
300 }
301 }
302
303 extraSysCal = other.extraSysCal;
304
305 azimuth = other.azimuth;
306 elevation = other.elevation;
307 parAngle = other.parAngle;
308 paRate = other.paRate;
309
310 focusAxi = other.focusAxi;
311 focusTan = other.focusTan;
312 focusRot = other.focusRot;
313
314 temp = other.temp;
315 pressure = other.pressure;
316 humidity = other.humidity;
317 windSpeed = other.windSpeed;
318 windAz = other.windAz;
319
320 strcpy(tcalTime, other.tcalTime);
321
322 refBeam = other.refBeam;
323
324 return *this;
325}
326
327//---------------------------------------------------------- MBrecord::extract
328
329// Extract a selected IF from one MBrecord into another.
330
331int MBrecord::extract(const MBrecord &other, int iIF)
332{
333 if (this == &other) {
334 return 1;
335 }
336
337 setNIFs(1);
338
339 scanNo = other.scanNo;
340 cycleNo = other.cycleNo;
341 strcpy(datobs, other.datobs);
342 utc = other.utc;
343
344 exposure = other.exposure;
345 strcpy(srcName, other.srcName);
346 srcRA = other.srcRA;
347 srcDec = other.srcDec;
348 restFreq = other.restFreq;
349 strcpy(obsType, other.obsType);
350
351 // Beam-dependent parameters.
352 beamNo = other.beamNo;
353 ra = other.ra;
354 dec = other.dec;
355 pCode = other.pCode;
356 rateAge = other.rateAge;
357 raRate = other.raRate;
358 decRate = other.decRate;
359 paRate = other.paRate;
360
361 // IF-dependent parameters.
362 nIF = 1;
363 IFno[0] = other.IFno[iIF];
364 nChan[0] = other.nChan[iIF];
365 nPol[0] = other.nPol[iIF];
366 fqRefPix[0] = other.fqRefPix[iIF];
367 fqRefVal[0] = other.fqRefVal[iIF];
368 fqDelt[0] = other.fqDelt[iIF];
369
370 for (int j = 0; j < 2; j++) {
371 tsys[0][j] = other.tsys[iIF][j];
372 }
373
374 for (int j = 0; j < 2; j++) {
375 calfctr[0][j] = other.calfctr[iIF][j];
376 xcalfctr[0][j] = other.xcalfctr[iIF][j];
377 }
378
379 haveBase = other.haveBase;
380 for (int ipol = 0; ipol < nPol[0]; ipol++) {
381 baseLin[0][ipol][0] = other.baseLin[iIF][ipol][0];
382 baseLin[0][ipol][1] = other.baseLin[iIF][ipol][1];
383
384 for (int j = 0; j < 24; j++) {
385 baseSub[0][ipol][j] = other.baseSub[iIF][ipol][j];
386 }
387 }
388
389 for (int j = 0; j < 2; j++) {
390 tcal[0][j] = other.tcal[iIF][j];
391 }
392
393 haveSpectra = other.haveSpectra;
394 if (haveSpectra) {
395 int nprod = nChan[0] * nPol[0];
396 int nxpol = other.xpol[iIF] ? nChan[0] * 2 : 0;
397 allocate(0, nprod, nxpol);
398
399 // Copy data.
400 float *specp = spectra[0];
401 float *ospecp = other.spectra[iIF];
402 unsigned char *flagp = flagged[0];
403 unsigned char *oflagp = other.flagged[iIF];
404 for (int j = 0; j < nChan[0]*nPol[0]; j++) {
405 *(specp++) = *(ospecp++);
406 *(flagp++) = *(oflagp++);
407 }
408
409 if (xpol[0]) {
410 float *xpolp = xpol[0];
411 float *oxpolp = other.xpol[iIF];
412 for (int j = 0; j < 2*nChan[0]; j++) {
413 *(xpolp++) = *(oxpolp++);
414 }
415 }
416 }
417
418 extraSysCal = other.extraSysCal;
419
420 azimuth = other.azimuth;
421 elevation = other.elevation;
422 parAngle = other.parAngle;
423
424 focusAxi = other.focusAxi;
425 focusTan = other.focusTan;
426 focusRot = other.focusRot;
427
428 temp = other.temp;
429 pressure = other.pressure;
430 humidity = other.humidity;
431 windSpeed = other.windSpeed;
432 windAz = other.windAz;
433
434 strcpy(tcalTime, other.tcalTime);
435
436 refBeam = other.refBeam;
437
438 return 0;
439}
Note: See TracBrowser for help on using the repository browser.