source: trunk/src/SDMemTable.cc @ 322

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

cache all the ScalarColumn? and ArrayColumn? objects to avoid reconstructnig
themn for every row get/put.

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