2 #------------------------------------------------------------------------------
4 # \\ / F ield | FOAM-extend: Open Source CFD
6 # \\ / A nd | For copyright notice see file Copyright
8 #------------------------------------------------------------------------------
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/>.
26 # foamUpdateCaseFileHeader
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
40 Usage: ${0##*/} [OPTION] <file1> ... <fileN>
43 -v VER specifies the version to be written in the header
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.
56 /*--------------------------------*- C++ -*----------------------------------*\\
58 | \\\\ / F ield | foam-extend: Open Source CFD |
59 | \\\\ / O peration | Version: ${foamVersion} |
60 | \\\\ / A nd | Web: http://www.extend-project.de |
61 | \\\\/ M anipulation | |
62 \\*---------------------------------------------------------------------------*/
77 if [ -n "${LOCATION}" ];
91 # extract attribute '$1' from file '$2'
94 sed -n -e 's/[ ;]*$//' -e "s/^ *$1 *//p" $2
100 opts
=$
(getopt hv
: $
*)
103 echo "Aborting due to invalid option"
107 while [ "$1" != "--" ]
122 [ $# -ge 1 ] || usage
124 # constant width for version
125 foamVersion
=$
(printf %-33s $foamVersion)
133 if [ ! -x "$caseFile" ] && (grep "^ *FoamFile" $caseFile >/dev
/null
2>&1)
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
152 echo " Invalid case file: $caseFile" 1>&2
156 #------------------------------------------------------------------------------