source: branches/alma/external/atnf/PKSIO/PKSSDwriter.cc@ 1769

Last change on this file since 1769 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: 9.3 KB
RevLine 
[1325]1//#---------------------------------------------------------------------------
2//# PKSSDwriter.cc: Class to write Parkes multibeam data to an SDFITS file.
3//#---------------------------------------------------------------------------
[1757]4//# livedata - processing pipeline for single-dish, multibeam spectral data.
5//# Copyright (C) 2000-2009, Australia Telescope National Facility, CSIRO
[1325]6//#
[1757]7//# This file is part of livedata.
[1325]8//#
[1757]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.
[1325]13//#
[1757]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.
[1325]18//#
[1757]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/>.
[1325]21//#
[1757]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: PKSSDwriter.cc,v 19.17 2009-09-29 07:33:38 cal103 Exp $
[1325]32//#---------------------------------------------------------------------------
33
[1757]34#include <atnf/PKSIO/MBrecord.h>
[1325]35#include <atnf/PKSIO/PKSSDwriter.h>
36
[1757]37#include <casa/Logging/LogIO.h>
38
39#include <casa/stdio.h>
[1325]40#include <casa/Quanta/MVTime.h>
41
[1757]42#include <string>
43#include <cstring>
[1325]44
[1757]45// Class name
46const string className = "PKSSDwriter" ;
47
[1325]48//--------------------------------------------------- PKSSDwriter::PKSSDwriter
49
50// Default constructor.
51
52PKSSDwriter::PKSSDwriter()
53{
54}
55
56//-------------------------------------------------- PKSSDwriter::~PKSSDwriter
57
58// Destructor.
59
60PKSSDwriter::~PKSSDwriter()
61{
62 close();
63}
64
65//-------------------------------------------------------- PKSSDwriter::create
66
67// Create the SDFITS file and and write static data.
68
69Int PKSSDwriter::create(
70 const String sdName,
71 const String observer,
72 const String project,
73 const String antName,
74 const Vector<Double> antPosition,
75 const String obsMode,
[1757]76 const String bunit,
[1325]77 const Float equinox,
78 const String dopplerFrame,
79 const Vector<uInt> nChan,
80 const Vector<uInt> nPol,
81 const Vector<Bool> haveXPol,
[1757]82 const Bool haveBase)
[1325]83{
[1757]84 const string methodName = "create()" ;
85 LogIO os( LogOrigin( className, methodName, WHERE ) ) ;
86
[1325]87 double antPos[3];
88 antPos[0] = antPosition(0);
89 antPos[1] = antPosition(1);
90 antPos[2] = antPosition(2);
91
92 cNIF = nChan.nelements();
93 if (nPol.nelements() != cNIF || haveXPol.nelements() != cNIF) {
[1757]94 os << LogIO::SEVERE << "Inconsistent number of IFs for nChan, nPol, and/or haveXPol." << LogIO::POST ;
[1325]95 return 1;
96 }
97
98 cNChan.assign(nChan);
99 cNPol.assign(nPol);
100
101 cHaveXPol.resize(cNIF);
102 for (uInt iIF = 0; iIF < cNIF; iIF++) {
103 // Convert Bool -> uInt.
104 cHaveXPol(iIF) = haveXPol(iIF) ? 1 : 0;
105 }
106
107 cHaveBase = haveBase;
108
109 // Storage in the trivial cNChan, cNPol, and cHaveXPol arrays should always
110 // be contiguous so the pointer returned by getStorage() shouldn't need to
111 // be deleted via freeStorage() (i.e. deleteIt always returned False). This
112 // storage will, of course, be deleted when the PKSwriter object is deleted.
113 Bool deleteIt;
114 Int status = cSDwriter.create((char *)sdName.chars(),
115 (char *)observer.chars(), (char *)project.chars(),
[1757]116 (char *)antName.chars(), antPos, (char *)obsMode.chars(),
117 (char *)bunit.chars(), equinox, (char *)dopplerFrame.chars(), cNIF,
[1325]118 (int *)cNChan.getStorage(deleteIt),
119 (int *)cNPol.getStorage(deleteIt),
120 (int *)cHaveXPol.getStorage(deleteIt), (int)cHaveBase, 1);
[1757]121 //logMsg(cSDwriter.getMsg());
122 //cSDwriter.clearMsg();
[1325]123 if (status) {
124 cSDwriter.deleteFile();
125 close();
126 }
127
128 return status;
129}
130
131//--------------------------------------------------------- PKSSDwriter::write
132
133// Write the next data record.
134
135Int PKSSDwriter::write(
[1757]136 const PKSrecord &pksrec)
[1325]137{
[1757]138 const string methodName = "write()" ;
139 LogIO os( LogOrigin( className, methodName, WHERE ) ) ;
140
[1325]141 // Do basic checks.
[1757]142 Int IFno = pksrec.IFno;
[1325]143 uInt iIF = IFno - 1;
144 if (IFno < 1 || Int(cNIF) < IFno) {
[1757]145 os << LogIO::SEVERE
146 << "Invalid IF number " << IFno
147 << " (maximum " << cNIF << ")." << LogIO::POST ;
[1325]148 return 1;
149 }
150
[1757]151 uInt nChan = pksrec.spectra.nrow();
[1325]152 if (nChan != cNChan(iIF)) {
[1757]153 os << LogIO::SEVERE << "Wrong number of channels for IF " << IFno << "," << endl
[1325]154 << "got " << nChan << " should be " << cNChan(iIF) << "." << endl;
[1757]155 os << LogIO::POST ;
[1325]156 return 1;
157 }
158
[1757]159 uInt nPol = pksrec.spectra.ncolumn();
[1325]160 if (nPol != cNPol(iIF)) {
[1757]161 os << LogIO::SEVERE << "Wrong number of polarizations for IF " << IFno << "," << endl
162 << "got " << nPol << " should be " << cNPol(iIF) << "." << endl;
163 os << LogIO::POST ;
[1325]164 return 1;
165 }
166
[1757]167 // Extract calendar information frrom mjd.
168 MVTime time(pksrec.mjd);
[1325]169 Int year = time.year();
170 Int month = time.month();
171 Int day = time.monthday();
172
[1757]173 // Transfer data to a single-IF MBrecord.
174 MBrecord mbrec(1);
[1325]175
176 // Start with basic beam- and IF-independent bookkeeping information.
[1757]177 mbrec.scanNo = pksrec.scanNo;
178 mbrec.cycleNo = pksrec.cycleNo;
[1325]179
180 sprintf(mbrec.datobs, "%4.4d-%2.2d-%2.2d", year, month, day);
[1757]181 mbrec.utc = fmod(pksrec.mjd, 1.0) * 86400.0;
182 mbrec.exposure = float(pksrec.interval);
[1325]183
[1757]184 strncpy(mbrec.srcName, (char *)pksrec.srcName.chars(), 17);
185 mbrec.srcRA = pksrec.srcDir(0);
186 mbrec.srcDec = pksrec.srcDir(1);
187 if (pksrec.restFreq.shape()==0) {
188 mbrec.restFreq = 0;
189 }
190 else {
191 mbrec.restFreq = pksrec.restFreq(0);
192 }
193 strncpy(mbrec.obsType, (char *)pksrec.obsType.chars(), 16);
[1325]194
195 // Now beam-dependent parameters.
[1757]196 mbrec.beamNo = pksrec.beamNo;
197 mbrec.ra = pksrec.direction(0);
198 mbrec.dec = pksrec.direction(1);
199 mbrec.raRate = pksrec.scanRate(0);
200 mbrec.decRate = pksrec.scanRate(1);
[1325]201
202 // Now IF-dependent parameters.
203 mbrec.nIF = 1;
204 mbrec.IFno[0] = IFno;
205 mbrec.nChan[0] = nChan;
206 mbrec.nPol[0] = nPol;
207
208 mbrec.fqRefPix[0] = (nChan/2) + 1;
[1757]209 mbrec.fqRefVal[0] = pksrec.refFreq;
210 mbrec.fqDelt[0] = pksrec.freqInc;
[1325]211
212 // Now the data itself.
[1757]213 for (uInt i = 0; i < pksrec.tsys.nelements(); i++) {
214 mbrec.tsys[0][i] = pksrec.tsys(i);
[1325]215 }
216
217 for (uInt ipol = 0; ipol < nPol; ipol++) {
[1757]218 mbrec.calfctr[0][ipol] = pksrec.calFctr(ipol);
[1325]219 }
220
221 if (cHaveXPol(iIF)) {
[1757]222 mbrec.xcalfctr[0][0] = pksrec.xCalFctr.real();
223 mbrec.xcalfctr[0][1] = pksrec.xCalFctr.imag();
[1325]224 } else {
225 mbrec.xcalfctr[0][0] = 0.0f;
226 mbrec.xcalfctr[0][1] = 0.0f;
227 }
228
229 if (cHaveBase) {
230 mbrec.haveBase = 1;
231
232 for (uInt ipol = 0; ipol < nPol; ipol++) {
[1757]233 mbrec.baseLin[0][ipol][0] = pksrec.baseLin(0,ipol);
234 mbrec.baseLin[0][ipol][1] = pksrec.baseLin(1,ipol);
[1325]235
[1757]236 for (uInt j = 0; j < pksrec.baseSub.nrow(); j++) {
237 mbrec.baseSub[0][ipol][j] = pksrec.baseSub(j,ipol);
[1325]238 }
[1757]239 for (uInt j = pksrec.baseSub.nrow(); j < 24; j++) {
[1325]240 mbrec.baseSub[0][ipol][j] = 0.0f;
241 }
242 }
243
244 } else {
245 mbrec.haveBase = 0;
246 }
247
248 Bool delSpectra = False;
[1757]249 const Float *specstor = pksrec.spectra.getStorage(delSpectra);
[1325]250 mbrec.spectra[0] = (float *)specstor;
251
252 Bool delFlagged = False;
[1757]253 const uChar *flagstor = pksrec.flagged.getStorage(delFlagged);
[1325]254 mbrec.flagged[0] = (unsigned char *)flagstor;
255
256 Bool delXPol = False;
257 const Complex *xpolstor;
258 if (cHaveXPol(iIF)) {
[1757]259 xpolstor = pksrec.xPol.getStorage(delXPol);
[1325]260 } else {
261 xpolstor = 0;
262 }
263 mbrec.xpol[0] = (float *)xpolstor;
264
265 // Finish off with system calibration parameters.
266 mbrec.extraSysCal = 1;
[1757]267 mbrec.refBeam = pksrec.refBeam;
268 for (uInt i = 0; i < pksrec.tcal.nelements(); i++) {
269 mbrec.tcal[0][i] = pksrec.tcal(i);
[1325]270 }
[1757]271 strncpy(mbrec.tcalTime, (char *)pksrec.tcalTime.chars(), 16);
272 mbrec.azimuth = pksrec.azimuth;
273 mbrec.elevation = pksrec.elevation;
274 mbrec.parAngle = pksrec.parAngle;
275 mbrec.focusAxi = pksrec.focusAxi;
276 mbrec.focusTan = pksrec.focusTan;
277 mbrec.focusRot = pksrec.focusRot;
278 mbrec.temp = pksrec.temperature;
279 mbrec.pressure = pksrec.pressure;
280 mbrec.humidity = pksrec.humidity;
281 mbrec.windSpeed = pksrec.windSpeed;
282 mbrec.windAz = pksrec.windAz;
[1325]283
284 Int status = cSDwriter.write(mbrec);
[1757]285 //logMsg(cSDwriter.getMsg());
286 //cSDwriter.clearMsg();
[1325]287 if (status) {
288 status = 1;
289 }
290
[1757]291 pksrec.spectra.freeStorage(specstor, delSpectra);
292 pksrec.flagged.freeStorage(flagstor, delFlagged);
293 pksrec.xPol.freeStorage(xpolstor, delXPol);
[1325]294
295 return status;
296}
297
[1757]298//------------------------------------------------------- PKSSDwriter::history
299
300// Write a history record.
301
302Int PKSSDwriter::history(const String text)
303{
304 return cSDwriter.history((char *)text.chars());
305}
306
307Int PKSSDwriter::history(const char *text)
308{
309 return cSDwriter.history((char *)text);
310}
311
[1325]312//--------------------------------------------------------- PKSSDwriter::close
313
314// Close the SDFITS file.
315
316void PKSSDwriter::close()
317{
318 cSDwriter.close();
[1757]319 //logMsg(cSDwriter.getMsg());
320 //cSDwriter.clearMsg();
[1325]321}
Note: See TracBrowser for help on using the repository browser.