source: trunk/src/SDReader.cc@ 103

Last change on this file since 103 was 87, checked in by mar637, 20 years ago

chnged cerr's to throws, added rest function.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.6 KB
Line 
1//#---------------------------------------------------------------------------
2//# SDReader.cc: A class to read single dish spectra from SDFITS, RPFITS
3//#---------------------------------------------------------------------------
4//# Copyright (C) 2004
5//# Malte Marquarding, 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:
30//#---------------------------------------------------------------------------
31#include <atnf/PKSIO/PKSreader.h>
32#include <casa/Exceptions.h>
33#include "SDReader.h"
34
35using namespace asap;
36
37SDReader::SDReader() :
38 reader_(0),
39 table_(new SDMemTable()) {
40 cursor_ = 0;
41}
42SDReader::SDReader(const std::string& filename) :
43 reader_(0),
44 table_(new SDMemTable()) {
45 cursor_ = 0;
46 open(filename);
47}
48
49SDReader::SDReader(CountedPtr<SDMemTable> tbl) :
50 reader_(0),
51 table_(tbl) {
52 cursor_ = 0;
53}
54
55SDReader::~SDReader() {
56 if (reader_) delete reader_; reader_ = 0;
57}
58
59void SDReader::reset() {
60 cursor_ = 0;
61 table_ = new SDMemTable();
62 if (reader_) delete reader_; reader_ = 0;
63 // re-create the reader
64 Bool haveBase, haveSpectra, haveXPol;
65 String format;
66 Vector<Bool> beams;
67 if ((reader_ = getPKSreader(filename_, 0, False, format, beams, nIF_,
68 nChan_, nPol_, haveBase, haveSpectra,
69 haveXPol)) == 0) {
70 throw(AipsError("PKSreader failed"));
71 }
72 // re-enter the header
73 table_->putSDHeader(header_);
74}
75
76void SDReader::close() {
77 cerr << "disabled" << endl;
78}
79
80void SDReader::open(const std::string& filename) {
81 if (reader_) delete reader_; reader_ = 0;
82 Bool haveBase, haveSpectra, haveXPol;
83 String inName(filename);
84 filename_ = inName;
85 String format;
86 Vector<Bool> beams;
87 if ((reader_ = getPKSreader(inName, 0, False, format, beams, nIF_,
88 nChan_, nPol_, haveBase, haveSpectra,
89 haveXPol)) == 0) {
90 throw(AipsError("PKSreader failed"));
91 //cerr << "PKSreader failed" << endl;
92 }
93 if (!haveSpectra) {
94 delete reader_;
95 reader_ = 0;
96 throw(AipsError("No spectral data in file."));
97 return;
98 }
99 nBeam_ = beams.nelements();
100 // Get basic parameters.
101 header_ = SDHeader();
102 header_.nchan = nChan_;
103 header_.npol = nPol_;
104 header_.nbeam = nBeam_;
105 Int status = reader_->getHeader(header_.observer, header_.project,
106 header_.antennaname, header_.antennaposition,
107 header_.obstype,header_.equinox,
108 header_.freqref,
109 header_.utc, header_.reffreq,
110 header_.bandwidth);
111 if (status) {
112 delete reader_;
113 reader_ = 0;
114 throw(AipsError("Failed to get header."));
115 return;
116 }
117 if ((header_.obstype).matches("*SW*")) {
118 // need robust way here - probably read ahead of next timestamp
119 cout << "Header indicates frequency switched observation.\n"
120 "setting # of IFs = 1 " << endl;
121 nIF_ = 1;
122 }
123 header_.nif = nIF_;
124 // Apply selection criteria.
125 Vector<Int> start(nIF_, 1);
126 Vector<Int> end(nIF_, 0);
127 Vector<Int> ref;
128 Vector<Bool> beamSel(nBeam_,True);
129 Vector<Bool> IFsel(nIF_,True);
130 reader_->select(beamSel, IFsel, start, end, ref, True, haveXPol);
131 table_->putSDHeader(header_);
132 frequencies_.setRefFrame(header_.freqref);
133 frequencies_.setEquinox(header_.equinox);
134}
135
136int SDReader::read(const std::vector<int>& seq) {
137 int status = 0;
138
139 Int beamNo, IFno, refBeam, scanNo, cycleNo;
140 Float azimuth, elevation, focusAxi, focusRot, focusTan,
141 humidity, parAngle, pressure, temperature, windAz, windSpeed;
142 Double bandwidth, freqInc, interval, mjd, refFreq, restFreq, srcVel;
143 String fieldName, srcName, tcalTime;
144 Vector<Float> calFctr, sigma, tcal, tsys;
145 Matrix<Float> baseLin, baseSub;
146 Vector<Double> direction(2), scanRate(2), srcDir(2), srcPM(2);
147 Matrix<Float> spectra;
148 Matrix<uChar> flagtra;
149 Complex xCalFctr;
150 Vector<Complex> xPol;
151 uInt n = seq.size();
152
153 uInt stepsize = header_.nif*header_.nbeam;
154 //cerr << "SDReader stepsize = " << stepsize << endl;
155 uInt seqi = 0;
156 Bool getAll = False;
157 if (seq[n-1] == -1) getAll = True;
158 while ( (cursor_ <= seq[n-1]) || getAll) {
159 // only needs to be create if in seq
160 SDContainer sc(header_.nbeam,header_.nif,header_.npol,header_.nchan);
161
162 // iterate over one correlator integration cycle = nBeam*nIF
163 for (uInt row=0; row < stepsize; row++) {
164 // stepsize as well
165 // spectra(nChan,nPol)!!!
166 status = reader_->read(scanNo, cycleNo, mjd, interval, fieldName,
167 srcName, srcDir, srcPM, srcVel, IFno, refFreq,
168 bandwidth, freqInc, restFreq, tcal, tcalTime,
169 azimuth, elevation, parAngle, focusAxi,
170 focusTan, focusRot, temperature, pressure,
171 humidity, windSpeed, windAz, refBeam,
172 beamNo, direction, scanRate,
173 tsys, sigma, calFctr, baseLin, baseSub,
174 spectra, flagtra, xCalFctr, xPol);
175 if (status) {
176 if (status == -1) {
177 // EOF.
178 if (row < stepsize-1) cerr << "incomplete integration data." << endl;
179 //cerr << "EOF" << endl;
180 table_->putSDFreqTable(frequencies_);
181 return status;
182 }
183 }
184 // if in the given list
185 if (cursor_ == seq[seqi] || getAll) {
186 // add integration cycle
187 if (row==0) {
188 //add invariant info: scanNo, mjd, interval, fieldName,
189 //srcName, azimuth, elevation, parAngle, focusAxi, focusTan,
190 //focusRot, temperature, pressure, humidity, windSpeed,
191 //windAz srcDir, srcPM, srcVel
192 sc.timestamp = mjd;
193 sc.interval = interval;
194 sc.sourcename = srcName;
195 }
196 // add specific info
197 // IFno beamNo are 1-relative
198 // refPix = nChan/2+1 in Integer arith.!
199 Int refPix = header_.nchan/2+1;
200 Int frqslot = frequencies_.addFrequency(refPix, refFreq, freqInc);
201 sc.setFrequencyMap(frqslot,IFno-1);
202
203 sc.scanid = scanNo-1;//make it 0-based
204 sc.setSpectrum(spectra, beamNo-1, IFno-1);
205 sc.setFlags(flagtra, beamNo-1, IFno-1);
206 sc.setTsys(tsys, beamNo-1, IFno-1);
207 sc.setDirection(direction, beamNo-1);
208 }
209 }
210 if (cursor_ == seq[seqi] || getAll) {
211 // insert container into table/list
212 table_->putSDContainer(sc);
213 seqi++;// next in list
214 }
215 cursor_++;// increment position in file
216 }
217 table_->putSDFreqTable(frequencies_);
218 return status;
219}
Note: See TracBrowser for help on using the repository browser.