vtf-logo

WENOStatistics.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) California Institute of Technology
00004 // Carlos Pantano
00005 
00006 #ifndef AMROC_WENOSTATISTICS_H
00007 #define AMROC_WENOSTATISTICS_H
00008 
00016 #include <iostream>
00017 #include <fstream>
00018 #include <string>
00019 #include <stdlib.h>
00020 #include "DAGH.h"
00021 #include "AMRBase.h"
00022 #include "Interpolation.h"
00023 
00024 #include "StatParser/StatParser.h"
00025 
00026 //#define DEBUG_PRINT_STATISTICS
00027 
00028 template <class VectorType, class InterpolationType, class OutputType, int dim>
00029 class WENOStatistics : public AMRBase<VectorType,dim>, 
00030                        private StatParser<typename InterpolationType::point_type,
00031                                           typename VectorType::InternalDataType,dim> {
00032   typedef AMRBase<VectorType,dim> base;
00033   typedef typename VectorType::InternalDataType DataType;
00034   typedef typename InterpolationType::point_type point_type;
00035   typedef StatParser<point_type,DataType,dim> stparser;
00036   typedef typename stparser::symrec symrec;
00037 
00038   // bring members from templated base class into scope
00039   using StatParser<point_type,DataType,dim>::group_table;
00040   using StatParser<point_type,DataType,dim>::putsym;
00041   using StatParser<point_type,DataType,dim>::unlinksym;
00042   using StatParser<point_type,DataType,dim>::vectorize;
00043   using StatParser<point_type,DataType,dim>::buildcoords;
00044   using StatParser<point_type,DataType,dim>::clearcoords;
00045 
00046 public:
00047   typedef typename base::vec_grid_fct_type vec_grid_fct_type;  
00048   typedef GridFunction<DataType,dim> grid_fct_type;
00049 
00050 public:
00051   WENOStatistics(InterpolationType *int_ref, OutputType* out_ref) : base() {
00052     _Step = 1;
00053     _FileOutput = out_ref;
00054     _Interpolation = int_ref;
00055     _OutputFile = "stats";
00056     _DumpMeshes = 0;
00057   }
00058 
00059   void Setup(GridHierarchy *gh, const int& ghosts, int* shape, double* geom) {
00060     base::SetupData(gh, ghosts);
00061 
00062     int MaxLev;
00063     int nx, ny, nz;
00064     char s[36];
00065 
00066     MaxLev = MaxLevel(base::GH());
00067 
00068     nx = shape[0];
00069     putsym(TOK_INTEGER, STAT_NX)->vdata.ivalue = nx;
00070     // add level dependent point number
00071     sprintf(s, "%s(%d)", STAT_NX, 1);
00072     putsym(TOK_INTEGER, s)->vdata.ivalue = nx;
00073     for ( int i = 0; i < MaxLev-1 ; i++ ) {
00074         sprintf(s, "%s(%d)", STAT_NX, i+2);
00075         nx *= RefineFactor(base::GH(),i);
00076         putsym(TOK_INTEGER, s)->vdata.ivalue = nx;
00077     }
00078     putsym(TOK_INTEGER, STAT_NXF)->vdata.ivalue = nx;
00079     putsym(TOK_DOUBLE, STAT_XMIN)->vdata.dvalue = geom[0];
00080     putsym(TOK_DOUBLE, STAT_XMAX)->vdata.dvalue = geom[1];
00081 
00082     if ( dim > 1 ) {
00083         ny = shape[1];
00084         putsym(TOK_INTEGER, STAT_NY)->vdata.ivalue = ny;
00085         // add level dependent point number
00086         sprintf(s, "%s(%d)", STAT_NY, 1);
00087         putsym(TOK_INTEGER, s)->vdata.ivalue = ny;
00088         for ( int i = 0; i < MaxLev-1 ; i++ ) {
00089             sprintf(s, "%s(%d)", STAT_NY, i+2);
00090             ny *= RefineFactor(base::GH(),i);;
00091             putsym(TOK_INTEGER, s)->vdata.ivalue = ny;
00092         }
00093         putsym(TOK_INTEGER, STAT_NYF)->vdata.ivalue = ny;
00094         putsym(TOK_DOUBLE, STAT_YMIN)->vdata.dvalue = geom[2];
00095         putsym(TOK_DOUBLE, STAT_YMAX)->vdata.dvalue = geom[3];
00096     }
00097 
00098     if ( dim > 2 ) {
00099         nz = shape[2];
00100         putsym(TOK_INTEGER, STAT_NZ)->vdata.ivalue = nz;
00101         // add level dependent point number
00102         sprintf(s, "%s(%d)", STAT_NZ, 1);
00103         putsym(TOK_INTEGER, s)->vdata.ivalue = nz;
00104         for ( int i = 0; i < MaxLev-1 ; i++ ) {
00105             sprintf(s, "%s(%d)", STAT_NZ, i+2);
00106             nz *= RefineFactor(base::GH(),i);;
00107             putsym(TOK_INTEGER, s)->vdata.ivalue = nz;
00108         }
00109         putsym(TOK_INTEGER, STAT_NZF)->vdata.ivalue = nz;
00110         putsym(TOK_DOUBLE, STAT_ZMIN)->vdata.dvalue = geom[4];
00111         putsym(TOK_DOUBLE, STAT_ZMAX)->vdata.dvalue = geom[5];
00112     }
00113 
00114     /* simulation variables (dimension dependent) */
00115     // by convention I take positive iptr's as conservative
00116     // variables and negative iptr's as primitive variables.
00117     symrec *ptr;
00118 
00119     putsym(TOK_VARIABLE, "rho")->vdata.iptr = 1;
00120     putsym(TOK_VARIABLE, "r")->vdata.iptr = 1;
00121     (ptr = putsym(TOK_VARIABLE, "u"))->vdata.iptr = 2; ptr->src = STAT_DERIVED;
00122     if ( dim > 1 ) {
00123       (ptr = putsym(TOK_VARIABLE, "v"))->vdata.iptr = 3; ptr->src = STAT_DERIVED;
00124     }
00125     if ( dim > 2 ) {
00126       (ptr = putsym(TOK_VARIABLE, "w"))->vdata.iptr = 4; ptr->src = STAT_DERIVED;
00127     }
00128     putsym(TOK_VARIABLE, "E")->vdata.iptr = 5;
00129     for ( int i = 0; i < NVARS - 5 ; i++ ) {
00130       char name[12];
00131       sprintf(name, "Y%d", i+1);
00132       (ptr = putsym(TOK_VARIABLE, name))->vdata.iptr = 
00133         ((dim == 1 ? 7 : (dim == 2 ? 8 : 9))+i); ptr->src = STAT_DERIVED;
00134     }
00135     if ( dim == 3 ) {
00136       (ptr = putsym(TOK_VARIABLE, "sgske"))->vdata.iptr = (NVARS+5); ptr->src = STAT_DERIVED;
00137     }
00138     putsym(TOK_VARIABLE, "T")->vdata.iptr = NVARS+1;
00139     (ptr = putsym(TOK_VARIABLE, "p"))->vdata.iptr = 
00140       (dim == 1 ? 5 : (dim == 2 ? 6 : 7)); ptr->src = STAT_DERIVED;
00141     (ptr = putsym(TOK_VARIABLE, "gamma"))->vdata.iptr = 
00142       (dim == 1 ? 6 : (dim == 2 ? 7 : 8)); ptr->src = STAT_DERIVED;
00143     putsym(TOK_VARINARRAY, "q")->vdata.iptr = 0;
00144     (ptr = putsym(TOK_VARINARRAY, "qout"))->vdata.iptr = 0; ptr->src = STAT_DERIVED;
00145 
00146     // Process the rack definition file
00147     if ( _DefFile.length() ) { 
00148       stparser::parse(_DefFile.c_str());
00149       // if any group did not specify step sampling rate, then set it to default common value
00150       for ( typename stparser::grpvec::const_iterator g = group_table.begin() ; 
00151             g != group_table.end(); g++) 
00152         if ( (*g)->step == 0 ) (*g)->step = _Step;
00153       
00154       // write probe information: coordinates
00155       int me = MY_PROC; 
00156       if (me == VizServer) {
00157         if ( _DumpMeshes ) {
00158           int ig = 1;
00159           for ( typename stparser::grpvec::const_iterator g = group_table.begin() ; 
00160                 g != group_table.end(); g++, ig++) {
00161             // for each probe
00162             int ip = 1;
00163             for ( typename stparser::provec::const_iterator p = (*g)->probe_table.begin() ;
00164                   p != (*g)->probe_table.end() ; p ++, ip++ )
00165               {
00166                 if ( buildcoords(*p) != RETURN_OK ) return;
00167                 
00168                 int i, j;
00169                 FILE * fp; 
00170                 char name[128];
00171                 
00172                 sprintf(name, "group%d-probe%d.dat", ig, ip);
00173                 fp = fopen(name, "w");
00174                 if ( (*p)->type == TOK_THREAD ) {
00175                   for ( i = 0 ; i < (*p)->options.thread.na ; i++ ) {
00176                     fprintf(fp, "%12.8lf %12.8lf %12.8lf\n", (*p)->coords[i](0), 
00177                             (*p)->coords[i](1), 
00178                             (*p)->coords[i](2));
00179                   } 
00180                 } else {
00181                   int na, nb;
00182                   if ( (*p)->type == TOK_SURFACE ) {
00183                     na = (*p)->options.surface.na;
00184                     nb = (*p)->options.surface.nb;
00185                   } else if ((*p)->type == TOK_PLANES ) {
00186                     na = (*p)->options.plane.na;
00187                     nb = (*p)->options.plane.nb;
00188                   }
00189                   fprintf(fp, "VARIABLES = \"X\", \"Y\", \"Z\"\n");
00190                   fprintf(fp, "ZONE I=%d, J=%d, F=POINT\n", na, nb);
00191                   for ( j = 0 ; j < nb ; j++ )
00192                     for ( i = 0 ; i < na ; i++ ) {
00193                       int l = i+j*na;
00194                       fprintf(fp, "%12.8lf %12.8lf %12.8lf\n", (*p)->coords[l](0),
00195                               (*p)->coords[l](1), (*p)->coords[l](2));
00196                     }
00197                 }
00198                 fclose(fp);
00199                 
00200                 clearcoords(*p);
00201               }
00202           }
00203         }
00204       }
00205     }
00206   }
00207 
00208   virtual void register_at(ControlDevice& Ctrl) { register_at(Ctrl, ""); }
00209   virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00210     LocCtrl = Ctrl.getSubDevice(prefix+"Statistics");
00211     
00212     RegisterAt(LocCtrl,"DefinitionFile",_DefFile);
00213     RegisterAt(LocCtrl,"OutputFile",_OutputFile);
00214     RegisterAt(LocCtrl,"Step",_Step);
00215     RegisterAt(LocCtrl,"WriteMeshes", _DumpMeshes);
00216   }
00217 
00218   ~WENOStatistics() {
00219     _FileOutput = NULL;
00220     _Interpolation = NULL;
00221   }
00222 
00223  public:
00224 
00225   void Evaluate(double * t, vec_grid_fct_type& U, grid_fct_type& Work)
00226     {
00227       int me ; 
00228       int Npoints;
00229       
00230       std::ofstream outfile;
00231       std::ostream* out;
00232 
00233       if ( group_table.size() == 0 ) return;
00234 
00235       //int TimeC = CurrentTime(base::GH(),0);
00236       int TimeC = StepsTaken(base::GH(),0);
00237 
00238       // check step sampling rate
00239       int gcheck = 0;
00240       for ( typename stparser::grpvec::const_iterator g = group_table.begin() ; 
00241             g != group_table.end(); g++) {
00242         if ( TimeC%((*g)->step) == 0 ) {
00243           gcheck = 1;
00244           break;
00245         }
00246       }
00247 
00248       //if ( TimeC%_Step != 0 ) return;
00249       if ( gcheck == 0 ) return;
00250 
00251       me = MY_PROC; 
00252 
00253       // open output file
00254       if (me == VizServer) {
00255         char fname[256];
00256         int time = CurrentTime(base::GH(), 0);
00257         std::sprintf(fname,"%s%d.dat",_OutputFile.c_str(),time);
00258         outfile.open(fname, std::ios::out );
00259         out = new std::ostream(outfile.rdbuf());
00260         // write time header
00261         *out << "# time " << t[0] << std::endl;
00262       }
00263       
00264       // for each group
00265       int ig = 1, iptr;
00266       for ( typename stparser::grpvec::const_iterator g = group_table.begin() ; 
00267             g != group_table.end(); g++, ig++ ) {
00268 
00269         if ( TimeC%((*g)->step) == 0 ) { 
00270 
00271         if (me == VizServer) 
00272           *out << "# group " << ig << std::endl;
00273         // for each probe
00274         int ip = 1;
00275         for ( typename stparser::provec::const_iterator p = (*g)->probe_table.begin() ; 
00276               p != (*g)->probe_table.end() ; p ++, ip++ )
00277           {
00278             if ( buildcoords(*p) != RETURN_OK ) return;
00279             
00280             // write probe type
00281             if (me == VizServer) 
00282               *out << "# probe " << token((*p)->type) << " " << ip << std::endl;
00283             
00284             // compute derived information
00285             switch ( (*p)->type ) {
00286             case TOK_THREAD:
00287               Npoints = (*p)->options.thread.na;
00288               break;
00289             case TOK_SURFACE:
00290               Npoints = (*p)->options.surface.na*(*p)->options.surface.nb;
00291               break;
00292             case TOK_PLANES:
00293               Npoints = (*p)->options.plane.na*(*p)->options.plane.nb;
00294               break;
00295             case TOK_VOLUME:
00296               /* not implemented yet */
00297               break;
00298             }
00299             
00300             symrec *ptr, *ptr_ref;
00301   
00302             /* first, make a copy of the stack */
00303             ptr = clonestack((*g)->sym_table);
00304   
00305             /* traverse the stack and evaluate */
00306             while ( ptr ) {
00307 #ifdef DEBUG_PRINT_STATISTICS
00308                 (comm_service::log() << token(ptr->type) << "\n").flush();
00309 #endif
00310               // vectorize the data array that will be used for the result
00311               vectorize(ptr, Npoints);
00312               // the arguments of the operator do not need to be vectorized
00313               // for all processors since they are not used. Only VizServer
00314               // performs operations with them.
00315               
00316               switch( ptr->type ) {
00317               case TOK_OP_PLUS:
00318                   if (me == VizServer) {
00319                       vectorize(ptr->prev, Npoints);
00320                       vectorize(ptr->prev->prev, Npoints);
00321                       for ( int l = 0 ; l < Npoints ; l++ )
00322                           ptr->pdata[l] = ptr->prev->prev->pdata[l] + ptr->prev->pdata[l];
00323                   }
00324                   unlinksym(ptr->prev->prev);
00325                   unlinksym(ptr->prev);
00326                 break;
00327               case TOK_OP_MINUS:
00328                 if (me == VizServer) {
00329                     vectorize(ptr->prev, Npoints);
00330                     vectorize(ptr->prev->prev, Npoints);
00331                     for ( int l = 0 ; l < Npoints ; l++ )
00332                         ptr->pdata[l] = ptr->prev->prev->pdata[l] - ptr->prev->pdata[l];
00333                 }
00334                 unlinksym(ptr->prev->prev);
00335                 unlinksym(ptr->prev);
00336                 break;
00337               case TOK_OP_PROD:
00338                 if (me == VizServer) {
00339                     vectorize(ptr->prev, Npoints);
00340                     vectorize(ptr->prev->prev, Npoints);
00341                     for ( int l = 0 ; l < Npoints ; l++ )
00342                         ptr->pdata[l] = ptr->prev->prev->pdata[l] * ptr->prev->pdata[l];
00343                 }
00344                 unlinksym(ptr->prev->prev);
00345                 unlinksym(ptr->prev);
00346                 break;
00347               case TOK_OP_DIV:
00348                 if (me == VizServer) {
00349                     vectorize(ptr->prev, Npoints);
00350                     vectorize(ptr->prev->prev, Npoints);
00351                     for ( int l = 0 ; l < Npoints ; l++ )
00352                         ptr->pdata[l] = ptr->prev->prev->pdata[l] / ptr->prev->pdata[l];
00353                 }
00354                 unlinksym(ptr->prev->prev);
00355                 unlinksym(ptr->prev);
00356                 break;
00357               case TOK_OP_NEG:
00358                 if (me == VizServer) {
00359                     vectorize(ptr->prev, Npoints);
00360                     for ( int l = 0 ; l < Npoints ; l++ )
00361                         ptr->pdata[l] = - ptr->prev->pdata[l];
00362                 }
00363                 unlinksym(ptr->prev);
00364                 break;
00365               case TOK_OP_POWER:
00366                 if (me == VizServer) {
00367                     vectorize(ptr->prev, Npoints);
00368                     vectorize(ptr->prev->prev, Npoints);
00369                     for ( int l = 0 ; l < Npoints ; l++ )
00370                         ptr->pdata[l] = pow(ptr->prev->prev->pdata[l], ptr->prev->pdata[l]);
00371                 }
00372                 unlinksym(ptr->prev->prev);
00373                 unlinksym(ptr->prev);
00374                 break;
00375               case TOK_POINTER:
00376                 ptr_ref = ptr->ref;
00377                 switch(ptr_ref->type) {
00378                 case TOK_FUNCTION1:
00379                   if (me == VizServer) {
00380                       vectorize(ptr->prev, Npoints);
00381                       for ( int l = 0 ; l < Npoints ; l++ )
00382                           ptr->pdata[l] = ((func_t1)ptr_ref->vdata.ptr)(ptr->prev->pdata[l]);
00383                   }
00384                   unlinksym(ptr->prev);
00385                   break;
00386                 case TOK_FUNCTION2:
00387                   if (me == VizServer) {
00388                       vectorize(ptr->prev, Npoints);
00389                       vectorize(ptr->prev->prev, Npoints);
00390                       for ( int l = 0 ; l < Npoints ; l++ )
00391                           ptr->pdata[l] = ((func_t2)ptr_ref->vdata.ptr)(ptr->prev->prev->pdata[l], 
00392                                                                         ptr->prev->pdata[l]);
00393                   }
00394                   unlinksym(ptr->prev->prev);
00395                   unlinksym(ptr->prev);
00396                   break;
00397                 case TOK_VARINARRAY:
00398                 case TOK_VARIABLE:
00399                   
00400                     // for variables in one of the AMR arrays, the pointer is located in the
00401                     // current token, not the defered one (ref). For variables in regular
00402                     // variables, the pointer is stored in the pointed variable.
00403                   if ( ptr_ref->type == TOK_VARINARRAY ) 
00404                     iptr = ptr->vdata.iptr;
00405                   else 
00406                     iptr = ptr_ref->vdata.iptr;
00407                   
00408                   // process the variables here
00409                   if ( ptr_ref->src == STAT_DERIVED ) {
00410                     // output variable type case
00411                     for (register int l=0; l<=FineLevel(base::GH()); l++) {
00412                       int Time = CurrentTime(base::GH(),l);
00413                       // if derived variable (call Transform)
00414                       _FileOutput->Transform(U, Work, Time, l, iptr, t[l]);
00415                     }
00416 #ifdef DEBUG_PRINT_STATISTICS
00417                     (comm_service::log() << " convert output\n" ).flush();
00418 #endif
00419                   } else {
00420                     int _dim = dim;
00421                     // conservative vector of state variable case
00422                     if ( _dim == 2 ) { 
00423                       for ( int Level = FineLevel(base::GH()) ; Level >= 0 ; Level --) {
00424                         int Time = CurrentTime(base::GH(),Level);
00425                         forall (U,Time,Level,c)
00426                           Coords ss(U(Time,Level,c).bbox().stepsize());
00427                           BBox bbi(U.boundingbbox(Time,Level,c));
00428                           BeginFastIndex2(U, U(Time,Level,c).bbox(), 
00429                                           U(Time,Level,c).data(), VectorType);
00430                           BeginFastIndex2(Work, Work(Time,Level,c).bbox(), 
00431                                           Work(Time,Level,c).data(), DataType);
00432                           for_2 (i, j, bbi, ss)
00433                             FastIndex2(Work,i,j) = FastIndex2(U,i,j)(iptr-1);
00434                           end_for
00435                           EndFastIndex2(U);
00436                           EndFastIndex2(Work);
00437                         end_forall
00438                         } 
00439                     } else if ( _dim == 3 ) {
00440                       for ( int Level = FineLevel(base::GH()) ; Level >= 0 ; Level --) {
00441                         int Time = CurrentTime(base::GH(),Level);
00442                         forall (U,Time,Level,c)
00443                           Coords ss(U(Time,Level,c).bbox().stepsize());
00444                           BBox bbi(U.boundingbbox(Time,Level,c));
00445                           BeginFastIndex3(U, U(Time,Level,c).bbox(),  
00446                                           U(Time,Level,c).data(), VectorType); 
00447                           BeginFastIndex3(Work, Work(Time,Level,c).bbox(), 
00448                                           Work(Time,Level,c).data(), DataType);
00449                           for_3 (i, j, k, bbi, ss)
00450                             FastIndex3(Work,i,j,k) = FastIndex3(U,i,j,k)(iptr-1);
00451                           end_for
00452                           EndFastIndex3(U);
00453                           EndFastIndex3(Work); 
00454                           end_forall
00455                       } 
00456                     }
00457 #ifdef DEBUG_PRINT_STATISTICS
00458                     (comm_service::log() << " convert array\n" ).flush();
00459 #endif
00460                   }
00461                   // note that we use data so the pointer token will be converted.
00462                   _Interpolation->PointsValues(Work,t[0],Npoints,(*p)->coords,ptr->pdata);
00463 #ifdef DEBUG_PRINT_STATISTICS
00464                   (comm_service::log() << "before (" << iptr << ") ..." ).flush();
00465 #endif
00466                   _Interpolation->ArrayCombine(VizServer,Npoints,ptr->pdata);
00467 #ifdef DEBUG_PRINT_STATISTICS
00468                   (comm_service::log() << "after\n" ).flush();
00469 #endif
00470 #ifndef DAGH_NO_MPI
00471                   MPI_Barrier(comm_service::comm()); 
00472 #endif
00473                   break;
00474                 case TOK_COORDINATE:
00475                   if (me == VizServer) {
00476                     int iptr = (ptr_ref->vdata.iptr)-1;
00477                     if ( iptr >= dim ) {
00478                       staterror("invalid coordinate in this stack");
00479                       return;
00480                     }
00481                     for ( int l = 0 ; l < Npoints ; l++ )
00482                       ptr->pdata[l] = (*p)->coords[l](iptr);
00483                   }
00484                   break;
00485                   
00486                 default:
00487                   staterror("there should not be any other pointer type left in this stack");
00488                   return;
00489                 }
00490                 break;
00491               case TOK_SEPARATOR:
00492                 // output
00493                 if (me == VizServer) {
00494                     int na, nb, avea, aveb;
00495                     vectorize(ptr->prev, Npoints);
00496                   // write probe data
00497                   switch((*p)->type) {
00498                   case TOK_THREAD:
00499                     if ( (*p)->options.thread.ave == STAT_AVERAGED ) {
00500                       double sum = 0.0;
00501                       for ( int ip = 0 ; ip < Npoints ; ip ++ )
00502                         sum += ptr->prev->pdata[ip];
00503                       *out << (sum/Npoints) << std::endl;
00504                     } else {
00505                       for ( int ip = 0 ; ip < Npoints ; ip ++ )
00506                         *out << ptr->prev->pdata[ip] << " ";
00507                       *out << std::endl;
00508                     }
00509                     break;
00510                   case TOK_SURFACE:
00511                       avea = (*p)->options.surface.avea;
00512                       aveb = (*p)->options.surface.aveb;
00513                       na = (*p)->options.surface.na;
00514                       nb = (*p)->options.surface.nb;
00515                   case TOK_PLANES:
00516                       if ( (*p)->type == TOK_PLANES ) {
00517                           avea = STAT_AVERAGED;
00518                           aveb = STAT_AVERAGED;
00519                           na = (*p)->options.plane.na;
00520                           nb = (*p)->options.plane.nb;
00521                       }
00522                       
00523                     if ( avea == STAT_AVERAGED && aveb == STAT_AVERAGED ) {
00524                       double sum = 0.0;
00525                       for ( int ip = 0 ; ip < Npoints ; ip ++ )
00526                         sum += ptr->prev->pdata[ip];
00527                       *out << (sum/Npoints) << std::endl;
00528                     } else if ( avea == STAT_RAW && aveb == STAT_AVERAGED ) {
00529                       for ( int i = 0 ; i < na ; i++ ) {
00530                         double sum=0.0;
00531                         for ( int j = 0 ; j < nb ; j++ ) {
00532                           sum += ptr->prev->pdata[i+j*na];
00533                           *out << (sum/nb) << " ";
00534                         }
00535                       }
00536                       *out << std::endl;
00537                     }  else if ( avea == STAT_AVERAGED && aveb == STAT_RAW ) {
00538                       for ( int j = 0 ; j < nb ; j++ ) {
00539                         double sum=0.0;
00540                         for ( int i = 0 ; i < na ; i++ ) {
00541                           sum += ptr->prev->pdata[i+j*na];
00542                           *out << (sum/na) << " ";
00543                         }
00544                       }
00545                       *out << std::endl;
00546                     } else {
00547                       for ( int ip = 0 ; ip < Npoints ; ip ++ )
00548                         *out << ptr->prev->pdata[ip] << " ";
00549                       *out << std::endl;
00550                     }
00551                     break;
00552                   case TOK_VOLUME:
00553                     
00554                     break;
00555                   }
00556                 }
00557                 unlinksym(ptr->prev);
00558                 break;
00559               case TOK_FUNCTION1:
00560               case TOK_FUNCTION2:
00561               case TOK_VARINARRAY:
00562               case TOK_VARIABLE:
00563               case TOK_COORDINATE:
00564                 staterror("there should not be any pointer type tokens"
00565                           " left in the stack");
00566                 return;
00567               default:
00568                   if ( ptr->type != TOK_DOUBLE ) {
00569                       staterror("unhandled stack token");
00570                       return;
00571                   }
00572                 break;
00573               }
00574               // need special code to handle the separator token, to flush the queue
00575               if ( ptr->type == TOK_SEPARATOR ) {
00576                   ptr_ref = ptr->next;
00577                   unlinksym(ptr);
00578                   ptr = ptr_ref;
00579               } else {
00580                   ptr->type = TOK_DOUBLE;
00581                   ptr = ptr->next;
00582               }
00583               
00584 #ifdef DEBUG_PRINT_STATISTICS
00585               (comm_service::log() << " end of token switch\n" ).flush();
00586 #endif
00587             }
00588           clearcoords(*p);  
00589           }
00590         }
00591       }
00592       // close output file
00593       if (me == VizServer) {
00594         outfile.close();
00595         delete out;
00596       }
00597     }
00598   
00599 private:
00600   int _DumpMeshes;
00601   int _Step;
00602   ControlDevice LocCtrl;
00603   std::string _OutputFile;
00604   std::string _DefFile;
00605   
00606   OutputType* _FileOutput;
00607   InterpolationType* _Interpolation;
00608 };
00609 
00610 #endif