Prevent overwrite by default and can be overriden with cmdline option

This commit is contained in:
Yeongdo Park 2018-11-10 08:36:29 -05:00
parent e9252cb06a
commit 663384bf3b

View file

@ -166,6 +166,13 @@ std::string ofReactionString (const std::shared_ptr<Cantera::Reaction> r)
}
bool is_file_exist(const std::string &fileName)
{
std::ifstream infile(fileName);
return infile.good();
}
int main(int argc, char *argv[])
{
@ -179,9 +186,9 @@ int main(int argc, char *argv[])
std::ofstream fthermo;
std::ofstream frxn;
options.add_options()
("name", "Name of ideal gas mix in CTI file", cxxopts::value(sgas))
("w,overwrite", "Overwrite exsisting files")
("h,help", "print help message")
;
@ -218,9 +225,26 @@ int main(int argc, char *argv[])
Cantera::IdealGasMix gas_(scti, sgas);
fthermo.open(sthermo);
bool overwrite = result["overwrite"].as<bool>();
if (is_file_exist(sthermo) && (!overwrite))
{
throw std::system_error(EEXIST, std::system_category(), sthermo);
}
else
{
fthermo.open(sthermo);
}
if (is_file_exist(srxn) && (!overwrite))
{
throw std::system_error(EEXIST, std::system_category(), srxn);
}
else
{
frxn.open(srxn);
}
frxn.open(srxn);
// Thermo Part =============================================================