1 | #include <stdio.h>
|
---|
2 | #include <stdlib.h>
|
---|
3 | #include <math.h>
|
---|
4 | #include <iostream>
|
---|
5 |
|
---|
6 | #include "sopnamsp.h"
|
---|
7 | #include "histinit.h"
|
---|
8 | #include "dvlist.h"
|
---|
9 | #include "ntuple.h"
|
---|
10 | #include "xntuple.h"
|
---|
11 | #include "datatable.h"
|
---|
12 | #include "swppfdtable.h"
|
---|
13 |
|
---|
14 | /* Programme test des classes DVList, NTuple,, XNTuple */
|
---|
15 | /* DataTable et les handlers PPF */
|
---|
16 | /* SOPHYA - R. Ansari (LAL) - 2000 - 2005 */
|
---|
17 |
|
---|
18 | void test_dvl();
|
---|
19 | void test_ntuple();
|
---|
20 | void test_xntuple() ;
|
---|
21 | void test_Xntuple() ;
|
---|
22 | void test_DataTable() ;
|
---|
23 | void test_SwPPFDataTable() ;
|
---|
24 |
|
---|
25 | int main(int narg, char *arg[])
|
---|
26 | {
|
---|
27 | SophyaInit();
|
---|
28 | if (narg < 2) {
|
---|
29 | cout << " tnt/Erreur arg - Usage: tnt d/n/x/X/DT/SWDT \n"
|
---|
30 | << " d:DVList n:NTuple x/X:XNTuple DT,SWDT: SwPPF/DataTable test \n" << endl;
|
---|
31 | exit(0);
|
---|
32 | }
|
---|
33 |
|
---|
34 | try {
|
---|
35 | if (*arg[1] == 'd') test_dvl();
|
---|
36 | else if (*arg[1] == 'n') test_ntuple();
|
---|
37 | else if (*arg[1] == 'x') test_xntuple();
|
---|
38 | else if (*arg[1] == 'X') test_Xntuple();
|
---|
39 | else if (strcmp(arg[1],"DT") == 0) test_DataTable();
|
---|
40 | else if (strcmp(arg[1],"SWDT") == 0) test_SwPPFDataTable();
|
---|
41 | }
|
---|
42 | catch(PThrowable exc ) {
|
---|
43 | cerr << "tnt-main() , Catched exception: \n" << exc.Msg() << endl;
|
---|
44 | }
|
---|
45 | catch(std::exception ex) {
|
---|
46 | cerr << "tnt-main() , Catched exception ! " << (string)(ex.what()) << endl;
|
---|
47 | }
|
---|
48 | catch(...) {
|
---|
49 | cerr << "tnt-main() , Catched ... ! " << endl;
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | /* ***** Test de NTuple simple ***** */
|
---|
54 | void test_ntuple()
|
---|
55 | {
|
---|
56 | char * names[3] = {"XPos", "YPos", "Val"};
|
---|
57 | int i,j, k;
|
---|
58 | float xnt[3];
|
---|
59 |
|
---|
60 | cout << "======= test_ntuple: Testing NTuple ======= " << endl;
|
---|
61 |
|
---|
62 | cout << "Creation Ntuple avec X,Y,Val ... " << endl;
|
---|
63 | NTuple nt1(3, names, 20);
|
---|
64 |
|
---|
65 | k = 0;
|
---|
66 | for(j=0; j<8; j++)
|
---|
67 | for(i=0; i<12; i++)
|
---|
68 | { xnt[0] = i+0.5; xnt[1] = j+0.5; xnt[2] = k;
|
---|
69 | nt1.Fill(xnt); k++; }
|
---|
70 |
|
---|
71 | nt1.Info().Comment() = "NTuple de Test - Cree par tnt.cc";
|
---|
72 | nt1.Info()["Version"] = SophyaVersion();
|
---|
73 | nt1.Show(cout);
|
---|
74 | nt1.Print(0, 5);
|
---|
75 | nt1.Print(18, 5);
|
---|
76 | nt1.Print(94, 5);
|
---|
77 |
|
---|
78 | string fn = "nt.ppf";
|
---|
79 | {
|
---|
80 | cout << "Ecriture NTuple ds nt.ppf ... \n" << endl;
|
---|
81 | ObjFileIO<NTuple> fio(&nt1);
|
---|
82 | fio.Write(fn);
|
---|
83 | }
|
---|
84 |
|
---|
85 | {
|
---|
86 | cout << "Lecture NTuple (nt2) ds nt.ppf ... \n" << endl;
|
---|
87 | PInPersist fsi(fn);
|
---|
88 | NTuple nt2;
|
---|
89 | fsi >> nt2;
|
---|
90 | nt2.Show(cout);
|
---|
91 | nt2.Print(0, 5);
|
---|
92 | nt2.Print(18, 5);
|
---|
93 | nt2.Print(94, 5);
|
---|
94 | }
|
---|
95 |
|
---|
96 |
|
---|
97 | }
|
---|
98 |
|
---|
99 | /* ***** Test de dvlist ***** */
|
---|
100 | void test_dvl()
|
---|
101 | {
|
---|
102 | DVList dvl;
|
---|
103 |
|
---|
104 | cout << "\n ======= test_dvl: Testing MuTyV ======= " << endl;
|
---|
105 | MuTyV zvs = " ( 1.41 -2.71) ";
|
---|
106 | MuTyV dvs = "434.898";
|
---|
107 | MuTyV fvu = 314.1596;
|
---|
108 | MuTyV ivu = 7654321;
|
---|
109 | cout << " float->string: fvu= " << fvu << " (string)fvu=" << (string)fvu << endl;
|
---|
110 | cout << " int->string: ivu= " << ivu << " (string)ivu=" << (string)ivu << endl;
|
---|
111 | complex<double> zzd = zvs;
|
---|
112 | cout << "String->complex<double>: zvs = " << zvs
|
---|
113 | << " (complex<double>)zvs= " << zzd << endl;
|
---|
114 | cout << "String->double: dvs = " << dvs
|
---|
115 | << " (double)dvs= " << (double)dvs << endl;
|
---|
116 | TimeStamp ts;
|
---|
117 | MuTyV tv = ts;
|
---|
118 | cout << "MuTyV=TimeStamp->String: tv = " << tv
|
---|
119 | << " ->double= " << (double)tv << " ->TimeStamp:"
|
---|
120 | << TimeStamp((double)tv).ToString() << endl;
|
---|
121 |
|
---|
122 |
|
---|
123 | cout << "\n\n ======= test_dvl: Testing DVList ======= " << endl;
|
---|
124 | dvl.SetI("Var XXX", 12345);
|
---|
125 | dvl.SetI("IV1-80", 80);
|
---|
126 | dvl.SetI("IV2-330", 330);
|
---|
127 |
|
---|
128 | dvl.SetD("DV1-0.2", 0.2);
|
---|
129 | dvl.SetD("DV2-4.5", 4.5);
|
---|
130 | dvl.SetZ("ZV", complex<r_8>(2.0,-1.44));
|
---|
131 |
|
---|
132 | dvl.SetI("IVV3-783", 783);
|
---|
133 | dvl("IVV3-783-O") = 7783;
|
---|
134 | // dvl["Avec[]"] = "operateur [] !";
|
---|
135 | dvl.SetD("DVV3", 3.141592652141592652);
|
---|
136 | dvl.SetComment("DVV3", "Comment for DVV3, r_8 type variable");
|
---|
137 | dvl("DVV3avec()") = 44.555e-8;
|
---|
138 |
|
---|
139 | dvl.SetS("Blanc_White", "123.456Ma premiere chaine");
|
---|
140 | dvl.SetI("IntegerValue", 55777);
|
---|
141 | dvl.SetComment("IntegerValue", "This variable has a comment");
|
---|
142 | dvl.Comment() = "This is a test DVL produced by the program tdvl.cc \n Using SOPHYA , Feb 2000";
|
---|
143 |
|
---|
144 | dvl["Sinf"] = "inf 0985";
|
---|
145 | dvl["ToDay"] = ts;
|
---|
146 | dvl.Print();
|
---|
147 |
|
---|
148 |
|
---|
149 | double d = dvl("DV2-4.5");
|
---|
150 | float f = dvl("DVV3");
|
---|
151 | int i = dvl("IVV3-783");
|
---|
152 | complex<r_8> z = dvl("ZV");
|
---|
153 |
|
---|
154 | printf("\n \n Essai1 (IVV3 DVV3 DV2= ) %d %.20g %g \n", i, f, (float)d);
|
---|
155 | printf("\n \n Essai ZV= (%.2g %g I) \n", z.real(), z.imag());
|
---|
156 | cout << "Test Comment/IntegerValue: " << dvl.GetComment("IntegerValue") << endl;
|
---|
157 | cout << "Test Comment/DVV3: " << dvl.GetComment("DVV3") << endl;
|
---|
158 |
|
---|
159 | cout << "Test string recup " << (string)(dvl["Blanc_White"]) << endl;
|
---|
160 | cout << "Test string recup(int=80) " << (string)(dvl["IV1-80"]) << endl;
|
---|
161 | dvl("DVV3") = (double)3.141592652141592652;
|
---|
162 | cout << "Test string recup(double=Pi..i) " << (string)(dvl["DVV3"]) << endl;
|
---|
163 |
|
---|
164 | {
|
---|
165 | cout << " Writing DVList in file PPF dvl.ppf " << endl;
|
---|
166 | POutPersist os("dvl.ppf");
|
---|
167 | os << dvl ;
|
---|
168 | }
|
---|
169 |
|
---|
170 | cout << "-------------------------- \n\n"
|
---|
171 | << " reading DVList from file dvl.ppf ... \n" << endl;
|
---|
172 |
|
---|
173 | DVList dvlr("dvl.ppf");
|
---|
174 | double df1 = (double)( dvlr["DVV3"] );
|
---|
175 | double df2 = (double)3.141592652141592652 - df1;
|
---|
176 | cout << " Test Precision : Pi-Pi= " << df2 << "DVV3= " << df1 << endl;
|
---|
177 |
|
---|
178 | cout << dvlr;
|
---|
179 |
|
---|
180 | }
|
---|
181 | void test_DataTable()
|
---|
182 | {
|
---|
183 | cout << "======= test_DataTable: simple DataTable test ======= " << endl;
|
---|
184 | DataTable dt(64);
|
---|
185 | dt.AddIntegerColumn("line");
|
---|
186 | dt.AddStringColumn("sline");
|
---|
187 | dt.AddDoubleColumn("x");
|
---|
188 | dt.AddFloatColumn("f_sin");
|
---|
189 | dt.AddFloatColumn("f_cos");
|
---|
190 | dt.AddDoubleColumn("f_sinxcos");
|
---|
191 | dt.AddDoubleColumn("f_x2");
|
---|
192 | dt.AddComplexColumn("cmplx_cos_sin");
|
---|
193 | dt.AddDoubleComplexColumn("dcmplx_cos_sin");
|
---|
194 | MuTyV rec[10];
|
---|
195 | cout << " 1/ First 1000 lines .... " << endl;
|
---|
196 | for(int k = 0; k<1000; k++) {
|
---|
197 | rec[0] = k;
|
---|
198 | string sline = "L-";
|
---|
199 | sline += (string)rec[0];
|
---|
200 | rec[1] = sline;
|
---|
201 | double x = M_PI*k/100.;
|
---|
202 | double fx = sin(x)*cos(x);
|
---|
203 | double sx = sin(x);
|
---|
204 | double cx = cos(x);
|
---|
205 | rec[2] = x;
|
---|
206 | rec[3] = sx;
|
---|
207 | rec[4] = cx;
|
---|
208 | rec[5] = fx;
|
---|
209 | rec[6] = x*x;
|
---|
210 | rec[7] = complex<r_4>(cx, sx);
|
---|
211 | rec[8] = complex<r_8>(cx, sx);
|
---|
212 | dt.AddLine(rec);
|
---|
213 | }
|
---|
214 | cout << "1.b/ Use of = operator to make copy of dt " << endl;
|
---|
215 | DataTable dtc1;
|
---|
216 | dtc1 = dt;
|
---|
217 |
|
---|
218 | dt.Show();
|
---|
219 | cout << " 2/ Lines 1000-2000 .... " << endl;
|
---|
220 | for(int k = 1000; k<2000; k++) {
|
---|
221 | rec[0] = k;
|
---|
222 | string sline = "L-";
|
---|
223 | sline += (string)rec[0];
|
---|
224 | rec[1] = sline;
|
---|
225 | double x = M_PI*k/100.;
|
---|
226 | double fx = sin(x)*cos(x);
|
---|
227 | double sx = sin(x);
|
---|
228 | double cx = cos(x);
|
---|
229 | rec[2] = x;
|
---|
230 | rec[3] = sx;
|
---|
231 | rec[4] = cx;
|
---|
232 | rec[5] = fx;
|
---|
233 | rec[6] = x*x;
|
---|
234 | rec[7] = complex<r_4>(cx, sx);
|
---|
235 | rec[8] = complex<r_8>(cx, sx);
|
---|
236 | dt.AddLine(rec);
|
---|
237 | }
|
---|
238 | cout << "2.b/ dt.Show(); : " << endl;
|
---|
239 | dt.Show();
|
---|
240 | cout << "2.c/ dtc1.Show(); : " << endl;
|
---|
241 | dtc1.Show();
|
---|
242 | cout << "2.d/ dt.LineHeaderToString() dt.LineToString(k) : " << endl;
|
---|
243 | cout << dt.LineHeaderToString() ;
|
---|
244 | for(int k = 0; k<1500; k+=75)
|
---|
245 | cout << "Line[" << k << "] " << dt.LineToString(k) << endl ;
|
---|
246 | {
|
---|
247 | cout << "3/ Writing DataTable dt to PPF stream dtable.ppf " << endl;
|
---|
248 | POutPersist po("dtable.ppf");
|
---|
249 | po << dt;
|
---|
250 | }
|
---|
251 | {
|
---|
252 | cout << "4/ Reading DataTable dtr from PPF stream dtable.ppf " << endl;
|
---|
253 | PInPersist pi("dtable.ppf");
|
---|
254 | DataTable dtr;
|
---|
255 | pi >> dtr;
|
---|
256 | cout << "4.b/ cout << dtr; " << endl;
|
---|
257 | cout << dtr;
|
---|
258 | cout << "4.c/ dtr.LineHeaderToString() dtr.LineToString(k) : " << endl;
|
---|
259 | cout << dtr.LineHeaderToString() ;
|
---|
260 | for(int k = 0; k<1500; k+=75)
|
---|
261 | cout << "Line[" << k << "] " << dtr.LineToString(k) << endl ;
|
---|
262 |
|
---|
263 | }
|
---|
264 |
|
---|
265 | cout << "============ FIN test_DataTable ============== " << endl;
|
---|
266 | }
|
---|
267 |
|
---|
268 | void test_SwPPFDataTable()
|
---|
269 | {
|
---|
270 | cout << "======= test_SwPPFDataTable(): simple SwPPFDataTable test ======= " << endl;
|
---|
271 | {
|
---|
272 | POutPersist po("swdtable.ppf");
|
---|
273 | SwPPFDataTable dt(po, 64);
|
---|
274 | dt.AddIntegerColumn("line");
|
---|
275 | dt.AddDoubleColumn("x");
|
---|
276 | dt.AddFloatColumn("f_sin");
|
---|
277 | dt.AddFloatColumn("f_cos");
|
---|
278 | dt.AddDoubleColumn("f_sinxcos");
|
---|
279 | dt.AddDoubleColumn("f_x2");
|
---|
280 | dt.AddComplexColumn("cmplx_cos_sin");
|
---|
281 | dt.AddDoubleComplexColumn("dcmplx_cos_sin");
|
---|
282 | MuTyV rec[10];
|
---|
283 | cout << " 1/ First 1000 lines .... " << endl;
|
---|
284 | for(int k = 0; k<1000; k++) {
|
---|
285 | rec[0] = k;
|
---|
286 | double x = M_PI*k/100.;
|
---|
287 | double fx = sin(x)*cos(x);
|
---|
288 | double sx = sin(x);
|
---|
289 | double cx = cos(x);
|
---|
290 | rec[1] = x;
|
---|
291 | rec[2] = sx;
|
---|
292 | rec[3] = cx;
|
---|
293 | rec[4] = fx;
|
---|
294 | rec[5] = x*x;
|
---|
295 | rec[6] = complex<r_4>(cx, sx);
|
---|
296 | rec[7] = complex<r_8>(cx, sx);
|
---|
297 | dt.AddLine(rec);
|
---|
298 | }
|
---|
299 | cout << "1.b/ Use of = operator to make copy of dt " << endl;
|
---|
300 | SwPPFDataTable dtc1;
|
---|
301 | dtc1 = dt;
|
---|
302 | dt.Show();
|
---|
303 | cout << " 2/ Lines 1000-2000 .... " << endl;
|
---|
304 | for(int k = 1000; k<2000; k++) {
|
---|
305 | rec[0] = k;
|
---|
306 | double x = M_PI*k/100.;
|
---|
307 | double fx = sin(x)*cos(x);
|
---|
308 | rec[1] = x;
|
---|
309 | rec[2] = sin(x);
|
---|
310 | rec[3] = cos(x);
|
---|
311 | rec[4] = fx;
|
---|
312 | rec[5] = x*x;
|
---|
313 | dt.AddLine(rec);
|
---|
314 | }
|
---|
315 | cout << "2.b/ dt.Show(); : " << endl;
|
---|
316 | dt.Show();
|
---|
317 | cout << "2.c/ dtc1.Show(); : " << endl;
|
---|
318 | dtc1.Show();
|
---|
319 | cout << "3/ Writing SwPPFDataTable dt to PPF stream swdtable.ppf " << endl;
|
---|
320 | po << dt;
|
---|
321 | }
|
---|
322 | {
|
---|
323 | cout << "4/ Reading SwPPFDataTable dtr from PPF stream swdtable.ppf " << endl;
|
---|
324 | PInPersist pi("swdtable.ppf");
|
---|
325 | SwPPFDataTable dtr;
|
---|
326 | pi >> dtr;
|
---|
327 | cout << "4.b/ cout << dtr; " << endl;
|
---|
328 | cout << dtr;
|
---|
329 | cout << "4.c/ dtr.LineHeaderToString() dtr.LineToString(k) : " << endl;
|
---|
330 | cout << dtr.LineHeaderToString() ;
|
---|
331 | for(int k = 0; k<1500; k+=75)
|
---|
332 | cout << "Line[" << k << "] " << dtr.LineToString(k) << endl ;
|
---|
333 | }
|
---|
334 |
|
---|
335 | cout << "============ FIN test_SwPPFDataTable() ======== ======= " << endl;
|
---|
336 | }
|
---|
337 |
|
---|
338 |
|
---|
339 |
|
---|
340 |
|
---|
341 | void test_Xntuple()
|
---|
342 | {
|
---|
343 | char* names[] = {"str1", "str2", "str3", "str4", "str5"} ;
|
---|
344 | XNTuple nt(0, 0, 0, 5, names) ;
|
---|
345 | char** ce = new char*[5] ;
|
---|
346 | int i;
|
---|
347 | for(i = 0 ; i < 5 ; i++)
|
---|
348 | ce[i] = new char[20] ;
|
---|
349 |
|
---|
350 | cout << "======= test_Xtuple: simple XNTuple test ======= " << endl;
|
---|
351 |
|
---|
352 | strncpy(ce[1], "toto a une auto", 20) ;
|
---|
353 | strncpy(ce[2], "titi a une iti", 20) ;
|
---|
354 | strncpy(ce[3], "tutu a une utu", 20) ;
|
---|
355 | strncpy(ce[4], "tata a une ata", 20) ;
|
---|
356 | for(i = 0 ; i < 100000 ; i++) {
|
---|
357 | sprintf(ce[0], "%d", i) ;
|
---|
358 | nt.Fill(NULL, NULL, NULL, ce) ;
|
---|
359 | }
|
---|
360 |
|
---|
361 | nt.Show() ;
|
---|
362 | cout << nt.LineHeaderToString() ;
|
---|
363 | cout << nt.LineToString(5027) << endl ;
|
---|
364 |
|
---|
365 | char* names2[] = {"d0", "d1", "f0", "f1", "f2", "i0", "str0", "str1"} ;
|
---|
366 | XNTuple nt2(2, 3, 1, 2, names2) ;
|
---|
367 | double de[2] ; float fe[3] ; int ie ;
|
---|
368 | char** ce2 = new char*[2] ;
|
---|
369 | for(i = 0 ; i < 2 ; i++) ce2[i] = new char[20] ;
|
---|
370 | strncpy(ce2[1], "glop glop", 20) ;
|
---|
371 |
|
---|
372 | for(i = 0 ; i < 100000 ; i++) {
|
---|
373 | de[0] = i ;
|
---|
374 | de[1] = sin((double)i) ;
|
---|
375 | fe[0] = i ;
|
---|
376 | fe[1] = i * cos((double)i) ;
|
---|
377 | fe[2] = 2*i ;
|
---|
378 | ie = -i;
|
---|
379 | sprintf(ce[0], "%d", i) ;
|
---|
380 | nt2.Fill(de, fe, &ie, ce) ;
|
---|
381 | }
|
---|
382 | nt2.Show() ;
|
---|
383 | nt2.LineHeaderToString() ;
|
---|
384 | // nt2.LineToString(20) ;
|
---|
385 | }
|
---|
386 |
|
---|
387 |
|
---|
388 | void test_xntuple()
|
---|
389 | {
|
---|
390 | char* names[] = {"dblval", "floval", "intval", "strval"} ;
|
---|
391 | XNTuple nt(1, 1, 1, 1, names) ;
|
---|
392 | double de ;
|
---|
393 | float fe ;
|
---|
394 | int ie ;
|
---|
395 | char* ce = new char[22] ;
|
---|
396 |
|
---|
397 |
|
---|
398 | cout << "======= test_Xtuple: XNTuple test ======= " << endl;
|
---|
399 | int i;
|
---|
400 | for(i = 0 ; i < nt.NVar() ; i++)
|
---|
401 | printf(" +++ %s <--> %d \n",
|
---|
402 | nt.NomIndex(i).c_str(), nt.IndexNom(nt.NomIndex(i).c_str())) ;
|
---|
403 |
|
---|
404 | for(i = 0 ; i < 100000 ; i++) {
|
---|
405 | de = fe = ie = i ;
|
---|
406 | sprintf(ce, "%d", i) ;
|
---|
407 | nt.Fill(&de, &fe, &ie, &ce) ;
|
---|
408 | }
|
---|
409 | nt.Show() ;
|
---|
410 | cout << nt.VarList_C("toto") ;
|
---|
411 | cout << nt.LineHeaderToString() ;
|
---|
412 | cout << nt.LineToString(20) << endl << endl ;
|
---|
413 |
|
---|
414 |
|
---|
415 | XNTuple nt2 ;
|
---|
416 | nt2.SwapPath() = "/tmp/sop/" ;
|
---|
417 | nt2.Copy(nt) ;
|
---|
418 | nt2.Show() ;
|
---|
419 | for(i = 0 ; i < 100000 ; i++) {
|
---|
420 | de = fe = ie = i ;
|
---|
421 | sprintf(ce, "%d", i) ;
|
---|
422 | nt2.Fill(&de, &fe, &ie, &ce) ;
|
---|
423 | }
|
---|
424 | nt2.Show() ;
|
---|
425 |
|
---|
426 | {
|
---|
427 | POutPersist os("xnt.ppf");
|
---|
428 | os << nt2 ;
|
---|
429 | }
|
---|
430 |
|
---|
431 | XNTuple::SetSwapPath("/tmp/sop/") ;
|
---|
432 | XNTuple nt3("xnt.ppf") ;
|
---|
433 | nt3.Show() ;
|
---|
434 |
|
---|
435 | for(i = 0 ; i < nt3.NEntry() ; i+= 1000)
|
---|
436 | printf("%f %f %d %s\n",
|
---|
437 | nt3.GetDVal(i,0),
|
---|
438 | nt3.GetFVal(i,1),
|
---|
439 | nt3.GetIVal(i,2),
|
---|
440 | nt3.GetSVal(i,3).c_str()) ;
|
---|
441 |
|
---|
442 | double min, max ;
|
---|
443 | for(i = 0 ; i < nt3.NVar() ; i++) {
|
---|
444 | nt3.GetMinMax(i, min, max) ;
|
---|
445 | printf("GetMinMax(%s) : %f/%f\n",
|
---|
446 | nt3.NomIndex(i).c_str(), min, max) ;
|
---|
447 | }
|
---|
448 | // nt3.Show() ;
|
---|
449 | }
|
---|
450 |
|
---|