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