1 | // |
---|
2 | // C++ Implementation: STWeather |
---|
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 "STWeather.h" |
---|
22 | |
---|
23 | |
---|
24 | using namespace casa; |
---|
25 | |
---|
26 | namespace asap { |
---|
27 | |
---|
28 | const casa::String STWeather::name_ = "WEATHER"; |
---|
29 | |
---|
30 | STWeather::STWeather(const Scantable& parent) : |
---|
31 | STSubTable( parent, name_ ) |
---|
32 | { |
---|
33 | setup(); |
---|
34 | } |
---|
35 | |
---|
36 | |
---|
37 | asap::STWeather::STWeather( casa::Table tab ) : STSubTable(tab, name_) |
---|
38 | { |
---|
39 | temperatureCol_.attach(table_,"TEMPERATURE"); |
---|
40 | pressureCol_.attach(table_,"PRESSURE"); |
---|
41 | humidityCol_.attach(table_,"HUMIDITY"); |
---|
42 | windspeedCol_.attach(table_,"WINDSPEED"); |
---|
43 | windazCol_.attach(table_,"WINDAZ"); |
---|
44 | |
---|
45 | } |
---|
46 | |
---|
47 | STWeather::~STWeather() |
---|
48 | { |
---|
49 | } |
---|
50 | |
---|
51 | STWeather & asap::STWeather::operator =( const STWeather & other ) |
---|
52 | { |
---|
53 | if ( this != &other ) { |
---|
54 | static_cast<STSubTable&>(*this) = other; |
---|
55 | temperatureCol_.attach(table_,"TEMPERATURE"); |
---|
56 | pressureCol_.attach(table_,"PRESSURE"); |
---|
57 | humidityCol_.attach(table_,"HUMIDITY"); |
---|
58 | windspeedCol_.attach(table_,"WINDSPEED"); |
---|
59 | windazCol_.attach(table_,"WINDAZ"); |
---|
60 | } |
---|
61 | return *this; |
---|
62 | } |
---|
63 | |
---|
64 | |
---|
65 | void asap::STWeather::setup( ) |
---|
66 | { |
---|
67 | // add to base class table |
---|
68 | table_.addColumn(ScalarColumnDesc<Float>("TEMPERATURE")); |
---|
69 | table_.addColumn(ScalarColumnDesc<Float>("PRESSURE")); |
---|
70 | table_.addColumn(ScalarColumnDesc<Float>("HUMIDITY")); |
---|
71 | table_.addColumn(ScalarColumnDesc<Float>("WINDSPEED")); |
---|
72 | table_.addColumn(ScalarColumnDesc<Float>("WINDAZ")); |
---|
73 | |
---|
74 | // new cached columns |
---|
75 | temperatureCol_.attach(table_,"TEMPERATURE"); |
---|
76 | pressureCol_.attach(table_,"PRESSURE"); |
---|
77 | humidityCol_.attach(table_,"HUMIDITY"); |
---|
78 | windspeedCol_.attach(table_,"WINDSPEED"); |
---|
79 | windazCol_.attach(table_,"WINDAZ"); |
---|
80 | } |
---|
81 | |
---|
82 | uInt STWeather::addEntry( Float temp, Float pressure, Float humidity, |
---|
83 | Float wspeed, Float waz ) |
---|
84 | { |
---|
85 | /// @todo this is a zero implementation as none of the telescopes |
---|
86 | /// fills in this information (yet) |
---|
87 | // test if this already exists |
---|
88 | Table result = table_( near(table_.col("TEMPERATURE"), temp) |
---|
89 | && near(table_.col("PRESSURE"), pressure) |
---|
90 | && near(table_.col("WINDSPEED"), wspeed) |
---|
91 | && near(table_.col("WINDAZ"), waz) |
---|
92 | && near(table_.col("HUMIDITY"), humidity), 1 ); |
---|
93 | uInt resultid = 0; |
---|
94 | if ( result.nrow() > 0) { |
---|
95 | ROScalarColumn<uInt> c(result, "ID"); |
---|
96 | c.get(0, resultid); |
---|
97 | } else { |
---|
98 | uInt rno = table_.nrow(); |
---|
99 | table_.addRow(); |
---|
100 | // get last assigned freq_id and increment |
---|
101 | if ( rno > 0 ) { |
---|
102 | idCol_.get(rno-1, resultid); |
---|
103 | resultid++; |
---|
104 | } |
---|
105 | temperatureCol_.put(rno, temp); |
---|
106 | pressureCol_.put(rno, pressure); |
---|
107 | windspeedCol_.put(rno, wspeed); |
---|
108 | windazCol_.put(rno, waz); |
---|
109 | humidityCol_.put(rno, humidity); |
---|
110 | idCol_.put(rno, resultid); |
---|
111 | } |
---|
112 | return resultid; |
---|
113 | } |
---|
114 | |
---|
115 | void STWeather::getEntry( Float& temperature, Float& pressure, |
---|
116 | Float& humidity, Float& windspeed, Float& windaz, |
---|
117 | uInt id ) const |
---|
118 | { |
---|
119 | Table t = table_(table_.col("ID") == Int(id), 1 ); |
---|
120 | if (t.nrow() == 0 ) { |
---|
121 | throw(AipsError("STWeather::getEntry - id out of range")); |
---|
122 | } |
---|
123 | ROTableRow row(t); |
---|
124 | // get first row - there should only be one matching id |
---|
125 | const TableRecord& rec = row.get(0); |
---|
126 | temperature = rec.asFloat("TEMPERATURE"); |
---|
127 | pressure = rec.asDouble("PRESSURE"); |
---|
128 | humidity = rec.asDouble("HUMIDITY"); |
---|
129 | windspeed = rec.asDouble("WINDSPEED"); |
---|
130 | windaz = rec.asDouble("WINDAZ"); |
---|
131 | } |
---|
132 | |
---|
133 | } |
---|
134 | |
---|