Using stringstream and bugfixing using c_str(). Compatible with kalinka now
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
#include <deque>
|
#include <deque>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
|
|||||||
@@ -223,32 +223,34 @@ void Simulation::initLogger(void) {
|
|||||||
|
|
||||||
for (int i = 0; i < numberZBins; i++)
|
for (int i = 0; i < numberZBins; i++)
|
||||||
{
|
{
|
||||||
string fileName = dirname + "/z=" + to_string(zLogValues[i]) + ".dat";
|
stringstream fileName;
|
||||||
outStream[i].open(fileName);
|
fileName << dirname << "/z=" << zLogValues[i] << ".dat";
|
||||||
|
outStream[i].open(fileName.str().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
string Simulation::getDirName() {
|
string Simulation::getDirName() {
|
||||||
string poub = getenv("poub");
|
string poub = getenv("poub");
|
||||||
string pname = getenv("pname");
|
string pname = getenv("pname");
|
||||||
int i = 1;
|
int i = 1;
|
||||||
string dirname;
|
stringstream dirname;
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
int isDir;
|
int isDir;
|
||||||
do {
|
do {
|
||||||
dirname = poub + "/" + pname + "_" + getTimeString() + "_" + to_string(i++);
|
dirname.clear();
|
||||||
|
dirname << poub << "/" << pname << "_" << getTimeString() << "_" << i++;
|
||||||
isDir = 0;
|
isDir = 0;
|
||||||
if (stat(dirname.c_str(), &statbuf) != -1) {
|
if (stat(dirname.str().c_str(), &statbuf) != -1) {
|
||||||
if (S_ISDIR(statbuf.st_mode)) {
|
if (S_ISDIR(statbuf.st_mode)) {
|
||||||
isDir = 1;
|
isDir = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while ( isDir == 1 );
|
} while ( isDir == 1 );
|
||||||
|
|
||||||
if (mkdir(dirname.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) {
|
if (mkdir(dirname.str().c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) {
|
||||||
cerr<<"Simulation::initLogger: Could not create folder "<<dirname.c_str()<<" for Logging."<<endl;
|
cerr<<"Simulation::initLogger: Could not create folder "<<dirname.str()<<" for Logging."<<endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
return(dirname);
|
return(dirname.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
string Simulation::getTimeString() {
|
string Simulation::getTimeString() {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ void runTests() {
|
|||||||
|
|
||||||
void TestSimulation::injection (int numParticles, string outputFilePath) {
|
void TestSimulation::injection (int numParticles, string outputFilePath) {
|
||||||
ofstream outFile;
|
ofstream outFile;
|
||||||
outFile.open (outputFilePath);
|
outFile.open (outputFilePath.c_str());
|
||||||
for (int i = 0;i<numParticles;i++) {
|
for (int i = 0;i<numParticles;i++) {
|
||||||
outFile << inject() <<endl;
|
outFile << inject() <<endl;
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ void TestSimulation::injection (int numParticles, string outputFilePath) {
|
|||||||
|
|
||||||
void TestSimulation::decaySpectrum (int numPoints,string outputFilePath) {
|
void TestSimulation::decaySpectrum (int numPoints,string outputFilePath) {
|
||||||
ofstream outFile;
|
ofstream outFile;
|
||||||
outFile.open (outputFilePath);
|
outFile.open (outputFilePath.c_str());
|
||||||
double x,y;
|
double x,y;
|
||||||
for (int i = 0;i<numPoints;i++) {
|
for (int i = 0;i<numPoints;i++) {
|
||||||
x = i * Etridecay_eV/(numPoints-1);
|
x = i * Etridecay_eV/(numPoints-1);
|
||||||
@@ -40,7 +40,7 @@ void TestSimulation::decaySpectrum (int numPoints,string outputFilePath) {
|
|||||||
|
|
||||||
void TestSimulation::rejectionBetaDecay(int numDecays, string outputFilePath) {
|
void TestSimulation::rejectionBetaDecay(int numDecays, string outputFilePath) {
|
||||||
ofstream outFile;
|
ofstream outFile;
|
||||||
outFile.open (outputFilePath);
|
outFile.open (outputFilePath.c_str());
|
||||||
for (int i = 0;i<numDecays;i++) {
|
for (int i = 0;i<numDecays;i++) {
|
||||||
outFile << getBetaDecayEnergyRejection_eV() <<endl;
|
outFile << getBetaDecayEnergyRejection_eV() <<endl;
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ void TestSimulation::rejectionBetaDecay(int numDecays, string outputFilePath) {
|
|||||||
|
|
||||||
void TestSimulation::maxwellBoltzmann(int numDecays, string outputFilePath) {
|
void TestSimulation::maxwellBoltzmann(int numDecays, string outputFilePath) {
|
||||||
ofstream outFile;
|
ofstream outFile;
|
||||||
outFile.open (outputFilePath);
|
outFile.open (outputFilePath.c_str());
|
||||||
for (int i = 0;i<numDecays;i++) {
|
for (int i = 0;i<numDecays;i++) {
|
||||||
//outFile << getEnergyBoltzmann_eV() <<endl;
|
//outFile << getEnergyBoltzmann_eV() <<endl;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user