OpenLB 1.7
Loading...
Searching...
No Matches
Public Member Functions | List of all members
olb::CSV< T > Class Template Reference

#include <CSVWriter.h>

+ Inheritance diagram for olb::CSV< T >:
+ Collaboration diagram for olb::CSV< T >:

Public Member Functions

 CSV (std::string name, char separator, std::vector< std::string > columnTags)
 Constructor with name for output file.
 
 CSV (std::string name="unnamed")
 
 CSV (std::string name, char separator)
 
 CSV (std::string name, std::vector< std::string > columnTags)
 
void writeDataFile (T xValue, T yValue, const std::string &plotFileName, int precision=16)
 former datFileOut functions these functions create a datafile in the csv format in order to write in a separated datafile as the one named in the constructor, just put the name as the plotFileName parameter
 
void writeDataFile (T xValue, const std::vector< T > &yValues, const std::string &plotFileName, int precision=16)
 writes the data file for one double and a vector of doubles with a specific filename
 
void writeDataFile (T xValue, T yValue, int precision=16)
 writes the data file for two doubles (x and y)
 
void writeDataFile (T xValue, const std::vector< T > &yValues, int precision=16)
 writes the data file for one double and a vector of doubles (x and y1,y2,...)
 
void setColumnTags (const std::vector< std::string > columnTags, std::string &plotFileName)
 adds column tags at the beginning of the csv data file.
 
void setColumnTags (const std::vector< std::string > columnTags)
 
void clearFile (std::string filename)
 clears the file
 
void clearFile ()
 

Detailed Description

template<typename T>
class olb::CSV< T >

Definition at line 34 of file CSVWriter.h.

Constructor & Destructor Documentation

◆ CSV() [1/4]

template<typename T >
olb::CSV< T >::CSV ( std::string name,
char separator,
std::vector< std::string > columnTags )

Constructor with name for output file.

Constructor with name of outputFiles boolean true for real-time plotting //WARNING: experimental!

add (new) data file

Definition at line 39 of file CSVWriter.hh.

40 : _name(name),
41 _dataFile(singleton::directories().getGnuplotOutDir()+"data/"+_name+".dat"),
42 _dir(singleton::directories().getGnuplotOutDir()),
43 _separator(separator),
44 _columnTags(columnTags)
45{
46 if (singleton::mpi().getRank() == _rank) {
47 std::ofstream fout;
48
50 fout.open(_dataFile.c_str(), std::ios::trunc);
51 if(columnTags.size()>0)
52 {
53 setColumnTags(columnTags);
54 }
55 fout.close();
56 }
57}
void setColumnTags(const std::vector< std::string > columnTags, std::string &plotFileName)
adds column tags at the beginning of the csv data file.
Definition CSVWriter.hh:119
MpiManager & mpi()
Directories & directories()
Definition singleton.h:150

◆ CSV() [2/4]

template<typename T >
olb::CSV< T >::CSV ( std::string name = "unnamed")
explicit

Definition at line 63 of file CSVWriter.hh.

63: CSV(name, ' ', std::vector<std::string> {}){}
CSV(std::string name, char separator, std::vector< std::string > columnTags)
Constructor with name for output file.
Definition CSVWriter.hh:39

◆ CSV() [3/4]

template<typename T >
olb::CSV< T >::CSV ( std::string name,
char separator )

Definition at line 66 of file CSVWriter.hh.

66: CSV(name, separator, std::vector<std::string> {}){}

◆ CSV() [4/4]

template<typename T >
olb::CSV< T >::CSV ( std::string name,
std::vector< std::string > columnTags )

Definition at line 60 of file CSVWriter.hh.

60: CSV(name, ' ', columnTags){}

Member Function Documentation

◆ clearFile() [1/2]

template<typename T >
void olb::CSV< T >::clearFile ( )

Definition at line 153 of file CSVWriter.hh.

154{
155 clearFile(_name);
156}
void clearFile()
Definition CSVWriter.hh:153

◆ clearFile() [2/2]

template<typename T >
void olb::CSV< T >::clearFile ( std::string filename)

clears the file

empty the file by opening an ofstream

Definition at line 145 of file CSVWriter.hh.

