STYLE: linearAxialAngularSpring: indentation
[OpenFOAM-2.0.x.git] / bin / foamCopySettings
blobf913f1212e2c47b81f341b209b401420708cddd1
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 # foamCopySettings
28 # Description
29 # Usage: foamCopySettings srcDir dstDir
31 # Copy OpenFOAM settings from one case to another, without copying
32 # the mesh or results
33 # - requires rsync
35 # Note
36 # The foamCopySettings.rc (found with the ~OpenFOAM expansion) can be used
37 # to add any custom rsync options.
38 #-------------------------------------------------------------------------------
39 Script=${0##*/}
41 #------------------------------------------------------------------------------
42 usage() {
43 exec 1>&2
44 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
45 cat <<USAGE
47 Usage: $Script srcDir dstDir
49 Copy OpenFOAM settings from one case to another, without copying
50 the mesh or results.
51 - requires rsync
53 Note
54 The $Script.rc (found via the ~OpenFOAM expansion - see foamEtcFile)
55 can be used to add any custom rsync options.
57 USAGE
58 exit 1
60 #------------------------------------------------------------------------------
62 # parse options
63 while [ "$#" -gt 0 ]
65 case "$1" in
66 -h | -help)
67 usage
69 -*)
70 usage "unknown option: '$*'"
73 break
75 esac
76 done
78 # need rsync
79 type rsync >/dev/null 2>&1 || usage "Error: 'rsync' seems to be missing"
81 [ "$#" -eq 2 ] || usage "Error: incorrect number of arguments"
83 srcDir=${1%/}
84 dstDir=${2%/}
86 for i in $srcDir $dstDir
88 [ -d "$i" ] || { echo "Error: directory '$i' does not exist"; exit 1; }
89 done
91 # check that the srcDir looks okay
92 for i in $srcDir/constant $srcDir/system
94 if [ ! -d "$i" ]
95 then
96 echo "Error: no '${i##*/}' directory in '$srcDir'"
97 echo " does not appear to be an OpenFOAM case"
98 exit 1
100 done
102 # files and directories to copy
103 # avoid processor directories here too to make for cleaner output
104 fileList=$(find -H $srcDir -mindepth 1 -maxdepth 1 -not -name "processor*")
106 # avoid polyMesh and processor* directories
107 rsync="rsync --exclude polyMesh --exclude processor*"
110 # get any extra user options
111 # extract lines starting with '--longOption'
113 if rcFile=$(foamEtcFile $Script.rc)
114 then
115 rsync="$rsync "$(sed -ne '/^ *--/p' $rcFile | tr '\n' ' ')
119 # TODO:
120 # - verify that it works with multiple mesh regions
121 # - special treatment for starting with negative crank angles
124 echo
125 echo "synchronizing with"
126 echo " $rsync"
127 echo
129 for i in $fileList
131 name="${i##*/}"
132 # skip numerical (results) directories (except 0)
133 # and things that look like log files or queuing system output
134 case "$name" in
135 ( [1-9] | [0-9]?* | log | *.log | foam.[eo][1-9]* )
136 echo "$i [skipped]"
137 continue
139 # skip things that look sampled directories and converted data
140 ( probes | sets | surfaces | En[Ss]ight )
141 echo "$i [skipped]"
142 continue
145 echo "$i -> $dstDir/$name"
146 $rsync -a $i $dstDir
148 esac
149 done
151 # ------------------------------------------------------------------ end-of-file