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

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

ajout doc GLM

  • Property svn:executable set to *
File size: 9.2 KB
Line 
1#include "machdefs.h"
2#include <stdlib.h>
3#include <stdio.h>
4#include <math.h>
5
6#include "scan.h"
7#include <complex>
8#include "piocmplx.h"
9
10// valeurs de Pi, 2*Pi, etc
11#include "nbmath.h"
12
13
14//
15//++
16// Class Scan
17//
18// include scan.h dvlist.h math.h nbmath.h
19//
20// Storage and treatment of data for a scanning of a part of the sky
21// with a set of given values for parameters (see constructor)
22//--
23//++
24Scan::Scan(float Ouv,float* Omega,float Fech,float T,
25 float t0=0., float phi0=0.)
26
27//
28// * Ouv = aperture angle (rad)
29// * Omega[3] = direction of rotation axis of the satellite (teta,phi)
30// and rotation velocity (rad/s)
31// * Fech = sampling frequency (Hz)
32// * T = total time of data acquistion (s)
33// * t0 = starting time (s)
34// * phi0 = offset of antenna (rad)
35//--
36{
37 mInfo_=NULL;
38 // On memorise les arguments d'appel
39 Ouverture_= Ouv;
40 OmegaTeta_= Omega[0];
41 //
42 // je ne comprends pas ce qui se passe ci-apres (GLM)
43 if( (Omega[0]== 0.0) || (Omega[0]==(float)Pi) )
44 OmegaPhi_ = Omega[1];
45 else
46 OmegaPhi_ = Omega[1]+(float)Pi/2.;
47 OmegaRad_ = Omega[2];
48 FrequenceEch_ = Fech;
49 TempsFinal_ = T;
50 TempsInitial_ = t0;
51 PhiZero_ = phi0;
52
53 float aux= 0.0;
54 // Nombre total de points
55 aux= (TempsFinal_-TempsInitial_)*FrequenceEch_;
56 NmaxPts_= (int_4)(aux);
57
58 // Nombre total de tours
59 aux= OmegaRad_*(TempsFinal_-TempsInitial_)/(2.*Pi);
60 NmaxTrs_= (int_4)(aux);
61
62 // Nombre de points par tour
63 aux= 2.*Pi*FrequenceEch_/OmegaRad_;
64 NPts1Tr_= (int_4)(aux);
65
66 // Creation et initialisation du vecteur des mesures aux points
67 // sPix_ = new r_8[NmaxPts_];
68 sPix_.ReSize(NmaxPts_);
69 sPix_.Reset();
70 // for( int_4 i=0; i<NmaxPts_; i++ ) sPix_[i]= 0.;
71 for( int_4 i=0; i<NmaxPts_; i++ ) sPix_(i)= 0.;
72
73 // matrice de passage du systeme lie au satellite au systeme fixe
74
75 Rota_[0]= cos((double)OmegaPhi_);
76 Rota_[1]= -sin((double)OmegaPhi_)*cos((double)OmegaTeta_);
77 Rota_[2]= sin((double)OmegaPhi_)*sin((double)OmegaTeta_);
78 Rota_[3]= sin((double)OmegaPhi_);
79 Rota_[4]= cos((double)OmegaPhi_)*cos((double)OmegaTeta_);
80 Rota_[5]= -cos((double)OmegaPhi_)*sin((double)OmegaTeta_);
81 Rota_[6]= 0.0;
82 Rota_[7]= sin((double)OmegaTeta_);
83 Rota_[8]= cos((double)OmegaTeta_);
84
85
86 // printf("%f %f %f \n",Rota_[0],Rota_[1],Rota_[2]);
87 // printf("%f %f %f \n",Rota_[3],Rota_[4],Rota_[5]);
88 // printf("%f %f %f \n",Rota_[6],Rota_[7],Rota_[8]);
89
90}
91
92
93//++
94Scan::Scan(const Scan& s)
95
96// copy constructor
97//--
98{
99 NmaxPts_ = s.NmaxPts_;
100 Ouverture_ = s.Ouverture_;
101 OmegaTeta_ = s.OmegaTeta_;
102 OmegaPhi_ = s.OmegaPhi_;
103 OmegaRad_ = s.OmegaRad_;
104 FrequenceEch_ = s.FrequenceEch_;
105 TempsFinal_ = s.TempsFinal_;
106 TempsInitial_ = s.TempsInitial_;
107 PhiZero_ = s.PhiZero_;
108 sPix_=s.sPix_;
109 for (int k=0; k<9; k++) Rota_[k]=s. Rota_[k];
110}
111//++
112// Titre Destructor
113//--
114//++
115Scan::~Scan()
116
117//
118//--
119{
120 // delete[] sPix_ ;
121}
122
123
124//++
125// Titre Public Methods
126//--
127
128//++
129int_4 Scan::NbPoints() const
130
131// Return the number of points in the scan
132//--
133{
134 return(NmaxPts_);
135}
136
137/* --Methode-- */
138//++
139int_4 Scan::NbTours() const
140
141// Return total nomber of turns
142//--
143{
144 return(NmaxTrs_);
145}
146
147/* --Methode-- */
148//++
149int_4 Scan::NbPts1Tr() const
150
151// Return nomber of points for 1 turn
152//--
153{
154 return(NPts1Tr_);
155}
156
157/* --Methode-- */
158//++
159int_4 Scan::ValueIndex(float t) const
160
161// Return index of pixel associated to time t
162//--
163{
164 int_4 k;
165 float eps= 1.0E-06;
166
167 // verification si t est dans [TempsInitial_,TempsFinal_]
168 if( (t< TempsInitial_) || (t> TempsFinal_) ) {
169 printf("\n ValueIndex:: probleme sur le temps t= %f",t);
170 return(-1);
171 }
172
173 k= (int_4)((t-TempsInitial_)*FrequenceEch_+eps);
174 if ( (k< 0) || (k >= NmaxPts_) ) {
175 printf("\n ValueIndex:: probleme sur l'indice du point k= %d",k);
176 return(-1);
177 }
178 return(k);
179}
180
181/* --Methode-- */
182//++
183void Scan::Direction(float t, float& teta , float& phi)
184
185// Return (teta,phi) coordinate of pixel related to time t
186//--
187{
188 r_8 alfa,xs,ys,zs,x,y,z;
189
190 // coordonnees dans le systeme du satellite
191 alfa= OmegaRad_*(t-TempsInitial_)+PhiZero_;
192 xs = sin((double)Ouverture_)*cos(alfa);
193 ys = sin((double)Ouverture_)*sin(alfa);
194 zs = cos((double)Ouverture_);
195
196 // coordonnees dans le systeme fixe
197 x = Rota_[0]*xs+Rota_[1]*ys+Rota_[2]*zs;
198 y = Rota_[3]*xs+Rota_[4]*ys+Rota_[5]*zs;
199 z = Rota_[6]*xs+Rota_[7]*ys+Rota_[8]*zs;
200
201 // angles teta,phi
202 teta = acos(z);
203 phi = atan2(y,x);
204 if( phi< 0. ) phi= DeuxPi+phi;
205}
206
207/* --Methode-- */
208//++
209void Scan::DirectionIndex(int_4 k, float& teta, float& phi)
210
211// Return (teta,phi) coordinates of pixel with index k
212//--
213{
214 float t;
215
216 //recupere le temps associe a l'indice k du pixel
217 t= TempsInitial_+(float)k/FrequenceEch_;
218
219 // angles teta,phi
220 Direction(t, teta, phi);
221}
222
223static r_8 dummy_pixel = 0;
224/* --Methode-- */
225//++
226r_8 const& Scan::PixelValue(int_4 k) const
227
228// Retourne la valeur du contenu du pixel d'indice k
229//--
230{
231 if ( (k<0) || (k >= NmaxPts_) ) {
232 printf("\n ValueIndex::indice du pixel errone k= %d",k);
233 return(dummy_pixel);
234 }
235 // return(sPix_[k]);
236 //return(sPix_(k));
237 return *(sPix_.Data()+k);
238}
239//++
240r_8 & Scan::PixelValue(int_4 k)
241
242// Retourne la valeur du contenu du pixel d'indice k
243//--
244{
245 if ( (k<0) || (k >= NmaxPts_) ) {
246 printf("\n ValueIndex::indice du pixel errone k= %d",k);
247 return(dummy_pixel);
248 }
249 // return(sPix_[k]);
250 //return(sPix_(k));
251 return *(sPix_.Data()+k);
252}
253
254//void Scan::Clear() {
255// if (sPix_) delete[] sPix_;
256//}
257void Scan::InitNull() {
258 // sPix_=NULL;
259 sPix_.Reset();
260 mInfo_=NULL;
261}
262Scan& Scan::operator = (const Scan& s)
263{
264 NmaxPts_ = s.NmaxPts_;
265 Ouverture_ = s.Ouverture_;
266 OmegaTeta_ = s.OmegaTeta_;
267 OmegaPhi_ = s.OmegaPhi_;
268 OmegaRad_ = s.OmegaRad_;
269 FrequenceEch_ = s.FrequenceEch_;
270 TempsFinal_ = s.TempsFinal_;
271 TempsInitial_ = s.TempsInitial_;
272 PhiZero_ = s.PhiZero_;
273 sPix_=s.sPix_;
274 for (int k=0; k<9; k++) Rota_[k]=s. Rota_[k];
275 return *this;
276}
277
278
279//++
280// Titre Operators
281//--
282//++
283// Links double& operator()(int_4 k)
284//--
285//++
286// fill and/or return value of the pixel with index k
287//--
288
289
290
291
292
293//++
294// Titre class FIO_Scan
295// Delegated objects for persitance management
296//--
297
298//*******************************************************************
299// class FIO_Scan
300// Les objets delegues pour la gestion de persistance
301//*******************************************************************
302
303//++
304FIO_Scan::FIO_Scan()
305//
306//--
307{
308 dobj= new Scan;
309 ownobj= true;
310}
311//++
312FIO_Scan::FIO_Scan(string const& filename)
313//
314//--
315{
316 dobj= new Scan;
317 ownobj= true;
318 Read(filename);
319}
320//++
321FIO_Scan::FIO_Scan(const Scan& obj)
322//
323//--
324{
325 dobj= new Scan(obj);
326 ownobj= true;
327}
328FIO_Scan::FIO_Scan(Scan* obj)
329{
330 dobj= obj;
331 ownobj= false;
332}
333//++
334FIO_Scan::~FIO_Scan()
335//
336//--
337{
338 if (ownobj && dobj) delete dobj;
339}
340//++
341AnyDataObj* FIO_Scan::DataObj()
342//
343//--
344{
345 return(dobj);
346}
347
348//++
349void FIO_Scan::ReadSelf(PInPersist& is)
350//
351//--
352{
353
354 int NmaxPts, NmaxTrs, NPts1Tr;
355 r_4 Ouverture, OmegaTeta, OmegaPhi, OmegaRad, FrequenceEch;
356 r_4 TempsFinal, TempsInitial, PhiZero;
357 r_8 Rota[9];
358
359 if(dobj == NULL)
360 {
361 dobj= new Scan;
362 }
363
364 // Pour savoir s'il y avait un DVList Info associe
365 char strg[256];
366 is.GetLine(strg, 255);
367 bool hadinfo= false;
368 if (strncmp(strg+strlen(strg)-7, "HasInfo", 7) == 0) hadinfo = true;
369 if(hadinfo)
370 { // Lecture eventuelle du DVList Info
371 is >> dobj->Info();
372 }
373
374
375 is.GetI4(NmaxPts);
376 is.GetI4(NmaxTrs);
377 is.GetI4(NPts1Tr);
378 dobj->SetIntParams(NmaxPts,NmaxTrs,NPts1Tr);
379
380 is.GetR4(Ouverture);
381 is.GetR4(OmegaTeta);
382 is.GetR4(OmegaPhi);
383 is.GetR4(OmegaRad);
384 is.GetR4(FrequenceEch);
385 is.GetR4(TempsFinal);
386 is.GetR4(TempsInitial);
387 is.GetR4(PhiZero);
388 is.GetR8s(Rota, 9);
389 dobj->SetFloatParams(Ouverture,OmegaTeta,OmegaPhi,OmegaRad,
390 FrequenceEch,TempsFinal,TempsInitial,PhiZero,Rota);
391 r_8* sPix=new r_8[NmaxPts];
392 PIOSReadArray(is, sPix, NmaxPts);
393 dobj->setDataBlock(sPix, NmaxPts);
394 delete [] sPix;
395}
396//++
397void FIO_Scan::WriteSelf(POutPersist& os) const
398//
399//--
400{
401 r_4 Ouverture, OmegaTeta, OmegaPhi, OmegaRad, FrequenceEch;
402 r_4 TempsFinal, TempsInitial, PhiZero;
403 r_8 Rota[9];
404 char strg[256];
405
406 if(dobj == NULL)
407 {
408 cout << " FIO_Scan::WriteSelf:: dobj= null " << endl;
409 return;
410 }
411 dobj->GetFloatParams(Ouverture,OmegaTeta,OmegaPhi,OmegaRad,
412 FrequenceEch,TempsFinal,TempsInitial,PhiZero,Rota);
413 if (dobj->ptrInfo())
414 {sprintf(strg, "Scan: Theta=%9f Phi=%9f omega=%9f HasInfo",
415 (float)OmegaTeta, (float)OmegaPhi, (float)OmegaRad);
416 os.PutLine(strg);
417 os << dobj->Info();
418 }
419 else
420 {
421 sprintf(strg, "Scan: Theta=%9f Phi=%9f omega=%9f ",
422 (float)OmegaTeta, (float)OmegaPhi, (float)OmegaRad);
423 os.PutLine(strg);
424 }
425
426 os.PutI4(dobj->NbPoints());
427 os.PutI4(dobj->NbTours());
428 os.PutI4(dobj->NbPts1Tr());
429
430 os.PutR4(Ouverture);
431 os.PutR4(OmegaTeta);
432 os.PutR4(OmegaPhi);
433 os.PutR4(OmegaRad);
434 os.PutR4(FrequenceEch);
435 os.PutR4(TempsFinal);
436 os.PutR4(TempsInitial);
437 os.PutR4(PhiZero);
438 os.PutR8s(Rota, 9);
439
440 PIOSWriteArray(os,(dobj->getDataBlock())->Data(), dobj->NbPoints());
441
442}
Note: See TracBrowser for help on using the repository browser.