/** \file datacreator.cpp * * Declarations of assisting functions in creating data and plot files. * */ //============================ INCLUDES =========================== #include "datacreator.hpp" //=========================== FUNCTIONS============================ /** Opens a file with \a *filename in \a *dir. * \param output file handle on return * \param *dir directory * \param *filename name of file * \return true if file has been opened */ bool OpenOutputFile(ofstream &output, const char *dir, const char *filename) { stringstream name; name << dir << "/" << filename; output.open(name.str().c_str(), ios::out); if (output == NULL) { cout << "Unable to open " << name.str() << " for writing, is directory correct?" << endl; return false; } return true; }; /** Plots an energy vs. order. * \param &Fragments EnergyMatrix class containing matrix values * \param KeySet KeySetContainer class holding bond KeySetContainer::Order * \param *prefix prefix in filename (without ending) * \param *msg message to be place in first line as a comment * \return true if file was written successfully */ bool CreateDataEnergyOrder(class EnergyMatrix &Fragments, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum) { stringstream filename; ofstream output; filename << prefix << ".dat"; if (!OpenOutputFile(output, dir, filename.str().c_str())) return false; cout << msg << endl; output << "# " << msg << ", created on " << datum; output << "#Order\tFrag.No.\t" << Fragments.Header << endl; for (int BondOrder=0;BondOrder fabs(Fragments.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][1])) { for (int k=Fragments.ColumnCounter;k--;) Fragments.Matrix[ Fragments.MatrixCounter ][j][k] = Fragments.Matrix[ KeySet.OrderSet[BondOrder][i] ][j][k]; } } } }; /** Plot matrix vs. fragment. */ bool CreateDataFragmentOrder(class MatrixContainer &Fragment, class KeySetsContainer &KeySet, char *dir, char *prefix, char *msg, char *datum, void (*CreateFragmentOrder)(class MatrixContainer &, class KeySetsContainer &, int)) { stringstream filename; ofstream output; filename << prefix << ".dat"; if (!OpenOutputFile(output, dir, filename.str().c_str())) return false; cout << msg << endl; output << "# " << msg << ", created on " << datum; output << "#Order\tFrag.No.\t" << Fragment.Header << endl; // max for (int BondOrder=0;BondOrder MYEPSILON) && (tmp < stored)) { // current force is greater than stored for (int m=NDIM;m--;) Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l+m] = Force.Matrix[MatrixNumber][ k ][l+m]; stored = tmp; } } } }; /** Scans forces for the mean in magnitude. * Results are stored in the matrix ForceMatrix::MatrixCounter of \a Force. * \param Force ForceMatrix class containing matrix values * \param MatrixNumber the index for the ForceMatrix::matrix array */ void CreateMeanForce(class MatrixContainer &Force, int MatrixNumber) { int divisor = 0; for (int l=Force.ColumnCounter;l--;) Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l] = 0.; for (int l=5;l MYEPSILON) divisor++; } tmp /= (double)divisor; Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l] = tmp; } }; /** Scans forces for the maximum in magnitude. * Results are stored in the matrix ForceMatrix::MatrixCounter of \a Force. * \param Force ForceMatrix class containing matrix values * \param MatrixNumber the index for the ForceMatrix::matrix array */ void CreateMaximumForce(class MatrixContainer &Force, int MatrixNumber) { for (int l=5;l stored) { // current force is greater than stored for (int m=NDIM;m--;) Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l+m] = Force.Matrix[MatrixNumber][ k ][l+m]; stored = tmp; } } } }; /** Leaves the Force.Matrix as it is. * \param Force ForceMatrix class containing matrix values * \param MatrixNumber the index for the ForceMatrix::matrix array */ void CreateSameForce(class MatrixContainer &Force, int MatrixNumber) { // does nothing }; /** Adds vectorwise all forces. * Results are stored in the matrix ForceMatrix::MatrixCounter of \a Force. * \param Force ForceMatrix class containing matrix values * \param MatrixNumber the index for the ForceMatrix::matrix array */ void CreateVectorSumForce(class MatrixContainer &Force, int MatrixNumber) { for (int l=Force.ColumnCounter;l--;) Force.Matrix[MatrixNumber][ Force.RowCounter[MatrixNumber] ][l] = 0.; for (int l=0;l> item; for (int i=2; i<= Energy.ColumnCounter;i++) { line >> item; output << "'" << prefix << ".dat' title '" << item << "' using " << xargument << ":(abs($" << i+2 << ")) " << uses; if (i != (Energy.ColumnCounter)) output << ", \\"; output << endl; } }; /** Writes plot lines for energies. * \param output file handler * \param Energy MatrixContainer with matrix values * \param *prefix prefix of data file * \param *xargument number of column to plot against (x axis) * \param *uses uses command */ void EnergyPlotLine(ofstream &output, class MatrixContainer &Energy, const char *prefix, const char *xargument, const char *uses) { char item[1024]; stringstream line(Energy.Header); line >> item; for (int i=2; i<= Energy.ColumnCounter;i++) { line >> item; output << "'" << prefix << ".dat' title '" << item << "' using " << xargument << ":" << i+2 << " " << uses; if (i != (Energy.ColumnCounter)) output << ", \\"; output << endl; } }; /** Writes plot lines for absolute force magnitudes. * \param output file handler * \param Force MatrixContainer with matrix values * \param *prefix prefix of data file * \param *xargument number of column to plot against (x axis) * \param *uses uses command */ void ForceMagnitudePlotLine(ofstream &output, class MatrixContainer &Force, const char *prefix, const char *xargument, const char *uses) { char item[1024]; stringstream line(Force.Header); line >> item; line >> item; line >> item; line >> item; line >> item; for (int i=7; i< Force.ColumnCounter;i+=NDIM) { line >> item; item[strlen(item)-1] = '\0'; // kill residual index char (the '0') output << "'" << prefix << ".dat' title '" << item << "' using " << xargument << ":(sqrt($" << i+1 << "*$" << i+1 << "+$" << i+2 << "*$" << i+2 << "+$" << i+3 << "*$" << i+3 << ")) " << uses; if (i != (Force.ColumnCounter-1)) output << ", \\"; output << endl; line >> item; line >> item; } }; /** Writes plot lines for first component of force vector. * \param output file handler * \param Force MatrixContainer with matrix values * \param *prefix prefix of data file * \param *xargument number of column to plot against (x axis) * \param *uses uses command */ void AbsFirstForceValuePlotLine(ofstream &output, class MatrixContainer &Force, const char *prefix, const char *xargument, const char *uses) { char item[1024]; stringstream line(Force.Header); line >> item; line >> item; line >> item; line >> item; line >> item; for (int i=7; i< Force.ColumnCounter;i+=NDIM) { line >> item; item[strlen(item)-1] = '\0'; // kill residual index char (the '0') output << "'" << prefix << ".dat' title '" << item << "' using " << xargument << ":(abs($" << i+1 << ")) " << uses; if (i != (Force.ColumnCounter-1)) output << ", \\"; output << endl; line >> item; line >> item; } }; /** Writes plot lines for force vector as boxes with a fillcolor. * \param output file handler * \param Force MatrixContainer with matrix values * \param *prefix prefix of data file * \param *xargument number of column to plot against (x axis) * \param *uses uses command */ void BoxesForcePlotLine(ofstream &output, class MatrixContainer &Force, const char *prefix, const char *xargument, const char *uses) { char item[1024]; stringstream line(Force.Header); char *fillcolor[5] = {"black", "red", "blue", "green", "cyan"}; line >> item; line >> item; line >> item; line >> item; line >> item; for (int i=7; i< Force.ColumnCounter;i+=NDIM) { line >> item; item[strlen(item)-1] = '\0'; // kill residual index char (the '0') output << "'" << prefix << ".dat' title '" << item << "' using ($" << xargument << "+" << fixed << setprecision(1) << (double)((i-7)/3)*0.2 << "):(sqrt($" << i+1 << "*$" << i+1 << "+$" << i+2 << "*$" << i+2 << "+$" << i+3 << "*$" << i+3 << ")) " << uses << " " << fillcolor[(i-7)/3]; if (i != (Force.ColumnCounter-1)) output << ", \\"; output << endl; line >> item; line >> item; } }; /** Writes plot lines for first force vector component as boxes with a fillcolor. * \param output file handler * \param Force MatrixContainer with matrix values * \param *prefix prefix of data file * \param *xargument number of column to plot against (x axis) * \param *uses uses command */ void BoxesFirstForceValuePlotLine(ofstream &output, class MatrixContainer &Force, const char *prefix, const char *xargument, const char *uses) { char item[1024]; stringstream line(Force.Header); char *fillcolor[5] = {"black", "red", "blue", "green", "cyan"}; line >> item; line >> item; line >> item; line >> item; line >> item; for (int i=7; i< Force.ColumnCounter;i+=NDIM) { line >> item; item[strlen(item)-1] = '\0'; // kill residual index char (the '0') output << "'" << prefix << ".dat' title '" << item << "' using ($" << xargument << "+" << fixed << setprecision(1) << (double)((i-7)/3)*0.2 << "):" << i+1 << " " << uses << " " << fillcolor[(i-7)/3]; if (i != (Force.ColumnCounter-1)) output << ", \\"; output << endl; line >> item; line >> item; } };