| [224] | 1 | #include <stdio.h> | 
|---|
|  | 2 | #include <stdlib.h> | 
|---|
|  | 3 | #include <math.h> | 
|---|
| [2322] | 4 | #include <iostream> | 
|---|
| [2832] | 5 | #include <fstream> | 
|---|
| [224] | 6 |  | 
|---|
| [2615] | 7 | #include "sopnamsp.h" | 
|---|
| [768] | 8 | #include "histinit.h" | 
|---|
| [720] | 9 | #include "dvlist.h" | 
|---|
| [224] | 10 | #include "ntuple.h" | 
|---|
| [720] | 11 | #include "xntuple.h" | 
|---|
| [2686] | 12 | #include "datatable.h" | 
|---|
| [2702] | 13 | #include "swppfdtable.h" | 
|---|
| [224] | 14 |  | 
|---|
| [2686] | 15 | /*  Programme test des classes  DVList, NTuple,, XNTuple          */ | 
|---|
|  | 16 | /*  DataTable et les handlers PPF                                 */ | 
|---|
|  | 17 | /*  SOPHYA - R. Ansari (LAL)  -   2000 -  2005                    */ | 
|---|
|  | 18 |  | 
|---|
| [720] | 19 | void test_dvl(); | 
|---|
|  | 20 | void test_ntuple(); | 
|---|
|  | 21 | void test_xntuple() ; | 
|---|
|  | 22 | void test_Xntuple() ; | 
|---|
| [2686] | 23 | void test_DataTable() ; | 
|---|
| [2702] | 24 | void test_SwPPFDataTable() ; | 
|---|
| [720] | 25 |  | 
|---|
|  | 26 | int main(int narg, char *arg[]) | 
|---|
| [224] | 27 | { | 
|---|
| [768] | 28 | SophyaInit(); | 
|---|
| [720] | 29 | if (narg < 2) { | 
|---|
| [2702] | 30 | cout << " tnt/Erreur arg - Usage: tnt d/n/x/X/DT/SWDT \n" | 
|---|
|  | 31 | << " d:DVList n:NTuple x/X:XNTuple DT,SWDT: SwPPF/DataTable test \n" << endl; | 
|---|
| [720] | 32 | exit(0); | 
|---|
|  | 33 | } | 
|---|
| [2832] | 34 | int rc = 0; | 
|---|
| [720] | 35 | try { | 
|---|
|  | 36 | if (*arg[1] == 'd')  test_dvl(); | 
|---|
|  | 37 | else if (*arg[1] == 'n')  test_ntuple(); | 
|---|
|  | 38 | else if (*arg[1] == 'x')  test_xntuple(); | 
|---|
|  | 39 | else if (*arg[1] == 'X')  test_Xntuple(); | 
|---|
| [2702] | 40 | else if (strcmp(arg[1],"DT") == 0)  test_DataTable(); | 
|---|
|  | 41 | else if (strcmp(arg[1],"SWDT") == 0)  test_SwPPFDataTable(); | 
|---|
| [720] | 42 | } | 
|---|
|  | 43 | catch(PThrowable exc ) { | 
|---|
|  | 44 | cerr << "tnt-main() , Catched exception: \n" << exc.Msg() << endl; | 
|---|
| [2832] | 45 | rc = 97; | 
|---|
| [720] | 46 | } | 
|---|
|  | 47 | catch(std::exception ex) { | 
|---|
|  | 48 | cerr << "tnt-main() , Catched exception ! " << (string)(ex.what()) << endl; | 
|---|
| [2832] | 49 | rc = 98; | 
|---|
| [720] | 50 | } | 
|---|
|  | 51 | catch(...) { | 
|---|
|  | 52 | cerr << "tnt-main() , Catched ... ! " << endl; | 
|---|
| [2832] | 53 | rc = 99; | 
|---|
| [720] | 54 | } | 
|---|
| [2832] | 55 | return rc; | 
|---|
| [720] | 56 | } | 
|---|
| [224] | 57 |  | 
|---|
| [720] | 58 | /*  ***** Test de NTuple simple ***** */ | 
|---|
|  | 59 | void test_ntuple() | 
|---|
|  | 60 | { | 
|---|
|  | 61 | char * names[3] = {"XPos", "YPos", "Val"}; | 
|---|
|  | 62 | int i,j, k; | 
|---|
|  | 63 | float xnt[3]; | 
|---|
| [224] | 64 |  | 
|---|
| [720] | 65 | cout << "======= test_ntuple:  Testing NTuple ======= " << endl; | 
|---|
| [224] | 66 |  | 
|---|
| [720] | 67 | cout << "Creation Ntuple avec X,Y,Val ... " << endl; | 
|---|
|  | 68 | NTuple  nt1(3, names, 20); | 
|---|
| [224] | 69 |  | 
|---|
| [720] | 70 | k = 0; | 
|---|
|  | 71 | for(j=0; j<8; j++) | 
|---|
|  | 72 | for(i=0; i<12; i++) | 
|---|
|  | 73 | { xnt[0] = i+0.5;  xnt[1] = j+0.5;  xnt[2] = k; | 
|---|
|  | 74 | nt1.Fill(xnt); k++; } | 
|---|
|  | 75 |  | 
|---|
| [1161] | 76 | nt1.Info().Comment() = "NTuple de Test - Cree par tnt.cc"; | 
|---|
|  | 77 | nt1.Info()["Version"] = SophyaVersion(); | 
|---|
| [720] | 78 | nt1.Show(cout); | 
|---|
|  | 79 | nt1.Print(0, 5); | 
|---|
|  | 80 | nt1.Print(18, 5); | 
|---|
|  | 81 | nt1.Print(94, 5); | 
|---|
|  | 82 |  | 
|---|
|  | 83 | string fn = "nt.ppf"; | 
|---|
|  | 84 | { | 
|---|
|  | 85 | cout << "Ecriture NTuple ds nt.ppf ... \n" << endl; | 
|---|
|  | 86 | ObjFileIO<NTuple> fio(&nt1); | 
|---|
|  | 87 | fio.Write(fn); | 
|---|
|  | 88 | } | 
|---|
|  | 89 |  | 
|---|
|  | 90 | { | 
|---|
|  | 91 | cout << "Lecture NTuple (nt2) ds nt.ppf ... \n" << endl; | 
|---|
| [2702] | 92 | PInPersist fsi(fn); | 
|---|
|  | 93 | NTuple nt2; | 
|---|
|  | 94 | fsi >> nt2; | 
|---|
|  | 95 | nt2.Show(cout); | 
|---|
|  | 96 | nt2.Print(0, 5); | 
|---|
|  | 97 | nt2.Print(18, 5); | 
|---|
|  | 98 | nt2.Print(94, 5); | 
|---|
| [720] | 99 | } | 
|---|
|  | 100 |  | 
|---|
|  | 101 |  | 
|---|
|  | 102 | } | 
|---|
|  | 103 |  | 
|---|
|  | 104 | /*  ***** Test de dvlist ***** */ | 
|---|
|  | 105 | void test_dvl() | 
|---|
| [583] | 106 | { | 
|---|
| [720] | 107 | DVList dvl; | 
|---|
|  | 108 |  | 
|---|
| [1161] | 109 | cout << "\n ======= test_dvl:  Testing MuTyV ======= " << endl; | 
|---|
|  | 110 | MuTyV zvs = " ( 1.41 -2.71) "; | 
|---|
|  | 111 | MuTyV dvs = "434.898"; | 
|---|
|  | 112 | MuTyV fvu = 314.1596; | 
|---|
|  | 113 | MuTyV ivu = 7654321; | 
|---|
|  | 114 | cout << " float->string: fvu= " << fvu << " (string)fvu=" << (string)fvu << endl; | 
|---|
|  | 115 | cout << " int->string: ivu= " << ivu << " (string)ivu=" << (string)ivu << endl; | 
|---|
| [1343] | 116 | complex<double> zzd = zvs; | 
|---|
| [1161] | 117 | cout << "String->complex<double>: zvs = " << zvs | 
|---|
| [1343] | 118 | << " (complex<double>)zvs= " << zzd << endl; | 
|---|
| [1161] | 119 | cout << "String->double: dvs = " << dvs | 
|---|
| [2828] | 120 | << " (double)dvs= " << (double)dvs << endl; | 
|---|
|  | 121 | TimeStamp ts; | 
|---|
|  | 122 | MuTyV tv = ts; | 
|---|
|  | 123 | cout << "MuTyV=TimeStamp->String: tv = " << tv | 
|---|
|  | 124 | << " ->double= " << (double)tv << " ->TimeStamp:" | 
|---|
|  | 125 | << TimeStamp((double)tv).ToString() << endl; | 
|---|
| [2832] | 126 | tv = "1995-09-23T15:20:32"; | 
|---|
|  | 127 | string tts = (string)tv; | 
|---|
|  | 128 | cout << "MuTyV=TimeStamp tv=" << tv << " ->TimeStamp(tv)=" | 
|---|
|  | 129 | << TimeStamp(tts) << endl; | 
|---|
| [1161] | 130 |  | 
|---|
|  | 131 | cout << "\n\n ======= test_dvl:  Testing DVList ======= " << endl; | 
|---|
| [720] | 132 | dvl.SetI("Var XXX", 12345); | 
|---|
|  | 133 | dvl.SetI("IV1-80", 80); | 
|---|
|  | 134 | dvl.SetI("IV2-330", 330); | 
|---|
|  | 135 |  | 
|---|
|  | 136 | dvl.SetD("DV1-0.2", 0.2); | 
|---|
|  | 137 | dvl.SetD("DV2-4.5", 4.5); | 
|---|
| [1082] | 138 | dvl.SetZ("ZV", complex<r_8>(2.0,-1.44)); | 
|---|
| [720] | 139 |  | 
|---|
|  | 140 | dvl.SetI("IVV3-783", 783); | 
|---|
|  | 141 | dvl("IVV3-783-O") =  7783; | 
|---|
|  | 142 | // dvl["Avec[]"] =  "operateur [] !"; | 
|---|
|  | 143 | dvl.SetD("DVV3", 3.141592652141592652); | 
|---|
|  | 144 | dvl.SetComment("DVV3", "Comment for DVV3, r_8 type variable"); | 
|---|
|  | 145 | dvl("DVV3avec()") =  44.555e-8; | 
|---|
|  | 146 |  | 
|---|
|  | 147 | dvl.SetS("Blanc_White", "123.456Ma premiere chaine"); | 
|---|
|  | 148 | dvl.SetI("IntegerValue", 55777); | 
|---|
|  | 149 | dvl.SetComment("IntegerValue", "This variable has a comment"); | 
|---|
|  | 150 | dvl.Comment() = "This is a test DVL produced by the program tdvl.cc \n Using SOPHYA , Feb 2000"; | 
|---|
| [1161] | 151 |  | 
|---|
|  | 152 | dvl["Sinf"] = "inf 0985"; | 
|---|
| [2828] | 153 | dvl["ToDay"] = ts; | 
|---|
| [720] | 154 | dvl.Print(); | 
|---|
|  | 155 |  | 
|---|
| [1161] | 156 |  | 
|---|
| [720] | 157 | double d = dvl("DV2-4.5"); | 
|---|
|  | 158 | float f = dvl("DVV3"); | 
|---|
|  | 159 | int i = dvl("IVV3-783"); | 
|---|
| [1082] | 160 | complex<r_8> z = dvl("ZV"); | 
|---|
| [720] | 161 |  | 
|---|
|  | 162 | printf("\n \n Essai1 (IVV3 DVV3 DV2= ) %d  %.20g  %g \n", i, f, (float)d); | 
|---|
| [1082] | 163 | printf("\n \n Essai ZV= (%.2g  %g I) \n", z.real(), z.imag()); | 
|---|
| [720] | 164 | cout << "Test Comment/IntegerValue: " << dvl.GetComment("IntegerValue") << endl; | 
|---|
|  | 165 | cout << "Test Comment/DVV3: " << dvl.GetComment("DVV3") << endl; | 
|---|
|  | 166 |  | 
|---|
|  | 167 | cout << "Test string recup  " << (string)(dvl["Blanc_White"]) << endl; | 
|---|
|  | 168 | cout << "Test string recup(int=80)  " << (string)(dvl["IV1-80"]) << endl; | 
|---|
|  | 169 | dvl("DVV3") = (double)3.141592652141592652; | 
|---|
|  | 170 | cout << "Test string recup(double=Pi..i)  " << (string)(dvl["DVV3"]) << endl; | 
|---|
|  | 171 |  | 
|---|
|  | 172 | { | 
|---|
|  | 173 | cout << " Writing DVList in file PPF dvl.ppf " << endl; | 
|---|
|  | 174 | POutPersist os("dvl.ppf"); | 
|---|
|  | 175 | os << dvl ; | 
|---|
|  | 176 | } | 
|---|
|  | 177 |  | 
|---|
|  | 178 | cout << "-------------------------- \n\n" | 
|---|
|  | 179 | << " reading DVList from file dvl.ppf ... \n" << endl; | 
|---|
|  | 180 |  | 
|---|
|  | 181 | DVList dvlr("dvl.ppf"); | 
|---|
|  | 182 | double df1 = (double)( dvlr["DVV3"] ); | 
|---|
|  | 183 | double df2 = (double)3.141592652141592652 - df1; | 
|---|
| [1082] | 184 | cout << " Test Precision : Pi-Pi= " << df2  << "DVV3= " << df1 << endl; | 
|---|
| [720] | 185 |  | 
|---|
|  | 186 | cout << dvlr; | 
|---|
|  | 187 |  | 
|---|
| [583] | 188 | } | 
|---|
| [2686] | 189 | void test_DataTable() | 
|---|
|  | 190 | { | 
|---|
|  | 191 | cout << "======= test_DataTable:  simple DataTable test ======= " << endl; | 
|---|
|  | 192 | DataTable dt(64); | 
|---|
|  | 193 | dt.AddIntegerColumn("line"); | 
|---|
| [2733] | 194 | dt.AddStringColumn("sline"); | 
|---|
| [2686] | 195 | dt.AddDoubleColumn("x"); | 
|---|
|  | 196 | dt.AddFloatColumn("f_sin"); | 
|---|
|  | 197 | dt.AddFloatColumn("f_cos"); | 
|---|
|  | 198 | dt.AddDoubleColumn("f_sinxcos"); | 
|---|
|  | 199 | dt.AddDoubleColumn("f_x2"); | 
|---|
| [2828] | 200 | dt.AddComplexColumn("cmplx_cos_sin"); | 
|---|
|  | 201 | dt.AddDoubleComplexColumn("dcmplx_cos_sin"); | 
|---|
| [2832] | 202 | dt.AddDateTimeColumn("datime"); | 
|---|
| [2686] | 203 | MuTyV rec[10]; | 
|---|
| [2832] | 204 | TimeStamp ts("01/3/2005","0:0:0"); | 
|---|
|  | 205 | TimeStamp ts2(0.); | 
|---|
|  | 206 |  | 
|---|
| [2686] | 207 | cout << " 1/ First 1000 lines .... " << endl; | 
|---|
|  | 208 | for(int k = 0; k<1000; k++) { | 
|---|
|  | 209 | rec[0] = k; | 
|---|
| [2733] | 210 | string sline = "L-"; | 
|---|
|  | 211 | sline += (string)rec[0]; | 
|---|
|  | 212 | rec[1] = sline; | 
|---|
| [2686] | 213 | double x = M_PI*k/100.; | 
|---|
|  | 214 | double fx = sin(x)*cos(x); | 
|---|
| [2828] | 215 | double sx = sin(x); | 
|---|
|  | 216 | double cx = cos(x); | 
|---|
| [2733] | 217 | rec[2] = x; | 
|---|
| [2828] | 218 | rec[3] = sx; | 
|---|
|  | 219 | rec[4] = cx; | 
|---|
| [2733] | 220 | rec[5] = fx; | 
|---|
|  | 221 | rec[6] = x*x; | 
|---|
| [2828] | 222 | rec[7] = complex<r_4>(cx, sx); | 
|---|
|  | 223 | rec[8] = complex<r_8>(cx, sx); | 
|---|
| [2832] | 224 | ts2.Set(ts.ToDays()+(double)k/24.); | 
|---|
|  | 225 | rec[9] = ts2; | 
|---|
| [2686] | 226 | dt.AddLine(rec); | 
|---|
|  | 227 | } | 
|---|
|  | 228 | cout << "1.b/ Use of = operator to make copy of dt " << endl; | 
|---|
|  | 229 | DataTable dtc1; | 
|---|
|  | 230 | dtc1 = dt; | 
|---|
| [224] | 231 |  | 
|---|
| [2686] | 232 | dt.Show(); | 
|---|
|  | 233 | cout << " 2/ Lines 1000-2000  .... " << endl; | 
|---|
|  | 234 | for(int k = 1000; k<2000; k++) { | 
|---|
|  | 235 | rec[0] = k; | 
|---|
| [2733] | 236 | string sline = "L-"; | 
|---|
|  | 237 | sline += (string)rec[0]; | 
|---|
|  | 238 | rec[1] = sline; | 
|---|
| [2686] | 239 | double x = M_PI*k/100.; | 
|---|
|  | 240 | double fx = sin(x)*cos(x); | 
|---|
| [2828] | 241 | double sx = sin(x); | 
|---|
|  | 242 | double cx = cos(x); | 
|---|
| [2733] | 243 | rec[2] = x; | 
|---|
| [2828] | 244 | rec[3] = sx; | 
|---|
|  | 245 | rec[4] = cx; | 
|---|
| [2733] | 246 | rec[5] = fx; | 
|---|
|  | 247 | rec[6] = x*x; | 
|---|
| [2828] | 248 | rec[7] = complex<r_4>(cx, sx); | 
|---|
|  | 249 | rec[8] = complex<r_8>(cx, sx); | 
|---|
| [2832] | 250 | ts2.Set(ts.ToDays()+(double)k/24.); | 
|---|
|  | 251 | rec[9] = ts2; | 
|---|
| [2686] | 252 | dt.AddLine(rec); | 
|---|
|  | 253 | } | 
|---|
|  | 254 | cout << "2.b/ dt.Show();  : " << endl; | 
|---|
|  | 255 | dt.Show(); | 
|---|
|  | 256 | cout << "2.c/ dtc1.Show();  : " << endl; | 
|---|
|  | 257 | dtc1.Show(); | 
|---|
|  | 258 | cout << "2.d/  dt.LineHeaderToString() dt.LineToString(k)   : " << endl; | 
|---|
| [2832] | 259 | cout << dt.LineHeaderToString() << endl; | 
|---|
| [2686] | 260 | for(int k = 0; k<1500; k+=75) | 
|---|
|  | 261 | cout << "Line[" << k << "] " << dt.LineToString(k) << endl ; | 
|---|
|  | 262 | { | 
|---|
|  | 263 | cout << "3/ Writing DataTable dt to PPF stream dtable.ppf " << endl; | 
|---|
|  | 264 | POutPersist po("dtable.ppf"); | 
|---|
|  | 265 | po << dt; | 
|---|
|  | 266 | } | 
|---|
|  | 267 | { | 
|---|
|  | 268 | cout << "4/ Reading DataTable dtr from PPF stream dtable.ppf " << endl; | 
|---|
|  | 269 | PInPersist pi("dtable.ppf"); | 
|---|
|  | 270 | DataTable dtr; | 
|---|
|  | 271 | pi >> dtr; | 
|---|
|  | 272 | cout << "4.b/ cout << dtr; " << endl; | 
|---|
|  | 273 | cout << dtr; | 
|---|
|  | 274 | cout << "4.c/  dtr.LineHeaderToString() dtr.LineToString(k)   : " << endl; | 
|---|
| [2832] | 275 | cout << dtr.LineHeaderToString() << endl; | 
|---|
| [2686] | 276 | for(int k = 0; k<1500; k+=75) | 
|---|
|  | 277 | cout << "Line[" << k << "] " << dtr.LineToString(k) << endl ; | 
|---|
|  | 278 |  | 
|---|
|  | 279 | } | 
|---|
| [2832] | 280 | { | 
|---|
|  | 281 | cout << "5/ Reading DataTable dtr from text file dtable.txt " << endl; | 
|---|
|  | 282 | { | 
|---|
|  | 283 | cout << "5.a Writing lines to file dtable.txt " << endl; | 
|---|
|  | 284 | ofstream os("dtable.txt"); | 
|---|
|  | 285 | dt.Print(os,0,450); | 
|---|
|  | 286 | } | 
|---|
|  | 287 | cout << "5.b CopyStructure + FillFromASCIIFile from dtable.txt " << endl; | 
|---|
|  | 288 | ifstream is("dtable.txt"); | 
|---|
|  | 289 | DataTable dtr; | 
|---|
|  | 290 | dtr.CopyStructure(dt); | 
|---|
|  | 291 | dtr.FillFromASCIIFile(is); | 
|---|
|  | 292 | cout << dtr; | 
|---|
|  | 293 | cout << "5.c/  dtr.LineHeaderToString() dtr.LineToString(k)   : " << endl; | 
|---|
|  | 294 | cout << dtr.LineHeaderToString() << endl; | 
|---|
|  | 295 | for(int k = 0; k<10; k++) | 
|---|
|  | 296 | cout << "Line[" << k << "] " << dtr.LineToString(k) << endl ; | 
|---|
|  | 297 | for(int k = 50; k<300; k+=25) | 
|---|
|  | 298 | cout << "Line[" << k << "] " << dtr.LineToString(k) << endl ; | 
|---|
|  | 299 |  | 
|---|
|  | 300 | } | 
|---|
| [2686] | 301 |  | 
|---|
|  | 302 | cout << "============ FIN  test_DataTable ============== " << endl; | 
|---|
|  | 303 | } | 
|---|
|  | 304 |  | 
|---|
| [2702] | 305 | void test_SwPPFDataTable() | 
|---|
|  | 306 | { | 
|---|
|  | 307 | cout << "======= test_SwPPFDataTable():  simple SwPPFDataTable test ======= " << endl; | 
|---|
|  | 308 | { | 
|---|
|  | 309 | POutPersist po("swdtable.ppf"); | 
|---|
|  | 310 | SwPPFDataTable dt(po, 64); | 
|---|
|  | 311 | dt.AddIntegerColumn("line"); | 
|---|
| [2832] | 312 | dt.AddStringColumn("sline"); | 
|---|
| [2702] | 313 | dt.AddDoubleColumn("x"); | 
|---|
|  | 314 | dt.AddFloatColumn("f_sin"); | 
|---|
|  | 315 | dt.AddFloatColumn("f_cos"); | 
|---|
|  | 316 | dt.AddDoubleColumn("f_sinxcos"); | 
|---|
|  | 317 | dt.AddDoubleColumn("f_x2"); | 
|---|
| [2828] | 318 | dt.AddComplexColumn("cmplx_cos_sin"); | 
|---|
|  | 319 | dt.AddDoubleComplexColumn("dcmplx_cos_sin"); | 
|---|
| [2832] | 320 | dt.AddDateTimeColumn("datime"); | 
|---|
| [2702] | 321 | MuTyV rec[10]; | 
|---|
| [2832] | 322 | TimeStamp ts("01/3/2005","0:0:0"); | 
|---|
|  | 323 | TimeStamp ts2(0.); | 
|---|
| [2702] | 324 | cout << " 1/ First 1000 lines .... " << endl; | 
|---|
|  | 325 | for(int k = 0; k<1000; k++) { | 
|---|
|  | 326 | rec[0] = k; | 
|---|
| [2832] | 327 | string sline = "L-"; | 
|---|
|  | 328 | sline += (string)rec[0]; | 
|---|
|  | 329 | rec[1] = sline; | 
|---|
| [2702] | 330 | double x = M_PI*k/100.; | 
|---|
|  | 331 | double fx = sin(x)*cos(x); | 
|---|
| [2828] | 332 | double sx = sin(x); | 
|---|
|  | 333 | double cx = cos(x); | 
|---|
| [2832] | 334 | rec[2] = x; | 
|---|
|  | 335 | rec[3] = sx; | 
|---|
|  | 336 | rec[4] = cx; | 
|---|
|  | 337 | rec[5] = fx; | 
|---|
|  | 338 | rec[6] = x*x; | 
|---|
|  | 339 | rec[7] = complex<r_4>(cx, sx); | 
|---|
|  | 340 | rec[8] = complex<r_8>(cx, sx); | 
|---|
|  | 341 | ts2.Set(ts.ToDays()+(double)k/24.); | 
|---|
|  | 342 | rec[9] = ts2; | 
|---|
| [2702] | 343 | dt.AddLine(rec); | 
|---|
|  | 344 | } | 
|---|
|  | 345 | cout << "1.b/ Use of = operator to make copy of dt " << endl; | 
|---|
|  | 346 | SwPPFDataTable dtc1; | 
|---|
|  | 347 | dtc1 = dt; | 
|---|
|  | 348 | dt.Show(); | 
|---|
|  | 349 | cout << " 2/ Lines 1000-2000  .... " << endl; | 
|---|
|  | 350 | for(int k = 1000; k<2000; k++) { | 
|---|
|  | 351 | rec[0] = k; | 
|---|
| [2832] | 352 | string sline = "L-"; | 
|---|
|  | 353 | sline += (string)rec[0]; | 
|---|
|  | 354 | rec[1] = sline; | 
|---|
| [2702] | 355 | double x = M_PI*k/100.; | 
|---|
|  | 356 | double fx = sin(x)*cos(x); | 
|---|
| [2832] | 357 | double sx = sin(x); | 
|---|
|  | 358 | double cx = cos(x); | 
|---|
|  | 359 | rec[2] = x; | 
|---|
|  | 360 | rec[3] = sx; | 
|---|
|  | 361 | rec[4] = cx; | 
|---|
|  | 362 | rec[5] = fx; | 
|---|
|  | 363 | rec[6] = x*x; | 
|---|
|  | 364 | rec[7] = complex<r_4>(cx, sx); | 
|---|
|  | 365 | rec[8] = complex<r_8>(cx, sx); | 
|---|
|  | 366 | ts2.Set(ts.ToDays()+(double)k/24.); | 
|---|
|  | 367 | rec[9] = ts2; | 
|---|
| [2702] | 368 | dt.AddLine(rec); | 
|---|
|  | 369 | } | 
|---|
|  | 370 | cout << "2.b/ dt.Show();  : " << endl; | 
|---|
|  | 371 | dt.Show(); | 
|---|
|  | 372 | cout << "2.c/ dtc1.Show();  : " << endl; | 
|---|
|  | 373 | dtc1.Show(); | 
|---|
|  | 374 | cout << "3/ Writing SwPPFDataTable dt to PPF stream swdtable.ppf " << endl; | 
|---|
|  | 375 | po << dt; | 
|---|
|  | 376 | } | 
|---|
|  | 377 | { | 
|---|
|  | 378 | cout << "4/ Reading SwPPFDataTable dtr from PPF stream swdtable.ppf " << endl; | 
|---|
|  | 379 | PInPersist pi("swdtable.ppf"); | 
|---|
|  | 380 | SwPPFDataTable dtr; | 
|---|
|  | 381 | pi >> dtr; | 
|---|
|  | 382 | cout << "4.b/ cout << dtr; " << endl; | 
|---|
|  | 383 | cout << dtr; | 
|---|
|  | 384 | cout << "4.c/  dtr.LineHeaderToString() dtr.LineToString(k)   : " << endl; | 
|---|
| [2832] | 385 | cout << dtr.LineHeaderToString() << endl; | 
|---|
| [2702] | 386 | for(int k = 0; k<1500; k+=75) | 
|---|
|  | 387 | cout << "Line[" << k << "] " << dtr.LineToString(k) << endl ; | 
|---|
|  | 388 | } | 
|---|
|  | 389 |  | 
|---|
|  | 390 | cout << "============ FIN  test_SwPPFDataTable() ======== ======= " << endl; | 
|---|
|  | 391 | } | 
|---|
|  | 392 |  | 
|---|
|  | 393 |  | 
|---|
|  | 394 |  | 
|---|
|  | 395 |  | 
|---|
| [720] | 396 | void test_Xntuple() | 
|---|
| [583] | 397 | { | 
|---|
| [720] | 398 | char* names[] = {"str1", "str2", "str3", "str4", "str5"} ; | 
|---|
|  | 399 | XNTuple nt(0, 0, 0, 5, names) ; | 
|---|
|  | 400 | char** ce = new char*[5] ; | 
|---|
| [1326] | 401 | int i; | 
|---|
|  | 402 | for(i = 0 ; i < 5 ; i++) | 
|---|
| [720] | 403 | ce[i] = new char[20] ; | 
|---|
| [224] | 404 |  | 
|---|
| [720] | 405 | cout << "======= test_Xtuple:  simple XNTuple test ======= " << endl; | 
|---|
|  | 406 |  | 
|---|
|  | 407 | strncpy(ce[1], "toto a une auto", 20) ; | 
|---|
|  | 408 | strncpy(ce[2], "titi a une iti", 20) ; | 
|---|
|  | 409 | strncpy(ce[3], "tutu a une utu", 20) ; | 
|---|
|  | 410 | strncpy(ce[4], "tata a une ata", 20) ; | 
|---|
| [1326] | 411 | for(i = 0 ; i < 100000 ; i++) { | 
|---|
| [720] | 412 | sprintf(ce[0], "%d", i) ; | 
|---|
|  | 413 | nt.Fill(NULL, NULL, NULL, ce) ; | 
|---|
|  | 414 | } | 
|---|
|  | 415 |  | 
|---|
|  | 416 | nt.Show() ; | 
|---|
|  | 417 | cout << nt.LineHeaderToString() ; | 
|---|
|  | 418 | cout << nt.LineToString(5027) << endl ; | 
|---|
|  | 419 |  | 
|---|
|  | 420 | char* names2[] = {"d0", "d1", "f0", "f1", "f2", "i0", "str0", "str1"} ; | 
|---|
|  | 421 | XNTuple nt2(2, 3, 1, 2, names2) ; | 
|---|
|  | 422 | double de[2] ; float fe[3] ; int ie ; | 
|---|
|  | 423 | char** ce2 = new char*[2] ; | 
|---|
| [1326] | 424 | for(i = 0 ; i < 2 ; i++) ce2[i] = new char[20] ; | 
|---|
| [720] | 425 | strncpy(ce2[1], "glop glop", 20) ; | 
|---|
|  | 426 |  | 
|---|
| [1326] | 427 | for(i = 0 ; i < 100000 ; i++) { | 
|---|
| [720] | 428 | de[0] = i ; | 
|---|
| [1406] | 429 | de[1] = sin((double)i) ; | 
|---|
| [720] | 430 | fe[0] = i ; | 
|---|
| [1406] | 431 | fe[1] = i * cos((double)i) ; | 
|---|
| [720] | 432 | fe[2] = 2*i ; | 
|---|
|  | 433 | ie    = -i; | 
|---|
|  | 434 | sprintf(ce[0], "%d", i) ; | 
|---|
|  | 435 | nt2.Fill(de, fe, &ie, ce) ; | 
|---|
|  | 436 | } | 
|---|
|  | 437 | nt2.Show() ; | 
|---|
|  | 438 | nt2.LineHeaderToString() ; | 
|---|
|  | 439 | //    nt2.LineToString(20) ; | 
|---|
| [583] | 440 | } | 
|---|
| [224] | 441 |  | 
|---|
|  | 442 |  | 
|---|
| [720] | 443 | void test_xntuple() | 
|---|
|  | 444 | { | 
|---|
|  | 445 | char* names[] = {"dblval", "floval", "intval", "strval"} ; | 
|---|
|  | 446 | XNTuple nt(1, 1, 1, 1, names) ; | 
|---|
|  | 447 | double de ; | 
|---|
|  | 448 | float  fe ; | 
|---|
|  | 449 | int    ie ; | 
|---|
|  | 450 | char*  ce = new char[22] ; | 
|---|
|  | 451 |  | 
|---|
|  | 452 |  | 
|---|
|  | 453 | cout << "======= test_Xtuple:  XNTuple test ======= " << endl; | 
|---|
| [1326] | 454 | int i; | 
|---|
|  | 455 | for(i = 0 ; i < nt.NVar() ; i++) | 
|---|
| [720] | 456 | printf(" +++ %s <--> %d \n", | 
|---|
|  | 457 | nt.NomIndex(i).c_str(), nt.IndexNom(nt.NomIndex(i).c_str())) ; | 
|---|
| [224] | 458 |  | 
|---|
| [1326] | 459 | for(i = 0 ; i < 100000 ; i++) { | 
|---|
| [720] | 460 | de = fe = ie = i ; | 
|---|
|  | 461 | sprintf(ce, "%d", i) ; | 
|---|
|  | 462 | nt.Fill(&de, &fe, &ie, &ce) ; | 
|---|
|  | 463 | } | 
|---|
|  | 464 | nt.Show() ; | 
|---|
|  | 465 | cout << nt.VarList_C("toto") ; | 
|---|
|  | 466 | cout << nt.LineHeaderToString() ; | 
|---|
|  | 467 | cout << nt.LineToString(20) << endl << endl ; | 
|---|
|  | 468 |  | 
|---|
|  | 469 |  | 
|---|
|  | 470 | XNTuple nt2 ; | 
|---|
|  | 471 | nt2.SwapPath() = "/tmp/sop/" ; | 
|---|
|  | 472 | nt2.Copy(nt) ; | 
|---|
|  | 473 | nt2.Show() ; | 
|---|
| [1326] | 474 | for(i = 0 ; i < 100000 ; i++) { | 
|---|
| [720] | 475 | de = fe = ie = i ; | 
|---|
|  | 476 | sprintf(ce, "%d", i) ; | 
|---|
|  | 477 | nt2.Fill(&de, &fe, &ie, &ce) ; | 
|---|
|  | 478 | } | 
|---|
|  | 479 | nt2.Show() ; | 
|---|
|  | 480 |  | 
|---|
|  | 481 | { | 
|---|
|  | 482 | POutPersist os("xnt.ppf"); | 
|---|
|  | 483 | os << nt2 ; | 
|---|
|  | 484 | } | 
|---|
| [224] | 485 |  | 
|---|
| [720] | 486 | XNTuple::SetSwapPath("/tmp/sop/") ; | 
|---|
|  | 487 | XNTuple nt3("xnt.ppf") ; | 
|---|
|  | 488 | nt3.Show() ; | 
|---|
|  | 489 |  | 
|---|
| [1326] | 490 | for(i = 0 ; i < nt3.NEntry() ; i+= 1000) | 
|---|
| [720] | 491 | printf("%f %f %d %s\n", | 
|---|
|  | 492 | nt3.GetDVal(i,0), | 
|---|
|  | 493 | nt3.GetFVal(i,1), | 
|---|
|  | 494 | nt3.GetIVal(i,2), | 
|---|
|  | 495 | nt3.GetSVal(i,3).c_str()) ; | 
|---|
|  | 496 |  | 
|---|
|  | 497 | double min, max ; | 
|---|
| [1326] | 498 | for(i = 0 ; i < nt3.NVar() ; i++) { | 
|---|
| [720] | 499 | nt3.GetMinMax(i, min, max) ; | 
|---|
|  | 500 | printf("GetMinMax(%s) : %f/%f\n", | 
|---|
|  | 501 | nt3.NomIndex(i).c_str(), min, max) ; | 
|---|
|  | 502 | } | 
|---|
|  | 503 | //    nt3.Show() ; | 
|---|
| [224] | 504 | } | 
|---|
|  | 505 |  | 
|---|