source: branches/alma/src/STWeather.cpp@ 1391

Last change on this file since 1391 was 856, checked in by mar637, 19 years ago

added name()
reworked copy constructor for (Table tab) to also pass name to base class

File size: 3.3 KB
Line 
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
24using namespace casa;
25
26namespace asap {
27
28const casa::String STWeather::name_ = "WEATHER";
29
30STWeather::STWeather(const Scantable& parent) :
31 STSubTable( parent, name_ )
32{
33 setup();
34}
35
36
37asap::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
47STWeather::~STWeather()
48{
49}
50
51STWeather & 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
65void 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
82uInt 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 uInt nrow = table_.nrow();
88 if ( nrow == 0 ) {
89 table_.addRow();
90 TableRow row(table_);
91 TableRecord& rec = row.record();
92 RecordFieldPtr< Float > rfp;
93 rfp.attachToRecord(rec,"TEMPERATURE");
94 *rfp = temp;
95 rfp.attachToRecord(rec,"PRESSURE");
96 *rfp = pressure;
97 rfp.attachToRecord(rec,"HUMIDITY");
98 *rfp = humidity;
99 rfp.attachToRecord(rec,"WINDSPEED");
100 *rfp = wspeed;
101 rfp.attachToRecord(rec,"WINDAZ");
102 *rfp = waz;
103 row.put(table_.nrow()-1, rec);
104 }
105 return 0;
106}
107
108void STWeather::getEntry( Float& temperature, Float& pressure,
109 Float& humidity, Float& windspeed, Float& windaz,
110 uInt id )
111{
112 Table t = table_(table_.col("ID") == Int(id) );
113 if (t.nrow() == 0 ) {
114 throw(AipsError("STWeather::getEntry - id out of range"));
115 }
116 ROTableRow row(t);
117 // get first row - there should only be one matching id
118 const TableRecord& rec = row.get(0);
119 temperature = rec.asFloat("TEMPERATURE");
120 pressure = rec.asDouble("PRESSURE");
121 humidity = rec.asDouble("HUMIDITY");
122 windspeed = rec.asDouble("WINDSPEED");
123 windaz = rec.asDouble("WINDAZ");
124}
125
126}
127
Note: See TracBrowser for help on using the repository browser.