casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Importmiriad.h
Go to the documentation of this file.
1 //# Importmiriad: miriad dataset to casacore::MeasurementSet conversion
2 //# Copyright (C) 1997,2000,2001,2002,2013,2015
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This program is free software; you can redistribute it and/or modify
6 //# it under the terms of the GNU General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or
8 //# (at your option) any later version.
9 //#
10 //# This program is distributed in the hope that it will be useful,
11 //# but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 //# GNU General Public License for more details.
14 //#
15 //# You should have received a copy of the GNU General Public License
16 //# along with this program; if not, write to the Free Software
17 //# Foundation, Inc., 675 Masve, Cambridge, MA 02139, USA.
18 //#
19 
20 #ifndef MIRIAD_IMPORTMIRIAD_H
21 #define MIRIAD_IMPORTMIRIAD_H
22 
23 //#Includes
24 
25 #include <casa/Inputs/Input.h>
26 #include <casa/OS/File.h>
27 #include <casa/Utilities/GenSort.h>
28 
29 #include <casa/Arrays/Cube.h>
30 #include <casa/Arrays/Matrix.h>
31 #include <casa/Arrays/Vector.h>
32 #include <casa/Arrays/ArrayMath.h>
33 #include <casa/Arrays/ArrayUtil.h>
35 #include <casa/Arrays/MatrixMath.h>
36 
37 #include <measures/Measures.h>
41 
42 #include <tables/Tables.h>
44 
45 #include <ms/MeasurementSets.h>
46 
47 #include <mirlib/maxdimc.h>
48 #include <mirlib/miriad.h>
49 
50 #include <casa/namespace.h>
51 namespace casa { //# NAMESPACE CASA - BEGIN
52 
53 
54 // MIRIAD dataset casacore::MeasurementSet filler. Derived from carmafiller.
55 //
56 // Despite that this program is written in C++ and uses classes, it is
57 // really a set of routines manipulating a huge common block.....
58 //
59 // Acknowledgement: this program was originally cloned off uvfitsfiller.cc
60 // whose code is now in MSFitsInput.cc
61 // Ray Plante wrote the other filler, with which we had
62 // some cross talk
63 //
64 //
65 // Limitations, Caveats and Remaining ToDo's
66 // - does not apply the various (miriad) complex gain corrections
67 // (uvcat and friends should be used for that in miriad, it would be
68 // silly to duplicate that code here)
69 // - this code won't run if casacore::Double!=double or casacore::Float!=float or casacore::Int!=int
70 // On some future 64bit machines this may cause problems?
71 // - CARMA type arrays when dishes are not the same size
72 // - do not mix arrays from different telescopes (e.g. BIMA and ATCA)
73 // but it should handle different configurations (ARRAYs) of the same
74 // instrument
75 // - handle multiple array configuration datasets that were UVCAT'ed
76 // (needs to count antennae up at each array configuration)
77 // - true miriad storage manager ?
78 //
79 // - check UV override, is that being handled transparently?
80 //
81 // - spectral windows layout (code present, fix table access descriptors)
82 // CHECK: what happens if e.g. uvcat does some line= preprocessing
83 // - correct restfreq's in source tables that relate to the spectral windows
84 // (this code currently coredumps)
85 // - make win=,narrow=,wide=0 cause non of them to be written in that selection
86 // - add weather table
87 // - although no more wides are written, there is a way to make a small MS
88 // from the wides only by preprocessing in miriad, but conceivably
89 // could be done here as well?? -- except the narrow= keyword seems to write
90 // files that suffer from the casacore::Table array conformance error
91 //
92 // Todo: to deal with multiple zoom setups (freq changes), we need
93 // to track which spectral windows each source appears to make a proper
94 // source table indexed by source id and spw id
95 
96 
97 // History:
98 // Spring 1997: written (cloned off uvfitsfiller) Peter Teuben
99 // July 1997: Y2K, fixed table-interface PJT
100 // Dec 1997: fixed wideband only data (e.g. uvgen) PJT
101 // ??? somebody fixed up this code for some new release ???
102 // May 2000: fixed up for various new AIPS++ conventions PJT
103 // and added multi-source & field PJT
104 // Sep 2000: development now on linux, converted to OldMS PJT
105 // Dec 2000: casacore::Conversion to casacore::MS (MS2) PJT
106 // typical compile time: (P600/256M/15MBps HD: 36")
107 // typical 3c273 conversion time: 2.6" (5.3->11.3 MB)
108 // Cf. that to "uvio" processing time, which runs at disk I/O
109 // speed (15 MB/s on the beforementioned laptop)
110 // Jan-Feb 2001: window layout, restfreq's and various things to get
111 // msmultiscale to work; added some syscal support PJT
112 // April 2001: final cleanup for the 1.5 AIPS++ release - PJT
113 // [note that from this moment on bimafiller is for
114 // experimental use and deprecated, the new version
115 // will be called 'mirfiller'
116 // Oct 2001: mirlib changed location
117 // Sep 2009: revived in CASA, added various tables for CARMA
118 // also renamed from bimafiller to carmafiller
119 // Sep 2011: initial release
120 // Mar 2013: Rename to importmiriad and make it work for ATCA
121 // CABB data (more channels, windows and 4 pols) MHW
122 // May 2014: Fix some compiler warnings, add TOPO option MHW
123 // Jul 2015: Cope with data with changing freq setups,e.g.,
124 // CABB zoom data with multiple sources MHW
125 // Jan 2016 Turn from standalone app into tool+task MHW
126 
127 // a placeholder for the MIRIAD spectral window configuration
128 // see also the MIRIAD programmers guide, and its appendix on UV Variables
129 // for CARMA we have MAXWIN = MAXWIDE (16 normally, 6 in 2006-2009, more later)
130 // narrow band (plus MAXWIDE space to point into the wide band data too)
131 
132 typedef struct window { // CASA defines everything mid-band mid-interval
133  int nspect; // number of valid windows (<=MAXWIN, typically 16)
134  int nschan[MAXWIN+MAXWIDE]; // number of channels in a window
135  int ischan[MAXWIN+MAXWIDE]; // starting channel of a window (1-based)
136  double sdf[MAXWIN+MAXWIDE]; // channel separation
137  double sfreq[MAXWIN+MAXWIDE]; // frequency of first channel in window (doppler changes)
138  double restfreq[MAXWIN+MAXWIDE]; // rest freq, if appropriate
139  char code[MAXWIN+MAXWIDE]; // code to CASA identification (N, W or S; S not used anymore)
140 
141  // wide band (for CARMA these are the spectral window averages - i.e. nspect=nwide)
142  int nwide; // number of wide band channels
143  float wfreq[MAXWIDE]; // freq
144  float wwidth[MAXWIDE]; // width
145  // ifchain for ATCA
146  int chain[MAXWIN+MAXWIDE]; // if conversion chain
147 
148 
149 } WINDOW;
150 
151 // the maximum number of fields in mosaicing observations, careful, miriad
152 // often has a smaller value, like 64 or 128.
153 #ifndef MAXFIELD
154 # define MAXFIELD 10000
155 #endif
156 
157 #ifndef MAXMSG
158 # define MAXMSG 256
159 #endif
160 
161 #ifndef MAXFSET
162 # define MAXFSET 100
163 #endif
164 
165 // a helper class
166 
168 {
169  // This is an implementation helper class used to store 'local' data
170  // during the filling process.
171 public:
172  // Create from a miriad dataset (a directory)
174  casacore::Bool Qtsys=false,
175  casacore::Bool Qarrays=false,
176  casacore::Bool Qlinecal=false);
177 
178  // Standard destructor
179  ~Importmiriad();
180 
181  // Check some of the contents of the data and header read
183 
184  // Debug output level
185  casacore::Bool Debug(int level);
186 
187  // Set up the casacore::MeasurementSet, including StorageManagers and fixed columns.
188  // If useTSM is true, the Tiled Storage Manager will be used to store
189  // DATA, FLAG and WEIGHT_SPECTRUM
190  void setupMeasurementSet(const casacore::String& MSFileName, casacore::Bool useTSM=true);
191 
192  // Fill the main table by reading in all the visibilities
193  void fillMSMainTable();
194 
195  // Make an Antenna casacore::Table (can be called incrementally now)
196  void fillAntennaTable();
197 
198  // Make a Syscal casacore::Table (can be called incrementally)
199  void fillSyscalTable();
200 
201  // fill Spectralwindow table
203 
204  // fill Field table
205  void fillFieldTable();
206 
207  // fill Source table
208  void fillSourceTable();
209 
210  // fill the Feed table with minimal info needed for synthesis processing
211  void fillFeedTable();
212 
213  // Fill the Observation and History (formerly ObsLog) tables
214  void fillObsTables();
215 
216  // fix up the EPOCH MEASURE_REFERENCE keywords using the value found
217  // in the (last) AN table - check if miriad really needs it
218  void fixEpochReferences();
219 
220  void Tracking(int record);
221  void check_window();
223  void Error(char *msg);
224  void Warning(char *msg);
225  void show();
226  void close();
227 
228 private:
230  casacore::Int uv_handle_p; // miriad handle
231  casacore::MeasurementSet ms_p; // the casacore::MS itself
232  casacore::MSColumns *msc_p; // handy pointer to the columns in an casacore::MS
233  casacore::Int debug_p; // debug level
235  project_p,
236  object_p,
237  telescope_p,
238  observer_p,
239  version_p,
240  timsys_p;
245  casacore::Int nArray_p; // number of arrays (nAnt_p.nelements())
246  casacore::Block<casacore::Int> nAnt_p; // number of antennas per array
248  casacore::Vector<casacore::Double> arrayXYZ_p; // needs to be made with 3 elements
249  casacore::Vector<casacore::Double> ras_p, decs_p; // ra/dec for source list (source_p)
250  casacore::Vector<casacore::String> source_p, // list of source names (?? object_p ??)
251  purpose_p; // purpose of this source
253  casacore::Vector<casacore::Bool> keep_p; // keep this window for output to MS
254 
255 
256  // the following variables are for miriad, hence not casacore::Double/casacore::Int/Float
257  // thus the code may have to be fixed on machines where these do not
258  // agree ... may need special access code to get those into CASA
259  // types on 64 bit machines??
260 
261  double preamble[5] /*, first_time*/;
262  int ifield, nfield, npoint /*, nsource*/; // both dra/ddec should become casacore::Vector's
263  float dra[MAXFIELD], ddec[MAXFIELD]; // offset in radians
264  double ra[MAXFIELD], dec[MAXFIELD];
265  int field[MAXFIELD]; // source index
267  float dra_p=0, ddec_p=0;
268  int pol_p[4];
269  // char message[MAXMSG];
270 
271 
272  // The following items more or less follow the uv variables in a dataset
276  casacore::Double ra_p, dec_p; // current pointing center RA,DEC at EPOCH
278  casacore::Double freq_p; // rest frequency of the primary line
280  casacore::Double time_p; // current MJD time
281  casacore::Double timeFirst_p; // First MJD time encountered
282 
283  // MIRIAD spectral window definition
285  WINDOW win[MAXFSET]; // allow for 16 different frequency setups
286 
287  casacore::Bool Qtsys_p; /* tsys weight's */
288  casacore::Bool Qarrays_p; /* write separate arrays */
289  casacore::Bool Qlinecal_p; /* do linecal */
290 
291  // casacore::Data buffers.... again in MIRIAD format
292 
293  float data[2*MAXCHAN], wdata[2*MAXCHAN]; // 2*MAXCHAN since (Re,Im) pairs complex numbers
297 
298  // Counters
299  int nvis;
300 };
301 } // Namespace CASA - END
302 
303 #endif
MIRIAD dataset casacore::MeasurementSet filler.
Definition: Importmiriad.h:132
casacore::String telescope_p
Definition: Importmiriad.h:234
casacore::Int ddid_p
Definition: Importmiriad.h:284
void fillMSMainTable()
Fill the main table by reading in all the visibilities.
int Int
Definition: aipstype.h:50
void checkInput(casacore::Block< casacore::Int > &spw, casacore::Block< casacore::Int > &wide)
Check some of the contents of the data and header read.
void fillSyscalTable()
Make a Syscal casacore::Table (can be called incrementally)
double preamble[5]
the following variables are for miriad, hence not casacore::Double/casacore::Int/Float thus the code ...
Definition: Importmiriad.h:261
casacore::Matrix< casacore::Int > corrProduct_p
Definition: Importmiriad.h:242
float wfreq[MAXWIDE]
Definition: Importmiriad.h:143
casacore::Double timeFirst_p
Definition: Importmiriad.h:281
casacore::MDirection::Types epochRef_p
Definition: Importmiriad.h:244
casacore::Int npol_p
Definition: Importmiriad.h:273
float data[2 *MAXCHAN]
casacore::Data buffers....
Definition: Importmiriad.h:293
double ra[MAXFIELD]
Definition: Importmiriad.h:264
void fillAntennaTable()
Make an Antenna casacore::Table (can be called incrementally now)
casacore::Vector< casacore::Double > decs_p
Definition: Importmiriad.h:249
casacore::MSColumns * msc_p
Definition: Importmiriad.h:232
#define MAXCHAN
Definition: maxdimc.h:29
int chain[MAXWIN+MAXWIDE]
ifchain for ATCA
Definition: Importmiriad.h:146
casacore::Float jyperk_p
Definition: Importmiriad.h:277
casacore::Vector< casacore::String > purpose_p
Definition: Importmiriad.h:250
casacore::Vector< casacore::Int > corrIndex_p
Definition: Importmiriad.h:241
casacore::MeasurementSet ms_p
Definition: Importmiriad.h:231
casacore::Float phasem1[MAXANT]
Definition: Importmiriad.h:275
void fillFeedTable()
fill the Feed table with minimal info needed for synthesis processing
casacore::Bool Qlinecal_p
Definition: Importmiriad.h:289
void fillSourceTable()
fill Source table
#define MAXANT
Definition: maxdimc.h:27
casacore::Block< casacore::Vector< casacore::Double > > receptorAngle_p
Definition: Importmiriad.h:247
casacore::Vector< casacore::String > source_p
Definition: Importmiriad.h:250
struct casa::window WINDOW
MIRIAD dataset casacore::MeasurementSet filler.
casacore::Double dec_p
Definition: Importmiriad.h:276
casacore::Int nants_p
char message[MAXMSG];
Definition: Importmiriad.h:273
int wflags[MAXCHAN]
Definition: Importmiriad.h:294
#define MAXWIN
Definition: maxdimc.h:31
casacore::Vector< casacore::Double > arrayXYZ_p
Definition: Importmiriad.h:248
double sfreq[MAXWIN+MAXWIDE]
Definition: Importmiriad.h:137
ostream-like interface to creating log messages.
Definition: LogIO.h:167
int nwide
wide band (for CARMA these are the spectral window averages - i.e.
Definition: Importmiriad.h:142
casacore::Double ra_p
Definition: Importmiriad.h:276
casacore::String object_p
Definition: Importmiriad.h:234
float dra[MAXFIELD]
Definition: Importmiriad.h:263
a helper class
Definition: Importmiriad.h:167
casacore::String observer_p
Definition: Importmiriad.h:234
casacore::String version_p
Definition: Importmiriad.h:234
void Tracking(int record)
casacore::Bool Debug(int level)
Debug output level.
void Error(char *msg)
void fillSpectralWindowTable(casacore::String vel)
fill Spectralwindow table
casacore::Vector< casacore::Double > ras_p
Definition: Importmiriad.h:249
Types
Types of known MDirections Warning: The order defines the order in the translation matrix FromTo in ...
Definition: MDirection.h:188
casacore::String timsys_p
Definition: Importmiriad.h:234
float wwidth[MAXWIDE]
Definition: Importmiriad.h:144
casacore::Double time_p
Definition: Importmiriad.h:280
#define MAXWIDE
Definition: maxdimc.h:32
int nvis
Counters.
Definition: Importmiriad.h:299
~Importmiriad()
Standard destructor.
casacore::Double freq_p
Definition: Importmiriad.h:278
void Warning(char *msg)
casacore::Int nants_offset_p
Definition: Importmiriad.h:273
casacore::String infile_p
Definition: Importmiriad.h:229
casacore::Vector< casacore::Bool > keep_p
Definition: Importmiriad.h:253
#define MAXFIELD
the maximum number of fields in mosaicing observations, careful, miriad often has a smaller value...
Definition: Importmiriad.h:154
int fcount[MAXFIELD]
Definition: Importmiriad.h:266
casacore::Bool compareWindows(WINDOW &w1, WINDOW &w2)
casacore::String project_p
Definition: Importmiriad.h:234
casacore::Float inttime_p
Definition: Importmiriad.h:277
double Double
Definition: aipstype.h:55
float systemp[MAXANT *MAXWIDE]
Definition: Importmiriad.h:295
int flags[MAXCHAN]
Definition: Importmiriad.h:294
float wdata[2 *MAXCHAN]
Definition: Importmiriad.h:293
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::Int nchan_p
Definition: Importmiriad.h:273
float Float
Definition: aipstype.h:54
float ddec[MAXFIELD]
Definition: Importmiriad.h:263
casacore::String array_p
Definition: Importmiriad.h:234
void setupMeasurementSet(const casacore::String &MSFileName, casacore::Bool useTSM=true)
Set up the casacore::MeasurementSet, including StorageManagers and fixed columns. ...
int field[MAXFIELD]
Definition: Importmiriad.h:265
casacore::Int nArray_p
Definition: Importmiriad.h:245
casacore::Int nwide_p
Definition: Importmiriad.h:273
A Table intended to hold astronomical data (a set of Measurements).
double sdf[MAXWIN+MAXWIDE]
Definition: Importmiriad.h:136
casacore::Bool Qarrays_p
Definition: Importmiriad.h:288
void fillObsTables()
Fill the Observation and History (formerly ObsLog) tables.
bool debug
casacore::Int nFreqSet_p
Definition: Importmiriad.h:284
casacore::Int mount_p
Definition: Importmiriad.h:279
char code[MAXWIN+MAXWIDE]
Definition: Importmiriad.h:139
int ischan[MAXWIN+MAXWIDE]
Definition: Importmiriad.h:135
int nschan[MAXWIN+MAXWIDE]
Definition: Importmiriad.h:134
void fillFieldTable()
fill Field table
A class to provide easy read-write access to MeasurementSet columns.
Definition: MSColumns.h:221
casacore::Vector< casacore::Int > nPixel_p
Definition: Importmiriad.h:241
casacore::Block< casacore::Int > nAnt_p
Definition: Importmiriad.h:246
String: the storage and methods of handling collections of characters.
Definition: String.h:223
casacore::Vector< casacore::Int > corrType_p
Definition: Importmiriad.h:241
#define MAXFSET
Definition: Importmiriad.h:162
casacore::Int debug_p
Definition: Importmiriad.h:233
casacore::Bool Qtsys_p
Definition: Importmiriad.h:287
casacore::Double antpos[3 *MAXANT]
Definition: Importmiriad.h:274
Importmiriad(casacore::String &infile, casacore::Int debug=0, casacore::Bool Qtsys=false, casacore::Bool Qarrays=false, casacore::Bool Qlinecal=false)
This is an implementation helper class used to store &#39;local&#39; data during the filling process...
double dec[MAXFIELD]
Definition: Importmiriad.h:264
casacore::LogIO os_p
Definition: Importmiriad.h:252
casacore::Int freqSet_p
MIRIAD spectral window definition.
Definition: Importmiriad.h:284
casacore::Double epoch_p
Definition: Importmiriad.h:243
WINDOW win[MAXFSET]
Definition: Importmiriad.h:285
double restfreq[MAXWIN+MAXWIDE]
Definition: Importmiriad.h:138
void fixEpochReferences()
fix up the EPOCH MEASURE_REFERENCE keywords using the value found in the (last) AN table - check if m...
casacore::Int uv_handle_p
Definition: Importmiriad.h:230