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

Last change on this file since 3101 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
RevLine 
[1757]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>
[2198]43#include <casa/Containers/Record.h>
[2766]44#include <casa/Utilities/CountedPtr.h>
[1757]45#include <atnf/PKSIO/NRODataRecord.h>
46#include <casa/namespace.h>
[2436]47#include <casa/iomanip.h>
[1757]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
[2748]85  NRODataset( std::string name ) ;
[1757]86
87  // Destructor
88  virtual ~NRODataset() ;
89
90  // Data initialization
[2783]91  virtual void initialize() = 0 ;
[1757]92
[3101]93  // whether data is NEWSTAR or not
94  virtual bool isNewstarFormat() const {return true;}
95
[1757]96  // open file
97  virtual int open() ;
98
99  // close file
100  virtual void close() ;
101
102  // Fill data header from file
[2782]103  virtual int fillHeader() ;
[1757]104
105  // Fill data record
106  virtual int fillRecord( int i ) ;
107
108  // simple getter
[2764]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 ; } ;
[3066]117  int getARYNM() const { return ARYNM ; } ;
118  int getNSCAN() const { return NSCAN ; } ;
[2764]119  const std::string getTITLE() const { return TITLE ; } ;
120  const std::string getOBJ() const { return OBJ ; } ;
121  const std::string getEPOCH() const { return EPOCH ; } ;
[3066]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 ; } ;
[2764]128  const std::string getSCMOD() const { return SCMOD ; } ;
[3066]129  double getURVEL() const { return URVEL ; } ;
[2764]130  const std::string getVREF() const { return VREF ; } ;
131  const std::string getVDEF() const { return VDEF ; } ;
132  const std::string getSWMOD() const { return SWMOD ; } ;
[3066]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 ; } ;
[2764]141  const std::string getCMTTM() const { return CMTTM ; } ;
[3066]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 ; } ;
[2764]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 ;} ;
[3066]188  int getDataSize() const { return datasize_ ; } ;
189  int getRowNum() const { return rowNum_ ; } ;
[1757]190
191  // get various parameters
192  NRODataRecord *getRecord( int i ) ;
[2748]193  virtual std::vector< std::vector<double> > getSpectrum() ;
194  virtual std::vector<double> getSpectrum( int i ) ;
[1757]195  virtual int getIndex( int irow ) ;
196  virtual int getPolarizationNum() ;
[2748]197  virtual std::vector<double> getStartIntTime() ;
[1757]198  virtual double getStartIntTime( int i ) ;
[2156]199  virtual double getScanTime( int i ) ;
[2766]200  virtual double getMJD( const char *time ) ;
[2748]201  virtual std::vector<bool> getIFs() ;
202  virtual std::vector<double> getFrequencies( int i ) ;
203  virtual uInt getArrayId( std::string type ) ;
[2777]204  virtual uInt getSortedArrayId( std::string type ) ;
[2434]205  virtual uInt getPolNo( int irow ) ;
[1757]206
207 protected:
[2783]208  // initialize common part
209  void initializeCommon() ;
210
[1757]211  // fill header information
212  virtual int fillHeader( int sameEndian ) = 0 ;
[2783]213  int fillHeaderCommon( int sameEndian ) ;
[1757]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
[2766]225  void convertEndian( NRODataRecord &r ) ;
[1757]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
[1868]245  // convert frequency frame
246  virtual double toLSR( double v, double t, double x, double y ) ;
247
[2434]248  // POLNO from RX
[2748]249  //uInt polNoFromRX( const char *rx ) ;
250  uInt polNoFromRX( const std::string &rx ) ;
[2434]251
[2777]252  // initialize array information (only for OTF data)
253  void initArray();
254
255  // return ARRYMAX
256  virtual int arrayMax() {return 0;} ;
257
[2781]258  // get scanNum from NSCAN (NSCAN or NSCAN + 1)
259  int getScanNum();
260
[1757]261  // Type of file record
[2748]262  std::string LOFIL ;
[1757]263
264  // Version
[2748]265  std::string VER ;
[1757]266
267  // Group name
[2748]268  std::string GROUP ;
[1757]269
270  // Project name
[2748]271  std::string PROJ ;
[1757]272
273  // Name of observation scheduling file
[2748]274  std::string SCHED ;
[1757]275
276  // Name of observer
[2748]277  std::string OBSVR ;
[1757]278
279  // Observation start time with format of "YYYYMMDDHHMMSS" (UTC)
[2748]280  std::string LOSTM ;
[1757]281
282  // observation end time with format of "YYYYMMDDHHMMSS" (UTC)
[2748]283  std::string LOETM ;
[1757]284
285  // Number of arrays (beams and IFs)
286  int ARYNM ;
287
288  // Number of scans
289  int NSCAN ;
290
291  // Title of observation
[2748]292  std::string TITLE ;
[1757]293
294  // Name of target object
[2748]295  std::string OBJ ;
[1757]296
297  // Equinox (B1950 or J2000)
[2748]298  std::string EPOCH ;
[1757]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
[2748]319  std::string SCMOD ;
[1757]320
321  // User-defined recessional velocity [m/s]
322  double URVEL ;
323
324  // Reference frame for recessional velocity  (LSR or HEL or GAL)
[2748]325  std::string VREF ;
[1757]326
327  // Definition of recessional velocity  (RAD or OPT)
[2748]328  std::string VDEF ;
[1757]329
330  // Switching mode  (POS or BEAM or FREQ)
[2748]331  std::string SWMOD ;
[1757]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
[2748]358  std::string CMTTM ;
[1757]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)
[2748]409  std::string SITE ;
[1757]410
411  // Dummy data
[2748]412  std::string CDMY1 ;
[1757]413
414  // Type of detector frontend
[2748]415  std::vector<std::string> RX ;
[1757]416
417  // HPBW [rad]
[2748]418  std::vector<double> HPBW ;
[1757]419
420  // Aperture efficiencies
[2748]421  std::vector<double> EFFA ;
[1757]422
423  // Beam efficiencies
[2748]424  std::vector<double> EFFB ;
[1757]425
426  // Antenna efficiencies
[2748]427  std::vector<double> EFFL ;
[1757]428
429  // FSS efficiencies
[2748]430  std::vector<double> EFSS ;
[1757]431
432  // Antenna gain
[2748]433  std::vector<double> GAIN ;
[1757]434
435  // Type of polarization at feed horn  (R or L or H or V)
[2748]436  std::vector<std::string> HORN ;
[1757]437
438  // Type of polarization  (CIRC or LINR)
[2748]439  std::vector<std::string> POLTP ;
[1757]440
441  // Rotation direction of circular polarization
[2748]442  std::vector<double> POLDR ;
[1757]443
444  // Polarization angle of linear polarization
[2748]445  std::vector<double> POLAN ;
[1757]446
447  // Switching frequency of frequcency switching [Hz]
[2748]448  std::vector<double> DFRQ ;
[1757]449
450  // Type of sideband  (LSB or USB or DSB)
[2748]451  std::vector<std::string> SIDBD ;
[1757]452
453  // Identifier of reference synthesizer
[2748]454  std::vector<int> REFN ;
[1757]455
456  // Temperature of calibrator
[2748]457  std::vector<int> IPINT ;
[1757]458
459  // Beam id of the multi-beam detector
[2748]460  std::vector<int> MULTN ;
[1757]461
462  // Scaling factor of the multi-beam detector
[2748]463  std::vector<double> MLTSCF ;
[1757]464
465  // Type of LAG window  (NONE or HANN or HAMM or BLCK)
[2748]466  std::vector<std::string> LAGWIND ;
[1757]467
468  // Bandwidth at backend
[2748]469  std::vector<double> BEBW ;
[1757]470
471  // Spectral resolution at backend
[2748]472  std::vector<double> BERES ;
[1757]473
474  // Channel width at backend
[2748]475  std::vector<double> CHWID ;
[1757]476
477  // Array usage  (1: used  0: not used)
[2748]478  std::vector<int> ARRY ;
[1757]479
480  // Frequency calibration: Number of measurement (max 10)
[2748]481  std::vector<int> NFCAL ;
[1757]482
483  // Frequency calibration: Central frequency [Hz]
[2748]484  std::vector<double> F0CAL ;
[1757]485
486  // Frequency calibration: Measured central frequency [Hz]
[2748]487  std::vector< std::vector<double> > FQCAL ;
[1757]488
489  // Frequency calibration: Measured channel number
[2748]490  std::vector< std::vector<double> > CHCAL ;
[1757]491
492  // Frequency calibration: Measured channel width [Hz]
[2748]493  std::vector< std::vector<double> > CWCAL ;
[1757]494
495  // DSB scaling factor
[2748]496  std::vector<double> DSBFC ;
[1757]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
[2766]520  CountedPtr<NRODataRecord> record_ ;
[1757]521
522  // input filename
[2748]523  std::string filename_ ;
[1757]524
525  // file pointer
526  FILE *fp_ ;
527
528  // OS endian
529  int same_ ;
530
531  // Logger
532  //LogIO os ;
[1868]533
534  // reference frequency for each array
[2748]535  std::vector<double> refFreq_ ;
[2198]536
[2777]537  // list of array names
538  std::vector<std::string> arrayNames_;
539
[2198]540  // record to store REFPIX, REFVAL, INCREMENT pair for each array
541  Record frec_ ;
[1757]542} ;
543
[2436]544// debug message output
[2748]545template<class T> inline void nro_debug_output( char *name, int len, std::vector<T> &val )
[2436]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}
[1757]558
[2748]559template<class T> inline void nro_debug_output( char *name, int len1, int len2, std::vector< std::vector<T> > &val )
[2436]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
[1757]579#endif /* NRO_HEADER_H */
Note: See TracBrowser for help on using the repository browser.