source: trunk/src/SDReader.cc@ 84

Last change on this file since 84 was 83, checked in by mar637, 20 years ago

chnaged namesapce form "atnf_sd" to "asap"

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