[1325] | 1 | //#---------------------------------------------------------------------------
|
---|
| 2 | //# PKSSDwriter.cc: Class to write Parkes multibeam data to an SDFITS file.
|
---|
| 3 | //#---------------------------------------------------------------------------
|
---|
[1720] | 4 | //# livedata - processing pipeline for single-dish, multibeam spectral data.
|
---|
| 5 | //# Copyright (C) 2000-2009, Australia Telescope National Facility, CSIRO
|
---|
[1325] | 6 | //#
|
---|
[1720] | 7 | //# This file is part of livedata.
|
---|
[1325] | 8 | //#
|
---|
[1720] | 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 | //#
|
---|
[1720] | 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 | //#
|
---|
[1720] | 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 | //#
|
---|
[1720] | 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 |
|
---|
[1452] | 34 | #include <atnf/PKSIO/MBrecord.h>
|
---|
[1325] | 35 | #include <atnf/PKSIO/PKSSDwriter.h>
|
---|
| 36 |
|
---|
[1779] | 37 | #include <casa/Logging/LogIO.h>
|
---|
| 38 |
|
---|
[1452] | 39 | #include <casa/stdio.h>
|
---|
[1325] | 40 | #include <casa/Quanta/MVTime.h>
|
---|
| 41 |
|
---|
[1735] | 42 | #include <string>
|
---|
[1734] | 43 | #include <cstring>
|
---|
| 44 |
|
---|
[1779] | 45 | // Class name
|
---|
| 46 | const string className = "PKSSDwriter" ;
|
---|
| 47 |
|
---|
[1325] | 48 | //--------------------------------------------------- PKSSDwriter::PKSSDwriter
|
---|
| 49 |
|
---|
| 50 | // Default constructor.
|
---|
| 51 |
|
---|
| 52 | PKSSDwriter::PKSSDwriter()
|
---|
| 53 | {
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | //-------------------------------------------------- PKSSDwriter::~PKSSDwriter
|
---|
| 57 |
|
---|
| 58 | // Destructor.
|
---|
| 59 |
|
---|
| 60 | PKSSDwriter::~PKSSDwriter()
|
---|
| 61 | {
|
---|
| 62 | close();
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | //-------------------------------------------------------- PKSSDwriter::create
|
---|
| 66 |
|
---|
| 67 | // Create the SDFITS file and and write static data.
|
---|
| 68 |
|
---|
| 69 | Int 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,
|
---|
[1399] | 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,
|
---|
| 82 | const Bool haveBase)
|
---|
| 83 | {
|
---|
[1779] | 84 | const string methodName = "create()" ;
|
---|
| 85 | LogIO os( LogOrigin( className, methodName, WHERE ) ) ;
|
---|
[1452] | 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) {
|
---|
[1779] | 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(),
|
---|
[1399] | 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);
|
---|
[1779] | 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 |
|
---|
| 135 | Int PKSSDwriter::write(
|
---|
[1452] | 136 | const PKSrecord &pksrec)
|
---|
[1325] | 137 | {
|
---|
[1779] | 138 | const string methodName = "write()" ;
|
---|
| 139 | LogIO os( LogOrigin( className, methodName, WHERE ) ) ;
|
---|
| 140 |
|
---|
[1325] | 141 | // Do basic checks.
|
---|
[1452] | 142 | Int IFno = pksrec.IFno;
|
---|
[1325] | 143 | uInt iIF = IFno - 1;
|
---|
| 144 | if (IFno < 1 || Int(cNIF) < IFno) {
|
---|
[1779] | 145 | os << LogIO::SEVERE
|
---|
| 146 | << "Invalid IF number " << IFno
|
---|
| 147 | << " (maximum " << cNIF << ")." << LogIO::POST ;
|
---|
[1325] | 148 | return 1;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
[1452] | 151 | uInt nChan = pksrec.spectra.nrow();
|
---|
[1325] | 152 | if (nChan != cNChan(iIF)) {
|
---|
[1779] | 153 | os << LogIO::SEVERE << "Wrong number of channels for IF " << IFno << "," << endl
|
---|
[1325] | 154 | << "got " << nChan << " should be " << cNChan(iIF) << "." << endl;
|
---|
[1779] | 155 | os << LogIO::POST ;
|
---|
[1325] | 156 | return 1;
|
---|
| 157 | }
|
---|
| 158 |
|
---|
[1452] | 159 | uInt nPol = pksrec.spectra.ncolumn();
|
---|
[1325] | 160 | if (nPol != cNPol(iIF)) {
|
---|
[1779] | 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 |
|
---|
[1779] | 167 | // Extract calendar information frrom mjd.
|
---|
[1452] | 168 | MVTime time(pksrec.mjd);
|
---|
[1325] | 169 | Int year = time.year();
|
---|
| 170 | Int month = time.month();
|
---|
| 171 | Int day = time.monthday();
|
---|
| 172 |
|
---|
[1452] | 173 | // Transfer data to a single-IF MBrecord.
|
---|
| 174 | MBrecord mbrec(1);
|
---|
[1325] | 175 |
|
---|
| 176 | // Start with basic beam- and IF-independent bookkeeping information.
|
---|
[1452] | 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);
|
---|
[1452] | 181 | mbrec.utc = fmod(pksrec.mjd, 1.0) * 86400.0;
|
---|
| 182 | mbrec.exposure = float(pksrec.interval);
|
---|
[1325] | 183 |
|
---|
[1452] | 184 | strncpy(mbrec.srcName, (char *)pksrec.srcName.chars(), 17);
|
---|
| 185 | mbrec.srcRA = pksrec.srcDir(0);
|
---|
| 186 | mbrec.srcDec = pksrec.srcDir(1);
|
---|
[1779] | 187 | if (pksrec.restFreq.shape()==0) {
|
---|
| 188 | mbrec.restFreq = 0;
|
---|
| 189 | }
|
---|
| 190 | else {
|
---|
| 191 | mbrec.restFreq = pksrec.restFreq(0);
|
---|
| 192 | }
|
---|
[1452] | 193 | strncpy(mbrec.obsType, (char *)pksrec.obsType.chars(), 16);
|
---|
[1325] | 194 |
|
---|
| 195 | // Now beam-dependent parameters.
|
---|
[1452] | 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;
|
---|
[1452] | 209 | mbrec.fqRefVal[0] = pksrec.refFreq;
|
---|
| 210 | mbrec.fqDelt[0] = pksrec.freqInc;
|
---|
[1325] | 211 |
|
---|
| 212 | // Now the data itself.
|
---|
[1452] | 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++) {
|
---|
[1452] | 218 | mbrec.calfctr[0][ipol] = pksrec.calFctr(ipol);
|
---|
[1325] | 219 | }
|
---|
| 220 |
|
---|
| 221 | if (cHaveXPol(iIF)) {
|
---|
[1452] | 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++) {
|
---|
[1452] | 233 | mbrec.baseLin[0][ipol][0] = pksrec.baseLin(0,ipol);
|
---|
| 234 | mbrec.baseLin[0][ipol][1] = pksrec.baseLin(1,ipol);
|
---|
[1325] | 235 |
|
---|
[1452] | 236 | for (uInt j = 0; j < pksrec.baseSub.nrow(); j++) {
|
---|
| 237 | mbrec.baseSub[0][ipol][j] = pksrec.baseSub(j,ipol);
|
---|
[1325] | 238 | }
|
---|
[1635] | 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;
|
---|
[1452] | 249 | const Float *specstor = pksrec.spectra.getStorage(delSpectra);
|
---|
[1325] | 250 | mbrec.spectra[0] = (float *)specstor;
|
---|
| 251 |
|
---|
| 252 | Bool delFlagged = False;
|
---|
[1452] | 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)) {
|
---|
[1452] | 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;
|
---|
[1452] | 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 | }
|
---|
[1452] | 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);
|
---|
[1779] | 285 | //logMsg(cSDwriter.getMsg());
|
---|
| 286 | //cSDwriter.clearMsg();
|
---|
[1325] | 287 | if (status) {
|
---|
| 288 | status = 1;
|
---|
| 289 | }
|
---|
| 290 |
|
---|
[1452] | 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 |
|
---|
[1399] | 298 | //------------------------------------------------------- PKSSDwriter::history
|
---|
| 299 |
|
---|
| 300 | // Write a history record.
|
---|
| 301 |
|
---|
| 302 | Int PKSSDwriter::history(const String text)
|
---|
| 303 | {
|
---|
| 304 | return cSDwriter.history((char *)text.chars());
|
---|
| 305 | }
|
---|
| 306 |
|
---|
| 307 | Int 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 |
|
---|
| 316 | void PKSSDwriter::close()
|
---|
| 317 | {
|
---|
| 318 | cSDwriter.close();
|
---|
[1779] | 319 | //logMsg(cSDwriter.getMsg());
|
---|
| 320 | //cSDwriter.clearMsg();
|
---|
[1325] | 321 | }
|
---|