source: trunk/src/SDWriter.cc@ 207

Last change on this file since 207 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
Line 
1 //#---------------------------------------------------------------------------
2//# SDWriter.cc: ASAP class to write out single dish spectra.
3//#---------------------------------------------------------------------------
4//# Copyright (C) 2004
5//# 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 199 2005-01-14 04:03:57Z kil064 $
30//#---------------------------------------------------------------------------
31
32#include <string>
33
34#include <casa/aips.h>
35#include <casa/Arrays.h>
36#include <casa/BasicSL/Complex.h>
37#include <casa/Utilities/CountedPtr.h>
38
39#include <atnf/PKSIO/PKSMS2writer.h>
40#include <atnf/PKSIO/PKSSDwriter.h>
41
42#include "SDContainer.h"
43#include "SDMemTable.h"
44#include "SDWriter.h"
45#include "SDFITSImageWriter.h"
46#include "SDAsciiWriter.h"
47
48using namespace casa;
49using namespace asap;
50
51//--------------------------------------------------------- SDWriter::SDWriter
52
53// Default constructor.
54
55SDWriter::SDWriter(const std::string &format)
56{
57 cFormat = format;
58//
59 if (cFormat == "MS2") {
60 cWriter = new PKSMS2writer();
61 } else if (cFormat == "SDFITS") {
62 cWriter = new PKSSDwriter();
63 } else if (cFormat == "FITS") {
64 cWriter = 0;
65 } else if (cFormat == "ASCII") {
66 cWriter = 0;
67 }
68}
69
70//-------------------------------------------------------- SDWriter::~SDWriter
71
72// Destructor.
73
74SDWriter::~SDWriter()
75{
76 if (cWriter) {
77 delete cWriter;
78 }
79}
80
81//-------------------------------------------------------- SDWriter::setFormat
82
83// Reset the output format.
84
85Int SDWriter::setFormat(const std::string &format)
86{
87 if (format != cFormat) {
88 if (cWriter) delete cWriter;
89//
90 cFormat = format;
91 if (cFormat == "MS2") {
92 cWriter = new PKSMS2writer();
93 } else if (cFormat == "SDFITS") {
94 cWriter = new PKSSDwriter();
95 } else if (cFormat == "FITS") {
96 cWriter = 0;
97 } else if (cFormat == "ASCII") {
98 cWriter = 0;
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
109Int SDWriter::write(const CountedPtr<SDMemTable> table,
110 const std::string &filename)
111{
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 }
123 } else if (cFormat=="ASCII") {
124 SDAsciiWriter iw;
125 if (iw.write(*table, filename)) {
126 return 0;
127 } else {
128 return 1;
129 }
130 }
131
132// MS or SDFITS
133
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;
154 for (Int iRow = 0; iRow < table->nRow(); iRow++) {
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.
171 //String fieldName = "";
172 //Vector<Double> srcDir(2, 0.0);
173 Vector<Double> srcPM(2, 0.0);
174 Double srcVel = 0.0;
175 Double freqInc = 0.0;
176 Double restFreq = 0.0;
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;
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;
190 //Int refBeam = 0;
191 //Vector<Double> direction(2, 0.0);
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,
200 sd.interval, sd.fieldname, sd.sourcename,
201 sd.getDirection(iBeam),
202 srcPM, srcVel, iIF+1, hdr.reffreq,
203 hdr.bandwidth, freqInc, restFreq, sd.tcal,
204 sd.tcaltime, sd.azimuth, sd.elevation,
205 sd.parangle,
206 focusAxi, focusTan, focusRot, temperature,
207 pressure, humidity, windSpeed, windAz,
208 sd.refbeam, iBeam+1,
209 sd.getDirection(iBeam),
210 scanRate,
211 sd.getTsys(iBeam, iIF), sigma, calFctr,
212 baseLin, baseSub,
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.