Prevent overwrite by default and can be overriden with cmdline option
This commit is contained in:
parent
e9252cb06a
commit
663384bf3b
1 changed files with 27 additions and 3 deletions
30
ct2foam.C
30
ct2foam.C
|
|
@ -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 =============================================================
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue