source: trunk/external/atnf/PKSIO/PKSMBrecord.cc@ 1449

Last change on this file since 1449 was 1427, checked in by Malte Marquarding, 16 years ago

sync with livedata/implement/atnf

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