Changeset 12512


Ignore:
Timestamp:
06/22/12 15:38:56 (13 years ago)
Author:
Mathieu Morlighem
Message:

Starting to replace _printf by _pprintString

Location:
issm/trunk-jpl/src/c
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/include/macros.h

    r12507 r12512  
    5757   do{std::cout << StreamArgs;}while(0)
    5858/*}}}*/
     59/* _pprintLine_ {{{*/
     60/* macro to print a line, adds std::endl */
     61#define _pprintLine_(StreamArgs)\
     62  do{std::ostringstream aLoNgAnDwEiRdLoCaLnAmeFoRtHiSmAcRoOnLy; \
     63          aLoNgAnDwEiRdLoCaLnAmeFoRtHiSmAcRoOnLy << StreamArgs << std::ends; \
     64          PrintfFunction(aLoNgAnDwEiRdLoCaLnAmeFoRtHiSmAcRoOnLy.str());}while(0)
     65/*}}}*/
     66/* _pprintString_ {{{*/
     67/* macro to print some string, adds std::ends */
     68#define _pprintString_(StreamArgs)\
     69  do{std::ostringstream aLoNgAnDwEiRdLoCaLnAmeFoRtHiSmAcRoOnLy; \
     70          aLoNgAnDwEiRdLoCaLnAmeFoRtHiSmAcRoOnLy << StreamArgs << std::ends; \
     71          PrintfFunction(aLoNgAnDwEiRdLoCaLnAmeFoRtHiSmAcRoOnLy.str());}while(0)
     72/*}}}*/
    5973/* _assert_ {{{*/
    6074/*Assertion macro: do nothing if macro _ISSM_DEBUG_ undefined*/
  • issm/trunk-jpl/src/c/io/PrintfFunction.cpp

    r12511 r12512  
    2929                /* Try to print in the allocated space. */
    3030                va_start(args, format);
    31 #ifndef WIN32
    3231                n=vsnprintf(buffer,size,format,args);
    33 #else
    34                 n=vsnprintf(buffer,size,format,args);
    35 #endif
    3632                va_end(args);
    3733
     
    5551        return 1;
    5652}
     53int PrintfFunction(const string & message){
     54        extern int  my_rank;
     55        if(my_rank==0){
     56                printf("%s\n",message.c_str());
     57        }
     58}
  • issm/trunk-jpl/src/c/io/io.h

    r12377 r12512  
    1515/*printf: */
    1616int PrintfFunction(const char* format,...);
     17int PrintfFunction(const string & message);
    1718
    1819#endif  /* _IO_H_ */
  • issm/trunk-jpl/src/c/modules/Krigingx/pKrigingx.cpp

    r12493 r12512  
    5656                /*partition loop across threads: */
    5757                for(int idx=my_rank;idx<n_interp;idx+=num_procs){
    58                         _printf_(true,"\r      interpolation progress: %5.2lf%%",double(idx)/double(n_interp)*100);
     58                        _pprintString_("\r      interpolation progress: "<<setw(6)<<setprecision(2)<<double(idx)/double(n_interp)*100<<"%");
    5959                        observations->InterpolationKriging(&predictions[idx],&error[idx],x_interp[idx],y_interp[idx],radius,mindata,maxdata,variogram);
    6060                }
    61                 _printf_(true,"\r      interpolation progress: %5.2lf%%\n",100.);
     61                _pprintLine_("\r      interpolation progress: "<<fixed<<setw(6)<<setprecision(2)<<100.<<"%");
    6262
    6363#ifdef _HAVE_MPI_
     
    7474                /*partition loop across threads: */
    7575                for(int idx=my_rank;idx<n_interp;idx+=num_procs){
    76                         _printf_(true,"\r      interpolation progress: %5.2lf%%",double(idx)/double(n_interp)*100);
     76                        _pprintString_("\r      interpolation progress: "<<setw(6)<<setprecision(2)<<double(idx)/double(n_interp)*100<<"%");
    7777                        observations->InterpolationNearestNeighbor(&predictions[idx],x_interp[idx],y_interp[idx],radius);
    7878                }
    79                 _printf_(true,"\r      interpolation progress: %5.2lf%%\n",100.);
     79                _pprintLine_("\r      interpolation progress: "<<fixed<<setw(6)<<setprecision(2)<<100.<<"%");
    8080
    8181#ifdef _HAVE_MPI_
     
    9191                /*partition loop across threads: */
    9292                for(int idx=my_rank;idx<n_interp;idx+=num_procs){
    93                         _printf_(true,"\r      interpolation progress: %5.2lf%%",double(idx)/double(n_interp)*100);
     93                        _pprintString_("\r      interpolation progress: "<<setw(6)<<setprecision(2)<<double(idx)/double(n_interp)*100<<"%");
    9494                        observations->InterpolationIDW(&predictions[idx],x_interp[idx],y_interp[idx],radius,mindata,maxdata,power);
    9595                }
    96                 _printf_(true,"\r      interpolation progress: %5.2lf%%\n",100.);
     96                _pprintLine_("\r      interpolation progress: "<<fixed<<setw(6)<<setprecision(2)<<100.<<"%");
    9797
    9898#ifdef _HAVE_MPI_
  • issm/trunk-jpl/src/c/objects/KML/KML_LatLonBox.cpp

    r12493 r12512  
    4444void  KML_LatLonBox::Echo(){
    4545
    46         bool  flag=true;
    4746
    48         _printf_(flag,"KML_LatLonBox:\n");
     47        _printLine_("KML_LatLonBox:");
    4948        KML_Object::Echo();
    5049
    51         _printf_(flag,"         north: %0.16g\n"    ,north);
    52         _printf_(flag,"         south: %0.16g\n"    ,south);
    53         _printf_(flag,"          east: %0.16g\n"    ,east);
    54         _printf_(flag,"          west: %0.16g\n"    ,west);
    55         _printf_(flag,"      rotation: %0.16g\n"    ,rotation);
    56 
    57         return;
     50        _printLine_("         north: " << north);
     51        _printLine_("         south: " << south);
     52        _printLine_("          east: " << east);
     53        _printLine_("          west: " << west);
     54        _printLine_("      rotation: " << rotation);
    5855}
    5956/*}}}*/
    60 
    6157/*FUNCTION KML_LatLonBox::DeepEcho {{{*/
    6258void  KML_LatLonBox::DeepEcho(){
     
    6965}
    7066/*}}}*/
    71 
    7267/*FUNCTION KML_LatLonBox::DeepEcho {{{*/
    7368void  KML_LatLonBox::DeepEcho(const char* indent){
     
    7570        bool  flag=true;
    7671
    77         _printf_(flag,"%sKML_LatLonBox:\n",indent);
     72        _printLine_(indent << "KML_LatLonBox:");
    7873        KML_Object::DeepEcho(indent);
    7974
    80         _printf_(flag,"%s         north: %0.16g\n"    ,indent,north);
    81         _printf_(flag,"%s         south: %0.16g\n"    ,indent,south);
    82         _printf_(flag,"%s          east: %0.16g\n"    ,indent,east);
    83         _printf_(flag,"%s          west: %0.16g\n"    ,indent,west);
    84         _printf_(flag,"%s      rotation: %0.16g\n"    ,indent,rotation);
    85 
    86         return;
     75        _printLine_("         north: " << north);
     76        _printLine_("         south: " << south);
     77        _printLine_("          east: " << east);
     78        _printLine_("          west: " << west);
     79        _printLine_("      rotation: " << rotation);
    8780}
    8881/*}}}*/
    89 
    9082/*FUNCTION KML_LatLonBox::Write {{{*/
    9183void  KML_LatLonBox::Write(FILE* filout,const char* indent){
     
    109101}
    110102/*}}}*/
    111 
    112103/*FUNCTION KML_LatLonBox::Read {{{*/
    113104void  KML_LatLonBox::Read(FILE* fid,char* kstr){
     
    172163}
    173164/*}}}*/
    174 
  • issm/trunk-jpl/src/c/shared/Numerics/BrentSearch.cpp

    r12507 r12512  
    3131        IssmDouble x,x1,x2,xm;
    3232        IssmDouble tol1,tol2,seps;
    33         IssmDouble tolerance=1.e-4;
    34         int    maxiter,iter;
    35         bool   loop=true,goldenflag;
     33        IssmDouble tolerance = 1.e-4;
     34        int        maxiter ,iter;
     35        bool       loop= true,goldenflag;
    3636
    3737        /*Recover parameters:*/
     
    4545        fxmin = (*f)(xmin,optargs);
    4646        if (isnan(fxmin)) _error2_("Function evaluation returned NaN");
    47         _printf_(VerboseControl(),"\n        Iteration         x           f(x)       Tolerance         Procedure\n\n");
    48         _printf_(VerboseControl(),"        %s    %12.6g  %12.6g  %s","   N/A",xmin,fxmin,"         N/A         boundary\n");
     47        cout<<setprecision(5);
     48        if(VerboseControl()) _pprintLine_("");
     49        if(VerboseControl()) _pprintLine_("       Iteration         x           f(x)       Tolerance         Procedure");
     50        if(VerboseControl()) _pprintLine_("");
     51        if(VerboseControl()) _pprintLine_("           N/A    "<<setw(12)<<xmin<<"  "<<setw(12)<<fxmin<<"           N/A         boundary");
    4952        fxmax = (*f)(xmax,optargs);
    5053        if (isnan(fxmax)) _error2_("Function evaluation returned NaN");
    51         _printf_(VerboseControl(),"        %s    %12.6g  %12.6g  %s","   N/A",xmax,fxmax,"         N/A         boundary\n");
     54        if(VerboseControl()) _pprintLine_("           N/A    "<<setw(12)<<xmax<<"  "<<setw(12)<<fxmax<<"           N/A         boundary");
    5255
    5356        /*test if jump option activated and xmin==0*/
     
    8588
    8689        /*4: print result*/
    87         _printf_(VerboseControl(),"         %5i    %12.6g  %12.6g  %12.6g  %s\n",iter,xbest,fxbest,pow(pow(xbest-xm,2),0.5),"       initial");
     90        if(VerboseControl())
     91         _pprintLine_("         "<<setw(5)<<iter<<"    "<<setw(12)<<xbest<<"  "<<setw(12)<<fxbest<<"  "<<setw(12)<<pow(pow(xbest-xm,2),0.5)<<"         initial");
    8892        if (!isnan(cm_jump) && (xmin==0) && ((fxbest/fxmin)<cm_jump)){
    8993                _printf_(VerboseControl(),"      optimization terminated: current x satisfies criteria 'cm_jump'=%g\n",cm_jump);
     
    180184                tol1=seps*pow(pow(xbest,2),0.5)+tolerance/3.0;
    181185                tol2=2.0*tol1;
    182                 _printf_(VerboseControl(),"         %5i    %12.6g  %12.6g  %12.6g  %s\n",iter,x,fx,pow(pow(xbest-xm,2),0.5),goldenflag?"       golden":"       parabolic");
     186                if(VerboseControl())
     187                 _pprintLine_("         "<<setw(5)<<iter<<"    "<<setw(12)<<x<<"  "<<setw(12)<<fx<<"  "<<setw(12)<<pow(pow(xbest-xm,2),0.5)<<
     188                                         "         "<<(goldenflag?"golden":"parabolic"));
    183189
    184190                /*Stop the optimization?*/
  • issm/trunk-jpl/src/c/solutions/issm.cpp

    r12493 r12512  
    154154        #ifdef _HAVE_MPI_
    155155        MPI_Barrier(MPI_COMM_WORLD); finish = MPI_Wtime( );
    156         _printf_(true,"\n   %-34s %f seconds  \n","FemModel initialization elapsed time:",finish_init-start_init);
    157         _printf_(true,"   %-34s %f seconds  \n","Core solution elapsed time:",finish_core-start_core);
    158         _printf_(true,"\n   %s %i hrs %i min %i sec\n\n","Total elapsed time:",int((finish-start)/3600),int(int(finish-start)%3600/60),int(finish-start)%60);
     156        _pprintLine_("");
     157        _pprintLine_("   "<<setw(40)<<left<<"FemModel initialization elapsed time:"<<finish_init-start_init);
     158        _pprintLine_("   "<<setw(40)<<left<<"Core solution elapsed time:"<<finish_core-start_core);
     159        _pprintLine_("");
     160        _pprintLine_("   Total elapsed time:"<<int((finish-start)/3600)<<" hrs "<<int(int(finish-start)%3600/60)<<" min "<<int(finish-start)%60<<" sec");
     161        _pprintLine_("");
    159162        #else
    160163        finish=(IssmPDouble)clock();
    161         _printf_(true,"\n   %-34s %f seconds  \n","FemModel initialization elapsed time:",(finish_init-start_init)/CLOCKS_PER_SEC);
    162         _printf_(true,"   %-34s %f seconds  \n","Core solution elapsed time:",(finish_core-start_core)/CLOCKS_PER_SEC);
    163         _printf_(true,"\n   %s %i hrs %i min %i sec\n\n","Total elapsed time:",int((finish-start)/3600/CLOCKS_PER_SEC),int(int((finish-start)/CLOCKS_PER_SEC)%3600/60),(int(finish-start)/CLOCKS_PER_SEC)%60);
     164        _pprintLine_("");
     165        _pprintLine_("   "<<setw(40)<<left<<"FemModel initialization elapsed time:"<<(finish_init-start_init)/CLOCKS_PER_SEC);
     166        _pprintLine_("   "<<setw(40)<<left<<"Core solution elapsed time:"<<(finish_core-start_core)/CLOCKS_PER_SEC);
     167        _pprintLine_("");
     168        _pprintLine_("   Total elapsed time:"
     169                                <<int((finish-start)/CLOCKS_PER_SEC/3600)<<" hrs "
     170                                <<int(int(finish-start)/CLOCKS_PER_SEC%3600/60)<<" min "
     171                                <<int(finish-start)/CLOCKS_PER_SEC%60<<" sec");
     172        _pprintLine_("");
    164173        #endif
    165        
    166                
    167174       
    168175        #ifdef _HAVE_PETSC_
Note: See TracChangeset for help on using the changeset viewer.