source: trunk/src/STMolecules.cpp@ 816

Last change on this file since 816 was 809, checked in by mar637, 19 years ago

Moelecule subtable for Scantable. Initial revision.

File size: 1.8 KB
Line 
1//
2// C++ Implementation: STMolecules
3//
4// Description:
5//
6//
7// Author: Malte Marquarding <asap@atnf.csiro.au>, (C) 2006
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#include <casa/Exceptions/Error.h>
13#include <tables/Tables/TableDesc.h>
14#include <tables/Tables/SetupNewTab.h>
15#include <tables/Tables/ScaColDesc.h>
16#include <tables/Tables/TableRecord.h>
17#include <tables/Tables/TableParse.h>
18#include <tables/Tables/TableRow.h>
19#include <casa/Containers/RecordField.h>
20
21#include "STMolecules.h"
22
23
24using namespace casa;
25
26namespace asap {
27
28const casa::String STMolecules::name_ = "MOLECULES";
29
30STMolecules::STMolecules(casa::Table::TableType tt) :
31 STSubTable( name_, tt )
32{
33 setup();
34}
35
36
37STMolecules::~STMolecules()
38{
39}
40
41void asap::STMolecules::setup( )
42{
43 // add to base class table
44 table_.addColumn(ScalarColumnDesc<Double>("RESTFREQUENCY"));
45 table_.addColumn(ScalarColumnDesc<String>("NAME"));
46 table_.addColumn(ScalarColumnDesc<String>("FORMATTEDNAME"));
47 table_.rwKeywordSet().define("UNIT", String("Hz"));
48 // new cached columns
49 restfreqCol_.attach(table_,"RESTFREQUENCY");
50 nameCol_.attach(table_,"NAME");
51 formattednameCol_.attach(table_,"FORMATTEDNAME");
52}
53
54uInt STMolecules::addEntry( Double restfreq, const String& name,
55 const String& formattedname )
56{
57
58 Table result =
59 table_( near(table_.col("RESTFREQUENCY"), restfreq) );
60 uInt resultid = 0;
61 if ( result.nrow() > 0) {
62 ROScalarColumn<uInt> c(result, "ID");
63 c.get(0, resultid);
64 } else {
65 uInt rno = table_.nrow();
66 table_.addRow();
67 // get last assigned _id and increment
68 if ( rno > 0 ) {
69 idCol_.get(rno-1, resultid);
70 resultid++;
71 }
72 restfreqCol_.put(rno, restfreq);
73 nameCol_.put(rno, name);
74 formattednameCol_.put(rno, formattedname);
75 idCol_.put(rno, resultid);
76 }
77 return resultid;
78}
79
80}
Note: See TracBrowser for help on using the repository browser.