source: trunk/src/SDMemTable.cc@ 304

Last change on this file since 304 was 303, checked in by kil064, 20 years ago

add function resetCursor

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 36.6 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,dpl;
334 un = theinfo[0];
335 rfrm = theinfo[1];
336 dpl = theinfo[2];
337
338 Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
339 Vector<Double> rstf;
340 t.keywordSet().get("RESTFREQS",rstf);
341 Bool canDo = True;
342 Unit u1("km/s");Unit u2("Hz");
343 if (Unit(un) == u1) {
344 Vector<Double> rstf;
345 t.keywordSet().get("RESTFREQS",rstf);
346 if (rstf.nelements() == 0) {
347 throw(AipsError("Can't set unit to km/s if no restfrequencies are specified"));
348 }
349 } else if (Unit(un) != u2 && un != "") {
350 throw(AipsError("Unit not conformant with Spectral Coordinates"));
351 }
352 t.rwKeywordSet().define("UNIT", un);
353//
354 MFrequency::Types mdr;
355 if (!MFrequency::getType(mdr, rfrm)) {
356
357 Int a,b;const uInt* c;
358 const String* valid = MFrequency::allMyTypes(a, b, c);
359 String pfix = "Please specify a legal frame type. Types are\n";
360 throw(AipsError(pfix+(*valid)));
361 } else {
362 t.rwKeywordSet().define("REFFRAME",rfrm);
363 }
364//
365 MDoppler::Types dtype;
366 dpl.upcase();
367 if (!MDoppler::getType(dtype, dpl)) {
368 throw(AipsError("Doppler type unknown"));
369 } else {
370 t.rwKeywordSet().define("DOPPLER",dpl);
371 }
372}
373
374
375std::vector<double> SDMemTable::getAbcissa(Int whichRow) const
376{
377 std::vector<double> abc(nChan());
378
379// Get header units keyword
380
381 Table t = table_.keywordSet().asTable("FREQUENCIES");
382 String sunit;
383 t.keywordSet().get("UNIT",sunit);
384 if (sunit == "") sunit = "pixel";
385 Unit u(sunit);
386
387// Easy if just wanting pixels
388
389 if (sunit==String("pixel")) {
390 // assume channels/pixels
391 std::vector<double>::iterator it;
392 uInt i=0;
393 for (it = abc.begin(); it != abc.end(); ++it) {
394 (*it) = Double(i++);
395 }
396//
397 return abc;
398 }
399
400// Continue with km/s or Hz. Get FreqID
401
402 ROArrayColumn<uInt> fid(table_, "FREQID");
403 Vector<uInt> v;
404 fid.get(whichRow, v);
405 uInt specidx = v(IFSel_);
406
407// Get SpectralCoordinate, set reference frame conversion,
408// velocity conversion, and rest freq state
409
410 SpectralCoordinate spc = getSpectralCoordinate(specidx, whichRow);
411//
412 Vector<Double> pixel(nChan());
413 indgen(pixel);
414//
415 if (u == Unit("km/s")) {
416 Vector<Double> world;
417 spc.pixelToVelocity(world,pixel);
418 std::vector<double>::iterator it;
419 uInt i = 0;
420 for (it = abc.begin(); it != abc.end(); ++it) {
421 (*it) = world[i];
422 i++;
423 }
424 } else if (u == Unit("Hz")) {
425
426// Set world axis units
427
428 Vector<String> wau(1); wau = u.getName();
429 spc.setWorldAxisUnits(wau);
430//
431 std::vector<double>::iterator it;
432 Double tmp;
433 uInt i = 0;
434 for (it = abc.begin(); it != abc.end(); ++it) {
435 spc.toWorld(tmp,pixel[i]);
436 (*it) = tmp;
437 i++;
438 }
439 }
440 return abc;
441}
442
443std::string SDMemTable::getAbcissaString(Int whichRow) const
444{
445 ROArrayColumn<uInt> fid(table_, "FREQID");
446 Table t = table_.keywordSet().asTable("FREQUENCIES");
447//
448 String sunit;
449 t.keywordSet().get("UNIT",sunit);
450 if (sunit == "") sunit = "pixel";
451 Unit u(sunit);
452//
453 Vector<uInt> v;
454 fid.get(whichRow, v);
455 uInt specidx = v(IFSel_);
456
457// Get SpectralCoordinate, with frame, velocity, rest freq state set
458
459 SpectralCoordinate spc = getSpectralCoordinate(specidx, whichRow);
460//
461 String s = "Channel";
462 if (u == Unit("km/s")) {
463 s = CoordinateUtil::axisLabel(spc,0,True,True,True);
464 } else if (u == Unit("Hz")) {
465 Vector<String> wau(1);wau = u.getName();
466 spc.setWorldAxisUnits(wau);
467//
468 s = CoordinateUtil::axisLabel(spc,0,True,True,False);
469 }
470 return s;
471}
472
473void SDMemTable::setSpectrum(std::vector<float> spectrum, int whichRow)
474{
475 ArrayColumn<Float> spec(table_, "SPECTRA");
476 Array<Float> arr;
477 spec.get(whichRow, arr);
478 if (spectrum.size() != arr.shape()(3)) {
479 throw(AipsError("Attempting to set spectrum with incorrect length."));
480 }
481
482 ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
483 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
484 ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
485 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
486 ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
487 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
488
489 std::vector<float>::iterator it = spectrum.begin();
490 for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
491 (*i) = Float(*it);
492 it++;
493 }
494 spec.put(whichRow, arr);
495}
496
497void SDMemTable::getSpectrum(Vector<Float>& spectrum, Int whichRow) const
498{
499 ROArrayColumn<Float> spec(table_, "SPECTRA");
500 Array<Float> arr;
501 spec.get(whichRow, arr);
502 spectrum.resize(arr.shape()(3));
503 ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
504 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
505 ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
506 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
507 ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
508 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
509
510 ArrayAccessor<Float, Axis<asap::BeamAxis> > va(spectrum);
511 for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
512 (*va) = (*i);
513 va++;
514 }
515}
516/*
517void SDMemTable::getMask(Vector<Bool>& mask, Int whichRow) const {
518 ROArrayColumn<uChar> spec(table_, "FLAGTRA");
519 Array<uChar> arr;
520 spec.get(whichRow, arr);
521 mask.resize(arr.shape()(3));
522
523 ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
524 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
525 ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0);
526 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
527 ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1);
528 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
529
530 Bool useUserMask = ( chanMask_.size() == arr.shape()(3) );
531
532 ArrayAccessor<Bool, Axis<asap::BeamAxis> > va(mask);
533 std::vector<bool> tmp;
534 tmp = chanMask_; // WHY the fxxx do I have to make a copy here. The
535 // iterator should work on chanMask_??
536 std::vector<bool>::iterator miter;
537 miter = tmp.begin();
538
539 for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
540 bool out =!static_cast<bool>(*i);
541 if (useUserMask) {
542 out = out && (*miter);
543 miter++;
544 }
545 (*va) = out;
546 va++;
547 }
548}
549*/
550MaskedArray<Float> SDMemTable::rowAsMaskedArray(uInt whichRow,
551 Bool useSelection) const
552{
553 ROArrayColumn<Float> spec(table_, "SPECTRA");
554 Array<Float> arr;
555 ROArrayColumn<uChar> flag(table_, "FLAGTRA");
556 Array<uChar> farr;
557 spec.get(whichRow, arr);
558 flag.get(whichRow, farr);
559 Array<Bool> barr(farr.shape());convertArray(barr, farr);
560 MaskedArray<Float> marr;
561 if (useSelection) {
562 ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
563 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
564 ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
565 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
566 ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
567 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
568
569 ArrayAccessor<Bool, Axis<asap::BeamAxis> > baa0(barr);
570 baa0.reset(baa0.begin(uInt(beamSel_)));//go to beam
571 ArrayAccessor<Bool, Axis<asap::IFAxis> > baa1(baa0);
572 baa1.reset(baa1.begin(uInt(IFSel_)));// go to IF
573 ArrayAccessor<Bool, Axis<asap::PolAxis> > baa2(baa1);
574 baa2.reset(baa2.begin(uInt(polSel_)));// go to pol
575
576 Vector<Float> a(arr.shape()(3));
577 Vector<Bool> b(barr.shape()(3));
578 ArrayAccessor<Float, Axis<asap::BeamAxis> > a0(a);
579 ArrayAccessor<Bool, Axis<asap::BeamAxis> > b0(b);
580
581 ArrayAccessor<Bool, Axis<asap::ChanAxis> > j(baa2);
582 for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2);
583 i != i.end(); ++i) {
584 (*a0) = (*i);
585 (*b0) = !(*j);
586 j++;
587 a0++;
588 b0++;
589 }
590 marr.setData(a,b);
591 } else {
592 marr.setData(arr,!barr);
593 }
594 return marr;
595}
596
597Float SDMemTable::getTsys(Int whichRow) const
598{
599 ROArrayColumn<Float> ts(table_, "TSYS");
600 Array<Float> arr;
601 ts.get(whichRow, arr);
602 Float out;
603 IPosition ip(arr.shape());
604 ip(0) = beamSel_;ip(1) = IFSel_;ip(2) = polSel_;ip(3)=0;
605 out = arr(ip);
606 return out;
607}
608
609MDirection SDMemTable::getDirection(Int whichRow, Bool refBeam) const
610{
611 MDirection::Types mdr = getDirectionReference();
612 ROArrayColumn<Double> dir(table_, "DIRECTION");
613 Array<Double> posit;
614 dir.get(whichRow,posit);
615 Vector<Double> wpos(2);
616 wpos[0] = posit(IPosition(2,beamSel_,0));
617 wpos[1] = posit(IPosition(2,beamSel_,1));
618 Quantum<Double> lon(wpos[0],Unit(String("rad")));
619 Quantum<Double> lat(wpos[1],Unit(String("rad")));
620 return MDirection(lon, lat, mdr);
621}
622
623MEpoch SDMemTable::getEpoch (Int whichRow) const
624{
625 MEpoch::Types met = getTimeReference();
626//
627 ROScalarColumn<Double> tme(table_, "TIME");
628 Double obstime;
629 tme.get(whichRow,obstime);
630 MVEpoch tm2(Quantum<Double>(obstime, Unit(String("d"))));
631 return MEpoch(tm2, met);
632}
633
634MPosition SDMemTable::getAntennaPosition () const
635{
636 Vector<Double> antpos;
637 table_.keywordSet().get("AntennaPosition", antpos);
638 MVPosition mvpos(antpos(0),antpos(1),antpos(2));
639 return MPosition(mvpos);
640}
641
642
643SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt whichIdx) const
644{
645
646 Table t = table_.keywordSet().asTable("FREQUENCIES");
647 if (whichIdx > t.nrow() ) {
648 throw(AipsError("SDMemTable::getSpectralCoordinate - whichIdx out of range"));
649 }
650
651 Double rp,rv,inc;
652 String rf;
653 ROScalarColumn<Double> rpc(t, "REFPIX");
654 ROScalarColumn<Double> rvc(t, "REFVAL");
655 ROScalarColumn<Double> incc(t, "INCREMENT");
656 t.keywordSet().get("BASEREFFRAME",rf);
657
658// Create SpectralCoordinate (units Hz)
659
660 MFrequency::Types mft;
661 if (!MFrequency::getType(mft, rf)) {
662 cerr << "Frequency type unknown assuming TOPO" << endl;
663 mft = MFrequency::TOPO;
664 }
665 rpc.get(whichIdx, rp);
666 rvc.get(whichIdx, rv);
667 incc.get(whichIdx, inc);
668//
669 SpectralCoordinate spec(mft,rv,inc,rp);
670//
671 return spec;
672}
673
674
675SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt whichIdx, uInt whichRow) const
676{
677// Create basic SC
678
679 SpectralCoordinate spec = getSpectralCoordinate (whichIdx);
680//
681 Table t = table_.keywordSet().asTable("FREQUENCIES");
682
683// Set rest frequencies
684
685 Vector<Double> vec;
686 t.keywordSet().get("RESTFREQS",vec);
687 if (vec.nelements() > 0) {
688 spec.setRestFrequencies(vec);
689
690// Select rest freq
691
692 if (vec.nelements() >= nIF()) {
693 spec.selectRestFrequency(uInt(IFSel_));
694 }
695 }
696
697// Set up frame conversion layer
698
699 String frm;
700 t.keywordSet().get("REFFRAME",frm);
701 if (frm == "") frm = "TOPO";
702 MFrequency::Types mtype;
703 if (!MFrequency::getType(mtype, frm)) {
704 cout << "Frequency type unknown assuming TOPO" << endl; // SHould never happen
705 mtype = MFrequency::TOPO;
706 }
707
708// Set reference frame conversion (requires row)
709
710 MDirection direct = getDirection(whichRow);
711 MEpoch epoch = getEpoch(whichRow);
712 MPosition pos = getAntennaPosition();
713 if (!spec.setReferenceConversion(mtype,epoch,pos,direct)) {
714 throw(AipsError("Couldn't convert frequency frame."));
715 }
716
717// Now velocity conversion if appropriate
718
719 String unitStr;
720 t.keywordSet().get("UNIT",unitStr);
721//
722 String dpl;
723 t.keywordSet().get("DOPPLER",dpl);
724 MDoppler::Types dtype;
725 MDoppler::getType(dtype, dpl);
726
727// Only set velocity unit if non-blank and non-Hz
728
729 if (!unitStr.empty()) {
730 Unit unitU(unitStr);
731 if (unitU==Unit("Hz")) {
732 } else {
733 spec.setVelocity(unitStr, dtype);
734 }
735 }
736//
737 return spec;
738}
739
740
741Bool SDMemTable::setCoordinate(const SpectralCoordinate& speccord,
742 uInt whichIdx) {
743 Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
744 if (whichIdx > t.nrow() ) {
745 throw(AipsError("SDMemTable::setCoordinate - coord no out of range"));
746 }
747 ScalarColumn<Double> rpc(t, "REFPIX");
748 ScalarColumn<Double> rvc(t, "REFVAL");
749 ScalarColumn<Double> incc(t, "INCREMENT");
750
751 rpc.put(whichIdx, speccord.referencePixel()[0]);
752 rvc.put(whichIdx, speccord.referenceValue()[0]);
753 incc.put(whichIdx, speccord.increment()[0]);
754
755 return True;
756}
757
758Int SDMemTable::nCoordinates() const
759{
760 return table_.keywordSet().asTable("FREQUENCIES").nrow();
761}
762
763void SDMemTable::setRestFreqs(std::vector<double> freqs,
764 const std::string& theunit)
765{
766 Vector<Double> tvec(freqs);
767 Quantum<Vector<Double> > q(tvec, String(theunit));
768 tvec.resize();
769 tvec = q.getValue("Hz");
770 Table t = table_.keywordSet().asTable("FREQUENCIES");
771 t.rwKeywordSet().define("RESTFREQS",tvec);
772}
773
774std::vector<double> SDMemTable::getRestFreqs() const
775{
776 Table t = table_.keywordSet().asTable("FREQUENCIES");
777 Vector<Double> tvec;
778 t.keywordSet().get("RESTFREQS",tvec);
779 std::vector<double> stlout;
780 tvec.tovector(stlout);
781 return stlout;
782}
783
784bool SDMemTable::putSDFreqTable(const SDFrequencyTable& sdft)
785{
786 TableDesc td("", "1", TableDesc::Scratch);
787 td.addColumn(ScalarColumnDesc<Double>("REFPIX"));
788 td.addColumn(ScalarColumnDesc<Double>("REFVAL"));
789 td.addColumn(ScalarColumnDesc<Double>("INCREMENT"));
790 SetupNewTable aNewTab("freqs", td, Table::New);
791 Table aTable (aNewTab, Table::Memory, sdft.length());
792 ScalarColumn<Double> sc0(aTable, "REFPIX");
793 ScalarColumn<Double> sc1(aTable, "REFVAL");
794 ScalarColumn<Double> sc2(aTable, "INCREMENT");
795 for (uInt i=0; i < sdft.length(); ++i) {
796 sc0.put(i,sdft.referencePixel(i));
797 sc1.put(i,sdft.referenceValue(i));
798 sc2.put(i,sdft.increment(i));
799 }
800 String rf = sdft.refFrame();
801 if (rf.contains("TOPO")) rf = "TOPO";
802
803 aTable.rwKeywordSet().define("BASEREFFRAME", rf);
804 aTable.rwKeywordSet().define("REFFRAME", rf);
805 aTable.rwKeywordSet().define("EQUINOX", sdft.equinox());
806 aTable.rwKeywordSet().define("UNIT", String(""));
807 aTable.rwKeywordSet().define("DOPPLER", String("RADIO"));
808 Vector<Double> rfvec;
809 String rfunit;
810 sdft.restFrequencies(rfvec,rfunit);
811 Quantum<Vector<Double> > q(rfvec, rfunit);
812 rfvec.resize();
813 rfvec = q.getValue("Hz");
814 aTable.rwKeywordSet().define("RESTFREQS", rfvec);
815 table_.rwKeywordSet().defineTable ("FREQUENCIES", aTable);
816 return True;
817}
818
819SDFrequencyTable SDMemTable::getSDFreqTable() const
820{
821 // TODO !!!!! implement this properly USE with care
822 const Table& t = table_.keywordSet().asTable("FREQUENCIES");
823 SDFrequencyTable sdft;
824 sdft.setLength(t.nrow());
825 return sdft;
826}
827
828bool SDMemTable::putSDContainer(const SDContainer& sdc)
829{
830 ScalarColumn<Double> mjd(table_, "TIME");
831 ScalarColumn<String> srcn(table_, "SRCNAME");
832 ScalarColumn<String> fldn(table_, "FIELDNAME");
833 ArrayColumn<Float> spec(table_, "SPECTRA");
834 ArrayColumn<uChar> flags(table_, "FLAGTRA");
835 ArrayColumn<Float> ts(table_, "TSYS");
836 ScalarColumn<Int> scan(table_, "SCANID");
837 ScalarColumn<Double> integr(table_, "INTERVAL");
838 ArrayColumn<uInt> freqid(table_, "FREQID");
839 ArrayColumn<Double> dir(table_, "DIRECTION");
840 ScalarColumn<Int> rbeam(table_, "REFBEAM");
841 ArrayColumn<Float> tcal(table_, "TCAL");
842 ScalarColumn<String> tcalt(table_, "TCALTIME");
843 ScalarColumn<Float> az(table_, "AZIMUTH");
844 ScalarColumn<Float> el(table_, "ELEVATION");
845 ScalarColumn<Float> para(table_, "PARANGLE");
846 ArrayColumn<String> hist(table_, "HISTORY");
847
848 uInt rno = table_.nrow();
849 table_.addRow();
850
851 mjd.put(rno, sdc.timestamp);
852 srcn.put(rno, sdc.sourcename);
853 fldn.put(rno, sdc.fieldname);
854 spec.put(rno, sdc.getSpectrum());
855 flags.put(rno, sdc.getFlags());
856 ts.put(rno, sdc.getTsys());
857 scan.put(rno, sdc.scanid);
858 integr.put(rno, sdc.interval);
859 freqid.put(rno, sdc.getFreqMap());
860 dir.put(rno, sdc.getDirection());
861 rbeam.put(rno, sdc.refbeam);
862 tcal.put(rno, sdc.tcal);
863 tcalt.put(rno, sdc.tcaltime);
864 az.put(rno, sdc.azimuth);
865 el.put(rno, sdc.elevation);
866 para.put(rno, sdc.parangle);
867 hist.put(rno, sdc.getHistory());
868
869 return true;
870}
871
872SDContainer SDMemTable::getSDContainer(uInt whichRow) const
873{
874 ROScalarColumn<Double> mjd(table_, "TIME");
875 ROScalarColumn<String> srcn(table_, "SRCNAME");
876 ROScalarColumn<String> fldn(table_, "FIELDNAME");
877 ROArrayColumn<Float> spec(table_, "SPECTRA");
878 ROArrayColumn<uChar> flags(table_, "FLAGTRA");
879 ROArrayColumn<Float> ts(table_, "TSYS");
880 ROScalarColumn<Int> scan(table_, "SCANID");
881 ROScalarColumn<Double> integr(table_, "INTERVAL");
882 ROArrayColumn<uInt> freqid(table_, "FREQID");
883 ROArrayColumn<Double> dir(table_, "DIRECTION");
884 ROScalarColumn<Int> rbeam(table_, "REFBEAM");
885 ROArrayColumn<Float> tcal(table_, "TCAL");
886 ROScalarColumn<String> tcalt(table_, "TCALTIME");
887 ROScalarColumn<Float> az(table_, "AZIMUTH");
888 ROScalarColumn<Float> el(table_, "ELEVATION");
889 ROScalarColumn<Float> para(table_, "PARANGLE");
890 ROArrayColumn<String> hist(table_, "HISTORY");
891
892 SDContainer sdc(nBeam(),nIF(),nPol(),nChan());
893 mjd.get(whichRow, sdc.timestamp);
894 srcn.get(whichRow, sdc.sourcename);
895 integr.get(whichRow, sdc.interval);
896 scan.get(whichRow, sdc.scanid);
897 fldn.get(whichRow, sdc.fieldname);
898 rbeam.get(whichRow, sdc.refbeam);
899 az.get(whichRow, sdc.azimuth);
900 el.get(whichRow, sdc.elevation);
901 para.get(whichRow, sdc.parangle);
902 Vector<Float> tc;
903 tcal.get(whichRow, tc);
904 sdc.tcal[0] = tc[0];sdc.tcal[1] = tc[1];
905 tcalt.get(whichRow, sdc.tcaltime);
906 Array<Float> spectrum;
907 Array<Float> tsys;
908 Array<uChar> flagtrum;
909 Vector<uInt> fmap;
910 Array<Double> direction;
911 Vector<String> histo;
912 spec.get(whichRow, spectrum);
913 sdc.putSpectrum(spectrum);
914 flags.get(whichRow, flagtrum);
915 sdc.putFlags(flagtrum);
916 ts.get(whichRow, tsys);
917 sdc.putTsys(tsys);
918 freqid.get(whichRow, fmap);
919 sdc.putFreqMap(fmap);
920 dir.get(whichRow, direction);
921 sdc.putDirection(direction);
922 hist.get(whichRow, histo);
923 sdc.putHistory(histo);
924 return sdc;
925}
926
927bool SDMemTable::putSDHeader(const SDHeader& sdh)
928{
929 table_.rwKeywordSet().define("nIF", sdh.nif);
930 table_.rwKeywordSet().define("nBeam", sdh.nbeam);
931 table_.rwKeywordSet().define("nPol", sdh.npol);
932 table_.rwKeywordSet().define("nChan", sdh.nchan);
933 table_.rwKeywordSet().define("Observer", sdh.observer);
934 table_.rwKeywordSet().define("Project", sdh.project);
935 table_.rwKeywordSet().define("Obstype", sdh.obstype);
936 table_.rwKeywordSet().define("AntennaName", sdh.antennaname);
937 table_.rwKeywordSet().define("AntennaPosition", sdh.antennaposition);
938 table_.rwKeywordSet().define("Equinox", sdh.equinox);
939 table_.rwKeywordSet().define("FreqRefFrame", sdh.freqref);
940 table_.rwKeywordSet().define("FreqRefVal", sdh.reffreq);
941 table_.rwKeywordSet().define("Bandwidth", sdh.bandwidth);
942 table_.rwKeywordSet().define("UTC", sdh.utc);
943 table_.rwKeywordSet().define("FluxUnit", sdh.fluxunit);
944 table_.rwKeywordSet().define("Epoch", sdh.epoch);
945 return true;
946}
947
948SDHeader SDMemTable::getSDHeader() const
949{
950 SDHeader sdh;
951 table_.keywordSet().get("nBeam",sdh.nbeam);
952 table_.keywordSet().get("nIF",sdh.nif);
953 table_.keywordSet().get("nPol",sdh.npol);
954 table_.keywordSet().get("nChan",sdh.nchan);
955 table_.keywordSet().get("Observer", sdh.observer);
956 table_.keywordSet().get("Project", sdh.project);
957 table_.keywordSet().get("Obstype", sdh.obstype);
958 table_.keywordSet().get("AntennaName", sdh.antennaname);
959 table_.keywordSet().get("AntennaPosition", sdh.antennaposition);
960 table_.keywordSet().get("Equinox", sdh.equinox);
961 table_.keywordSet().get("FreqRefFrame", sdh.freqref);
962 table_.keywordSet().get("FreqRefVal", sdh.reffreq);
963 table_.keywordSet().get("Bandwidth", sdh.bandwidth);
964 table_.keywordSet().get("UTC", sdh.utc);
965 table_.keywordSet().get("FluxUnit", sdh.fluxunit);
966 table_.keywordSet().get("Epoch", sdh.epoch);
967 return sdh;
968}
969void SDMemTable::makePersistent(const std::string& filename)
970{
971 table_.deepCopy(filename,Table::New);
972}
973
974Int SDMemTable::nScan() const {
975 Int n = 0;
976 ROScalarColumn<Int> scans(table_, "SCANID");
977 Int previous = -1;Int current=0;
978 for (uInt i=0; i< scans.nrow();i++) {
979 scans.getScalar(i,current);
980 if (previous != current) {
981 previous = current;
982 n++;
983 }
984 }
985 return n;
986}
987
988String SDMemTable::formatSec(Double x) const
989{
990 Double xcop = x;
991 MVTime mvt(xcop/24./3600.); // make days
992
993 if (x < 59.95)
994 return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_HM, 7)+"s";
995 else if (x < 3599.95)
996 return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_H,7)+" ";
997 else {
998 ostringstream oss;
999 oss << setw(2) << std::right << setprecision(1) << mvt.hour();
1000 oss << ":" << mvt.string(MVTime::TIME_CLEAN_NO_H,7) << " ";
1001 return String(oss);
1002 }
1003};
1004
1005String SDMemTable::formatDirection(const MDirection& md) const
1006{
1007 Vector<Double> t = md.getAngle(Unit(String("rad"))).getValue();
1008 Int prec = 7;
1009
1010 MVAngle mvLon(t[0]);
1011 String sLon = mvLon.string(MVAngle::TIME,prec);
1012 MVAngle mvLat(t[1]);
1013 String sLat = mvLat.string(MVAngle::ANGLE+MVAngle::DIG2,prec);
1014
1015 return sLon + String(" ") + sLat;
1016}
1017
1018
1019std::string SDMemTable::getFluxUnit() const
1020{
1021 String tmp;
1022 table_.keywordSet().get("FluxUnit", tmp);
1023 return tmp;
1024}
1025
1026void SDMemTable::setFluxUnit(const std::string& unit)
1027{
1028 String tmp(unit);
1029 Unit tU(tmp);
1030 if (tU==Unit("K") || tU==Unit("Jy")) {
1031 table_.rwKeywordSet().define(String("FluxUnit"), tmp);
1032 } else {
1033 throw AipsError("Illegal unit - must be compatible with Jy or K");
1034 }
1035}
1036
1037
1038void SDMemTable::setInstrument(const std::string& name)
1039{
1040 Bool throwIt = True;
1041 Instrument ins = convertInstrument (name, throwIt);
1042 String nameU(name);
1043 nameU.upcase();
1044 table_.rwKeywordSet().define(String("AntennaName"), nameU);
1045}
1046
1047std::string SDMemTable::summary() const {
1048 ROScalarColumn<Int> scans(table_, "SCANID");
1049 ROScalarColumn<String> srcs(table_, "SRCNAME");
1050
1051 // get number of integrations per scan
1052 int cIdx = 0;
1053 int idx = 0;
1054 int scount = 0;
1055 std::vector<int> cycles;
1056 for (uInt i=0; i<scans.nrow();++i) {
1057 while (idx == cIdx && i<scans.nrow()) {
1058 scans.getScalar(++i,cIdx);
1059 ++scount;
1060 }
1061 idx = cIdx;
1062 cycles.push_back(scount);
1063 scount=0;
1064 --i;
1065 }
1066
1067
1068 ostringstream oss;
1069 oss << endl;
1070 oss << "--------------------------------------------------" << endl;
1071 oss << " Scan Table Summary" << endl;
1072 oss << "--------------------------------------------------" << endl;
1073 oss.flags(std::ios_base::left);
1074 oss << setw(15) << "Beams:" << setw(4) << nBeam() << endl
1075 << setw(15) << "IFs:" << setw(4) << nIF() << endl
1076 << setw(15) << "Polarisations:" << setw(4) << nPol() << endl
1077 << setw(15) << "Channels:" << setw(4) << nChan() << endl;
1078 oss << endl;
1079 String tmp;
1080 table_.keywordSet().get("Observer", tmp);
1081 oss << setw(15) << "Observer:" << tmp << endl;
1082 oss << setw(15) << "Obs Date:" << getTime(-1,True) << endl;
1083 table_.keywordSet().get("Project", tmp);
1084 oss << setw(15) << "Project:" << tmp << endl;
1085 table_.keywordSet().get("Obstype", tmp);
1086 oss << setw(15) << "Obs. Type:" << tmp << endl;
1087 table_.keywordSet().get("AntennaName", tmp);
1088 oss << setw(15) << "Antenna Name:" << tmp << endl;
1089 table_.keywordSet().get("FluxUnit", tmp);
1090 oss << setw(15) << "Flux Unit:" << tmp << endl;
1091 Table t = table_.keywordSet().asTable("FREQUENCIES");
1092 Vector<Double> vec;
1093 t.keywordSet().get("RESTFREQS",vec);
1094 oss << setw(15) << "Rest Freqs:";
1095 if (vec.nelements() > 0) {
1096 oss << setprecision(0) << vec << " [Hz]" << endl;
1097 } else {
1098 oss << "None set" << endl;
1099 }
1100 oss << setw(15) << "Abcissa:" << getAbcissaString() << endl;
1101 oss << setw(15) << "Cursor:" << "Beam[" << getBeam() << "] "
1102 << "IF[" << getIF() << "] " << "Pol[" << getPol() << "]" << endl;
1103 oss << endl;
1104 uInt count = 0;
1105 String name;
1106 Int previous = -1;Int current=0;
1107 Int integ = 0;
1108 String dirtype ="Position ("+
1109 MDirection::showType(getDirectionReference())+
1110 ")";
1111 oss << setw(6) << "Scan"
1112 << setw(15) << "Source"
1113 << setw(26) << dirtype
1114 << setw(10) << "Time"
1115 << setw(13) << "Integration" << endl;
1116 oss << "-------------------------------------------------------------------------------" << endl;
1117
1118 std::vector<int>::iterator it = cycles.begin();
1119 for (uInt i=0; i< scans.nrow();i++) {
1120 scans.getScalar(i,current);
1121 if (previous != current) {
1122 srcs.getScalar(i,name);
1123 previous = current;
1124 String t = formatSec(Double(getInterval(i)));
1125 String posit = formatDirection(getDirection(i,True));
1126 oss << setw(6) << count
1127 << setw(15) << name
1128 << setw(26) << posit
1129 << setw(10) << getTime(i,False)
1130 << setw(3) << std::right << *it << " x "
1131 << setw(10)
1132 << t << std::left << endl;
1133 count++;
1134 it++;
1135 } else {
1136 integ++;
1137 }
1138 }
1139 oss << endl;
1140 oss << "Table contains " << table_.nrow() << " integration(s)." << endl;
1141 oss << "in " << count << " scan(s)." << endl;
1142 oss << "-------------------------------------------------------------------------------";
1143 return String(oss);
1144}
1145
1146Int SDMemTable::nBeam() const
1147{
1148 Int n;
1149 table_.keywordSet().get("nBeam",n);
1150 return n;
1151}
1152Int SDMemTable::nIF() const {
1153 Int n;
1154 table_.keywordSet().get("nIF",n);
1155 return n;
1156}
1157Int SDMemTable::nPol() const {
1158 Int n;
1159 table_.keywordSet().get("nPol",n);
1160 return n;
1161}
1162Int SDMemTable::nChan() const {
1163 Int n;
1164 table_.keywordSet().get("nChan",n);
1165 return n;
1166}
1167bool SDMemTable::appendHistory(const std::string& hist, int whichRow)
1168{
1169 ArrayColumn<String> histo(table_, "HISTORY");
1170 Vector<String> history;
1171 histo.get(whichRow, history);
1172 history.resize(history.nelements()+1,True);
1173 history[history.nelements()-1] = hist;
1174 histo.put(whichRow, history);
1175}
1176
1177std::vector<std::string> SDMemTable::history(int whichRow) const
1178{
1179 ROArrayColumn<String> hist(table_, "HISTORY");
1180 Vector<String> history;
1181 hist.get(whichRow, history);
1182 std::vector<std::string> stlout;
1183 // there is no Array<String>.tovector(std::vector<std::string>), so
1184 // do it by hand
1185 for (uInt i=0; i<history.nelements(); ++i) {
1186 stlout.push_back(history[i]);
1187 }
1188 return stlout;
1189}
1190/*
1191void SDMemTable::maskChannels(const std::vector<Int>& whichChans ) {
1192
1193 std::vector<int>::iterator it;
1194 ArrayAccessor<uChar, Axis<asap::PolAxis> > j(flags_);
1195 for (it = whichChans.begin(); it != whichChans.end(); it++) {
1196 j.reset(j.begin(uInt(*it)));
1197 for (ArrayAccessor<uChar, Axis<asap::BeamAxis> > i(j); i != i.end(); ++i) {
1198 for (ArrayAccessor<uChar, Axis<asap::IFAxis> > ii(i); ii != ii.end(); ++ii) {
1199 for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > iii(ii);
1200 iii != iii.end(); ++iii) {
1201 (*iii) =
1202 }
1203 }
1204 }
1205 }
1206
1207}
1208*/
1209void SDMemTable::flag(int whichRow)
1210{
1211 ArrayColumn<uChar> spec(table_, "FLAGTRA");
1212 Array<uChar> arr;
1213 spec.get(whichRow, arr);
1214
1215 ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
1216 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
1217 ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0);
1218 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
1219 ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1);
1220 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
1221
1222 for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
1223 (*i) = uChar(True);
1224 }
1225
1226 spec.put(whichRow, arr);
1227}
1228
1229MDirection::Types SDMemTable::getDirectionReference() const
1230{
1231 Float eq;
1232 table_.keywordSet().get("Equinox",eq);
1233 std::map<float,string> mp;
1234 mp[2000.0] = "J2000";
1235 mp[1950.0] = "B1950";
1236 MDirection::Types mdr;
1237 if (!MDirection::getType(mdr, mp[eq])) {
1238 mdr = MDirection::J2000;
1239 cerr << "Unknown equinox using J2000" << endl;
1240 }
1241//
1242 return mdr;
1243}
1244
1245MEpoch::Types SDMemTable::getTimeReference () const
1246{
1247 MEpoch::Types met;
1248 String ep;
1249 table_.keywordSet().get("Epoch",ep);
1250 if (!MEpoch::getType(met, ep)) {
1251 cerr << "Epoch type uknown - using UTC" << endl;
1252 met = MEpoch::UTC;
1253 }
1254//
1255 return met;
1256}
1257
1258
1259Instrument SDMemTable::convertInstrument (const String& instrument,
1260 Bool throwIt)
1261{
1262 String t(instrument);
1263 t.upcase();
1264
1265// The strings are what SDReader returns, after cunning interrogation
1266// of station names... :-(
1267
1268 Instrument inst = asap::UNKNOWN;
1269 if (t==String("DSS-43")) {
1270 inst = TIDBINBILLA;
1271 } else if (t==String("ATPKSMB")) {
1272 inst = ATPKSMB;
1273 } else if (t==String("ATPKSHOH")) {
1274 inst = ATPKSHOH;
1275 } else if (t==String("ATMOPRA")) {
1276 inst = ATMOPRA;
1277 } else if (t==String("CEDUNA")) {
1278 inst = CEDUNA;
1279 } else if (t==String("HOBART")) {
1280 inst = HOBART;
1281 } else {
1282 if (throwIt) {
1283 throw AipsError("Unrecognized instrument - use function scan.set_instrument to set");
1284 }
1285 }
1286 return inst;
1287}
1288
Note: See TracBrowser for help on using the repository browser.