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)zvs= " << (double)dvs << endl;
|
---|
116 |
|
---|
117 |
|
---|
118 | cout << "\n\n ======= test_dvl: Testing DVList ======= " << endl;
|
---|
119 | dvl.SetI("Var XXX", 12345);
|
---|
120 | dvl.SetI("IV1-80", 80);
|
---|
121 | dvl.SetI("IV2-330", 330);
|
---|
122 |
|
---|
123 | dvl.SetD("DV1-0.2", 0.2);
|
---|
124 | dvl.SetD("DV2-4.5", 4.5);
|
---|
125 | dvl.SetZ("ZV", complex<r_8>(2.0,-1.44));
|
---|
126 |
|
---|
127 | dvl.SetI("IVV3-783", 783);
|
---|
128 | dvl("IVV3-783-O") = 7783;
|
---|
129 | // dvl["Avec[]"] = "operateur [] !";
|
---|
130 | dvl.SetD("DVV3", 3.141592652141592652);
|
---|
131 | dvl.SetComment("DVV3", "Comment for DVV3, r_8 type variable");
|
---|
132 | dvl("DVV3avec()") = 44.555e-8;
|
---|
133 |
|
---|
134 | dvl.SetS("Blanc_White", "123.456Ma premiere chaine");
|
---|
135 | dvl.SetI("IntegerValue", 55777);
|
---|
136 | dvl.SetComment("IntegerValue", "This variable has a comment");
|
---|
137 | dvl.Comment() = "This is a test DVL produced by the program tdvl.cc \n Using SOPHYA , Feb 2000";
|
---|
138 |
|
---|
139 | dvl["Sinf"] = "inf 0985";
|
---|
140 | dvl.Print();
|
---|
141 |
|
---|
142 |
|
---|
143 | double d = dvl("DV2-4.5");
|
---|
144 | float f = dvl("DVV3");
|
---|
145 | int i = dvl("IVV3-783");
|
---|
146 | complex<r_8> z = dvl("ZV");
|
---|
147 |
|
---|
148 | printf("\n \n Essai1 (IVV3 DVV3 DV2= ) %d %.20g %g \n", i, f, (float)d);
|
---|
149 | printf("\n \n Essai ZV= (%.2g %g I) \n", z.real(), z.imag());
|
---|
150 | cout << "Test Comment/IntegerValue: " << dvl.GetComment("IntegerValue") << endl;
|
---|
151 | cout << "Test Comment/DVV3: " << dvl.GetComment("DVV3") << endl;
|
---|
152 |
|
---|
153 | cout << "Test string recup " << (string)(dvl["Blanc_White"]) << endl;
|
---|
154 | cout << "Test string recup(int=80) " << (string)(dvl["IV1-80"]) << endl;
|
---|
155 | dvl("DVV3") = (double)3.141592652141592652;
|
---|
156 | cout << "Test string recup(double=Pi..i) " << (string)(dvl["DVV3"]) << endl;
|
---|
157 |
|
---|
158 | {
|
---|
159 | cout << " Writing DVList in file PPF dvl.ppf " << endl;
|
---|
160 | POutPersist os("dvl.ppf");
|
---|
161 | os << dvl ;
|
---|
162 | }
|
---|
163 |
|
---|
164 | cout << "-------------------------- \n\n"
|
---|
165 | << " reading DVList from file dvl.ppf ... \n" << endl;
|
---|
166 |
|
---|
167 | DVList dvlr("dvl.ppf");
|
---|
168 | double df1 = (double)( dvlr["DVV3"] );
|
---|
169 | double df2 = (double)3.141592652141592652 - df1;
|
---|
170 | cout << " Test Precision : Pi-Pi= " << df2 << "DVV3= " << df1 << endl;
|
---|
171 |
|
---|
172 | cout << dvlr;
|
---|
173 |
|
---|
174 | }
|
---|
175 | void test_DataTable()
|
---|
176 | {
|
---|
177 | cout << "======= test_DataTable: simple DataTable test ======= " << endl;
|
---|
178 | DataTable dt(64);
|
---|
179 | dt.AddIntegerColumn("line");
|
---|
180 | dt.AddDoubleColumn("x");
|
---|
181 | dt.AddFloatColumn("f_sin");
|
---|
182 | dt.AddFloatColumn("f_cos");
|
---|
183 | dt.AddDoubleColumn("f_sinxcos");
|
---|
184 | dt.AddDoubleColumn("f_x2");
|
---|
185 | MuTyV rec[10];
|
---|
186 | cout << " 1/ First 1000 lines .... " << endl;
|
---|
187 | for(int k = 0; k<1000; k++) {
|
---|
188 | rec[0] = k;
|
---|
189 | double x = M_PI*k/100.;
|
---|
190 | double fx = sin(x)*cos(x);
|
---|
191 | rec[1] = x;
|
---|
192 | rec[2] = sin(x);
|
---|
193 | rec[3] = cos(x);
|
---|
194 | rec[4] = fx;
|
---|
195 | rec[5] = x*x;
|
---|
196 | dt.AddLine(rec);
|
---|
197 | }
|
---|
198 | cout << "1.b/ Use of = operator to make copy of dt " << endl;
|
---|
199 | DataTable dtc1;
|
---|
200 | dtc1 = dt;
|
---|
201 |
|
---|
202 | dt.Show();
|
---|
203 | cout << " 2/ Lines 1000-2000 .... " << endl;
|
---|
204 | for(int k = 1000; k<2000; k++) {
|
---|
205 | rec[0] = k;
|
---|
206 | double x = M_PI*k/100.;
|
---|
207 | double fx = sin(x)*cos(x);
|
---|
208 | rec[1] = x;
|
---|
209 | rec[2] = sin(x);
|
---|
210 | rec[3] = cos(x);
|
---|
211 | rec[4] = fx;
|
---|
212 | rec[5] = x*x;
|
---|
213 | dt.AddLine(rec);
|
---|
214 | }
|
---|
215 | cout << "2.b/ dt.Show(); : " << endl;
|
---|
216 | dt.Show();
|
---|
217 | cout << "2.c/ dtc1.Show(); : " << endl;
|
---|
218 | dtc1.Show();
|
---|
219 | cout << "2.d/ dt.LineHeaderToString() dt.LineToString(k) : " << endl;
|
---|
220 | cout << dt.LineHeaderToString() ;
|
---|
221 | for(int k = 0; k<1500; k+=75)
|
---|
222 | cout << "Line[" << k << "] " << dt.LineToString(k) << endl ;
|
---|
223 | {
|
---|
224 | cout << "3/ Writing DataTable dt to PPF stream dtable.ppf " << endl;
|
---|
225 | POutPersist po("dtable.ppf");
|
---|
226 | po << dt;
|
---|
227 | }
|
---|
228 | {
|
---|
229 | cout << "4/ Reading DataTable dtr from PPF stream dtable.ppf " << endl;
|
---|
230 | PInPersist pi("dtable.ppf");
|
---|
231 | DataTable dtr;
|
---|
232 | pi >> dtr;
|
---|
233 | cout << "4.b/ cout << dtr; " << endl;
|
---|
234 | cout << dtr;
|
---|
235 | cout << "4.c/ dtr.LineHeaderToString() dtr.LineToString(k) : " << endl;
|
---|
236 | cout << dtr.LineHeaderToString() ;
|
---|
237 | for(int k = 0; k<1500; k+=75)
|
---|
238 | cout << "Line[" << k << "] " << dtr.LineToString(k) << endl ;
|
---|
239 |
|
---|
240 | }
|
---|
241 |
|
---|
242 | cout << "============ FIN test_DataTable ============== " << endl;
|
---|
243 | }
|
---|
244 |
|
---|
245 | void test_SwPPFDataTable()
|
---|
246 | {
|
---|
247 | cout << "======= test_SwPPFDataTable(): simple SwPPFDataTable test ======= " << endl;
|
---|
248 | {
|
---|
249 | POutPersist po("swdtable.ppf");
|
---|
250 | SwPPFDataTable dt(po, 64);
|
---|
251 | dt.AddIntegerColumn("line");
|
---|
252 | dt.AddDoubleColumn("x");
|
---|
253 | dt.AddFloatColumn("f_sin");
|
---|
254 | dt.AddFloatColumn("f_cos");
|
---|
255 | dt.AddDoubleColumn("f_sinxcos");
|
---|
256 | dt.AddDoubleColumn("f_x2");
|
---|
257 | MuTyV rec[10];
|
---|
258 | cout << " 1/ First 1000 lines .... " << endl;
|
---|
259 | for(int k = 0; k<1000; k++) {
|
---|
260 | rec[0] = k;
|
---|
261 | double x = M_PI*k/100.;
|
---|
262 | double fx = sin(x)*cos(x);
|
---|
263 | rec[1] = x;
|
---|
264 | rec[2] = sin(x);
|
---|
265 | rec[3] = cos(x);
|
---|
266 | rec[4] = fx;
|
---|
267 | rec[5] = x*x;
|
---|
268 | dt.AddLine(rec);
|
---|
269 | }
|
---|
270 | cout << "1.b/ Use of = operator to make copy of dt " << endl;
|
---|
271 | SwPPFDataTable dtc1;
|
---|
272 | dtc1 = dt;
|
---|
273 | dt.Show();
|
---|
274 | cout << " 2/ Lines 1000-2000 .... " << endl;
|
---|
275 | for(int k = 1000; k<2000; k++) {
|
---|
276 | rec[0] = k;
|
---|
277 | double x = M_PI*k/100.;
|
---|
278 | double fx = sin(x)*cos(x);
|
---|
279 | rec[1] = x;
|
---|
280 | rec[2] = sin(x);
|
---|
281 | rec[3] = cos(x);
|
---|
282 | rec[4] = fx;
|
---|
283 | rec[5] = x*x;
|
---|
284 | dt.AddLine(rec);
|
---|
285 | }
|
---|
286 | cout << "2.b/ dt.Show(); : " << endl;
|
---|
287 | dt.Show();
|
---|
288 | cout << "2.c/ dtc1.Show(); : " << endl;
|
---|
289 | dtc1.Show();
|
---|
290 | cout << "3/ Writing SwPPFDataTable dt to PPF stream swdtable.ppf " << endl;
|
---|
291 | po << dt;
|
---|
292 | }
|
---|
293 | {
|
---|
294 | cout << "4/ Reading SwPPFDataTable dtr from PPF stream swdtable.ppf " << endl;
|
---|
295 | PInPersist pi("swdtable.ppf");
|
---|
296 | SwPPFDataTable dtr;
|
---|
297 | pi >> dtr;
|
---|
298 | cout << "4.b/ cout << dtr; " << endl;
|
---|
299 | cout << dtr;
|
---|
300 | cout << "4.c/ dtr.LineHeaderToString() dtr.LineToString(k) : " << endl;
|
---|
301 | cout << dtr.LineHeaderToString() ;
|
---|
302 | for(int k = 0; k<1500; k+=75)
|
---|
303 | cout << "Line[" << k << "] " << dtr.LineToString(k) << endl ;
|
---|
304 | }
|
---|
305 |
|
---|
306 | cout << "============ FIN test_SwPPFDataTable() ======== ======= " << endl;
|
---|
307 | }
|
---|
308 |
|
---|
309 |
|
---|
310 |
|
---|
311 |
|
---|
312 | void test_Xntuple()
|
---|
313 | {
|
---|
314 | char* names[] = {"str1", "str2", "str3", "str4", "str5"} ;
|
---|
315 | XNTuple nt(0, 0, 0, 5, names) ;
|
---|
316 | char** ce = new char*[5] ;
|
---|
317 | int i;
|
---|
318 | for(i = 0 ; i < 5 ; i++)
|
---|
319 | ce[i] = new char[20] ;
|
---|
320 |
|
---|
321 | cout << "======= test_Xtuple: simple XNTuple test ======= " << endl;
|
---|
322 |
|
---|
323 | strncpy(ce[1], "toto a une auto", 20) ;
|
---|
324 | strncpy(ce[2], "titi a une iti", 20) ;
|
---|
325 | strncpy(ce[3], "tutu a une utu", 20) ;
|
---|
326 | strncpy(ce[4], "tata a une ata", 20) ;
|
---|
327 | for(i = 0 ; i < 100000 ; i++) {
|
---|
328 | sprintf(ce[0], "%d", i) ;
|
---|
329 | nt.Fill(NULL, NULL, NULL, ce) ;
|
---|
330 | }
|
---|
331 |
|
---|
332 | nt.Show() ;
|
---|
333 | cout << nt.LineHeaderToString() ;
|
---|
334 | cout << nt.LineToString(5027) << endl ;
|
---|
335 |
|
---|
336 | char* names2[] = {"d0", "d1", "f0", "f1", "f2", "i0", "str0", "str1"} ;
|
---|
337 | XNTuple nt2(2, 3, 1, 2, names2) ;
|
---|
338 | double de[2] ; float fe[3] ; int ie ;
|
---|
339 | char** ce2 = new char*[2] ;
|
---|
340 | for(i = 0 ; i < 2 ; i++) ce2[i] = new char[20] ;
|
---|
341 | strncpy(ce2[1], "glop glop", 20) ;
|
---|
342 |
|
---|
343 | for(i = 0 ; i < 100000 ; i++) {
|
---|
344 | de[0] = i ;
|
---|
345 | de[1] = sin((double)i) ;
|
---|
346 | fe[0] = i ;
|
---|
347 | fe[1] = i * cos((double)i) ;
|
---|
348 | fe[2] = 2*i ;
|
---|
349 | ie = -i;
|
---|
350 | sprintf(ce[0], "%d", i) ;
|
---|
351 | nt2.Fill(de, fe, &ie, ce) ;
|
---|
352 | }
|
---|
353 | nt2.Show() ;
|
---|
354 | nt2.LineHeaderToString() ;
|
---|
355 | // nt2.LineToString(20) ;
|
---|
356 | }
|
---|
357 |
|
---|
358 |
|
---|
359 | void test_xntuple()
|
---|
360 | {
|
---|
361 | char* names[] = {"dblval", "floval", "intval", "strval"} ;
|
---|
362 | XNTuple nt(1, 1, 1, 1, names) ;
|
---|
363 | double de ;
|
---|
364 | float fe ;
|
---|
365 | int ie ;
|
---|
366 | char* ce = new char[22] ;
|
---|
367 |
|
---|
368 |
|
---|
369 | cout << "======= test_Xtuple: XNTuple test ======= " << endl;
|
---|
370 | int i;
|
---|
371 | for(i = 0 ; i < nt.NVar() ; i++)
|
---|
372 | printf(" +++ %s <--> %d \n",
|
---|
373 | nt.NomIndex(i).c_str(), nt.IndexNom(nt.NomIndex(i).c_str())) ;
|
---|
374 |
|
---|
375 | for(i = 0 ; i < 100000 ; i++) {
|
---|
376 | de = fe = ie = i ;
|
---|
377 | sprintf(ce, "%d", i) ;
|
---|
378 | nt.Fill(&de, &fe, &ie, &ce) ;
|
---|
379 | }
|
---|
380 | nt.Show() ;
|
---|
381 | cout << nt.VarList_C("toto") ;
|
---|
382 | cout << nt.LineHeaderToString() ;
|
---|
383 | cout << nt.LineToString(20) << endl << endl ;
|
---|
384 |
|
---|
385 |
|
---|
386 | XNTuple nt2 ;
|
---|
387 | nt2.SwapPath() = "/tmp/sop/" ;
|
---|
388 | nt2.Copy(nt) ;
|
---|
389 | nt2.Show() ;
|
---|
390 | for(i = 0 ; i < 100000 ; i++) {
|
---|
391 | de = fe = ie = i ;
|
---|
392 | sprintf(ce, "%d", i) ;
|
---|
393 | nt2.Fill(&de, &fe, &ie, &ce) ;
|
---|
394 | }
|
---|
395 | nt2.Show() ;
|
---|
396 |
|
---|
397 | {
|
---|
398 | POutPersist os("xnt.ppf");
|
---|
399 | os << nt2 ;
|
---|
400 | }
|
---|
401 |
|
---|
402 | XNTuple::SetSwapPath("/tmp/sop/") ;
|
---|
403 | XNTuple nt3("xnt.ppf") ;
|
---|
404 | nt3.Show() ;
|
---|
405 |
|
---|
406 | for(i = 0 ; i < nt3.NEntry() ; i+= 1000)
|
---|
407 | printf("%f %f %d %s\n",
|
---|
408 | nt3.GetDVal(i,0),
|
---|
409 | nt3.GetFVal(i,1),
|
---|
410 | nt3.GetIVal(i,2),
|
---|
411 | nt3.GetSVal(i,3).c_str()) ;
|
---|
412 |
|
---|
413 | double min, max ;
|
---|
414 | for(i = 0 ; i < nt3.NVar() ; i++) {
|
---|
415 | nt3.GetMinMax(i, min, max) ;
|
---|
416 | printf("GetMinMax(%s) : %f/%f\n",
|
---|
417 | nt3.NomIndex(i).c_str(), min, max) ;
|
---|
418 | }
|
---|
419 | // nt3.Show() ;
|
---|
420 | }
|
---|
421 |
|
---|