MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
StreamerBase Class Reference

#include <StreamerBase.h>

+ Inheritance diagram for StreamerBase:
+ Collaboration diagram for StreamerBase:

Public Member Functions

string getOutFilepath () const
 
StreamerBaseoperator= (const StreamerBase &st)
 
void setOutFilepath (string stream)
 
 StreamerBase ()
 
 ~StreamerBase ()
 
- Public Member Functions inherited from TableBase
void clearVec ()
 
void compareVec (vector< double > other, string op)
 
void compareXplot (string fname, string plotname, string op)
 
const vector< double > & data ()
 
double getOutputValue () const
 
string getPlotDump () const
 
vector< double > getVec () const
 
unsigned int getVecSize () const
 
double getY (unsigned int index) const
 
double interpolate (double x, double xmin, double xmax) const
 
void linearTransform (double scale, double offset)
 
void loadCSV (string fname, int startLine, int colNum, char separator)
 
void loadXplot (string fname, string plotname)
 
void loadXplotRange (string fname, string plotname, unsigned int start, unsigned int end)
 
double * lookupVec (unsigned int index)
 
void plainPlot (string file)
 
void setOutputValue (double val)
 
void setPlotDump (string v)
 
void setVec (vector< double > val)
 
void setVecSize (unsigned int num)
 
 TableBase ()
 
void xplot (string file, string plotname)
 

Static Public Member Functions

static void writeToCSVFile (const string &filepath, const string &openmode, const vector< double > &data, const vector< string > &columns)
 Write data to csv file. See the documentation of writeToOutfile for details. More...
 
static void writeToNPYFile (const string &filepath, const string &openmode, const vector< double > &data, const vector< string > &columns)
 Write to NPY format. See the documentation of writeToOutfile for more details. More...
 
static void writeToOutFile (const string &filepath, const string &format, const string &openmode, const vector< double > &data, const vector< string > &columns)
 Write to a output file in given format. More...
 
- Static Public Member Functions inherited from TableBase
static const CinfoinitCinfo ()
 

Private Attributes

string outfilePath_
 

Static Private Attributes

static const char delimiter_ = ' '
 
static const char eol = '\n'
 

Additional Inherited Members

- Protected Member Functions inherited from TableBase
vector< double > & vec ()
 

Detailed Description

Definition at line 31 of file StreamerBase.h.

Constructor & Destructor Documentation

StreamerBase::StreamerBase ( )

Definition at line 30 of file StreamerBase.cpp.

31 {
32 }
StreamerBase::~StreamerBase ( )

Definition at line 41 of file StreamerBase.cpp.

42 {
43 
44 }

Member Function Documentation

string StreamerBase::getOutFilepath ( void  ) const

Definition at line 47 of file StreamerBase.cpp.

References outfilePath_.

48 {
49  return outfilePath_;
50 }
string outfilePath_
Definition: StreamerBase.h:91
StreamerBase & StreamerBase::operator= ( const StreamerBase st)

Definition at line 34 of file StreamerBase.cpp.

References outfilePath_.

35 {
36  this->outfilePath_ = st.outfilePath_;
37  return *this;
38 }
string outfilePath_
Definition: StreamerBase.h:91
void StreamerBase::setOutFilepath ( string  stream)

Definition at line 52 of file StreamerBase.cpp.

References outfilePath_.

53 {
54  outfilePath_ = filepath;
55 }
string outfilePath_
Definition: StreamerBase.h:91
void StreamerBase::writeToCSVFile ( const string &  filepath,
const string &  openmode,
const vector< double > &  data,
const vector< string > &  columns 
)
static

Write data to csv file. See the documentation of writeToOutfile for details.

Definition at line 83 of file StreamerBase.cpp.

References delimiter_, eol, LOG, moose::toString(), and moose::warning.

Referenced by writeToOutFile().

