Merge commit 'b5be6201e00421a59e574a07b3d28cde5defff84'
[foam-extend-4.0.git] / bin / foamUpdateCaseFileHeader
blobe3c8ee18304b658c0ef446a1435f4346f1e4abc4
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | foam-extend: Open Source CFD
5 # \\ / O peration | Version: 4.0
6 # \\ / A nd | Web: http://www.foam-extend.org
7 # \\/ M anipulation | For copyright notice see file Copyright
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 # 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 foamVersion=$WM_PROJECT_VERSION
37 usage() {
38 cat<<USAGE
40 Usage: ${0##*/} [OPTION] <file1> ... <fileN>
42 options:
43 -v VER specifies the version to be written in the header
44 -h help
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 -v option.
50 USAGE
51 exit 1
54 printHeader() {
55 cat<<HEADER
56 /*--------------------------------*- C++ -*----------------------------------*\\
57 | ========= | |
58 | \\\\ / F ield | foam-extend: Open Source CFD |
59 | \\\\ / O peration | Version: ${foamVersion} |
60 | \\\\ / A nd | Web: http://www.foam-extend.org |
61 | \\\\/ M anipulation | For copyright notice see file Copyright |
62 \\*---------------------------------------------------------------------------*/
63 FoamFile
65 version 2.0;
66 format ${FORMAT};
67 class ${CLASS};
68 HEADER
70 if [ -n "${NOTE}" ];
71 then
72 cat<<HEADER
73 note ${NOTE};
74 HEADER
77 if [ -n "${LOCATION}" ];
78 then
79 cat<<HEADER
80 location ${LOCATION};
81 HEADER
84 cat<<HEADER
85 object ${OBJECT};
87 HEADER
91 # extract attribute '$1' from file '$2'
93 FoamFileAttribute() {
94 sed -n -e 's/[ ;]*$//' -e "s/^ *$1 *//p" $2
98 # OPTIONS
100 opts=$(getopt hv: $*)
101 if [ $? -ne 0 ]
102 then
103 echo "Aborting due to invalid option"
104 usage
106 eval set -- '$opts'
107 while [ "$1" != "--" ]
109 case $1 in
111 foamVersion=$2
112 shift
115 usage
117 esac
118 shift
119 done
120 shift
122 [ $# -ge 1 ] || usage
124 # constant width for version
125 foamVersion=$(printf %-33s $foamVersion)
128 # MAIN
131 for caseFile
133 if [ ! -x "$caseFile" ] && (grep "^ *FoamFile" $caseFile >/dev/null 2>&1)
134 then
135 echo "Updating case file: $caseFile"
136 sed -n '/FoamFile/,/}/p' $caseFile > FoamFile.tmp
138 FORMAT=$(FoamFileAttribute format FoamFile.tmp)
139 CLASS=$(FoamFileAttribute class FoamFile.tmp)
140 NOTE=$(FoamFileAttribute note FoamFile.tmp)
141 LOCATION=$(FoamFileAttribute location FoamFile.tmp)
142 OBJECT=$(FoamFileAttribute object FoamFile.tmp)
144 printHeader > FoamFile.tmp
145 sed '1,/}/d' $caseFile | sed '/./,/^$/!d' | sed 's/ *$//g' >> FoamFile.tmp
146 #sed '1,/}/d' $caseFile >> FoamFile.tmp
148 # use cat to avoid removing/replace soft-links
149 [ -s FoamFile.tmp ] && cat FoamFile.tmp >| $caseFile
150 rm -f FoamFile.tmp 2>/dev/null
151 else
152 echo " Invalid case file: $caseFile" 1>&2
154 done
156 #------------------------------------------------------------------------------