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