STYLE: linearAxialAngularSpring: indentation
[OpenFOAM-2.0.x.git] / bin / foamNewCase
blob510152e91e019d1ff09455620ac05ad9d14ccc12
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 # foamNewCase
28 # Description
29 # Create a new case from a template for particular applications
30 # - requires rsync
32 #------------------------------------------------------------------------------
33 siteDir=${WM_PROJECT_SITE:-${WM_PROJECT_INST_DIR:-<unknown>}/site}
34 userDir=$HOME/.OpenFOAM
35 version=${WM_PROJECT_VERSION:-unknown}
36 templateDir="appTemplates"
38 #------------------------------------------------------------------------------
39 usage() {
40 exec 1>&2
41 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
42 cat<<USAGE
44 Usage: ${0##*/} [OPTION]
45 options:
46 -app <name> specify the application to use
47 -case <dir> specify alternative case directory, default is the cwd
48 -list list the applications available
49 -version <ver> specify an alternative version (default: '$WM_PROJECT_VERSION')
51 clone initial application settings to the specified case from
52 $userDir/$templateDir/{$version,}/<APP>
53 $siteDir/$templateDir/{$version,}/<APP>
55 USAGE
56 exit 1
58 #------------------------------------------------------------------------------
59 unset appName caseName listOpt
61 # parse options
62 while [ "$#" -gt 0 ]
64 case "$1" in
65 -h | -help)
66 usage
68 -app)
69 [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
70 appName="$2"
71 shift 2
73 -case)
74 [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
75 caseName="$2"
76 shift 2
78 -l | -list)
79 listOpt=true
80 shift
82 -v | -ver | -version)
83 [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
84 version="$2"
85 shift 2
87 -*)
88 usage "unknown option: '$*'"
91 usage "unexpected argument: '$*'"
93 esac
94 done
96 # need rsync, except for when listing
97 type rsync >/dev/null 2>&1 || [ "$listOpt" = true ] || usage "Error: 'rsync' seems to be missing"
100 #------------------------------------------------------------------------------
102 [ -n "$version" ] || {
103 echo "Error: no -version specified and \$WM_PROJECT_VERSION is not set"
104 exit 1
108 # find apps in current directory
109 # considered an app if it has constant/ and system/ directories
111 findApps()
113 for app in $(/bin/ls -d * 2>/dev/null)
115 [ -d "$app/constant" -a -d "$app/system" ] && echo $app
116 done
120 appList=$(
121 for dir in $userDir/$templateDir $siteDir/$templateDir
123 if cd $dir 2>/dev/null
124 then
125 findApps ## generic
126 cd $version 2>/dev/null && findApps ## version-specific
128 done | sort | uniq
132 listApps()
134 echo
135 echo "applications available:"
136 for i in $appList
138 echo " $i"
139 done
140 echo
144 if [ "$listOpt" = true ]
145 then
146 listApps
147 exit 0
148 elif [ "$(echo $appList | wc -w)" -eq 0 ]
149 then
150 echo "Error: no applications available"
151 exit 1
152 elif [ -z "$appName" ]
153 then
154 echo "Error: no -app specified"
155 listApps
156 exit 1
160 # get the corresponding srcDir name
161 srcDir=$(
162 for dir in $userDir/$templateDir $siteDir/$templateDir
164 if [ -d $dir ]
165 then
166 for appDir in $dir/$version/$appName $dir/$appName
168 if [ -d $appDir -a -d $appDir/constant -a -d $appDir/system ]
169 then
170 echo "$appDir"
171 break 2
173 done
175 done
179 [ -d "$srcDir" ] || {
180 echo "Error: could not find template for $appName"
181 listApps
182 exit 1
186 # adjust for caseName as required
187 if [ -n "$caseName" ]
188 then
189 [ -d "$caseName" ] || mkdir -p "$caseName"
190 cd "$caseName" 2>/dev/null || usage "directory does not exist: '$caseName'"
192 newDir=$PWD
195 [ -d "$newDir" -a -w "$newDir" ] || {
196 echo "Error: target directory does not exist or is unwritable"
197 echo " $newDir"
198 exit 1
201 # add some useful subdirs:
202 mkdir -p $newDir/postPro
205 echo " application $appName"
206 echo " source $srcDir"
207 echo " target $newDir"
209 echo " syncing ..."
210 # sync updated files only, itemize changes so we know what is going on
211 rsync -aui $srcDir/ $newDir
215 # reuse or create new FOAM_SETTINGS (useful for queuing systems)
217 if [ -e "$newDir/FOAM_SETTINGS" ]
218 then
219 echo " retaining FOAM_SETTINGS"
220 else
221 echo " creating FOAM_SETTINGS"
222 cat << SETTINGS > "$newDir/FOAM_SETTINGS"
223 APPLICATION=$appName
224 FOAM_VERSION=OpenFOAM-$version
225 SETTINGS
228 echo Done
230 #------------------------------------------------------------------------------