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

Last change on this file since 3110 was 3101, checked in by Takeshi Nakazato, 8 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: Yes/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...


Bug fix on frequency labeling for NOSTAR data. Do not apply additional (NEWSTAR specific) frequency correction if the data is NOSTAR.

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