Changeset 87


Ignore:
Timestamp:
11/12/04 12:08:27 (20 years ago)
Author:
mar637
Message:

chnged cerr's to throws, added rest function.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SDReader.cc

    r83 r87  
    3030//#---------------------------------------------------------------------------
    3131#include <atnf/PKSIO/PKSreader.h>
    32 
     32#include <casa/Exceptions.h>
    3333#include "SDReader.h"
    3434
     
    5959void SDReader::reset() {
    6060  cursor_ = 0;
    61   open(filename_);
     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_);
    6274}
    6375
     
    7082  Bool   haveBase, haveSpectra, haveXPol;
    7183  String inName(filename);
     84  filename_ = inName;
    7285  String format;
    7386  Vector<Bool> beams;
     
    7588                              nChan_, nPol_, haveBase, haveSpectra,
    7689                              haveXPol)) == 0)  {
    77     cerr << "PKSreader failed" << endl;
     90    throw(AipsError("PKSreader failed"));
     91    //cerr << "PKSreader failed" << endl;
    7892  }
    7993  if (!haveSpectra) {
    8094    delete reader_;
    8195    reader_ = 0;
    82     cerr << "Spectral data absent." << endl;
     96    throw(AipsError("No spectral data in file."));
    8397    return;
    8498  }
     
    89103  header_.npol = nPol_;
    90104  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,
     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,
    97110                                  header_.bandwidth);
    98111  if (status) {
    99112    delete reader_;
    100113    reader_ = 0;
    101     cerr << "Failed to get data description." << endl;
     114    throw(AipsError("Failed to get header."));
    102115    return;
    103116  }
    104   //header_.print(); 
    105117  if ((header_.obstype).matches("*SW*")) {
    106118    // need robust way here - probably read ahead of next timestamp
     
    123135
    124136int SDReader::read(const std::vector<int>& seq) {
    125   int status = 0; 
    126  
     137  int status = 0;
     138
    127139  Int    beamNo, IFno, refBeam, scanNo, cycleNo;
    128   Float  azimuth, elevation, focusAxi, focusRot, focusTan, 
     140  Float  azimuth, elevation, focusAxi, focusRot, focusTan,
    129141    humidity, parAngle, pressure, temperature, windAz, windSpeed;
    130142  Double bandwidth, freqInc, interval, mjd, refFreq, restFreq, srcVel;
     
    152164      // stepsize as well
    153165      // spectra(nChan,nPol)!!!
    154       status = reader_->read(scanNo, cycleNo, mjd, interval, fieldName, 
    155                              srcName, srcDir, srcPM, srcVel, IFno, refFreq,
    156                              bandwidth, freqInc, restFreq, tcal, tcalTime,
    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);         
     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);
    163175      if (status) {
    164         if (status == -1) {
    165           // EOF.
    166           if (row < stepsize-1) cerr << "incomplete integration data." << endl;
    167           cerr << "EOF" << endl;
    168           table_->putSDFreqTable(frequencies_);
    169           return status;
    170         }
    171       }     
     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      }
    172184      // if in the given list
    173185      if (cursor_ == seq[seqi] || getAll) {
    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
    180           sc.timestamp = mjd;
    181           sc.interval = interval;         
    182           sc.sourcename = srcName;
    183         }
    184         // add specific info
    185         // IFno beamNo are 1-relative
    186         // refPix = nChan/2+1 in  Integer arith.!       
    187         Int refPix = header_.nchan/2+1;
    188         Int frqslot = frequencies_.addFrequency(refPix, refFreq, freqInc);
    189         sc.setFrequencyMap(frqslot,IFno-1);
    190 
    191         sc.scanid = scanNo-1;//make it 0-based
    192         sc.setSpectrum(spectra, beamNo-1, IFno-1);
    193         sc.setFlags(flagtra,  beamNo-1, IFno-1);
    194         sc.setTsys(tsys, beamNo-1, IFno-1);
    195         sc.setDirection(direction, beamNo-1);
     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);
    196208      }
    197209    }
Note: See TracChangeset for help on using the changeset viewer.