source: trunk/src/FillerBase.cpp@ 2225

Last change on this file since 2225 was 2209, checked in by Takeshi Nakazato, 13 years ago

New Development: No

JIRA Issue: Yes CAS-1913

Ready for Test: No

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Added setWeather2 and setTcal2 that are used in asdm2ASAP.


File size: 8.5 KB
RevLine 
[1778]1//
2// C++ Interface: FillerBase
3//
4// Description:
5//
6//
7// Author: Malte Marquarding <asap@atnf.csiro.au>, (C) 2010
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12
[1780]13#include <casa/Containers/RecordField.h>
[2209]14#include <tables/Tables/ExprNode.h>
[1778]15
[1780]16#include "FillerBase.h"
17
[1778]18using namespace casa;
19
[1786]20namespace asap {
21
22FillerBase::FillerBase(casa::CountedPtr<Scantable> stable) :
23 table_(stable)
[1778]24{
[1795]25 row_ = TableRow(table_->table());
[1778]26}
27
[1793]28void FillerBase::setHeader(const STHeader& header)
29{
30 table_->setHeader(header);
31}
32
[1778]33void FillerBase::setSpectrum(const Vector<Float>& spectrum,
[1788]34 const Vector<uChar>& flags,
35 const Vector<Float>& tsys)
[1778]36{
37 RecordFieldPtr< Array<Float> > specCol(row_.record(), "SPECTRA");
38 RecordFieldPtr< Array<uChar> > flagCol(row_.record(), "FLAGTRA");
[1788]39 RecordFieldPtr< Array<Float> > tsysCol(row_.record(), "TSYS");
40
[1876]41 //*specCol = spectrum;
42 //*flagCol = flags;
43 //*tsysCol = tsys;
44 specCol.define(spectrum);
45 flagCol.define(flags);
46 tsysCol.define(tsys);
[1778]47}
48
[1803]49void FillerBase::setFlagrow(uInt flag)
50{
51 RecordFieldPtr<uInt> flagrowCol(row_.record(), "FLAGROW");
52 *flagrowCol = flag;
53}
[1788]54
55void FillerBase::setOpacity(Float opacity)
56{
57 RecordFieldPtr<Float> tauCol(row_.record(), "OPACITY") ;
58 *tauCol = opacity ;
59}
60
[1778]61void FillerBase::setIndex(uInt scanno, uInt cycleno, uInt ifno, uInt polno,
62 uInt beamno)
63{
64 RecordFieldPtr<uInt> beamCol(row_.record(), "BEAMNO");
65 RecordFieldPtr<uInt> ifCol(row_.record(), "IFNO");
66 RecordFieldPtr<uInt> polCol(row_.record(), "POLNO");
67 RecordFieldPtr<uInt> cycleCol(row_.record(), "CYCLENO");
[1780]68 RecordFieldPtr<uInt> scanCol(row_.record(), "SCANNO");
[1778]69 *beamCol = beamno;
70 *cycleCol = cycleno;
71 *ifCol = ifno;
72 *polCol = polno;
73 *scanCol = scanno;
74}
75
76void FillerBase::setFrequency(Double refpix, Double refval,
[1780]77 Double incr)
[1778]78{
79 /// @todo this has to change when nchan isn't global anymore
80 uInt id= table_->frequencies().addEntry(refpix, refval, incr);
81 RecordFieldPtr<uInt> mfreqidCol(row_.record(), "FREQ_ID");
82 *mfreqidCol = id;
83
84}
85
86
[1780]87void FillerBase::setMolecule(const Vector<Double>& restfreq)
[1778]88{
[1780]89 Vector<String> tmp;
90 uInt id = table_->molecules().addEntry(restfreq, tmp, tmp);
[1778]91 RecordFieldPtr<uInt> molidCol(row_.record(), "MOLECULE_ID");
92 *molidCol = id;
93}
94
[1780]95void FillerBase::setDirection(const Vector<Double>& dir,
[1778]96 Float az, Float el)
97{
98 RecordFieldPtr<Array<Double> > dirCol(row_.record(), "DIRECTION");
99 *dirCol = dir;
100 RecordFieldPtr<Float> azCol(row_.record(), "AZIMUTH");
101 *azCol = az;
102 RecordFieldPtr<Float> elCol(row_.record(), "ELEVATION");
103 *elCol = el;
104}
105
106void FillerBase::setFocus(Float pa, Float faxis,
107 Float ftan, Float frot)
108{
109 RecordFieldPtr<uInt> mfocusidCol(row_.record(), "FOCUS_ID");
110 uInt id = table_->focus().addEntry(pa, faxis, ftan, frot);
111 *mfocusidCol = id;
112}
113
[1809]114void FillerBase::setTime(Double mjd, Double interval)
[1778]115{
116 RecordFieldPtr<Double> mjdCol(row_.record(), "TIME");
117 *mjdCol = mjd;
118 RecordFieldPtr<Double> intCol(row_.record(), "INTERVAL");
119 *intCol = interval;
120
121}
122
123void FillerBase::setWeather(Float temperature, Float pressure,
124 Float humidity,
125 Float windspeed, Float windaz)
126{
127 uInt id = table_->weather().addEntry(temperature, pressure,
128 humidity, windspeed, windaz);
129 RecordFieldPtr<uInt> mweatheridCol(row_.record(), "WEATHER_ID");
130 *mweatheridCol = id;
131}
132
133void FillerBase::setTcal(const String& tcaltime,
134 const Vector<Float>& tcal)
135{
136 uInt id = table_->tcal().addEntry(tcaltime, tcal);
137 RecordFieldPtr<uInt> mcalidCol(row_.record(), "TCAL_ID");
138 *mcalidCol = id;
139}
140
141void FillerBase::setScanRate(const Vector<Double>& srate)
142{
143 RecordFieldPtr<Array<Double> > srateCol(row_.record(), "SCANRATE");
144 *srateCol = srate;
145}
146
147void FillerBase::setReferenceBeam(Int beamno)
148{
149 RecordFieldPtr<Int> rbCol(row_.record(), "REFBEAMNO");
150 *rbCol = beamno;
151}
152
153void FillerBase::setSource(const std::string& name, Int type,
154 const std::string& fieldname,
155 const Vector<Double>& dir,
156 const Vector<Double>& propermot,
[1780]157 Double velocity)
[1778]158{
159 RecordFieldPtr<String> srcnCol(row_.record(), "SRCNAME");
[1780]160 *srcnCol = name;
[1778]161 RecordFieldPtr<Int> srctCol(row_.record(), "SRCTYPE");
162 *srctCol = type;
163 RecordFieldPtr<String> fieldnCol(row_.record(), "FIELDNAME");
164 *fieldnCol = fieldname;
165 RecordFieldPtr<Array<Double> > spmCol(row_.record(), "SRCPROPERMOTION");
[1780]166 *spmCol = propermot;
[1778]167 RecordFieldPtr<Array<Double> > sdirCol(row_.record(), "SRCDIRECTION");
[1780]168 *sdirCol = dir;
[1778]169 RecordFieldPtr<Double> svelCol(row_.record(), "SRCVELOCITY");
[1780]170 *svelCol = velocity;
[1778]171}
172
173void FillerBase::commitRow()
174{
175 table_->table().addRow();
176 row_.put(table_->table().nrow()-1);
177}
178
[2209]179void FillerBase::setWeather2(Float temperature,
180 Float pressure,
181 Float humidity,
182 Float windspeed,
183 Float windaz)
184{
185 uInt id ;
186 Table tab = table_->weather().table() ;
187 Table subt = tab( tab.col("TEMPERATURE") == temperature \
188 && tab.col("PRESSURE") == pressure \
189 && tab.col("HUMIDITY") == humidity \
190 && tab.col("WINDSPEED") == windspeed \
191 && tab.col("WINDAZ") == windaz ) ;
192 Int nrow = tab.nrow() ;
193 Int nrowSel = subt.nrow() ;
194 if ( nrowSel == 0 ) {
195 tab.addRow( 1, True ) ;
196 TableRow row( tab ) ;
197 TableRecord &rec = row.record() ;
198 RecordFieldPtr<casa::uInt> rfpi ;
199 rfpi.attachToRecord( rec, "ID" ) ;
200 *rfpi = (uInt)nrow ;
201 RecordFieldPtr<casa::Float> rfp ;
202 rfp.attachToRecord( rec, "TEMPERATURE" ) ;
203 *rfp = temperature ;
204 rfp.attachToRecord( rec, "PRESSURE" ) ;
205 *rfp = pressure ;
206 rfp.attachToRecord( rec, "HUMIDITY" ) ;
207 *rfp = humidity ;
208 rfp.attachToRecord( rec, "WINDSPEED" ) ;
209 *rfp = windspeed ;
210 rfp.attachToRecord( rec, "WINDAZ" ) ;
211 *rfp = windaz ;
212 row.put( nrow, rec ) ;
213 id = (uInt)nrow ;
214 }
215 else {
216 ROTableColumn tc( subt, "ID" ) ;
217 id = tc.asuInt( 0 ) ;
218 }
219 RecordFieldPtr<uInt> mweatheridCol(row_.record(), "WEATHER_ID");
220 *mweatheridCol = id;
221}
222
223void FillerBase::setTcal2(const String& tcaltime,
224 const Vector<Float>& tcal)
225{
226 uInt id ;
227 Table tab = table_->tcal().table() ;
228 Int nrow = tab.nrow() ;
229 Vector<uInt> rowList( 0 ) ;
230 ArrayColumn<Float> tcalCol( tab, "TCAL" ) ;
231 TableColumn timeCol( tab, "TIME" ) ;
232 TableColumn idCol( tab, "ID" ) ;
233 uInt nelem = tcal.nelements() ;
234 for ( Int irow = 0 ; irow < nrow ; irow++ ) {
235 if ( tcalCol.shape(irow)[0] == nelem ) {
236 rowList.resize( rowList.nelements()+1, True ) ;
237 rowList[rowList.nelements()-1] = irow ;
238 }
239 }
240
241 //cout << "rowList = " << rowList << endl ;
242
243 if ( rowList.nelements() == 0 ) {
244 // add new row
245 tab.addRow( 1 ) ;
246 //cout << "tab.nrow() = " << tab.nrow() << endl ;
247 tcalCol.put( nrow, tcal ) ;
248 timeCol.putScalar( nrow, tcaltime ) ;
249 id = (uInt)nrow ;
250 idCol.putScalar( nrow, id ) ;
251 }
252 else {
253 uInt ichan = 0 ;
254 while ( rowList.nelements() > 1 && ichan < nelem ) {
255 Vector<uInt> tmp = rowList.copy() ;
256 rowList.resize( 0 ) ;
257 for ( uInt irow = 0 ; irow < tmp.nelements() ; irow++ ) {
258 Vector<Float> t = tcalCol( tmp[irow] ) ;
259 if ( t[ichan] == tcal[ichan] ) {
260 rowList.resize( rowList.nelements()+1, True ) ;
261 rowList[rowList.nelements()-1] = irow ;
262 }
263 }
264 ichan++ ;
265 }
266
267 //cout << "updated rowList = " << rowList << endl ;
268
269 if ( rowList.nelements() == 0 ) {
270 // add new row
271 tab.addRow( 1, True ) ;
272 //cout << "tab.nrow() = " << tab.nrow() << endl ;
273 tcalCol.put( nrow, tcal ) ;
274 timeCol.putScalar( nrow, tcaltime ) ;
275 id = (uInt)nrow ;
276 idCol.putScalar( nrow, id ) ;
277 }
278 else {
279 Vector<Float> t = tcalCol( rowList[0] ) ;
280 if ( allEQ( t, tcal ) ) {
281 ROTableColumn tc( tab, "ID" ) ;
282 id = tc.asuInt( rowList[0] ) ;
283 }
284 else {
285 // add new row
286 tab.addRow( 1, True ) ;
287 //cout << "tab.nrow() = " << tab.nrow() << endl ;
288 tcalCol.put( nrow, tcal ) ;
289 timeCol.putScalar( nrow, tcaltime ) ;
290 id = (uInt)nrow ;
291 idCol.putScalar( nrow, id ) ;
292 }
293 }
294 }
295
296 RecordFieldPtr<uInt> mcalidCol(row_.record(), "TCAL_ID");
297 *mcalidCol = id;
298}
299
[1778]300};
Note: See TracBrowser for help on using the repository browser.