source: trunk/src/Scantable.cpp @ 852

Last change on this file since 852 was 852, checked in by mar637, 18 years ago

added member function rownumbers()
reworked subtable handling

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.2 KB
Line 
1//
2// C++ Implementation: Scantable
3//
4// Description:
5//
6//
7// Author: Malte Marquarding <asap@atnf.csiro.au>, (C) 2005
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#include <map>
13
14#include <casa/aips.h>
15#include <casa/iostream.h>
16#include <casa/iomanip.h>
17#include <casa/OS/Path.h>
18#include <casa/OS/File.h>
19#include <casa/Arrays/Array.h>
20#include <casa/Arrays/ArrayMath.h>
21#include <casa/Arrays/MaskArrMath.h>
22#include <casa/Arrays/ArrayLogical.h>
23#include <casa/Arrays/ArrayAccessor.h>
24#include <casa/Arrays/VectorSTLIterator.h>
25#include <casa/Arrays/Vector.h>
26#include <casa/BasicMath/Math.h>
27#include <casa/BasicSL/Constants.h>
28#include <casa/Quanta/MVAngle.h>
29#include <casa/Containers/RecordField.h>
30
31#include <tables/Tables/TableParse.h>
32#include <tables/Tables/TableDesc.h>
33#include <tables/Tables/TableCopy.h>
34#include <tables/Tables/SetupNewTab.h>
35#include <tables/Tables/ScaColDesc.h>
36#include <tables/Tables/ArrColDesc.h>
37#include <tables/Tables/TableRow.h>
38#include <tables/Tables/TableVector.h>
39#include <tables/Tables/TableIter.h>
40
41#include <tables/Tables/ExprNode.h>
42#include <tables/Tables/TableRecord.h>
43#include <measures/Measures/MFrequency.h>
44#include <measures/Measures/MEpoch.h>
45#include <measures/Measures/MeasTable.h>
46#include <measures/Measures/MeasRef.h>
47#include <measures/TableMeasures/TableMeasRefDesc.h>
48#include <measures/TableMeasures/TableMeasValueDesc.h>
49#include <measures/TableMeasures/TableMeasDesc.h>
50#include <measures/TableMeasures/ScalarMeasColumn.h>
51#include <coordinates/Coordinates/CoordinateUtil.h>
52#include <casa/Quanta/MVTime.h>
53#include <casa/Quanta/MVAngle.h>
54
55#include "Scantable.h"
56#include "SDAttr.h"
57
58using namespace casa;
59
60namespace asap {
61
62Scantable::Scantable(Table::TableType ttype) :
63  type_(ttype)
64{
65  setupMainTable();
66  freqTable_ = STFrequencies(*this);
67  table_.rwKeywordSet().defineTable("FREQUENCIES", freqTable_.table());
68  weatherTable_ = STWeather(*this);
69  table_.rwKeywordSet().defineTable("WEATHER", weatherTable_.table());
70  focusTable_ = STFocus(*this);
71  table_.rwKeywordSet().defineTable("FOCUS", focusTable_.table());
72  tcalTable_ = STTcal(*this);
73  table_.rwKeywordSet().defineTable("TCAL", tcalTable_.table());
74  moleculeTable_ = STMolecules(*this);
75  table_.rwKeywordSet().defineTable("MOLECULES", moleculeTable_.table());
76  setupHistoryTable();
77  setupFitTable();
78  historyTable_ = table_.keywordSet().asTable("HISTORY");
79  fitTable_ = table_.keywordSet().asTable("FITS");
80  cout << "DEBUG" << endl;
81
82  originalTable_ = table_;
83  attach();
84  cout << "debug" << endl;
85}
86
87Scantable::Scantable(const std::string& name, Table::TableType ttype) :
88  type_(ttype)
89{
90  Table tab(name);
91  Int version;
92  tab.keywordSet().get("VERSION", version);
93  if (version != version_) {
94    throw(AipsError("Unsupported version of ASAP file."));
95  }
96  if ( type_ == Table::Memory )
97    table_ = tab.copyToMemoryTable(generateName());
98  else
99    table_ = tab;
100  freqTable_ = STFrequencies(table_.keywordSet().asTable("FREQUENCIES"));
101  focusTable_ = STFocus(table_.keywordSet().asTable("FOCUS"));
102  weatherTable_ = STWeather(table_.keywordSet().asTable("WEATHER"));
103  tcalTable_ = STTcal(table_.keywordSet().asTable("TCAL"));
104  moleculeTable_ = STMolecules(table_.keywordSet().asTable("MOLECULES"));
105  originalTable_ = table_;
106  attach();
107}
108
109
110Scantable::Scantable( const Scantable& other, bool clear )
111{
112  // with or without data
113  if (clear) {
114    table_ = TableCopy::makeEmptyMemoryTable(String(generateName()),
115                                             other.table_, True);
116  } else {
117    table_ = other.table_.copyToMemoryTable(String(generateName()));
118  }
119
120  originalTable_ = table_;
121  attach();
122}
123
124Scantable::~Scantable()
125{
126  cout << "~Scantable() " << this << endl;
127}
128
129void Scantable::setupMainTable()
130{
131  TableDesc td("", "1", TableDesc::Scratch);
132  td.comment() = "An ASAP Scantable";
133  td.rwKeywordSet().define("VERSION", Int(version_));
134
135  // n Cycles
136  td.addColumn(ScalarColumnDesc<uInt>("SCANNO"));
137  // new index every nBeam x nIF x nPol
138  td.addColumn(ScalarColumnDesc<uInt>("CYCLENO"));
139
140  td.addColumn(ScalarColumnDesc<uInt>("BEAMNO"));
141  td.addColumn(ScalarColumnDesc<uInt>("IFNO"));
142  td.rwKeywordSet().define("POLTYPE", String("linear"));
143  td.addColumn(ScalarColumnDesc<uInt>("POLNO"));
144
145  td.addColumn(ScalarColumnDesc<uInt>("FREQ_ID"));
146  td.addColumn(ScalarColumnDesc<uInt>("MOLECULE_ID"));
147  // linear, circular, stokes [I Q U V], stokes1 [I Plinear Pangle V]
148  td.addColumn(ScalarColumnDesc<Int>("REFBEAMNO"));
149
150  td.addColumn(ScalarColumnDesc<Double>("TIME"));
151  TableMeasRefDesc measRef(MEpoch::UTC); // UTC as default
152  TableMeasValueDesc measVal(td, "TIME");
153  TableMeasDesc<MEpoch> mepochCol(measVal, measRef);
154  mepochCol.write(td);
155
156  td.addColumn(ScalarColumnDesc<Double>("INTERVAL"));
157
158  td.addColumn(ScalarColumnDesc<String>("SRCNAME"));
159  // Type of source (on=0, off=1, other=-1)
160  td.addColumn(ScalarColumnDesc<Int>("SRCTYPE", Int(-1)));
161  td.addColumn(ScalarColumnDesc<String>("FIELDNAME"));
162
163  //The actual Data Vectors
164  td.addColumn(ArrayColumnDesc<Float>("SPECTRA"));
165  td.addColumn(ArrayColumnDesc<uChar>("FLAGTRA"));
166  td.addColumn(ArrayColumnDesc<Float>("TSYS"));
167
168  td.addColumn(ArrayColumnDesc<Double>("DIRECTION",
169                                       IPosition(1,2),
170                                       ColumnDesc::Direct));
171  TableMeasRefDesc mdirRef(MDirection::J2000); // default
172  TableMeasValueDesc tmvdMDir(td, "DIRECTION");
173  // the TableMeasDesc gives the column a type
174  TableMeasDesc<MDirection> mdirCol(tmvdMDir, mdirRef);
175  // writing create the measure column
176  mdirCol.write(td);
177  td.addColumn(ScalarColumnDesc<Double>("AZIMUTH"));
178  td.addColumn(ScalarColumnDesc<Double>("ELEVATION"));
179  td.addColumn(ScalarColumnDesc<Float>("PARANGLE"));
180
181  td.addColumn(ScalarColumnDesc<uInt>("TCAL_ID"));
182  td.addColumn(ScalarColumnDesc<uInt>("FIT_ID"));
183
184  td.addColumn(ScalarColumnDesc<uInt>("FOCUS_ID"));
185  td.addColumn(ScalarColumnDesc<uInt>("WEATHER_ID"));
186
187  td.rwKeywordSet().define("OBSMODE", String(""));
188
189  // Now create Table SetUp from the description.
190  SetupNewTable aNewTab(generateName(), td, Table::New);
191  table_ = Table(aNewTab, type_, 0);
192  originalTable_ = table_;
193
194}
195
196void Scantable::setupHistoryTable( )
197{
198  TableDesc tdh("", "1", TableDesc::Scratch);
199  tdh.addColumn(ScalarColumnDesc<String>("ITEM"));
200  SetupNewTable histtab("history", tdh, Table::New);
201  Table histTable(histtab, Table::Memory);
202  table_.rwKeywordSet().defineTable("HISTORY", histTable);
203}
204
205void Scantable::setupFitTable()
206{
207  TableDesc td("", "1", TableDesc::Scratch);
208  td.addColumn(ScalarColumnDesc<uInt>("FIT_ID"));
209  td.addColumn(ArrayColumnDesc<String>("FUNCTIONS"));
210  td.addColumn(ArrayColumnDesc<Int>("COMPONENTS"));
211  td.addColumn(ArrayColumnDesc<Double>("PARAMETERS"));
212  td.addColumn(ArrayColumnDesc<Bool>("PARMASK"));
213  td.addColumn(ArrayColumnDesc<String>("FRAMEINFO"));
214  SetupNewTable aNewTab("fits", td, Table::New);
215  Table aTable(aNewTab, Table::Memory);
216  table_.rwKeywordSet().defineTable("FITS", aTable);
217}
218
219void Scantable::attach()
220{
221  timeCol_.attach(table_, "TIME");
222  srcnCol_.attach(table_, "SRCNAME");
223  specCol_.attach(table_, "SPECTRA");
224  flagsCol_.attach(table_, "FLAGTRA");
225  tsCol_.attach(table_, "TSYS");
226  cycleCol_.attach(table_,"CYCLENO");
227  scanCol_.attach(table_, "SCANNO");
228  beamCol_.attach(table_, "BEAMNO");
229  ifCol_.attach(table_, "IFNO");
230  polCol_.attach(table_, "POLNO");
231  integrCol_.attach(table_, "INTERVAL");
232  azCol_.attach(table_, "AZIMUTH");
233  elCol_.attach(table_, "ELEVATION");
234  dirCol_.attach(table_, "DIRECTION");
235  paraCol_.attach(table_, "PARANGLE");
236  fldnCol_.attach(table_, "FIELDNAME");
237  rbeamCol_.attach(table_, "REFBEAMNO");
238
239  mfitidCol_.attach(table_,"FIT_ID");
240  fitidCol_.attach(fitTable_,"FIT_ID");
241
242  mfreqidCol_.attach(table_, "FREQ_ID");
243
244  mtcalidCol_.attach(table_, "TCAL_ID");
245
246  mfocusidCol_.attach(table_, "FOCUS_ID");
247
248  mmolidCol_.attach(table_, "MOLECULE_ID");
249}
250
251void Scantable::setHeader(const SDHeader& sdh)
252{
253  table_.rwKeywordSet().define("nIF", sdh.nif);
254  table_.rwKeywordSet().define("nBeam", sdh.nbeam);
255  table_.rwKeywordSet().define("nPol", sdh.npol);
256  table_.rwKeywordSet().define("nChan", sdh.nchan);
257  table_.rwKeywordSet().define("Observer", sdh.observer);
258  table_.rwKeywordSet().define("Project", sdh.project);
259  table_.rwKeywordSet().define("Obstype", sdh.obstype);
260  table_.rwKeywordSet().define("AntennaName", sdh.antennaname);
261  table_.rwKeywordSet().define("AntennaPosition", sdh.antennaposition);
262  table_.rwKeywordSet().define("Equinox", sdh.equinox);
263  table_.rwKeywordSet().define("FreqRefFrame", sdh.freqref);
264  table_.rwKeywordSet().define("FreqRefVal", sdh.reffreq);
265  table_.rwKeywordSet().define("Bandwidth", sdh.bandwidth);
266  table_.rwKeywordSet().define("UTC", sdh.utc);
267  table_.rwKeywordSet().define("FluxUnit", sdh.fluxunit);
268  table_.rwKeywordSet().define("Epoch", sdh.epoch);
269}
270
271SDHeader Scantable::getHeader() const
272{
273  SDHeader sdh;
274  table_.keywordSet().get("nBeam",sdh.nbeam);
275  table_.keywordSet().get("nIF",sdh.nif);
276  table_.keywordSet().get("nPol",sdh.npol);
277  table_.keywordSet().get("nChan",sdh.nchan);
278  table_.keywordSet().get("Observer", sdh.observer);
279  table_.keywordSet().get("Project", sdh.project);
280  table_.keywordSet().get("Obstype", sdh.obstype);
281  table_.keywordSet().get("AntennaName", sdh.antennaname);
282  table_.keywordSet().get("AntennaPosition", sdh.antennaposition);
283  table_.keywordSet().get("Equinox", sdh.equinox);
284  table_.keywordSet().get("FreqRefFrame", sdh.freqref);
285  table_.keywordSet().get("FreqRefVal", sdh.reffreq);
286  table_.keywordSet().get("Bandwidth", sdh.bandwidth);
287  table_.keywordSet().get("UTC", sdh.utc);
288  table_.keywordSet().get("FluxUnit", sdh.fluxunit);
289  table_.keywordSet().get("Epoch", sdh.epoch);
290  return sdh;
291}
292
293bool Scantable::conformant( const Scantable& other )
294{
295  return this->getHeader().conformant(other.getHeader());
296}
297
298
299int Scantable::nscan() const {
300  int n = 0;
301  int previous = -1; int current = 0;
302  for (uInt i=0; i< scanCol_.nrow();i++) {
303    scanCol_.getScalar(i,current);
304    if (previous != current) {
305      previous = current;
306      n++;
307    }
308  }
309  return n;
310}
311
312std::string Scantable::formatSec(Double x) const
313{
314  Double xcop = x;
315  MVTime mvt(xcop/24./3600.);  // make days
316
317  if (x < 59.95)
318    return  String("      ") + mvt.string(MVTime::TIME_CLEAN_NO_HM, 7)+"s";
319  else if (x < 3599.95)
320    return String("   ") + mvt.string(MVTime::TIME_CLEAN_NO_H,7)+" ";
321  else {
322    ostringstream oss;
323    oss << setw(2) << std::right << setprecision(1) << mvt.hour();
324    oss << ":" << mvt.string(MVTime::TIME_CLEAN_NO_H,7) << " ";
325    return String(oss);
326  }
327};
328
329std::string Scantable::formatDirection(const MDirection& md) const
330{
331  Vector<Double> t = md.getAngle(Unit(String("rad"))).getValue();
332  Int prec = 7;
333
334  MVAngle mvLon(t[0]);
335  String sLon = mvLon.string(MVAngle::TIME,prec);
336  MVAngle mvLat(t[1]);
337  String sLat = mvLat.string(MVAngle::ANGLE+MVAngle::DIG2,prec);
338  return sLon + String(" ") + sLat;
339}
340
341
342std::string Scantable::getFluxUnit() const
343{
344  return table_.keywordSet().asString("FluxUnit");
345}
346
347void Scantable::setFluxUnit(const std::string& unit)
348{
349  String tmp(unit);
350  Unit tU(tmp);
351  if (tU==Unit("K") || tU==Unit("Jy")) {
352     table_.rwKeywordSet().define(String("FluxUnit"), tmp);
353  } else {
354     throw AipsError("Illegal unit - must be compatible with Jy or K");
355  }
356}
357
358void Scantable::setInstrument(const std::string& name)
359{
360  bool throwIt = true;
361  Instrument ins = SDAttr::convertInstrument(name, throwIt);
362  String nameU(name);
363  nameU.upcase();
364  table_.rwKeywordSet().define(String("AntennaName"), nameU);
365}
366
367MPosition Scantable::getAntennaPosition () const
368{
369  Vector<Double> antpos;
370  table_.keywordSet().get("AntennaPosition", antpos);
371  MVPosition mvpos(antpos(0),antpos(1),antpos(2));
372  return MPosition(mvpos);
373}
374
375void Scantable::makePersistent(const std::string& filename)
376{
377  String inname(filename);
378  Path path(inname);
379  inname = path.expandedName();
380  table_.deepCopy(inname, Table::New);
381}
382
383int Scantable::nbeam( int scanno ) const
384{
385  if ( scanno < 0 ) {
386    Int n;
387    table_.keywordSet().get("nBeam",n);
388    return int(n);
389  } else {
390    // take the first POLNO,IFNO,CYCLENO as nbeam shouldn't vary with these
391    Table tab = table_(table_.col("SCANNO") == scanno
392                       && table_.col("POLNO") == 0
393                       && table_.col("IFNO") == 0
394                       && table_.col("CYCLENO") == 0 );
395    ROTableVector<uInt> v(tab, "BEAMNO");
396    return int(v.nelements());
397  }
398  return 0;
399}
400
401int Scantable::nif( int scanno ) const
402{
403  if ( scanno < 0 ) {
404    Int n;
405    table_.keywordSet().get("nIF",n);
406    return int(n);
407  } else {
408    // take the first POLNO,BEAMNO,CYCLENO as nbeam shouldn't vary with these
409    Table tab = table_(table_.col("SCANNO") == scanno
410                       && table_.col("POLNO") == 0
411                       && table_.col("BEAMNO") == 0
412                       && table_.col("CYCLENO") == 0 );
413    ROTableVector<uInt> v(tab, "IFNO");
414    return int(v.nelements());
415  }
416  return 0;
417}
418
419int Scantable::npol( int scanno ) const
420{
421  if ( scanno < 0 ) {
422    Int n;
423    table_.keywordSet().get("nPol",n);
424    return n;
425  } else {
426    // take the first POLNO,IFNO,CYCLENO as nbeam shouldn't vary with these
427    Table tab = table_(table_.col("SCANNO") == scanno
428                       && table_.col("IFNO") == 0
429                       && table_.col("BEAMNO") == 0
430                       && table_.col("CYCLENO") == 0 );
431    ROTableVector<uInt> v(tab, "POLNO");
432    return int(v.nelements());
433  }
434  return 0;
435}
436
437int Scantable::ncycle( int scanno ) const
438{
439  if ( scanno < 0 ) {
440    Block<String> cols(2);
441    cols[0] = "SCANNO";
442    cols[1] = "CYCLENO";
443    TableIterator it(table_, cols);
444    int n = 0;
445    while ( !it.pastEnd() ) {
446      ++n;
447    }
448    return n;
449  } else {
450    // take the first POLNO,IFNO,CYCLENO as nbeam shouldn't vary with these
451    Table tab = table_(table_.col("SCANNO") == scanno
452                       && table_.col("BEAMNO") == 0
453                       && table_.col("IFNO") == 0
454                       && table_.col("POLNO") == 0 );
455    return int(tab.nrow());
456  }
457  return 0;
458}
459
460
461int Scantable::nrow( int scanno ) const
462{
463  return int(table_.nrow());
464}
465
466int Scantable::nchan( int ifno ) const
467{
468  if ( ifno < 0 ) {
469    Int n;
470    table_.keywordSet().get("nChan",n);
471    return int(n);
472  } else {
473    // take the first SCANNO,POLNO,BEAMNO,CYCLENO as nbeam shouldn't vary with these
474    Table tab = table_(table_.col("SCANNO") == 0
475                       && table_.col("IFNO") == ifno
476                       && table_.col("BEAMNO") == 0
477                       && table_.col("POLNO") == 0
478                       && table_.col("CYCLENO") == 0 );
479    ROArrayColumn<Float> v(tab, "SPECTRA");
480    return v(0).nelements();
481  }
482  return 0;
483}
484
485
486int Scantable::getBeam(int whichrow) const
487{
488  return beamCol_(whichrow);
489}
490
491int Scantable::getIF(int whichrow) const
492{
493  return ifCol_(whichrow);
494}
495
496int Scantable::getPol(int whichrow) const
497{
498  return polCol_(whichrow);
499}
500
501Table Scantable::getHistoryTable() const
502{
503  return table_.keywordSet().asTable("HISTORY");
504}
505
506void Scantable::appendToHistoryTable(const Table& otherHist)
507{
508  Table t = table_.rwKeywordSet().asTable("HISTORY");
509
510  addHistory(asap::SEPERATOR);
511  TableCopy::copyRows(t, otherHist, t.nrow(), 0, otherHist.nrow());
512  addHistory(asap::SEPERATOR);
513}
514
515void Scantable::addHistory(const std::string& hist)
516{
517  Table t = table_.rwKeywordSet().asTable("HISTORY");
518  uInt nrow = t.nrow();
519  t.addRow();
520  ScalarColumn<String> itemCol(t, "ITEM");
521  itemCol.put(nrow, hist);
522}
523
524std::vector<std::string> Scantable::getHistory() const
525{
526  Vector<String> history;
527  const Table& t = table_.keywordSet().asTable("HISTORY");
528  uInt nrow = t.nrow();
529  ROScalarColumn<String> itemCol(t, "ITEM");
530  std::vector<std::string> stlout;
531  String hist;
532  for (uInt i=0; i<nrow; ++i) {
533    itemCol.get(i, hist);
534    stlout.push_back(hist);
535  }
536  return stlout;
537}
538
539std::string Scantable::formatTime(const MEpoch& me, bool showdate) const
540{
541  MVTime mvt(me.getValue());
542  if (showdate)
543    mvt.setFormat(MVTime::YMD);
544  else
545    mvt.setFormat(MVTime::TIME);
546  ostringstream oss;
547  oss << mvt;
548  return String(oss);
549}
550
551void Scantable::calculateAZEL()
552{
553  MPosition mp = getAntennaPosition();
554  MEpoch::ROScalarColumn timeCol(table_, "TIME");
555  ostringstream oss;
556  oss << "Computed azimuth/elevation using " << endl
557      << mp << endl;
558  for (uInt i=0; i<nrow(); ++i) {
559    MEpoch me = timeCol(i);
560    MDirection md = dirCol_(i);
561    dirCol_.get(i,md);
562    oss  << " Time: " << formatTime(me,False) << " Direction: " << formatDirection(md)
563         << endl << "     => ";
564    MeasFrame frame(mp, me);
565    Vector<Double> azel =
566        MDirection::Convert(md, MDirection::Ref(MDirection::AZEL,
567                                                frame)
568                            )().getAngle("rad").getValue();
569    azCol_.put(i,azel[0]);
570    elCol_.put(i,azel[1]);
571    oss << "azel: " << azel[0]/C::pi*180.0 << " "
572        << azel[1]/C::pi*180.0 << " (deg)" << endl;
573  }
574  pushLog(String(oss));
575}
576
577std::vector<bool> Scantable::getMask(int whichrow) const
578{
579  Vector<uChar> flags;
580  flagsCol_.get(uInt(whichrow), flags);
581  Vector<Bool> bflag(flags.shape());
582  convertArray(bflag, flags);
583  bflag = !bflag;
584  std::vector<bool> mask;
585  bflag.tovector(mask);
586  return mask;
587}
588
589std::vector<float> Scantable::getSpectrum(int whichrow) const
590{
591  Vector<Float> arr;
592  specCol_.get(whichrow, arr);
593  std::vector<float> out;
594  arr.tovector(out);
595  return out;
596}
597
598String Scantable::generateName()
599{
600  return (File::newUniqueName("./","temp")).baseName();
601}
602
603const casa::Table& Scantable::table( ) const
604{
605  return table_;
606}
607
608casa::Table& Scantable::table( )
609{
610  return table_;
611}
612
613std::string Scantable::getPolarizationLabel(bool linear, bool stokes,
614                                            bool linpol, int polidx) const
615{
616  uInt idx = 0;
617  if (polidx >=0) idx = polidx;
618  return "";
619  //return SDPolUtil::polarizationLabel(idx, linear, stokes, linpol);
620}
621
622void Scantable::unsetSelection()
623{
624  table_ = originalTable_;
625  attach();
626  selector_.reset();
627}
628
629void Scantable::setSelection( const STSelector& selection )
630{
631  Table tab = const_cast<STSelector&>(selection).apply(originalTable_);
632  if ( tab.nrow() == 0 ) {
633    throw(AipsError("Selection contains no data. Not applying it."));
634  }
635  table_ = tab;
636  attach();
637  selector_ = selection;
638}
639
640std::string Scantable::summary( bool verbose )
641{
642  // Format header info
643  ostringstream oss;
644  oss << endl;
645  oss << asap::SEPERATOR << endl;
646  oss << " Scan Table Summary" << endl;
647  oss << asap::SEPERATOR << endl;
648  oss.flags(std::ios_base::left);
649  oss << setw(15) << "Beams:" << setw(4) << nbeam() << endl
650      << setw(15) << "IFs:" << setw(4) << nif() << endl
651      << setw(15) << "Polarisations:" << setw(4) << npol() << endl
652      << setw(15) << "Channels:"  << setw(4) << nchan() << endl;
653  oss << endl;
654  String tmp;
655  //table_.keywordSet().get("Observer", tmp);
656  oss << setw(15) << "Observer:" << table_.keywordSet().asString("Observer") << endl;
657  oss << setw(15) << "Obs Date:" << getTime(-1,true) << endl;
658  table_.keywordSet().get("Project", tmp);
659  oss << setw(15) << "Project:" << tmp << endl;
660  table_.keywordSet().get("Obstype", tmp);
661  oss << setw(15) << "Obs. Type:" << tmp << endl;
662  table_.keywordSet().get("AntennaName", tmp);
663  oss << setw(15) << "Antenna Name:" << tmp << endl;
664  table_.keywordSet().get("FluxUnit", tmp);
665  oss << setw(15) << "Flux Unit:" << tmp << endl;
666  Vector<Float> vec;
667  oss << setw(15) << "Rest Freqs:";
668  if (vec.nelements() > 0) {
669      oss << setprecision(10) << vec << " [Hz]" << endl;
670  } else {
671      oss << "none" << endl;
672  }
673  oss << setw(15) << "Abcissa:" << "channel" << endl;
674  oss << selector_.print() << endl;
675  oss << endl;
676  // main table
677  String dirtype = "Position ("
678                  + MDirection::showType(dirCol_.getMeasRef().getType())
679                  + ")";
680  oss << setw(5) << "Scan"
681      << setw(15) << "Source"
682//      << setw(24) << dirtype
683      << setw(10) << "Time"
684      << setw(18) << "Integration" << endl
685      << setw(5) << "" << setw(10) << "Beam" << dirtype << endl
686      << setw(15) << "" << setw(5) << "IF"
687      << setw(8) << "Frame" << setw(16)
688      << "RefVal" << setw(10) << "RefPix" << setw(12) << "Increment" <<endl;
689  oss << asap::SEPERATOR << endl;
690  TableIterator iter(table_, "SCANNO");
691  while (!iter.pastEnd()) {
692    Table subt = iter.table();
693    ROTableRow row(subt);
694    MEpoch::ROScalarColumn timeCol(subt,"TIME");
695    const TableRecord& rec = row.get(0);
696    oss << setw(4) << std::right << rec.asuInt("SCANNO")
697        << std::left << setw(1) << ""
698        << setw(15) << rec.asString("SRCNAME")
699        << setw(10) << formatTime(timeCol(0), false);
700    // count the cycles in the scan
701    TableIterator cyciter(subt, "CYCLENO");
702    int nint = 0;
703    while (!cyciter.pastEnd()) {
704      ++nint;
705      ++cyciter;
706    }
707    oss << setw(3) << std::right << nint  << setw(3) << " x " << std::left
708        << setw(6) <<  formatSec(rec.asFloat("INTERVAL")) << endl;
709
710    TableIterator biter(subt, "BEAMNO");
711    while (!biter.pastEnd()) {
712      Table bsubt = biter.table();
713      ROTableRow brow(bsubt);
714      MDirection::ROScalarColumn bdirCol(bsubt,"DIRECTION");
715      const TableRecord& brec = brow.get(0);
716      oss << setw(6) << "" <<  setw(10) << brec.asuInt("BEAMNO");
717      oss  << setw(24) << formatDirection(bdirCol(0)) << endl;
718      TableIterator iiter(bsubt, "IFNO");
719      while (!iiter.pastEnd()) {
720        Table isubt = iiter.table();
721        ROTableRow irow(isubt);
722        const TableRecord& irec = irow.get(0);
723        oss << std::right <<setw(8) << "" << std::left << irec.asuInt("IFNO");
724        oss << frequencies().print(irec.asuInt("FREQ_ID"));
725
726        ++iiter;
727      }
728      ++biter;
729    }
730    ++iter;
731  }
732  /// @todo implement verbose mode
733  return String(oss);
734}
735
736std::string Scantable::getTime(int whichrow, bool showdate) const
737{
738  MEpoch::ROScalarColumn timeCol(table_, "TIME");
739  MEpoch me;
740  if (whichrow > -1) {
741    me = timeCol(uInt(whichrow));
742  } else {
743    Double tm;
744    table_.keywordSet().get("UTC",tm);
745    me = MEpoch(MVEpoch(tm));
746  }
747  return formatTime(me, showdate);
748}
749
750std::string Scantable::getAbcissaLabel( int whichrow ) const
751{
752  if ( whichrow > table_.nrow() ) throw(AipsError("Illegal ro number"));
753  const MPosition& mp = getAntennaPosition();
754  const MDirection& md = dirCol_(whichrow);
755  const MEpoch& me = timeCol_(whichrow);
756  const Double& rf = mmolidCol_(whichrow);
757  SpectralCoordinate spc =
758    freqTable_.getSpectralCoordinate(md, mp, me, rf, mfreqidCol_(whichrow));
759
760  String s = "Channel";
761  Unit u = Unit(freqTable_.getUnitString());
762  if (u == Unit("km/s")) {
763    s = CoordinateUtil::axisLabel(spc,0,True,True,True);
764  } else if (u == Unit("Hz")) {
765    Vector<String> wau(1);wau = u.getName();
766    spc.setWorldAxisUnits(wau);
767
768    s = CoordinateUtil::axisLabel(spc,0,True,True,False);
769  }
770  return s;
771
772}
773
774void asap::Scantable::setRestFrequencies( double rf, const std::string& unit )
775{
776  ///@todo lookup in line table
777  Unit u(unit);
778  Quantum<Double> urf(rf, u);
779  uInt id = moleculeTable_.addEntry(urf.getValue("Hz"), "", "");
780  TableVector<uInt> tabvec(table_, "MOLECULE_ID");
781  tabvec = id;
782}
783
784void asap::Scantable::setRestFrequencies( const std::string& name )
785{
786  throw(AipsError("setRestFrequencies( const std::string& name ) NYI"));
787  ///@todo implement
788}
789
790std::vector< unsigned int > asap::Scantable::rownumbers( ) const
791{
792  std::vector<unsigned int> stlout;
793  Vector<uInt> vec = table_.rowNumbers();
794  vec.tovector(stlout);
795  return stlout;
796}
797
798}//namespace asap
Note: See TracBrowser for help on using the repository browser.