source: branches/alma/src/LineCatalog.cpp@ 1686

Last change on this file since 1686 was 1603, checked in by TakTsutsumi, 15 years ago

New Development: No, merge with asap2.3.1

JIRA Issue: Yes CAS-1450

Ready to Release: Yes/No

Interface Changes: Yes/No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes

Module(s): single dish

Description: Upgrade of alma branch based on ASAP2.2.0

(rev.1562) to ASAP2.3.1 (rev.1561)


File size: 3.8 KB
Line 
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>
18#include <casa/iostream.h>
19#include <casa/iomanip.h>
20#include <casa/OS/Path.h>
21#include <casa/OS/File.h>
22#include <casa/Arrays/Vector.h>
23#include <tables/Tables/ReadAsciiTable.h>
24#include <tables/Tables/TableParse.h>
25#include <tables/Tables/ScalarColumn.h>
26
27#include "STAttr.h"
28#include "LineCatalog.h"
29
30using namespace casa;
31
32namespace asap
33{
34
35LineCatalog::LineCatalog(const std::string& name)
36{
37 Path path(name);
38 std::string inname = path.expandedName();
39 File f(inname);
40 if (f.isDirectory()) { //assume it's a table
41 table_ = Table(inname);
42 } else {
43 String formatString;
44 // formatSring , TableType, ascii file name, TableDesc name, table name, autoheader
45 table_ = readAsciiTable(formatString, Table::Plain, inname, "", "", True);
46 // do not keep aips++ table
47 table_.markForDelete();
48 }
49 baseTable_ = table_;
50}
51
52void LineCatalog::setStrengthLimits(double smin, double smax)
53{
54 table_ = setLimits(smin, smax, "Column4");
55}
56
57void LineCatalog::setFrequencyLimits(double fmin, double fmax)
58{
59 table_ = setLimits(fmin, fmax, "Column2");
60}
61
62void LineCatalog::setPattern(const std::string& name, const std::string& stype)
63{
64 std::string mode = stype+"('"+name+"')";
65 std::string taql = "SELECT FROM $1 WHERE Column1 == " + mode;
66 Table tmp = tableCommand(taql, table_);
67 if (tmp.nrow() > 0) table_ = tmp.sort("Column2");
68 else throw(AipsError("No match."));
69}
70
71Table LineCatalog::setLimits(double lmin, double lmax, const std::string& colname)
72{
73 Table tmp = table_(table_.col(colname) > lmin && table_.col(colname) < lmax);
74 if (tmp.nrow() > 0) return tmp.sort("Column2");
75 else throw(AipsError("No match."));
76}
77
78void LineCatalog::save(const std::string& name)
79{
80 Path path(name);
81 std::string inname = path.expandedName();
82 table_.deepCopy(inname, Table::New);
83}
84
85std::string LineCatalog::summary(int row) const
86{
87 std::string stlout;
88 ostringstream oss;
89 oss << asap::SEPERATOR << endl;
90 oss << "Line Catalog summary" << endl;
91 oss << asap::SEPERATOR << endl << endl;
92 if (row == -1) {
93 for (uint i=0; i<table_.nrow(); ++i) {
94 oss << std::right << setw(7) << i << setw(2) << "";
95 oss << std::left << setw(20) << getName(i);
96 oss << setw(12) << setprecision(8) << std::left << getFrequency(i);
97 oss << setw(12) << setprecision(8) << std::left << getStrength(i);
98 oss << endl;
99 }
100 } else {
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 << setw(12) << setprecision(8) << std::left << getStrength(row);
106 oss << endl;
107 } else {
108 throw(AipsError("Row doesn't exist"));
109 }
110 }
111 return String(oss);
112}
113
114
115std::string LineCatalog::getName(uint row) const
116{
117 ROScalarColumn<String> col(table_, "Column1");
118 return col(row);
119}
120
121double LineCatalog::getFrequency(uint row) const
122{
123 return getDouble("Column2", row);
124}
125
126double LineCatalog::getStrength(uint row) const
127{
128 return getDouble("Column4", row);
129}
130
131double LineCatalog::getDouble(const std::string& colname, uint row) const {
132 DataType dtype = table_.tableDesc().columnDesc(colname).dataType();
133 if (dtype == TpDouble) {
134 ROScalarColumn<Double> col(table_, colname);
135 return col(row);
136 } else if (dtype == TpInt) {
137 ROScalarColumn<Int> col(table_, colname);
138 return Double(col(row));
139 } else {
140 throw AipsError("Column " + colname + "doesn't contain numerical values." );
141 }
142}
143
144} // namespace
145
146
Note: See TracBrowser for help on using the repository browser.