source: Sophya/trunk/SophyaLib/Samba/scan.cc@ 515

Last change on this file since 515 was 515, checked in by ansari, 26 years ago

Portage SGI-CC Reza 26/10/99

  • Property svn:executable set to *
File size: 7.1 KB
Line 
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//++
38Scan::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//++
103Scan::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 int_4 k;
119 for (k=0; k<NmaxPts_; k++) sPix_[k]=s.sPix_[k];
120 for (k=0; k<9; k++) Rota_[k]=s. Rota_[k];
121}
122//++
123// Titre Destructeur
124//--
125//++
126Scan::~Scan()
127
128//
129//--
130{
131 delete[] sPix_ ;
132}
133//++
134void Scan::WriteSelf(POutPersist& s) const
135
136// créer un fichier persistant
137//--
138{
139 char strg[256];
140 if (mInfo_) {sprintf(strg, "Scan: Theta=%9f Phi=%9f omega=%9f HasInfo", (float)OmegaTeta_, (float)OmegaPhi_, (float)OmegaRad_);
141 }
142 else {sprintf(strg, "Scan: Theta=%9f Phi=%9f omega=%9f ", (float)OmegaTeta_, (float)OmegaPhi_, (float)OmegaRad_);
143 }
144 s.PutLine(strg);
145 if (mInfo_) s << (*mInfo_);
146 s.PutI4( NmaxPts_);
147 s.PutI4(NmaxTrs_);
148 s.PutI4( NPts1Tr_);
149 s.PutR4(Ouverture_);
150 s.PutR4(OmegaTeta_);
151 s.PutR4(OmegaPhi_);
152 s.PutR4(OmegaRad_);
153 s.PutR4(FrequenceEch_);
154 s.PutR4(TempsFinal_);
155 s.PutR4( TempsInitial_);
156 s.PutR4( PhiZero_);
157 s.PutR8s(sPix_,NmaxPts_);
158 s.PutR8s(Rota_, 9);
159 return;
160}
161
162
163//++
164void Scan::ReadSelf(PInPersist& s)
165
166// relire un fichier persistant
167//--
168{
169 Clear();
170 char strg[256];
171 s.GetLine(strg,255);
172// Pour savoir s'il y avait un DVList Info associe
173 bool hadinfo = false;
174 if (strncmp(strg+strlen(strg)-7, "HasInfo", 7) == 0) hadinfo = true;
175// Pour savoir s'il y avait un DVList Info associe
176 if (hadinfo) { // Lecture eventuelle du DVList Info
177 if (mInfo_ == NULL) mInfo_ = new DVList;
178 s >> (*mInfo_);
179 }
180 s.GetI4( NmaxPts_);
181 s.GetI4(NmaxTrs_);
182 s.GetI4( NPts1Tr_);
183 s.GetR4(Ouverture_);
184 s.GetR4(OmegaTeta_);
185 s.GetR4(OmegaPhi_);
186 s.GetR4(OmegaRad_);
187 s.GetR4(FrequenceEch_);
188 s.GetR4(TempsFinal_);
189 s.GetR4( TempsInitial_);
190 s.GetR4( PhiZero_);
191 sPix_=new r_8[NmaxPts_];
192 s.GetR8s(sPix_,NmaxPts_);
193 s.GetR8s(Rota_, 9);
194}
195
196
197//++
198// Titre Méthodes
199//--
200
201//++
202int_4 Scan::NbPoints() const
203
204// Retourne le nombre de Points du scan
205//--
206{
207 return(NmaxPts_);
208}
209
210/* --Methode-- */
211//++
212int_4 Scan::NbTours() const
213
214// Retourne le nombre total de tours
215//--
216{
217 return(NmaxTrs_);
218}
219
220/* --Methode-- */
221//++
222int_4 Scan::NbPts1Tr() const
223
224// Retourne le nombre de points pour 1 tour
225//--
226{
227 return(NPts1Tr_);
228}
229
230/* --Methode-- */
231//++
232int_4 Scan::ValueIndex(float t) const
233
234// Retourne l'indice du pixel associé au temps t
235//--
236{
237 int_4 k;
238 float eps= 1.0E-06;
239
240 // verification si t est dans [TempsInitial_,TempsFinal_]
241 if( (t< TempsInitial_) || (t> TempsFinal_) ) {
242 printf("\n ValueIndex:: probleme sur le temps t= %f",t);
243 return(-1);
244 }
245
246 k= (int_4)((t-TempsInitial_)*FrequenceEch_+eps);
247 if ( (k< 0) || (k >= NmaxPts_) ) {
248 printf("\n ValueIndex:: probleme sur l'indice du point k= %d",k);
249 return(-1);
250 }
251 return(k);
252}
253
254/* --Methode-- */
255//++
256void Scan::Direction(float t, float& teta , float& phi)
257
258// Retourne les coordonnées (teta,phi) du pixel lié au temps t
259//--
260{
261 r_8 alfa,xs,ys,zs,x,y,z;
262
263 // coordonnees dans le systeme du satellite
264 alfa= OmegaRad_*(t-TempsInitial_)+PhiZero_;
265 xs = sin((double)Ouverture_)*cos(alfa);
266 ys = sin((double)Ouverture_)*sin(alfa);
267 zs = cos((double)Ouverture_);
268
269 // coordonnees dans le systeme fixe
270 x = Rota_[0]*xs+Rota_[1]*ys+Rota_[2]*zs;
271 y = Rota_[3]*xs+Rota_[4]*ys+Rota_[5]*zs;
272 z = Rota_[6]*xs+Rota_[7]*ys+Rota_[8]*zs;
273
274 // angles teta,phi
275 teta = acos(z);
276 phi = atan2(y,x);
277 if( phi< 0. ) phi= DeuxPi+phi;
278}
279
280/* --Methode-- */
281//++
282void Scan::DirectionIndex(int_4 k, float& teta, float& phi)
283
284// Retourne les coordonnées (teta,phi) du pixel d'indice k
285//--
286{
287 float t;
288
289 //recupere le temps associe a l'indice k du pixel
290 t= TempsInitial_+(float)k/FrequenceEch_;
291
292 // angles teta,phi
293 Direction(t, teta, phi);
294}
295
296static r_8 dummy_pixel = 0;
297/* --Methode-- */
298//++
299r_8& Scan::PixelValue(int_4 k) const
300
301// Retourne la valeur du contenu du pixel d'indice k
302//--
303{
304 if ( (k<0) || (k >= NmaxPts_) ) {
305 printf("\n ValueIndex::indice du pixel errone k= %d",k);
306 return(dummy_pixel);
307 }
308 return(sPix_[k]);
309}
310
311void Scan::Clear() {
312 if (sPix_) delete[] sPix_;
313}
314void Scan::InitNull() {
315 sPix_=NULL;
316 mInfo_=NULL;
317}
318
319
320//++
321// Titre Opérateurs
322//--
323//++
324// Links double& operator()(int_4 k)
325//--
326//++
327// Surcharge de la parenthese a un indice entier : remplit ou/et renvoie
328// la valeur du contenu du pixel d'indice k
329//--
330
331
332
333
334
Note: See TracBrowser for help on using the repository browser.