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

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

Update from livedata CVS

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