Changeset 3572 in Sophya for trunk/SophyaProg/Tests/tnt.cc
- Timestamp:
- Feb 7, 2009, 10:50:34 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaProg/Tests/tnt.cc
r2852 r3572 9 9 #include "dvlist.h" 10 10 #include "ntuple.h" 11 #include "xntuple.h"12 11 #include "datatable.h" 13 12 #include "swppfdtable.h" … … 19 18 void test_dvl(); 20 19 void test_ntuple(); 21 void test_xntuple() ;22 void test_Xntuple() ;23 20 void test_DataTable() ; 24 21 void test_SwPPFDataTable() ; … … 28 25 SophyaInit(); 29 26 if (narg < 2) { 30 cout << " tnt/Erreur arg - Usage: tnt d/n/ x/X/DT/SWDT \n"31 << " d:DVList n:NTuple x/X:XNTupleDT,SWDT: SwPPF/DataTable test \n" << endl;27 cout << " tnt/Erreur arg - Usage: tnt d/n/DT/SWDT \n" 28 << " d:DVList n:NTuple DT,SWDT: SwPPF/DataTable test \n" << endl; 32 29 exit(0); 33 30 } … … 36 33 if (*arg[1] == 'd') test_dvl(); 37 34 else if (*arg[1] == 'n') test_ntuple(); 38 else if (*arg[1] == 'x') test_xntuple();39 else if (*arg[1] == 'X') test_Xntuple();40 35 else if (strcmp(arg[1],"DT") == 0) test_DataTable(); 41 36 else if (strcmp(arg[1],"SWDT") == 0) test_SwPPFDataTable(); … … 59 54 void test_ntuple() 60 55 { 61 c har * names[3] = {"XPos", "YPos", "Val"};56 const char * names[3] = {"XPos", "YPos", "Val"}; 62 57 int i,j, k; 63 58 float xnt[3]; … … 424 419 425 420 426 void test_Xntuple()427 {428 char* names[] = {"str1", "str2", "str3", "str4", "str5"} ;429 XNTuple nt(0, 0, 0, 5, names) ;430 char** ce = new char*[5] ;431 int i;432 for(i = 0 ; i < 5 ; i++)433 ce[i] = new char[20] ;434 435 cout << "======= test_Xtuple: simple XNTuple test ======= " << endl;436 437 strncpy(ce[1], "toto a une auto", 20) ;438 strncpy(ce[2], "titi a une iti", 20) ;439 strncpy(ce[3], "tutu a une utu", 20) ;440 strncpy(ce[4], "tata a une ata", 20) ;441 for(i = 0 ; i < 100000 ; i++) {442 sprintf(ce[0], "%d", i) ;443 nt.Fill(NULL, NULL, NULL, ce) ;444 }445 446 nt.Show() ;447 cout << nt.LineHeaderToString() ;448 cout << nt.LineToString(5027) << endl ;449 450 char* names2[] = {"d0", "d1", "f0", "f1", "f2", "i0", "str0", "str1"} ;451 XNTuple nt2(2, 3, 1, 2, names2) ;452 double de[2] ; float fe[3] ; int ie ;453 char** ce2 = new char*[2] ;454 for(i = 0 ; i < 2 ; i++) ce2[i] = new char[20] ;455 strncpy(ce2[1], "glop glop", 20) ;456 457 for(i = 0 ; i < 100000 ; i++) {458 de[0] = i ;459 de[1] = sin((double)i) ;460 fe[0] = i ;461 fe[1] = i * cos((double)i) ;462 fe[2] = 2*i ;463 ie = -i;464 sprintf(ce[0], "%d", i) ;465 nt2.Fill(de, fe, &ie, ce) ;466 }467 nt2.Show() ;468 nt2.LineHeaderToString() ;469 // nt2.LineToString(20) ;470 }471 472 473 void test_xntuple()474 {475 char* names[] = {"dblval", "floval", "intval", "strval"} ;476 XNTuple nt(1, 1, 1, 1, names) ;477 double de ;478 float fe ;479 int ie ;480 char* ce = new char[22] ;481 482 483 cout << "======= test_Xtuple: XNTuple test ======= " << endl;484 int i;485 for(i = 0 ; i < nt.NVar() ; i++)486 printf(" +++ %s <--> %d \n",487 nt.NomIndex(i).c_str(), nt.IndexNom(nt.NomIndex(i).c_str())) ;488 489 for(i = 0 ; i < 100000 ; i++) {490 de = fe = ie = i ;491 sprintf(ce, "%d", i) ;492 nt.Fill(&de, &fe, &ie, &ce) ;493 }494 nt.Show() ;495 cout << nt.VarList_C("toto") ;496 cout << nt.LineHeaderToString() ;497 cout << nt.LineToString(20) << endl << endl ;498 499 500 XNTuple nt2 ;501 nt2.SwapPath() = "/tmp/sop/" ;502 nt2.Copy(nt) ;503 nt2.Show() ;504 for(i = 0 ; i < 100000 ; i++) {505 de = fe = ie = i ;506 sprintf(ce, "%d", i) ;507 nt2.Fill(&de, &fe, &ie, &ce) ;508 }509 nt2.Show() ;510 511 {512 POutPersist os("xnt.ppf");513 os << nt2 ;514 }515 516 XNTuple::SetSwapPath("/tmp/sop/") ;517 XNTuple nt3("xnt.ppf") ;518 nt3.Show() ;519 520 for(i = 0 ; i < nt3.NEntry() ; i+= 1000)521 printf("%f %f %d %s\n",522 nt3.GetDVal(i,0),523 nt3.GetFVal(i,1),524 nt3.GetIVal(i,2),525 nt3.GetSVal(i,3).c_str()) ;526 527 double min, max ;528 for(i = 0 ; i < nt3.NVar() ; i++) {529 nt3.GetMinMax(i, min, max) ;530 printf("GetMinMax(%s) : %f/%f\n",531 nt3.NomIndex(i).c_str(), min, max) ;532 }533 // nt3.Show() ;534 }535
Note:
See TracChangeset
for help on using the changeset viewer.