diff --git a/ct2foam.C b/ct2foam.C index 5a8b80e..dd69775 100644 --- a/ct2foam.C +++ b/ct2foam.C @@ -166,6 +166,13 @@ std::string ofReactionString (const std::shared_ptr 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(); + + 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 =============================================================