source: trunk/src/STWeather.cpp @ 838

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

added getEntry to support export for STWriter.

File size: 2.7 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(casa::Table::TableType tt) :
31  STSubTable( name_, tt )
32{
33  setup();
34}
35
36
37STWeather::~STWeather()
38{
39}
40
41void asap::STWeather::setup( )
42{
43  // add to base class table
44  table_.addColumn(ScalarColumnDesc<Float>("TEMPERATURE"));
45  table_.addColumn(ScalarColumnDesc<Float>("PRESSURE"));
46  table_.addColumn(ScalarColumnDesc<Float>("HUMIDITY"));
47  table_.addColumn(ScalarColumnDesc<Float>("WINDSPEED"));
48  table_.addColumn(ScalarColumnDesc<Float>("WINDAZ"));
49
50  // new cached columns
51  temperatureCol_.attach(table_,"TEMPERATURE");
52  pressureCol_.attach(table_,"PRESSURE");
53  humidityCol_.attach(table_,"HUMIDITY");
54  windspeedCol_.attach(table_,"WINDSPEED");
55  windazCol_.attach(table_,"WINDAZ");
56}
57
58uInt STWeather::addEntry( Float temp, Float pressure, Float humidity,
59                          Float wspeed, Float waz )
60{
61  /// @todo this is a zero implementation as none of the telescopes
62  /// fills in this information (yet)
63  uInt nrow = table_.nrow();
64  if ( nrow == 0 ) {
65    table_.addRow();
66    TableRow row(table_);
67    TableRecord& rec = row.record();
68    RecordFieldPtr< Float > rfp;
69    rfp.attachToRecord(rec,"TEMPERATURE");
70    *rfp = temp;
71    rfp.attachToRecord(rec,"PRESSURE");
72    *rfp = pressure;
73    rfp.attachToRecord(rec,"HUMIDITY");
74    *rfp = humidity;
75    rfp.attachToRecord(rec,"WINDSPEED");
76    *rfp = wspeed;
77    rfp.attachToRecord(rec,"WINDAZ");
78    *rfp = waz;
79    row.put(table_.nrow()-1, rec);
80  }
81  return 0;
82}
83
84void STWeather::getEntry( Float& temperature, Float& pressure,
85                          Float& humidity, Float& windspeed, Float& windaz,
86                          uInt id )
87{
88  Table t = table_(table_.col("ID") == Int(id) );
89  if (t.nrow() == 0 ) {
90    throw(AipsError("STWeather::getEntry - id out of range"));
91  }
92  ROTableRow row(t);
93  // get first row - there should only be one matching id
94  const TableRecord& rec = row.get(0);
95  temperature = rec.asFloat("TEMPERATURE");
96  pressure = rec.asDouble("PRESSURE");
97  humidity = rec.asDouble("HUMIDITY");
98  windspeed = rec.asDouble("WINDSPEED");
99  windaz = rec.asDouble("WINDAZ");
100}
101
102}
103
Note: See TracBrowser for help on using the repository browser.