15 #include "libmesh/int_range.h" 24 "Name of single image file to extract mesh parameters from. " 25 "If provided, a 2D mesh is created.");
26 params.
addParam<FileNameNoExtension>(
"file_base",
27 "Image file base to open, use this option when " 28 "a stack of images must be read (ignored if " 30 params.
addParam<std::vector<unsigned int>>(
32 "Range of images to analyze, used with 'file_base' (ignored if 'file' is given)");
33 params.
addParam<std::string>(
"file_suffix",
"Suffix of the file to open, e.g. 'png'");
45 std::string file_base;
46 std::vector<unsigned int> file_range;
50 file = params.
get<FileName>(
"file");
56 file_base = params.
get<FileNameNoExtension>(
"file_base");
58 file_range = params.
get<std::vector<unsigned int>>(
"file_range");
65 if (has_file && has_file_base)
72 if (!has_file && !has_file_base)
79 if (has_file_base && !has_file_suffix)
86 if (has_file && has_file_range)
87 mooseWarning(
"Warning: file_range was ignored since a filename was provided.");
90 if (has_file_base && !has_file_range)
92 file_range.push_back(0);
99 if (has_file_range && file_range.size() == 1)
100 file_range.push_back(file_range[0]);
104 if (has_file_range && file_range.size() != 2)
106 mooseWarning(
"A maximum of two values are allowed in the file_range, extra values truncated.");
107 file_range.resize(2);
111 std::sort(file_range.begin(), file_range.end());
117 else if (has_file_base)
124 tinydir_open_sorted(&dir, split_file.first.c_str());
127 std::ostringstream oss;
128 oss <<
"(" << split_file.second <<
".*?(\\d+))\\..*";
129 pcrecpp::RE file_base_and_num_regex(oss.str());
136 tinydir_readfile_n(&dir, &file, i);
141 std::string the_base;
142 unsigned int file_num = 0;
143 file_base_and_num_regex.FullMatch(file.name, &the_base, &file_num);
145 if (!the_base.empty() && file_num >= file_range[0] && file_num <= file_range[1])
146 _filenames.push_back(split_file.first +
"/" + file.name);
166 mooseError(
"Cannot provide both file and file_base parameters");
169 mooseError(
"You must provide a valid value for either the 'file' parameter or the " 170 "'file_base' parameter.");
174 "If you provide a 'file_base', you must also provide a valid 'file_suffix', e.g. 'png'.");
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
std::pair< std::filesystem::path, std::filesystem::path > splitFileName(const T &full_file)
Function for splitting path and filename.
static InputParameters validParams()
auto max(const L &left, const R &right)
bool hasExtension(const std::string &filename, std::string ext, bool strip_exodus_ext=false)
Function tests if the supplied filename as the desired extension.
IntRange< T > make_range(T beg, T end)
FileRangeBuilder(const InputParameters ¶ms)
std::vector< std::string > _filenames