Changeset 50


Ignore:
Timestamp:
07/15/04 15:58:02 (20 years ago)
Author:
mmarquar
Message:

Removed name_ related fields and functions.
Changed getTime to sprint out string of MVTime.
Added range checks for setIF/Pol/Beam functions.
Added const to get type functions, where it was missing.
Removed debugging cerr from getAbscissa
Added setCoordinate to set the Frequency Table from SpectralCoordinate?.
Added nScans()
Added more info printing to summary

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SDMemTable.cc

    r39 r50  
    3232
    3333#include <aips/iostream.h>
     34#include <aips/iomanip.h>
    3435#include <aips/Arrays/Array.h>
    3536#include <aips/Arrays/ArrayMath.h>
     
    4950#include <aips/Tables/TableRecord.h>
    5051#include <aips/Measures/MFrequency.h>
     52#include <aips/Quanta/MVTime.h>
    5153
    5254#include "SDMemTable.h"
     
    6567  beamSel_(0),
    6668  polSel_(0) {
    67   Table tab("dummy");
     69  Table tab(name);
    6870  table_ = tab.copyToMemoryTable("dummy");
    6971}
     
    9193  String exprs = String("select * from $1 where SCANID == ")
    9294    +String::toString(scanID);
    93   cerr << exprs << endl;
     95  //cerr << exprs << endl;
    9496  Table t = tableCommand(exprs,tab);
    9597  table_ = t.copyToMemoryTable("dummy");
     
    9799
    98100SDMemTable::~SDMemTable(){
    99   cerr << "goodbye from SDMemTable @ " << this << endl;
     101  //cerr << "goodbye from SDMemTable @ " << this << endl;
    100102}
    101103
     
    128130}
    129131
    130 Double SDMemTable::getTime(Int whichRow) const {
     132std::string SDMemTable::getTime(Int whichRow) const {
    131133  ROScalarColumn<Double> src(table_, "TIME");
    132134  Double tm;
    133135  src.get(whichRow, tm);
    134   return tm;
     136  MVTime mvt(tm);
     137  mvt.setFormat(MVTime::YMD);
     138  ostringstream oss;
     139  oss << mvt;
     140  String str(oss);
     141  return str;
     142}
     143double SDMemTable::getInterval(Int whichRow) const {
     144  ROScalarColumn<Double> src(table_, "INTERVAL");
     145  Double intval;
     146  src.get(whichRow, intval);
     147  return intval;
    135148}
    136149
    137150bool SDMemTable::setIF(Int whichIF) {
    138   //if ( whichIF >= 0 && whichIF < nIF_) {
     151  if ( whichIF >= 0 && whichIF < nIF()) {
    139152    IFSel_ = whichIF;
    140153    return true;
    141     //}
    142     //return false;
    143 }
     154  }
     155  return false;
     156}
     157
    144158bool SDMemTable::setBeam(Int whichBeam) {
    145   //if ( whichBeam >= 0 && whichBeam < nBeam_) {
     159  if ( whichBeam >= 0 && whichBeam < nBeam()) {
    146160    beamSel_ = whichBeam;
    147161    return true;
    148     //}
    149     //return false;
    150 
    151 }
     162  }
     163  return false;
     164}
     165
    152166bool SDMemTable::setPol(Int whichPol) {
    153   //if ( whichPol >= 0 && whichPol < nPol_) {
     167  if ( whichPol >= 0 && whichPol < nPol()) {
    154168    polSel_ = whichPol;
    155169    return true;
    156     //}
    157     //return false;
     170  }
     171  return false;
    158172}
    159173
     
    200214  return mask;
    201215}
    202 std::vector<float> SDMemTable::getSpectrum(Int whichRow) {
     216std::vector<float> SDMemTable::getSpectrum(Int whichRow) const {
    203217
    204218  std::vector<float> spectrum;
     
    228242  fid.get(whichRow, v);
    229243  uInt specidx = v(IFSel_);
    230   cerr << "specidx = " << specidx << endl;
    231244  Unit u;
    232245  if (whichUnit == "") {
     
    236249  }
    237250  SpectralCoordinate spc = getCoordinate(specidx);
    238   cerr << "debug"  << endl;
    239251  if ( u == Unit("km/s") ) {
    240     cerr << "vel ??? " << restfreq << endl;
    241252    if (Double(restfreq) >  Double(0.000001)) {
    242253      cerr << "converting to velocities"<< endl;
     
    259270    Double tmp;
    260271    uInt i = 0;
    261     for (it = absc.begin(); it != absc.end(); ++it) {
    262      
     272    for (it = absc.begin(); it != absc.end(); ++it) {     
    263273      spc.toWorld(tmp,absc1[i]);
    264274      (*it) = tmp;
    265275      i++;
    266276    }
    267     cerr << "converted all pic to world" << endl;
    268   }
    269   cerr << "exiting getAbscissa" << endl;
     277  }
    270278  return absc;
    271279}
     
    401409  rvc.get(whichIdx, rv);
    402410  incc.get(whichIdx, inc);
    403   cerr << "creating speccord from " << whichIdx << ": "
    404        << rp <<", " << rv << ", " << inc << ", " << mft <<endl;
     411  //cerr << "creating speccord from " << whichIdx << ": "
     412  //     << rp <<", " << rv << ", " << inc << ", " << mft <<endl;
    405413  SpectralCoordinate spec(mft,rv,inc,rp);
    406   cerr << "debugit" << endl;
    407414  return spec;
    408415}
     416
     417Bool SDMemTable::setCoordinate(const SpectralCoordinate& speccord,
     418                               uInt whichIdx) {
     419  Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
     420  if (whichIdx > t.nrow() ) {
     421    cerr << "SDMemTable::setCoordinate - whichIdx out of range" << endl;
     422    return;
     423  }
     424  ScalarColumn<Double> rpc(t, "REFPIX");
     425  ScalarColumn<Double> rvc(t, "REFVAL");
     426  ScalarColumn<Double> incc(t, "INCREMENT");
     427 
     428  rpc.put(whichIdx, speccord.referencePixel()[0]);
     429  rvc.put(whichIdx, speccord.referenceValue()[0]);
     430  incc.put(whichIdx, speccord.increment()[0]);
     431
     432  return True;
     433}
     434
    409435
    410436bool SDMemTable::putSDFreqTable(const SDFrequencyTable& sdft) {
     
    427453  aTable.rwKeywordSet().define("Unit", String("kms-1"));
    428454  table_.rwKeywordSet().defineTable ("FREQUENCIES", aTable);
    429   cerr << "debug - putSDFreqTable" << endl;
    430455  return True;
    431456}
     
    508533  table_.rwKeywordSet().define("UTC", sdh.utc);
    509534  table_.unlock();
    510   cerr << "Table Header set" << endl;
    511535  return true;
    512 }\
     536}
    513537
    514538SDHeader SDMemTable::getSDHeader() const {
     
    534558}
    535559
     560Int SDMemTable::nScans() const {
     561  Int n = 0;
     562  ROScalarColumn<Int> scans(table_, "SCANID");
     563  Int previous = -1;Int current=0;
     564  for (uInt i=0; i< scans.nrow();i++) {
     565    scans.getScalar(i,current);
     566    if (previous != current) {
     567      previous = current;     
     568      n++;
     569    }
     570  }
     571  return n;
     572}
     573
    536574void SDMemTable::summary() const {
    537575  ROScalarColumn<Int> scans(table_, "SCANID");
     
    546584  String name;
    547585  Int previous = -1;Int current=0;
    548   cout << "Scan\tSource" << endl;
     586  cout << "Scan\tSource\t\tTime\t\tIntegration" << endl;
    549587  for (uInt i=0; i< scans.nrow();i++) {
    550588    scans.getScalar(i,current);
    551589    if (previous != current) {
    552590      srcs.getScalar(i,name);
    553       previous = current;     
     591      previous = current;
     592      Double t = getInterval();
     593      String unit("sec");
     594      if (t/60.0 > 1.0) {
     595        t/=60.0;unit = "min";
     596      }
     597      cout << count << "\t"
     598           << name << "\t"
     599           << getTime() << "\t"
     600           << setprecision(2) <<  setiosflags(std::ios_base::fixed)
     601           << t << " " << unit << endl
     602           << endl;
    554603      count++;
    555       cout << count << "\t"
    556            << name
    557            << endl;
    558604    }
    559605  }
  • trunk/src/SDMemTable.h

    r39 r50  
    5454  // create a new (empty) SDMemTable
    5555  SDMemTable();
    56   // create a SDMemTable from a )aips++) table on disk
     56  // create a SDMemTable from an (aips++) table on disk
    5757  SDMemTable(const std::string& name);
    5858
     
    7878  // get spectrum,mask and tsys for the given row, at the selected
    7979  // cursor - all as stl vectors
    80   virtual std::vector<float> getSpectrum(Int whichRow);
    81   virtual std::vector<bool> getMask(Int whichRow) const;
     80  virtual std::vector<float> getSpectrum(Int whichRow=0) const;
     81  virtual std::vector<bool> getMask(Int whichRow=0) const;
    8282
    83   virtual Float getTsys(Int whichRow) const;
     83  virtual Float getTsys(Int whichRow=0) const;
    8484  // get all as aips++ Vectors
    8585  virtual void getSpectrum(Vector<Float>& spectrum, Int whichRow=0);
     
    8787
    8888  // get info for current row
    89   virtual Double getTime(Int whichRow) const ;
    90   virtual std::string getSourceName(Int whichRow) const;
    91  
     89  std::string getTime(Int whichRow=0) const ;
     90  std::string getSourceName(Int whichRow=0) const;
     91  double getInterval(Int whichRow=0) const;
     92
    9293  // set the current value
    9394  virtual bool setIF(Int whichIF=0);
     
    102103  virtual Int getPol() { return polSel_; }   
    103104 
     105  // number of scans in table
     106  virtual Int nScans() const;
     107
    104108  // print a summary to stdout
    105109  virtual void summary() const;
     
    130134
    131135  SpectralCoordinate getCoordinate(uInt whichIdx) const;
     136  Bool setCoordinate(const SpectralCoordinate& speccord, uInt whichIdx);
     137
    132138  std::vector<double> getAbscissa(int whichRow,
    133139                                  const std::string& whichUnit="GHz",
     
    139145  Int IFSel_,beamSel_,polSel_;
    140146  std::vector<bool> chanMask_; 
    141   String name_;
    142   // the unerlying memory table
     147  // the underlying memory table
    143148  Table table_;
    144149};
Note: See TracChangeset for help on using the changeset viewer.