source: trunk/src/Scantable.cpp@ 1929

Last change on this file since 1929 was 1929, checked in by Takeshi Nakazato, 15 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: s=sd.scantable('sddata()

s.nbeam(999) # unexisting scan number
s.ncycle(999)
s.nif(999)
s.npol(999)

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Fixed a bug in nbeam, ncycle, nif, and npol that causes seg fault.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 55.6 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#include <fstream>
14
15#include <casa/aips.h>
16#include <casa/iostream.h>
17#include <casa/iomanip.h>
18#include <casa/OS/Path.h>
19#include <casa/OS/File.h>
20#include <casa/Arrays/Array.h>
21#include <casa/Arrays/ArrayMath.h>
22#include <casa/Arrays/MaskArrMath.h>
23#include <casa/Arrays/ArrayLogical.h>
24#include <casa/Arrays/ArrayAccessor.h>
25#include <casa/Arrays/Vector.h>
26#include <casa/Arrays/VectorSTLIterator.h>
27#include <casa/Arrays/Slice.h>
28#include <casa/BasicMath/Math.h>
29#include <casa/BasicSL/Constants.h>
30#include <casa/Quanta/MVAngle.h>
31#include <casa/Containers/RecordField.h>
32#include <casa/Utilities/GenSort.h>
33#include <casa/Logging/LogIO.h>
34
35#include <tables/Tables/TableParse.h>
36#include <tables/Tables/TableDesc.h>
37#include <tables/Tables/TableCopy.h>
38#include <tables/Tables/SetupNewTab.h>
39#include <tables/Tables/ScaColDesc.h>
40#include <tables/Tables/ArrColDesc.h>
41#include <tables/Tables/TableRow.h>
42#include <tables/Tables/TableVector.h>
43#include <tables/Tables/TableIter.h>
44
45#include <tables/Tables/ExprNode.h>
46#include <tables/Tables/TableRecord.h>
47#include <casa/Quanta/MVTime.h>
48#include <casa/Quanta/MVAngle.h>
49#include <measures/Measures/MeasRef.h>
50#include <measures/Measures/MeasTable.h>
51// needed to avoid error in .tcc
52#include <measures/Measures/MCDirection.h>
53//
54#include <measures/Measures/MDirection.h>
55#include <measures/Measures/MFrequency.h>
56#include <measures/Measures/MEpoch.h>
57#include <measures/TableMeasures/TableMeasRefDesc.h>
58#include <measures/TableMeasures/TableMeasValueDesc.h>
59#include <measures/TableMeasures/TableMeasDesc.h>
60#include <measures/TableMeasures/ScalarMeasColumn.h>
61#include <coordinates/Coordinates/CoordinateUtil.h>
62
63#include "Scantable.h"
64#include "STPolLinear.h"
65#include "STPolCircular.h"
66#include "STPolStokes.h"
67#include "STAttr.h"
68#include "MathUtils.h"
69
70using namespace casa;
71
72namespace asap {
73
74std::map<std::string, STPol::STPolFactory *> Scantable::factories_;
75
76void Scantable::initFactories() {
77 if ( factories_.empty() ) {
78 Scantable::factories_["linear"] = &STPolLinear::myFactory;
79 Scantable::factories_["circular"] = &STPolCircular::myFactory;
80 Scantable::factories_["stokes"] = &STPolStokes::myFactory;
81 }
82}
83
84Scantable::Scantable(Table::TableType ttype) :
85 type_(ttype)
86{
87 initFactories();
88 setupMainTable();
89 freqTable_ = STFrequencies(*this);
90 table_.rwKeywordSet().defineTable("FREQUENCIES", freqTable_.table());
91 weatherTable_ = STWeather(*this);
92 table_.rwKeywordSet().defineTable("WEATHER", weatherTable_.table());
93 focusTable_ = STFocus(*this);
94 table_.rwKeywordSet().defineTable("FOCUS", focusTable_.table());
95 tcalTable_ = STTcal(*this);
96 table_.rwKeywordSet().defineTable("TCAL", tcalTable_.table());
97 moleculeTable_ = STMolecules(*this);
98 table_.rwKeywordSet().defineTable("MOLECULES", moleculeTable_.table());
99 historyTable_ = STHistory(*this);
100 table_.rwKeywordSet().defineTable("HISTORY", historyTable_.table());
101 fitTable_ = STFit(*this);
102 table_.rwKeywordSet().defineTable("FIT", fitTable_.table());
103 table_.tableInfo().setType( "Scantable" ) ;
104 originalTable_ = table_;
105 attach();
106}
107
108Scantable::Scantable(const std::string& name, Table::TableType ttype) :
109 type_(ttype)
110{
111 initFactories();
112
113 Table tab(name, Table::Update);
114 uInt version = tab.keywordSet().asuInt("VERSION");
115 if (version != version_) {
116 throw(AipsError("Unsupported version of ASAP file."));
117 }
118 if ( type_ == Table::Memory ) {
119 table_ = tab.copyToMemoryTable(generateName());
120 } else {
121 table_ = tab;
122 }
123 table_.tableInfo().setType( "Scantable" ) ;
124
125 attachSubtables();
126 originalTable_ = table_;
127 attach();
128}
129/*
130Scantable::Scantable(const std::string& name, Table::TableType ttype) :
131 type_(ttype)
132{
133 initFactories();
134 Table tab(name, Table::Update);
135 uInt version = tab.keywordSet().asuInt("VERSION");
136 if (version != version_) {
137 throw(AipsError("Unsupported version of ASAP file."));
138 }
139 if ( type_ == Table::Memory ) {
140 table_ = tab.copyToMemoryTable(generateName());
141 } else {
142 table_ = tab;
143 }
144
145 attachSubtables();
146 originalTable_ = table_;
147 attach();
148}
149*/
150
151Scantable::Scantable( const Scantable& other, bool clear )
152{
153 // with or without data
154 String newname = String(generateName());
155 type_ = other.table_.tableType();
156 if ( other.table_.tableType() == Table::Memory ) {
157 if ( clear ) {
158 table_ = TableCopy::makeEmptyMemoryTable(newname,
159 other.table_, True);
160 } else
161 table_ = other.table_.copyToMemoryTable(newname);
162 } else {
163 other.table_.deepCopy(newname, Table::New, False,
164 other.table_.endianFormat(),
165 Bool(clear));
166 table_ = Table(newname, Table::Update);
167 table_.markForDelete();
168 }
169 table_.tableInfo().setType( "Scantable" ) ;
170 /// @todo reindex SCANNO, recompute nbeam, nif, npol
171 if ( clear ) copySubtables(other);
172 attachSubtables();
173 originalTable_ = table_;
174 attach();
175}
176
177void Scantable::copySubtables(const Scantable& other) {
178 Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
179 TableCopy::copyRows(t, other.freqTable_.table());
180 t = table_.rwKeywordSet().asTable("FOCUS");
181 TableCopy::copyRows(t, other.focusTable_.table());
182 t = table_.rwKeywordSet().asTable("WEATHER");
183 TableCopy::copyRows(t, other.weatherTable_.table());
184 t = table_.rwKeywordSet().asTable("TCAL");
185 TableCopy::copyRows(t, other.tcalTable_.table());
186 t = table_.rwKeywordSet().asTable("MOLECULES");
187 TableCopy::copyRows(t, other.moleculeTable_.table());
188 t = table_.rwKeywordSet().asTable("HISTORY");
189 TableCopy::copyRows(t, other.historyTable_.table());
190 t = table_.rwKeywordSet().asTable("FIT");
191 TableCopy::copyRows(t, other.fitTable_.table());
192}
193
194void Scantable::attachSubtables()
195{
196 freqTable_ = STFrequencies(table_);
197 focusTable_ = STFocus(table_);
198 weatherTable_ = STWeather(table_);
199 tcalTable_ = STTcal(table_);
200 moleculeTable_ = STMolecules(table_);
201 historyTable_ = STHistory(table_);
202 fitTable_ = STFit(table_);
203}
204
205Scantable::~Scantable()
206{
207 //cout << "~Scantable() " << this << endl;
208}
209
210void Scantable::setupMainTable()
211{
212 TableDesc td("", "1", TableDesc::Scratch);
213 td.comment() = "An ASAP Scantable";
214 td.rwKeywordSet().define("VERSION", uInt(version_));
215
216 // n Cycles
217 td.addColumn(ScalarColumnDesc<uInt>("SCANNO"));
218 // new index every nBeam x nIF x nPol
219 td.addColumn(ScalarColumnDesc<uInt>("CYCLENO"));
220
221 td.addColumn(ScalarColumnDesc<uInt>("BEAMNO"));
222 td.addColumn(ScalarColumnDesc<uInt>("IFNO"));
223 // linear, circular, stokes
224 td.rwKeywordSet().define("POLTYPE", String("linear"));
225 td.addColumn(ScalarColumnDesc<uInt>("POLNO"));
226
227 td.addColumn(ScalarColumnDesc<uInt>("FREQ_ID"));
228 td.addColumn(ScalarColumnDesc<uInt>("MOLECULE_ID"));
229
230 ScalarColumnDesc<Int> refbeamnoColumn("REFBEAMNO");
231 refbeamnoColumn.setDefault(Int(-1));
232 td.addColumn(refbeamnoColumn);
233
234 ScalarColumnDesc<uInt> flagrowColumn("FLAGROW");
235 flagrowColumn.setDefault(uInt(0));
236 td.addColumn(flagrowColumn);
237
238 td.addColumn(ScalarColumnDesc<Double>("TIME"));
239 TableMeasRefDesc measRef(MEpoch::UTC); // UTC as default
240 TableMeasValueDesc measVal(td, "TIME");
241 TableMeasDesc<MEpoch> mepochCol(measVal, measRef);
242 mepochCol.write(td);
243
244 td.addColumn(ScalarColumnDesc<Double>("INTERVAL"));
245
246 td.addColumn(ScalarColumnDesc<String>("SRCNAME"));
247 // Type of source (on=0, off=1, other=-1)
248 ScalarColumnDesc<Int> stypeColumn("SRCTYPE");
249 stypeColumn.setDefault(Int(-1));
250 td.addColumn(stypeColumn);
251 td.addColumn(ScalarColumnDesc<String>("FIELDNAME"));
252
253 //The actual Data Vectors
254 td.addColumn(ArrayColumnDesc<Float>("SPECTRA"));
255 td.addColumn(ArrayColumnDesc<uChar>("FLAGTRA"));
256 td.addColumn(ArrayColumnDesc<Float>("TSYS"));
257
258 td.addColumn(ArrayColumnDesc<Double>("DIRECTION",
259 IPosition(1,2),
260 ColumnDesc::Direct));
261 TableMeasRefDesc mdirRef(MDirection::J2000); // default
262 TableMeasValueDesc tmvdMDir(td, "DIRECTION");
263 // the TableMeasDesc gives the column a type
264 TableMeasDesc<MDirection> mdirCol(tmvdMDir, mdirRef);
265 // a uder set table type e.g. GALCTIC, B1950 ...
266 td.rwKeywordSet().define("DIRECTIONREF", String("J2000"));
267 // writing create the measure column
268 mdirCol.write(td);
269 td.addColumn(ScalarColumnDesc<Float>("AZIMUTH"));
270 td.addColumn(ScalarColumnDesc<Float>("ELEVATION"));
271 td.addColumn(ScalarColumnDesc<Float>("OPACITY"));
272
273 td.addColumn(ScalarColumnDesc<uInt>("TCAL_ID"));
274 ScalarColumnDesc<Int> fitColumn("FIT_ID");
275 fitColumn.setDefault(Int(-1));
276 td.addColumn(fitColumn);
277
278 td.addColumn(ScalarColumnDesc<uInt>("FOCUS_ID"));
279 td.addColumn(ScalarColumnDesc<uInt>("WEATHER_ID"));
280
281 // columns which just get dragged along, as they aren't used in asap
282 td.addColumn(ScalarColumnDesc<Double>("SRCVELOCITY"));
283 td.addColumn(ArrayColumnDesc<Double>("SRCPROPERMOTION"));
284 td.addColumn(ArrayColumnDesc<Double>("SRCDIRECTION"));
285 td.addColumn(ArrayColumnDesc<Double>("SCANRATE"));
286
287 td.rwKeywordSet().define("OBSMODE", String(""));
288
289 // Now create Table SetUp from the description.
290 SetupNewTable aNewTab(generateName(), td, Table::Scratch);
291 table_ = Table(aNewTab, type_, 0);
292 originalTable_ = table_;
293}
294
295void Scantable::attach()
296{
297 timeCol_.attach(table_, "TIME");
298 srcnCol_.attach(table_, "SRCNAME");
299 srctCol_.attach(table_, "SRCTYPE");
300 specCol_.attach(table_, "SPECTRA");
301 flagsCol_.attach(table_, "FLAGTRA");
302 tsysCol_.attach(table_, "TSYS");
303 cycleCol_.attach(table_,"CYCLENO");
304 scanCol_.attach(table_, "SCANNO");
305 beamCol_.attach(table_, "BEAMNO");
306 ifCol_.attach(table_, "IFNO");
307 polCol_.attach(table_, "POLNO");
308 integrCol_.attach(table_, "INTERVAL");
309 azCol_.attach(table_, "AZIMUTH");
310 elCol_.attach(table_, "ELEVATION");
311 dirCol_.attach(table_, "DIRECTION");
312 fldnCol_.attach(table_, "FIELDNAME");
313 rbeamCol_.attach(table_, "REFBEAMNO");
314
315 mweatheridCol_.attach(table_,"WEATHER_ID");
316 mfitidCol_.attach(table_,"FIT_ID");
317 mfreqidCol_.attach(table_, "FREQ_ID");
318 mtcalidCol_.attach(table_, "TCAL_ID");
319 mfocusidCol_.attach(table_, "FOCUS_ID");
320 mmolidCol_.attach(table_, "MOLECULE_ID");
321
322 //Add auxiliary column for row-based flagging (CAS-1433 Wataru Kawasaki)
323 attachAuxColumnDef(flagrowCol_, "FLAGROW", 0);
324
325}
326
327template<class T, class T2>
328void Scantable::attachAuxColumnDef(ScalarColumn<T>& col,
329 const String& colName,
330 const T2& defValue)
331{
332 try {
333 col.attach(table_, colName);
334 } catch (TableError& err) {
335 String errMesg = err.getMesg();
336 if (errMesg == "Table column " + colName + " is unknown") {
337 table_.addColumn(ScalarColumnDesc<T>(colName));
338 col.attach(table_, colName);
339 col.fillColumn(static_cast<T>(defValue));
340 } else {
341 throw;
342 }
343 } catch (...) {
344 throw;
345 }
346}
347
348template<class T, class T2>
349void Scantable::attachAuxColumnDef(ArrayColumn<T>& col,
350 const String& colName,
351 const Array<T2>& defValue)
352{
353 try {
354 col.attach(table_, colName);
355 } catch (TableError& err) {
356 String errMesg = err.getMesg();
357 if (errMesg == "Table column " + colName + " is unknown") {
358 table_.addColumn(ArrayColumnDesc<T>(colName));
359 col.attach(table_, colName);
360
361 int size = 0;
362 ArrayIterator<T2>& it = defValue.begin();
363 while (it != defValue.end()) {
364 ++size;
365 ++it;
366 }
367 IPosition ip(1, size);
368 Array<T>& arr(ip);
369 for (int i = 0; i < size; ++i)
370 arr[i] = static_cast<T>(defValue[i]);
371
372 col.fillColumn(arr);
373 } else {
374 throw;
375 }
376 } catch (...) {
377 throw;
378 }
379}
380
381void Scantable::setHeader(const STHeader& sdh)
382{
383 table_.rwKeywordSet().define("nIF", sdh.nif);
384 table_.rwKeywordSet().define("nBeam", sdh.nbeam);
385 table_.rwKeywordSet().define("nPol", sdh.npol);
386 table_.rwKeywordSet().define("nChan", sdh.nchan);
387 table_.rwKeywordSet().define("Observer", sdh.observer);
388 table_.rwKeywordSet().define("Project", sdh.project);
389 table_.rwKeywordSet().define("Obstype", sdh.obstype);
390 table_.rwKeywordSet().define("AntennaName", sdh.antennaname);
391 table_.rwKeywordSet().define("AntennaPosition", sdh.antennaposition);
392 table_.rwKeywordSet().define("Equinox", sdh.equinox);
393 table_.rwKeywordSet().define("FreqRefFrame", sdh.freqref);
394 table_.rwKeywordSet().define("FreqRefVal", sdh.reffreq);
395 table_.rwKeywordSet().define("Bandwidth", sdh.bandwidth);
396 table_.rwKeywordSet().define("UTC", sdh.utc);
397 table_.rwKeywordSet().define("FluxUnit", sdh.fluxunit);
398 table_.rwKeywordSet().define("Epoch", sdh.epoch);
399 table_.rwKeywordSet().define("POLTYPE", sdh.poltype);
400}
401
402STHeader Scantable::getHeader() const
403{
404 STHeader sdh;
405 table_.keywordSet().get("nBeam",sdh.nbeam);
406 table_.keywordSet().get("nIF",sdh.nif);
407 table_.keywordSet().get("nPol",sdh.npol);
408 table_.keywordSet().get("nChan",sdh.nchan);
409 table_.keywordSet().get("Observer", sdh.observer);
410 table_.keywordSet().get("Project", sdh.project);
411 table_.keywordSet().get("Obstype", sdh.obstype);
412 table_.keywordSet().get("AntennaName", sdh.antennaname);
413 table_.keywordSet().get("AntennaPosition", sdh.antennaposition);
414 table_.keywordSet().get("Equinox", sdh.equinox);
415 table_.keywordSet().get("FreqRefFrame", sdh.freqref);
416 table_.keywordSet().get("FreqRefVal", sdh.reffreq);
417 table_.keywordSet().get("Bandwidth", sdh.bandwidth);
418 table_.keywordSet().get("UTC", sdh.utc);
419 table_.keywordSet().get("FluxUnit", sdh.fluxunit);
420 table_.keywordSet().get("Epoch", sdh.epoch);
421 table_.keywordSet().get("POLTYPE", sdh.poltype);
422 return sdh;
423}
424
425void Scantable::setSourceType( int stype )
426{
427 if ( stype < 0 || stype > 1 )
428 throw(AipsError("Illegal sourcetype."));
429 TableVector<Int> tabvec(table_, "SRCTYPE");
430 tabvec = Int(stype);
431}
432
433bool Scantable::conformant( const Scantable& other )
434{
435 return this->getHeader().conformant(other.getHeader());
436}
437
438
439
440std::string Scantable::formatSec(Double x) const
441{
442 Double xcop = x;
443 MVTime mvt(xcop/24./3600.); // make days
444
445 if (x < 59.95)
446 return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_HM, 7)+"s";
447 else if (x < 3599.95)
448 return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_H,7)+" ";
449 else {
450 ostringstream oss;
451 oss << setw(2) << std::right << setprecision(1) << mvt.hour();
452 oss << ":" << mvt.string(MVTime::TIME_CLEAN_NO_H,7) << " ";
453 return String(oss);
454 }
455};
456
457std::string Scantable::formatDirection(const MDirection& md) const
458{
459 Vector<Double> t = md.getAngle(Unit(String("rad"))).getValue();
460 Int prec = 7;
461
462 MVAngle mvLon(t[0]);
463 String sLon = mvLon.string(MVAngle::TIME,prec);
464 uInt tp = md.getRef().getType();
465 if (tp == MDirection::GALACTIC ||
466 tp == MDirection::SUPERGAL ) {
467 sLon = mvLon(0.0).string(MVAngle::ANGLE_CLEAN,prec);
468 }
469 MVAngle mvLat(t[1]);
470 String sLat = mvLat.string(MVAngle::ANGLE+MVAngle::DIG2,prec);
471 return sLon + String(" ") + sLat;
472}
473
474
475std::string Scantable::getFluxUnit() const
476{
477 return table_.keywordSet().asString("FluxUnit");
478}
479
480void Scantable::setFluxUnit(const std::string& unit)
481{
482 String tmp(unit);
483 Unit tU(tmp);
484 if (tU==Unit("K") || tU==Unit("Jy")) {
485 table_.rwKeywordSet().define(String("FluxUnit"), tmp);
486 } else {
487 throw AipsError("Illegal unit - must be compatible with Jy or K");
488 }
489}
490
491void Scantable::setInstrument(const std::string& name)
492{
493 bool throwIt = true;
494 // create an Instrument to see if this is valid
495 STAttr::convertInstrument(name, throwIt);
496 String nameU(name);
497 nameU.upcase();
498 table_.rwKeywordSet().define(String("AntennaName"), nameU);
499}
500
501void Scantable::setFeedType(const std::string& feedtype)
502{
503 if ( Scantable::factories_.find(feedtype) == Scantable::factories_.end() ) {
504 std::string msg = "Illegal feed type "+ feedtype;
505 throw(casa::AipsError(msg));
506 }
507 table_.rwKeywordSet().define(String("POLTYPE"), feedtype);
508}
509
510MPosition Scantable::getAntennaPosition() const
511{
512 Vector<Double> antpos;
513 table_.keywordSet().get("AntennaPosition", antpos);
514 MVPosition mvpos(antpos(0),antpos(1),antpos(2));
515 return MPosition(mvpos);
516}
517
518void Scantable::makePersistent(const std::string& filename)
519{
520 String inname(filename);
521 Path path(inname);
522 /// @todo reindex SCANNO, recompute nbeam, nif, npol
523 inname = path.expandedName();
524 // WORKAROUND !!! for Table bug
525 // Remove when fixed in casacore
526 if ( table_.tableType() == Table::Memory && !selector_.empty() ) {
527 Table tab = table_.copyToMemoryTable(generateName());
528 tab.deepCopy(inname, Table::New);
529 tab.markForDelete();
530
531 } else {
532 table_.deepCopy(inname, Table::New);
533 }
534}
535
536int Scantable::nbeam( int scanno ) const
537{
538 if ( scanno < 0 ) {
539 Int n;
540 table_.keywordSet().get("nBeam",n);
541 return int(n);
542 } else {
543 // take the first POLNO,IFNO,CYCLENO as nbeam shouldn't vary with these
544 Table t = table_(table_.col("SCANNO") == scanno);
545 if ( t.nrow() == 0 ) return 0 ;
546 ROTableRow row(t);
547 const TableRecord& rec = row.get(0);
548 Table subt = t( t.col("IFNO") == Int(rec.asuInt("IFNO"))
549 && t.col("POLNO") == Int(rec.asuInt("POLNO"))
550 && t.col("CYCLENO") == Int(rec.asuInt("CYCLENO")) );
551 ROTableVector<uInt> v(subt, "BEAMNO");
552 return int(v.nelements());
553 }
554 return 0;
555}
556
557int Scantable::nif( int scanno ) const
558{
559 if ( scanno < 0 ) {
560 Int n;
561 table_.keywordSet().get("nIF",n);
562 return int(n);
563 } else {
564 // take the first POLNO,BEAMNO,CYCLENO as nbeam shouldn't vary with these
565 Table t = table_(table_.col("SCANNO") == scanno);
566 if ( t.nrow() == 0 ) return 0 ;
567 ROTableRow row(t);
568 const TableRecord& rec = row.get(0);
569 Table subt = t( t.col("BEAMNO") == Int(rec.asuInt("BEAMNO"))
570 && t.col("POLNO") == Int(rec.asuInt("POLNO"))
571 && t.col("CYCLENO") == Int(rec.asuInt("CYCLENO")) );
572 if ( subt.nrow() == 0 ) return 0;
573 ROTableVector<uInt> v(subt, "IFNO");
574 return int(v.nelements());
575 }
576 return 0;
577}
578
579int Scantable::npol( int scanno ) const
580{
581 if ( scanno < 0 ) {
582 Int n;
583 table_.keywordSet().get("nPol",n);
584 return n;
585 } else {
586 // take the first POLNO,IFNO,CYCLENO as nbeam shouldn't vary with these
587 Table t = table_(table_.col("SCANNO") == scanno);
588 if ( t.nrow() == 0 ) return 0 ;
589 ROTableRow row(t);
590 const TableRecord& rec = row.get(0);
591 Table subt = t( t.col("BEAMNO") == Int(rec.asuInt("BEAMNO"))
592 && t.col("IFNO") == Int(rec.asuInt("IFNO"))
593 && t.col("CYCLENO") == Int(rec.asuInt("CYCLENO")) );
594 if ( subt.nrow() == 0 ) return 0;
595 ROTableVector<uInt> v(subt, "POLNO");
596 return int(v.nelements());
597 }
598 return 0;
599}
600
601int Scantable::ncycle( int scanno ) const
602{
603 if ( scanno < 0 ) {
604 Block<String> cols(2);
605 cols[0] = "SCANNO";
606 cols[1] = "CYCLENO";
607 TableIterator it(table_, cols);
608 int n = 0;
609 while ( !it.pastEnd() ) {
610 ++n;
611 ++it;
612 }
613 return n;
614 } else {
615 Table t = table_(table_.col("SCANNO") == scanno);
616 if ( t.nrow() == 0 ) return 0 ;
617 ROTableRow row(t);
618 const TableRecord& rec = row.get(0);
619 Table subt = t( t.col("BEAMNO") == Int(rec.asuInt("BEAMNO"))
620 && t.col("POLNO") == Int(rec.asuInt("POLNO"))
621 && t.col("IFNO") == Int(rec.asuInt("IFNO")) );
622 if ( subt.nrow() == 0 ) return 0;
623 return int(subt.nrow());
624 }
625 return 0;
626}
627
628
629int Scantable::nrow( int scanno ) const
630{
631 return int(table_.nrow());
632}
633
634int Scantable::nchan( int ifno ) const
635{
636 if ( ifno < 0 ) {
637 Int n;
638 table_.keywordSet().get("nChan",n);
639 return int(n);
640 } else {
641 // take the first SCANNO,POLNO,BEAMNO,CYCLENO as nbeam shouldn't
642 // vary with these
643 Table t = table_(table_.col("IFNO") == ifno);
644 if ( t.nrow() == 0 ) return 0;
645 ROArrayColumn<Float> v(t, "SPECTRA");
646 return v.shape(0)(0);
647 }
648 return 0;
649}
650
651int Scantable::nscan() const {
652 Vector<uInt> scannos(scanCol_.getColumn());
653 uInt nout = genSort( scannos, Sort::Ascending,
654 Sort::QuickSort|Sort::NoDuplicates );
655 return int(nout);
656}
657
658int Scantable::getChannels(int whichrow) const
659{
660 return specCol_.shape(whichrow)(0);
661}
662
663int Scantable::getBeam(int whichrow) const
664{
665 return beamCol_(whichrow);
666}
667
668std::vector<uint> Scantable::getNumbers(const ScalarColumn<uInt>& col) const
669{
670 Vector<uInt> nos(col.getColumn());
671 uInt n = genSort( nos, Sort::Ascending, Sort::QuickSort|Sort::NoDuplicates );
672 nos.resize(n, True);
673 std::vector<uint> stlout;
674 nos.tovector(stlout);
675 return stlout;
676}
677
678int Scantable::getIF(int whichrow) const
679{
680 return ifCol_(whichrow);
681}
682
683int Scantable::getPol(int whichrow) const
684{
685 return polCol_(whichrow);
686}
687
688std::string Scantable::formatTime(const MEpoch& me, bool showdate) const
689{
690 MVTime mvt(me.getValue());
691 if (showdate)
692 mvt.setFormat(MVTime::YMD);
693 else
694 mvt.setFormat(MVTime::TIME);
695 ostringstream oss;
696 oss << mvt;
697 return String(oss);
698}
699
700void Scantable::calculateAZEL()
701{
702 MPosition mp = getAntennaPosition();
703 MEpoch::ROScalarColumn timeCol(table_, "TIME");
704 ostringstream oss;
705 oss << "Computed azimuth/elevation using " << endl
706 << mp << endl;
707 for (Int i=0; i<nrow(); ++i) {
708 MEpoch me = timeCol(i);
709 MDirection md = getDirection(i);
710 oss << " Time: " << formatTime(me,False) << " Direction: " << formatDirection(md)
711 << endl << " => ";
712 MeasFrame frame(mp, me);
713 Vector<Double> azel =
714 MDirection::Convert(md, MDirection::Ref(MDirection::AZEL,
715 frame)
716 )().getAngle("rad").getValue();
717 azCol_.put(i,Float(azel[0]));
718 elCol_.put(i,Float(azel[1]));
719 oss << "azel: " << azel[0]/C::pi*180.0 << " "
720 << azel[1]/C::pi*180.0 << " (deg)" << endl;
721 }
722 pushLog(String(oss));
723}
724
725void Scantable::clip(const Float uthres, const Float dthres, bool clipoutside, bool unflag)
726{
727 for (uInt i=0; i<table_.nrow(); ++i) {
728 Vector<uChar> flgs = flagsCol_(i);
729 srchChannelsToClip(i, uthres, dthres, clipoutside, unflag, flgs);
730 flagsCol_.put(i, flgs);
731 }
732}
733
734std::vector<bool> Scantable::getClipMask(int whichrow, const Float uthres, const Float dthres, bool clipoutside, bool unflag)
735{
736 Vector<uChar> flags;
737 flagsCol_.get(uInt(whichrow), flags);
738 srchChannelsToClip(uInt(whichrow), uthres, dthres, clipoutside, unflag, flags);
739 Vector<Bool> bflag(flags.shape());
740 convertArray(bflag, flags);
741 //bflag = !bflag;
742
743 std::vector<bool> mask;
744 bflag.tovector(mask);
745 return mask;
746}
747
748void Scantable::srchChannelsToClip(uInt whichrow, const Float uthres, const Float dthres, bool clipoutside, bool unflag,
749 Vector<uChar> flgs)
750{
751 Vector<Float> spcs = specCol_(whichrow);
752 uInt nchannel = nchan();
753 if (spcs.nelements() != nchannel) {
754 throw(AipsError("Data has incorrect number of channels"));
755 }
756 uChar userflag = 1 << 7;
757 if (unflag) {
758 userflag = 0 << 7;
759 }
760 if (clipoutside) {
761 for (uInt j = 0; j < nchannel; ++j) {
762 Float spc = spcs(j);
763 if ((spc >= uthres) || (spc <= dthres)) {
764 flgs(j) = userflag;
765 }
766 }
767 } else {
768 for (uInt j = 0; j < nchannel; ++j) {
769 Float spc = spcs(j);
770 if ((spc < uthres) && (spc > dthres)) {
771 flgs(j) = userflag;
772 }
773 }
774 }
775}
776
777void Scantable::flag(const std::vector<bool>& msk, bool unflag)
778{
779 std::vector<bool>::const_iterator it;
780 uInt ntrue = 0;
781 for (it = msk.begin(); it != msk.end(); ++it) {
782 if ( *it ) {
783 ntrue++;
784 }
785 }
786 if ( selector_.empty() && (msk.size() == 0 || msk.size() == ntrue) )
787 throw(AipsError("Trying to flag whole scantable."));
788 if ( msk.size() == 0 ) {
789 uChar userflag = 1 << 7;
790 if ( unflag ) {
791 userflag = 0 << 7;
792 }
793 for ( uInt i=0; i<table_.nrow(); ++i) {
794 Vector<uChar> flgs = flagsCol_(i);
795 flgs = userflag;
796 flagsCol_.put(i, flgs);
797 }
798 return;
799 }
800 if ( int(msk.size()) != nchan() ) {
801 throw(AipsError("Mask has incorrect number of channels."));
802 }
803 for ( uInt i=0; i<table_.nrow(); ++i) {
804 Vector<uChar> flgs = flagsCol_(i);
805 if ( flgs.nelements() != msk.size() ) {
806 throw(AipsError("Mask has incorrect number of channels."
807 " Probably varying with IF. Please flag per IF"));
808 }
809 std::vector<bool>::const_iterator it;
810 uInt j = 0;
811 uChar userflag = 1 << 7;
812 if ( unflag ) {
813 userflag = 0 << 7;
814 }
815 for (it = msk.begin(); it != msk.end(); ++it) {
816 if ( *it ) {
817 flgs(j) = userflag;
818 }
819 ++j;
820 }
821 flagsCol_.put(i, flgs);
822 }
823}
824
825void Scantable::flagRow(const std::vector<uInt>& rows, bool unflag)
826{
827 if ( selector_.empty() && (rows.size() == table_.nrow()) )
828 throw(AipsError("Trying to flag whole scantable."));
829
830 uInt rowflag = (unflag ? 0 : 1);
831 std::vector<uInt>::const_iterator it;
832 for (it = rows.begin(); it != rows.end(); ++it)
833 flagrowCol_.put(*it, rowflag);
834}
835
836std::vector<bool> Scantable::getMask(int whichrow) const
837{
838 Vector<uChar> flags;
839 flagsCol_.get(uInt(whichrow), flags);
840 Vector<Bool> bflag(flags.shape());
841 convertArray(bflag, flags);
842 bflag = !bflag;
843 std::vector<bool> mask;
844 bflag.tovector(mask);
845 return mask;
846}
847
848std::vector<float> Scantable::getSpectrum( int whichrow,
849 const std::string& poltype ) const
850{
851 String ptype = poltype;
852 if (poltype == "" ) ptype = getPolType();
853 if ( whichrow < 0 || whichrow >= nrow() )
854 throw(AipsError("Illegal row number."));
855 std::vector<float> out;
856 Vector<Float> arr;
857 uInt requestedpol = polCol_(whichrow);
858 String basetype = getPolType();
859 if ( ptype == basetype ) {
860 specCol_.get(whichrow, arr);
861 } else {
862 CountedPtr<STPol> stpol(STPol::getPolClass(Scantable::factories_,
863 basetype));
864 uInt row = uInt(whichrow);
865 stpol->setSpectra(getPolMatrix(row));
866 Float fang,fhand,parang;
867 fang = focusTable_.getTotalAngle(mfocusidCol_(row));
868 fhand = focusTable_.getFeedHand(mfocusidCol_(row));
869 stpol->setPhaseCorrections(fang, fhand);
870 arr = stpol->getSpectrum(requestedpol, ptype);
871 }
872 if ( arr.nelements() == 0 )
873 pushLog("Not enough polarisations present to do the conversion.");
874 arr.tovector(out);
875 return out;
876}
877
878void Scantable::setSpectrum( const std::vector<float>& spec,
879 int whichrow )
880{
881 Vector<Float> spectrum(spec);
882 Vector<Float> arr;
883 specCol_.get(whichrow, arr);
884 if ( spectrum.nelements() != arr.nelements() )
885 throw AipsError("The spectrum has incorrect number of channels.");
886 specCol_.put(whichrow, spectrum);
887}
888
889
890String Scantable::generateName()
891{
892 return (File::newUniqueName("./","temp")).baseName();
893}
894
895const casa::Table& Scantable::table( ) const
896{
897 return table_;
898}
899
900casa::Table& Scantable::table( )
901{
902 return table_;
903}
904
905std::string Scantable::getPolType() const
906{
907 return table_.keywordSet().asString("POLTYPE");
908}
909
910void Scantable::unsetSelection()
911{
912 table_ = originalTable_;
913 attach();
914 selector_.reset();
915}
916
917void Scantable::setSelection( const STSelector& selection )
918{
919 Table tab = const_cast<STSelector&>(selection).apply(originalTable_);
920 if ( tab.nrow() == 0 ) {
921 throw(AipsError("Selection contains no data. Not applying it."));
922 }
923 table_ = tab;
924 attach();
925 selector_ = selection;
926}
927
928std::string Scantable::summary( bool verbose )
929{
930 // Format header info
931 ostringstream oss;
932 oss << endl;
933 oss << asap::SEPERATOR << endl;
934 oss << " Scan Table Summary" << endl;
935 oss << asap::SEPERATOR << endl;
936 oss.flags(std::ios_base::left);
937 oss << setw(15) << "Beams:" << setw(4) << nbeam() << endl
938 << setw(15) << "IFs:" << setw(4) << nif() << endl
939 << setw(15) << "Polarisations:" << setw(4) << npol()
940 << "(" << getPolType() << ")" << endl
941 << setw(15) << "Channels:" << nchan() << endl;
942 String tmp;
943 oss << setw(15) << "Observer:"
944 << table_.keywordSet().asString("Observer") << endl;
945 oss << setw(15) << "Obs Date:" << getTime(-1,true) << endl;
946 table_.keywordSet().get("Project", tmp);
947 oss << setw(15) << "Project:" << tmp << endl;
948 table_.keywordSet().get("Obstype", tmp);
949 oss << setw(15) << "Obs. Type:" << tmp << endl;
950 table_.keywordSet().get("AntennaName", tmp);
951 oss << setw(15) << "Antenna Name:" << tmp << endl;
952 table_.keywordSet().get("FluxUnit", tmp);
953 oss << setw(15) << "Flux Unit:" << tmp << endl;
954 //Vector<Double> vec(moleculeTable_.getRestFrequencies());
955 int nid = moleculeTable_.nrow();
956 Bool firstline = True;
957 oss << setw(15) << "Rest Freqs:";
958 for (int i=0; i<nid; i++) {
959 Table t = table_(table_.col("MOLECULE_ID") == i);
960 if (t.nrow() > 0) {
961 Vector<Double> vec(moleculeTable_.getRestFrequency(i));
962 if (vec.nelements() > 0) {
963 if (firstline) {
964 oss << setprecision(10) << vec << " [Hz]" << endl;
965 firstline=False;
966 }
967 else{
968 oss << setw(15)<<" " << setprecision(10) << vec << " [Hz]" << endl;
969 }
970 } else {
971 oss << "none" << endl;
972 }
973 }
974 }
975
976 oss << setw(15) << "Abcissa:" << getAbcissaLabel(0) << endl;
977 oss << selector_.print() << endl;
978 oss << endl;
979 // main table
980 String dirtype = "Position ("
981 + getDirectionRefString()
982 + ")";
983 oss << setw(5) << "Scan" << setw(15) << "Source"
984 << setw(10) << "Time" << setw(18) << "Integration" << endl;
985 oss << setw(5) << "" << setw(5) << "Beam" << setw(3) << "" << dirtype << endl;
986 oss << setw(10) << "" << setw(3) << "IF" << setw(3) << ""
987 << setw(8) << "Frame" << setw(16)
988 << "RefVal" << setw(10) << "RefPix" << setw(12) << "Increment"
989 << setw(7) << "Channels"
990 << endl;
991 oss << asap::SEPERATOR << endl;
992 TableIterator iter(table_, "SCANNO");
993 while (!iter.pastEnd()) {
994 Table subt = iter.table();
995 ROTableRow row(subt);
996 MEpoch::ROScalarColumn timeCol(subt,"TIME");
997 const TableRecord& rec = row.get(0);
998 oss << setw(4) << std::right << rec.asuInt("SCANNO")
999 << std::left << setw(1) << ""
1000 << setw(15) << rec.asString("SRCNAME")
1001 << setw(10) << formatTime(timeCol(0), false);
1002 // count the cycles in the scan
1003 TableIterator cyciter(subt, "CYCLENO");
1004 int nint = 0;
1005 while (!cyciter.pastEnd()) {
1006 ++nint;
1007 ++cyciter;
1008 }
1009 oss << setw(3) << std::right << nint << setw(3) << " x " << std::left
1010 << setw(6) << formatSec(rec.asFloat("INTERVAL")) << endl;
1011
1012 TableIterator biter(subt, "BEAMNO");
1013 while (!biter.pastEnd()) {
1014 Table bsubt = biter.table();
1015 ROTableRow brow(bsubt);
1016 const TableRecord& brec = brow.get(0);
1017 uInt row0 = bsubt.rowNumbers(table_)[0];
1018 oss << setw(5) << "" << setw(4) << std::right << brec.asuInt("BEAMNO")<< std::left;
1019 oss << setw(4) << "" << formatDirection(getDirection(row0)) << endl;
1020 TableIterator iiter(bsubt, "IFNO");
1021 while (!iiter.pastEnd()) {
1022 Table isubt = iiter.table();
1023 ROTableRow irow(isubt);
1024 const TableRecord& irec = irow.get(0);
1025 oss << setw(9) << "";
1026 oss << setw(3) << std::right << irec.asuInt("IFNO") << std::left
1027 << setw(1) << "" << frequencies().print(irec.asuInt("FREQ_ID"))
1028 << setw(3) << "" << nchan(irec.asuInt("IFNO"))
1029 << endl;
1030
1031 ++iiter;
1032 }
1033 ++biter;
1034 }
1035 ++iter;
1036 }
1037 /// @todo implement verbose mode
1038 return String(oss);
1039}
1040
1041std::string Scantable::getTime(int whichrow, bool showdate) const
1042{
1043 MEpoch::ROScalarColumn timeCol(table_, "TIME");
1044 MEpoch me;
1045 if (whichrow > -1) {
1046 me = timeCol(uInt(whichrow));
1047 } else {
1048 Double tm;
1049 table_.keywordSet().get("UTC",tm);
1050 me = MEpoch(MVEpoch(tm));
1051 }
1052 return formatTime(me, showdate);
1053}
1054
1055MEpoch Scantable::getEpoch(int whichrow) const
1056{
1057 if (whichrow > -1) {
1058 return timeCol_(uInt(whichrow));
1059 } else {
1060 Double tm;
1061 table_.keywordSet().get("UTC",tm);
1062 return MEpoch(MVEpoch(tm));
1063 }
1064}
1065
1066std::string Scantable::getDirectionString(int whichrow) const
1067{
1068 return formatDirection(getDirection(uInt(whichrow)));
1069}
1070
1071
1072SpectralCoordinate Scantable::getSpectralCoordinate(int whichrow) const {
1073 const MPosition& mp = getAntennaPosition();
1074 const MDirection& md = getDirection(whichrow);
1075 const MEpoch& me = timeCol_(whichrow);
1076 //Double rf = moleculeTable_.getRestFrequency(mmolidCol_(whichrow));
1077 Vector<Double> rf = moleculeTable_.getRestFrequency(mmolidCol_(whichrow));
1078 return freqTable_.getSpectralCoordinate(md, mp, me, rf,
1079 mfreqidCol_(whichrow));
1080}
1081
1082std::vector< double > Scantable::getAbcissa( int whichrow ) const
1083{
1084 if ( whichrow > int(table_.nrow()) ) throw(AipsError("Illegal row number"));
1085 std::vector<double> stlout;
1086 int nchan = specCol_(whichrow).nelements();
1087 String us = freqTable_.getUnitString();
1088 if ( us == "" || us == "pixel" || us == "channel" ) {
1089 for (int i=0; i<nchan; ++i) {
1090 stlout.push_back(double(i));
1091 }
1092 return stlout;
1093 }
1094 SpectralCoordinate spc = getSpectralCoordinate(whichrow);
1095 Vector<Double> pixel(nchan);
1096 Vector<Double> world;
1097 indgen(pixel);
1098 if ( Unit(us) == Unit("Hz") ) {
1099 for ( int i=0; i < nchan; ++i) {
1100 Double world;
1101 spc.toWorld(world, pixel[i]);
1102 stlout.push_back(double(world));
1103 }
1104 } else if ( Unit(us) == Unit("km/s") ) {
1105 Vector<Double> world;
1106 spc.pixelToVelocity(world, pixel);
1107 world.tovector(stlout);
1108 }
1109 return stlout;
1110}
1111void Scantable::setDirectionRefString( const std::string & refstr )
1112{
1113 MDirection::Types mdt;
1114 if (refstr != "" && !MDirection::getType(mdt, refstr)) {
1115 throw(AipsError("Illegal Direction frame."));
1116 }
1117 if ( refstr == "" ) {
1118 String defaultstr = MDirection::showType(dirCol_.getMeasRef().getType());
1119 table_.rwKeywordSet().define("DIRECTIONREF", defaultstr);
1120 } else {
1121 table_.rwKeywordSet().define("DIRECTIONREF", String(refstr));
1122 }
1123}
1124
1125std::string Scantable::getDirectionRefString( ) const
1126{
1127 return table_.keywordSet().asString("DIRECTIONREF");
1128}
1129
1130MDirection Scantable::getDirection(int whichrow ) const
1131{
1132 String usertype = table_.keywordSet().asString("DIRECTIONREF");
1133 String type = MDirection::showType(dirCol_.getMeasRef().getType());
1134 if ( usertype != type ) {
1135 MDirection::Types mdt;
1136 if (!MDirection::getType(mdt, usertype)) {
1137 throw(AipsError("Illegal Direction frame."));
1138 }
1139 return dirCol_.convert(uInt(whichrow), mdt);
1140 } else {
1141 return dirCol_(uInt(whichrow));
1142 }
1143}
1144
1145std::string Scantable::getAbcissaLabel( int whichrow ) const
1146{
1147 if ( whichrow > int(table_.nrow()) ) throw(AipsError("Illegal ro number"));
1148 const MPosition& mp = getAntennaPosition();
1149 const MDirection& md = getDirection(whichrow);
1150 const MEpoch& me = timeCol_(whichrow);
1151 //const Double& rf = mmolidCol_(whichrow);
1152 const Vector<Double> rf = moleculeTable_.getRestFrequency(mmolidCol_(whichrow));
1153 SpectralCoordinate spc =
1154 freqTable_.getSpectralCoordinate(md, mp, me, rf, mfreqidCol_(whichrow));
1155
1156 String s = "Channel";
1157 Unit u = Unit(freqTable_.getUnitString());
1158 if (u == Unit("km/s")) {
1159 s = CoordinateUtil::axisLabel(spc, 0, True,True, True);
1160 } else if (u == Unit("Hz")) {
1161 Vector<String> wau(1);wau = u.getName();
1162 spc.setWorldAxisUnits(wau);
1163 s = CoordinateUtil::axisLabel(spc, 0, True, True, False);
1164 }
1165 return s;
1166
1167}
1168
1169/**
1170void asap::Scantable::setRestFrequencies( double rf, const std::string& name,
1171 const std::string& unit )
1172**/
1173void Scantable::setRestFrequencies( vector<double> rf, const vector<std::string>& name,
1174 const std::string& unit )
1175
1176{
1177 ///@todo lookup in line table to fill in name and formattedname
1178 Unit u(unit);
1179 //Quantum<Double> urf(rf, u);
1180 Quantum<Vector<Double> >urf(rf, u);
1181 Vector<String> formattedname(0);
1182 //cerr<<"Scantable::setRestFrequnecies="<<urf<<endl;
1183
1184 //uInt id = moleculeTable_.addEntry(urf.getValue("Hz"), name, "");
1185 uInt id = moleculeTable_.addEntry(urf.getValue("Hz"), mathutil::toVectorString(name), formattedname);
1186 TableVector<uInt> tabvec(table_, "MOLECULE_ID");
1187 tabvec = id;
1188}
1189
1190/**
1191void asap::Scantable::setRestFrequencies( const std::string& name )
1192{
1193 throw(AipsError("setRestFrequencies( const std::string& name ) NYI"));
1194 ///@todo implement
1195}
1196**/
1197void Scantable::setRestFrequencies( const vector<std::string>& name )
1198{
1199 throw(AipsError("setRestFrequencies( const vector<std::string>& name ) NYI"));
1200 ///@todo implement
1201}
1202
1203std::vector< unsigned int > Scantable::rownumbers( ) const
1204{
1205 std::vector<unsigned int> stlout;
1206 Vector<uInt> vec = table_.rowNumbers();
1207 vec.tovector(stlout);
1208 return stlout;
1209}
1210
1211
1212Matrix<Float> Scantable::getPolMatrix( uInt whichrow ) const
1213{
1214 ROTableRow row(table_);
1215 const TableRecord& rec = row.get(whichrow);
1216 Table t =
1217 originalTable_( originalTable_.col("SCANNO") == Int(rec.asuInt("SCANNO"))
1218 && originalTable_.col("BEAMNO") == Int(rec.asuInt("BEAMNO"))
1219 && originalTable_.col("IFNO") == Int(rec.asuInt("IFNO"))
1220 && originalTable_.col("CYCLENO") == Int(rec.asuInt("CYCLENO")) );
1221 ROArrayColumn<Float> speccol(t, "SPECTRA");
1222 return speccol.getColumn();
1223}
1224
1225std::vector< std::string > Scantable::columnNames( ) const
1226{
1227 Vector<String> vec = table_.tableDesc().columnNames();
1228 return mathutil::tovectorstring(vec);
1229}
1230
1231MEpoch::Types Scantable::getTimeReference( ) const
1232{
1233 return MEpoch::castType(timeCol_.getMeasRef().getType());
1234}
1235
1236void Scantable::addFit( const STFitEntry& fit, int row )
1237{
1238 //cout << mfitidCol_(uInt(row)) << endl;
1239 LogIO os( LogOrigin( "Scantable", "addFit()", WHERE ) ) ;
1240 os << mfitidCol_(uInt(row)) << LogIO::POST ;
1241 uInt id = fitTable_.addEntry(fit, mfitidCol_(uInt(row)));
1242 mfitidCol_.put(uInt(row), id);
1243}
1244
1245void Scantable::shift(int npix)
1246{
1247 Vector<uInt> fids(mfreqidCol_.getColumn());
1248 genSort( fids, Sort::Ascending,
1249 Sort::QuickSort|Sort::NoDuplicates );
1250 for (uInt i=0; i<fids.nelements(); ++i) {
1251 frequencies().shiftRefPix(npix, fids[i]);
1252 }
1253}
1254
1255String Scantable::getAntennaName() const
1256{
1257 String out;
1258 table_.keywordSet().get("AntennaName", out);
1259 return out;
1260}
1261
1262int Scantable::checkScanInfo(const std::vector<int>& scanlist) const
1263{
1264 String tbpath;
1265 int ret = 0;
1266 if ( table_.keywordSet().isDefined("GBT_GO") ) {
1267 table_.keywordSet().get("GBT_GO", tbpath);
1268 Table t(tbpath,Table::Old);
1269 // check each scan if other scan of the pair exist
1270 int nscan = scanlist.size();
1271 for (int i = 0; i < nscan; i++) {
1272 Table subt = t( t.col("SCAN") == scanlist[i]+1 );
1273 if (subt.nrow()==0) {
1274 //cerr <<"Scan "<<scanlist[i]<<" cannot be found in the scantable."<<endl;
1275 LogIO os( LogOrigin( "Scantable", "checkScanInfo()", WHERE ) ) ;
1276 os <<LogIO::WARN<<"Scan "<<scanlist[i]<<" cannot be found in the scantable."<<LogIO::POST;
1277 ret = 1;
1278 break;
1279 }
1280 ROTableRow row(subt);
1281 const TableRecord& rec = row.get(0);
1282 int scan1seqn = rec.asuInt("PROCSEQN");
1283 int laston1 = rec.asuInt("LASTON");
1284 if ( rec.asuInt("PROCSIZE")==2 ) {
1285 if ( i < nscan-1 ) {
1286 Table subt2 = t( t.col("SCAN") == scanlist[i+1]+1 );
1287 if ( subt2.nrow() == 0) {
1288 LogIO os( LogOrigin( "Scantable", "checkScanInfo()", WHERE ) ) ;
1289
1290 //cerr<<"Scan "<<scanlist[i+1]<<" cannot be found in the scantable."<<endl;
1291 os<<LogIO::WARN<<"Scan "<<scanlist[i+1]<<" cannot be found in the scantable."<<LogIO::POST;
1292 ret = 1;
1293 break;
1294 }
1295 ROTableRow row2(subt2);
1296 const TableRecord& rec2 = row2.get(0);
1297 int scan2seqn = rec2.asuInt("PROCSEQN");
1298 int laston2 = rec2.asuInt("LASTON");
1299 if (scan1seqn == 1 && scan2seqn == 2) {
1300 if (laston1 == laston2) {
1301 LogIO os( LogOrigin( "Scantable", "checkScanInfo()", WHERE ) ) ;
1302 //cerr<<"A valid scan pair ["<<scanlist[i]<<","<<scanlist[i+1]<<"]"<<endl;
1303 os<<"A valid scan pair ["<<scanlist[i]<<","<<scanlist[i+1]<<"]"<<LogIO::POST;
1304 i +=1;
1305 }
1306 else {
1307 LogIO os( LogOrigin( "Scantable", "checkScanInfo()", WHERE ) ) ;
1308 //cerr<<"Incorrect scan pair ["<<scanlist[i]<<","<<scanlist[i+1]<<"]"<<endl;
1309 os<<LogIO::WARN<<"Incorrect scan pair ["<<scanlist[i]<<","<<scanlist[i+1]<<"]"<<LogIO::POST;
1310 }
1311 }
1312 else if (scan1seqn==2 && scan2seqn == 1) {
1313 if (laston1 == laston2) {
1314 LogIO os( LogOrigin( "Scantable", "checkScanInfo()", WHERE ) ) ;
1315 //cerr<<"["<<scanlist[i]<<","<<scanlist[i+1]<<"] is a valid scan pair but in incorrect order."<<endl;
1316 os<<LogIO::WARN<<"["<<scanlist[i]<<","<<scanlist[i+1]<<"] is a valid scan pair but in incorrect order."<<LogIO::POST;
1317 ret = 1;
1318 break;
1319 }
1320 }
1321 else {
1322 LogIO os( LogOrigin( "Scantable", "checkScanInfo()", WHERE ) ) ;
1323 //cerr<<"The other scan for "<<scanlist[i]<<" appears to be missing. Check the input scan numbers."<<endl;
1324 os<<LogIO::WARN<<"The other scan for "<<scanlist[i]<<" appears to be missing. Check the input scan numbers."<<LogIO::POST;
1325 ret = 1;
1326 break;
1327 }
1328 }
1329 }
1330 else {
1331 LogIO os( LogOrigin( "Scantable", "checkScanInfo()", WHERE ) ) ;
1332 //cerr<<"The scan does not appear to be standard obsevation."<<endl;
1333 os<<LogIO::WARN<<"The scan does not appear to be standard obsevation."<<LogIO::POST;
1334 }
1335 //if ( i >= nscan ) break;
1336 }
1337 }
1338 else {
1339 LogIO os( LogOrigin( "Scantable", "checkScanInfo()", WHERE ) ) ;
1340 //cerr<<"No reference to GBT_GO table."<<endl;
1341 os<<LogIO::WARN<<"No reference to GBT_GO table."<<LogIO::POST;
1342 ret = 1;
1343 }
1344 return ret;
1345}
1346
1347std::vector<double> Scantable::getDirectionVector(int whichrow) const
1348{
1349 Vector<Double> Dir = dirCol_(whichrow).getAngle("rad").getValue();
1350 std::vector<double> dir;
1351 Dir.tovector(dir);
1352 return dir;
1353}
1354
1355void asap::Scantable::reshapeSpectrum( int nmin, int nmax )
1356 throw( casa::AipsError )
1357{
1358 // assumed that all rows have same nChan
1359 Vector<Float> arr = specCol_( 0 ) ;
1360 int nChan = arr.nelements() ;
1361
1362 // if nmin < 0 or nmax < 0, nothing to do
1363 if ( nmin < 0 ) {
1364 throw( casa::indexError<int>( nmin, "asap::Scantable::reshapeSpectrum: Invalid range. Negative index is specified." ) ) ;
1365 }
1366 if ( nmax < 0 ) {
1367 throw( casa::indexError<int>( nmax, "asap::Scantable::reshapeSpectrum: Invalid range. Negative index is specified." ) ) ;
1368 }
1369
1370 // if nmin > nmax, exchange values
1371 if ( nmin > nmax ) {
1372 int tmp = nmax ;
1373 nmax = nmin ;
1374 nmin = tmp ;
1375 LogIO os( LogOrigin( "Scantable", "reshapeSpectrum()", WHERE ) ) ;
1376 os << "Swap values. Applied range is ["
1377 << nmin << ", " << nmax << "]" << LogIO::POST ;
1378 }
1379
1380 // if nmin exceeds nChan, nothing to do
1381 if ( nmin >= nChan ) {
1382 throw( casa::indexError<int>( nmin, "asap::Scantable::reshapeSpectrum: Invalid range. Specified minimum exceeds nChan." ) ) ;
1383 }
1384
1385 // if nmax exceeds nChan, reset nmax to nChan
1386 if ( nmax >= nChan ) {
1387 if ( nmin == 0 ) {
1388 // nothing to do
1389 LogIO os( LogOrigin( "Scantable", "reshapeSpectrum()", WHERE ) ) ;
1390 os << "Whole range is selected. Nothing to do." << LogIO::POST ;
1391 return ;
1392 }
1393 else {
1394 LogIO os( LogOrigin( "Scantable", "reshapeSpectrum()", WHERE ) ) ;
1395 os << "Specified maximum exceeds nChan. Applied range is ["
1396 << nmin << ", " << nChan-1 << "]." << LogIO::POST ;
1397 nmax = nChan - 1 ;
1398 }
1399 }
1400
1401 // reshape specCol_ and flagCol_
1402 for ( int irow = 0 ; irow < nrow() ; irow++ ) {
1403 reshapeSpectrum( nmin, nmax, irow ) ;
1404 }
1405
1406 // update FREQUENCIES subtable
1407 Double refpix ;
1408 Double refval ;
1409 Double increment ;
1410 int freqnrow = freqTable_.table().nrow() ;
1411 Vector<uInt> oldId( freqnrow ) ;
1412 Vector<uInt> newId( freqnrow ) ;
1413 for ( int irow = 0 ; irow < freqnrow ; irow++ ) {
1414 freqTable_.getEntry( refpix, refval, increment, irow ) ;
1415 /***
1416 * need to shift refpix to nmin
1417 * note that channel nmin in old index will be channel 0 in new one
1418 ***/
1419 refval = refval - ( refpix - nmin ) * increment ;
1420 refpix = 0 ;
1421 freqTable_.setEntry( refpix, refval, increment, irow ) ;
1422 }
1423
1424 // update nchan
1425 int newsize = nmax - nmin + 1 ;
1426 table_.rwKeywordSet().define( "nChan", newsize ) ;
1427
1428 // update bandwidth
1429 // assumed all spectra in the scantable have same bandwidth
1430 table_.rwKeywordSet().define( "Bandwidth", increment * newsize ) ;
1431
1432 return ;
1433}
1434
1435void asap::Scantable::reshapeSpectrum( int nmin, int nmax, int irow )
1436{
1437 // reshape specCol_ and flagCol_
1438 Vector<Float> oldspec = specCol_( irow ) ;
1439 Vector<uChar> oldflag = flagsCol_( irow ) ;
1440 uInt newsize = nmax - nmin + 1 ;
1441 specCol_.put( irow, oldspec( Slice( nmin, newsize, 1 ) ) ) ;
1442 flagsCol_.put( irow, oldflag( Slice( nmin, newsize, 1 ) ) ) ;
1443
1444 return ;
1445}
1446
1447void asap::Scantable::regridChannel( int nChan, double dnu )
1448{
1449 LogIO os( LogOrigin( "Scantable", "regridChannel()", WHERE ) ) ;
1450 os << "Regrid abcissa with channel number " << nChan << " and spectral resoultion " << dnu << "Hz." << LogIO::POST ;
1451 // assumed that all rows have same nChan
1452 Vector<Float> arr = specCol_( 0 ) ;
1453 int oldsize = arr.nelements() ;
1454
1455 // if oldsize == nChan, nothing to do
1456 if ( oldsize == nChan ) {
1457 os << "Specified channel number is same as current one. Nothing to do." << LogIO::POST ;
1458 return ;
1459 }
1460
1461 // if oldChan < nChan, unphysical operation
1462 if ( oldsize < nChan ) {
1463 os << "Unphysical operation. Nothing to do." << LogIO::POST ;
1464 return ;
1465 }
1466
1467 // change channel number for specCol_ and flagCol_
1468 Vector<Float> newspec( nChan, 0 ) ;
1469 Vector<uChar> newflag( nChan, false ) ;
1470 vector<string> coordinfo = getCoordInfo() ;
1471 string oldinfo = coordinfo[0] ;
1472 coordinfo[0] = "Hz" ;
1473 setCoordInfo( coordinfo ) ;
1474 for ( int irow = 0 ; irow < nrow() ; irow++ ) {
1475 regridChannel( nChan, dnu, irow ) ;
1476 }
1477 coordinfo[0] = oldinfo ;
1478 setCoordInfo( coordinfo ) ;
1479
1480
1481 // NOTE: this method does not update metadata such as
1482 // FREQUENCIES subtable, nChan, Bandwidth, etc.
1483
1484 return ;
1485}
1486
1487void asap::Scantable::regridChannel( int nChan, double dnu, int irow )
1488{
1489 // logging
1490 //ofstream ofs( "average.log", std::ios::out | std::ios::app ) ;
1491 //ofs << "IFNO = " << getIF( irow ) << " irow = " << irow << endl ;
1492
1493 Vector<Float> oldspec = specCol_( irow ) ;
1494 Vector<uChar> oldflag = flagsCol_( irow ) ;
1495 Vector<Float> newspec( nChan, 0 ) ;
1496 Vector<uChar> newflag( nChan, false ) ;
1497
1498 // regrid
1499 vector<double> abcissa = getAbcissa( irow ) ;
1500 int oldsize = abcissa.size() ;
1501 double olddnu = abcissa[1] - abcissa[0] ;
1502 //int refChan = 0 ;
1503 //double frac = 0.0 ;
1504 //double wedge = 0.0 ;
1505 //double pile = 0.0 ;
1506 int ichan = 0 ;
1507 double wsum = 0.0 ;
1508 Vector<Float> z( nChan ) ;
1509 z[0] = abcissa[0] - 0.5 * olddnu + 0.5 * dnu ;
1510 for ( int ii = 1 ; ii < nChan ; ii++ )
1511 z[ii] = z[ii-1] + dnu ;
1512 Vector<Float> zi( nChan+1 ) ;
1513 Vector<Float> yi( oldsize + 1 ) ;
1514 zi[0] = z[0] - 0.5 * dnu ;
1515 zi[1] = z[0] + 0.5 * dnu ;
1516 for ( int ii = 2 ; ii < nChan ; ii++ )
1517 zi[ii] = zi[ii-1] + dnu ;
1518 zi[nChan] = z[nChan-1] + 0.5 * dnu ;
1519 yi[0] = abcissa[0] - 0.5 * olddnu ;
1520 yi[1] = abcissa[1] + 0.5 * olddnu ;
1521 for ( int ii = 2 ; ii < oldsize ; ii++ )
1522 yi[ii] = abcissa[ii-1] + olddnu ;
1523 yi[oldsize] = abcissa[oldsize-1] + 0.5 * olddnu ;
1524 if ( dnu > 0.0 ) {
1525 for ( int ii = 0 ; ii < nChan ; ii++ ) {
1526 double zl = zi[ii] ;
1527 double zr = zi[ii+1] ;
1528 for ( int j = ichan ; j < oldsize ; j++ ) {
1529 double yl = yi[j] ;
1530 double yr = yi[j+1] ;
1531 if ( yl <= zl ) {
1532 if ( yr <= zl ) {
1533 continue ;
1534 }
1535 else if ( yr <= zr ) {
1536 newspec[ii] += oldspec[j] * ( yr - zl ) ;
1537 newflag[ii] = newflag[ii] || oldflag[j] ;
1538 wsum += ( yr - zl ) ;
1539 }
1540 else {
1541 newspec[ii] += oldspec[j] * dnu ;
1542 newflag[ii] = newflag[ii] || oldflag[j] ;
1543 wsum += dnu ;
1544 ichan = j ;
1545 break ;
1546 }
1547 }
1548 else if ( yl < zr ) {
1549 if ( yr <= zr ) {
1550 newspec[ii] += oldspec[j] * ( yr - yl ) ;
1551 newflag[ii] = newflag[ii] || oldflag[j] ;
1552 wsum += ( yr - yl ) ;
1553 }
1554 else {
1555 newspec[ii] += oldspec[j] * ( zr - yl ) ;
1556 newflag[ii] = newflag[ii] || oldflag[j] ;
1557 wsum += ( zr - yl ) ;
1558 ichan = j ;
1559 break ;
1560 }
1561 }
1562 else {
1563 ichan = j - 1 ;
1564 break ;
1565 }
1566 }
1567 newspec[ii] /= wsum ;
1568 wsum = 0.0 ;
1569 }
1570 }
1571 else if ( dnu < 0.0 ) {
1572 for ( int ii = 0 ; ii < nChan ; ii++ ) {
1573 double zl = zi[ii] ;
1574 double zr = zi[ii+1] ;
1575 for ( int j = ichan ; j < oldsize ; j++ ) {
1576 double yl = yi[j] ;
1577 double yr = yi[j+1] ;
1578 if ( yl >= zl ) {
1579 if ( yr >= zl ) {
1580 continue ;
1581 }
1582 else if ( yr >= zr ) {
1583 newspec[ii] += oldspec[j] * abs( yr - zl ) ;
1584 newflag[ii] = newflag[ii] || oldflag[j] ;
1585 wsum += abs( yr - zl ) ;
1586 }
1587 else {
1588 newspec[ii] += oldspec[j] * abs( dnu ) ;
1589 newflag[ii] = newflag[ii] || oldflag[j] ;
1590 wsum += abs( dnu ) ;
1591 ichan = j ;
1592 break ;
1593 }
1594 }
1595 else if ( yl > zr ) {
1596 if ( yr >= zr ) {
1597 newspec[ii] += oldspec[j] * abs( yr - yl ) ;
1598 newflag[ii] = newflag[ii] || oldflag[j] ;
1599 wsum += abs( yr - yl ) ;
1600 }
1601 else {
1602 newspec[ii] += oldspec[j] * abs( zr - yl ) ;
1603 newflag[ii] = newflag[ii] || oldflag[j] ;
1604 wsum += abs( zr - yl ) ;
1605 ichan = j ;
1606 break ;
1607 }
1608 }
1609 else {
1610 ichan = j - 1 ;
1611 break ;
1612 }
1613 }
1614 newspec[ii] /= wsum ;
1615 wsum = 0.0 ;
1616 }
1617 }
1618// * ichan = 0
1619// ***/
1620// //ofs << "olddnu = " << olddnu << ", dnu = " << dnu << endl ;
1621// pile += dnu ;
1622// wedge = olddnu * ( refChan + 1 ) ;
1623// while ( wedge < pile ) {
1624// newspec[0] += olddnu * oldspec[refChan] ;
1625// newflag[0] = newflag[0] || oldflag[refChan] ;
1626// //ofs << "channel " << refChan << " is included in new channel 0" << endl ;
1627// refChan++ ;
1628// wedge += olddnu ;
1629// wsum += olddnu ;
1630// //ofs << "newspec[0] = " << newspec[0] << " wsum = " << wsum << endl ;
1631// }
1632// frac = ( wedge - pile ) / olddnu ;
1633// wsum += ( 1.0 - frac ) * olddnu ;
1634// newspec[0] += ( 1.0 - frac ) * olddnu * oldspec[refChan] ;
1635// newflag[0] = newflag[0] || oldflag[refChan] ;
1636// //ofs << "channel " << refChan << " is partly included in new channel 0" << " with fraction of " << ( 1.0 - frac ) << endl ;
1637// //ofs << "newspec[0] = " << newspec[0] << " wsum = " << wsum << endl ;
1638// newspec[0] /= wsum ;
1639// //ofs << "newspec[0] = " << newspec[0] << endl ;
1640// //ofs << "wedge = " << wedge << ", pile = " << pile << endl ;
1641
1642// /***
1643// * ichan = 1 - nChan-2
1644// ***/
1645// for ( int ichan = 1 ; ichan < nChan - 1 ; ichan++ ) {
1646// pile += dnu ;
1647// newspec[ichan] += frac * olddnu * oldspec[refChan] ;
1648// newflag[ichan] = newflag[ichan] || oldflag[refChan] ;
1649// //ofs << "channel " << refChan << " is partly included in new channel " << ichan << " with fraction of " << frac << endl ;
1650// refChan++ ;
1651// wedge += olddnu ;
1652// wsum = frac * olddnu ;
1653// //ofs << "newspec[" << ichan << "] = " << newspec[ichan] << " wsum = " << wsum << endl ;
1654// while ( wedge < pile ) {
1655// newspec[ichan] += olddnu * oldspec[refChan] ;
1656// newflag[ichan] = newflag[ichan] || oldflag[refChan] ;
1657// //ofs << "channel " << refChan << " is included in new channel " << ichan << endl ;
1658// refChan++ ;
1659// wedge += olddnu ;
1660// wsum += olddnu ;
1661// //ofs << "newspec[" << ichan << "] = " << newspec[ichan] << " wsum = " << wsum << endl ;
1662// }
1663// frac = ( wedge - pile ) / olddnu ;
1664// wsum += ( 1.0 - frac ) * olddnu ;
1665// newspec[ichan] += ( 1.0 - frac ) * olddnu * oldspec[refChan] ;
1666// newflag[ichan] = newflag[ichan] || oldflag[refChan] ;
1667// //ofs << "channel " << refChan << " is partly included in new channel " << ichan << " with fraction of " << ( 1.0 - frac ) << endl ;
1668// //ofs << "wedge = " << wedge << ", pile = " << pile << endl ;
1669// //ofs << "newspec[" << ichan << "] = " << newspec[ichan] << " wsum = " << wsum << endl ;
1670// newspec[ichan] /= wsum ;
1671// //ofs << "newspec[" << ichan << "] = " << newspec[ichan] << endl ;
1672// }
1673
1674// /***
1675// * ichan = nChan-1
1676// ***/
1677// // NOTE: Assumed that all spectra have the same bandwidth
1678// pile += dnu ;
1679// newspec[nChan-1] += frac * olddnu * oldspec[refChan] ;
1680// newflag[nChan-1] = newflag[nChan-1] || oldflag[refChan] ;
1681// //ofs << "channel " << refChan << " is partly included in new channel " << nChan-1 << " with fraction of " << frac << endl ;
1682// refChan++ ;
1683// wedge += olddnu ;
1684// wsum = frac * olddnu ;
1685// //ofs << "newspec[" << nChan - 1 << "] = " << newspec[nChan-1] << " wsum = " << wsum << endl ;
1686// for ( int jchan = refChan ; jchan < oldsize ; jchan++ ) {
1687// newspec[nChan-1] += olddnu * oldspec[jchan] ;
1688// newflag[nChan-1] = newflag[nChan-1] || oldflag[jchan] ;
1689// wsum += olddnu ;
1690// //ofs << "channel " << jchan << " is included in new channel " << nChan-1 << " with fraction of " << frac << endl ;
1691// //ofs << "newspec[" << nChan - 1 << "] = " << newspec[nChan-1] << " wsum = " << wsum << endl ;
1692// }
1693// //ofs << "wedge = " << wedge << ", pile = " << pile << endl ;
1694// //ofs << "newspec[" << nChan - 1 << "] = " << newspec[nChan-1] << " wsum = " << wsum << endl ;
1695// newspec[nChan-1] /= wsum ;
1696// //ofs << "newspec[" << nChan - 1 << "] = " << newspec[nChan-1] << endl ;
1697
1698// specCol_.put( irow, newspec ) ;
1699// flagsCol_.put( irow, newflag ) ;
1700
1701// // ofs.close() ;
1702
1703
1704 return ;
1705}
1706
1707std::vector<float> Scantable::getWeather(int whichrow) const
1708{
1709 std::vector<float> out(5);
1710 //Float temperature, pressure, humidity, windspeed, windaz;
1711 weatherTable_.getEntry(out[0], out[1], out[2], out[3], out[4],
1712 mweatheridCol_(uInt(whichrow)));
1713
1714
1715 return out;
1716}
1717
1718bool Scantable::getFlagtraFast(int whichrow)
1719{
1720 uChar flag;
1721 Vector<uChar> flags;
1722 flagsCol_.get(uInt(whichrow), flags);
1723 for (int i = 0; i < flags.size(); i++) {
1724 if (i==0) {
1725 flag = flags[i];
1726 }
1727 else {
1728 flag &= flags[i];
1729 }
1730 return ((flag >> 7) == 1);
1731 }
1732}
1733
1734void Scantable::doPolyBaseline(const std::vector<bool>& mask, int order, int rowno, Fitter& fitter)
1735{
1736 fitter.setExpression("poly", order);
1737
1738 std::vector<double> abcsd = getAbcissa(rowno);
1739 std::vector<float> abcs;
1740 for (int i = 0; i < abcsd.size(); i++) {
1741 abcs.push_back((float)abcsd[i]);
1742 }
1743 std::vector<float> spec = getSpectrum(rowno);
1744 std::vector<bool> fmask = getMask(rowno);
1745 if (fmask.size() != mask.size()) {
1746 throw(AipsError("different mask sizes"));
1747 }
1748 for (int i = 0; i < fmask.size(); i++) {
1749 fmask[i] = fmask[i] && mask[i];
1750 }
1751 fitter.setData(abcs, spec, fmask);
1752
1753 fitter.lfit();
1754}
1755
1756void Scantable::polyBaselineBatch(const std::vector<bool>& mask, int order, int rowno)
1757{
1758 Fitter fitter = Fitter();
1759 doPolyBaseline(mask, order, rowno, fitter);
1760 setSpectrum(fitter.getResidual(), rowno);
1761}
1762
1763void Scantable::polyBaseline(const std::vector<bool>& mask, int order, int rowno, long pars_ptr, long pars_size, long errs_ptr, long errs_size, long fmask_ptr, long fmask_size)
1764{
1765 Fitter fitter = Fitter();
1766 doPolyBaseline(mask, order, rowno, fitter);
1767 setSpectrum(fitter.getResidual(), rowno);
1768
1769 std::vector<float> pars = fitter.getParameters();
1770 if (pars_size != pars.size()) {
1771 throw(AipsError("wrong pars size"));
1772 }
1773 float *ppars = reinterpret_cast<float*>(pars_ptr);
1774 for (int i = 0; i < pars_size; i++) {
1775 ppars[i] = pars[i];
1776 }
1777
1778 std::vector<float> errs = fitter.getErrors();
1779 if (errs_size != errs.size()) {
1780 throw(AipsError("wrong errors size"));
1781 }
1782 float *perrs = reinterpret_cast<float*>(errs_ptr);
1783 for (int i = 0; i < errs_size; i++) {
1784 perrs[i] = errs[i];
1785 }
1786
1787 std::vector<bool> fmask = getMask(rowno);
1788 if (fmask_size != fmask.size()) {
1789 throw(AipsError("wrong fmask size"));
1790 }
1791 int *pfmask = reinterpret_cast<int*>(fmask_ptr);
1792 for (int i = 0; i < fmask_size; i++) {
1793 pfmask[i] = ((fmask[i] && mask[i]) ? 1 : 0);
1794 }
1795}
1796
1797}
1798//namespace asap
Note: See TracBrowser for help on using the repository browser.