12 #include "../utility/strutil.h"
22 "vector with all table entries",
29 "'File plotname' for dumpling an xplot, as a workaround for an error in the xplot python interface. Note separator is a space. The return value is a dummy.",
36 "Output value holding current table entry or output of a calculation",
42 "size of table. Note that this is the number of x divisions +1"
43 "since it must represent the largest value as well as the"
50 "Value of table at specified index",
59 "Linearly scales and offsets data. Scale first, then offset.",
63 "Dumps table contents to xplot-format file. "
64 "Argument 1 is filename, argument 2 is plotname",
68 "Dumps table contents to single-column ascii file. "
69 "Uses scientific notation. "
70 "Argument 1 is filename",
74 "Reads a single column from a CSV file. "
75 "Arguments: filename, column#, starting row#, separator",
80 "Reads a single plot from an xplot file. "
81 "Arguments: filename, plotname"
82 "When the file has 2 columns, the 2nd column is loaded.",
87 "Reads a single plot from an xplot file, and selects a "
88 "subset of points from it. "
89 "Arguments: filename, plotname, startindex, endindex"
90 "Uses C convention: startindex included, endindex not included."
91 "When the file has 2 columns, the 2nd column is loaded.",
96 "Reads a plot from an xplot file and compares with contents of TableBase."
97 "Result is put in 'output' field of table."
98 "If the comparison fails (e.g., due to zero entries), the "
100 "Arguments: filename, plotname, comparison_operation"
101 "Operations: rmsd (for RMSDifference), rmsr (RMSratio ), "
102 "dotp (Dot product, not yet implemented).",
107 "Compares contents of TableBase with a vector of doubles."
108 "Result is put in 'output' field of table."
109 "If the comparison fails (e.g., due to zero entries), the "
110 "return value is -1."
111 "Arguments: Other vector, comparison_operation"
112 "Operations: rmsd (for RMSDifference), rmsr (RMSratio ), "
113 "dotp (Dot product, not yet implemented).",
119 "Handles request to clear the data vector",
123 static Finfo* tableBaseFinfos[] = {
145 sizeof( tableBaseFinfos ) /
sizeof (
Finfo* ),
168 for ( vector< double >::iterator i =
vec_.begin(); i !=
vec_.end(); ++i)
169 *i = *i * scale + offset;
174 ofstream fout( fname.c_str(), ios_base::out );
175 fout.precision( 18 );
176 fout.setf( ios::scientific, ios::floatfield );
177 for ( vector< double >::iterator i =
vec_.begin(); i !=
vec_.end(); ++i)
184 ofstream fout( fname.c_str(), ios_base::app );
185 fout <<
"/newplot\n";
186 fout <<
"/plotname " << plotname <<
"\n";
187 for ( vector< double >::iterator i =
vec_.begin(); i !=
vec_.end(); ++i)
194 static const unsigned int len = strlen(
"/plotname" ) ;
195 if ( line.size() < len + 2 )
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 '" <<
205 name = name.substr( pos );
206 if ( plotname == name )
233 istringstream sstream( line );
238 if ( sstream >> y1 ) {
239 if ( sstream >> y2 ) {
240 if ( sstream >> y3 ) {
252 ifstream fin( fname.c_str() );
254 cout <<
"TableBase::innerLoadXplot: Failed to open file " << fname <<endl;
260 if ( plotname ==
"" )
262 while ( fin.good() ) {
263 getline( fin, line );
265 if ( isdigit( line[0] ) )
267 if ( line[0] ==
'-' && line.length() > 1 && isdigit( line[1] ) )
271 while ( fin.good() ) {
272 getline( fin, line );
275 if ( !getline ( fin, line ) )
284 if ( line.length() == 0 || line ==
"/newplot" || line ==
"/plotname" )
287 getline( fin, line );
289 }
while ( fin.good() );
291 return ( v.size() > 0 );
297 cout <<
"TableBase::loadXplot: unable to load data from file " << fname <<endl;
303 unsigned int start,
unsigned int end )
305 vector< double > temp;
307 cout <<
"TableBase::loadXplot: unable to load data from file " << fname <<endl;
310 if ( start > end || end > temp.size() ) {
311 cout <<
"TableBase::loadXplotRange: Bad range (" << start <<
312 ", " << end <<
"] for table of size " << temp.size() <<
313 " from file " << fname << endl;
317 vec_.insert(
vec_.end(), temp.begin() + start, temp.begin() + end );
321 string fname,
int startLine,
int colNum,
char separator )
323 cout <<
"TODO: Not implemented yet" << endl;
326 double getRMSDiff(
const vector< double >& v1,
const vector< double >& v2 )
328 unsigned int size = ( v1.size() < v2.size() ) ? v1.size() : v2.size();
333 for (
unsigned int i = 0; i < size; ++i ) {
334 double temp = v1[i] - v2[i];
335 sumsq += temp * temp;
337 return sqrt( sumsq / size );
340 double getRMS(
const vector< double >& v )
343 unsigned int size = v.size();
346 for ( vector< double >::const_iterator i = v.begin(); i != v.end(); ++i)
349 return sqrt( sumsq / size );
352 double getRMSRatio(
const vector< double >& v1,
const vector< double >& v2 )
356 if ( v1.size() == 0 || v2.size() == 0 )
358 if ( r1 + r2 > 1e-20 )
365 const unsigned int len = 5;
368 for ( i = 0; i < op.length() && i < len-1 ; ++i )
369 temp[i] = tolower( op[i] );
371 return string( temp );
376 vector< double > temp;
378 cout <<
"TableBase::compareXplot: unable to load data from file " << fname <<endl;
381 string hop =
headop( op );
383 if ( hop ==
"rmsd" ) {
387 if ( hop ==
"rmsr" ) {
392 cout <<
"TableBase::compareXplot: DotProduct not yet done\n";
400 string hop =
headop( op );
402 if ( hop ==
"rmsd" ) {
406 if ( hop ==
"rmsr" ) {
411 cout <<
"TableBase::compareVec: DotProduct not yet done\n";
435 if ( index <
vec_.size() )
436 return (
vec_[index] );
443 if (
vec_.size() == 0 )
445 if (
vec_.size() == 1 || input < xmin || xmin >= xmax )
448 return (
vec_.back() );
450 unsigned int xdivs =
vec_.size() - 1;
452 double fraction = ( input - xmin ) / ( xmax - xmin );
456 unsigned int j = xdivs * fraction;
457 if ( j >= (
vec_.size() - 1 ) )
460 double dx = (xmax - xmin ) / xdivs;
461 double lowerBound = xmin + j * dx;
462 double subFraction = ( input - lowerBound ) / dx;
464 double y =
vec_[j] + (
vec_[j + 1] -
vec_[j] ) * subFraction;
505 static string ret =
"plot.Dump";
512 std::size_t pos = v.rfind(
" ");
513 string fname = v.substr( 0, pos );
514 string plotname =
"plot";
515 if ( pos != string::npos )
516 plotname = v.substr( pos );
518 xplot( fname, plotname );
double getRMSDiff(const vector< double > &v1, const vector< double > &v2)
void xplot(string file, string plotname)
double getOutputValue() const
bool isNamedPlot(const string &line, const string &plotname)
static double op(double x)
void linearTransform(double scale, double offset)
void setVec(vector< double > val)
string headop(const string &op)
vector< double > getVec() const
double interpolate(double x, double xmin, double xmax) const
void setPlotDump(string v)
double getRMSRatio(const vector< double > &v1, const vector< double > &v2)
static const Cinfo * tableBaseCinfo
void setOutputValue(double val)
double getYcolumn(const string &line)
const vector< double > & data()
unsigned int getVecSize() const
static const Cinfo * initCinfo()
void loadCSV(string fname, int startLine, int colNum, char separator)
void loadXplotRange(string fname, string plotname, unsigned int start, unsigned int end)
void compareXplot(string fname, string plotname, string op)
void plainPlot(string file)
static const Cinfo * tableCinfo
double getY(unsigned int index) const
bool innerLoadXplot(string fname, string plotname, vector< double > &v)
double getRMS(const vector< double > &v)
static const Cinfo * initCinfo()
std::string trim(const std::string myString, const string &delimiters)
void setVecSize(unsigned int num)
void loadXplot(string fname, string plotname)
void compareVec(vector< double > other, string op)
string getPlotDump() const