source: trunk/src/LineCatalog.cpp@ 1114

Last change on this file since 1114 was 1113, checked in by mar637, 18 years ago

towards a working version

File size: 3.0 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);
40 if (f.isDirectory()) { //assume its 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 }
47 baseTable_ = table_;
48}
49
50void LineCatalog::setStrengthLimits(float smin, float smax)
51{
52 table_ = setLimits(smin, smax, "Column4");
53}
54
55void LineCatalog::setFrequencyLimits(float fmin, float fmax)
56{
57 table_ = setLimits(fmin, fmax, "Column2");
58}
59
60void LineCatalog::setPattern(const std::string& name, const std::string& stype)
61{
62 std::string mode = stype+"('"+name+"')";
63 std::string taql = "SELECT from $1 WHERE Column1 == "+mode;
64 Table tmp = tableCommand(taql, table_);
65 if (tmp.nrow() > 0) table_ = tmp;
66 else throw(AipsError("No match."));
67}
68
69Table LineCatalog::setLimits(float lmin, float lmax, const std::string& colname)
70{
71 Table tmp = table_(table_.col(colname) > lmin && table_.col(colname) > lmax);
72 if (tmp.nrow() > 0) return tmp;
73 else throw(AipsError("No match."));
74}
75
76void LineCatalog::save(const std::string& name)
77{
78 Path path(name);
79 std::string inname = path.expandedName();
80 table_.deepCopy(inname, Table::New);
81}
82
[1113]83std::string LineCatalog::summary(int row) const
84{
85 std::string stlout;
86 ostringstream oss;
87 oss << asap::SEPERATOR << endl;
88 oss << "Line Catalog summary" << endl;
89 oss << asap::SEPERATOR << endl << endl;
90 if (row == -1) {
91 Vector<uInt> rownrs = table_.rowNumbers(baseTable_);
92 for (uint i=0; i<rownrs.nelements(); ++i) {
93 oss << std::right << setw(7) << rownrs[i];
94 oss << std::left << setw(12) << getName(i);
95 oss << setw(12) << setprecision(8) << std::left << getFrequency(i);
96 oss << endl;
97 }
98 } else {
99 oss << std::right << setw(7) << row;
100 oss << std::left << setw(12) << getName(row);
101 oss << setw(12) << setprecision(8) << std::left << getFrequency(row);
102 oss << endl;
103 }
104 /// @todo implement me
105 return String(oss);
106}
107
108/*!
109 \fn asap::LineCatalog::getName(int row)
110 */
111std::string LineCatalog::getName(uint row) const
112{
113 ROScalarColumn<String> col(table_, "Column1");
114 return col(row);
115}
116
117double asap::LineCatalog::getFrequency(uint row) const
118{
119 ROScalarColumn<Double> col(table_, "Column2");
120 return col(row);
121}
122
123
[1108]124} // namespace
[1113]125
126
Note: See TracBrowser for help on using the repository browser.