From bf7ce67d9dd4184d0f3fcbfd33896790b8222432 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Wed, 17 Jul 2024 07:51:06 -0500 Subject: [PATCH] GridIn: do not use PathSearch --- include/deal.II/grid/grid_in.h | 5 ++--- source/grid/grid_in.cc | 28 ++++++++++------------------ 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/include/deal.II/grid/grid_in.h b/include/deal.II/grid/grid_in.h index 30f790d51e..4b5c5e67c8 100644 --- a/include/deal.II/grid/grid_in.h +++ b/include/deal.II/grid/grid_in.h @@ -366,9 +366,8 @@ public: read(std::istream &in, Format format = Default); /** - * Open the file given by the string and call the previous function read(). - * This function uses the PathSearch mechanism to find files. The file class - * used is MESH. + * Open the file given by the string and call the previous function + * read() taking a std::istream argument. */ void read(const std::string &in, Format format = Default); diff --git a/source/grid/grid_in.cc b/source/grid/grid_in.cc index 3cec748811..b793d88d00 100644 --- a/source/grid/grid_in.cc +++ b/source/grid/grid_in.cc @@ -14,7 +14,6 @@ #include -#include #include #include @@ -35,8 +34,8 @@ #include #include +#include #include -#include #include #include @@ -4139,39 +4138,32 @@ template void GridIn::read(const std::string &filename, Format format) { - // Search file class for meshes - PathSearch search("MESH"); - std::string name; - // Open the file and remember its name - if (format == Default) - name = search.find(filename); - else - name = search.find(filename, default_suffix(format)); - + // Check early that the file actually exists and if not throw ExcFileNotOpen. + AssertThrow(std::filesystem::exists(filename), ExcFileNotOpen(filename)); if (format == Default) { - const std::string::size_type slashpos = name.find_last_of('/'); - const std::string::size_type dotpos = name.find_last_of('.'); - if (dotpos < name.size() && + const std::string::size_type slashpos = filename.find_last_of('/'); + const std::string::size_type dotpos = filename.find_last_of('.'); + if (dotpos < filename.size() && (dotpos > slashpos || slashpos == std::string::npos)) { - std::string ext = name.substr(dotpos + 1); + std::string ext = filename.substr(dotpos + 1); format = parse_format(ext); } } if (format == assimp) { - read_assimp(name); + read_assimp(filename); } else if (format == exodusii) { - read_exodusii(name); + read_exodusii(filename); } else { - std::ifstream in(name); + std::ifstream in(filename); read(in, format); } } -- 2.39.5