ENH: cylinderAnnulusToCell: new cellSource for cellSets
[OpenFOAM-1.7.x.git] / bin / foamUpdateCaseFileHeader
blobef8e36cf1ea9a0e2326c18ca2fc2aa20ae87ca63
1 #!/bin/sh
2 #---------------------------------*- sh -*-------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
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 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
55 printHeader() {
56 cat<<HEADER
57 /*--------------------------------*- C++ -*----------------------------------*\\
58 | ========= | |
59 | \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
60 | \\\\ / O peration | Version: ${foamVersion} |
61 | \\\\ / A nd | Web: www.OpenFOAM.com |
62 | \\\\/ M anipulation | |
63 \\*---------------------------------------------------------------------------*/
64 FoamFile
66 version 2.0;
67 format ${1};
68 class ${2};
69 object ${3};
71 HEADER
76 # extract attribute '$1' from file '$2'
78 FoamFileAttribute() {
79 sed -n -e 's/[ ;]*$//' -e "s/^ *$1 *//p" $2
84 # OPTIONS
86 opts=$(getopt hv: $*)
87 if [ $? -ne 0 ]
88 then
89 echo "Aborting due to invalid option"
90 usage
92 eval set -- '$opts'
93 while [ "$1" != "--" ]
95 case $1 in
96 -v)
97 foamVersion=$2
98 shift
101 usage
103 esac
104 shift
105 done
106 shift
108 [ $# -ge 1 ] || usage
111 # constant width for version
112 foamVersion=$(printf %-36s $foamVersion)
115 # MAIN
117 unset NOTE
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 > FoamFile.tmp
126 FORMAT=$(FoamFileAttribute format FoamFile.tmp)
127 CLASS=$(FoamFileAttribute class FoamFile.tmp)
128 OBJECT=$(FoamFileAttribute object FoamFile.tmp)
129 # extract NOTE?
131 printHeader $FORMAT $CLASS $OBJECT $NOTE > FoamFile.tmp
132 sed '1,/}/d' $caseFile | sed '/./,/^$/!d' >> FoamFile.tmp
134 # use cat to avoid removing/replace soft-links
135 [ -s FoamFile.tmp ] && cat FoamFile.tmp >| $caseFile
136 rm -f FoamFile.tmp 2>/dev/null
137 else
138 echo " Invalid case file: $caseFile" 1>&2
140 done
142 #------------------------------------------------------------------------------