source: trunk/src/SDMemTable.cc @ 306

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

implement function getSDFreqTable which was empty before

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