~pconv-team/polconvertsd/trunk-1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* DATAIO - FITS-IDI interface to PolConvert

             Copyright (C) 2013  Ivan Marti-Vidal
             Nordic Node of EU ALMA Regional Center (Onsala, Sweden)
             Max-Planck-Institut fuer Radioastronomie (Bonn, Germany)
  
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
  
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
  
You should have received a copy of the GNU General Public License   
along with this program.  If not, see <http://www.gnu.org/licenses/>
  
*/




#include <sys/types.h>
#include <iostream> 
#include <fstream>
#include <math.h>
#include <complex>
#include "fitsio.h"

#ifndef __DATAIO_H__
#define __DATAIO_H__


typedef std::complex<float> cplx32f;

typedef struct {
double Nu0;
int Nchan;
double BW;
bool SB;
} FreqSetup;


typedef struct {
double *BaseLine[3];
double *SinDec;
double *CosDec;
double *AntLon;
int *Mount;
double *Lat;
int NtotAnt;
int NtotSou;
int **BasNum;
} ArrayGeometry;


typedef struct {
    int AntIdx;
    int IF;
    int Pol;
    double JD;
    double *AC;
    
} AutoCorrelation;


//   int NtotAnt, NtotSou;
//  double *BaseLine[3], *SinDec, *CosDec, *AntLon, *TanLat, **BasNum;
//   double *ParAngs[2];


/* Class to read FITS-IDI or SWIN files, setup the data streams,
and iterate over all the baselines with mixed polarization. */

class DataIO {
  public:

   ~DataIO();

   DataIO(); 

   int getNfreqs();
   int getNant();

   int getNchan(int freqid);
   long getMixedNvis();
   bool succeed();

   double getDay0();

   void getFrequencies(double* Freqarray);

// Compute parallactic angle.
  void getParAng(int sidx, int Ant1, int Ant2, double*UVW, double &P1, double &P2);

// Estimate amplitude ratios from the autocorrelations:
  std::complex<float> getAmpRatio(int ant, int spw, int chan);
  
  
// Set the current IF (and reset the mixed-vis. counter):
   virtual bool setCurrentIF(int i) = 0;


/* Very important function. Finds the next combination of the 4 correlation
   products. Returns the visibilities as an array of pointers;
   It also returns the time of the visibility and the ids of the antennas in the baseline. 
   If more than one lin-pol antenna are present, this function will still work, and will 
   return the pure-linear visibilities twice, one iteration for each antenna (the same is 
   true for the auto-correlations of each lin-pol antenna). 
   Returns false if no more mixed-pol visibilities are found for the corresponding IF. */
   virtual bool getNextMixedVis(double &JDTime, int &antenna, int &otherAnt, bool &conj, int &calField) = 0;


/* Complementary to the function above. Once the visibilities have been 
   corrected, this function puts them back into the right place. */
   virtual bool setCurrentMixedVis() = 0;


 // Modify the visibilities read by "getNextMixedVis" by the calibration matrix supplied
 // Saves the result in the "bufferVis" pointer  
  virtual void applyMatrix(std::complex<float> *M[2][2], bool swap, bool print, int thisAnt, FILE *plotFile) = 0;


 // Flag bad (unconvertable) data:
  virtual void zeroWeight() = 0;

// Close all files.
   virtual void finish() = 0;



   static const int MAXIF = 256;
   FreqSetup *Freqs;
   ArrayGeometry *Geometry;
   AutoCorrelation *AutoCorrs;
   float ***averAutocorrs;
   double *Freqvals[MAXIF], *doRange, *JDTimes;
   int *Basels, *Freqids, *an1, *an2, *linAnts, *field; //, *sour;
   double *ParAng[2];
   int NLinAnt, NIFs, Nband, status, Nants, Nfreqs, currFreq;
   long NLinVis, Nvis, currVis, *indexes;
   bool success, currConj;
   bool *conjugate, *is1, *is2, *is1orig, *is2orig;
   int Flux, *NAV;
   int nautos = 0;
   double day0;


};




#endif