Changeset 3572 in Sophya for trunk/SophyaProg/Tests/tnt.cc


Ignore:
Timestamp:
Feb 7, 2009, 10:50:34 PM (17 years ago)
Author:
cmv
Message:

char* -> const char* pour regler les problemes de deprecated string const... + comparaison unsigned signed + suppression EVOL_PLANCK rz+cmv 07/02/2009

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaProg/Tests/tnt.cc

    r2852 r3572  
    99#include "dvlist.h"
    1010#include "ntuple.h"
    11 #include "xntuple.h"
    1211#include "datatable.h"
    1312#include "swppfdtable.h"
     
    1918void test_dvl();
    2019void test_ntuple();
    21 void test_xntuple() ;
    22 void test_Xntuple() ;
    2320void test_DataTable() ;
    2421void test_SwPPFDataTable() ;
     
    2825  SophyaInit();
    2926  if (narg < 2) {
    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;
     27    cout << " tnt/Erreur arg - Usage: tnt d/n/DT/SWDT \n"
     28         << " d:DVList n:NTuple DT,SWDT: SwPPF/DataTable test \n" << endl;
    3229    exit(0);
    3330  }
     
    3633    if (*arg[1] == 'd')  test_dvl();
    3734    else if (*arg[1] == 'n')  test_ntuple();
    38     else if (*arg[1] == 'x')  test_xntuple();
    39     else if (*arg[1] == 'X')  test_Xntuple();
    4035    else if (strcmp(arg[1],"DT") == 0)  test_DataTable();
    4136    else if (strcmp(arg[1],"SWDT") == 0)  test_SwPPFDataTable();
     
    5954void test_ntuple()
    6055{
    61   char * names[3] = {"XPos", "YPos", "Val"};
     56  const char * names[3] = {"XPos", "YPos", "Val"};
    6257  int i,j, k;
    6358  float xnt[3];
     
    424419
    425420
    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.