bin/script changes

foamUpdateCaseFileHeader:
      - handle multiple files
      - use fixed version width
      - replace grep/tr/cut -> sed

    foamUpgradeTurbulenceProperties:
      - handle multiple files
This commit is contained in:
Mark Olesen
2008-07-17 23:26:54 +02:00
parent a34c8d635b
commit 1884b91c8c
2 changed files with 97 additions and 77 deletions

View File

@ -33,85 +33,108 @@
# Also removes consecutive blank lines from file. # Also removes consecutive blank lines from file.
# #
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
foamVersion=$WM_PROJECT_VERSION
# usage() {
# FUNCTIONS cat<<USAGE
#
printUsage () {
cat <<EOF
Usage: $0 <file>
Updates the header of application files
By default, writes current version in the header
Alternatively version can be specified with -v option
Also removes consecutive blank lines from file
Options are: usage: ${0##*/} [OPTION] <file1> ... <fileN>
-v "<version>" specifies the version to be written in the header
-h help options:
EOF -v "<version>" specifies the version to be written in the header
-h help
Updates the header of application files.
By default, writes current version in the header.
Alternatively version can be specified with -v option.
Also removes consecutive blank lines from file.
USAGE
exit 1
} }
printOpenFOAMheader () {
cat<<EOF printHeader() {
cat<<HEADER
/*--------------------------------*- C++ -*----------------------------------*\\ /*--------------------------------*- C++ -*----------------------------------*\\
| ========= | | | ========= | |
| \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\\\ / O peration | Version: ${1} | | \\\\ / O peration | Version: ${foamVersion} |
| \\\\ / A nd | Web: http://www.OpenFOAM.org | | \\\\ / A nd | Web: http://www.OpenFOAM.org |
| \\\\/ M anipulation | | | \\\\/ M anipulation | |
\\*---------------------------------------------------------------------------*/ \\*---------------------------------------------------------------------------*/
FoamFile FoamFile
{ {
version 2.0; version 2.0;
format ${2}; format ${1};
class ${3}; class ${2};
object ${4}; object ${3};
} }
EOF HEADER
} }
FoamFileAttribute () {
grep $1 $2 | tr -s " " | cut -d" " -f3 | cut -d\; -f1 #
# extract attribute '$1' from file '$2'
#
FoamFileAttribute() {
sed -n -e 's/[ ;]*$//' -e "s/^ *$1 *//p" $2
} }
VERSION=$WM_PROJECT_VERSION
# #
# OPTIONS # OPTIONS
# #
OPTS=`getopt hv: $*` OPTS=`getopt hv: $*`
if [ $? -ne 0 ] ; then if [ $? -ne 0 ]
then
echo "Aborting due to invalid option" echo "Aborting due to invalid option"
printUsage usage
exit 1
fi fi
eval set -- '$OPTS' eval set -- '$OPTS'
while [ "$1" != "--" ]; do while [ "$1" != "--" ]
do
case $1 in case $1 in
-v) VERSION=$2; shift;; -v)
-h) printUsage; exit 1;; foamVersion=$2
shift
;;
-h)
usage
;;
esac esac
shift shift
done done
shift shift
[ $# -ge 1 ] || usage
# constant width for version
foamVersion=`printf %-36s $foamVersion`
# #
# MAIN # MAIN
# #
CASE_FILE=$1 for caseFile
if [ "`grep FoamFile $CASE_FILE`" ] ; then do
echo "Updating case file:" $CASE_FILE if grep FoamFile $caseFile >/dev/null 2>&1
sed -n '/FoamFile/,/}/p' $CASE_FILE > FoamFile then
echo "Updating case file: $caseFile"
sed -n '/FoamFile/,/}/p' $caseFile > FoamFile
CLASS=`FoamFileAttribute class FoamFile` CLASS=`FoamFileAttribute class FoamFile`
OBJECT=`FoamFileAttribute object FoamFile` OBJECT=`FoamFileAttribute object FoamFile`
FORMAT=`FoamFileAttribute format FoamFile` FORMAT=`FoamFileAttribute format FoamFile`
printOpenFOAMheader $VERSION $FORMAT $CLASS $OBJECT > temp
sed '1,/}/d' $CASE_FILE | sed '/./,/^$/!d' >> temp
mv temp $1
rm FoamFile
else
echo "The following file does not appear to be a case file:"
echo " " $CASE_FILE
fi
printHeader $FORMAT $CLASS $OBJECT $NOTE > FoamFile.tmp
sed '1,/}/d' $caseFile | sed '/./,/^$/!d' >> FoamFile.tmp
mv FoamFile.tmp $caseFile
rm FoamFile
else
echo " Invalid case file: $caseFile"
fi
done
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -44,21 +44,12 @@ usage: ${0##*/} <turbulenceProperties>
Where <turbulenceProperties> is the full path to the Where <turbulenceProperties> is the full path to the
turbulenceProperties dictionary turbulenceProperties dictionary
Note: can upgrade several files at once
USAGE USAGE
exit 1 exit 1
} }
[ $# = 1 ] || usage
turbDict=$1
if [ ! -f $turbDict ]
then
echo " Error: file $turbDict does not exist"
echo ""
usage
fi
# #
# $1: turbulence model # $1: turbulence model
# $2: new properties type # $2: new properties type
@ -66,7 +57,7 @@ fi
# #
convertDict() convertDict()
{ {
echo " Identified $1 turbulence model in $3" echo "Identified $1 turbulence model in '$3'"
outputPath=`dirname $3` outputPath=`dirname $3`
sed -e "s/turbulenceProperties/$1Properties/" \ sed -e "s/turbulenceProperties/$1Properties/" \
@ -77,20 +68,26 @@ convertDict()
echo " wrote $outputPath/$1Properties" echo " wrote $outputPath/$1Properties"
} }
# [ $# -ge 1 ] || usage
# Identify type of turbulence model and convert
#
if grep turbulenceModel $turbDict >/dev/null 2>&1
then
convertDict RAS turbulenceModel $turbDict
elif grep LESmodel $turbDict >/dev/null 2>&1
then
convertDict LES LESmodel $turbDict
else
echo "Unable to determine turbulence model type - nothing changed"
exit 1
fi
echo "done." for turbDict
do
# Identify type of turbulence model and convert
if [ -f $turbDict ]
then
if grep turbulenceModel $turbDict >/dev/null 2>&1
then
convertDict RAS turbulenceModel $turbDict
elif grep LESmodel $turbDict >/dev/null 2>&1
then
convertDict LES LESmodel $turbDict
else
echo "Unable to determine turbulence model type in '$turbDict'"
echo " - nothing changed"
fi
else
echo "Error: file '$turbDict' does not exist"
fi
done
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------