ENH: polyBoundaryMesh: improved error message
[OpenFOAM-2.0.x.git] / bin / foamUpdateCaseFileHeader
blob3f9ce5242a1e75a49b150f462a2a46bf311befcb
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 # foamUpdateCaseFileHeader
28 # Description
29 # Updates the header of application files.
30 # By default, writes current version in the header.
31 # Alternatively version can be specified with -v option.
32 # Also removes consecutive blank lines from file.
34 #------------------------------------------------------------------------------
35 usage() {
36 exec 1>&2
37 while [ "$#" -ge 1 ]; do echo "$1"; shift; done
38 cat<<USAGE
40 Usage: ${0##*/} [OPTION] <file1> ... <fileN>
42 options:
43 -version <ver> specifies the version to be written in the header
44 -help print the usage
46 Updates the header of application files and removes consecutive blank lines.
47 By default, writes current OpenFOAM version in the header.
48 An alternative version can be specified with the -version option.
50 USAGE
51 exit 1
54 #------------------------------------------------------------------------------
56 # parse options
57 while [ "$#" -gt 0 ]
59 case "$1" in
60 -h | -help)
61 usage
63 -v | -version)
64 [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
65 version="$2"
66 shift 2
68 -*)
69 usage "unknown option: '$*'"
72 break
74 esac
75 done
77 # constant width for version - default to WM_PROJECT_VERSION
78 version=$(printf %-36s ${version:-$WM_PROJECT_VERSION})
80 [ $# -ge 1 ] || usage
82 #------------------------------------------------------------------------------
84 printHeader()
86 cat<<HEADER
87 /*--------------------------------*- C++ -*----------------------------------*\\
88 | ========= | |
89 | \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
90 | \\\\ / O peration | Version: $version |
91 | \\\\ / A nd | Web: www.OpenFOAM.org |
92 | \\\\/ M anipulation | |
93 \\*---------------------------------------------------------------------------*/
94 FoamFile
96 version 2.0;
97 format $1;
98 class $2;
99 object $3;
101 HEADER
106 # extract attribute '$1' from file '$2'
108 FoamFileAttribute()
110 sed -n -e 's/[ ;]*$//' -e "s/^ *$1 *//p" $2
115 # main
118 tmpFile=FoamFile.tmp$$
119 for caseFile
121 if grep FoamFile $caseFile >/dev/null 2>&1
122 then
123 echo "Updating case file: $caseFile"
124 sed -n '/FoamFile/,/}/p' $caseFile > $tmpFile
126 format=$(FoamFileAttribute format $tmpFile)
127 class=$(FoamFileAttribute class $tmpFile)
128 object=$(FoamFileAttribute object $tmpFile)
129 # extract note? - needs special handling
130 unset note
132 printHeader $format $class $object "$note" > $tmpFile
134 sed '1,/}/d' $caseFile | sed '/./,/^$/!d' >> $tmpFile
136 # use cat to avoid removing/replace soft-links
137 [ -s $tmpFile ] && cat $tmpFile >| $caseFile
138 rm -f $tmpFile 2>/dev/null
139 else
140 echo " Invalid case file: $caseFile" 1>&2
142 done
144 #------------------------------------------------------------------ end-of-file