ThirdParty: build instructions for Ubuntu 12.04 32 bit: fixing typo
[openfoam-extend-OpenFOAM-1.6-ext.git] / bin / foamUpdateCaseFileHeader
blob39b0af1611a435b1fb8ae9980653812ea1cdcc70
1 #!/bin/sh
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 # \\ / O peration |
6 # \\ / A nd | Copyright held by original author
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 the
14 # Free Software Foundation; either version 2 of the License, or (at your
15 # 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, write to the Free Software Foundation,
24 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 # Script
27 # foamUpdateCaseFileHeader
29 # Description
30 # Updates the header of application files.
31 # By default, writes current version in the header.
32 # Alternatively version can be specified with -v option.
33 # Also removes consecutive blank lines from file.
35 #------------------------------------------------------------------------------
36 foamVersion=$WM_PROJECT_VERSION
38 usage() {
39 cat<<USAGE
41 Usage: ${0##*/} [OPTION] <file1> ... <fileN>
43 options:
44 -v VER specifies the version to be written in the header
45 -h help
47 Updates the header of application files and removes consecutive blank lines.
48 By default, writes current OpenFOAM version in the header.
49 An alternative version can be specified with the -v option.
51 USAGE
52 exit 1
55 printHeader() {
56 cat<<HEADER
57 /*--------------------------------*- C++ -*----------------------------------*\\
58 | ========= | |
59 | \\\\ / F ield | OpenFOAM Extend Project: Open Source CFD |
60 | \\\\ / O peration | Version: ${foamVersion} |
61 | \\\\ / A nd | Web: www.extend-project.de |
62 | \\\\/ M anipulation | |
63 \\*---------------------------------------------------------------------------*/
64 FoamFile
66 version 2.0;
67 format ${FORMAT};
68 class ${CLASS};
69 HEADER
71 if [ -n "${NOTE}" ];
72 then
73 cat<<HEADER
74 note ${NOTE};
75 HEADER
78 if [ -n "${LOCATION}" ];
79 then
80 cat<<HEADER
81 location ${LOCATION};
82 HEADER
85 cat<<HEADER
86 object ${OBJECT};
88 HEADER
92 # extract attribute '$1' from file '$2'
94 FoamFileAttribute() {
95 sed -n -e 's/[ ;]*$//' -e "s/^ *$1 *//p" $2
99 # OPTIONS
101 opts=$(getopt hv: $*)
102 if [ $? -ne 0 ]
103 then
104 echo "Aborting due to invalid option"
105 usage
107 eval set -- '$opts'
108 while [ "$1" != "--" ]
110 case $1 in
112 foamVersion=$2
113 shift
116 usage
118 esac
119 shift
120 done
121 shift
123 [ $# -ge 1 ] || usage
125 # constant width for version
126 foamVersion=$(printf %-36s $foamVersion)
129 # MAIN
132 for caseFile
134 if [ ! -x "$caseFile" ] && (grep "^ *FoamFile" $caseFile >/dev/null 2>&1)
135 then
136 echo "Updating case file: $caseFile"
137 sed -n '/FoamFile/,/}/p' $caseFile > FoamFile.tmp
139 FORMAT=$(FoamFileAttribute format FoamFile.tmp)
140 CLASS=$(FoamFileAttribute class FoamFile.tmp)
141 NOTE=$(FoamFileAttribute note FoamFile.tmp)
142 LOCATION=$(FoamFileAttribute location FoamFile.tmp)
143 OBJECT=$(FoamFileAttribute object FoamFile.tmp)
145 printHeader > FoamFile.tmp
146 sed '1,/}/d' $caseFile | sed '/./,/^$/!d' | sed 's/ *$//g' >> FoamFile.tmp
147 #sed '1,/}/d' $caseFile >> FoamFile.tmp
149 # use cat to avoid removing/replace soft-links
150 [ -s FoamFile.tmp ] && cat FoamFile.tmp >| $caseFile
151 rm -f FoamFile.tmp 2>/dev/null
152 else
153 echo " Invalid case file: $caseFile" 1>&2
155 done
157 #------------------------------------------------------------------------------