source: Sophya/trunk/SophyaProg/Tests/tnt.cc@ 1161

Last change on this file since 1161 was 1161, checked in by ansari, 25 years ago

Modifs programmes test - Reza 29/8/2000

File size: 6.9 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <math.h>
4#include <iostream.h>
5
6#include "histinit.h"
7#include "dvlist.h"
8#include "ntuple.h"
9#include "xntuple.h"
10
11void test_dvl();
12void test_ntuple();
13void test_xntuple() ;
14void test_Xntuple() ;
15
16int main(int narg, char *arg[])
17{
18 SophyaInit();
19 if (narg < 2) {
20 cout << " tnt/Erreur arg - Usage: tnt d/n/x/X \n"
21 << " d:DVList n:NTuple x/X:XNTuple test \n" << endl;
22 exit(0);
23 }
24
25 try {
26 if (*arg[1] == 'd') test_dvl();
27 else if (*arg[1] == 'n') test_ntuple();
28 else if (*arg[1] == 'x') test_xntuple();
29 else if (*arg[1] == 'X') test_Xntuple();
30 }
31 catch(PThrowable exc ) {
32 cerr << "tnt-main() , Catched exception: \n" << exc.Msg() << endl;
33 }
34 catch(std::exception ex) {
35 cerr << "tnt-main() , Catched exception ! " << (string)(ex.what()) << endl;
36 }
37 catch(...) {
38 cerr << "tnt-main() , Catched ... ! " << endl;
39 }
40}
41
42/* ***** Test de NTuple simple ***** */
43void test_ntuple()
44{
45 char * names[3] = {"XPos", "YPos", "Val"};
46 int i,j, k;
47 float xnt[3];
48
49 cout << "======= test_ntuple: Testing NTuple ======= " << endl;
50
51 cout << "Creation Ntuple avec X,Y,Val ... " << endl;
52 NTuple nt1(3, names, 20);
53
54 k = 0;
55 for(j=0; j<8; j++)
56 for(i=0; i<12; i++)
57 { xnt[0] = i+0.5; xnt[1] = j+0.5; xnt[2] = k;
58 nt1.Fill(xnt); k++; }
59
60 nt1.Info().Comment() = "NTuple de Test - Cree par tnt.cc";
61 nt1.Info()["Version"] = SophyaVersion();
62 nt1.Show(cout);
63 nt1.Print(0, 5);
64 nt1.Print(18, 5);
65 nt1.Print(94, 5);
66
67 string fn = "nt.ppf";
68 {
69 cout << "Ecriture NTuple ds nt.ppf ... \n" << endl;
70 ObjFileIO<NTuple> fio(&nt1);
71 fio.Write(fn);
72 }
73
74 {
75 cout << "Lecture NTuple (nt2) ds nt.ppf ... \n" << endl;
76
77 ObjFileIO<NTuple> fio(fn);
78 NTuple* nt2 = (NTuple*)fio.DataObj();
79 nt2->Show(cout);
80 nt2->Print(0, 5);
81 nt2->Print(18, 5);
82 nt2->Print(94, 5);
83 }
84
85
86}
87
88/* ***** Test de dvlist ***** */
89void test_dvl()
90{
91DVList dvl;
92
93cout << "\n ======= test_dvl: Testing MuTyV ======= " << endl;
94MuTyV zvs = " ( 1.41 -2.71) ";
95MuTyV dvs = "434.898";
96MuTyV fvu = 314.1596;
97MuTyV ivu = 7654321;
98cout << " float->string: fvu= " << fvu << " (string)fvu=" << (string)fvu << endl;
99cout << " int->string: ivu= " << ivu << " (string)ivu=" << (string)ivu << endl;
100cout << "String->complex<double>: zvs = " << zvs
101 << " (complex<double>)zvs= " << (complex<double>)zvs << endl;
102cout << "String->double: dvs = " << dvs
103 << " (double)zvs= " << (double)dvs << endl;
104
105
106cout << "\n\n ======= test_dvl: Testing DVList ======= " << endl;
107dvl.SetI("Var XXX", 12345);
108dvl.SetI("IV1-80", 80);
109dvl.SetI("IV2-330", 330);
110
111dvl.SetD("DV1-0.2", 0.2);
112dvl.SetD("DV2-4.5", 4.5);
113dvl.SetZ("ZV", complex<r_8>(2.0,-1.44));
114
115dvl.SetI("IVV3-783", 783);
116dvl("IVV3-783-O") = 7783;
117// dvl["Avec[]"] = "operateur [] !";
118dvl.SetD("DVV3", 3.141592652141592652);
119dvl.SetComment("DVV3", "Comment for DVV3, r_8 type variable");
120dvl("DVV3avec()") = 44.555e-8;
121
122dvl.SetS("Blanc_White", "123.456Ma premiere chaine");
123dvl.SetI("IntegerValue", 55777);
124dvl.SetComment("IntegerValue", "This variable has a comment");
125dvl.Comment() = "This is a test DVL produced by the program tdvl.cc \n Using SOPHYA , Feb 2000";
126
127dvl["Sinf"] = "inf 0985";
128dvl.Print();
129
130
131double d = dvl("DV2-4.5");
132float f = dvl("DVV3");
133int i = dvl("IVV3-783");
134complex<r_8> z = dvl("ZV");
135
136printf("\n \n Essai1 (IVV3 DVV3 DV2= ) %d %.20g %g \n", i, f, (float)d);
137printf("\n \n Essai ZV= (%.2g %g I) \n", z.real(), z.imag());
138cout << "Test Comment/IntegerValue: " << dvl.GetComment("IntegerValue") << endl;
139cout << "Test Comment/DVV3: " << dvl.GetComment("DVV3") << endl;
140
141cout << "Test string recup " << (string)(dvl["Blanc_White"]) << endl;
142cout << "Test string recup(int=80) " << (string)(dvl["IV1-80"]) << endl;
143dvl("DVV3") = (double)3.141592652141592652;
144cout << "Test string recup(double=Pi..i) " << (string)(dvl["DVV3"]) << endl;
145
146 {
147 cout << " Writing DVList in file PPF dvl.ppf " << endl;
148 POutPersist os("dvl.ppf");
149 os << dvl ;
150 }
151
152 cout << "-------------------------- \n\n"
153 << " reading DVList from file dvl.ppf ... \n" << endl;
154
155 DVList dvlr("dvl.ppf");
156 double df1 = (double)( dvlr["DVV3"] );
157 double df2 = (double)3.141592652141592652 - df1;
158 cout << " Test Precision : Pi-Pi= " << df2 << "DVV3= " << df1 << endl;
159
160 cout << dvlr;
161
162}
163
164void test_Xntuple()
165{
166 char* names[] = {"str1", "str2", "str3", "str4", "str5"} ;
167 XNTuple nt(0, 0, 0, 5, names) ;
168 char** ce = new char*[5] ;
169 for(int i = 0 ; i < 5 ; i++)
170 ce[i] = new char[20] ;
171
172 cout << "======= test_Xtuple: simple XNTuple test ======= " << endl;
173
174 strncpy(ce[1], "toto a une auto", 20) ;
175 strncpy(ce[2], "titi a une iti", 20) ;
176 strncpy(ce[3], "tutu a une utu", 20) ;
177 strncpy(ce[4], "tata a une ata", 20) ;
178 for(int i = 0 ; i < 100000 ; i++) {
179 sprintf(ce[0], "%d", i) ;
180 nt.Fill(NULL, NULL, NULL, ce) ;
181 }
182
183 nt.Show() ;
184 cout << nt.LineHeaderToString() ;
185 cout << nt.LineToString(5027) << endl ;
186
187 char* names2[] = {"d0", "d1", "f0", "f1", "f2", "i0", "str0", "str1"} ;
188 XNTuple nt2(2, 3, 1, 2, names2) ;
189 double de[2] ; float fe[3] ; int ie ;
190 char** ce2 = new char*[2] ;
191 for(int i = 0 ; i < 2 ; i++) ce2[i] = new char[20] ;
192 strncpy(ce2[1], "glop glop", 20) ;
193
194 for(int i = 0 ; i < 100000 ; i++) {
195 de[0] = i ;
196 de[1] = sin(i) ;
197 fe[0] = i ;
198 fe[1] = i * cos(i) ;
199 fe[2] = 2*i ;
200 ie = -i;
201 sprintf(ce[0], "%d", i) ;
202 nt2.Fill(de, fe, &ie, ce) ;
203 }
204 nt2.Show() ;
205 nt2.LineHeaderToString() ;
206 // nt2.LineToString(20) ;
207}
208
209
210void test_xntuple()
211{
212 char* names[] = {"dblval", "floval", "intval", "strval"} ;
213 XNTuple nt(1, 1, 1, 1, names) ;
214 double de ;
215 float fe ;
216 int ie ;
217 char* ce = new char[22] ;
218
219
220 cout << "======= test_Xtuple: XNTuple test ======= " << endl;
221 for(int i = 0 ; i < nt.NVar() ; i++)
222 printf(" +++ %s <--> %d \n",
223 nt.NomIndex(i).c_str(), nt.IndexNom(nt.NomIndex(i).c_str())) ;
224
225 for(int i = 0 ; i < 100000 ; i++) {
226 de = fe = ie = i ;
227 sprintf(ce, "%d", i) ;
228 nt.Fill(&de, &fe, &ie, &ce) ;
229 }
230 nt.Show() ;
231 cout << nt.VarList_C("toto") ;
232 cout << nt.LineHeaderToString() ;
233 cout << nt.LineToString(20) << endl << endl ;
234
235
236 XNTuple nt2 ;
237 nt2.SwapPath() = "/tmp/sop/" ;
238 nt2.Copy(nt) ;
239 nt2.Show() ;
240 for(int i = 0 ; i < 100000 ; i++) {
241 de = fe = ie = i ;
242 sprintf(ce, "%d", i) ;
243 nt2.Fill(&de, &fe, &ie, &ce) ;
244 }
245 nt2.Show() ;
246
247 {
248 POutPersist os("xnt.ppf");
249 os << nt2 ;
250 }
251
252 XNTuple::SetSwapPath("/tmp/sop/") ;
253 XNTuple nt3("xnt.ppf") ;
254 nt3.Show() ;
255
256 for(int i = 0 ; i < nt3.NEntry() ; i+= 1000)
257 printf("%f %f %d %s\n",
258 nt3.GetDVal(i,0),
259 nt3.GetFVal(i,1),
260 nt3.GetIVal(i,2),
261 nt3.GetSVal(i,3).c_str()) ;
262
263 double min, max ;
264 for(int i = 0 ; i < nt3.NVar() ; i++) {
265 nt3.GetMinMax(i, min, max) ;
266 printf("GetMinMax(%s) : %f/%f\n",
267 nt3.NomIndex(i).c_str(), min, max) ;
268 }
269 // nt3.Show() ;
270}
271
Note: See TracBrowser for help on using the repository browser.