| 1 | #include "machdefs.h" | 
|---|
| 2 | #include <stdlib.h> | 
|---|
| 3 | #include <stdio.h> | 
|---|
| 4 | #include <math.h> | 
|---|
| 5 |  | 
|---|
| 6 | #include "scan.h" | 
|---|
| 7 |  | 
|---|
| 8 | // valeurs de Pi, 2*Pi, etc | 
|---|
| 9 | #include "nbmath.h" | 
|---|
| 10 |  | 
|---|
| 11 |  | 
|---|
| 12 | // | 
|---|
| 13 | //++ | 
|---|
| 14 | // Class        Scan | 
|---|
| 15 | // | 
|---|
| 16 | // include      scan.h  nbmath.h | 
|---|
| 17 | // | 
|---|
| 18 | //    Cette classe permet de stocker et traiter les données pour un balayage | 
|---|
| 19 | //    d'une portion de ciel pour un jeu de valeurs fixé des paramètres précisé | 
|---|
| 20 | //    dans le constructeur. | 
|---|
| 21 | //-- | 
|---|
| 22 | //++ | 
|---|
| 23 | // | 
|---|
| 24 | // Links        Parents | 
|---|
| 25 | // | 
|---|
| 26 | // | 
|---|
| 27 | //-- | 
|---|
| 28 | //++ | 
|---|
| 29 | // | 
|---|
| 30 | // Links        Descendants | 
|---|
| 31 | // | 
|---|
| 32 | // | 
|---|
| 33 | //-- | 
|---|
| 34 | //++ | 
|---|
| 35 | // Titre        Constructeurs | 
|---|
| 36 | //-- | 
|---|
| 37 | //++ | 
|---|
| 38 | Scan::Scan(float Ouv,float* Omega,float Fech,float T, | 
|---|
| 39 | float t0=0., float phi0=0.) | 
|---|
| 40 |  | 
|---|
| 41 | // | 
|---|
| 42 | //    * Ouv      = angle d'ouverture (rad) | 
|---|
| 43 | //    * Omega[3] = direction de l'axe de rotation du satellite (teta,phi) | 
|---|
| 44 | //    et vitesse de rotation (rad/s) | 
|---|
| 45 | //    * Fech     = fréquence d'échantillonnage (Hz) | 
|---|
| 46 | //    * T        = temps total de prise des données (s) | 
|---|
| 47 | //    * t0       = instant de départ (s) | 
|---|
| 48 | //    * phi0     = offset antenne (rad) | 
|---|
| 49 | //-- | 
|---|
| 50 | { | 
|---|
| 51 | mInfo_=NULL; | 
|---|
| 52 | // On memorise les arguments d'appel | 
|---|
| 53 | Ouverture_= Ouv; | 
|---|
| 54 | OmegaTeta_= Omega[0]; | 
|---|
| 55 | // | 
|---|
| 56 | // je ne comprends pas ce qui se passe ci-apres (GLM) | 
|---|
| 57 | if( (Omega[0]== 0.0) || (Omega[0]==(float)Pi) ) | 
|---|
| 58 | OmegaPhi_ = Omega[1]; | 
|---|
| 59 | else | 
|---|
| 60 | OmegaPhi_ = Omega[1]+(float)Pi/2.; | 
|---|
| 61 | OmegaRad_ = Omega[2]; | 
|---|
| 62 | FrequenceEch_  = Fech; | 
|---|
| 63 | TempsFinal_    = T; | 
|---|
| 64 | TempsInitial_  = t0; | 
|---|
| 65 | PhiZero_ = phi0; | 
|---|
| 66 |  | 
|---|
| 67 | float aux= 0.0; | 
|---|
| 68 | // Nombre total de points | 
|---|
| 69 | aux= (TempsFinal_-TempsInitial_)*FrequenceEch_; | 
|---|
| 70 | NmaxPts_= (int_4)(aux); | 
|---|
| 71 |  | 
|---|
| 72 | // Nombre total de tours | 
|---|
| 73 | aux= OmegaRad_*(TempsFinal_-TempsInitial_)/(2.*Pi); | 
|---|
| 74 | NmaxTrs_= (int_4)(aux); | 
|---|
| 75 |  | 
|---|
| 76 | // Nombre de points par tour | 
|---|
| 77 | aux= 2.*Pi*FrequenceEch_/OmegaRad_; | 
|---|
| 78 | NPts1Tr_= (int_4)(aux); | 
|---|
| 79 |  | 
|---|
| 80 | // Creation et initialisation du vecteur des mesures aux points | 
|---|
| 81 | sPix_ = new r_8[NmaxPts_]; | 
|---|
| 82 | for( int_4 i=0; i<NmaxPts_; i++ )  sPix_[i]= 0.; | 
|---|
| 83 |  | 
|---|
| 84 | // matrice de passage du systeme lie au satellite au systeme fixe | 
|---|
| 85 |  | 
|---|
| 86 | Rota_[0]=  cos((double)OmegaPhi_); | 
|---|
| 87 | Rota_[1]= -sin((double)OmegaPhi_)*cos((double)OmegaTeta_); | 
|---|
| 88 | Rota_[2]=  sin((double)OmegaPhi_)*sin((double)OmegaTeta_); | 
|---|
| 89 | Rota_[3]=  sin((double)OmegaPhi_); | 
|---|
| 90 | Rota_[4]=  cos((double)OmegaPhi_)*cos((double)OmegaTeta_); | 
|---|
| 91 | Rota_[5]= -cos((double)OmegaPhi_)*sin((double)OmegaTeta_); | 
|---|
| 92 | Rota_[6]=  0.0; | 
|---|
| 93 | Rota_[7]=  sin((double)OmegaTeta_); | 
|---|
| 94 | Rota_[8]=  cos((double)OmegaTeta_); | 
|---|
| 95 |  | 
|---|
| 96 |  | 
|---|
| 97 | // printf("%f  %f  %f \n",Rota_[0],Rota_[1],Rota_[2]); | 
|---|
| 98 | // printf("%f  %f  %f \n",Rota_[3],Rota_[4],Rota_[5]); | 
|---|
| 99 | // printf("%f  %f  %f \n",Rota_[6],Rota_[7],Rota_[8]); | 
|---|
| 100 |  | 
|---|
| 101 | } | 
|---|
| 102 | //++ | 
|---|
| 103 | Scan::Scan(const Scan& s) | 
|---|
| 104 |  | 
|---|
| 105 | //    Constructeur de copie | 
|---|
| 106 | //-- | 
|---|
| 107 | { | 
|---|
| 108 | NmaxPts_      = s. NmaxPts_; | 
|---|
| 109 | Ouverture_    = s.Ouverture_; | 
|---|
| 110 | OmegaTeta_    = s.OmegaTeta_; | 
|---|
| 111 | OmegaPhi_     = s.OmegaPhi_; | 
|---|
| 112 | OmegaRad_     = s.OmegaRad_; | 
|---|
| 113 | FrequenceEch_ = s. FrequenceEch_; | 
|---|
| 114 | TempsFinal_ = s.TempsFinal_; | 
|---|
| 115 | TempsInitial_ = s.TempsInitial_; | 
|---|
| 116 | PhiZero_ = s. PhiZero_; | 
|---|
| 117 | sPix_=new r_8[ NmaxPts_]; | 
|---|
| 118 | for (int_4 k=0; k<NmaxPts_; k++)  sPix_[k]=s.sPix_[k]; | 
|---|
| 119 | for (int k=0; k<9; k++) Rota_[k]=s. Rota_[k]; | 
|---|
| 120 | } | 
|---|
| 121 | //++ | 
|---|
| 122 | // Titre        Destructeur | 
|---|
| 123 | //-- | 
|---|
| 124 | //++ | 
|---|
| 125 | Scan::~Scan() | 
|---|
| 126 |  | 
|---|
| 127 | // | 
|---|
| 128 | //-- | 
|---|
| 129 | { | 
|---|
| 130 | delete[] sPix_ ; | 
|---|
| 131 | } | 
|---|
| 132 | //++ | 
|---|
| 133 | void Scan::WriteSelf(POutPersist& s) const | 
|---|
| 134 |  | 
|---|
| 135 | //    créer un fichier persistant | 
|---|
| 136 | //-- | 
|---|
| 137 | { | 
|---|
| 138 | char strg[256]; | 
|---|
| 139 | if (mInfo_) {sprintf(strg, "Scan: Theta=%9f Phi=%9f omega=%9f HasInfo", (float)OmegaTeta_, (float)OmegaPhi_, (float)OmegaRad_); | 
|---|
| 140 | } | 
|---|
| 141 | else {sprintf(strg, "Scan: Theta=%9f Phi=%9f omega=%9f ", (float)OmegaTeta_, (float)OmegaPhi_, (float)OmegaRad_); | 
|---|
| 142 | } | 
|---|
| 143 | s.PutLine(strg); | 
|---|
| 144 | if (mInfo_)  s << (*mInfo_); | 
|---|
| 145 | s.PutI4( NmaxPts_); | 
|---|
| 146 | s.PutI4(NmaxTrs_); | 
|---|
| 147 | s.PutI4( NPts1Tr_); | 
|---|
| 148 | s.PutR4(Ouverture_); | 
|---|
| 149 | s.PutR4(OmegaTeta_); | 
|---|
| 150 | s.PutR4(OmegaPhi_); | 
|---|
| 151 | s.PutR4(OmegaRad_); | 
|---|
| 152 | s.PutR4(FrequenceEch_); | 
|---|
| 153 | s.PutR4(TempsFinal_); | 
|---|
| 154 | s.PutR4( TempsInitial_); | 
|---|
| 155 | s.PutR4( PhiZero_); | 
|---|
| 156 | s.PutR8s(sPix_,NmaxPts_); | 
|---|
| 157 | s.PutR8s(Rota_, 9); | 
|---|
| 158 | return; | 
|---|
| 159 | } | 
|---|
| 160 |  | 
|---|
| 161 |  | 
|---|
| 162 | //++ | 
|---|
| 163 | void Scan::ReadSelf(PInPersist& s) | 
|---|
| 164 |  | 
|---|
| 165 | //    relire un fichier persistant | 
|---|
| 166 | //-- | 
|---|
| 167 | { | 
|---|
| 168 | Clear(); | 
|---|
| 169 | char strg[256]; | 
|---|
| 170 | s.GetLine(strg,255); | 
|---|
| 171 | // Pour savoir s'il y avait un DVList Info associe | 
|---|
| 172 | bool hadinfo = false; | 
|---|
| 173 | if (strncmp(strg+strlen(strg)-7, "HasInfo", 7) == 0)  hadinfo = true; | 
|---|
| 174 | // Pour savoir s'il y avait un DVList Info associe | 
|---|
| 175 | if (hadinfo) {    // Lecture eventuelle du DVList Info | 
|---|
| 176 | if (mInfo_ == NULL)  mInfo_ = new DVList; | 
|---|
| 177 | s >> (*mInfo_); | 
|---|
| 178 | } | 
|---|
| 179 | s.GetI4( NmaxPts_); | 
|---|
| 180 | s.GetI4(NmaxTrs_); | 
|---|
| 181 | s.GetI4( NPts1Tr_); | 
|---|
| 182 | s.GetR4(Ouverture_); | 
|---|
| 183 | s.GetR4(OmegaTeta_); | 
|---|
| 184 | s.GetR4(OmegaPhi_); | 
|---|
| 185 | s.GetR4(OmegaRad_); | 
|---|
| 186 | s.GetR4(FrequenceEch_); | 
|---|
| 187 | s.GetR4(TempsFinal_); | 
|---|
| 188 | s.GetR4( TempsInitial_); | 
|---|
| 189 | s.GetR4( PhiZero_); | 
|---|
| 190 | sPix_=new r_8[NmaxPts_]; | 
|---|
| 191 | s.GetR8s(sPix_,NmaxPts_); | 
|---|
| 192 | s.GetR8s(Rota_, 9); | 
|---|
| 193 | } | 
|---|
| 194 |  | 
|---|
| 195 |  | 
|---|
| 196 | //++ | 
|---|
| 197 | // Titre        Méthodes | 
|---|
| 198 | //-- | 
|---|
| 199 |  | 
|---|
| 200 | //++ | 
|---|
| 201 | int_4 Scan::NbPoints() const | 
|---|
| 202 |  | 
|---|
| 203 | //    Retourne le nombre de Points du scan | 
|---|
| 204 | //-- | 
|---|
| 205 | { | 
|---|
| 206 | return(NmaxPts_); | 
|---|
| 207 | } | 
|---|
| 208 |  | 
|---|
| 209 | /* --Methode-- */ | 
|---|
| 210 | //++ | 
|---|
| 211 | int_4 Scan::NbTours() const | 
|---|
| 212 |  | 
|---|
| 213 | //    Retourne le nombre total de tours | 
|---|
| 214 | //-- | 
|---|
| 215 | { | 
|---|
| 216 | return(NmaxTrs_); | 
|---|
| 217 | } | 
|---|
| 218 |  | 
|---|
| 219 | /* --Methode-- */ | 
|---|
| 220 | //++ | 
|---|
| 221 | int_4 Scan::NbPts1Tr() const | 
|---|
| 222 |  | 
|---|
| 223 | //    Retourne le nombre de points pour 1 tour | 
|---|
| 224 | //-- | 
|---|
| 225 | { | 
|---|
| 226 | return(NPts1Tr_); | 
|---|
| 227 | } | 
|---|
| 228 |  | 
|---|
| 229 | /* --Methode-- */ | 
|---|
| 230 | //++ | 
|---|
| 231 | int_4 Scan::ValueIndex(float t) const | 
|---|
| 232 |  | 
|---|
| 233 | //    Retourne l'indice du pixel associé au temps t | 
|---|
| 234 | //-- | 
|---|
| 235 | { | 
|---|
| 236 | int_4 k; | 
|---|
| 237 | float eps= 1.0E-06; | 
|---|
| 238 |  | 
|---|
| 239 | // verification si t est dans [TempsInitial_,TempsFinal_] | 
|---|
| 240 | if( (t< TempsInitial_) || (t> TempsFinal_) ) { | 
|---|
| 241 | printf("\n ValueIndex:: probleme sur le temps t= %f",t); | 
|---|
| 242 | return(-1); | 
|---|
| 243 | } | 
|---|
| 244 |  | 
|---|
| 245 | k= (int_4)((t-TempsInitial_)*FrequenceEch_+eps); | 
|---|
| 246 | if ( (k< 0) || (k >= NmaxPts_) ) { | 
|---|
| 247 | printf("\n ValueIndex:: probleme sur l'indice du point k= %d",k); | 
|---|
| 248 | return(-1); | 
|---|
| 249 | } | 
|---|
| 250 | return(k); | 
|---|
| 251 | } | 
|---|
| 252 |  | 
|---|
| 253 | /* --Methode-- */ | 
|---|
| 254 | //++ | 
|---|
| 255 | void Scan::Direction(float t, float&  teta , float&  phi) | 
|---|
| 256 |  | 
|---|
| 257 | //    Retourne les coordonnées (teta,phi) du pixel lié au temps t | 
|---|
| 258 | //-- | 
|---|
| 259 | { | 
|---|
| 260 | r_8 alfa,xs,ys,zs,x,y,z; | 
|---|
| 261 |  | 
|---|
| 262 | // coordonnees dans le systeme du satellite | 
|---|
| 263 | alfa= OmegaRad_*(t-TempsInitial_)+PhiZero_; | 
|---|
| 264 | xs = sin((double)Ouverture_)*cos(alfa); | 
|---|
| 265 | ys = sin((double)Ouverture_)*sin(alfa); | 
|---|
| 266 | zs = cos((double)Ouverture_); | 
|---|
| 267 |  | 
|---|
| 268 | // coordonnees dans le systeme fixe | 
|---|
| 269 | x = Rota_[0]*xs+Rota_[1]*ys+Rota_[2]*zs; | 
|---|
| 270 | y = Rota_[3]*xs+Rota_[4]*ys+Rota_[5]*zs; | 
|---|
| 271 | z = Rota_[6]*xs+Rota_[7]*ys+Rota_[8]*zs; | 
|---|
| 272 |  | 
|---|
| 273 | // angles teta,phi | 
|---|
| 274 | teta = acos(z); | 
|---|
| 275 | phi  = atan2(y,x); | 
|---|
| 276 | if( phi< 0. ) phi= DeuxPi+phi; | 
|---|
| 277 | } | 
|---|
| 278 |  | 
|---|
| 279 | /* --Methode-- */ | 
|---|
| 280 | //++ | 
|---|
| 281 | void Scan::DirectionIndex(int_4 k, float&  teta, float&  phi) | 
|---|
| 282 |  | 
|---|
| 283 | //    Retourne les coordonnées (teta,phi) du pixel d'indice k | 
|---|
| 284 | //-- | 
|---|
| 285 | { | 
|---|
| 286 | float t; | 
|---|
| 287 |  | 
|---|
| 288 | //recupere le temps associe a l'indice k du pixel | 
|---|
| 289 | t= TempsInitial_+(float)k/FrequenceEch_; | 
|---|
| 290 |  | 
|---|
| 291 | // angles teta,phi | 
|---|
| 292 | Direction(t, teta, phi); | 
|---|
| 293 | } | 
|---|
| 294 |  | 
|---|
| 295 | static r_8 dummy_pixel = 0; | 
|---|
| 296 | /* --Methode-- */ | 
|---|
| 297 | //++ | 
|---|
| 298 | r_8& Scan::PixelValue(int_4 k) const | 
|---|
| 299 |  | 
|---|
| 300 | //    Retourne la valeur du contenu du pixel d'indice k | 
|---|
| 301 | //-- | 
|---|
| 302 | { | 
|---|
| 303 | if ( (k<0) || (k >=  NmaxPts_) ) { | 
|---|
| 304 | printf("\n ValueIndex::indice du pixel errone k= %d",k); | 
|---|
| 305 | return(dummy_pixel); | 
|---|
| 306 | } | 
|---|
| 307 | return(sPix_[k]); | 
|---|
| 308 | } | 
|---|
| 309 |  | 
|---|
| 310 | void Scan::Clear() { | 
|---|
| 311 | if (sPix_)  delete[] sPix_; | 
|---|
| 312 | } | 
|---|
| 313 | void Scan::InitNull() { | 
|---|
| 314 | sPix_=NULL; | 
|---|
| 315 | mInfo_=NULL; | 
|---|
| 316 | } | 
|---|
| 317 |  | 
|---|
| 318 |  | 
|---|
| 319 | //++ | 
|---|
| 320 | // Titre        Opérateurs | 
|---|
| 321 | //-- | 
|---|
| 322 | //++ | 
|---|
| 323 | // Links        double&        operator()(int_4 k) | 
|---|
| 324 | //-- | 
|---|
| 325 | //++ | 
|---|
| 326 | //    Surcharge de la parenthese a un indice entier : remplit ou/et renvoie | 
|---|
| 327 | //    la valeur du contenu du pixel d'indice k | 
|---|
| 328 | //-- | 
|---|
| 329 |  | 
|---|
| 330 |  | 
|---|
| 331 |  | 
|---|
| 332 |  | 
|---|
| 333 |  | 
|---|