source: trunk/external-alma/atnf/PKSIO/NRODataset.h@ 2541

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

New Development: No

JIRA Issue: No

Ready for Test: Yes

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...

Defined template function for debug output.


File size: 14.3 KB
Line 
1//#---------------------------------------------------------------------------
2//# NRODataset.h: Base class for NRO dataset.
3//#---------------------------------------------------------------------------
4//# Copyright (C) 2000-2006
5//# Associated Universities, Inc. Washington DC, USA.
6//#
7//# This library is free software; you can redistribute it and/or modify it
8//# under the terms of the GNU Library General Public License as published by
9//# the Free Software Foundation; either version 2 of the License, or (at your
10//# option) any later version.
11//#
12//# This library is distributed in the hope that it will be useful, but WITHOUT
13//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15//# License for more details.
16//#
17//# You should have received a copy of the GNU Library General Public License
18//# along with this library; if not, write to the Free Software Foundation,
19//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
20//#
21//# Correspondence concerning AIPS++ should be addressed as follows:
22//# Internet email: aips2-request@nrao.edu.
23//# Postal address: AIPS++ Project Office
24//# National Radio Astronomy Observatory
25//# 520 Edgemont Road
26//# Charlottesville, VA 22903-2475 USA
27//#
28//# $Id$
29//#---------------------------------------------------------------------------
30//# Original: 2009/02/27, Takeshi Nakazato, NAOJ
31//#---------------------------------------------------------------------------
32
33#ifndef NRO_DATASET_H
34#define NRO_DATASET_H
35
36#include <string>
37#include <stdio.h>
38#include <vector>
39#include <iostream>
40
41//#include <casa/aips.h>
42#include <casa/Logging/LogIO.h>
43#include <casa/Containers/Record.h>
44#include <atnf/PKSIO/NRODataRecord.h>
45#include <casa/namespace.h>
46#include <casa/iomanip.h>
47
48#define SCAN_HEADER_SIZE 424
49
50
51using namespace std ;
52
53// <summary>
54// Base class for NRO accessor classes.
55// </summary>
56//
57// <prerequisite>
58// <li> <linkto class=NROReader>NROReader</linkto>
59// <li> <linkto class=NRODataRecord>NRODataRecord</linkto>
60// </prerequisite>
61//
62// <reviewed reviewer="" date="" tests="" demos="">
63// </reviewed>
64//
65// <etymology>
66// This class is a base class for classes that actually access data from NRO telescopes.
67// Concrete classes are defiened for each data type (OTF format or NRO FITS) and/or
68// telescopes (45m or ASTE).
69// The class have two filler method: fillHeader and fillRecord. The former reads header
70// information from the data. Since header data depends on the telescope and its configuration,
71// it is an abstract in this class and is defined in each concrete class.
72// On the other hand, the later reads each scan record (set of meta data
73// and spectral data). The method uses <linkto class=NRODataRecord>NRODataRecord</linkto>
74// to access scan record. It is implemented here since contents of scan record is
75// quite similar for several types of data.
76// </etymology>
77//
78// <synopsis>
79// Abstract class that is designed as a base class for all accessor classes.
80// </synopsis>
81//
82
83class NRODataset
84{
85 public:
86 // Constructor
87 NRODataset( string name ) ;
88
89 // Destructor
90 virtual ~NRODataset() ;
91
92 // Data initialization
93 virtual void initialize() ;
94
95 // open file
96 virtual int open() ;
97
98 // close file
99 virtual void close() ;
100
101 // Fill data header from file
102 virtual int fillHeader() = 0 ;
103
104 // Fill data record
105 virtual int fillRecord( int i ) ;
106
107 // simple getter
108 string getLOFIL() { return LOFIL ; } ;
109 string getVER() { return VER ; } ;
110 string getGROUP() { return GROUP ; } ;
111 string getPROJ() { return PROJ ; } ;
112 string getSCHED() { return SCHED ; } ;
113 string getOBSVR() { return OBSVR ; } ;
114 string getLOSTM() { return LOSTM ; } ;
115 string getLOETM() { return LOETM ; } ;
116 int getARYNM() { return ARYNM ; } ;
117 int getNSCAN() { return NSCAN ; } ;
118 string getTITLE() { return TITLE ; } ;
119 string getOBJ() { return OBJ ; } ;
120 string getEPOCH() { return EPOCH ; } ;
121 double getRA0() { return RA0 ; } ;
122 double getDEC0() { return DEC0 ; } ;
123 double getGLNG0() { return GLNG0 ; } ;
124 double getGLAT0() { return GLAT0 ; } ;
125 int getNCALB() { return NCALB ; } ;
126 int getSCNCD() { return SCNCD ; } ;
127 string getSCMOD() { return SCMOD ; } ;
128 double getURVEL() { return URVEL ; } ;
129 string getVREF() { return VREF ; } ;
130 string getVDEF() { return VDEF ; } ;
131 string getSWMOD() { return SWMOD ; } ;
132 double getFRQSW() { return FRQSW ; } ;
133 double getDBEAM() { return DBEAM ; } ;
134 double getMLTOF() { return MLTOF ; } ;
135 double getCMTQ() { return CMTQ ; } ;
136 double getCMTE() { return CMTE ; } ;
137 double getCMTSOM() { return CMTSOM ; } ;
138 double getCMTNODE() { return CMTNODE ; } ;
139 double getCMTI() { return CMTI ; } ;
140 string getCMTTM() { return CMTTM ; } ;
141 double getSBDX() { return SBDX ; } ;
142 double getSBDY() { return SBDY ; } ;
143 double getSBDZ1() { return SBDZ1 ; } ;
144 double getSBDZ2() { return SBDZ2 ; } ;
145 double getDAZP() { return DAZP ; } ;
146 double getDELP() { return DELP ; } ;
147 int getCHBIND() { return CHBIND ; } ;
148 int getNUMCH() { return NUMCH ; } ;
149 int getCHMIN() { return CHMIN ; } ;
150 int getCHMAX() { return CHMAX ; } ;
151 double getALCTM() { return ALCTM ; } ;
152 double getIPTIM() { return IPTIM ; } ;
153 double getPA() { return PA ; } ;
154 int getSCNLEN() { return SCNLEN ; } ;
155 int getSBIND() { return SBIND ; } ;
156 int getIBIT() { return IBIT ; } ;
157 string getSITE() { return SITE ; } ;
158 vector<string> getRX() { return RX ; } ;
159 vector<double> getHPBW() { return HPBW ; } ;
160 vector<double> getEFFA() { return EFFA ; } ;
161 vector<double> getEFFB() { return EFFB ; } ;
162 vector<double> getEFFL() { return EFFL ; } ;
163 vector<double> getEFSS() { return EFSS ; } ;
164 vector<double> getGAIN() { return GAIN ; } ;
165 vector<string> getHORN() { return HORN ; } ;
166 vector<string> getPOLTP() { return POLTP ; } ;
167 vector<double> getPOLDR() { return POLDR ; } ;
168 vector<double> getPOLAN() { return POLAN ; } ;
169 vector<double> getDFRQ() { return DFRQ ; } ;
170 vector<string> getSIDBD() { return SIDBD ; } ;
171 vector<int> getREFN() { return REFN ; } ;
172 vector<int> getIPINT() { return IPINT ; } ;
173 vector<int> getMULTN() { return MULTN ; } ;
174 vector<double> getMLTSCF() { return MLTSCF ; } ;
175 vector<string> getLAGWIND() { return LAGWIND ; } ;
176 vector<double> getBEBW() { return BEBW ; } ;
177 vector<double> getBERES() { return BERES ; } ;
178 vector<double> getCHWID() { return CHWID ; } ;
179 vector<int> getARRY() { return ARRY ; } ;
180 vector<int> getNFCAL() { return NFCAL ; } ;
181 vector<double> getF0CAL() { return F0CAL ; } ;
182 vector< vector<double> > getFQCAL() { return FQCAL ; } ;
183 vector< vector<double> > getCHCAL() { return CHCAL ; } ;
184 vector< vector<double> > getCWCAL() { return CWCAL ; } ;
185 string getCDMY1() { return CDMY1 ; } ;
186 vector<double> getDSBFC() { return DSBFC ;} ;
187 int getDataSize() { return datasize_ ; } ;
188 int getRowNum() { return rowNum_ ; } ;
189
190 // get various parameters
191 NRODataRecord *getRecord( int i ) ;
192 virtual vector< vector<double> > getSpectrum() ;
193 virtual vector<double> getSpectrum( int i ) ;
194 virtual int getIndex( int irow ) ;
195 virtual int getPolarizationNum() ;
196 virtual vector<double> getStartIntTime() ;
197 virtual double getStartIntTime( int i ) ;
198 virtual double getScanTime( int i ) ;
199 virtual double getMJD( char *time ) ;
200 virtual vector<bool> getIFs() ;
201 virtual vector<double> getFrequencies( int i ) ;
202 virtual uInt getArrayId( string type ) ;
203 virtual uInt getPolNo( int irow ) ;
204
205 protected:
206 // fill header information
207 virtual int fillHeader( int sameEndian ) = 0 ;
208
209 // Endian conversion for int variable
210 void convertEndian( int &value ) ;
211
212 // Endian convertion for float variable
213 void convertEndian( float &value ) ;
214
215 // Endian conversion for double variable
216 void convertEndian( double &value ) ;
217
218 // Endian conversion for NRODataRecord
219 void convertEndian( NRODataRecord *r ) ;
220
221 // Read char data
222 int readHeader( char *v, int size ) ;
223
224 // Read int data
225 int readHeader( int &v, int b ) ;
226
227 // Read float data
228 int readHeader( float &v, int b ) ;
229
230 // Read double data
231 int readHeader( double &v, int b ) ;
232
233 // Release DataRecord
234 void releaseRecord() ;
235
236 // show primary information
237 void show() ;
238
239 // convert frequency frame
240 virtual double toLSR( double v, double t, double x, double y ) ;
241
242 // POLNO from RX
243 uInt polNoFromRX( const char *rx ) ;
244
245 // Type of file record
246 string LOFIL ;
247
248 // Version
249 string VER ;
250
251 // Group name
252 string GROUP ;
253
254 // Project name
255 string PROJ ;
256
257 // Name of observation scheduling file
258 string SCHED ;
259
260 // Name of observer
261 string OBSVR ;
262
263 // Observation start time with format of "YYYYMMDDHHMMSS" (UTC)
264 string LOSTM ;
265
266 // observation end time with format of "YYYYMMDDHHMMSS" (UTC)
267 string LOETM ;
268
269 // Number of arrays (beams and IFs)
270 int ARYNM ;
271
272 // Number of scans
273 int NSCAN ;
274
275 // Title of observation
276 string TITLE ;
277
278 // Name of target object
279 string OBJ ;
280
281 // Equinox (B1950 or J2000)
282 string EPOCH ;
283
284 // Right ascension [rad]
285 double RA0 ;
286
287 // Declination [rad]
288 double DEC0 ;
289
290 // Galactic longitude [rad]
291 double GLNG0 ;
292
293 // Galactic latitude [rad]
294 double GLAT0 ;
295
296 // Calibration interval
297 int NCALB ;
298
299 // Scan coordinate (0: RADEC 1: LB 2: AZEL)
300 int SCNCD ;
301
302 // Scan sequence pattern
303 string SCMOD ;
304
305 // User-defined recessional velocity [m/s]
306 double URVEL ;
307
308 // Reference frame for recessional velocity (LSR or HEL or GAL)
309 string VREF ;
310
311 // Definition of recessional velocity (RAD or OPT)
312 string VDEF ;
313
314 // Switching mode (POS or BEAM or FREQ)
315 string SWMOD ;
316
317 // Switching frequency [Hz]
318 double FRQSW ;
319
320 // Off-beam angle of beam switching [rad]
321 double DBEAM ;
322
323 // Initial inclination angle of multi-beam array
324 double MLTOF ;
325
326 // Comet: Perihelion distance
327 double CMTQ ;
328
329 // Comet: Eccentricity
330 double CMTE ;
331
332 // Comet: Argument of perihelion
333 double CMTSOM ;
334
335 // Comet: Longitude of the ascending node
336 double CMTNODE ;
337
338 // Comet: Orbital inclination angle
339 double CMTI ;
340
341 // Comet: Time of the perihelion passage
342 string CMTTM ;
343
344 // Correction for position of subreflector DX [mm]
345 double SBDX ;
346
347 // Correction for position of subreflector DY [mm]
348 double SBDY ;
349
350 // Correction for position of subreflector DZ1 [mm]
351 double SBDZ1 ;
352
353 // Correction for position of subreflector DZ2 [mm]
354 double SBDZ2 ;
355
356 // Correction for pointing on azimuth [rad]
357 double DAZP ;
358
359 // Correction for pointing on elevation [rad]
360 double DELP ;
361
362 // Number of channel binding
363 int CHBIND ;
364
365 // Number of channel after binding
366 int NUMCH ;
367
368 // Channel range (minimum)
369 int CHMIN ;
370
371 // Channel range (maximum)
372 int CHMAX ;
373
374 // ALC time constant
375 double ALCTM ;
376
377 // Interval to get data from spectrometer
378 double IPTIM ;
379
380 // Position angle of the map
381 double PA ;
382
383 // Length of scan record [bytes]
384 int SCNLEN ;
385
386 // Range of space binding
387 int SBIND ;
388
389 // Quantization bit number (fixed to 12)
390 int IBIT ;
391
392 // Site (antenna) name (45m or ASTE)
393 string SITE ;
394
395 // Dummy data
396 string CDMY1 ;
397
398 // Type of detector frontend
399 vector<string> RX ;
400
401 // HPBW [rad]
402 vector<double> HPBW ;
403
404 // Aperture efficiencies
405 vector<double> EFFA ;
406
407 // Beam efficiencies
408 vector<double> EFFB ;
409
410 // Antenna efficiencies
411 vector<double> EFFL ;
412
413 // FSS efficiencies
414 vector<double> EFSS ;
415
416 // Antenna gain
417 vector<double> GAIN ;
418
419 // Type of polarization at feed horn (R or L or H or V)
420 vector<string> HORN ;
421
422 // Type of polarization (CIRC or LINR)
423 vector<string> POLTP ;
424
425 // Rotation direction of circular polarization
426 vector<double> POLDR ;
427
428 // Polarization angle of linear polarization
429 vector<double> POLAN ;
430
431 // Switching frequency of frequcency switching [Hz]
432 vector<double> DFRQ ;
433
434 // Type of sideband (LSB or USB or DSB)
435 vector<string> SIDBD ;
436
437 // Identifier of reference synthesizer
438 vector<int> REFN ;
439
440 // Temperature of calibrator
441 vector<int> IPINT ;
442
443 // Beam id of the multi-beam detector
444 vector<int> MULTN ;
445
446 // Scaling factor of the multi-beam detector
447 vector<double> MLTSCF ;
448
449 // Type of LAG window (NONE or HANN or HAMM or BLCK)
450 vector<string> LAGWIND ;
451
452 // Bandwidth at backend
453 vector<double> BEBW ;
454
455 // Spectral resolution at backend
456 vector<double> BERES ;
457
458 // Channel width at backend
459 vector<double> CHWID ;
460
461 // Array usage (1: used 0: not used)
462 vector<int> ARRY ;
463
464 // Frequency calibration: Number of measurement (max 10)
465 vector<int> NFCAL ;
466
467 // Frequency calibration: Central frequency [Hz]
468 vector<double> F0CAL ;
469
470 // Frequency calibration: Measured central frequency [Hz]
471 vector< vector<double> > FQCAL ;
472
473 // Frequency calibration: Measured channel number
474 vector< vector<double> > CHCAL ;
475
476 // Frequency calibration: Measured channel width [Hz]
477 vector< vector<double> > CWCAL ;
478
479 // DSB scaling factor
480 vector<double> DSBFC ;
481
482 // number of scan
483 int scanNum_ ;
484
485 // number of row
486 int rowNum_ ;
487
488 // length of scan (byte)
489 int scanLen_ ;
490
491 // length of spectral data (byte)
492 int dataLen_ ;
493
494 // Data size of the header [bytes]
495 int datasize_ ;
496
497 // maximum channel number
498 int chmax_ ;
499
500 // Current data id
501 int dataid_ ;
502
503 // Data record
504 NRODataRecord *record_ ;
505
506 // input filename
507 string filename_ ;
508
509 // file pointer
510 FILE *fp_ ;
511
512 // OS endian
513 int same_ ;
514
515 // Logger
516 //LogIO os ;
517
518 // reference frequency for each array
519 vector<double> refFreq_ ;
520
521 // record to store REFPIX, REFVAL, INCREMENT pair for each array
522 Record frec_ ;
523} ;
524
525// debug message output
526template<class T> inline void nro_debug_output( char *name, int len, vector<T> &val )
527{
528 for ( int i = 0 ; i < len ; i++ ) {
529 if ( i == 0 ) {
530 cout << setw(8) << left << name ;
531 }
532 else if ( ( i % 5 ) == 0 ) {
533 cout << endl << " " ;
534 }
535 cout << "\'" << val[i] << "\' " ;
536 }
537 cout << endl ;
538}
539
540template<class T> inline void nro_debug_output( char *name, int len1, int len2, vector< vector<T> > &val )
541{
542 for ( int i = 0 ; i < len1 ; i++ ) {
543 for ( int j = 0 ; j < len2 ; j++ ) {
544 if ( j == 0 ) {
545 if ( i < 10 )
546 cout << name << "0" << i << " " ;
547 else
548 cout << name << i << " " ;
549 }
550 else if ( ( j % 5 ) == 0 ) {
551 cout << endl << " " ;
552 }
553 cout << "\'" << val[i][j] << "\' " ;
554 }
555 cout << endl ;
556 }
557}
558
559
560#endif /* NRO_HEADER_H */
Note: See TracBrowser for help on using the repository browser.