foamListTimes.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Application
25  foamListTimes
26 
27 Description
28  List times using timeSelector.
29 
30 Usage
31 
32  - foamListTimes [OPTION]
33 
34  \param -rm \n
35  Remove selected time directories
36  \param -processor \n
37  List times from processor0/ directory
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #include "argList.H"
42 #include "timeSelector.H"
43 #include "Time.H"
44 
45 using namespace Foam;
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 int main(int argc, char *argv[])
50 {
51  argList::addNote("List times using timeSelector");
52 
53  timeSelector::addOptions(true, true);
57  (
58  "processor",
59  "list times from processor0/ directory"
60  );
62  (
63  "rm",
64  "remove selected time directories"
65  );
66  #include "setRootCase.H"
67 
68  label nProcs = 0;
69 
70  // Create the processor databases
71  PtrList<Time> databases(1);
72 
73  if (args.optionFound("processor"))
74  {
75  // Determine the processor count directly
76  while (isDir(args.path()/(word("processor") + name(nProcs))))
77  {
78  ++nProcs;
79  }
80 
81  if (!nProcs)
82  {
84  << "No processor* directories found"
85  << exit(FatalError);
86  }
87 
88  // Create the processor databases
89  databases.setSize(nProcs);
90 
91  forAll(databases, procI)
92  {
93  databases.set
94  (
95  procI,
96  new Time
97  (
99  args.rootPath(),
100  args.caseName()/fileName(word("processor") + name(procI))
101  )
102  );
103  }
104  }
105  else
106  {
107  databases.set
108  (
109  0,
110  new Time
111  (
113  args.rootPath(),
114  args.caseName()
115  )
116  );
117  }
118 
119  // Use the times list from the master processor
120  // and select a subset based on the command-line options
122  (
123  databases[0].times(),
124  args
125  );
126 
127  if (args.optionFound("rm"))
128  {
129  if (args.optionFound("processor"))
130  {
131  for (label procI=0; procI<nProcs; procI++)
132  {
133  fileName procPath
134  (
135  args.path()/(word("processor") + name(procI))
136  );
137 
138  forAll(timeDirs, timeI)
139  {
140  rmDir(procPath/timeDirs[timeI].name());
141  }
142  }
143  }
144  else
145  {
146  forAll(timeDirs, timeI)
147  {
148  rmDir(args.path()/timeDirs[timeI].name());
149  }
150  }
151  }
152  else
153  {
154  forAll(timeDirs, timeI)
155  {
156  Info<< timeDirs[timeI].name() << endl;
157  }
158  }
159 
160  return 0;
161 }
162 
163 
164 // ************************************************************************* //
Foam::argList::noBanner
static void noBanner()
Disable emitting the banner information.
Definition: argList.C:155
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::argList::addNote
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:139
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::argList::addBoolOption
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:98
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::argList::rootPath
const fileName & rootPath() const
Return root path.
Definition: argListI.H:36
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::Info
messageStream Info
argList.H
main
int main(int argc, char *argv[])
Definition: postCalc.C:54
Foam::PtrList
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
Foam::argList::path
fileName path() const
Return the path to the caseName.
Definition: argListI.H:60
Foam::FatalError
error FatalError
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::isDir
bool isDir(const fileName &)
Does the name exist as a DIRECTORY in the file system?
Definition: POSIX.C:615
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
setRootCase.H
timeDirs
static instantList timeDirs
Definition: globalFoam.H:44
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::timeSelector::addOptions
static void addOptions(const bool constant=true, const bool withZero=false)
Add the options handled by timeSelector to argList::validOptions.
Definition: timeSelector.C:114
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
timeSelector.H
Foam::argList::optionFound
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
Foam::timeSelector::select
instantList select(const instantList &) const
Select a list of Time values that are within the ranges.
Definition: timeSelector.C:100
Foam::argList::caseName
const fileName & caseName() const
Return case name (parallel run) or global case (serial run)
Definition: argListI.H:42
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:161
args
Foam::argList args(argc, argv)
Foam::Time::controlDictName
static word controlDictName
The default control dictionary name (normally "controlDict")
Definition: Time.H:213
Foam::rmDir
bool rmDir(const fileName &)
Remove a dirctory and its contents.
Definition: POSIX.C:974
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47