source: trunk/src/SDWriter.cc@ 230

Last change on this file since 230 was 199, checked in by kil064, 20 years ago

add ascii file capabilut via SDAsciiWriter

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 KB
RevLine 
[192]1 //#---------------------------------------------------------------------------
[28]2//# SDWriter.cc: ASAP class to write out single dish spectra.
3//#---------------------------------------------------------------------------
4//# Copyright (C) 2004
[125]5//# ATNF
[28]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 199 2005-01-14 04:03:57Z kil064 $
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"
[192]45#include "SDFITSImageWriter.h"
[199]46#include "SDAsciiWriter.h"
[28]47
[125]48using namespace casa;
[83]49using namespace asap;
[28]50
51//--------------------------------------------------------- SDWriter::SDWriter
52
53// Default constructor.
54
[125]55SDWriter::SDWriter(const std::string &format)
[28]56{
57 cFormat = format;
[192]58//
[28]59 if (cFormat == "MS2") {
60 cWriter = new PKSMS2writer();
[192]61 } else if (cFormat == "SDFITS") {
[28]62 cWriter = new PKSSDwriter();
[192]63 } else if (cFormat == "FITS") {
64 cWriter = 0;
[199]65 } else if (cFormat == "ASCII") {
66 cWriter = 0;
[28]67 }
68}
69
70//-------------------------------------------------------- SDWriter::~SDWriter
71
72// Destructor.
73
74SDWriter::~SDWriter()
75{
[192]76 if (cWriter) {
77 delete cWriter;
78 }
[28]79}
80
81//-------------------------------------------------------- SDWriter::setFormat
82
83// Reset the output format.
84
[192]85Int SDWriter::setFormat(const std::string &format)
[28]86{
87 if (format != cFormat) {
[192]88 if (cWriter) delete cWriter;
89//
[28]90 cFormat = format;
91 if (cFormat == "MS2") {
92 cWriter = new PKSMS2writer();
[192]93 } else if (cFormat == "SDFITS") {
[28]94 cWriter = new PKSSDwriter();
[192]95 } else if (cFormat == "FITS") {
96 cWriter = 0;
[199]97 } else if (cFormat == "ASCII") {
98 cWriter = 0;
[28]99 }
100 }
101 return 0;
102}
103
104//------------------------------------------------------------ SDWriter::write
105
106// Write an SDMemTable to file in the desired format, closing the file when
107// finished.
108
[192]109Int SDWriter::write(const CountedPtr<SDMemTable> table,
110 const std::string &filename)
[28]111{
[192]112
113// Image FITS
114
115 if (cFormat=="FITS") {
116 Bool verbose = True;
117 SDFITSImageWriter iw;
118 if (iw.write(*table, filename, verbose)) {
119 return 0;
120 } else {
121 return 1;
122 }
[199]123 } else if (cFormat=="ASCII") {
124 SDAsciiWriter iw;
125 if (iw.write(*table, filename)) {
126 return 0;
127 } else {
128 return 1;
129 }
130 }
[192]131
132// MS or SDFITS
133
[28]134 // Extract the header from the table.
135 SDHeader hdr = table->getSDHeader();
136 Int nPol = hdr.npol;
137 Int nChan = hdr.nchan;
138
139 // Create the output file and write static data.
140 Int status;
141 if (status = cWriter->create(filename, hdr.observer, hdr.project,
142 hdr.antennaname, hdr.antennaposition,
143 hdr.obstype, hdr.equinox, hdr.freqref,
144 nChan, nPol, False, False)) {
145 cerr << "Failed to create output file." << endl;
146 return 1;
147 }
148
149 Int scanNo = -1;
150 Int cycleNo;
151 Double mjd0 = 0.0;
152
153 Int count = 0;
[94]154 for (Int iRow = 0; iRow < table->nRow(); iRow++) {
[28]155 // Extract the next integration from the table.
156 SDContainer sd = table->getSDContainer(iRow);
157 if (sd.scanid != scanNo) {
158 scanNo = sd.scanid;
159 mjd0 = sd.timestamp;
160 cycleNo = 1;
161 } else if (fabs(sd.timestamp-mjd0) > sd.interval) {
162 cycleNo++;
163 }
164
165 // Write it out beam by beam.
166 for (Int iBeam = 0; iBeam < hdr.nbeam; iBeam++) {
167
168 // Write it out IF by IF.
169 for (Int iIF = 0; iIF < hdr.nif; iIF++) {
170 // None of these are stored in SDMemTable by SDReader.
[112]171 //String fieldName = "";
[79]172 //Vector<Double> srcDir(2, 0.0);
[28]173 Vector<Double> srcPM(2, 0.0);
174 Double srcVel = 0.0;
175 Double freqInc = 0.0;
[74]176 Double restFreq = 0.0;
[112]177 //Vector<Float> tcal(2, 0.0f);
178 //String tcalTime = "";
179 //Float azimuth = 0.0f;
180 //Float elevation = 0.0f;
181 //Float parAngle = 0.0f;
[28]182 Float focusAxi = 0.0f;
183 Float focusTan = 0.0f;
184 Float focusRot = 0.0f;
185 Float temperature = 0.0f;
186 Float pressure = 0.0f;
187 Float humidity = 0.0f;
188 Float windSpeed = 0.0f;
189 Float windAz = 0.0f;
[112]190 //Int refBeam = 0;
[79]191 //Vector<Double> direction(2, 0.0);
[28]192 Vector<Double> scanRate(2, 0.0);
193 Vector<Float> sigma(nPol, 0.0f);
194 Vector<Float> calFctr(nPol, 0.0f);
195 Matrix<Float> baseLin(nPol,2, 0.0f);
196 Matrix<Float> baseSub(nPol,9, 0.0f);
197 Complex xCalFctr;
198 Vector<Complex> xPol;
199 if (status = cWriter->write(sd.scanid, cycleNo, sd.timestamp,
[112]200 sd.interval, sd.fieldname, sd.sourcename,
[94]201 sd.getDirection(iBeam),
202 srcPM, srcVel, iIF+1, hdr.reffreq,
[112]203 hdr.bandwidth, freqInc, restFreq, sd.tcal,
204 sd.tcaltime, sd.azimuth, sd.elevation,
205 sd.parangle,
[28]206 focusAxi, focusTan, focusRot, temperature,
207 pressure, humidity, windSpeed, windAz,
[112]208 sd.refbeam, iBeam+1,
[94]209 sd.getDirection(iBeam),
210 scanRate,
[75]211 sd.getTsys(iBeam, iIF), sigma, calFctr,
212 baseLin, baseSub,
[28]213 sd.getSpectrum(iBeam, iIF),
214 sd.getFlags(iBeam, iIF),
215 xCalFctr, xPol)) {
216 cerr << "Error writing output file." << endl;
217 return 1;
218 }
219
220 count++;
221 }
222 }
223 }
224
225 cout << "SDWriter: wrote " << count << " rows to " << filename << endl;
226 cWriter->close();
227
228 return 0;
229}
Note: See TracBrowser for help on using the repository browser.