source: trunk/src/SDWriter.cc@ 127

Last change on this file since 127 was 125, checked in by mar637, 20 years ago

Moved to casa namespace.
Adjusted the copyright to be ATNF.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 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 125 2004-12-10 03:54:54Z mar637 $
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
46using namespace casa;
47using namespace asap;
48
49//--------------------------------------------------------- SDWriter::SDWriter
50
51// Default constructor.
52
53SDWriter::SDWriter(const std::string &format)
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
68SDWriter::~SDWriter()
69{
70 // Nothing.
71}
72
73//-------------------------------------------------------- SDWriter::setFormat
74
75// Reset the output format.
76
77Int SDWriter::setFormat(
78 const std::string &format)
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
99Int SDWriter::write(
100 const CountedPtr<SDMemTable> table,
101 const std::string &filename)
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->nRow(); 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 = "";
141 //Vector<Double> srcDir(2, 0.0);
142 Vector<Double> srcPM(2, 0.0);
143 Double srcVel = 0.0;
144 Double freqInc = 0.0;
145 Double restFreq = 0.0;
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;
160 //Vector<Double> direction(2, 0.0);
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, sd.fieldname, sd.sourcename,
170 sd.getDirection(iBeam),
171 srcPM, srcVel, iIF+1, hdr.reffreq,
172 hdr.bandwidth, freqInc, restFreq, sd.tcal,
173 sd.tcaltime, sd.azimuth, sd.elevation,
174 sd.parangle,
175 focusAxi, focusTan, focusRot, temperature,
176 pressure, humidity, windSpeed, windAz,
177 sd.refbeam, iBeam+1,
178 sd.getDirection(iBeam),
179 scanRate,
180 sd.getTsys(iBeam, iIF), sigma, calFctr,
181 baseLin, baseSub,
182 sd.getSpectrum(iBeam, iIF),
183 sd.getFlags(iBeam, iIF),
184 xCalFctr, xPol)) {
185 cerr << "Error writing output file." << endl;
186 return 1;
187 }
188
189 count++;
190 }
191 }
192 }
193
194 cout << "SDWriter: wrote " << count << " rows to " << filename << endl;
195 cWriter->close();
196
197 return 0;
198}
Note: See TracBrowser for help on using the repository browser.