146{
148 std::ofstream fout(singleton::directories().getGnuplotOutDir() + "data/" + filename + ".dat",std::ios::out);
149 fout.close();
150}

References olb::singleton::directories().

+ Here is the call graph for this function:

◆ setColumnTags() [1/2]

template<typename T >
void olb::CSV< T >::setColumnTags ( const std::vector< std::string > columnTags)

Definition at line 139 of file CSVWriter.hh.

140{
141 setColumnTags(columnTags, _name);
142}

◆ setColumnTags() [2/2]

template<typename T >
void olb::CSV< T >::setColumnTags ( const std::vector< std::string > columnTags,
std::string & plotFileName )

adds column tags at the beginning of the csv data file.

saves the content of the file and rewrites it with the tags at the top and then inserting the content again

to prevent having a separator at the end

Definition at line 119 of file CSVWriter.hh.

120{
121 OstreamManager clout(std::cout,"setColumnTags");
122
123 std::ofstream fout(singleton::directories().getGnuplotOutDir() + "data/" + plotFileName + ".dat",std::ios::out);
124
125 if(fout.is_open())
126 {
127 unsigned int k = 0;
128 for(;k < columnTags.size() -1; k++)
129 {
130 fout << columnTags.at(k) << _separator;
131 }
133 fout << columnTags.at(k) << std::endl;
134 }
135 fout.close();
136}

References olb::singleton::directories().

+ Here is the call graph for this function:

◆ writeDataFile() [1/4]

template<typename T >
void olb::CSV< T >::writeDataFile ( T xValue,
const std::vector< T > & yValues,
const std::string & plotFileName,
int precision = 16 )

writes the data file for one double and a vector of doubles with a specific filename

Definition at line 70 of file CSVWriter.hh.

71{
72 if (singleton::mpi().getRank() == _rank) {
73 std::ofstream fout;
74 std::string DATAF;
75 DATAF = singleton::directories().getGnuplotOutDir()+"data/"+plotNameFile+".dat";
76 fout.precision(precision);
77 fout.open(DATAF.c_str(), std::ios::out | std::ios::app);
78 fout << BaseType<T>(xValue);
79 for (unsigned int i = 0; i < yValues.size(); i++) {
80 fout << _separator << BaseType<T>(yValues[i]);
81 }
82 fout << std::endl;
83 fout.close();
84 }
85 return;
86}
std::string getGnuplotOutDir() const
Definition singleton.h:101

References olb::singleton::directories(), olb::singleton::Directories::getGnuplotOutDir(), and olb::singleton::mpi().

+ Here is the call graph for this function:

◆ writeDataFile() [2/4]

template<typename T >
void olb::CSV< T >::writeDataFile ( T xValue,
const std::vector< T > & yValues,
int precision = 16 )

writes the data file for one double and a vector of doubles (x and y1,y2,...)

Definition at line 101 of file CSVWriter.hh.

102{
103 writeDataFile(xValue, yValues, _name, precision);
104 return;
105}
void writeDataFile(T xValue, T yValue, const std::string &plotFileName, int precision=16)
former datFileOut functions these functions create a datafile in the csv format in order to write in ...
Definition CSVWriter.hh:91

◆ writeDataFile() [3/4]

template<typename T >
void olb::CSV< T >::writeDataFile ( T xValue,
T yValue,
const std::string & plotFileName,
int precision = 16 )

former datFileOut functions these functions create a datafile in the csv format in order to write in a separated datafile as the one named in the constructor, just put the name as the plotFileName parameter

writes the data file for two doubles with a specific filename

Definition at line 91 of file CSVWriter.hh.

92{
93 std::vector<T> yValues{yValue};
94 writeDataFile(xValue, yValues, plotNameFile, precision);
95 return;
96}

◆ writeDataFile() [4/4]

template<typename T >
void olb::CSV< T >::writeDataFile ( T xValue,
T yValue,
int precision = 16 )

writes the data file for two doubles (x and y)

Definition at line 109 of file CSVWriter.hh.

110{
111 std::vector<T> yValues{yValue};
112 writeDataFile(xValue, yValues, _name,precision);
113 return;
114}

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