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 <code>MESH</code>.
+ * 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);
#include <deal.II/base/exceptions.h>
-#include <deal.II/base/path_search.h>
#include <deal.II/base/patterns.h>
#include <deal.II/base/utilities.h>
#include <algorithm>
#include <cctype>
+#include <filesystem>
#include <fstream>
-#include <functional>
#include <limits>
#include <map>
void
GridIn<dim, spacedim>::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);
}
}