[1108] | 1 |
|
---|
| 2 | //
|
---|
| 3 | // C++ Implementation: LineCatalog
|
---|
| 4 | //
|
---|
| 5 | // Description: A class representing a line catalog
|
---|
| 6 | //
|
---|
| 7 | //
|
---|
| 8 | // Author: Malte Marquarding <asap@atnf.csiro.au>, (C) 2006
|
---|
| 9 | //
|
---|
| 10 | // Copyright: See COPYING file that comes with this distribution
|
---|
| 11 | //
|
---|
| 12 | //
|
---|
| 13 |
|
---|
| 14 | // std includes
|
---|
| 15 |
|
---|
| 16 | // casa includes
|
---|
| 17 | #include <casa/Exceptions/Error.h>
|
---|
[1113] | 18 | #include <casa/iostream.h>
|
---|
| 19 | #include <casa/iomanip.h>
|
---|
[1108] | 20 | #include <casa/OS/Path.h>
|
---|
| 21 | #include <casa/OS/File.h>
|
---|
[1113] | 22 | #include <casa/Arrays/Vector.h>
|
---|
[1108] | 23 | #include <tables/Tables/ReadAsciiTable.h>
|
---|
| 24 | #include <tables/Tables/TableParse.h>
|
---|
[1113] | 25 | #include <tables/Tables/ScalarColumn.h>
|
---|
[1108] | 26 |
|
---|
[1113] | 27 | #include "STAttr.h"
|
---|
[1108] | 28 | #include "LineCatalog.h"
|
---|
| 29 |
|
---|
| 30 | using namespace casa;
|
---|
| 31 |
|
---|
| 32 | namespace asap
|
---|
| 33 | {
|
---|
| 34 |
|
---|
| 35 | LineCatalog::LineCatalog(const std::string& name)
|
---|
| 36 | {
|
---|
| 37 | Path path(name);
|
---|
| 38 | std::string inname = path.expandedName();
|
---|
| 39 | File f(inname);
|
---|
[1126] | 40 | if (f.isDirectory()) { //assume it's a table
|
---|
[1108] | 41 | table_ = Table(inname);
|
---|
| 42 | } else {
|
---|
| 43 | String formatString;
|
---|
| 44 | // formatSring , TableType, ascii file name, TableDesc name, table name, autoheader
|
---|
[1126] | 45 | table_ = readAsciiTable(formatString, Table::Plain, inname, "", "", True);
|
---|
| 46 | // do not keep aips++ table
|
---|
| 47 | table_.markForDelete();
|
---|
[1108] | 48 | }
|
---|
| 49 | baseTable_ = table_;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
[1126] | 52 | void LineCatalog::setStrengthLimits(double smin, double smax)
|
---|
[1108] | 53 | {
|
---|
| 54 | table_ = setLimits(smin, smax, "Column4");
|
---|
| 55 | }
|
---|
| 56 |
|
---|
[1126] | 57 | void LineCatalog::setFrequencyLimits(double fmin, double fmax)
|
---|
[1108] | 58 | {
|
---|
| 59 | table_ = setLimits(fmin, fmax, "Column2");
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | void LineCatalog::setPattern(const std::string& name, const std::string& stype)
|
---|
| 63 | {
|
---|
[1126] | 64 | //std::string mode = stype+"('"+name+"')";
|
---|
| 65 | std::string taql = "SELECT FROM $1 WHERE Column1 == pattern('"+name+"')";
|
---|
| 66 | cerr << taql << endl;
|
---|
[1108] | 67 | Table tmp = tableCommand(taql, table_);
|
---|
[1126] | 68 | if (tmp.nrow() > 0) table_ = tmp.sort("Column2");
|
---|
[1108] | 69 | else throw(AipsError("No match."));
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[1126] | 72 | Table LineCatalog::setLimits(double lmin, double lmax, const std::string& colname)
|
---|
[1108] | 73 | {
|
---|
[1126] | 74 | Table tmp = table_(table_.col(colname) > lmin && table_.col(colname) < lmax);
|
---|
| 75 | if (tmp.nrow() > 0) return tmp.sort("Column2");
|
---|
[1108] | 76 | else throw(AipsError("No match."));
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | void LineCatalog::save(const std::string& name)
|
---|
| 80 | {
|
---|
| 81 | Path path(name);
|
---|
| 82 | std::string inname = path.expandedName();
|
---|
| 83 | table_.deepCopy(inname, Table::New);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[1113] | 86 | std::string LineCatalog::summary(int row) const
|
---|
| 87 | {
|
---|
| 88 | std::string stlout;
|
---|
| 89 | ostringstream oss;
|
---|
| 90 | oss << asap::SEPERATOR << endl;
|
---|
| 91 | oss << "Line Catalog summary" << endl;
|
---|
| 92 | oss << asap::SEPERATOR << endl << endl;
|
---|
| 93 | if (row == -1) {
|
---|
[1126] | 94 | for (uint i=0; i<table_.nrow(); ++i) {
|
---|
| 95 | oss << std::right << setw(7) << i << setw(2) << "";
|
---|
| 96 | oss << std::left << setw(20) << getName(i);
|
---|
[1113] | 97 | oss << setw(12) << setprecision(8) << std::left << getFrequency(i);
|
---|
| 98 | oss << endl;
|
---|
| 99 | }
|
---|
| 100 | } else {
|
---|
[1126] | 101 | if ( row < table_.nrow() ) {
|
---|
| 102 | oss << std::right << setw(7) << row << setw(2) << "";
|
---|
| 103 | oss << std::left << setw(20) << getName(row);
|
---|
| 104 | oss << setw(12) << setprecision(8) << std::left << getFrequency(row);
|
---|
| 105 | oss << endl;
|
---|
| 106 | } else {
|
---|
| 107 | throw(AipsError("Row doesn't exist"));
|
---|
| 108 | }
|
---|
[1113] | 109 | }
|
---|
| 110 | /// @todo implement me
|
---|
| 111 | return String(oss);
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | /*!
|
---|
| 115 | \fn asap::LineCatalog::getName(int row)
|
---|
| 116 | */
|
---|
| 117 | std::string LineCatalog::getName(uint row) const
|
---|
| 118 | {
|
---|
| 119 | ROScalarColumn<String> col(table_, "Column1");
|
---|
| 120 | return col(row);
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | double asap::LineCatalog::getFrequency(uint row) const
|
---|
| 124 | {
|
---|
| 125 | ROScalarColumn<Double> col(table_, "Column2");
|
---|
| 126 | return col(row);
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 |
|
---|
[1108] | 130 | } // namespace
|
---|
[1113] | 131 |
|
---|
| 132 |
|
---|