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

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

Adaptation modifs MuTyV - Reza 24/7/2000

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