diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 45b8d3414..2392fa88d 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -63,6 +63,7 @@ list (APPEND MAIN_SOURCE_FILES opm/polymer/TransportSolverTwophasePolymer.cpp opm/polymer/fullyimplicit/FullyImplicitCompressiblePolymerSolver.cpp opm/polymer/fullyimplicit/PolymerPropsAd.cpp + opm/simulators/ensureDirectoryExists.cpp opm/simulators/SimulatorCompressibleTwophase.cpp opm/simulators/SimulatorIncompTwophase.cpp opm/simulators/WellSwitchingLogger.cpp @@ -258,6 +259,7 @@ list (APPEND PUBLIC_HEADER_FILES opm/polymer/fullyimplicit/SimulatorFullyImplicitBlackoilPolymer.hpp opm/polymer/fullyimplicit/SimulatorFullyImplicitBlackoilPolymer_impl.hpp opm/polymer/fullyimplicit/WellStateFullyImplicitBlackoilPolymer.hpp + opm/simulators/ensureDirectoryExists.hpp opm/simulators/ParallelFileMerger.hpp opm/simulators/SimulatorCompressibleTwophase.hpp opm/simulators/SimulatorIncompTwophase.hpp diff --git a/examples/sim_2p_comp_reorder.cpp b/examples/sim_2p_comp_reorder.cpp index 67f2a7b01..b8c7b9342 100644 --- a/examples/sim_2p_comp_reorder.cpp +++ b/examples/sim_2p_comp_reorder.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -195,13 +196,7 @@ try if (output) { output_dir = param.getDefault("output_dir", std::string("output")); - boost::filesystem::path fpath(output_dir); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(output_dir); std::string filename = output_dir + "/epoch_timing.param"; epoch_os.open(filename.c_str(), std::fstream::trunc | std::fstream::out); // open file to clean it. The file is appended to in SimulatorTwophase diff --git a/examples/sim_2p_incomp.cpp b/examples/sim_2p_incomp.cpp index 6363042f7..3a03146bb 100644 --- a/examples/sim_2p_incomp.cpp +++ b/examples/sim_2p_incomp.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -210,13 +211,7 @@ try if (output) { output_dir = param.getDefault("output_dir", std::string("output")); - boost::filesystem::path fpath(output_dir); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(output_dir); std::string filename = output_dir + "/epoch_timing.param"; epoch_os.open(filename.c_str(), std::fstream::trunc | std::fstream::out); // open file to clean it. The file is appended to in SimulatorTwophase diff --git a/examples/sim_2p_incomp_ad.cpp b/examples/sim_2p_incomp_ad.cpp index 2e6be36df..6fbb6b046 100644 --- a/examples/sim_2p_incomp_ad.cpp +++ b/examples/sim_2p_incomp_ad.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #include @@ -212,13 +213,7 @@ try if (output) { output_dir = param.getDefault("output_dir", std::string("output")); - boost::filesystem::path fpath(output_dir); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(output_dir); std::string filename = output_dir + "/epoch_timing.param"; epoch_os.open(filename.c_str(), std::fstream::trunc | std::fstream::out); // open file to clean it. The file is appended to in SimulatorTwophase diff --git a/examples/sim_poly2p_comp_reorder.cpp b/examples/sim_poly2p_comp_reorder.cpp index acddeb9cf..a17e226ea 100644 --- a/examples/sim_poly2p_comp_reorder.cpp +++ b/examples/sim_poly2p_comp_reorder.cpp @@ -51,6 +51,8 @@ #include #include +#include + #include #include @@ -224,13 +226,7 @@ try if (output) { std::string output_dir = param.getDefault("output_dir", std::string("output")); - boost::filesystem::path fpath(output_dir); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(output_dir); param.writeParam(output_dir + "/simulation.param"); } diff --git a/examples/sim_poly2p_incomp_reorder.cpp b/examples/sim_poly2p_incomp_reorder.cpp index d0b327eb6..f5b7aaf95 100644 --- a/examples/sim_poly2p_incomp_reorder.cpp +++ b/examples/sim_poly2p_incomp_reorder.cpp @@ -51,6 +51,8 @@ #include #include +#include + #include #include @@ -256,13 +258,7 @@ try if (output) { std::string output_dir = param.getDefault("output_dir", std::string("output")); - boost::filesystem::path fpath(output_dir); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(output_dir); param.writeParam(output_dir + "/simulation.param"); } diff --git a/examples/sim_poly_fi2p_comp_ad.cpp b/examples/sim_poly_fi2p_comp_ad.cpp index 5cffd14ed..09833b482 100644 --- a/examples/sim_poly_fi2p_comp_ad.cpp +++ b/examples/sim_poly_fi2p_comp_ad.cpp @@ -70,6 +70,8 @@ #include #include +#include + #include #include @@ -128,14 +130,7 @@ try // Create output directory if needed. output_dir = param.getDefault("output_dir", std::string("output")); - boost::filesystem::path fpath(output_dir); - try { - create_directories(fpath); - } - catch (...) { - std::cerr << "Creating directories failed: " << fpath << std::endl; - return EXIT_FAILURE; - } + ensureDirectoryExists(output_dir); // Write simulation parameters. param.writeParam(output_dir + "/simulation.param"); } diff --git a/opm/autodiff/FlowMain.hpp b/opm/autodiff/FlowMain.hpp index 407cf3dbb..a041c338f 100644 --- a/opm/autodiff/FlowMain.hpp +++ b/opm/autodiff/FlowMain.hpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -378,15 +379,7 @@ namespace Opm // Write parameters used for later reference. (only if rank is zero) if (output_to_files_) { // Create output directory if needed. - boost::filesystem::path fpath(output_dir_); - if (!is_directory(fpath)) { - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } - } + ensureDirectoryExists(output_dir_); // Write simulation parameters. param_.writeParam(output_dir_ + "/simulation.param"); } diff --git a/opm/autodiff/FlowMainEbos.hpp b/opm/autodiff/FlowMainEbos.hpp index 9f2a2e4ad..981efe273 100644 --- a/opm/autodiff/FlowMainEbos.hpp +++ b/opm/autodiff/FlowMainEbos.hpp @@ -24,6 +24,7 @@ #define OPM_FLOW_MAIN_EBOS_HEADER_INCLUDED #include +#include #include #include @@ -263,15 +264,7 @@ namespace Opm // Write parameters used for later reference. (only if rank is zero) if (output_to_files_) { // Create output directory if needed. - boost::filesystem::path fpath(output_dir_); - if (!is_directory(fpath)) { - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } - } + ensureDirectoryExists(output_dir_); // Write simulation parameters. param_.writeParam(output_dir_ + "/simulation.param"); } diff --git a/opm/autodiff/SimulatorFullyImplicitBlackoilOutput.cpp b/opm/autodiff/SimulatorFullyImplicitBlackoilOutput.cpp index e8b10060e..51124528e 100644 --- a/opm/autodiff/SimulatorFullyImplicitBlackoilOutput.cpp +++ b/opm/autodiff/SimulatorFullyImplicitBlackoilOutput.cpp @@ -66,13 +66,7 @@ namespace Opm // Write data in VTK format. std::ostringstream vtkfilename; vtkfilename << output_dir << "/vtk_files"; - boost::filesystem::path fpath(vtkfilename.str()); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(vtkfilename.str()); vtkfilename << "/output-" << std::setw(3) << std::setfill('0') << step << ".vtu"; std::ofstream vtkfile(vtkfilename.str().c_str()); if (!vtkfile) { @@ -106,13 +100,7 @@ namespace Opm for (Opm::DataMap::const_iterator it = dm.begin(); it != dm.end(); ++it) { std::ostringstream fname; fname << output_dir << "/" << it->first; - boost::filesystem::path fpath = fname.str(); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error,"Creating directories failed: " << fpath); - } + ensureDirectoryExists(fname.str()); fname << "/" << std::setw(3) << std::setfill('0') << step << ".txt"; std::ofstream file(fname.str().c_str()); if (!file) { @@ -161,13 +149,7 @@ namespace Opm std::ostringstream vtkpath; vtkpath << output_dir << "/vtk_files"; vtkpath << "/output-" << std::setw(3) << std::setfill('0') << step; - boost::filesystem::path fpath(vtkpath.str()); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(vtkpath.str()); vtkfilename << "output-" << std::setw(3) << std::setfill('0') << step; #if DUNE_VERSION_NEWER(DUNE_GRID, 2, 3) Dune::VTKWriter writer(grid.leafGridView(), Dune::VTK::nonconforming); diff --git a/opm/autodiff/SimulatorFullyImplicitBlackoilOutput.hpp b/opm/autodiff/SimulatorFullyImplicitBlackoilOutput.hpp index 209eb3fef..a9876609e 100644 --- a/opm/autodiff/SimulatorFullyImplicitBlackoilOutput.hpp +++ b/opm/autodiff/SimulatorFullyImplicitBlackoilOutput.hpp @@ -44,7 +44,7 @@ #include #include - +#include #include #include @@ -123,13 +123,7 @@ namespace Opm for (Opm::DataMap::const_iterator it = dm.begin(); it != dm.end(); ++it) { std::ostringstream fname; fname << output_dir << "/" << it->first; - boost::filesystem::path fpath = fname.str(); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(fname.str()); fname << "/" << std::setw(3) << std::setfill('0') << step << ".txt"; std::ofstream file(fname.str().c_str()); if (!file) { @@ -376,13 +370,7 @@ namespace Opm eclIO_ = std::move(eclIO); // Ensure that output dir exists - boost::filesystem::path fpath(outputDir_); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(outputDir_); // create output thread if enabled and rank is I/O rank // async output is enabled by default if pthread are enabled diff --git a/opm/autodiff/SimulatorIncompTwophaseAd.cpp b/opm/autodiff/SimulatorIncompTwophaseAd.cpp index 2c73e1686..f21acab06 100644 --- a/opm/autodiff/SimulatorIncompTwophaseAd.cpp +++ b/opm/autodiff/SimulatorIncompTwophaseAd.cpp @@ -51,6 +51,8 @@ #include #include #include +#include + #include #include @@ -177,13 +179,7 @@ namespace Opm // Write data in VTK format. std::ostringstream vtkfilename; vtkfilename << output_dir << "/vtk_files"; - boost::filesystem::path fpath(vtkfilename.str()); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(vtkfilename.str()); vtkfilename << "/output-" << std::setw(3) << std::setfill('0') << step << ".vtu"; std::ofstream vtkfile(vtkfilename.str().c_str()); if (!vtkfile) { @@ -205,13 +201,7 @@ namespace Opm { std::ostringstream fname; fname << output_dir << "/" << name; - boost::filesystem::path fpath = fname.str(); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(fname.str()); fname << "/" << std::setw(3) << std::setfill('0') << step << ".txt"; std::ofstream file(fname.str().c_str()); if (!file) { @@ -236,13 +226,7 @@ namespace Opm for (Opm::DataMap::const_iterator it = dm.begin(); it != dm.end(); ++it) { std::ostringstream fname; fname << output_dir << "/" << it->first; - boost::filesystem::path fpath = fname.str(); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(fname.str()); fname << "/" << std::setw(3) << std::setfill('0') << step << ".txt"; std::ofstream file(fname.str().c_str()); if (!file) { @@ -384,13 +368,7 @@ namespace Opm output_vtk_ = param.getDefault("output_vtk", true); output_dir_ = param.getDefault("output_dir", std::string("output")); // Ensure that output dir exists - boost::filesystem::path fpath(output_dir_); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(output_dir_); output_interval_ = param.getDefault("output_interval", 1); } diff --git a/opm/polymer/SimulatorCompressiblePolymer.cpp b/opm/polymer/SimulatorCompressiblePolymer.cpp index 39f2c8916..db3bde1ae 100644 --- a/opm/polymer/SimulatorCompressiblePolymer.cpp +++ b/opm/polymer/SimulatorCompressiblePolymer.cpp @@ -53,6 +53,8 @@ #include #include +#include + #include #include #include @@ -200,13 +202,7 @@ namespace Opm output_vtk_ = param.getDefault("output_vtk", true); output_dir_ = param.getDefault("output_dir", std::string("output")); // Ensure that output dir exists - boost::filesystem::path fpath(output_dir_); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(output_dir_); output_interval_ = param.getDefault("output_interval", 1); } @@ -525,13 +521,7 @@ namespace Opm // Write data in VTK format. std::ostringstream vtkfilename; vtkfilename << output_dir << "/vtk_files"; - boost::filesystem::path fpath(vtkfilename.str()); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(vtkfilename.str()); vtkfilename << "/output-" << std::setw(5) << std::setfill('0') << step << ".vtu"; std::ofstream vtkfile(vtkfilename.str().c_str()); if (!vtkfile) { @@ -568,13 +558,7 @@ namespace Opm for (Opm::DataMap::const_iterator it = dm.begin(); it != dm.end(); ++it) { std::ostringstream fname; fname << output_dir << "/" << it->first; - boost::filesystem::path fpath = fname.str(); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(fname.str()); fname << "/" << std::setw(5) << std::setfill('0') << step << ".txt"; std::ofstream file(fname.str().c_str()); if (!file) { diff --git a/opm/polymer/SimulatorPolymer.cpp b/opm/polymer/SimulatorPolymer.cpp index 29dbd5d40..47d84bced 100644 --- a/opm/polymer/SimulatorPolymer.cpp +++ b/opm/polymer/SimulatorPolymer.cpp @@ -55,6 +55,8 @@ #include #include +#include + #include #include #include @@ -211,13 +213,7 @@ namespace Opm output_vtk_ = param.getDefault("output_vtk", true); output_dir_ = param.getDefault("output_dir", std::string("output")); // Ensure that output dir exists - boost::filesystem::path fpath(output_dir_); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(output_dir_); output_interval_ = param.getDefault("output_interval", 1); } @@ -525,13 +521,7 @@ namespace Opm // Write data in VTK format. std::ostringstream vtkfilename; vtkfilename << output_dir << "/vtk_files"; - boost::filesystem::path fpath(vtkfilename.str()); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(vtkfilename.str()); vtkfilename << "/output-" << std::setw(5) << std::setfill('0') << step << ".vtu"; std::ofstream vtkfile(vtkfilename.str().c_str()); if (!vtkfile) { @@ -566,13 +556,7 @@ namespace Opm for (Opm::DataMap::const_iterator it = dm.begin(); it != dm.end(); ++it) { std::ostringstream fname; fname << output_dir << "/" << it->first; - boost::filesystem::path fpath = fname.str(); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(fname.str()); fname << "/" << std::setw(5) << std::setfill('0') << step << ".txt"; std::ofstream file(fname.str().c_str()); if (!file) { diff --git a/opm/simulators/SimulatorCompressibleTwophase.cpp b/opm/simulators/SimulatorCompressibleTwophase.cpp index 831af9d72..8f66dfe7f 100644 --- a/opm/simulators/SimulatorCompressibleTwophase.cpp +++ b/opm/simulators/SimulatorCompressibleTwophase.cpp @@ -49,6 +49,8 @@ #include #include +#include + #include #include #include @@ -147,13 +149,7 @@ namespace Opm // Write data in VTK format. std::ostringstream vtkfilename; vtkfilename << output_dir << "/vtk_files"; - boost::filesystem::path fpath(vtkfilename.str()); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(vtkfilename.str()); vtkfilename << "/output-" << std::setw(3) << std::setfill('0') << step << ".vtu"; std::ofstream vtkfile(vtkfilename.str().c_str()); if (!vtkfile) { @@ -188,13 +184,7 @@ namespace Opm for (Opm::DataMap::const_iterator it = dm.begin(); it != dm.end(); ++it) { std::ostringstream fname; fname << output_dir << "/" << it->first; - boost::filesystem::path fpath = fname.str(); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(fname.str()); fname << "/" << std::setw(3) << std::setfill('0') << step << ".txt"; std::ofstream file(fname.str().c_str()); if (!file) { @@ -268,13 +258,7 @@ namespace Opm output_vtk_ = param.getDefault("output_vtk", true); output_dir_ = param.getDefault("output_dir", std::string("output")); // Ensure that output dir exists - boost::filesystem::path fpath(output_dir_); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(output_dir_); output_interval_ = param.getDefault("output_interval", 1); } diff --git a/opm/simulators/SimulatorIncompTwophase.cpp b/opm/simulators/SimulatorIncompTwophase.cpp index 3f811f2fa..dce591c5b 100644 --- a/opm/simulators/SimulatorIncompTwophase.cpp +++ b/opm/simulators/SimulatorIncompTwophase.cpp @@ -51,6 +51,9 @@ #include #include #include +#include + + #include #include @@ -190,13 +193,7 @@ namespace Opm // Write data in VTK format. std::ostringstream vtkfilename; vtkfilename << output_dir << "/vtk_files"; - boost::filesystem::path fpath(vtkfilename.str()); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(vtkfilename.str()); vtkfilename << "/output-" << std::setw(3) << std::setfill('0') << step << ".vtu"; std::ofstream vtkfile(vtkfilename.str().c_str()); if (!vtkfile) { @@ -219,13 +216,7 @@ namespace Opm { std::ostringstream fname; fname << output_dir << "/" << name; - boost::filesystem::path fpath = fname.str(); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(fname.str()); fname << "/" << std::setw(3) << std::setfill('0') << step << ".txt"; std::ofstream file(fname.str().c_str()); if (!file) { @@ -250,13 +241,7 @@ namespace Opm for (Opm::DataMap::const_iterator it = dm.begin(); it != dm.end(); ++it) { std::ostringstream fname; fname << output_dir << "/" << it->first; - boost::filesystem::path fpath = fname.str(); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(fname.str()); fname << "/" << std::setw(3) << std::setfill('0') << step << ".txt"; std::ofstream file(fname.str().c_str()); if (!file) { @@ -383,13 +368,7 @@ namespace Opm output_vtk_ = param.getDefault("output_vtk", true); output_dir_ = param.getDefault("output_dir", std::string("output")); // Ensure that output dir exists - boost::filesystem::path fpath(output_dir_); - try { - create_directories(fpath); - } - catch (...) { - OPM_THROW(std::runtime_error, "Creating directories failed: " << fpath); - } + ensureDirectoryExists(output_dir_); output_interval_ = param.getDefault("output_interval", 1); } diff --git a/opm/simulators/ensureDirectoryExists.cpp b/opm/simulators/ensureDirectoryExists.cpp new file mode 100644 index 000000000..0e8991728 --- /dev/null +++ b/opm/simulators/ensureDirectoryExists.cpp @@ -0,0 +1,45 @@ +/* + Copyright 2017 SINTEF Digital, Mathematics and Cybernetics. + Copyright 2017 Statoil ASA. + + This file is part of the Open Porous Media project (OPM). + + OPM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OPM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with OPM. If not, see . +*/ + +#include +#include + +namespace Opm +{ + + /// The directory pointed to by 'dirpath' will be created if it + /// does not already exist. Will throw an exception if this cannot + /// be done. + void ensureDirectoryExists(const boost::filesystem::path& dirpath) + { + if (dirpath != ".") { // Do not try to create the current directory. + if (!is_directory(dirpath)) { + try { + create_directories(dirpath); + } + catch (...) { + OPM_THROW(std::runtime_error, "Creating directories failed: " << dirpath); + } + } + } + } + + +} // namespace Opm diff --git a/opm/simulators/ensureDirectoryExists.hpp b/opm/simulators/ensureDirectoryExists.hpp new file mode 100644 index 000000000..5b22b961f --- /dev/null +++ b/opm/simulators/ensureDirectoryExists.hpp @@ -0,0 +1,40 @@ +/* + Copyright 2017 SINTEF Digital, Mathematics and Cybernetics. + Copyright 2017 Statoil ASA. + + This file is part of the Open Porous Media project (OPM). + + OPM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OPM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with OPM. If not, see . +*/ + +#ifndef OPM_ENSUREDIRECTORYEXISTS_HEADER_INCLUDED +#define OPM_ENSUREDIRECTORYEXISTS_HEADER_INCLUDED + +#include + +namespace Opm +{ + + /// The directory pointed to by 'dirpath' will be created if it + /// does not already exist. Will throw an exception if this cannot + /// be done. + /// + /// Note that std::string can be passed to this functions, as they + /// can be implicitly converted to boost::filesystem::path objects. + void ensureDirectoryExists(const boost::filesystem::path& dirpath); + + +} // namespace Opm + +#endif // OPM_ENSUREDIRECTORYEXISTS_HEADER_INCLUDED