source: trunk/src/SDReader.cc@ 27

Last change on this file since 27 was 25, checked in by mmarquar, 20 years ago

commented out debugging info. Removed temprary scanid replacement variables.

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