| [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] | 11 | void test_dvl(); | 
|---|
|  | 12 | void test_ntuple(); | 
|---|
|  | 13 | void test_xntuple() ; | 
|---|
|  | 14 | void test_Xntuple() ; | 
|---|
|  | 15 |  | 
|---|
|  | 16 | int 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 ***** */ | 
|---|
|  | 43 | void 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 |  | 
|---|
| [1161] | 60 | nt1.Info().Comment() = "NTuple de Test - Cree par tnt.cc"; | 
|---|
|  | 61 | nt1.Info()["Version"] = SophyaVersion(); | 
|---|
| [720] | 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 ***** */ | 
|---|
|  | 89 | void test_dvl() | 
|---|
| [583] | 90 | { | 
|---|
| [720] | 91 | DVList dvl; | 
|---|
|  | 92 |  | 
|---|
| [1161] | 93 | cout << "\n ======= test_dvl:  Testing MuTyV ======= " << endl; | 
|---|
|  | 94 | MuTyV zvs = " ( 1.41 -2.71) "; | 
|---|
|  | 95 | MuTyV dvs = "434.898"; | 
|---|
|  | 96 | MuTyV fvu = 314.1596; | 
|---|
|  | 97 | MuTyV ivu = 7654321; | 
|---|
|  | 98 | cout << " float->string: fvu= " << fvu << " (string)fvu=" << (string)fvu << endl; | 
|---|
|  | 99 | cout << " int->string: ivu= " << ivu << " (string)ivu=" << (string)ivu << endl; | 
|---|
| [1343] | 100 | complex<double> zzd = zvs; | 
|---|
| [1161] | 101 | cout << "String->complex<double>: zvs = " << zvs | 
|---|
| [1343] | 102 | << " (complex<double>)zvs= " << zzd << endl; | 
|---|
| [1161] | 103 | cout << "String->double: dvs = " << dvs | 
|---|
|  | 104 | << " (double)zvs= " << (double)dvs << endl; | 
|---|
|  | 105 |  | 
|---|
|  | 106 |  | 
|---|
|  | 107 | cout << "\n\n ======= test_dvl:  Testing DVList ======= " << endl; | 
|---|
| [720] | 108 | dvl.SetI("Var XXX", 12345); | 
|---|
|  | 109 | dvl.SetI("IV1-80", 80); | 
|---|
|  | 110 | dvl.SetI("IV2-330", 330); | 
|---|
|  | 111 |  | 
|---|
|  | 112 | dvl.SetD("DV1-0.2", 0.2); | 
|---|
|  | 113 | dvl.SetD("DV2-4.5", 4.5); | 
|---|
| [1082] | 114 | dvl.SetZ("ZV", complex<r_8>(2.0,-1.44)); | 
|---|
| [720] | 115 |  | 
|---|
|  | 116 | dvl.SetI("IVV3-783", 783); | 
|---|
|  | 117 | dvl("IVV3-783-O") =  7783; | 
|---|
|  | 118 | // dvl["Avec[]"] =  "operateur [] !"; | 
|---|
|  | 119 | dvl.SetD("DVV3", 3.141592652141592652); | 
|---|
|  | 120 | dvl.SetComment("DVV3", "Comment for DVV3, r_8 type variable"); | 
|---|
|  | 121 | dvl("DVV3avec()") =  44.555e-8; | 
|---|
|  | 122 |  | 
|---|
|  | 123 | dvl.SetS("Blanc_White", "123.456Ma premiere chaine"); | 
|---|
|  | 124 | dvl.SetI("IntegerValue", 55777); | 
|---|
|  | 125 | dvl.SetComment("IntegerValue", "This variable has a comment"); | 
|---|
|  | 126 | dvl.Comment() = "This is a test DVL produced by the program tdvl.cc \n Using SOPHYA , Feb 2000"; | 
|---|
| [1161] | 127 |  | 
|---|
|  | 128 | dvl["Sinf"] = "inf 0985"; | 
|---|
| [720] | 129 | dvl.Print(); | 
|---|
|  | 130 |  | 
|---|
| [1161] | 131 |  | 
|---|
| [720] | 132 | double d = dvl("DV2-4.5"); | 
|---|
|  | 133 | float f = dvl("DVV3"); | 
|---|
|  | 134 | int i = dvl("IVV3-783"); | 
|---|
| [1082] | 135 | complex<r_8> z = dvl("ZV"); | 
|---|
| [720] | 136 |  | 
|---|
|  | 137 | printf("\n \n Essai1 (IVV3 DVV3 DV2= ) %d  %.20g  %g \n", i, f, (float)d); | 
|---|
| [1082] | 138 | printf("\n \n Essai ZV= (%.2g  %g I) \n", z.real(), z.imag()); | 
|---|
| [720] | 139 | cout << "Test Comment/IntegerValue: " << dvl.GetComment("IntegerValue") << endl; | 
|---|
|  | 140 | cout << "Test Comment/DVV3: " << dvl.GetComment("DVV3") << endl; | 
|---|
|  | 141 |  | 
|---|
|  | 142 | cout << "Test string recup  " << (string)(dvl["Blanc_White"]) << endl; | 
|---|
|  | 143 | cout << "Test string recup(int=80)  " << (string)(dvl["IV1-80"]) << endl; | 
|---|
|  | 144 | dvl("DVV3") = (double)3.141592652141592652; | 
|---|
|  | 145 | cout << "Test string recup(double=Pi..i)  " << (string)(dvl["DVV3"]) << endl; | 
|---|
|  | 146 |  | 
|---|
|  | 147 | { | 
|---|
|  | 148 | cout << " Writing DVList in file PPF dvl.ppf " << endl; | 
|---|
|  | 149 | POutPersist os("dvl.ppf"); | 
|---|
|  | 150 | os << dvl ; | 
|---|
|  | 151 | } | 
|---|
|  | 152 |  | 
|---|
|  | 153 | cout << "-------------------------- \n\n" | 
|---|
|  | 154 | << " reading DVList from file dvl.ppf ... \n" << endl; | 
|---|
|  | 155 |  | 
|---|
|  | 156 | DVList dvlr("dvl.ppf"); | 
|---|
|  | 157 | double df1 = (double)( dvlr["DVV3"] ); | 
|---|
|  | 158 | double df2 = (double)3.141592652141592652 - df1; | 
|---|
| [1082] | 159 | cout << " Test Precision : Pi-Pi= " << df2  << "DVV3= " << df1 << endl; | 
|---|
| [720] | 160 |  | 
|---|
|  | 161 | cout << dvlr; | 
|---|
|  | 162 |  | 
|---|
| [583] | 163 | } | 
|---|
| [224] | 164 |  | 
|---|
| [720] | 165 | void test_Xntuple() | 
|---|
| [583] | 166 | { | 
|---|
| [720] | 167 | char* names[] = {"str1", "str2", "str3", "str4", "str5"} ; | 
|---|
|  | 168 | XNTuple nt(0, 0, 0, 5, names) ; | 
|---|
|  | 169 | char** ce = new char*[5] ; | 
|---|
| [1326] | 170 | int i; | 
|---|
|  | 171 | for(i = 0 ; i < 5 ; i++) | 
|---|
| [720] | 172 | ce[i] = new char[20] ; | 
|---|
| [224] | 173 |  | 
|---|
| [720] | 174 | cout << "======= test_Xtuple:  simple XNTuple test ======= " << endl; | 
|---|
|  | 175 |  | 
|---|
|  | 176 | strncpy(ce[1], "toto a une auto", 20) ; | 
|---|
|  | 177 | strncpy(ce[2], "titi a une iti", 20) ; | 
|---|
|  | 178 | strncpy(ce[3], "tutu a une utu", 20) ; | 
|---|
|  | 179 | strncpy(ce[4], "tata a une ata", 20) ; | 
|---|
| [1326] | 180 | for(i = 0 ; i < 100000 ; i++) { | 
|---|
| [720] | 181 | sprintf(ce[0], "%d", i) ; | 
|---|
|  | 182 | nt.Fill(NULL, NULL, NULL, ce) ; | 
|---|
|  | 183 | } | 
|---|
|  | 184 |  | 
|---|
|  | 185 | nt.Show() ; | 
|---|
|  | 186 | cout << nt.LineHeaderToString() ; | 
|---|
|  | 187 | cout << nt.LineToString(5027) << endl ; | 
|---|
|  | 188 |  | 
|---|
|  | 189 | char* names2[] = {"d0", "d1", "f0", "f1", "f2", "i0", "str0", "str1"} ; | 
|---|
|  | 190 | XNTuple nt2(2, 3, 1, 2, names2) ; | 
|---|
|  | 191 | double de[2] ; float fe[3] ; int ie ; | 
|---|
|  | 192 | char** ce2 = new char*[2] ; | 
|---|
| [1326] | 193 | for(i = 0 ; i < 2 ; i++) ce2[i] = new char[20] ; | 
|---|
| [720] | 194 | strncpy(ce2[1], "glop glop", 20) ; | 
|---|
|  | 195 |  | 
|---|
| [1326] | 196 | for(i = 0 ; i < 100000 ; i++) { | 
|---|
| [720] | 197 | de[0] = i ; | 
|---|
| [1406] | 198 | de[1] = sin((double)i) ; | 
|---|
| [720] | 199 | fe[0] = i ; | 
|---|
| [1406] | 200 | fe[1] = i * cos((double)i) ; | 
|---|
| [720] | 201 | fe[2] = 2*i ; | 
|---|
|  | 202 | ie    = -i; | 
|---|
|  | 203 | sprintf(ce[0], "%d", i) ; | 
|---|
|  | 204 | nt2.Fill(de, fe, &ie, ce) ; | 
|---|
|  | 205 | } | 
|---|
|  | 206 | nt2.Show() ; | 
|---|
|  | 207 | nt2.LineHeaderToString() ; | 
|---|
|  | 208 | //    nt2.LineToString(20) ; | 
|---|
| [583] | 209 | } | 
|---|
| [224] | 210 |  | 
|---|
|  | 211 |  | 
|---|
| [720] | 212 | void test_xntuple() | 
|---|
|  | 213 | { | 
|---|
|  | 214 | char* names[] = {"dblval", "floval", "intval", "strval"} ; | 
|---|
|  | 215 | XNTuple nt(1, 1, 1, 1, names) ; | 
|---|
|  | 216 | double de ; | 
|---|
|  | 217 | float  fe ; | 
|---|
|  | 218 | int    ie ; | 
|---|
|  | 219 | char*  ce = new char[22] ; | 
|---|
|  | 220 |  | 
|---|
|  | 221 |  | 
|---|
|  | 222 | cout << "======= test_Xtuple:  XNTuple test ======= " << endl; | 
|---|
| [1326] | 223 | int i; | 
|---|
|  | 224 | for(i = 0 ; i < nt.NVar() ; i++) | 
|---|
| [720] | 225 | printf(" +++ %s <--> %d \n", | 
|---|
|  | 226 | nt.NomIndex(i).c_str(), nt.IndexNom(nt.NomIndex(i).c_str())) ; | 
|---|
| [224] | 227 |  | 
|---|
| [1326] | 228 | for(i = 0 ; i < 100000 ; i++) { | 
|---|
| [720] | 229 | de = fe = ie = i ; | 
|---|
|  | 230 | sprintf(ce, "%d", i) ; | 
|---|
|  | 231 | nt.Fill(&de, &fe, &ie, &ce) ; | 
|---|
|  | 232 | } | 
|---|
|  | 233 | nt.Show() ; | 
|---|
|  | 234 | cout << nt.VarList_C("toto") ; | 
|---|
|  | 235 | cout << nt.LineHeaderToString() ; | 
|---|
|  | 236 | cout << nt.LineToString(20) << endl << endl ; | 
|---|
|  | 237 |  | 
|---|
|  | 238 |  | 
|---|
|  | 239 | XNTuple nt2 ; | 
|---|
|  | 240 | nt2.SwapPath() = "/tmp/sop/" ; | 
|---|
|  | 241 | nt2.Copy(nt) ; | 
|---|
|  | 242 | nt2.Show() ; | 
|---|
| [1326] | 243 | for(i = 0 ; i < 100000 ; i++) { | 
|---|
| [720] | 244 | de = fe = ie = i ; | 
|---|
|  | 245 | sprintf(ce, "%d", i) ; | 
|---|
|  | 246 | nt2.Fill(&de, &fe, &ie, &ce) ; | 
|---|
|  | 247 | } | 
|---|
|  | 248 | nt2.Show() ; | 
|---|
|  | 249 |  | 
|---|
|  | 250 | { | 
|---|
|  | 251 | POutPersist os("xnt.ppf"); | 
|---|
|  | 252 | os << nt2 ; | 
|---|
|  | 253 | } | 
|---|
| [224] | 254 |  | 
|---|
| [720] | 255 | XNTuple::SetSwapPath("/tmp/sop/") ; | 
|---|
|  | 256 | XNTuple nt3("xnt.ppf") ; | 
|---|
|  | 257 | nt3.Show() ; | 
|---|
|  | 258 |  | 
|---|
| [1326] | 259 | for(i = 0 ; i < nt3.NEntry() ; i+= 1000) | 
|---|
| [720] | 260 | printf("%f %f %d %s\n", | 
|---|
|  | 261 | nt3.GetDVal(i,0), | 
|---|
|  | 262 | nt3.GetFVal(i,1), | 
|---|
|  | 263 | nt3.GetIVal(i,2), | 
|---|
|  | 264 | nt3.GetSVal(i,3).c_str()) ; | 
|---|
|  | 265 |  | 
|---|
|  | 266 | double min, max ; | 
|---|
| [1326] | 267 | for(i = 0 ; i < nt3.NVar() ; i++) { | 
|---|
| [720] | 268 | nt3.GetMinMax(i, min, max) ; | 
|---|
|  | 269 | printf("GetMinMax(%s) : %f/%f\n", | 
|---|
|  | 270 | nt3.NomIndex(i).c_str(), min, max) ; | 
|---|
|  | 271 | } | 
|---|
|  | 272 | //    nt3.Show() ; | 
|---|
| [224] | 273 | } | 
|---|
|  | 274 |  | 
|---|