[28] | 1 | //#---------------------------------------------------------------------------
|
---|
| 2 | //# SDWriter.cc: ASAP class to write out single dish spectra.
|
---|
| 3 | //#---------------------------------------------------------------------------
|
---|
| 4 | //# Copyright (C) 2004
|
---|
| 5 | //# Mark Calabretta, ATNF
|
---|
| 6 | //#
|
---|
| 7 | //# This program is free software; you can redistribute it and/or modify it
|
---|
| 8 | //# under the terms of the GNU General Public License as published by the Free
|
---|
| 9 | //# Software Foundation; either version 2 of the License, or (at your option)
|
---|
| 10 | //# any later version.
|
---|
| 11 | //#
|
---|
| 12 | //# This program is distributed in the hope that it will be useful, but
|
---|
| 13 | //# WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
---|
| 15 | //# Public License for more details.
|
---|
| 16 | //#
|
---|
| 17 | //# You should have received a copy of the GNU General Public License along
|
---|
| 18 | //# with this program; if not, write to the Free Software Foundation, Inc.,
|
---|
| 19 | //# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
|
---|
| 20 | //#
|
---|
| 21 | //# Correspondence concerning this software should be addressed as follows:
|
---|
| 22 | //# Internet email: Malte.Marquarding@csiro.au
|
---|
| 23 | //# Postal address: Malte Marquarding,
|
---|
| 24 | //# Australia Telescope National Facility,
|
---|
| 25 | //# P.O. Box 76,
|
---|
| 26 | //# Epping, NSW, 2121,
|
---|
| 27 | //# AUSTRALIA
|
---|
| 28 | //#
|
---|
| 29 | //# $Id: SDWriter.cc 83 2004-09-07 01:31:02Z mar637 $
|
---|
| 30 | //#---------------------------------------------------------------------------
|
---|
| 31 |
|
---|
| 32 | #include <string>
|
---|
| 33 |
|
---|
[81] | 34 | #include <casa/aips.h>
|
---|
| 35 | #include <casa/Arrays.h>
|
---|
| 36 | #include <casa/BasicSL/Complex.h>
|
---|
| 37 | #include <casa/Utilities/CountedPtr.h>
|
---|
[28] | 38 |
|
---|
| 39 | #include <atnf/PKSIO/PKSMS2writer.h>
|
---|
| 40 | #include <atnf/PKSIO/PKSSDwriter.h>
|
---|
| 41 |
|
---|
[60] | 42 | #include "SDContainer.h"
|
---|
| 43 | #include "SDMemTable.h"
|
---|
| 44 | #include "SDWriter.h"
|
---|
[28] | 45 |
|
---|
[83] | 46 | using namespace asap;
|
---|
[28] | 47 |
|
---|
| 48 | //--------------------------------------------------------- SDWriter::SDWriter
|
---|
| 49 |
|
---|
| 50 | // Default constructor.
|
---|
| 51 |
|
---|
| 52 | SDWriter::SDWriter(
|
---|
[62] | 53 | const std::string &format)
|
---|
[28] | 54 | {
|
---|
| 55 | cFormat = format;
|
---|
| 56 |
|
---|
| 57 | if (cFormat == "MS2") {
|
---|
| 58 | cWriter = new PKSMS2writer();
|
---|
| 59 | } else {
|
---|
| 60 | cWriter = new PKSSDwriter();
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | //-------------------------------------------------------- SDWriter::~SDWriter
|
---|
| 65 |
|
---|
| 66 | // Destructor.
|
---|
| 67 |
|
---|
| 68 | SDWriter::~SDWriter()
|
---|
| 69 | {
|
---|
| 70 | // Nothing.
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | //-------------------------------------------------------- SDWriter::setFormat
|
---|
| 74 |
|
---|
| 75 | // Reset the output format.
|
---|
| 76 |
|
---|
| 77 | Int SDWriter::setFormat(
|
---|
[62] | 78 | const std::string &format)
|
---|
[28] | 79 | {
|
---|
| 80 | if (format != cFormat) {
|
---|
| 81 | delete cWriter;
|
---|
| 82 |
|
---|
| 83 | cFormat = format;
|
---|
| 84 | if (cFormat == "MS2") {
|
---|
| 85 | cWriter = new PKSMS2writer();
|
---|
| 86 | } else {
|
---|
| 87 | cWriter = new PKSSDwriter();
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | return 0;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | //------------------------------------------------------------ SDWriter::write
|
---|
| 95 |
|
---|
| 96 | // Write an SDMemTable to file in the desired format, closing the file when
|
---|
| 97 | // finished.
|
---|
| 98 |
|
---|
| 99 | Int SDWriter::write(
|
---|
| 100 | const CountedPtr<SDMemTable> table,
|
---|
[35] | 101 | const std::string &filename)
|
---|
[28] | 102 | {
|
---|
| 103 | // Extract the header from the table.
|
---|
| 104 | SDHeader hdr = table->getSDHeader();
|
---|
| 105 | Int nPol = hdr.npol;
|
---|
| 106 | Int nChan = hdr.nchan;
|
---|
| 107 |
|
---|
| 108 | // Create the output file and write static data.
|
---|
| 109 | Int status;
|
---|
| 110 | if (status = cWriter->create(filename, hdr.observer, hdr.project,
|
---|
| 111 | hdr.antennaname, hdr.antennaposition,
|
---|
| 112 | hdr.obstype, hdr.equinox, hdr.freqref,
|
---|
| 113 | nChan, nPol, False, False)) {
|
---|
| 114 | cerr << "Failed to create output file." << endl;
|
---|
| 115 | return 1;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | Int scanNo = -1;
|
---|
| 119 | Int cycleNo;
|
---|
| 120 | Double mjd0 = 0.0;
|
---|
| 121 |
|
---|
| 122 | Int count = 0;
|
---|
| 123 | for (Int iRow = 0; iRow < table->nRows(); iRow++) {
|
---|
| 124 | // Extract the next integration from the table.
|
---|
| 125 | SDContainer sd = table->getSDContainer(iRow);
|
---|
| 126 | if (sd.scanid != scanNo) {
|
---|
| 127 | scanNo = sd.scanid;
|
---|
| 128 | mjd0 = sd.timestamp;
|
---|
| 129 | cycleNo = 1;
|
---|
| 130 | } else if (fabs(sd.timestamp-mjd0) > sd.interval) {
|
---|
| 131 | cycleNo++;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | // Write it out beam by beam.
|
---|
| 135 | for (Int iBeam = 0; iBeam < hdr.nbeam; iBeam++) {
|
---|
| 136 |
|
---|
| 137 | // Write it out IF by IF.
|
---|
| 138 | for (Int iIF = 0; iIF < hdr.nif; iIF++) {
|
---|
| 139 | // None of these are stored in SDMemTable by SDReader.
|
---|
| 140 | String fieldName = "";
|
---|
[79] | 141 | //Vector<Double> srcDir(2, 0.0);
|
---|
[28] | 142 | Vector<Double> srcPM(2, 0.0);
|
---|
| 143 | Double srcVel = 0.0;
|
---|
| 144 | Double freqInc = 0.0;
|
---|
[74] | 145 | Double restFreq = 0.0;
|
---|
[28] | 146 | Vector<Float> tcal(2, 0.0f);
|
---|
| 147 | String tcalTime = "";
|
---|
| 148 | Float azimuth = 0.0f;
|
---|
| 149 | Float elevation = 0.0f;
|
---|
| 150 | Float parAngle = 0.0f;
|
---|
| 151 | Float focusAxi = 0.0f;
|
---|
| 152 | Float focusTan = 0.0f;
|
---|
| 153 | Float focusRot = 0.0f;
|
---|
| 154 | Float temperature = 0.0f;
|
---|
| 155 | Float pressure = 0.0f;
|
---|
| 156 | Float humidity = 0.0f;
|
---|
| 157 | Float windSpeed = 0.0f;
|
---|
| 158 | Float windAz = 0.0f;
|
---|
| 159 | Int refBeam = 0;
|
---|
[79] | 160 | //Vector<Double> direction(2, 0.0);
|
---|
[28] | 161 | Vector<Double> scanRate(2, 0.0);
|
---|
| 162 | Vector<Float> sigma(nPol, 0.0f);
|
---|
| 163 | Vector<Float> calFctr(nPol, 0.0f);
|
---|
| 164 | Matrix<Float> baseLin(nPol,2, 0.0f);
|
---|
| 165 | Matrix<Float> baseSub(nPol,9, 0.0f);
|
---|
| 166 | Complex xCalFctr;
|
---|
| 167 | Vector<Complex> xPol;
|
---|
| 168 | if (status = cWriter->write(sd.scanid, cycleNo, sd.timestamp,
|
---|
| 169 | sd.interval, fieldName, sd.sourcename,
|
---|
[79] | 170 | sd.getDirection(iBeam),
|
---|
| 171 | srcPM, srcVel, iIF+1, hdr.reffreq,
|
---|
[75] | 172 | hdr.bandwidth, freqInc, restFreq, tcal,
|
---|
[74] | 173 | tcalTime, azimuth, elevation, parAngle,
|
---|
[28] | 174 | focusAxi, focusTan, focusRot, temperature,
|
---|
| 175 | pressure, humidity, windSpeed, windAz,
|
---|
[79] | 176 | refBeam, iBeam+1,
|
---|
| 177 | sd.getDirection(iBeam),
|
---|
| 178 | scanRate,
|
---|
[75] | 179 | sd.getTsys(iBeam, iIF), sigma, calFctr,
|
---|
| 180 | baseLin, baseSub,
|
---|
[28] | 181 | sd.getSpectrum(iBeam, iIF),
|
---|
| 182 | sd.getFlags(iBeam, iIF),
|
---|
| 183 | xCalFctr, xPol)) {
|
---|
| 184 | cerr << "Error writing output file." << endl;
|
---|
| 185 | return 1;
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | count++;
|
---|
| 189 | }
|
---|
| 190 | }
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | cout << "SDWriter: wrote " << count << " rows to " << filename << endl;
|
---|
| 194 | cWriter->close();
|
---|
| 195 |
|
---|
| 196 | return 0;
|
---|
| 197 | }
|
---|