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() {
std::ostringstream istr;
istr << fieldDBGStep_m;
string SfileName = OpalData::getInstance()->getInputFn();
int pdot = SfileName.find(string("."), 0);
SfileName.erase(pdot, SfileName.size() - pdot);
string SfileName = OpalData::getInstance()->getInputBasename();
string rho_fn = string("fields/") + SfileName + string("-rho_scalar-") + string(istr.str());
fstr2.open(rho_fn.c_str(), ios::out);
......
......@@ -591,6 +591,11 @@ string OpalData::getInputFn() {
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() {
Inform msg("OpalData ");
......
......@@ -151,6 +151,9 @@ public:
/// get opals input filename
std::string getInputFn();
/// get input file name without extension
std::string getInputBasename();
/// store opals input filename
void storeInputFn(const std::string &fn);
......
......@@ -904,7 +904,7 @@ void ParallelCyclotronTracker::Tracker_LF() {
// for single Particle Mode, output at zero degree.
if(initialTotalNum_m == 1)
openFiles(inputFileNameWithoutExtension());
openFiles(OpalData::getInstance()->getInputBasename());
double const initialReferenceTheta = referenceTheta / 180.0 * pi;
......@@ -1456,7 +1456,7 @@ void ParallelCyclotronTracker::Tracker_RK4() {
// for single Particle Mode, output at zero degree.
if(initialTotalNum_m == 1)
openFiles(inputFileNameWithoutExtension());
openFiles(OpalData::getInstance()->getInputBasename());
initDistInGlobalFrame();
......@@ -2853,7 +2853,7 @@ void ParallelCyclotronTracker::Tracker_MTS() {
// for single Particle Mode, output at zero degree.
if(initialTotalNum_m == 1) {
openFiles(inputFileNameWithoutExtension());
openFiles(OpalData::getInstance()->getInputBasename());
}
initDistInGlobalFrame();
......@@ -3431,7 +3431,7 @@ bool ParallelCyclotronTracker::applyPluginElements(const double dt) {
}
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.precision(8);
if(myNode_m == 0) {
......@@ -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() {
if(!OpalData::getInstance()->inRestartRun()) {
double const initialReferenceTheta = referenceTheta / 180.0 * pi;
......
......@@ -342,8 +342,6 @@ private:
void initTrackOrbitFile();
std::string inputFileNameWithoutExtension();
void singleParticleDump();
void evaluateSpaceChargeField();
......
......@@ -169,10 +169,7 @@ ParallelTTracker::ParallelTTracker(const Beamline &beamline,
// itsBeamline = dynamic_cast<Beamline*>(beamline.clone());
#ifdef DBG_SYM
string SfileName = OpalData::getInstance()->getInputFn();
int pdot = SfileName.find(string("."), 0);
SfileName.erase(pdot, SfileName.size() - pdot);
string fn = SfileName + string(".fields");
string fn = OpalData::getInstance()->getInputBasename() + string(".fields");
of_m.open(fn.c_str(), ios::out);
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;
......
......@@ -1432,11 +1432,8 @@ void Distribution::doRestartEnvelope(EnvelopeBunch &beam, size_t Np, int restart
*gmsg << "Restart from a specified file:" << fn << endl;
} else {
fn = OpalData::getInstance()->getInputFn();
int pos = fn.find(string("."), 0);
fn.erase(pos, fn.size() - pos);
// beam.setTEmission(Attributes::getReal(itsAttr[TEMISSION]));
fn += string(".h5");
fn = OpalData::getInstance()->getInputBasename() + string(".h5");
}
#ifdef PARALLEL_IO
......@@ -2600,11 +2597,8 @@ void Distribution::doRestart(PartBunch &beam, size_t Np, int restartStep) {
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]));
fn += string(".h5");
fn = OpalData::getInstance()->getInputBasename() + string(".h5");
#ifdef PARALLEL_IO
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
*gmsg << "---------------- Start reading hdf5 file----------------" << endl;
h5_file_t *H5file;
string fn = OpalData::getInstance()->getInputFn();
int pos = fn.find(string("."), 0);
fn.erase(pos, fn.size() - pos);
fn += string(".h5");
string fn = OpalData::getInstance()->getInputBasename() + string(".h5");
#ifdef PARALLEL_IO
H5file = H5OpenFile(fn.c_str(), H5_O_RDONLY, Ippl::getComm());
......
......@@ -150,11 +150,7 @@ DataSink::DataSink() :
firstWriteH5part_m = true;
firstWriteH5Surface_m = true;
/// Define file names.
string fn = OpalData::getInstance()->getInputFn();
int pos = fn.find(string("."), 0);
fn.erase(pos, fn.size() - pos);
string fn = OpalData::getInstance()->getInputBasename();
surfacLossFileName_m = fn + string(".SurfaceLoss.h5");
statFileName_m = fn + string(".stat");
lBalFileName_m = fn + string(".lbal");
......@@ -196,10 +192,7 @@ DataSink::DataSink(int restartStep) :
firstWriteToStat_m = true;
firstWriteH5part_m = false;
/// Get file name root.
string fn = OpalData::getInstance()->getInputFn();
int pos = fn.find(string(".in"), 0);
fn.erase(pos, fn.size() - pos);
string fn = OpalData::getInstance()->getInputBasename();
statFileName_m = fn + string(".stat");
lBalFileName_m = fn + string(".lbal");
......@@ -2446,9 +2439,7 @@ void DataSink::writeGeomToVtk(BoundaryGeometry &bg, string fn) {
void DataSink::storeOneBunch(const PartBunch &beam, const string fn_appendix) {
h5_int64_t rc;
/// Define file names.
string fn = OpalData::getInstance()->getInputFn();
int pos = fn.find(string("."), 0);
fn.erase(pos, fn.size() - pos);
string fn = OpalData::getInstance()->getInputBasename();
fn = fn + fn_appendix + string(".h5");
h5_file_t *H5file;
......@@ -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) {
h5_int64_t rc;
/// Define file names.
string fn = OpalData::getInstance()->getInputFn();
int pos = fn.find(string("."), 0);
fn.erase(pos, fn.size() - pos);
string fn = OpalData::getInstance()->getInputBasename();
fn = fn + fn_appendix + string(".h5");
h5_file_t *H5file;
......
......@@ -27,10 +27,7 @@ public:
element_m("NULL"),
doHdf5Save_m(hdf5Save) {
if(!doHdf5Save_m) {
fn_m = OpalData::getInstance()->getInputFn();
int pos = fn_m.find(std::string("."), 0);
fn_m.erase(pos, fn_m.size() - pos);
fn_m += std::string(".loss");
fn_m = OpalData::getInstance()->getInputBasename() + std::string(".loss");
os_m.precision(8);
os_m.setf(std::ios::scientific, std::ios::floatfield);
if(OpalData::getInstance()->inRestartRun())
......@@ -47,10 +44,7 @@ public:
LossDataSink():
element_m("NULL") {
if(!doHdf5Save_m) {
fn_m = OpalData::getInstance()->getInputFn();
int pos = fn_m.find(std::string("."), 0);
fn_m.erase(pos, fn_m.size() - pos);
fn_m += std::string(".loss");
fn_m = OpalData::getInstance()->getInputBasename() + std::string(".loss");
os_m.precision(8);
os_m.setf(std::ios::scientific, std::ios::floatfield);
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