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

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

compil sour SGI-CC , Reza 14/11/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 int i;
170 for(i = 0 ; i < 5 ; i++)
171 ce[i] = new char[20] ;
172
173 cout << "======= test_Xtuple: simple XNTuple test ======= " << endl;
174
175 strncpy(ce[1], "toto a une auto", 20) ;
176 strncpy(ce[2], "titi a une iti", 20) ;
177 strncpy(ce[3], "tutu a une utu", 20) ;
178 strncpy(ce[4], "tata a une ata", 20) ;
179 for(i = 0 ; i < 100000 ; i++) {
180 sprintf(ce[0], "%d", i) ;
181 nt.Fill(NULL, NULL, NULL, ce) ;
182 }
183
184 nt.Show() ;
185 cout << nt.LineHeaderToString() ;
186 cout << nt.LineToString(5027) << endl ;
187
188 char* names2[] = {"d0", "d1", "f0", "f1", "f2", "i0", "str0", "str1"} ;
189 XNTuple nt2(2, 3, 1, 2, names2) ;
190 double de[2] ; float fe[3] ; int ie ;
191 char** ce2 = new char*[2] ;
192 for(i = 0 ; i < 2 ; i++) ce2[i] = new char[20] ;
193 strncpy(ce2[1], "glop glop", 20) ;
194
195 for(i = 0 ; i < 100000 ; i++) {
196 de[0] = i ;
197 de[1] = sin(i) ;
198 fe[0] = i ;
199 fe[1] = i * cos(i) ;
200 fe[2] = 2*i ;
201 ie = -i;
202 sprintf(ce[0], "%d", i) ;
203 nt2.Fill(de, fe, &ie, ce) ;
204 }
205 nt2.Show() ;
206 nt2.LineHeaderToString() ;
207 // nt2.LineToString(20) ;
208}
209
210
211void test_xntuple()
212{
213 char* names[] = {"dblval", "floval", "intval", "strval"} ;
214 XNTuple nt(1, 1, 1, 1, names) ;
215 double de ;
216 float fe ;
217 int ie ;
218 char* ce = new char[22] ;
219
220
221 cout << "======= test_Xtuple: XNTuple test ======= " << endl;
222 int i;
223 for(i = 0 ; i < nt.NVar() ; i++)
224 printf(" +++ %s <--> %d \n",
225 nt.NomIndex(i).c_str(), nt.IndexNom(nt.NomIndex(i).c_str())) ;
226
227 for(i = 0 ; i < 100000 ; i++) {
228 de = fe = ie = i ;
229 sprintf(ce, "%d", i) ;
230 nt.Fill(&de, &fe, &ie, &ce) ;
231 }
232 nt.Show() ;
233 cout << nt.VarList_C("toto") ;
234 cout << nt.LineHeaderToString() ;
235 cout << nt.LineToString(20) << endl << endl ;
236
237
238 XNTuple nt2 ;
239 nt2.SwapPath() = "/tmp/sop/" ;
240 nt2.Copy(nt) ;
241 nt2.Show() ;
242 for(i = 0 ; i < 100000 ; i++) {
243 de = fe = ie = i ;
244 sprintf(ce, "%d", i) ;
245 nt2.Fill(&de, &fe, &ie, &ce) ;
246 }
247 nt2.Show() ;
248
249 {
250 POutPersist os("xnt.ppf");
251 os << nt2 ;
252 }
253
254 XNTuple::SetSwapPath("/tmp/sop/") ;
255 XNTuple nt3("xnt.ppf") ;
256 nt3.Show() ;
257
258 for(i = 0 ; i < nt3.NEntry() ; i+= 1000)
259 printf("%f %f %d %s\n",
260 nt3.GetDVal(i,0),
261 nt3.GetFVal(i,1),
262 nt3.GetIVal(i,2),
263 nt3.GetSVal(i,3).c_str()) ;
264
265 double min, max ;
266 for(i = 0 ; i < nt3.NVar() ; i++) {
267 nt3.GetMinMax(i, min, max) ;
268 printf("GetMinMax(%s) : %f/%f\n",
269 nt3.NomIndex(i).c_str(), min, max) ;
270 }
271 // nt3.Show() ;
272}
273
Note: See TracBrowser for help on using the repository browser.