Commit 4779e020 authored by Matthias Toggweiler's avatar Matthias Toggweiler
Browse files

Introduce OpalData::getInputBasename() because inputname without trailing ".in" used so frequently

parent 28ea173f
...@@ -948,9 +948,7 @@ void PartBunch::computeSelfFields() { ...@@ -948,9 +948,7 @@ void PartBunch::computeSelfFields() {
std::ostringstream istr; std::ostringstream istr;
istr << fieldDBGStep_m; istr << fieldDBGStep_m;
string SfileName = OpalData::getInstance()->getInputFn(); string SfileName = OpalData::getInstance()->getInputBasename();
int pdot = SfileName.find(string("."), 0);
SfileName.erase(pdot, SfileName.size() - pdot);
string rho_fn = string("fields/") + SfileName + string("-rho_scalar-") + string(istr.str()); string rho_fn = string("fields/") + SfileName + string("-rho_scalar-") + string(istr.str());
fstr2.open(rho_fn.c_str(), ios::out); fstr2.open(rho_fn.c_str(), ios::out);
......
...@@ -591,6 +591,11 @@ string OpalData::getInputFn() { ...@@ -591,6 +591,11 @@ string OpalData::getInputFn() {
return p->inputFn; return p->inputFn;
} }
std::string OpalData::getInputBasename() {
std::string & fn = p->inputFn;
int const pdot = fn.rfind(".");
return fn.substr(0, pdot);
}
void OpalData::update() { void OpalData::update() {
Inform msg("OpalData "); Inform msg("OpalData ");
......
...@@ -151,6 +151,9 @@ public: ...@@ -151,6 +151,9 @@ public:
/// get opals input filename /// get opals input filename
std::string getInputFn(); std::string getInputFn();
/// get input file name without extension
std::string getInputBasename();
/// store opals input filename /// store opals input filename
void storeInputFn(const std::string &fn); void storeInputFn(const std::string &fn);
......
...@@ -904,7 +904,7 @@ void ParallelCyclotronTracker::Tracker_LF() { ...@@ -904,7 +904,7 @@ void ParallelCyclotronTracker::Tracker_LF() {
// for single Particle Mode, output at zero degree. // for single Particle Mode, output at zero degree.
if(initialTotalNum_m == 1) if(initialTotalNum_m == 1)
openFiles(inputFileNameWithoutExtension()); openFiles(OpalData::getInstance()->getInputBasename());
double const initialReferenceTheta = referenceTheta / 180.0 * pi; double const initialReferenceTheta = referenceTheta / 180.0 * pi;
...@@ -1456,7 +1456,7 @@ void ParallelCyclotronTracker::Tracker_RK4() { ...@@ -1456,7 +1456,7 @@ void ParallelCyclotronTracker::Tracker_RK4() {
// for single Particle Mode, output at zero degree. // for single Particle Mode, output at zero degree.
if(initialTotalNum_m == 1) if(initialTotalNum_m == 1)
openFiles(inputFileNameWithoutExtension()); openFiles(OpalData::getInstance()->getInputBasename());
initDistInGlobalFrame(); initDistInGlobalFrame();
...@@ -2853,7 +2853,7 @@ void ParallelCyclotronTracker::Tracker_MTS() { ...@@ -2853,7 +2853,7 @@ void ParallelCyclotronTracker::Tracker_MTS() {
// for single Particle Mode, output at zero degree. // for single Particle Mode, output at zero degree.
if(initialTotalNum_m == 1) { if(initialTotalNum_m == 1) {
openFiles(inputFileNameWithoutExtension()); openFiles(OpalData::getInstance()->getInputBasename());
} }
initDistInGlobalFrame(); initDistInGlobalFrame();
...@@ -3431,7 +3431,7 @@ bool ParallelCyclotronTracker::applyPluginElements(const double dt) { ...@@ -3431,7 +3431,7 @@ bool ParallelCyclotronTracker::applyPluginElements(const double dt) {
} }
void ParallelCyclotronTracker::initTrackOrbitFile() { void ParallelCyclotronTracker::initTrackOrbitFile() {
std::string f = inputFileNameWithoutExtension() + string("-trackOrbit.dat"); std::string f = OpalData::getInstance()->getInputBasename() + string("-trackOrbit.dat");
outfTrackOrbit_m.setf(ios::scientific, ios::floatfield); outfTrackOrbit_m.setf(ios::scientific, ios::floatfield);
outfTrackOrbit_m.precision(8); outfTrackOrbit_m.precision(8);
if(myNode_m == 0) { if(myNode_m == 0) {
...@@ -3445,12 +3445,6 @@ void ParallelCyclotronTracker::initTrackOrbitFile() { ...@@ -3445,12 +3445,6 @@ void ParallelCyclotronTracker::initTrackOrbitFile() {
} }
} }
std::string ParallelCyclotronTracker::inputFileNameWithoutExtension() {
std::string f = OpalData::getInstance()->getInputFn();
int const pdot = f.find(string("."), 0);
return f.erase(pdot, f.size() - pdot);
}
void ParallelCyclotronTracker::initDistInGlobalFrame() { void ParallelCyclotronTracker::initDistInGlobalFrame() {
if(!OpalData::getInstance()->inRestartRun()) { if(!OpalData::getInstance()->inRestartRun()) {
double const initialReferenceTheta = referenceTheta / 180.0 * pi; double const initialReferenceTheta = referenceTheta / 180.0 * pi;
......
...@@ -342,8 +342,6 @@ private: ...@@ -342,8 +342,6 @@ private:
void initTrackOrbitFile(); void initTrackOrbitFile();
std::string inputFileNameWithoutExtension();
void singleParticleDump(); void singleParticleDump();
void evaluateSpaceChargeField(); void evaluateSpaceChargeField();
......
...@@ -169,10 +169,7 @@ ParallelTTracker::ParallelTTracker(const Beamline &beamline, ...@@ -169,10 +169,7 @@ ParallelTTracker::ParallelTTracker(const Beamline &beamline,
// itsBeamline = dynamic_cast<Beamline*>(beamline.clone()); // itsBeamline = dynamic_cast<Beamline*>(beamline.clone());
#ifdef DBG_SYM #ifdef DBG_SYM
string SfileName = OpalData::getInstance()->getInputFn(); string fn = OpalData::getInstance()->getInputBasename() + string(".fields");
int pdot = SfileName.find(string("."), 0);
SfileName.erase(pdot, SfileName.size() - pdot);
string fn = SfileName + string(".fields");
of_m.open(fn.c_str(), ios::out); of_m.open(fn.c_str(), ios::out);
of_m.precision(9); of_m.precision(9);
of_m << "# spos Ex Ey Ez Bz By Bz at: (h,h),(h,-h),(-h,h)(-h,-h) h=0.001" << endl; of_m << "# spos Ex Ey Ez Bz By Bz at: (h,h),(h,-h),(-h,h)(-h,-h) h=0.001" << endl;
......
...@@ -1432,11 +1432,8 @@ void Distribution::doRestartEnvelope(EnvelopeBunch &beam, size_t Np, int restart ...@@ -1432,11 +1432,8 @@ void Distribution::doRestartEnvelope(EnvelopeBunch &beam, size_t Np, int restart
*gmsg << "Restart from a specified file:" << fn << endl; *gmsg << "Restart from a specified file:" << fn << endl;
} else { } else {
fn = OpalData::getInstance()->getInputFn();
int pos = fn.find(string("."), 0);
fn.erase(pos, fn.size() - pos);
// beam.setTEmission(Attributes::getReal(itsAttr[TEMISSION])); // beam.setTEmission(Attributes::getReal(itsAttr[TEMISSION]));
fn += string(".h5"); fn = OpalData::getInstance()->getInputBasename() + string(".h5");
} }
#ifdef PARALLEL_IO #ifdef PARALLEL_IO
...@@ -2600,11 +2597,8 @@ void Distribution::doRestart(PartBunch &beam, size_t Np, int restartStep) { ...@@ -2600,11 +2597,8 @@ void Distribution::doRestart(PartBunch &beam, size_t Np, int restartStep) {
IpplTimings::startTimer(beam.distrReload_m); IpplTimings::startTimer(beam.distrReload_m);
fn = OpalData::getInstance()->getInputFn();
int pos = fn.find(string("."), 0);
fn.erase(pos, fn.size() - pos);
// beam.setTEmission(Attributes::getReal(itsAttr[TEMISSION])); // beam.setTEmission(Attributes::getReal(itsAttr[TEMISSION]));
fn += string(".h5"); fn = OpalData::getInstance()->getInputBasename() + string(".h5");
#ifdef PARALLEL_IO #ifdef PARALLEL_IO
H5file = H5OpenFile(fn.c_str(), H5_O_RDONLY, Ippl::getComm()); H5file = H5OpenFile(fn.c_str(), H5_O_RDONLY, Ippl::getComm());
...@@ -2760,10 +2754,7 @@ void Distribution::doRestart_cycl(PartBunch &beam, size_t Np, int restartStep, c ...@@ -2760,10 +2754,7 @@ void Distribution::doRestart_cycl(PartBunch &beam, size_t Np, int restartStep, c
*gmsg << "---------------- Start reading hdf5 file----------------" << endl; *gmsg << "---------------- Start reading hdf5 file----------------" << endl;
h5_file_t *H5file; h5_file_t *H5file;
string fn = OpalData::getInstance()->getInputFn(); string fn = OpalData::getInstance()->getInputBasename() + string(".h5");
int pos = fn.find(string("."), 0);
fn.erase(pos, fn.size() - pos);
fn += string(".h5");
#ifdef PARALLEL_IO #ifdef PARALLEL_IO
H5file = H5OpenFile(fn.c_str(), H5_O_RDONLY, Ippl::getComm()); H5file = H5OpenFile(fn.c_str(), H5_O_RDONLY, Ippl::getComm());
......
...@@ -150,11 +150,7 @@ DataSink::DataSink() : ...@@ -150,11 +150,7 @@ DataSink::DataSink() :
firstWriteH5part_m = true; firstWriteH5part_m = true;
firstWriteH5Surface_m = true; firstWriteH5Surface_m = true;
/// Define file names. /// Define file names.
string fn = OpalData::getInstance()->getInputFn(); string fn = OpalData::getInstance()->getInputBasename();
int pos = fn.find(string("."), 0);
fn.erase(pos, fn.size() - pos);
surfacLossFileName_m = fn + string(".SurfaceLoss.h5"); surfacLossFileName_m = fn + string(".SurfaceLoss.h5");
statFileName_m = fn + string(".stat"); statFileName_m = fn + string(".stat");
lBalFileName_m = fn + string(".lbal"); lBalFileName_m = fn + string(".lbal");
...@@ -196,10 +192,7 @@ DataSink::DataSink(int restartStep) : ...@@ -196,10 +192,7 @@ DataSink::DataSink(int restartStep) :
firstWriteToStat_m = true; firstWriteToStat_m = true;
firstWriteH5part_m = false; firstWriteH5part_m = false;
/// Get file name root. /// Get file name root.
string fn = OpalData::getInstance()->getInputFn(); string fn = OpalData::getInstance()->getInputBasename();
int pos = fn.find(string(".in"), 0);
fn.erase(pos, fn.size() - pos);
statFileName_m = fn + string(".stat"); statFileName_m = fn + string(".stat");
lBalFileName_m = fn + string(".lbal"); lBalFileName_m = fn + string(".lbal");
...@@ -2446,9 +2439,7 @@ void DataSink::writeGeomToVtk(BoundaryGeometry &bg, string fn) { ...@@ -2446,9 +2439,7 @@ void DataSink::writeGeomToVtk(BoundaryGeometry &bg, string fn) {
void DataSink::storeOneBunch(const PartBunch &beam, const string fn_appendix) { void DataSink::storeOneBunch(const PartBunch &beam, const string fn_appendix) {
h5_int64_t rc; h5_int64_t rc;
/// Define file names. /// Define file names.
string fn = OpalData::getInstance()->getInputFn(); string fn = OpalData::getInstance()->getInputBasename();
int pos = fn.find(string("."), 0);
fn.erase(pos, fn.size() - pos);
fn = fn + fn_appendix + string(".h5"); fn = fn + fn_appendix + string(".h5");
h5_file_t *H5file; h5_file_t *H5file;
...@@ -2583,9 +2574,7 @@ void DataSink::storeOneBunch(const PartBunch &beam, const string fn_appendix) { ...@@ -2583,9 +2574,7 @@ void DataSink::storeOneBunch(const PartBunch &beam, const string fn_appendix) {
bool DataSink::readOneBunch(PartBunch &beam, const string fn_appendix, const size_t BinID) { bool DataSink::readOneBunch(PartBunch &beam, const string fn_appendix, const size_t BinID) {
h5_int64_t rc; h5_int64_t rc;
/// Define file names. /// Define file names.
string fn = OpalData::getInstance()->getInputFn(); string fn = OpalData::getInstance()->getInputBasename();
int pos = fn.find(string("."), 0);
fn.erase(pos, fn.size() - pos);
fn = fn + fn_appendix + string(".h5"); fn = fn + fn_appendix + string(".h5");
h5_file_t *H5file; h5_file_t *H5file;
......
...@@ -27,10 +27,7 @@ public: ...@@ -27,10 +27,7 @@ public:
element_m("NULL"), element_m("NULL"),
doHdf5Save_m(hdf5Save) { doHdf5Save_m(hdf5Save) {
if(!doHdf5Save_m) { if(!doHdf5Save_m) {
fn_m = OpalData::getInstance()->getInputFn(); fn_m = OpalData::getInstance()->getInputBasename() + std::string(".loss");
int pos = fn_m.find(std::string("."), 0);
fn_m.erase(pos, fn_m.size() - pos);
fn_m += std::string(".loss");
os_m.precision(8); os_m.precision(8);
os_m.setf(std::ios::scientific, std::ios::floatfield); os_m.setf(std::ios::scientific, std::ios::floatfield);
if(OpalData::getInstance()->inRestartRun()) if(OpalData::getInstance()->inRestartRun())
...@@ -47,10 +44,7 @@ public: ...@@ -47,10 +44,7 @@ public:
LossDataSink(): LossDataSink():
element_m("NULL") { element_m("NULL") {
if(!doHdf5Save_m) { if(!doHdf5Save_m) {
fn_m = OpalData::getInstance()->getInputFn(); fn_m = OpalData::getInstance()->getInputBasename() + std::string(".loss");
int pos = fn_m.find(std::string("."), 0);
fn_m.erase(pos, fn_m.size() - pos);
fn_m += std::string(".loss");
os_m.precision(8); os_m.precision(8);
os_m.setf(std::ios::scientific, std::ios::floatfield); os_m.setf(std::ios::scientific, std::ios::floatfield);
append(); append();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment