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
RevLine 
[2]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>
[87]32#include <casa/Exceptions.h>
[2]33#include "SDReader.h"
34
[83]35using namespace asap;
[2]36
37SDReader::SDReader() :
38 reader_(0),
39 table_(new SDMemTable()) {
40 cursor_ = 0;
41}
[46]42SDReader::SDReader(const std::string& filename) :
43 reader_(0),
44 table_(new SDMemTable()) {
45 cursor_ = 0;
46 open(filename);
47}
[2]48
49SDReader::SDReader(CountedPtr<SDMemTable> tbl) :
50 reader_(0),
51 table_(tbl) {
52 cursor_ = 0;
53}
54
55SDReader::~SDReader() {
[46]56 if (reader_) delete reader_; reader_ = 0;
[2]57}
58
59void SDReader::reset() {
[46]60 cursor_ = 0;
[87]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_);
[2]74}
75
[46]76void SDReader::close() {
77 cerr << "disabled" << endl;
78}
79
[2]80void SDReader::open(const std::string& filename) {
81 if (reader_) delete reader_; reader_ = 0;
82 Bool haveBase, haveSpectra, haveXPol;
83 String inName(filename);
[87]84 filename_ = inName;
[2]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) {
[87]90 throw(AipsError("PKSreader failed"));
[2]91 }
92 if (!haveSpectra) {
93 delete reader_;
94 reader_ = 0;
[87]95 throw(AipsError("No spectral data in file."));
[2]96 return;
97 }
98 nBeam_ = beams.nelements();
99 // Get basic parameters.
[110]100 if (haveXPol) {
101 cout << "Warning. Ignoring cross polarisation." << endl;
102 nPol_--;
103 }
[2]104 header_ = SDHeader();
105 header_.nchan = nChan_;
106 header_.npol = nPol_;
107 header_.nbeam = nBeam_;
[87]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,
[2]113 header_.bandwidth);
114 if (status) {
115 delete reader_;
116 reader_ = 0;
[87]117 throw(AipsError("Failed to get header."));
[2]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);
[18]134 table_->putSDHeader(header_);
[33]135 frequencies_.setRefFrame(header_.freqref);
136 frequencies_.setEquinox(header_.equinox);
[2]137}
138
139int SDReader::read(const std::vector<int>& seq) {
[87]140 int status = 0;
141
[17]142 Int beamNo, IFno, refBeam, scanNo, cycleNo;
[87]143 Float azimuth, elevation, focusAxi, focusRot, focusTan,
[2]144 humidity, parAngle, pressure, temperature, windAz, windSpeed;
[73]145 Double bandwidth, freqInc, interval, mjd, refFreq, restFreq, srcVel;
[2]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();
[25]155
[2]156 uInt stepsize = header_.nif*header_.nbeam;
[33]157 //cerr << "SDReader stepsize = " << stepsize << endl;
[2]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
[16]163 SDContainer sc(header_.nbeam,header_.nif,header_.npol,header_.nchan);
[2]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)!!!
[87]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);
[2]178 if (status) {
[87]179 if (status == -1) {
180 // EOF.
[110]181 if (row < stepsize-1) cerr << "incomplete scan data.\n Probably means not all Beams/IFs/Pols within a scan a present." << endl;
[87]182 //cerr << "EOF" << endl;
183 table_->putSDFreqTable(frequencies_);
184 return status;
185 }
186 }
[2]187 // if in the given list
[33]188 if (cursor_ == seq[seqi] || getAll) {
[87]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;
[110]198 sc.fieldname = fieldName;
199 sc.azimuth = azimuth;
200 sc.elevation = elevation;
[87]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);
[110]208 sc.tcal[0] = tcal[0];sc.tcal[1] = tcal[1];
209 sc.tcaltime = tcalTime;
210 sc.parangle = parAngle;
211 sc.refbeam = refBeam;
[87]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);
[2]217 }
218 }
[33]219 if (cursor_ == seq[seqi] || getAll) {
[2]220 // insert container into table/list
221 table_->putSDContainer(sc);
222 seqi++;// next in list
223 }
[16]224 cursor_++;// increment position in file
[2]225 }
[33]226 table_->putSDFreqTable(frequencies_);
[2]227 return status;
228}
Note: See TracBrowser for help on using the repository browser.