~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
/* 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 <stdlib.h>  
#include <string.h>
#include <math.h>
#include <dirent.h>
#include "DataIO.h"
#include "fitsio.h"


//#define   NIOBUF = 1;




DataIO::~DataIO() {

};

DataIO::DataIO() { printf("\nCreating VLBI data structure");};


// SELF-EXPLANATORY FUNCTIONS:
int DataIO::getNfreqs() {return Nfreqs;};  // NUMBER OF IFs
int DataIO::getNant() {return Nants;};  // TOTAL NUMBER OF ANTENNAS
int DataIO::getNchan(int freqid) {return Freqs[freqid].Nchan;};  // # OF CHANNEL IN freqid IF
long DataIO::getMixedNvis() {return NLinVis;};  // NUMBER OF MIXED-POLARIZATION VISIBILITIES FOUND



// GET FREQUENCIES OF CURRENT IF:
void DataIO::getFrequencies(double* output){
memcpy(output,Freqvals[currFreq],Freqs[currFreq].Nchan*sizeof(double));
};


// CHECK WHETHER SOMETHING FAILED:
bool DataIO::succeed(){return success;};


// GET FIRST DAY OF OBSERVATION (MODIFIED JULIAN DATE)
double DataIO::getDay0(){return day0;};







void DataIO::getParAng(int sidx, int Ant1, int Ant2, double*UVW, double &P1, double &P2){

double V2, Bx, By, Bz;
double CH, SH, CT1, CT2, HAng, H1, H2;
int ibas;


if(sidx<Geometry->NtotSou && Ant1<Geometry->NtotAnt && Ant2<Geometry->NtotAnt){

  V2 = Geometry->SinDec[sidx]*UVW[1] - Geometry->CosDec[sidx]*UVW[2];
  ibas = Geometry->BasNum[Ant1][Ant2];


  if (ibas<0){
  ibas = -ibas;
   Bx = -Geometry->BaseLine[0][ibas];
   By = -Geometry->BaseLine[1][ibas];
   Bz = -Geometry->BaseLine[2][ibas];
  } else {
   Bx = Geometry->BaseLine[0][ibas];
   By = Geometry->BaseLine[1][ibas];
   Bz = Geometry->BaseLine[2][ibas];
  };

  CH = (UVW[0]*By - V2*Bx); // /(By**2. + Bx**2.);
  SH = (UVW[0]*Bx + V2*By); // /(By**2. + Bx**2.);
  CT1 = Geometry->CosDec[sidx]*tan(Geometry->Lat[Ant1]);
  CT2 = Geometry->CosDec[sidx]*tan(Geometry->Lat[Ant2]);

  HAng = atan2(SH,CH);
  H1 = HAng + Geometry->AntLon[Ant1];
  H2 = HAng + Geometry->AntLon[Ant2];

  P1 = atan2(sin(H1), CT1 - Geometry->SinDec[sidx]*cos(H1));
  P2 = atan2(sin(H2), CT2 - Geometry->SinDec[sidx]*cos(H2));


} else {

  P1 = 0.0;
  P2 = 0.0;

};

};