source: Sophya/trunk/SophyaExt/FitsIOServer/datacirclefits.cc@ 1816

Last change on this file since 1816 was 1816, checked in by ansari, 24 years ago

remplacement nint() qui n'existe que sous OSF par l_ft_nint() ds datacirclefits.cc - Reza 16/12/01

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