source: trunk/src/SDWriter.cc@ 198

Last change on this file since 198 was 192, checked in by kil064, 20 years ago

adjust to allow FITSImage writing (use SDFITSImageWriter)
delete pointer in destructor

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