source: trunk/src/LineCatalog.cpp @ 1126

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

added linecatalog to python inteface

File size: 3.3 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 << 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 << endl;
106      } else {
107        throw(AipsError("Row doesn't exist"));
108      }
109  }
110  /// @todo implement me
111  return String(oss);
112}
113
114/*!
115    \fn asap::LineCatalog::getName(int row)
116 */
117std::string LineCatalog::getName(uint row) const
118{
119  ROScalarColumn<String> col(table_, "Column1");
120  return col(row);
121}
122
123double asap::LineCatalog::getFrequency(uint row) const
124{
125  ROScalarColumn<Double> col(table_, "Column2");
126  return col(row);
127}
128
129
130} // namespace
131
132
Note: See TracBrowser for help on using the repository browser.