source: trunk/src/LineCatalog.cpp @ 1259

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

Merge from Release2.1.0b tag

File size: 3.5 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 == pattern('"+name+"')";
66  cerr << taql << endl;
67  Table tmp = tableCommand(taql, table_);
68  if (tmp.nrow() > 0) table_ = tmp.sort("Column2");
69  else throw(AipsError("No match."));
70}
71
72Table LineCatalog::setLimits(double lmin, double lmax, const std::string& colname)
73{
74  Table tmp = table_(table_.col(colname) > lmin && table_.col(colname) < lmax);
75  if (tmp.nrow() > 0) return tmp.sort("Column2");
76  else throw(AipsError("No match."));
77}
78
79void 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
86std::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) {
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);
97      oss << setw(12) << setprecision(8) << std::left << getFrequency(i);
98      oss << setw(12) << setprecision(8) << std::left << getStrength(i);
99      oss << endl;
100    }
101  } else {
102      if ( row < table_.nrow() ) {
103        oss << std::right << setw(7) << row << setw(2) << "";
104        oss << std::left << setw(20) << getName(row);
105        oss << setw(12) << setprecision(8) << std::left << getFrequency(row);
106        oss << setw(12) << setprecision(8) << std::left << getStrength(row);
107        oss << endl;
108      } else {
109        throw(AipsError("Row doesn't exist"));
110      }
111  }
112  /// @todo implement me
113  return String(oss);
114}
115
116/*!
117    \fn asap::LineCatalog::getName(int row)
118 */
119std::string LineCatalog::getName(uint row) const
120{
121  ROScalarColumn<String> col(table_, "Column1");
122  return col(row);
123}
124
125double asap::LineCatalog::getFrequency(uint row) const
126{
127  ROScalarColumn<Double> col(table_, "Column2");
128  return col(row);
129}
130
131double asap::LineCatalog::getStrength(uint row) const
132{
133  ROScalarColumn<Double> col(table_, "Column3");
134  return col(row);
135}
136
137
138} // namespace
139
140
Note: See TracBrowser for help on using the repository browser.