source: trunk/src/LineCatalog.cpp@ 2141

Last change on this file since 2141 was 1534, checked in by Malte Marquarding, 16 years ago

Fix for Ticket #90; treating integer as double columns now

File size: 3.8 KB
RevLine 
[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
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);
[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]52void LineCatalog::setStrengthLimits(double smin, double smax)
[1108]53{
54 table_ = setLimits(smin, smax, "Column4");
55}
56
[1126]57void LineCatalog::setFrequencyLimits(double fmin, double fmax)
[1108]58{
59 table_ = setLimits(fmin, fmax, "Column2");
60}
61
62void LineCatalog::setPattern(const std::string& name, const std::string& stype)
63{
[1534]64 std::string mode = stype+"('"+name+"')";
65 std::string taql = "SELECT FROM $1 WHERE Column1 == " + mode;
[1108]66 Table tmp = tableCommand(taql, table_);
[1126]67 if (tmp.nrow() > 0) table_ = tmp.sort("Column2");
[1108]68 else throw(AipsError("No match."));
69}
70
[1126]71Table LineCatalog::setLimits(double lmin, double lmax, const std::string& colname)
[1108]72{
[1126]73 Table tmp = table_(table_.col(colname) > lmin && table_.col(colname) < lmax);
74 if (tmp.nrow() > 0) return tmp.sort("Column2");
[1108]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
[1113]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) {
[1126]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);
[1113]96 oss << setw(12) << setprecision(8) << std::left << getFrequency(i);
[1259]97 oss << setw(12) << setprecision(8) << std::left << getStrength(i);
[1113]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);
[1259]105 oss << setw(12) << setprecision(8) << std::left << getStrength(row);
[1126]106 oss << endl;
107 } else {
108 throw(AipsError("Row doesn't exist"));
109 }
[1113]110 }
111 return String(oss);
112}
113
[1534]114
[1113]115std::string LineCatalog::getName(uint row) const
116{
117 ROScalarColumn<String> col(table_, "Column1");
118 return col(row);
119}
120
[1534]121double LineCatalog::getFrequency(uint row) const
[1113]122{
[1534]123 return getDouble("Column2", row);
[1113]124}
125
[1534]126double LineCatalog::getStrength(uint row) const
[1259]127{
[1534]128 return getDouble("Column4", row);
[1259]129}
[1113]130
[1534]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}
[1259]143
[1108]144} // namespace
[1113]145
146
Note: See TracBrowser for help on using the repository browser.