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

Last change on this file since 3509 was 2615, checked in by cmv, 21 years ago

using namespace sophya enleve de machdefs.h, nouveau sopnamsp.h cmv 10/09/2004

  • Property svn:executable set to *
File size: 9.3 KB
Line 
1#include "sopnamsp.h"
2#include "machdefs.h"
3#include <stdlib.h>
4#include <stdio.h>
5#include <math.h>
6
7#include "scan.h"
8#include <complex>
9#include "fiondblock.h"
10
11// valeurs de Pi, 2*Pi, etc
12#include "smathconst.h"
13
14
15//
16//++
17// Class Scan
18//
19// include scan.h dvlist.h math.h nbmath.h
20//
21// Storage and treatment of data for a scanning of a part of the sky
22// with a set of given values for parameters (see constructor)
23//--
24//++
25Scan::Scan(float Ouv,float* Omega,float Fech,float T,
26 float t0=0., float phi0=0.)
27
28//
29// * Ouv = aperture angle (rad)
30// * Omega[3] = direction of rotation axis of the satellite (teta,phi)
31// and rotation velocity (rad/s)
32// * Fech = sampling frequency (Hz)
33// * T = total time of data acquistion (s)
34// * t0 = starting time (s)
35// * phi0 = offset of antenna (rad)
36//--
37{
38 mInfo_=NULL;
39 // On memorise les arguments d'appel
40 Ouverture_= Ouv;
41 OmegaTeta_= Omega[0];
42 //
43 // je ne comprends pas ce qui se passe ci-apres (GLM)
44 if( (Omega[0]== 0.0) || (Omega[0]==(float)Pi) )
45 OmegaPhi_ = Omega[1];
46 else
47 OmegaPhi_ = Omega[1]+(float)Pi/2.;
48 OmegaRad_ = Omega[2];
49 FrequenceEch_ = Fech;
50 TempsFinal_ = T;
51 TempsInitial_ = t0;
52 PhiZero_ = phi0;
53
54 float aux= 0.0;
55 // Nombre total de points
56 aux= (TempsFinal_-TempsInitial_)*FrequenceEch_;
57 NmaxPts_= (int_4)(aux);
58
59 // Nombre total de tours
60 aux= OmegaRad_*(TempsFinal_-TempsInitial_)/(2.*Pi);
61 NmaxTrs_= (int_4)(aux);
62
63 // Nombre de points par tour
64 aux= 2.*Pi*FrequenceEch_/OmegaRad_;
65 NPts1Tr_= (int_4)(aux);
66
67 // Creation et initialisation du vecteur des mesures aux points
68 // sPix_ = new r_8[NmaxPts_];
69 sPix_.ReSize(NmaxPts_);
70 sPix_.Reset();
71 // for( int_4 i=0; i<NmaxPts_; i++ ) sPix_[i]= 0.;
72 for( int_4 i=0; i<NmaxPts_; i++ ) sPix_(i)= 0.;
73
74 // matrice de passage du systeme lie au satellite au systeme fixe
75
76 Rota_[0]= cos((double)OmegaPhi_);
77 Rota_[1]= -sin((double)OmegaPhi_)*cos((double)OmegaTeta_);
78 Rota_[2]= sin((double)OmegaPhi_)*sin((double)OmegaTeta_);
79 Rota_[3]= sin((double)OmegaPhi_);
80 Rota_[4]= cos((double)OmegaPhi_)*cos((double)OmegaTeta_);
81 Rota_[5]= -cos((double)OmegaPhi_)*sin((double)OmegaTeta_);
82 Rota_[6]= 0.0;
83 Rota_[7]= sin((double)OmegaTeta_);
84 Rota_[8]= cos((double)OmegaTeta_);
85
86
87 // printf("%f %f %f \n",Rota_[0],Rota_[1],Rota_[2]);
88 // printf("%f %f %f \n",Rota_[3],Rota_[4],Rota_[5]);
89 // printf("%f %f %f \n",Rota_[6],Rota_[7],Rota_[8]);
90
91}
92
93
94//++
95Scan::Scan(const Scan& s, bool share) : sPix_(s.sPix_ , share)
96
97// copy constructor
98//--
99{
100 NmaxPts_ = s.NmaxPts_;
101 Ouverture_ = s.Ouverture_;
102 OmegaTeta_ = s.OmegaTeta_;
103 OmegaPhi_ = s.OmegaPhi_;
104 OmegaRad_ = s.OmegaRad_;
105 FrequenceEch_ = s.FrequenceEch_;
106 TempsFinal_ = s.TempsFinal_;
107 TempsInitial_ = s.TempsInitial_;
108 PhiZero_ = s.PhiZero_;
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(); pas de reset (pour le cas de share)
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_4 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// On lit le DataBlock;
392 FIO_NDataBlock<r_8> fio_nd(&dobj->DataBlock());
393 fio_nd.Read(is);
394}
395//++
396void FIO_Scan::WriteSelf(POutPersist& os) const
397//
398//--
399{
400 r_4 Ouverture, OmegaTeta, OmegaPhi, OmegaRad, FrequenceEch;
401 r_4 TempsFinal, TempsInitial, PhiZero;
402 r_8 Rota[9];
403 char strg[256];
404
405 if(dobj == NULL)
406 {
407 cout << " FIO_Scan::WriteSelf:: dobj= null " << endl;
408 return;
409 }
410 dobj->GetFloatParams(Ouverture,OmegaTeta,OmegaPhi,OmegaRad,
411 FrequenceEch,TempsFinal,TempsInitial,PhiZero,Rota);
412 if (dobj->ptrInfo())
413 {sprintf(strg, "Scan: Theta=%9f Phi=%9f omega=%9f HasInfo",
414 (float)OmegaTeta, (float)OmegaPhi, (float)OmegaRad);
415 os.PutLine(strg);
416 os << dobj->Info();
417 }
418 else
419 {
420 sprintf(strg, "Scan: Theta=%9f Phi=%9f omega=%9f ",
421 (float)OmegaTeta, (float)OmegaPhi, (float)OmegaRad);
422 os.PutLine(strg);
423 }
424
425 os.PutI4(dobj->NbPoints());
426 os.PutI4(dobj->NbTours());
427 os.PutI4(dobj->NbPts1Tr());
428
429 os.PutR4(Ouverture);
430 os.PutR4(OmegaTeta);
431 os.PutR4(OmegaPhi);
432 os.PutR4(OmegaRad);
433 os.PutR4(FrequenceEch);
434 os.PutR4(TempsFinal);
435 os.PutR4(TempsInitial);
436 os.PutR4(PhiZero);
437 os.PutR8s(Rota, 9);
438
439// On ecrit le dataBlock
440 FIO_NDataBlock<r_8> fio_nd(&dobj->DataBlock());
441 fio_nd.Write(os);
442
443}
Note: See TracBrowser for help on using the repository browser.