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

Last change on this file since 998 was 768, checked in by ansari, 26 years ago

Reorganisation - PeidaInit() -> SophyaInit() - Reza 2/3/2000

File size: 6.2 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);
98
99dvl.SetI("IVV3-783", 783);
100dvl("IVV3-783-O") = 7783;
101// dvl["Avec[]"] = "operateur [] !";
102dvl.SetD("DVV3", 3.141592652141592652);
103dvl.SetComment("DVV3", "Comment for DVV3, r_8 type variable");
104dvl("DVV3avec()") = 44.555e-8;
105
106dvl.SetS("Blanc_White", "123.456Ma premiere chaine");
107dvl.SetI("IntegerValue", 55777);
108dvl.SetComment("IntegerValue", "This variable has a comment");
109dvl.Comment() = "This is a test DVL produced by the program tdvl.cc \n Using SOPHYA , Feb 2000";
110dvl.Print();
111
112double d = dvl("DV2-4.5");
113float f = dvl("DVV3");
114int i = dvl("IVV3-783");
115
116printf("\n \n Essai1 (IVV3 DVV3 DV2= ) %d %.20g %g \n", i, f, (float)d);
117cout << "Test Comment/IntegerValue: " << dvl.GetComment("IntegerValue") << endl;
118cout << "Test Comment/DVV3: " << dvl.GetComment("DVV3") << endl;
119
120cout << "Test string recup " << (string)(dvl["Blanc_White"]) << endl;
121cout << "Test string recup(int=80) " << (string)(dvl["IV1-80"]) << endl;
122dvl("DVV3") = (double)3.141592652141592652;
123cout << "Test string recup(double=Pi..i) " << (string)(dvl["DVV3"]) << endl;
124
125 {
126 cout << " Writing DVList in file PPF dvl.ppf " << endl;
127 POutPersist os("dvl.ppf");
128 os << dvl ;
129 }
130
131 cout << "-------------------------- \n\n"
132 << " reading DVList from file dvl.ppf ... \n" << endl;
133
134 DVList dvlr("dvl.ppf");
135 double df1 = (double)( dvlr["DVV3"] );
136 double df2 = (double)3.141592652141592652 - df1;
137 cout << " Test Precision : Pi-Pi= " << df1 << "DVV3= " << df1 << endl;
138
139 cout << dvlr;
140
[583]141}
[224]142
[720]143void test_Xntuple()
[583]144{
[720]145 char* names[] = {"str1", "str2", "str3", "str4", "str5"} ;
146 XNTuple nt(0, 0, 0, 5, names) ;
147 char** ce = new char*[5] ;
148 for(int i = 0 ; i < 5 ; i++)
149 ce[i] = new char[20] ;
[224]150
[720]151 cout << "======= test_Xtuple: simple XNTuple test ======= " << endl;
152
153 strncpy(ce[1], "toto a une auto", 20) ;
154 strncpy(ce[2], "titi a une iti", 20) ;
155 strncpy(ce[3], "tutu a une utu", 20) ;
156 strncpy(ce[4], "tata a une ata", 20) ;
157 for(int i = 0 ; i < 100000 ; i++) {
158 sprintf(ce[0], "%d", i) ;
159 nt.Fill(NULL, NULL, NULL, ce) ;
160 }
161
162 nt.Show() ;
163 cout << nt.LineHeaderToString() ;
164 cout << nt.LineToString(5027) << endl ;
165
166 char* names2[] = {"d0", "d1", "f0", "f1", "f2", "i0", "str0", "str1"} ;
167 XNTuple nt2(2, 3, 1, 2, names2) ;
168 double de[2] ; float fe[3] ; int ie ;
169 char** ce2 = new char*[2] ;
170 for(int i = 0 ; i < 2 ; i++) ce2[i] = new char[20] ;
171 strncpy(ce2[1], "glop glop", 20) ;
172
173 for(int i = 0 ; i < 100000 ; i++) {
174 de[0] = i ;
175 de[1] = sin(i) ;
176 fe[0] = i ;
177 fe[1] = i * cos(i) ;
178 fe[2] = 2*i ;
179 ie = -i;
180 sprintf(ce[0], "%d", i) ;
181 nt2.Fill(de, fe, &ie, ce) ;
182 }
183 nt2.Show() ;
184 nt2.LineHeaderToString() ;
185 // nt2.LineToString(20) ;
[583]186}
[224]187
188
[720]189void test_xntuple()
190{
191 char* names[] = {"dblval", "floval", "intval", "strval"} ;
192 XNTuple nt(1, 1, 1, 1, names) ;
193 double de ;
194 float fe ;
195 int ie ;
196 char* ce = new char[22] ;
197
198
199 cout << "======= test_Xtuple: XNTuple test ======= " << endl;
200 for(int i = 0 ; i < nt.NVar() ; i++)
201 printf(" +++ %s <--> %d \n",
202 nt.NomIndex(i).c_str(), nt.IndexNom(nt.NomIndex(i).c_str())) ;
[224]203
[720]204 for(int i = 0 ; i < 100000 ; i++) {
205 de = fe = ie = i ;
206 sprintf(ce, "%d", i) ;
207 nt.Fill(&de, &fe, &ie, &ce) ;
208 }
209 nt.Show() ;
210 cout << nt.VarList_C("toto") ;
211 cout << nt.LineHeaderToString() ;
212 cout << nt.LineToString(20) << endl << endl ;
213
214
215 XNTuple nt2 ;
216 nt2.SwapPath() = "/tmp/sop/" ;
217 nt2.Copy(nt) ;
218 nt2.Show() ;
219 for(int i = 0 ; i < 100000 ; i++) {
220 de = fe = ie = i ;
221 sprintf(ce, "%d", i) ;
222 nt2.Fill(&de, &fe, &ie, &ce) ;
223 }
224 nt2.Show() ;
225
226 {
227 POutPersist os("xnt.ppf");
228 os << nt2 ;
229 }
[224]230
[720]231 XNTuple::SetSwapPath("/tmp/sop/") ;
232 XNTuple nt3("xnt.ppf") ;
233 nt3.Show() ;
234
235 for(int i = 0 ; i < nt3.NEntry() ; i+= 1000)
236 printf("%f %f %d %s\n",
237 nt3.GetDVal(i,0),
238 nt3.GetFVal(i,1),
239 nt3.GetIVal(i,2),
240 nt3.GetSVal(i,3).c_str()) ;
241
242 double min, max ;
243 for(int i = 0 ; i < nt3.NVar() ; i++) {
244 nt3.GetMinMax(i, min, max) ;
245 printf("GetMinMax(%s) : %f/%f\n",
246 nt3.NomIndex(i).c_str(), min, max) ;
247 }
248 // nt3.Show() ;
[224]249}
250
Note: See TracBrowser for help on using the repository browser.