source: branches/hpc33/src/NROFiller.cpp@ 2449

Last change on this file since 2449 was 2289, checked in by ShinnosukeKawakami, 13 years ago

merged parallel branch to trunk

File size: 6.6 KB
Line 
1//
2// C++ Interface: NROFiller
3//
4// Description:
5// This class is a concrete class that derives from FillerBase class.
6// The class implements the following methods to be able to read NRO
7// data (45m and ASTE).
8//
9// open()
10// close()
11// fill()
12//
13//
14// Author: Takeshi Nakazato <takeshi.nakazato@nao.ac.jp>, (C) 2010
15//
16// Copyright: See COPYING file that comes with this distribution
17//
18//
19
20#include "NROFiller.h"
21#include "STHeader.h"
22#include <casa/Containers/Record.h>
23#include <casa/Quanta/MVTime.h>
24#include <atnf/PKSIO/SrcType.h>
25
26using namespace casa;
27
28namespace asap
29{
30NROFiller::NROFiller(CountedPtr<Scantable> stable)
31 : FillerBase(stable)
32{
33}
34
35NROFiller::~NROFiller()
36{
37 close() ;
38}
39
40 bool NROFiller::open(const std::string& filename, const Record& rec)
41{
42 bool status = true ;
43
44 // get appropriate reader object
45 String format ;
46 reader_ = getNROReader( filename, format ) ;
47 if ( reader_.null() == True ) {
48 status = false ;
49 return status ;
50 }
51
52 // get header information
53 STHeader hdr ;
54 if ( reader_->getHeaderInfo( hdr.nchan,
55 hdr.npol,
56 hdr.nif,
57 hdr.nbeam,
58 hdr.observer,
59 hdr.project,
60 hdr.obstype,
61 hdr.antennaname,
62 hdr.antennaposition,
63 hdr.equinox,
64 hdr.freqref,
65 hdr.reffreq,
66 hdr.bandwidth,
67 hdr.utc,
68 hdr.fluxunit,
69 hdr.epoch,
70 hdr.poltype ) ) {
71 status = false ;
72 return status ;
73 }
74
75 // 2010/07/30 TBD: Do we need to set frame here?
76 table_->frequencies().setFrame( hdr.freqref, true ) ;
77 table_->frequencies().setFrame( hdr.freqref, false ) ;
78
79 // set Header
80 setHeader( hdr ) ;
81
82 return status ;
83}
84
85void NROFiller::fill()
86{
87 // for each row
88 uInt nRow = reader_->getRowNum() ;
89 vector< vector<double > > freqs ;
90 uInt scanno ;
91 uInt cycleno ;
92 uInt ifno ;
93 uInt beamno ;
94 uInt polno ;
95 vector<double> fqs ;
96 Vector<Double> restfreq ;
97 uInt refbeamno ;
98 Double scantime ;
99 Double interval ;
100 String srcname ;
101 String fieldname ;
102 Vector<Float> spectra ;
103 Vector<uChar> flagtra ;
104 Vector<Float> tsys ;
105 Vector<Double> direction ;
106 Float azimuth ;
107 Float elevation ;
108 Float parangle = 0.0 ;
109 Float opacity ;
110 uInt tcalid ;
111 Int fitid ;
112 uInt focusid ;
113 Float temperature ;
114 Float pressure ;
115 Float humidity ;
116 Float windvel ;
117 Float winddir ;
118 Double srcvel ;
119 Vector<Double> propermotion( 2, 0.0 ) ;
120 Vector<Double> srcdir ;
121 Vector<Double> scanrate( 2, 0.0 ) ;
122 Int rowCount = 0 ;
123
124 STHeader header = table_->getHeader() ;
125 String obsType = header.obstype.substr( 0, 3 ) ;
126 Vector<Float> defaultTcal( 1, 1.0 ) ;
127 String tcalTime = MVTime( header.utc ).string( MVTime::YMD ) ;
128
129 // TCAL subtable rows
130 setTcal( tcalTime, defaultTcal ) ;
131
132 // FOCUS subtable rows
133 setFocus( parangle ) ;
134
135 for ( Int irow = 0 ; irow < (Int)nRow ; irow++ ) {
136 // check scan intent
137 string scanType = reader_->getScanType( irow ) ;
138 SrcType::type srcType = SrcType::NOTYPE ;
139
140 // skip "ZERO" scan
141 if ( scanType.compare( 0, 4, "ZERO" ) == 0 ) {
142 continue ;
143 }
144
145 // set srcType
146 if ( obsType == "POS" || obsType == "BEA" ) {
147 if ( scanType.compare( 0, 2, "ON" ) == 0 )
148 srcType = SrcType::PSON ;
149 else if ( scanType.compare( 0, 3, "OFF" ) == 0 )
150 srcType = SrcType::PSOFF ;
151 }
152 else if ( obsType == "FRE" ) {
153 if ( scanType.compare( 0, 2, "ON" ) == 0 )
154 srcType = SrcType::FSON ;
155 else if ( scanType.compare( 0, 3, "OFF" ) == 0 )
156 srcType = SrcType::FSOFF ;
157 }
158
159 // get scan ifnromation
160 if ( reader_->getScanInfo( irow,
161 scanno,
162 cycleno,
163 ifno,
164 beamno,
165 polno,
166 fqs,
167 restfreq,
168 refbeamno,
169 scantime,
170 interval,
171 srcname,
172 fieldname,
173 spectra,
174 flagtra,
175 tsys,
176 direction,
177 azimuth,
178 elevation,
179 parangle,
180 opacity,
181 tcalid,
182 fitid,
183 focusid,
184 temperature,
185 pressure,
186 humidity,
187 windvel,
188 winddir,
189 srcvel,
190 propermotion,
191 srcdir,
192 scanrate ) ) {
193 throw AipsError( "Failed to read scan record" ) ;
194 return ;
195 }
196
197 // set IDs and subtable rows
198 // FREQUENCIES subtable row
199 setFrequency( (Double)fqs[0], (Double)fqs[1], (Double)fqs[2] ) ;
200
201 // MOLECULES subtable row
202 setMolecule( restfreq ) ;
203
204 // WEATHER subtable row
205 float p = 7.5 * temperature / ( 273.3 + temperature ) ;
206 float sh = 6.11 * powf( 10, p ) ;
207 temperature += 273.15 ; // C->K
208 winddir *= C::degree ; // deg->rad
209 humidity /= sh ; // P_H2O->relative humidity
210 setWeather2( temperature, pressure, humidity, windvel, winddir ) ;
211
212 // set row attributes
213 // SPECTRA, FLAGTRA, and TSYS
214 setSpectrum( spectra, flagtra, tsys ) ;
215
216 // SCANNO, CYCLENO, IFNO, POLNO, and BEAMNO
217 setIndex( scanno, cycleno, ifno, polno, beamno ) ;
218
219 // REFBEAMNO
220 setReferenceBeam( (Int)refbeamno ) ;
221
222 // DIRECTION
223 setDirection( direction, azimuth, elevation ) ;
224
225 // TIME and INTERVAL
226 setTime( scantime, interval ) ;
227
228 // SRCNAME, SRCTYPE, FIELDNAME, SRCDIRECTION, SRCPROPERMOTION, and SRCVELOCITY
229 setSource( srcname, srcType, fieldname, srcdir, propermotion, srcvel ) ;
230
231 // SCANRATE
232 setScanRate( scanrate ) ;
233
234 // OPACITY
235 setOpacity( opacity ) ;
236
237 // finally, commit row
238 commitRow() ;
239
240 // count up number of row committed
241 rowCount++ ;
242 }
243}
244
245void NROFiller::close()
246{
247 if (reader_.null() != False) {
248 reader_ = 0;
249 }
250 table_ = 0;
251}
252
253};
254
Note: See TracBrowser for help on using the repository browser.