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

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

mise a jour de persistances par objets delegues

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