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

Last change on this file since 1375 was 1325, checked in by mar637, 18 years ago

Changes to use casacore instead of casa_asap/aips++\nAdded atnf PKSIO library snapshot to external and linking against this local copy

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