Added export function to function container.

This commit is contained in:
Christian
2019-04-03 11:43:28 +02:00
parent c79661292e
commit e5d66411bb
6 changed files with 35 additions and 13 deletions
+19 -1
View File
@@ -58,7 +58,7 @@ void Func_Container::readFromCSV(std::string loadFilePath) {
if (!fileStream.good()) {
stringstream ss;
ss<<"Func_Container::readFromCSV: Could not open file: "<<loadFilePath<<endl;
ss<<"Func_Container::readFromCSV: Could not open file. \n loadFilePath= "<<loadFilePath<<endl;
throw MyException(ss.str());
}
@@ -97,6 +97,24 @@ void Func_Container::printAnkerpoints() {
}
}
void Func_Container::exportToFile(std::string exportFilePath) {
ofstream outFile;
outFile.open(exportFilePath);
if (!outFile.good()) {
stringstream ss;
ss<<"Func_Container::exportToFile: Could not open file. \n exportFilePath= "<<exportFilePath<<endl;
throw MyException(ss.str());
}
outFile<<"# Automatically generated Data of Function_Container class by exportToFile().\n";
outFile<<"# Generated on "<<getTimeString()<<".\n";
outFile<<"#key (usually Energy)\tparameter (usually TCS)\n";
dim1Map::iterator AnkerItr;
for (AnkerItr = Map.begin();AnkerItr!=Map.end();AnkerItr++) {
outFile<<AnkerItr->first<<"\t"<<AnkerItr->second<<"\n";
}
outFile.close();
}
// Func2D_Container
Func2D_Container::Func2D_Container(std::string loadFilePath) {
readFromCSV(loadFilePath);
+1
View File
@@ -22,6 +22,7 @@ public:
Func_Container(std::string loadFilePath);
void add_ankerpoint(double x, double fx);
double interpolate(double x);
void exportToFile(std::string exportFilePath);
private:
dim1Map Map;
void readFromCSV(std::string loadFilePath);
+12
View File
@@ -109,6 +109,18 @@ void replaceDelimiter(std::string &lineFromFile) {
return;
}
// System read out
string getTimeString() {
time_t rawtime;
struct tm * timeinfo;
char buffer[80];
time (&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer,sizeof(buffer),"%Y%m%d",timeinfo);
string str(buffer);
return(str);
}
// Calculate Kinematic Relations
double get_Ekin_eV_from_speed(double Speed_ms, double mass_eV) {
double beta = Speed_ms/c_ms;
+3
View File
@@ -40,6 +40,9 @@ bool checkIgnoreLine(std::string lineFromFile); // true if line is empty or star
void removeLeadingWhites(std::string &lineFromFile);
void replaceDelimiter(std::string &lineFromFile); // replaces delimiter (';'',''=') with whitespace
// System Read out
std::string getTimeString();
// Calculate Kinematic Relations
double get_Speed_from_Ekin_eV(double Ekin_eV, double mass_eV);
double get_gamma_from_Ekin_eV(double Ekin_eV, double mass_eV);
-11
View File
@@ -48,17 +48,6 @@ void Base_Logger::set_zLogValues() {
return;
}
string Base_Logger::getTimeString() {
time_t rawtime;
struct tm * timeinfo;
char buffer[80];
time (&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer,sizeof(buffer),"%Y%m%d",timeinfo);
string str(buffer);
return(str);
}
std::string Base_Logger::getparName() {
string parpath = getenv("parpath");
string parfile = remove_catEnding(getenv("parfile"));
-1
View File
@@ -40,7 +40,6 @@ protected:
void set_zLogValues();
std::string getparName();
std::string getTimeString();
std::string remove_catEnding (std::string inString);
bool isFile(std::string fileName);
bool isDir(std::string dirPath);