source: trunk/src/SDReader.cc@ 115

Last change on this file since 115 was 110, checked in by mar637, 20 years ago

filling azimuth,elevation,parangle,refbeam,fieldname,tcal,tcaltime
Ignoring Xpol

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.9 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 }
92 if (!haveSpectra) {
93 delete reader_;
94 reader_ = 0;
95 throw(AipsError("No spectral data in file."));
96 return;
97 }
98 nBeam_ = beams.nelements();
99 // Get basic parameters.
100 if (haveXPol) {
101 cout << "Warning. Ignoring cross polarisation." << endl;
102 nPol_--;
103 }
104 header_ = SDHeader();
105 header_.nchan = nChan_;
106 header_.npol = nPol_;
107 header_.nbeam = nBeam_;
108 Int status = reader_->getHeader(header_.observer, header_.project,
109 header_.antennaname, header_.antennaposition,
110 header_.obstype,header_.equinox,
111 header_.freqref,
112 header_.utc, header_.reffreq,
113 header_.bandwidth);
114 if (status) {
115 delete reader_;
116 reader_ = 0;
117 throw(AipsError("Failed to get header."));
118 return;
119 }
120 if ((header_.obstype).matches("*SW*")) {
121 // need robust way here - probably read ahead of next timestamp
122 cout << "Header indicates frequency switched observation.\n"
123 "setting # of IFs = 1 " << endl;
124 nIF_ = 1;
125 }
126 header_.nif = nIF_;
127 // Apply selection criteria.
128 Vector<Int> start(nIF_, 1);
129 Vector<Int> end(nIF_, 0);
130 Vector<Int> ref;
131 Vector<Bool> beamSel(nBeam_,True);
132 Vector<Bool> IFsel(nIF_,True);
133 reader_->select(beamSel, IFsel, start, end, ref, True, haveXPol);
134 table_->putSDHeader(header_);
135 frequencies_.setRefFrame(header_.freqref);
136 frequencies_.setEquinox(header_.equinox);
137}
138
139int SDReader::read(const std::vector<int>& seq) {
140 int status = 0;
141
142 Int beamNo, IFno, refBeam, scanNo, cycleNo;
143 Float azimuth, elevation, focusAxi, focusRot, focusTan,
144 humidity, parAngle, pressure, temperature, windAz, windSpeed;
145 Double bandwidth, freqInc, interval, mjd, refFreq, restFreq, srcVel;
146 String fieldName, srcName, tcalTime;
147 Vector<Float> calFctr, sigma, tcal, tsys;
148 Matrix<Float> baseLin, baseSub;
149 Vector<Double> direction(2), scanRate(2), srcDir(2), srcPM(2);
150 Matrix<Float> spectra;
151 Matrix<uChar> flagtra;
152 Complex xCalFctr;
153 Vector<Complex> xPol;
154 uInt n = seq.size();
155
156 uInt stepsize = header_.nif*header_.nbeam;
157 //cerr << "SDReader stepsize = " << stepsize << endl;
158 uInt seqi = 0;
159 Bool getAll = False;
160 if (seq[n-1] == -1) getAll = True;
161 while ( (cursor_ <= seq[n-1]) || getAll) {
162 // only needs to be create if in seq
163 SDContainer sc(header_.nbeam,header_.nif,header_.npol,header_.nchan);
164
165 // iterate over one correlator integration cycle = nBeam*nIF
166 for (uInt row=0; row < stepsize; row++) {
167 // stepsize as well
168 // spectra(nChan,nPol)!!!
169 status = reader_->read(scanNo, cycleNo, mjd, interval, fieldName,
170 srcName, srcDir, srcPM, srcVel, IFno, refFreq,
171 bandwidth, freqInc, restFreq, tcal, tcalTime,
172 azimuth, elevation, parAngle, focusAxi,
173 focusTan, focusRot, temperature, pressure,
174 humidity, windSpeed, windAz, refBeam,
175 beamNo, direction, scanRate,
176 tsys, sigma, calFctr, baseLin, baseSub,
177 spectra, flagtra, xCalFctr, xPol);
178 if (status) {
179 if (status == -1) {
180 // EOF.
181 if (row < stepsize-1) cerr << "incomplete scan data.\n Probably means not all Beams/IFs/Pols within a scan a present." << endl;
182 //cerr << "EOF" << endl;
183 table_->putSDFreqTable(frequencies_);
184 return status;
185 }
186 }
187 // if in the given list
188 if (cursor_ == seq[seqi] || getAll) {
189 // add integration cycle
190 if (row==0) {
191 //add invariant info: scanNo, mjd, interval, fieldName,
192 //srcName, azimuth, elevation, parAngle, focusAxi, focusTan,
193 //focusRot, temperature, pressure, humidity, windSpeed,
194 //windAz srcDir, srcPM, srcVel
195 sc.timestamp = mjd;
196 sc.interval = interval;
197 sc.sourcename = srcName;
198 sc.fieldname = fieldName;
199 sc.azimuth = azimuth;
200 sc.elevation = elevation;
201 }
202 // add specific info
203 // IFno beamNo are 1-relative
204 // refPix = nChan/2+1 in Integer arith.!
205 Int refPix = header_.nchan/2+1;
206 Int frqslot = frequencies_.addFrequency(refPix, refFreq, freqInc);
207 sc.setFrequencyMap(frqslot,IFno-1);
208 sc.tcal[0] = tcal[0];sc.tcal[1] = tcal[1];
209 sc.tcaltime = tcalTime;
210 sc.parangle = parAngle;
211 sc.refbeam = refBeam;
212 sc.scanid = scanNo-1;//make it 0-based
213 sc.setSpectrum(spectra, beamNo-1, IFno-1);
214 sc.setFlags(flagtra, beamNo-1, IFno-1);
215 sc.setTsys(tsys, beamNo-1, IFno-1);
216 sc.setDirection(direction, beamNo-1);
217 }
218 }
219 if (cursor_ == seq[seqi] || getAll) {
220 // insert container into table/list
221 table_->putSDContainer(sc);
222 seqi++;// next in list
223 }
224 cursor_++;// increment position in file
225 }
226 table_->putSDFreqTable(frequencies_);
227 return status;
228}
Note: See TracBrowser for help on using the repository browser.