MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TableBase.cpp File Reference
#include "header.h"
#include <fstream>
#include "../utility/strutil.h"
#include "TableBase.h"
+ Include dependency graph for TableBase.cpp:

Go to the source code of this file.

Functions

double getRMS (const vector< double > &v)
 
double getRMSDiff (const vector< double > &v1, const vector< double > &v2)
 
double getRMSRatio (const vector< double > &v1, const vector< double > &v2)
 
double getYcolumn (const string &line)
 
string headop (const string &op)
 
bool innerLoadXplot (string fname, string plotname, vector< double > &v)
 
bool isNamedPlot (const string &line, const string &plotname)
 

Variables

static const CinfotableBaseCinfo = TableBase::initCinfo()
 

Function Documentation

double getRMS ( const vector< double > &  v)

Definition at line 340 of file TableBase.cpp.

Referenced by getRMSRatio(), and testUtilsForCompareXplot().

341 {
342  double sumsq = 0;
343  unsigned int size = v.size();
344  if ( size == 0 )
345  return -1;
346  for ( vector< double >::const_iterator i = v.begin(); i != v.end(); ++i)
347  sumsq += *i * *i;
348 
349  return sqrt( sumsq / size );
350 }

+ Here is the caller graph for this function:

double getRMSDiff ( const vector< double > &  v1,
const vector< double > &  v2 
)

Definition at line 326 of file TableBase.cpp.

Referenced by TableBase::compareVec(), TableBase::compareXplot(), getRMSRatio(), and testUtilsForCompareXplot().

327 {
328  unsigned int size = ( v1.size() < v2.size() ) ? v1.size() : v2.size();
329  if ( size == 0 )
330  return -1;
331 
332  double sumsq = 0;
333  for ( unsigned int i = 0; i < size; ++i ) {
334  double temp = v1[i] - v2[i];
335  sumsq += temp * temp;
336  }
337  return sqrt( sumsq / size );
338 }

+ Here is the caller graph for this function:

double getRMSRatio ( const vector< double > &  v1,
const vector< double > &  v2 
)

Definition at line 352 of file TableBase.cpp.

References getRMS(), and getRMSDiff().

Referenced by TableBase::compareVec(), TableBase::compareXplot(), and testUtilsForCompareXplot().

353 {
354  double r1 = getRMS( v1 );
355  double r2 = getRMS( v2 );
356  if ( v1.size() == 0 || v2.size() == 0 )
357  return -1;
358  if ( r1 + r2 > 1e-20 )
359  return getRMSDiff( v1, v2 ) / (r1 + r2);
360  return -1;
361 }
double getRMSDiff(const vector< double > &v1, const vector< double > &v2)
Definition: TableBase.cpp:326
double getRMS(const vector< double > &v)
Definition: TableBase.cpp:340

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

double getYcolumn ( const string &  line)

Definition at line 231 of file TableBase.cpp.

Referenced by innerLoadXplot(), and testUtilsForLoadXplot().

232 {
233  istringstream sstream( line );
234  double y1 = 0.0;
235  double y2;
236  double y3;
237 
238  if ( sstream >> y1 ) {
239  if ( sstream >> y2 ) {
240  if ( sstream >> y3 ) {
241  return y1;
242  } else {
243  return y2;
244  }
245  }
246  }
247  return y1;
248 }

+ Here is the caller graph for this function:

string headop ( const string &  op)

Definition at line 363 of file TableBase.cpp.

Referenced by TableBase::compareVec(), and TableBase::compareXplot().

364 {
365  const unsigned int len = 5;
366  char temp[len];
367  unsigned int i = 0;
368  for ( i = 0; i < op.length() && i < len-1 ; ++i )
369  temp[i] = tolower( op[i] );
370  temp[i] = '\0';
371  return string( temp );
372 }
static double op(double x)

+ Here is the caller graph for this function:

bool innerLoadXplot ( string  fname,
string  plotname,
vector< double > &  v 
)

Definition at line 250 of file TableBase.cpp.

References getYcolumn(), isNamedPlot(), and moose::trim().

Referenced by TableBase::compareXplot(), TableBase::loadXplot(), and TableBase::loadXplotRange().

251 {
252  ifstream fin( fname.c_str() );
253  if ( !fin.good() ) {
254  cout << "TableBase::innerLoadXplot: Failed to open file " << fname <<endl;
255  return 0;
256  }
257 
258  string line;
259  // Here we advance to the first numerical line.
260  if ( plotname == "" ) // Just load starting from the 1st numerical line.
261  {
262  while ( fin.good() ) { // Break out of this loop if we find a number
263  getline( fin, line );
264  line = moose::trim(line);
265  if ( isdigit( line[0] ) )
266  break;;
267  if ( line[0] == '-' && line.length() > 1 && isdigit( line[1] ) )
268  break;
269  }
270  } else { // Find plotname and then begin loading.
271  while ( fin.good() ) {
272  getline( fin, line );
273  line = moose::trim(line);
274  if ( isNamedPlot ( line, plotname ) ) {
275  if ( !getline ( fin, line ) )
276  return 0;
277  break;
278  }
279  }
280  }
281 
282  v.resize( 0 );
283  do {
284  if ( line.length() == 0 || line == "/newplot" || line == "/plotname" )
285  break;
286  v.push_back( getYcolumn( line ) );
287  getline( fin, line );
288  line = moose::trim(line);
289  } while ( fin.good() );
290 
291  return ( v.size() > 0 );
292 }
bool isNamedPlot(const string &line, const string &plotname)
Definition: TableBase.cpp:192
double getYcolumn(const string &line)
Definition: TableBase.cpp:231
std::string trim(const std::string myString, const string &delimiters)
Definition: strutil.cpp:53

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool isNamedPlot ( const string &  line,
const string &  plotname 
)

Definition at line 192 of file TableBase.cpp.

References name.

Referenced by innerLoadXplot(), and testUtilsForLoadXplot().

193 {
194  static const unsigned int len = strlen( "/plotname" ) ;
195  if ( line.size() < len + 2 )
196  return 0;
197  if ( line[0] == '/' && line[1] == 'p' ) {
198  string name = line.substr( strlen( "/plotname" ) );
199  string::size_type pos = name.find_first_not_of( " " );
200  if ( pos == string::npos ) {
201  cout << "TableBase::loadXplot: Malformed plotname line '" <<
202  line << "'\n";
203  return 0;
204  }
205  name = name.substr( pos );
206  if ( plotname == name )
207  return 1;
208  }
209  return 0;
210 }
static char name[]
Definition: mfield.cpp:401

+ Here is the caller graph for this function:

Variable Documentation

const Cinfo* tableBaseCinfo = TableBase::initCinfo()
static

Definition at line 156 of file TableBase.cpp.