ENH: PatchEdgeFaceWave: new wave method
[OpenFOAM-2.0.x.git] / bin / foamPrintJobs
blob1ddc9d0fc0aa120e60ccdaa74966c9f9f068dac5
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 # \\/ M anipulation |
8 #-------------------------------------------------------------------------------
9 # License
10 # This file is part of OpenFOAM.
12 # OpenFOAM is free software: you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation, either version 3 of the License, or
15 # (at your option) any later version.
17 # OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
18 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 # for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 # Script
26 # foamPrintJobs
28 # Description
29 # Uses finishedJobs/ and runningJobs/ and stateFile to print job info
31 #------------------------------------------------------------------------------
32 Script=${0##*/}
34 JOBSTRING='%4s %8s %20s %10s %8s %4s %12s %12s %20s\n'
35 DEFSTATEFILE=$HOME/.OpenFOAM/foamCheckJobs.out
38 #-------------------------------------------------------------------------------
40 # Functions
42 #-------------------------------------------------------------------------------
44 usage() {
45 cat<<USAGE
46 Usage: $Script [stateFile]
48 This program prints a table of all running and finished jobs.
50 It is normally used in conjunction with foamCheckJobs which outputs
51 a "stateFile" containing the actual process status of all jobs.
53 If stateFile is not supplied, the default is used:
54 $DEFSTATEFILE
55 USAGE
56 exit 1
60 # printJob stat user case machine pid ncpus start end code
61 printJob() {
62 printf "$JOBSTRING" "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
66 # getRawEntry dictionary entry
67 # Prints value of dictionary entry
68 getRawEntry() {
69 grep -v '^//' $1 | grep "^[ \t]*$2 " | sed -e "s/^[ \t]*$2 [ ]*//"
72 # getEntry dictionary entry
73 # Like getRawEntry but strips " and ending ';'
74 getEntry() {
75 getRawEntry $1 $2 | sed -e 's/^"//' -e 's/;$//' -e 's/"$//'
79 # notEmpty directory
80 # Returns 0 if directory contains files/directories
81 notEmpty() {
82 if [ "`ls $1`" ]
83 then
84 return 0
85 else
86 return 1
90 # rightStr nChars string
91 # Prints rightmost nChars of string
92 rightStr() {
93 echo "$2" | sed -e "s/.*\(.\{$1\}\)\$/\1/"
96 leftStr() {
97 echo "$2" | sed -e "s/\(.\{$1\}\).*/\1/"
100 #-------------------------------------------------------------------------------
102 # Main
104 #-------------------------------------------------------------------------------
106 if [ $# -eq 1 ]
107 then
108 if [ "$1" = "-h" -o "$1" = "-help" ]
109 then
110 usage
111 else
112 STATEFILE="$1"
114 elif [ $# -eq 0 ]
115 then
116 STATEFILE=${STATEFILE:-$DEFSTATEFILE}
117 else
118 usage
121 #- Check a few things
123 if [ ! "$FOAM_JOB_DIR" ]
124 then
125 echo "$Script : FOAM_JOB_DIR environment variable not set."
126 echo
127 exit 1
129 if [ ! -d "$FOAM_JOB_DIR" ]
130 then
131 echo "$Script : directory does not exist."
132 echo " FOAM_JOB_DIR=$FOAM_JOB_DIR"
133 echo
134 exit 1
136 if [ ! -d "$FOAM_JOB_DIR/runningJobs" -o ! -d "$FOAM_JOB_DIR/finishedJobs" ]
137 then
138 echo "$Script : invalid directory."
139 echo " FOAM_JOB_DIR=$FOAM_JOB_DIR"
140 echo
141 exit 1
145 if [ -f "$STATEFILE" ]
146 then
147 echo ""
148 echo "Using process information from"
149 echo " $STATEFILE"
150 echo "on jobs in"
151 echo " $FOAM_JOB_DIR"
152 echo ""
153 else
154 echo ""
155 echo "Cannot read $STATEFILE."
156 echo ""
157 STATEFILE=''
161 #-- print header
162 printJob 'stat' 'user' 'case' 'machine' 'pid' 'ncpu' 'start' 'end' 'code'
163 printJob '----' '----' '----' '-------' '---' '----' '-----' '---' '----'
167 #-- print submitted
170 #-- print running
171 echo "Running:"
172 if notEmpty $FOAM_JOB_DIR/runningJobs
173 then
174 for f in `ls -t $FOAM_JOB_DIR/runningJobs/*`
176 machinePid=`basename $f`
178 machine=`echo $machinePid | sed -e 's/\..*$//'`
179 machine=`rightStr 10 "$machine"`
181 pid=`echo $machinePid | sed -e 's/.*\.\([0-9][0-9]*\)$/\1/'`
183 if [ "$STATEFILE" ]
184 then
185 stat=`getEntry $STATEFILE $machinePid`
187 stat=${stat:-'UNKN'}
189 case=`getEntry $f 'case'`
190 case=${case:-'---'}
191 case=`echo $case | sed -e 's!/.*!!'` # strip processorXXX ending
192 case=`rightStr 20 "$case"`
194 start=`getEntry $f 'startDate'`
195 start=${start:-'---'}
196 start=`leftStr 12 "$start"`
198 end='---'
200 code=`getEntry $f 'code'`
201 if [ "$code" ]
202 then
203 code=`basename $code`
204 else
205 code='---'
207 code=`rightStr 20 "$code"`
209 nProcs=`getEntry $f 'nProcs'`
210 nProcs=${nProcs:-'1'}
211 if [ $nProcs -eq 1 ]
212 then
213 nProcs='---'
215 nProcs=`rightStr 3 "$nProcs"`
217 user=`getEntry $f 'username'`
218 user=${user:-'---'}
219 user=`leftStr 8 "$user"`
221 printJob "$stat" "$user" "$case" "$machine" "$pid" "$nProcs" "$start" "$end" "$code"
222 done
226 #-- print finished
227 echo ""
228 echo "Finished:"
229 if notEmpty $FOAM_JOB_DIR/finishedJobs
230 then
231 for f in `ls -t $FOAM_JOB_DIR/finishedJobs/*`
233 machinePid=`basename $f`
235 machine=`echo $machinePid | sed -e 's/\..*$//'`
236 machine=`rightStr 10 "$machine"`
238 pid=`echo $machinePid | sed -e 's/.*\.\([0-9][0-9]*\)$/\1/'`
240 end=`getEntry $f endDate`
241 end=${end:-'---'}
242 end=`leftStr 12 "$end"`
244 if [ "$STATEFILE" ]
245 then
246 stat=`getEntry $STATEFILE $machinePid`
248 stat=${stat:-'UNKN'}
250 case=`getEntry $f case`
251 case=`echo $case | sed -e 's!/.*!!'` # strip processorXXX ending
252 case=${case:-'---'}
253 case=`rightStr 20 "$case"`
255 start=`getEntry $f startDate`
256 start=${start:-'---'}
257 start=`leftStr 12 "$start"`
259 code=`getEntry $f code`
260 if [ "$code" ]
261 then
262 code=`basename $code`
263 else
264 code='---'
266 code=`rightStr 20 "$code"`
268 nProcs=`getEntry $f 'nProcs'`
269 nProcs=${nProcs:-'1'}
270 if [ $nProcs -eq 1 ]
271 then
272 nProcs='---'
274 nProcs=`rightStr 3 "$nProcs"`
276 user=`getEntry $f 'username'`
277 user=${user:-'---'}
278 user=`leftStr 8 "$user"`
280 printJob "$stat" "$user" "$case" "$machine" "$pid" "$nProcs" "$start" "$end" "$code"
281 done
284 #------------------------------------------------------------------------------