77const regExp matcher(
"processors?[0-9]+(_[0-9]+-[0-9]+)?");
79bool isProcessorDir(
const string& dir)
81 return (dir.
starts_with(
"processor") && matcher.match(dir));
95 { restoreMethod::MEAN,
"mean" },
96 { restoreMethod::ORIG,
"orig" },
102 { restoreMethod::MEAN,
"Mean" },
103 { restoreMethod::ORIG,
".orig" },
110 return ListOps::create<word>
119bool dryrun =
false, verbose =
false;
128 const restoreMethod method,
135 const word ending(methodEndings[method]);
142 case restoreMethod::MEAN:
143 bak = methodEndings[restoreMethod::ORIG];
156 for (
word f : existingFiles)
159 if (
f.removeEnd(ending) &&
f.size())
174 for (
const word& dst : targets)
176 const word src(dst + ending);
178 if (!existingFiles.found(src))
183 if (bak.size() && existingFiles.found(dst))
185 if (dryrun ||
Foam::mv(dirName/dst, dirName/dst + bak))
187 Info<<
" mv " << dst <<
" " <<
word(dst + bak) <<
nl;
192 if (dryrun ||
Foam::mv(dirName/src, dirName/dst))
194 Info<<
" mv " << src <<
" " << dst <<
nl;
205int main(
int argc,
char *argv[])
209 "Restore field names by removing the ending. Fields are selected"
210 " automatically or can be specified as optional command arguments"
213 profiling::disable();
214 argList::noJobInfo();
215 argList::noFunctionObjects();
220 "The restore method (mean|orig) [MANDATORY]. "
221 "With <mean> renames files ending with 'Mean' "
222 "(with backup of existing as '.orig'). "
223 "With <orig> renames files ending with '.orig'"
225 argList::addBoolOption
228 "In serial mode use times from processor0/ directory, but operate on "
229 "processor\\d+ directories"
231 argList::addDryRunOption
233 "Report action without moving/renaming"
235 argList::addVerboseOption
237 "Additional verbosity"
241 argList::noMandatoryArgs();
242 argList::addArgument(
"fieldName ... fieldName");
244 timeSelector::addOptions(
true,
true);
255 restoreMethod method = restoreMethod::ORIG;
262 && methodNames.found(methodName)
265 method = methodNames[methodName];
269 Info<<
"Unspecified or unknown method name" <<
nl
272 <<
"... stopping" <<
nl <<
nl;
284 for (label argi=1; argi <
args.
size(); ++argi)
288 targetNames[uniq.
size()-1] =
args[argi];
297 <<
"using method=" << methodNames[method] <<
nl
304 <<
"using method=" << methodNames[method] <<
nl
305 <<
"autodetect fields" <<
nl;
315 if (
args.
found(
"processor") && !Pstream::parRun())
323 <<
"No processor* directories found"
343 const instantList timeDirs(timeSelector::select(timePaths->times(),
args));
346 label leadProcIdx = -1;
348 if (timeDirs.empty())
350 Info<<
"No times selected" <<
nl;
374 leadProcIdx = procDirs.
find(
"processor0");
376 if (!procDirs.
empty())
387 const std::string prefix
394 if (procDirs[idx].starts_with(prefix))
411 for (
const instant& t : timeDirs)
422 if (leadProcIdx >= 0)
427 for (
const fileName& procDir : procDirs)
429 count += restoreFields
440 if (Pstream::master())
444 Pstream::broadcast(files);
446 count += restoreFields
Various functions to operate on Lists.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
label size() const noexcept
The number of elements in table.
void resize(const label len)
Adjust allocated size of list.
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
label find(const T &val, label pos=0) const
Find index of the first occurrence of the value.
int dryRun() const noexcept
Return the dry-run flag.
int verbose() const noexcept
Return the verbose flag.
const fileName & rootPath() const noexcept
Return root path.
label size() const noexcept
The number of arguments.
bool found(const word &optName) const
Return true if the named option is found.
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
fileName path() const
Return the full path to the (processor local) case.
const fileName & caseName() const noexcept
Return case name (parallel run) or global case (serial run)
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
A class for handling file names.
static std::string name(const std::string &str)
Return basename (part beyond last /), including its extension.
virtual label nProcs(const fileName &dir, const fileName &local="") const
Get number of processor directories/results. Used for e.g.
An instant of time. Contains the time value and name. Uses Foam::Time when formatting the name.
Wrapper around C++11 regular expressions with some additional prefix-handling. The prefix-handling is...
bool starts_with(const std::string &s) const
True if string starts with the given prefix (cf. C++20)
A class for handling words, derived from Foam::string.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
const fileOperation & fileHandler()
Get current file handler.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
void inplaceSubsetList(ListType &input, const UnaryPredicate &pred, const bool invert=false)
Inplace subset of the list when predicate is true.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
void sort(UList< T > &list)
Sort the list.
fileNameList readDir(const fileName &directory, const fileName::Type type=fileName::FILE, const bool filtergz=true, const bool followLink=true)
Read a directory and return the entries as a fileName List.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
bool mv(const fileName &src, const fileName &dst, const bool followLink=false)
Rename src to dst.
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a)
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.
Extract name (as a word) from an object, typically using its name() method.
Encapsulation of natural order sorting for algorithms.