[1770] | 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 |
|
---|
[1816] | 8 | /* La fonction nint(double) n'existe pas partout ! */
|
---|
| 9 | static long l_ft_nint(double x)
|
---|
| 10 | {
|
---|
| 11 | return ( (x < 0.) ? (long)(x-0.5) : (long)(x+0.5) ) ;
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 |
|
---|
[1770] | 15 | DataCircleFits::DataCircleFits() :
|
---|
| 16 | _fptr(NULL)
|
---|
| 17 | , _NMeasurements(0)
|
---|
| 18 | , _ICircle(0)
|
---|
| 19 | , _mesures(NULL)
|
---|
[1815] | 20 | , _stored_data(false)
|
---|
[1770] | 21 | {;}
|
---|
| 22 |
|
---|
[1815] | 23 | DataCircleFits::DataCircleFits(fitsfile *is,int hdunum,bool sdata) :
|
---|
[1770] | 24 | _fptr(NULL)
|
---|
| 25 | , _NMeasurements(0)
|
---|
| 26 | , _ICircle(hdunum)
|
---|
| 27 | , _mesures(NULL)
|
---|
[1815] | 28 | , _stored_data(sdata)
|
---|
[1770] | 29 | {
|
---|
| 30 |
|
---|
| 31 | // pointer to the FITS file
|
---|
[1815] | 32 | _fptr= is;
|
---|
| 33 | int status = 0;
|
---|
[1770] | 34 |
|
---|
| 35 | // move to the HDU containing a circle
|
---|
[1815] | 36 | fits_movabs_hdu(_fptr,hdunum,NULL,&status);
|
---|
[1770] | 37 |
|
---|
| 38 | // angles of the circle
|
---|
[1815] | 39 | double theta;
|
---|
| 40 | fits_read_key(_fptr,TDOUBLE,"CIRTHETA",&theta,NULL,&status);
|
---|
[1770] | 41 |
|
---|
[1815] | 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 |
|
---|
[1770] | 48 | UnitVector temp(theta,phi);
|
---|
| 49 | SetCircle(temp,aperture);
|
---|
| 50 |
|
---|
[1815] | 51 | fits_read_key(_fptr,TINT,"NSAMPLES",&_NMeasurements,NULL,&status);
|
---|
[1770] | 52 |
|
---|
[1815] | 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];
|
---|
[1770] | 61 | int i;
|
---|
| 62 | for(i = 0; i < _NMeasurements; i++) {
|
---|
[1815] | 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);
|
---|
[1770] | 75 | }
|
---|
[1815] | 76 | }
|
---|
[1770] | 77 | }
|
---|
[1815] | 78 |
|
---|
[1770] | 79 | DataCircleFits::~DataCircleFits() {
|
---|
| 80 |
|
---|
| 81 | if(_mesures != NULL) delete [] _mesures;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | int DataCircleFits::NMeasurements() const {
|
---|
| 85 |
|
---|
| 86 | return _NMeasurements;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | double DataCircleFits::getData(double psi) const {
|
---|
| 90 |
|
---|
| 91 | double dtab;
|
---|
[1816] | 92 | int ibin= l_ft_nint(psi*_NMeasurements/(2.*M_PI));
|
---|
[1815] | 93 | //cout << " ibin= " << ibin << ", " << psi << endl;
|
---|
[1770] | 94 |
|
---|
| 95 | if(_stored_data) {
|
---|
| 96 | dtab= _mesures[ibin];
|
---|
| 97 | } else {
|
---|
[1815] | 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);
|
---|
[1770] | 118 | }
|
---|
| 119 | //cout << "DataCircleFits:: bin= " << ibin << ", " << dtab << endl;
|
---|
| 120 | return dtab;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | void DataCircleFits::print(ostream& out) const {
|
---|
| 124 |
|
---|
| 125 | out << " Circle:: ApertureAngle= " << ApertureAngle() << ", Theta= "
|
---|
| 126 | << Theta() << ", Phi= " << Phi() << ", NSamples= "
|
---|
| 127 | << NMeasurements() << endl;
|
---|
| 128 | }
|
---|
[1815] | 129 |
|
---|
| 130 | double 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 | }
|
---|
[1816] | 137 | int ibin= l_ft_nint(psi*_NMeasurements/(2.*M_PI));
|
---|
[1815] | 138 | return _mesures[ibin];
|
---|
| 139 | }
|
---|
| 140 | double 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 | }
|
---|