source: branches/newfiller/external-alma/atnf/PKSIO/MBrecord.cc@ 2754

Last change on this file since 2754 was 1757, checked in by Kana Sugimoto, 14 years ago

New Development: Yes

JIRA Issue: Yes (CAS-2211)

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: ASAP 3.0.0 interface changes

Test Programs:

Put in Release Notes: Yes

Module(s): all the CASA sd tools and tasks are affected.

Description: Merged ATNF-ASAP 3.0.0 developments to CASA (alma) branch.

Note you also need to update casa/code/atnf.


File size: 11.0 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 polNo = other.polNo ;
325 srcVelocity = other.srcVelocity ;
326
327 return *this;
328}
329
330//---------------------------------------------------------- MBrecord::extract
331
332// Extract a selected IF from one MBrecord into another.
333
334int MBrecord::extract(const MBrecord &other, int iIF)
335{
336 if (this == &other) {
337 return 1;
338 }
339
340 setNIFs(1);
341
342 scanNo = other.scanNo;
343 cycleNo = other.cycleNo;
344 strcpy(datobs, other.datobs);
345 utc = other.utc;
346
347 exposure = other.exposure;
348 strcpy(srcName, other.srcName);
349 srcRA = other.srcRA;
350 srcDec = other.srcDec;
351 restFreq = other.restFreq;
352 strcpy(obsType, other.obsType);
353
354 // Beam-dependent parameters.
355 beamNo = other.beamNo;
356 ra = other.ra;
357 dec = other.dec;
358 pCode = other.pCode;
359 rateAge = other.rateAge;
360 raRate = other.raRate;
361 decRate = other.decRate;
362 paRate = other.paRate;
363
364 // IF-dependent parameters.
365 nIF = 1;
366 IFno[0] = other.IFno[iIF];
367 nChan[0] = other.nChan[iIF];
368 nPol[0] = other.nPol[iIF];
369 fqRefPix[0] = other.fqRefPix[iIF];
370 fqRefVal[0] = other.fqRefVal[iIF];
371 fqDelt[0] = other.fqDelt[iIF];
372
373 for (int j = 0; j < 2; j++) {
374 tsys[0][j] = other.tsys[iIF][j];
375 }
376
377 for (int j = 0; j < 2; j++) {
378 calfctr[0][j] = other.calfctr[iIF][j];
379 xcalfctr[0][j] = other.xcalfctr[iIF][j];
380 }
381
382 haveBase = other.haveBase;
383 for (int ipol = 0; ipol < nPol[0]; ipol++) {
384 baseLin[0][ipol][0] = other.baseLin[iIF][ipol][0];
385 baseLin[0][ipol][1] = other.baseLin[iIF][ipol][1];
386
387 for (int j = 0; j < 24; j++) {
388 baseSub[0][ipol][j] = other.baseSub[iIF][ipol][j];
389 }
390 }
391
392 for (int j = 0; j < 2; j++) {
393 tcal[0][j] = other.tcal[iIF][j];
394 }
395
396 haveSpectra = other.haveSpectra;
397 if (haveSpectra) {
398 int nprod = nChan[0] * nPol[0];
399 int nxpol = other.xpol[iIF] ? nChan[0] * 2 : 0;
400 allocate(0, nprod, nxpol);
401
402 // Copy data.
403 float *specp = spectra[0];
404 float *ospecp = other.spectra[iIF];
405 unsigned char *flagp = flagged[0];
406 unsigned char *oflagp = other.flagged[iIF];
407 for (int j = 0; j < nChan[0]*nPol[0]; j++) {
408 *(specp++) = *(ospecp++);
409 *(flagp++) = *(oflagp++);
410 }
411
412 if (xpol[0]) {
413 float *xpolp = xpol[0];
414 float *oxpolp = other.xpol[iIF];
415 for (int j = 0; j < 2*nChan[0]; j++) {
416 *(xpolp++) = *(oxpolp++);
417 }
418 }
419 }
420
421 extraSysCal = other.extraSysCal;
422
423 azimuth = other.azimuth;
424 elevation = other.elevation;
425 parAngle = other.parAngle;
426
427 focusAxi = other.focusAxi;
428 focusTan = other.focusTan;
429 focusRot = other.focusRot;
430
431 temp = other.temp;
432 pressure = other.pressure;
433 humidity = other.humidity;
434 windSpeed = other.windSpeed;
435 windAz = other.windAz;
436
437 strcpy(tcalTime, other.tcalTime);
438
439 refBeam = other.refBeam;
440
441 polNo = other.polNo ;
442 srcVelocity = other.srcVelocity ;
443
444 return 0;
445}
Note: See TracBrowser for help on using the repository browser.