1 | #include <iostream>
|
---|
2 | #include "sopnamsp.h"
|
---|
3 | #include "datacirclefits.h"
|
---|
4 |
|
---|
5 | /*
|
---|
6 | Class used to recover the circles and measures involved in a mission. The parameters needful to create a circle and the number of samples on this circle are read from a FITS data array. In addition, a function returns the measurement at a given angular position psi on the circle.
|
---|
7 | */
|
---|
8 |
|
---|
9 | DataCircleFits::DataCircleFits() :
|
---|
10 | _fptr(NULL)
|
---|
11 | , _NMeasurements(0)
|
---|
12 | , _ICircle(0)
|
---|
13 | , _mesures(NULL)
|
---|
14 | , _stored_data(false)
|
---|
15 | {;}
|
---|
16 |
|
---|
17 | DataCircleFits::DataCircleFits(fitsfile *is,int hdunum,bool sdata) :
|
---|
18 | _fptr(NULL)
|
---|
19 | , _NMeasurements(0)
|
---|
20 | , _ICircle(hdunum)
|
---|
21 | , _mesures(NULL)
|
---|
22 | , _stored_data(sdata)
|
---|
23 | {
|
---|
24 |
|
---|
25 | // pointer to the FITS file
|
---|
26 | _fptr= is;
|
---|
27 | int status = 0;
|
---|
28 |
|
---|
29 | // move to the HDU containing a circle
|
---|
30 | fits_movabs_hdu(_fptr,hdunum,NULL,&status);
|
---|
31 |
|
---|
32 | // angles of the circle
|
---|
33 | double theta;
|
---|
34 | fits_read_key(_fptr,TDOUBLE,"CIRTHETA",&theta,NULL,&status);
|
---|
35 |
|
---|
36 | double phi;
|
---|
37 | fits_read_key(_fptr,TDOUBLE,"CIRPHI",&phi,NULL,&status);
|
---|
38 |
|
---|
39 | double aperture;
|
---|
40 | fits_read_key(_fptr,TDOUBLE,"CIRAPER",&aperture,NULL,&status);
|
---|
41 |
|
---|
42 | UnitVector temp(theta,phi);
|
---|
43 | SetCircle(temp,aperture);
|
---|
44 |
|
---|
45 | fits_read_key(_fptr,TINT,"NSAMPLES",&_NMeasurements,NULL,&status);
|
---|
46 |
|
---|
47 | if(_stored_data) {
|
---|
48 | // vector repeat value for the column (there is only 1 column)
|
---|
49 | long repeat;
|
---|
50 | fits_get_coltype(_fptr,1,NULL,&repeat,NULL,&status);
|
---|
51 |
|
---|
52 | double dnull= 0.;
|
---|
53 | int anull;
|
---|
54 | _mesures= new double[_NMeasurements];
|
---|
55 | int i;
|
---|
56 | for(i = 0; i < _NMeasurements; i++) {
|
---|
57 | // row index: range 1 to NAXIS2
|
---|
58 | int index= i+1;
|
---|
59 |
|
---|
60 | // starting line index
|
---|
61 | int stline= index/repeat;
|
---|
62 | int stelem= index-stline*repeat;
|
---|
63 | if(stelem != 0) {
|
---|
64 | stline++;
|
---|
65 | } else {
|
---|
66 | stelem= repeat;
|
---|
67 | }
|
---|
68 | fits_read_col(_fptr,TDOUBLE,1,stline,stelem,1,&dnull,&_mesures[i],&anull,&status);
|
---|
69 | }
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | DataCircleFits::~DataCircleFits() {
|
---|
74 |
|
---|
75 | if(_mesures != NULL) delete [] _mesures;
|
---|
76 | }
|
---|
77 |
|
---|
78 | int DataCircleFits::NMeasurements() const {
|
---|
79 |
|
---|
80 | return _NMeasurements;
|
---|
81 | }
|
---|
82 |
|
---|
83 | double DataCircleFits::getData(double psi) const {
|
---|
84 |
|
---|
85 | double dtab;
|
---|
86 | int ibin= l_ft_nint(psi*_NMeasurements/(2.*M_PI));
|
---|
87 | //cout << " ibin= " << ibin << ", " << psi << endl;
|
---|
88 |
|
---|
89 | if(_stored_data) {
|
---|
90 | dtab= _mesures[ibin];
|
---|
91 | } else {
|
---|
92 | int status= 0;
|
---|
93 | fits_movabs_hdu(_fptr,_ICircle,NULL,&status);
|
---|
94 |
|
---|
95 | // vector repeat value for the column (there is only 1 column)
|
---|
96 | long repeat;
|
---|
97 | fits_get_coltype(_fptr,1,NULL,&repeat,NULL,&status);
|
---|
98 |
|
---|
99 | double dnull= 0.;
|
---|
100 | int anull;
|
---|
101 |
|
---|
102 | int index= ibin+1;
|
---|
103 | // starting line index
|
---|
104 | int stline= index/repeat;
|
---|
105 | int stelem= index-stline*repeat;
|
---|
106 | if(stelem != 0) {
|
---|
107 | stline++;
|
---|
108 | } else {
|
---|
109 | stelem= repeat;
|
---|
110 | }
|
---|
111 | fits_read_col(_fptr,TDOUBLE,1,stline,stelem,1,&dnull,&dtab,&anull,&status);
|
---|
112 | }
|
---|
113 | //cout << "DataCircleFits:: bin= " << ibin << ", " << dtab << endl;
|
---|
114 | return dtab;
|
---|
115 | }
|
---|
116 |
|
---|
117 | void DataCircleFits::print(ostream& out) const {
|
---|
118 |
|
---|
119 | out << " Circle:: ApertureAngle= " << ApertureAngle() << ", Theta= "
|
---|
120 | << Theta() << ", Phi= " << Phi() << ", NSamples= "
|
---|
121 | << NMeasurements() << endl;
|
---|
122 | }
|
---|
123 |
|
---|
124 | double DataCircleFits::getTMeasure(double psi) const {
|
---|
125 |
|
---|
126 | if(_mesures == NULL) {
|
---|
127 | cout << " DataCircleFits::getTMeasure data must be stored"
|
---|
128 | << " in an array... verify the option" << endl;
|
---|
129 | exit(0);
|
---|
130 | }
|
---|
131 | int ibin= l_ft_nint(psi*_NMeasurements/(2.*M_PI));
|
---|
132 | return _mesures[ibin];
|
---|
133 | }
|
---|
134 |
|
---|
135 | double DataCircleFits::getTOffset() const {
|
---|
136 |
|
---|
137 | int status= 0;
|
---|
138 | fits_movabs_hdu(_fptr,_ICircle,NULL,&status);
|
---|
139 |
|
---|
140 | double omes= 0.0;
|
---|
141 | fits_read_key_dbl(_fptr,"OFFSET",&omes,NULL,&status);
|
---|
142 | return omes;
|
---|
143 | }
|
---|