85 {
86 
87  FILE* fp = fopen( filepath.c_str(), openmode.c_str() );
88  if( NULL == fp )
89  {
90  LOG( moose::warning, "Failed to open " << filepath );
91  return;
92  }
93 
94  // If writing in "w" mode, write the header first.
95  if( openmode == "w" )
96  {
97  string headerText = "";
98  for( vector<string>::const_iterator it = columns.begin();
99  it != columns.end(); it++ )
100  headerText += ( *it + delimiter_ );
101  headerText += eol;
102  fprintf( fp, "%s", headerText.c_str() );
103  }
104 
105  string text = "";
106  for( size_t i = 0; i < data.size(); i+=columns.size() )
107  {
108  // Start of a new row.
109  for( size_t ii = 0; ii < columns.size(); ii++ )
110  text += moose::toString( data[i+ii] ) + delimiter_;
111 
112  // At the end of each row, we remove the delimiter_ and append newline_.
113  *(text.end()-1) = eol;
114  }
115  fprintf( fp, "%s", text.c_str() );
116  fclose( fp );
117 }
string toString(double x)
Convert a given value to string.
Definition: global.cpp:199
static const char eol
Definition: StreamerBase.h:93
static const char delimiter_
Definition: StreamerBase.h:94

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void StreamerBase::writeToNPYFile ( const string &  filepath,
const string &  openmode,
const vector< double > &  data,
const vector< string > &  columns 
)
static

Write to NPY format. See the documentation of writeToOutfile for more details.

Definition at line 120 of file StreamerBase.cpp.

References TableBase::data().

Referenced by writeToOutFile().

122 {
123  cnpy2::save_numpy<double>( filepath, data, columns, openmode );
124 }
const vector< double > & data()
Definition: TableBase.cpp:498

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void StreamerBase::writeToOutFile ( const string &  filepath,
const string &  format,
const string &  openmode,
const vector< double > &  data,
const vector< string > &  columns 
)
static

Write to a output file in given format.

Parameters
filepath,pathof output file. If parent directories do not exist, they will be created. If creation fails for some reason, data will be saved in current working directory. The name of the file will be computed from the given directory name by replacing '/' or '\' by '_'.
formatnpy : numpy binary format (version 1 and 2), version 1 is default. csv or dat: comma separated value (delimiter ' ' )
openmode(write or append)
data,vectorof values
ncols(number of columns). Incoming data will be formatted into a matrix with ncols.

Definition at line 58 of file StreamerBase.cpp.

References LOG, moose::warning, writeToCSVFile(), and writeToNPYFile().

Referenced by Streamer::cleanUp(), Table::process(), Streamer::process(), Table::reinit(), Streamer::reinit(), and Table::~Table().

64 {
65  if( data.size() == 0 )
66  return;
67 
68  if( "npy" == outputFormat )
69  writeToNPYFile( filepath, openmode, data, columns );
70  else if( "csv" == outputFormat or "dat" == outputFormat )
71  writeToCSVFile( filepath, openmode, data, columns );
72  else
73  {
74  LOG( moose::warning, "Unsupported format " << outputFormat
75  << ". Use npy or csv. Falling back to default csv"
76  );
77  writeToCSVFile( filepath, openmode, data, columns );
78  }
79 }
static void writeToNPYFile(const string &filepath, const string &openmode, const vector< double > &data, const vector< string > &columns)
Write to NPY format. See the documentation of writeToOutfile for more details.
static void writeToCSVFile(const string &filepath, const string &openmode, const vector< double > &data, const vector< string > &columns)
Write data to csv file. See the documentation of writeToOutfile for details.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

const char StreamerBase::delimiter_ = ' '
staticprivate

Definition at line 94 of file StreamerBase.h.

Referenced by writeToCSVFile().

const char StreamerBase::eol = '\n'
staticprivate

Definition at line 93 of file StreamerBase.h.

Referenced by writeToCSVFile().

string StreamerBase::outfilePath_
private

Definition at line 91 of file StreamerBase.h.

Referenced by getOutFilepath(), operator=(), and setOutFilepath().


The documentation for this class was generated from the following files: