source: trunk/src/SDMemTable.cc @ 354

Last change on this file since 354 was 348, checked in by kil064, 19 years ago

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 37.2 KB
RevLine 
[2]1//#---------------------------------------------------------------------------
2//# SDMemTable.cc: A MemoryTable container for single dish integrations
3//#---------------------------------------------------------------------------
4//# Copyright (C) 2004
[125]5//# ATNF
[2]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
[206]32#include <map>
33
[125]34#include <casa/aips.h>
[80]35#include <casa/iostream.h>
36#include <casa/iomanip.h>
37#include <casa/Arrays/Array.h>
38#include <casa/Arrays/ArrayMath.h>
39#include <casa/Arrays/MaskArrMath.h>
40#include <casa/Arrays/ArrayLogical.h>
41#include <casa/Arrays/ArrayAccessor.h>
[206]42#include <casa/Arrays/Vector.h>
[286]43#include <casa/Quanta/MVAngle.h>
[2]44
[80]45#include <tables/Tables/TableParse.h>
46#include <tables/Tables/TableDesc.h>
47#include <tables/Tables/SetupNewTab.h>
48#include <tables/Tables/ScaColDesc.h>
49#include <tables/Tables/ArrColDesc.h>
[2]50
[80]51#include <tables/Tables/ExprNode.h>
52#include <tables/Tables/TableRecord.h>
53#include <measures/Measures/MFrequency.h>
54#include <measures/Measures/MeasTable.h>
[105]55#include <coordinates/Coordinates/CoordinateUtil.h>
[80]56#include <casa/Quanta/MVTime.h>
[281]57#include <casa/Quanta/MVAngle.h>
[2]58
[215]59#include "SDDefs.h"
[2]60#include "SDMemTable.h"
61#include "SDContainer.h"
62
[206]63
[125]64using namespace casa;
[83]65using namespace asap;
[2]66
[18]67SDMemTable::SDMemTable() :
68  IFSel_(0),
69  beamSel_(0),
[206]70  polSel_(0)
71{
[18]72  setup();
[322]73  attach();
[18]74}
[206]75
[2]76SDMemTable::SDMemTable(const std::string& name) :
77  IFSel_(0),
78  beamSel_(0),
[206]79  polSel_(0)
80{
[50]81  Table tab(name);
[22]82  table_ = tab.copyToMemoryTable("dummy");
[206]83  //cerr << "hello from C SDMemTable @ " << this << endl;
[329]84  attach();
[2]85}
86
[206]87SDMemTable::SDMemTable(const SDMemTable& other, Bool clear)
88{
[148]89  IFSel_= other.IFSel_;
90  beamSel_= other.beamSel_;
91  polSel_= other.polSel_;
92  chanMask_ = other.chanMask_;
93  table_ = other.table_.copyToMemoryTable(String("dummy"));
[2]94  // clear all rows()
[16]95  if (clear) {
[148]96    table_.removeRow(this->table_.rowNumbers());
[16]97  } else {
[148]98    IFSel_ = other.IFSel_;
99    beamSel_ = other.beamSel_;
100    polSel_ = other.polSel_;
[16]101  }
[322]102//
103  attach();
[206]104  //cerr << "hello from CC SDMemTable @ " << this << endl;
[2]105}
106
[80]107SDMemTable::SDMemTable(const Table& tab, const std::string& exprs) :
[2]108  IFSel_(0),
109  beamSel_(0),
[206]110  polSel_(0)
111{
[2]112  Table t = tableCommand(exprs,tab);
[89]113  if (t.nrow() == 0)
114      throw(AipsError("Query unsuccessful."));
[22]115  table_ = t.copyToMemoryTable("dummy");
[329]116  attach();
[2]117}
118
[206]119SDMemTable::~SDMemTable()
120{
[105]121  //cerr << "goodbye from SDMemTable @ " << this << endl;
[2]122}
123
[206]124SDMemTable SDMemTable::getScan(Int scanID) const
125{
[80]126  String cond("SELECT * from $1 WHERE SCANID == ");
127  cond += String::toString(scanID);
128  return SDMemTable(table_, cond);
[2]129}
130
[206]131SDMemTable &SDMemTable::operator=(const SDMemTable& other)
132{
[148]133  if (this != &other) {
134     IFSel_= other.IFSel_;
135     beamSel_= other.beamSel_;
136     polSel_= other.polSel_;
137     chanMask_.resize(0);
138     chanMask_ = other.chanMask_;
139     table_ = other.table_.copyToMemoryTable(String("dummy"));
[322]140     attach();
[206]141  }
142  //cerr << "hello from ASS SDMemTable @ " << this << endl;
[138]143  return *this;
144}
145
[206]146SDMemTable SDMemTable::getSource(const std::string& source) const
147{
[80]148  String cond("SELECT * from $1 WHERE SRCNAME == ");
149  cond += source;
150  return SDMemTable(table_, cond);
151}
152
[206]153void SDMemTable::setup()
154{
[2]155  TableDesc td("", "1", TableDesc::Scratch);
156  td.comment() = "A SDMemTable";
[322]157//
[2]158  td.addColumn(ScalarColumnDesc<Double>("TIME"));
159  td.addColumn(ScalarColumnDesc<String>("SRCNAME"));
160  td.addColumn(ArrayColumnDesc<Float>("SPECTRA"));
161  td.addColumn(ArrayColumnDesc<uChar>("FLAGTRA"));
[89]162  td.addColumn(ArrayColumnDesc<Float>("TSYS"));
163  td.addColumn(ScalarColumnDesc<Int>("SCANID"));
164  td.addColumn(ScalarColumnDesc<Double>("INTERVAL"));
[39]165  td.addColumn(ArrayColumnDesc<uInt>("FREQID"));
[78]166  td.addColumn(ArrayColumnDesc<Double>("DIRECTION"));
[105]167  td.addColumn(ScalarColumnDesc<String>("FIELDNAME"));
168  td.addColumn(ScalarColumnDesc<String>("TCALTIME"));
169  td.addColumn(ArrayColumnDesc<Float>("TCAL"));
170  td.addColumn(ScalarColumnDesc<Float>("AZIMUTH"));
171  td.addColumn(ScalarColumnDesc<Float>("ELEVATION"));
172  td.addColumn(ScalarColumnDesc<Float>("PARANGLE"));
173  td.addColumn(ScalarColumnDesc<Int>("REFBEAM"));
[206]174  td.addColumn(ArrayColumnDesc<String>("HISTORY"));
[105]175
[2]176  // Now create a new table from the description.
[18]177
[22]178  SetupNewTable aNewTab("dummy", td, Table::New);
[89]179  table_ = Table(aNewTab, Table::Memory, 0);
[2]180}
181
[322]182void SDMemTable::attach ()
183{
184  timeCol_.attach(table_, "TIME");
185  srcnCol_.attach(table_, "SRCNAME");
186  specCol_.attach(table_, "SPECTRA");
187  flagsCol_.attach(table_, "FLAGTRA");
188  tsCol_.attach(table_, "TSYS");
189  scanCol_.attach(table_, "SCANID");
190  integrCol_.attach(table_, "INTERVAL");
191  freqidCol_.attach(table_, "FREQID");
192  dirCol_.attach(table_, "DIRECTION");
193  fldnCol_.attach(table_, "FIELDNAME");
194  tcaltCol_.attach(table_, "TCALTIME");
195  tcalCol_.attach(table_, "TCAL");
196  azCol_.attach(table_, "AZIMUTH");
197  elCol_.attach(table_, "ELEVATION");
198  paraCol_.attach(table_, "PARANGLE");
199  rbeamCol_.attach(table_, "REFBEAM");
200  histCol_.attach(table_, "HISTORY");
201}
202
203
[206]204std::string SDMemTable::getSourceName(Int whichRow) const
205{
[2]206  String name;
[322]207  srcnCol_.get(whichRow, name);
[2]208  return name;
209}
210
[281]211std::string SDMemTable::getTime(Int whichRow, Bool showDate) const
[206]212{
[2]213  Double tm;
[281]214  if (whichRow > -1) {
[322]215    timeCol_.get(whichRow, tm);
[281]216  } else {
217    table_.keywordSet().get("UTC",tm);
218  }
[50]219  MVTime mvt(tm);
[281]220  if (showDate)
221    mvt.setFormat(MVTime::YMD);
222  else
223    mvt.setFormat(MVTime::TIME);
[50]224  ostringstream oss;
225  oss << mvt;
[281]226  return String(oss);
[2]227}
[281]228
[206]229double SDMemTable::getInterval(Int whichRow) const
230{
[50]231  Double intval;
[322]232  integrCol_.get(whichRow, intval);
[50]233  return intval;
234}
[2]235
[206]236bool SDMemTable::setIF(Int whichIF)
237{
[50]238  if ( whichIF >= 0 && whichIF < nIF()) {
[2]239    IFSel_ = whichIF;
240    return true;
[50]241  }
242  return false;
[2]243}
[50]244
[206]245bool SDMemTable::setBeam(Int whichBeam)
246{
[50]247  if ( whichBeam >= 0 && whichBeam < nBeam()) {
[2]248    beamSel_ = whichBeam;
249    return true;
[50]250  }
251  return false;
252}
[2]253
[206]254bool SDMemTable::setPol(Int whichPol)
255{
[50]256  if ( whichPol >= 0 && whichPol < nPol()) {
[2]257    polSel_ = whichPol;
258    return true;
[50]259  }
260  return false;
[2]261}
262
[303]263void SDMemTable::resetCursor ()
264{
265   polSel_ = 0;
266   IFSel_ = 0;
267   beamSel_ = 0;
268}
269
[206]270bool SDMemTable::setMask(std::vector<int> whichChans)
271{
[16]272  std::vector<int>::iterator it;
[322]273  uInt n = flagsCol_.shape(0)(3);
[105]274  if (whichChans.empty()) {
275    chanMask_ = std::vector<bool>(n,true);
276    return true;     
277  }
[16]278  chanMask_.resize(n,true);
[39]279  for (it = whichChans.begin(); it != whichChans.end(); ++it) {
[105]280    if (*it < n) {
[16]281      chanMask_[*it] = false;
[105]282    }
[16]283  }
[2]284  return true;
285}
286
[16]287std::vector<bool> SDMemTable::getMask(Int whichRow) const {
288  std::vector<bool> mask;
289  Array<uChar> arr;
[322]290  flagsCol_.get(whichRow, arr);
[206]291  ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
[16]292  aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
[206]293  ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0);
[16]294  aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
[206]295  ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1);
[16]296  aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
297
298  Bool useUserMask = ( chanMask_.size() == arr.shape()(3) );
299
300  std::vector<bool> tmp;
301  tmp = chanMask_; // WHY the fxxx do I have to make a copy here
302  std::vector<bool>::iterator miter;
303  miter = tmp.begin();
304
[206]305  for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
[16]306    bool out =!static_cast<bool>(*i);
307    if (useUserMask) {
308      out = out && (*miter);
309      miter++;
310    }
311    mask.push_back(out);
[89]312  }
[16]313  return mask;
[2]314}
[206]315std::vector<float> SDMemTable::getSpectrum(Int whichRow) const
316{
[2]317  std::vector<float> spectrum;
318  Array<Float> arr;
[322]319  specCol_.get(whichRow, arr);
[206]320  ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
[2]321  aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
[206]322  ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
[2]323  aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
[206]324  ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
[16]325  aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
[206]326  for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
[16]327    spectrum.push_back(*i);
[2]328  }
329  return spectrum;
330}
[206]331std::vector<string> SDMemTable::getCoordInfo() const
332{
[105]333  String un;
334  Table t = table_.keywordSet().asTable("FREQUENCIES");
335  String sunit;
336  t.keywordSet().get("UNIT",sunit);
337  String dpl;
338  t.keywordSet().get("DOPPLER",dpl);
339  if (dpl == "") dpl = "RADIO";
340  String rfrm;
341  t.keywordSet().get("REFFRAME",rfrm);
342  std::vector<string> inf;
343  inf.push_back(sunit);
344  inf.push_back(rfrm);
345  inf.push_back(dpl);
[263]346  t.keywordSet().get("BASEREFFRAME",rfrm);
347  inf.push_back(rfrm);
[105]348  return inf;
349}
[39]350
[206]351void SDMemTable::setCoordInfo(std::vector<string> theinfo)
352{
[105]353  std::vector<string>::iterator it;
[306]354  String un,rfrm, brfrm,dpl;
355  un = theinfo[0];              // Abcissa unit
356  rfrm = theinfo[1];            // Active (or conversion) frame
357  dpl = theinfo[2];             // Doppler
358  brfrm = theinfo[3];           // Base frame
359//
[105]360  Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
[306]361//
[105]362  Vector<Double> rstf;
363  t.keywordSet().get("RESTFREQS",rstf);
[306]364//
[105]365  Bool canDo = True;
366  Unit u1("km/s");Unit u2("Hz");
367  if (Unit(un) == u1) {
368    Vector<Double> rstf;
369    t.keywordSet().get("RESTFREQS",rstf);
370    if (rstf.nelements() == 0) {
371        throw(AipsError("Can't set unit to km/s if no restfrequencies are specified"));
372    }
373  } else if (Unit(un) != u2 && un != "") {
374        throw(AipsError("Unit not conformant with Spectral Coordinates"));
375  }
376  t.rwKeywordSet().define("UNIT", un);
[275]377//
[105]378  MFrequency::Types mdr;
379  if (!MFrequency::getType(mdr, rfrm)) {
380   
381    Int a,b;const uInt* c;
382    const String* valid = MFrequency::allMyTypes(a, b, c);
383    String pfix = "Please specify a legal frame type. Types are\n";
384    throw(AipsError(pfix+(*valid)));
385  } else {
386    t.rwKeywordSet().define("REFFRAME",rfrm);
387  }
[275]388//
389  MDoppler::Types dtype;
390  dpl.upcase();
391  if (!MDoppler::getType(dtype, dpl)) {
392    throw(AipsError("Doppler type unknown"));
393  } else {
394    t.rwKeywordSet().define("DOPPLER",dpl);
395  }
[306]396//
397  if (!MFrequency::getType(mdr, brfrm)) {
398     Int a,b;const uInt* c;
399     const String* valid = MFrequency::allMyTypes(a, b, c);
400     String pfix = "Please specify a legal frame type. Types are\n";
401     throw(AipsError(pfix+(*valid)));
402   } else {
403    t.rwKeywordSet().define("BASEREFFRAME",brfrm);
404   }
[105]405}
406
[286]407
[206]408std::vector<double> SDMemTable::getAbcissa(Int whichRow) const
409{
[286]410  std::vector<double> abc(nChan());
[206]411
[286]412// Get header units keyword
[206]413
[286]414  Table t = table_.keywordSet().asTable("FREQUENCIES");
[105]415  String sunit;
416  t.keywordSet().get("UNIT",sunit);
417  if (sunit == "") sunit = "pixel";
418  Unit u(sunit);
[286]419
420// Easy if just wanting pixels
421
422  if (sunit==String("pixel")) {
423    // assume channels/pixels
424    std::vector<double>::iterator it;
425    uInt i=0;
426    for (it = abc.begin(); it != abc.end(); ++it) {
427      (*it) = Double(i++);
428    }
429//
430    return abc;
[78]431  }
432
[286]433// Continue with km/s or Hz.  Get FreqID
434
[347]435  Vector<uInt> freqIDs;
436  freqidCol_.get(whichRow, freqIDs);
437  uInt freqID = freqIDs(IFSel_);
[286]438
439// Get SpectralCoordinate, set reference frame conversion,
440// velocity conversion, and rest freq state
441
[347]442  SpectralCoordinate spc = getSpectralCoordinate(freqID, whichRow);
[286]443//
444  Vector<Double> pixel(nChan());
445  indgen(pixel);
446//
447  if (u == Unit("km/s")) {
448     Vector<Double> world;
449     spc.pixelToVelocity(world,pixel);
450     std::vector<double>::iterator it;
451     uInt i = 0;
452     for (it = abc.begin(); it != abc.end(); ++it) {
453       (*it) = world[i];
454       i++;
455     }
[39]456  } else if (u == Unit("Hz")) {
[286]457
458// Set world axis units
459
[39]460    Vector<String> wau(1); wau = u.getName();
461    spc.setWorldAxisUnits(wau);
[286]462//
[39]463    std::vector<double>::iterator it;
464    Double tmp;
465    uInt i = 0;
[286]466    for (it = abc.begin(); it != abc.end(); ++it) {
467      spc.toWorld(tmp,pixel[i]);
[39]468      (*it) = tmp;
469      i++;
470    }
471  }
[286]472  return abc;
[39]473}
474
[164]475std::string SDMemTable::getAbcissaString(Int whichRow) const
[105]476{
477  Table t = table_.keywordSet().asTable("FREQUENCIES");
[286]478//
[105]479  String sunit;
480  t.keywordSet().get("UNIT",sunit);
481  if (sunit == "") sunit = "pixel";
482  Unit u(sunit);
[286]483//
[347]484  Vector<uInt> freqIDs;
485  freqidCol_.get(whichRow, freqIDs);
486  uInt freqID = freqIDs(IFSel_);
[286]487
488// Get SpectralCoordinate, with frame, velocity, rest freq state set
489
[347]490  SpectralCoordinate spc = getSpectralCoordinate(freqID, whichRow);
[275]491//
[105]492  String s = "Channel";
493  if (u == Unit("km/s")) {
494    s = CoordinateUtil::axisLabel(spc,0,True,True,True);
495  } else if (u == Unit("Hz")) {
496    Vector<String> wau(1);wau = u.getName();
497    spc.setWorldAxisUnits(wau);
[286]498//
499    s = CoordinateUtil::axisLabel(spc,0,True,True,False);
[105]500  }
501  return s;
502}
503
[206]504void SDMemTable::setSpectrum(std::vector<float> spectrum, int whichRow)
505{
[89]506  Array<Float> arr;
[322]507  specCol_.get(whichRow, arr);
[89]508  if (spectrum.size() != arr.shape()(3)) {
509    throw(AipsError("Attempting to set spectrum with incorrect length."));
510  }
511
[206]512  ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
[89]513  aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
[206]514  ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
[89]515  aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
[206]516  ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
[89]517  aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
518
519  std::vector<float>::iterator it = spectrum.begin();
[206]520  for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
[89]521    (*i) = Float(*it);
522    it++;
523  }
[322]524  specCol_.put(whichRow, arr);
[89]525}
526
[206]527void SDMemTable::getSpectrum(Vector<Float>& spectrum, Int whichRow) const
528{
[21]529  Array<Float> arr;
[322]530  specCol_.get(whichRow, arr);
[21]531  spectrum.resize(arr.shape()(3));
[206]532  ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
[21]533  aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
[206]534  ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
[21]535  aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
[206]536  ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
[21]537  aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
[2]538
[206]539  ArrayAccessor<Float, Axis<asap::BeamAxis> > va(spectrum);
540  for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
[21]541    (*va) = (*i);
542    va++;
543  }
544}
[89]545/*
[68]546void SDMemTable::getMask(Vector<Bool>& mask, Int whichRow) const {
[21]547  Array<uChar> arr;
[322]548  flagsCol_.get(whichRow, arr);
[21]549  mask.resize(arr.shape()(3));
550
[206]551  ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
[21]552  aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
[206]553  ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0);
[21]554  aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
[206]555  ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1);
[21]556  aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
557
558  Bool useUserMask = ( chanMask_.size() == arr.shape()(3) );
[89]559
[206]560  ArrayAccessor<Bool, Axis<asap::BeamAxis> > va(mask);
[21]561  std::vector<bool> tmp;
562  tmp = chanMask_; // WHY the fxxx do I have to make a copy here. The
[89]563                   // iterator should work on chanMask_??
[21]564  std::vector<bool>::iterator miter;
565  miter = tmp.begin();
566
[206]567  for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
[21]568    bool out =!static_cast<bool>(*i);
569    if (useUserMask) {
570      out = out && (*miter);
571      miter++;
572    }
573    (*va) = out;
574    va++;
[89]575  }
[21]576}
[89]577*/
[16]578MaskedArray<Float> SDMemTable::rowAsMaskedArray(uInt whichRow,
[164]579                                                Bool useSelection) const
580{
[2]581  Array<Float> arr;
582  Array<uChar> farr;
[322]583  specCol_.get(whichRow, arr);
584  flagsCol_.get(whichRow, farr);
[2]585  Array<Bool> barr(farr.shape());convertArray(barr, farr);
586  MaskedArray<Float> marr;
[16]587  if (useSelection) {
[206]588    ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
[16]589    aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
[206]590    ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
[16]591    aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
[206]592    ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
[16]593    aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
[89]594
[206]595    ArrayAccessor<Bool, Axis<asap::BeamAxis> > baa0(barr);
[16]596    baa0.reset(baa0.begin(uInt(beamSel_)));//go to beam
[206]597    ArrayAccessor<Bool, Axis<asap::IFAxis> > baa1(baa0);
[16]598    baa1.reset(baa1.begin(uInt(IFSel_)));// go to IF
[206]599    ArrayAccessor<Bool, Axis<asap::PolAxis> > baa2(baa1);
[16]600    baa2.reset(baa2.begin(uInt(polSel_)));// go to pol
601
602    Vector<Float> a(arr.shape()(3));
603    Vector<Bool> b(barr.shape()(3));
[206]604    ArrayAccessor<Float, Axis<asap::BeamAxis> > a0(a);
605    ArrayAccessor<Bool, Axis<asap::BeamAxis> > b0(b);
[16]606
[206]607    ArrayAccessor<Bool, Axis<asap::ChanAxis> > j(baa2);
608    for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2);
609         i != i.end(); ++i) {
[16]610      (*a0) = (*i);
611      (*b0) = !(*j);
612      j++;
613      a0++;
614      b0++;
615    }
616    marr.setData(a,b);
617  } else {
618    marr.setData(arr,!barr);
619  }
[2]620  return marr;
621}
622
[206]623Float SDMemTable::getTsys(Int whichRow) const
624{
[2]625  Array<Float> arr;
[322]626  tsCol_.get(whichRow, arr);
[2]627  Float out;
628  IPosition ip(arr.shape());
[16]629  ip(0) = beamSel_;ip(1) = IFSel_;ip(2) = polSel_;ip(3)=0;
[2]630  out = arr(ip);
631  return out;
632}
633
[281]634MDirection SDMemTable::getDirection(Int whichRow, Bool refBeam) const
[206]635{
[212]636  MDirection::Types mdr = getDirectionReference();
[206]637  Array<Double> posit;
[322]638  dirCol_.get(whichRow,posit);
[206]639  Vector<Double> wpos(2);
640  wpos[0] = posit(IPosition(2,beamSel_,0));
641  wpos[1] = posit(IPosition(2,beamSel_,1));
642  Quantum<Double> lon(wpos[0],Unit(String("rad")));
643  Quantum<Double> lat(wpos[1],Unit(String("rad")));
[286]644  return MDirection(lon, lat, mdr);
[206]645}
[39]646
[286]647MEpoch SDMemTable::getEpoch (Int whichRow) const
[206]648{
[286]649  MEpoch::Types met = getTimeReference();
650//
651  Double obstime;
[322]652  timeCol_.get(whichRow,obstime);
[286]653  MVEpoch tm2(Quantum<Double>(obstime, Unit(String("d"))));
654  return MEpoch(tm2, met);
655}
656
657MPosition SDMemTable::getAntennaPosition () const
658{
659  Vector<Double> antpos;
660  table_.keywordSet().get("AntennaPosition", antpos);
661  MVPosition mvpos(antpos(0),antpos(1),antpos(2));
662  return MPosition(mvpos);
663}
664
665
[347]666SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt freqID) const
[286]667{
[206]668 
[39]669  Table t = table_.keywordSet().asTable("FREQUENCIES");
[347]670  if (freqID> t.nrow() ) {
671    throw(AipsError("SDMemTable::getSpectralCoordinate - freqID out of range"));
[39]672  }
[89]673
[39]674  Double rp,rv,inc;
675  String rf;
676  ROScalarColumn<Double> rpc(t, "REFPIX");
677  ROScalarColumn<Double> rvc(t, "REFVAL");
678  ROScalarColumn<Double> incc(t, "INCREMENT");
[105]679  t.keywordSet().get("BASEREFFRAME",rf);
[89]680
[286]681// Create SpectralCoordinate (units Hz)
682
[39]683  MFrequency::Types mft;
684  if (!MFrequency::getType(mft, rf)) {
685    cerr << "Frequency type unknown assuming TOPO" << endl;
[89]686    mft = MFrequency::TOPO;
687  }
[347]688  rpc.get(freqID, rp);
689  rvc.get(freqID, rv);
690  incc.get(freqID, inc);
[286]691//
[39]692  SpectralCoordinate spec(mft,rv,inc,rp);
[286]693//
694  return spec;
695}
696
697
[347]698SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt freqID, uInt whichRow) const
[286]699{
700// Create basic SC
701
[347]702  SpectralCoordinate spec = getSpectralCoordinate (freqID);
[286]703//
704  Table t = table_.keywordSet().asTable("FREQUENCIES");
705
[347]706// Get rest frequencies from table, one per IF ???
[286]707
708  Vector<Double> vec;
709  t.keywordSet().get("RESTFREQS",vec);
710  if (vec.nelements() > 0) {
[89]711    spec.setRestFrequencies(vec);
[286]712
713// Select rest freq
714
[348]715    if (IFSel_ < vec.nelements()) {
[286]716       spec.selectRestFrequency(uInt(IFSel_));
[347]717    } else {
718       cerr << "There is no rest frequency for this IF; selecting rest freq for IF=0" << endl;
719       spec.selectRestFrequency(0u);
[286]720    }
721  }
722
723// Set up frame conversion layer
724
725  String frm;
726  t.keywordSet().get("REFFRAME",frm);
727  if (frm == "") frm = "TOPO";
728  MFrequency::Types mtype;
729  if (!MFrequency::getType(mtype, frm)) {
[347]730    cerr << "Frequency type unknown assuming TOPO" << endl;       // SHould never happen
[286]731    mtype = MFrequency::TOPO;
732  }
733
734// Set reference frame conversion  (requires row)
735
736  MDirection direct = getDirection(whichRow);
737  MEpoch epoch = getEpoch(whichRow);
738  MPosition pos = getAntennaPosition();
739  if (!spec.setReferenceConversion(mtype,epoch,pos,direct)) {
740    throw(AipsError("Couldn't convert frequency frame."));
741  }
742
743// Now velocity conversion if appropriate
744
745  String unitStr;
746  t.keywordSet().get("UNIT",unitStr);
747//
748  String dpl;
749  t.keywordSet().get("DOPPLER",dpl);
750  MDoppler::Types dtype;
751  MDoppler::getType(dtype, dpl);
752
753// Only set velocity unit if non-blank and non-Hz
754
755  if (!unitStr.empty()) {
756     Unit unitU(unitStr);
757     if (unitU==Unit("Hz")) {
758     } else {
759        spec.setVelocity(unitStr, dtype);
760     }
761  }
762//
[39]763  return spec;
764}
765
[286]766
[89]767Bool SDMemTable::setCoordinate(const SpectralCoordinate& speccord,
[347]768                               uInt freqID) {
[50]769  Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
[347]770  if (freqID > t.nrow() ) {
[89]771    throw(AipsError("SDMemTable::setCoordinate - coord no out of range"));
[50]772  }
773  ScalarColumn<Double> rpc(t, "REFPIX");
774  ScalarColumn<Double> rvc(t, "REFVAL");
775  ScalarColumn<Double> incc(t, "INCREMENT");
[89]776
[347]777  rpc.put(freqID, speccord.referencePixel()[0]);
778  rvc.put(freqID, speccord.referenceValue()[0]);
779  incc.put(freqID, speccord.increment()[0]);
[50]780
781  return True;
782}
783
[89]784Int SDMemTable::nCoordinates() const
785{
786  return table_.keywordSet().asTable("FREQUENCIES").nrow();
787}
[50]788
[206]789void SDMemTable::setRestFreqs(std::vector<double> freqs,
790                              const std::string& theunit)
[89]791{
792  Vector<Double> tvec(freqs);
793  Quantum<Vector<Double> > q(tvec, String(theunit));
794  tvec.resize();
795  tvec = q.getValue("Hz");
796  Table t = table_.keywordSet().asTable("FREQUENCIES");
797  t.rwKeywordSet().define("RESTFREQS",tvec);
798}
799
[251]800std::vector<double> SDMemTable::getRestFreqs() const
801{
802  Table t = table_.keywordSet().asTable("FREQUENCIES");
803  Vector<Double> tvec;
804  t.keywordSet().get("RESTFREQS",tvec);
805  std::vector<double> stlout;
806  tvec.tovector(stlout);
807  return stlout; 
808}
809
[206]810bool SDMemTable::putSDFreqTable(const SDFrequencyTable& sdft)
811{
[39]812  TableDesc td("", "1", TableDesc::Scratch);
813  td.addColumn(ScalarColumnDesc<Double>("REFPIX"));
814  td.addColumn(ScalarColumnDesc<Double>("REFVAL"));
815  td.addColumn(ScalarColumnDesc<Double>("INCREMENT"));
816  SetupNewTable aNewTab("freqs", td, Table::New);
817  Table aTable (aNewTab, Table::Memory, sdft.length());
818  ScalarColumn<Double> sc0(aTable, "REFPIX");
819  ScalarColumn<Double> sc1(aTable, "REFVAL");
820  ScalarColumn<Double> sc2(aTable, "INCREMENT");
821  for (uInt i=0; i < sdft.length(); ++i) {
822    sc0.put(i,sdft.referencePixel(i));
823    sc1.put(i,sdft.referenceValue(i));
824    sc2.put(i,sdft.increment(i));
825  }
[105]826  String rf = sdft.refFrame();
827  if (rf.contains("TOPO")) rf = "TOPO";
828
829  aTable.rwKeywordSet().define("BASEREFFRAME", rf);
830  aTable.rwKeywordSet().define("REFFRAME", rf);
[39]831  aTable.rwKeywordSet().define("EQUINOX", sdft.equinox());
[105]832  aTable.rwKeywordSet().define("UNIT", String(""));
833  aTable.rwKeywordSet().define("DOPPLER", String("RADIO"));
[89]834  Vector<Double> rfvec;
[206]835  String rfunit;
836  sdft.restFrequencies(rfvec,rfunit);
837  Quantum<Vector<Double> > q(rfvec, rfunit);
838  rfvec.resize();
839  rfvec = q.getValue("Hz");
[89]840  aTable.rwKeywordSet().define("RESTFREQS", rfvec);
[39]841  table_.rwKeywordSet().defineTable ("FREQUENCIES", aTable);
842  return True;
843}
844
[206]845SDFrequencyTable SDMemTable::getSDFreqTable() const
846{
[251]847  const Table& t = table_.keywordSet().asTable("FREQUENCIES");
[39]848  SDFrequencyTable sdft;
[306]849
850// Add refpix/refval/incr.  What are the units ? Hz I suppose
851// but it's nowhere described...
852
853  Vector<Double> refPix, refVal, incr;
854  ScalarColumn<Double> refPixCol(t, "REFPIX");
855  ScalarColumn<Double> refValCol(t, "REFVAL");
856  ScalarColumn<Double> incrCol(t, "INCREMENT");
857  refPix = refPixCol.getColumn();
858  refVal = refValCol.getColumn();
859  incr = incrCol.getColumn();
860//
861  uInt n = refPix.nelements();
862  for (uInt i=0; i<n; i++) {
863     sdft.addFrequency(refPix[i], refVal[i], incr[i]);
864  }
865
866// Frequency reference frame.  I don't know if this
867// is the correct frame.  It might be 'REFFRAME'
868// rather than 'BASEREFFRAME' ?
869
870  String baseFrame;
871  t.keywordSet().get("BASEREFFRAME",baseFrame);
872  sdft.setRefFrame(baseFrame);
873
874// Equinox
875
876  Float equinox;
877  t.keywordSet().get("EQUINOX", equinox);
878  sdft.setEquinox(equinox);
879
880// Rest Frequency
881
882  Vector<Double> restFreqs;
883  t.keywordSet().get("RESTFREQS", restFreqs);
884  for (uInt i=0; i<restFreqs.nelements(); i++) {
885     sdft.addRestFrequency(restFreqs[i]);
886  }
887  sdft.setRestFrequencyUnit(String("Hz"));
888//
[39]889  return sdft;
890}
891
[206]892bool SDMemTable::putSDContainer(const SDContainer& sdc)
893{
[2]894  uInt rno = table_.nrow();
895  table_.addRow();
[89]896
[322]897//  mjd.put(rno, sdc.timestamp);
898  timeCol_.put(rno, sdc.timestamp);
899  srcnCol_.put(rno, sdc.sourcename);
900  fldnCol_.put(rno, sdc.fieldname);
901  specCol_.put(rno, sdc.getSpectrum());
902  flagsCol_.put(rno, sdc.getFlags());
903  tsCol_.put(rno, sdc.getTsys());
904  scanCol_.put(rno, sdc.scanid);
905  integrCol_.put(rno, sdc.interval);
906  freqidCol_.put(rno, sdc.getFreqMap());
907  dirCol_.put(rno, sdc.getDirection());
908  rbeamCol_.put(rno, sdc.refbeam);
909  tcalCol_.put(rno, sdc.tcal);
910  tcaltCol_.put(rno, sdc.tcaltime);
911  azCol_.put(rno, sdc.azimuth);
912  elCol_.put(rno, sdc.elevation);
913  paraCol_.put(rno, sdc.parangle);
914  histCol_.put(rno, sdc.getHistory());
[89]915
[2]916  return true;
917}
[18]918
[206]919SDContainer SDMemTable::getSDContainer(uInt whichRow) const
920{
[21]921  SDContainer sdc(nBeam(),nIF(),nPol(),nChan());
[322]922  timeCol_.get(whichRow, sdc.timestamp);
923  srcnCol_.get(whichRow, sdc.sourcename);
924  integrCol_.get(whichRow, sdc.interval);
925  scanCol_.get(whichRow, sdc.scanid);
926  fldnCol_.get(whichRow, sdc.fieldname);
927  rbeamCol_.get(whichRow, sdc.refbeam);
928  azCol_.get(whichRow, sdc.azimuth);
929  elCol_.get(whichRow, sdc.elevation);
930  paraCol_.get(whichRow, sdc.parangle);
[105]931  Vector<Float> tc;
[322]932  tcalCol_.get(whichRow, tc);
[105]933  sdc.tcal[0] = tc[0];sdc.tcal[1] = tc[1];
[322]934  tcaltCol_.get(whichRow, sdc.tcaltime);
[21]935  Array<Float> spectrum;
936  Array<Float> tsys;
937  Array<uChar> flagtrum;
[39]938  Vector<uInt> fmap;
[78]939  Array<Double> direction;
[206]940  Vector<String> histo;
[322]941  specCol_.get(whichRow, spectrum);
[21]942  sdc.putSpectrum(spectrum);
[322]943  flagsCol_.get(whichRow, flagtrum);
[21]944  sdc.putFlags(flagtrum);
[322]945  tsCol_.get(whichRow, tsys);
[21]946  sdc.putTsys(tsys);
[322]947  freqidCol_.get(whichRow, fmap);
[39]948  sdc.putFreqMap(fmap);
[322]949  dirCol_.get(whichRow, direction);
[78]950  sdc.putDirection(direction);
[322]951  histCol_.get(whichRow, histo);
[206]952  sdc.putHistory(histo);
[21]953  return sdc;
954}
[78]955
[206]956bool SDMemTable::putSDHeader(const SDHeader& sdh)
957{
[18]958  table_.rwKeywordSet().define("nIF", sdh.nif);
959  table_.rwKeywordSet().define("nBeam", sdh.nbeam);
960  table_.rwKeywordSet().define("nPol", sdh.npol);
961  table_.rwKeywordSet().define("nChan", sdh.nchan);
962  table_.rwKeywordSet().define("Observer", sdh.observer);
963  table_.rwKeywordSet().define("Project", sdh.project);
964  table_.rwKeywordSet().define("Obstype", sdh.obstype);
965  table_.rwKeywordSet().define("AntennaName", sdh.antennaname);
966  table_.rwKeywordSet().define("AntennaPosition", sdh.antennaposition);
967  table_.rwKeywordSet().define("Equinox", sdh.equinox);
968  table_.rwKeywordSet().define("FreqRefFrame", sdh.freqref);
969  table_.rwKeywordSet().define("FreqRefVal", sdh.reffreq);
970  table_.rwKeywordSet().define("Bandwidth", sdh.bandwidth);
971  table_.rwKeywordSet().define("UTC", sdh.utc);
[206]972  table_.rwKeywordSet().define("FluxUnit", sdh.fluxunit);
973  table_.rwKeywordSet().define("Epoch", sdh.epoch);
[18]974  return true;
[50]975}
[21]976
[206]977SDHeader SDMemTable::getSDHeader() const
978{
[21]979  SDHeader sdh;
980  table_.keywordSet().get("nBeam",sdh.nbeam);
981  table_.keywordSet().get("nIF",sdh.nif);
982  table_.keywordSet().get("nPol",sdh.npol);
983  table_.keywordSet().get("nChan",sdh.nchan);
984  table_.keywordSet().get("Observer", sdh.observer);
985  table_.keywordSet().get("Project", sdh.project);
986  table_.keywordSet().get("Obstype", sdh.obstype);
987  table_.keywordSet().get("AntennaName", sdh.antennaname);
988  table_.keywordSet().get("AntennaPosition", sdh.antennaposition);
989  table_.keywordSet().get("Equinox", sdh.equinox);
990  table_.keywordSet().get("FreqRefFrame", sdh.freqref);
991  table_.keywordSet().get("FreqRefVal", sdh.reffreq);
992  table_.keywordSet().get("Bandwidth", sdh.bandwidth);
993  table_.keywordSet().get("UTC", sdh.utc);
[206]994  table_.keywordSet().get("FluxUnit", sdh.fluxunit);
995  table_.keywordSet().get("Epoch", sdh.epoch);
[21]996  return sdh;
[18]997}
[206]998void SDMemTable::makePersistent(const std::string& filename)
999{
[2]1000  table_.deepCopy(filename,Table::New);
1001}
1002
[89]1003Int SDMemTable::nScan() const {
[50]1004  Int n = 0;
1005  Int previous = -1;Int current=0;
[322]1006  for (uInt i=0; i< scanCol_.nrow();i++) {
1007    scanCol_.getScalar(i,current);
[50]1008    if (previous != current) {
[89]1009      previous = current;
[50]1010      n++;
1011    }
1012  }
1013  return n;
1014}
1015
[260]1016String SDMemTable::formatSec(Double x) const
[206]1017{
[105]1018  Double xcop = x;
1019  MVTime mvt(xcop/24./3600.);  // make days
[281]1020 
[105]1021  if (x < 59.95)
[281]1022    return  String("      ") + mvt.string(MVTime::TIME_CLEAN_NO_HM, 7)+"s";
1023  else if (x < 3599.95)
1024    return String("   ") + mvt.string(MVTime::TIME_CLEAN_NO_H,7)+" ";
1025  else {
1026    ostringstream oss;
1027    oss << setw(2) << std::right << setprecision(1) << mvt.hour();
1028    oss << ":" << mvt.string(MVTime::TIME_CLEAN_NO_H,7) << " ";
1029    return String(oss);
1030  }   
[105]1031};
1032
[281]1033String SDMemTable::formatDirection(const MDirection& md) const
1034{
1035  Vector<Double> t = md.getAngle(Unit(String("rad"))).getValue();
1036  Int prec = 7;
1037
1038  MVAngle mvLon(t[0]);
1039  String sLon = mvLon.string(MVAngle::TIME,prec);
1040  MVAngle mvLat(t[1]);
1041  String sLat = mvLat.string(MVAngle::ANGLE+MVAngle::DIG2,prec);
1042
1043   return sLon + String(" ") + sLat;
1044}
1045
1046
[206]1047std::string SDMemTable::getFluxUnit() const
1048{
1049  String tmp;
1050  table_.keywordSet().get("FluxUnit", tmp);
1051  return tmp;
1052}
1053
[218]1054void SDMemTable::setFluxUnit(const std::string& unit)
1055{
1056  String tmp(unit);
1057  Unit tU(tmp);
1058  if (tU==Unit("K") || tU==Unit("Jy")) {
1059     table_.rwKeywordSet().define(String("FluxUnit"), tmp);
1060  } else {
1061     throw AipsError("Illegal unit - must be compatible with Jy or K");
1062  }
1063}
1064
[275]1065
[236]1066void SDMemTable::setInstrument(const std::string& name)
1067{
1068  Bool throwIt = True;
1069  Instrument ins = convertInstrument (name, throwIt);
1070  String nameU(name);
1071  nameU.upcase();
1072  table_.rwKeywordSet().define(String("AntennaName"), nameU);
1073}
1074
[260]1075std::string SDMemTable::summary() const  {
[281]1076
1077  // get number of integrations per scan
1078  int cIdx = 0;
1079  int idx = 0;
1080  int scount = 0;
1081  std::vector<int> cycles;
[322]1082  for (uInt i=0; i<scanCol_.nrow();++i) {
1083    while (idx == cIdx && i<scanCol_.nrow()) {
1084      scanCol_.getScalar(++i,cIdx);
[281]1085      ++scount;
1086    }
1087    idx = cIdx;
1088    cycles.push_back(scount);
1089    scount=0;
1090    --i;
1091  } 
1092
1093
[89]1094  ostringstream oss;
1095  oss << endl;
1096  oss << "--------------------------------------------------" << endl;
1097  oss << " Scan Table Summary" << endl;
1098  oss << "--------------------------------------------------" << endl;
1099  oss.flags(std::ios_base::left);
1100  oss << setw(15) << "Beams:" << setw(4) << nBeam() << endl
1101      << setw(15) << "IFs:" << setw(4) << nIF() << endl
1102      << setw(15) << "Polarisations:" << setw(4) << nPol() << endl
1103      << setw(15) << "Channels:"  << setw(4) << nChan() << endl;
1104  oss << endl;
1105  String tmp;
1106  table_.keywordSet().get("Observer", tmp);
1107  oss << setw(15) << "Observer:" << tmp << endl;
[281]1108  oss << setw(15) << "Obs Date:" << getTime(-1,True) << endl;
[89]1109  table_.keywordSet().get("Project", tmp);
1110  oss << setw(15) << "Project:" << tmp << endl;
1111  table_.keywordSet().get("Obstype", tmp);
1112  oss << setw(15) << "Obs. Type:" << tmp << endl;
1113  table_.keywordSet().get("AntennaName", tmp);
1114  oss << setw(15) << "Antenna Name:" << tmp << endl;
[206]1115  table_.keywordSet().get("FluxUnit", tmp);
1116  oss << setw(15) << "Flux Unit:" << tmp << endl;
[260]1117  Table t = table_.keywordSet().asTable("FREQUENCIES");
[105]1118  Vector<Double> vec;
1119  t.keywordSet().get("RESTFREQS",vec);
1120  oss << setw(15) << "Rest Freqs:";
1121  if (vec.nelements() > 0) {
1122      oss << setprecision(0) << vec << " [Hz]" << endl;
1123  } else {
1124      oss << "None set" << endl;
1125  }
[158]1126  oss << setw(15) << "Abcissa:" << getAbcissaString() << endl;
[105]1127  oss << setw(15) << "Cursor:" << "Beam[" << getBeam() << "] "
1128      << "IF[" << getIF() << "] " << "Pol[" << getPol() << "]" << endl;
[89]1129  oss << endl;
[2]1130  uInt count = 0;
1131  String name;
1132  Int previous = -1;Int current=0;
[89]1133  Int integ = 0;
[281]1134  String dirtype ="Position ("+
1135    MDirection::showType(getDirectionReference())+
1136    ")";
[89]1137  oss << setw(6) << "Scan"
[281]1138      << setw(15) << "Source"
1139      << setw(26) << dirtype
1140      << setw(10) << "Time"
1141      << setw(13) << "Integration" << endl;
1142  oss << "-------------------------------------------------------------------------------" << endl;
1143 
1144  std::vector<int>::iterator it = cycles.begin();
[322]1145  for (uInt i=0; i< scanCol_.nrow();i++) {
1146    scanCol_.getScalar(i,current);
[2]1147    if (previous != current) {
[322]1148      srcnCol_.getScalar(i,name);
[50]1149      previous = current;
[105]1150      String t = formatSec(Double(getInterval(i)));
[281]1151      String posit = formatDirection(getDirection(i,True));
1152      oss << setw(6) << count
1153          << setw(15) << name
1154          << setw(26) << posit
1155          << setw(10) << getTime(i,False)
1156          << setw(3) << std::right << *it << " x "
1157          << setw(10)
1158          << t << std::left << endl;
[50]1159      count++;
[281]1160      it++;
[89]1161    } else {
1162      integ++;
[2]1163    }
1164  }
[89]1165  oss << endl;
[321]1166  oss << "Table contains " << table_.nrow() << " integration(s) in " << count << " scan(s)." << endl;
1167
1168// Frequency Table
1169
1170  std::vector<string> info = getCoordInfo();
1171  SDFrequencyTable sdft = getSDFreqTable();
1172  oss << endl << endl;
[325]1173  oss << "FreqID  Frame   RefFreq(Hz)     RefPix   Increment(Hz)" << endl;
[328]1174  oss << "-------------------------------------------------------------------------------" << endl;
[321]1175  for (uInt i=0; i<sdft.length(); i++) {
[325]1176     oss << setw(8) << i << setw(8)
1177                    << info[3] << setw(16) << setprecision (8)
1178                    << sdft.referenceValue(i) << setw(10)
1179                    << sdft.referencePixel(i) << setw(12)
[321]1180                    << sdft.increment(i) << endl;
1181  }
1182  oss << "-------------------------------------------------------------------------------" << endl;
[89]1183  return String(oss);
[2]1184}
[18]1185
[206]1186Int SDMemTable::nBeam() const
1187{
[18]1188  Int n;
1189  table_.keywordSet().get("nBeam",n);
1190  return n;
1191}
1192Int SDMemTable::nIF() const {
1193  Int n;
1194  table_.keywordSet().get("nIF",n);
1195  return n;
1196}
1197Int SDMemTable::nPol() const {
1198  Int n;
1199  table_.keywordSet().get("nPol",n);
1200  return n;
1201}
1202Int SDMemTable::nChan() const {
1203  Int n;
1204  table_.keywordSet().get("nChan",n);
1205  return n;
1206}
[206]1207bool SDMemTable::appendHistory(const std::string& hist, int whichRow)
1208{
1209  Vector<String> history;
[322]1210  histCol_.get(whichRow, history);
[206]1211  history.resize(history.nelements()+1,True);
1212  history[history.nelements()-1] = hist;
[322]1213  histCol_.put(whichRow, history);
[206]1214}
1215
1216std::vector<std::string> SDMemTable::history(int whichRow) const
1217{
1218  Vector<String> history;
[322]1219  histCol_.get(whichRow, history);
[206]1220  std::vector<std::string> stlout;
1221  // there is no Array<String>.tovector(std::vector<std::string>), so
1222  // do it by hand
1223  for (uInt i=0; i<history.nelements(); ++i) {
1224    stlout.push_back(history[i]);
1225  }
1226  return stlout;
1227}
[16]1228/*
[18]1229void SDMemTable::maskChannels(const std::vector<Int>& whichChans ) {
[89]1230
[16]1231  std::vector<int>::iterator it;
[206]1232  ArrayAccessor<uChar, Axis<asap::PolAxis> > j(flags_);
[16]1233  for (it = whichChans.begin(); it != whichChans.end(); it++) {
1234    j.reset(j.begin(uInt(*it)));
[206]1235    for (ArrayAccessor<uChar, Axis<asap::BeamAxis> > i(j); i != i.end(); ++i) {
1236      for (ArrayAccessor<uChar, Axis<asap::IFAxis> > ii(i); ii != ii.end(); ++ii) {
1237        for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > iii(ii);
[89]1238             iii != iii.end(); ++iii) {
1239          (*iii) =
1240        }
[16]1241      }
1242    }
1243  }
[89]1244
[16]1245}
1246*/
[206]1247void SDMemTable::flag(int whichRow)
1248{
[89]1249  Array<uChar> arr;
[322]1250  flagsCol_.get(whichRow, arr);
[89]1251
[206]1252  ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
[89]1253  aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
[206]1254  ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0);
[89]1255  aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
[206]1256  ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1);
[89]1257  aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
1258
[206]1259  for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
[89]1260    (*i) = uChar(True);
1261  }
1262
[322]1263  flagsCol_.put(whichRow, arr);
[89]1264}
[212]1265
[281]1266MDirection::Types SDMemTable::getDirectionReference() const
[212]1267
1268  Float eq;
1269  table_.keywordSet().get("Equinox",eq);
1270  std::map<float,string> mp;
1271  mp[2000.0] = "J2000";
1272  mp[1950.0] = "B1950";
1273  MDirection::Types mdr;
1274  if (!MDirection::getType(mdr, mp[eq])) {   
1275    mdr = MDirection::J2000;
1276    cerr  << "Unknown equinox using J2000" << endl;
1277  }
1278//
1279  return mdr;
1280}
1281
1282MEpoch::Types SDMemTable::getTimeReference () const
1283{
1284  MEpoch::Types met;
1285  String ep;
1286  table_.keywordSet().get("Epoch",ep);
1287  if (!MEpoch::getType(met, ep)) {
1288    cerr << "Epoch type uknown - using UTC" << endl;
1289    met = MEpoch::UTC;
1290  }
1291//
1292  return met;
1293}
1294
[236]1295
1296Instrument SDMemTable::convertInstrument (const String& instrument,
1297                                          Bool throwIt)
1298{
1299   String t(instrument);
1300   t.upcase();
[293]1301
1302// The strings are what SDReader returns, after cunning interrogation
1303// of station names... :-(
1304
[236]1305   Instrument inst = asap::UNKNOWN;
[293]1306   if (t==String("DSS-43")) {               
[236]1307      inst = TIDBINBILLA;
1308   } else if (t==String("ATPKSMB")) {
[292]1309      inst = ATPKSMB;
1310   } else if (t==String("ATPKSHOH")) {
1311      inst = ATPKSHOH;
1312   } else if (t==String("ATMOPRA")) {
1313      inst = ATMOPRA;
1314   } else if (t==String("CEDUNA")) {
1315      inst = CEDUNA;
1316   } else if (t==String("HOBART")) {
1317      inst = HOBART;
[236]1318   } else {
1319      if (throwIt) {
1320         throw AipsError("Unrecognized instrument - use function scan.set_instrument to set");
1321      }
1322   }
1323   return inst;
1324}
1325
Note: See TracBrowser for help on using the repository browser.