Header update
[foam-extend-3.2.git] / bin / foamExec
blobc418aa61b0127c994b2929eb6d74cdc37520f780
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | foam-extend: Open Source CFD
5 # \\ / O peration |
6 # \\ / A nd | For copyright notice see file Copyright
7 # \\/ M anipulation |
8 #------------------------------------------------------------------------------
9 # License
10 # This file is part of foam-extend.
12 # foam-extend is free software: you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by the
14 # Free Software Foundation, either version 3 of the License, or (at your
15 # option) any later version.
17 # foam-extend is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 # General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 # Script
26 # foamExec
28 # Description
29 # Usage: foamExec [-v foamVersion] <foamCommand> ...
31 # Runs the <foamVersion> version of executable <foamCommand>
32 # with the rest of the arguments.
34 # Can also be used for parallel runs e.g.
35 # mpirun -np <nProcs> \
36 # foamExec -v <foamVersion> <foamCommand> ... -parallel
38 #------------------------------------------------------------------------------
39 Script=${0##*/}
41 usage() {
42 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
43 cat<<USAGE
45 usage: ${0##*/} [OPTION] <application> ...
47 options:
48 -v ver specify foam version
49 -help this usage
51 * run a particular foam version of <application>
53 USAGE
54 exit 1
58 # This script should exist in <foamInstall>/foam-extend-<VERSION>/bin/
59 # extract the <foamInstall> and <version> elements
60 # using a function preserves the command args
61 getDefaults() {
62 set -- $(echo $0 | sed -e 's@/foam-extend-\([^/]*\)/bin/[^/]*$@ \1@')
63 foamInstall=$1
64 version=$2
67 getDefaults
69 # parse options
70 while [ "$#" -gt 0 ]
72 case "$1" in
73 -h | -help)
74 usage
76 -v)
77 shift
78 version=$1
79 shift
81 --)
82 shift
83 break
85 -*)
86 usage "invalid option '$1'"
89 break
91 esac
92 done
94 if [ "$#" -lt 1 ]
95 then
96 usage "no application specified"
99 unset foamDotFile
101 # Check user-specific foam-extend bashrc file
102 foamDotFile="$HOME/.foam-extend-$version/bashrc"
103 if [ -f $foamDotFile ]
104 then
105 . $foamDotFile
106 foamDotFile=okay
107 else
108 # Use the FOAM_INST_DIR variable for locating the installed version
109 for FOAM_INST_DIR in $foamInstall $WM_PROJECT_INST_DIR
111 foamDotFile="$FOAM_INST_DIR/foam-extend-$version/etc/bashrc"
112 if [ -f $foamDotFile ]
113 then
114 . $foamDotFile
115 foamDotFile=okay
116 break
118 done
122 if [ "$foamDotFile" != okay ]
123 then
124 echo "Error : bashrc file could not be found for foam-extend-$version" 1>&2
125 exit 1
128 # Pass on the rest of the arguments
129 exec $*
131 #------------------------------------------------------------------------------