Added termination of Electrons after 100 Interactions
This commit is contained in:
@@ -57,15 +57,69 @@ void Func_Container::add_ankerpoint(double x, double fx) {
|
||||
}
|
||||
|
||||
void Func_Container::readFromCSV(std::string loadFilePath) {
|
||||
// Very simple implementation, maybe improve in further version... stability towards file format, comments...
|
||||
double xTemp;
|
||||
double fxTemp;
|
||||
ifstream fileStream(loadFilePath);
|
||||
|
||||
ifstream file(loadFilePath);
|
||||
|
||||
while ((file >> xTemp) && (file >> fxTemp)) {
|
||||
add_ankerpoint(xTemp, fxTemp);
|
||||
if (!fileStream.good()) {
|
||||
stringstream ss;
|
||||
ss<<"Func_Container::readFromCSV: Could not open file: "<<loadFilePath<<endl;
|
||||
throw MyException(ss.str());
|
||||
}
|
||||
file.close();
|
||||
|
||||
string lineFromFile;
|
||||
stringstream ss;
|
||||
double xTemp, fxTemp;
|
||||
bool lineReadError = false;
|
||||
|
||||
while (getline(fileStream, lineFromFile)) {
|
||||
removeLeadingWhites(lineFromFile);
|
||||
replaceDelimiter(lineFromFile);
|
||||
if ( checkIgnoreLine(lineFromFile) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ss.clear();
|
||||
ss.str(lineFromFile);
|
||||
|
||||
if (ss>>xTemp && ss>>fxTemp) {
|
||||
add_ankerpoint(xTemp, fxTemp);
|
||||
} else {
|
||||
if (!lineReadError) {
|
||||
cout<<"Func_Container::readFromCSV: Warning could not read line in inputFile. \nloadFilePath = "<<loadFilePath<<endl;
|
||||
lineReadError = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
fileStream.close();
|
||||
|
||||
}
|
||||
|
||||
void Func_Container::printAnkerpoints() {
|
||||
dim1Map::iterator AnkerItr;
|
||||
for (AnkerItr = Map.begin();AnkerItr!=Map.end();AnkerItr++) {
|
||||
cout<<AnkerItr->first<<"\t"<<AnkerItr->second<<"\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool checkIgnoreLine(string lineFromFile) {
|
||||
if (lineFromFile[0] =='#') {
|
||||
return true;
|
||||
} else if ( lineFromFile.empty() ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
void removeLeadingWhites(string &lineFromFile) {
|
||||
static const string WHITESPACE = " \n\r\t\f\v";
|
||||
size_t start = lineFromFile.find_first_not_of(WHITESPACE);
|
||||
lineFromFile = (start == std::string::npos) ? "" : lineFromFile.substr(start);
|
||||
return;
|
||||
}
|
||||
|
||||
void replaceDelimiter(string &lineFromFile) {
|
||||
replace(lineFromFile.begin(), lineFromFile.end(), ';', ' ');
|
||||
replace(lineFromFile.begin(), lineFromFile.end(), ',', ' ');
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user