From 1884b91c8c098d90f0f6af41a1d1fbc5f9866e91 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 17 Jul 2008 23:26:54 +0200 Subject: [PATCH] bin/script changes foamUpdateCaseFileHeader: - handle multiple files - use fixed version width - replace grep/tr/cut -> sed foamUpgradeTurbulenceProperties: - handle multiple files --- bin/foamUpdateCaseFileHeader | 121 +++++++++++++++++----------- bin/foamUpgradeTurbulenceProperties | 53 ++++++------ 2 files changed, 97 insertions(+), 77 deletions(-) diff --git a/bin/foamUpdateCaseFileHeader b/bin/foamUpdateCaseFileHeader index dad6dfc355..6b7aa8439f 100755 --- a/bin/foamUpdateCaseFileHeader +++ b/bin/foamUpdateCaseFileHeader @@ -33,85 +33,108 @@ # Also removes consecutive blank lines from file. # #------------------------------------------------------------------------------ +foamVersion=$WM_PROJECT_VERSION -# -# FUNCTIONS -# -printUsage () { -cat < - 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() { + cat<" specifies the version to be written in the header --h help -EOF +usage: ${0##*/} [OPTION] ... + +options: + -v "" 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< FoamFile - CLASS=`FoamFileAttribute class FoamFile` - OBJECT=`FoamFileAttribute object 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 +for caseFile +do + if grep FoamFile $caseFile >/dev/null 2>&1 + then + echo "Updating case file: $caseFile" + sed -n '/FoamFile/,/}/p' $caseFile > FoamFile + CLASS=`FoamFileAttribute class FoamFile` + OBJECT=`FoamFileAttribute object FoamFile` + FORMAT=`FoamFileAttribute format FoamFile` + + 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 #------------------------------------------------------------------------------ diff --git a/bin/foamUpgradeTurbulenceProperties b/bin/foamUpgradeTurbulenceProperties index b5ba0a9b0b..8c1437aca6 100755 --- a/bin/foamUpgradeTurbulenceProperties +++ b/bin/foamUpgradeTurbulenceProperties @@ -41,24 +41,15 @@ usage() { usage: ${0##*/} - Where is the full path to the - turbulenceProperties dictionary + Where is the full path to the + turbulenceProperties dictionary + + Note: can upgrade several files at once USAGE exit 1 } -[ $# = 1 ] || usage - -turbDict=$1 -if [ ! -f $turbDict ] -then - echo " Error: file $turbDict does not exist" - echo "" - usage -fi - - # # $1: turbulence model # $2: new properties type @@ -66,7 +57,7 @@ fi # convertDict() { - echo " Identified $1 turbulence model in $3" + echo "Identified $1 turbulence model in '$3'" outputPath=`dirname $3` sed -e "s/turbulenceProperties/$1Properties/" \ @@ -77,20 +68,26 @@ convertDict() echo " wrote $outputPath/$1Properties" } -# -# 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 +[ $# -ge 1 ] || usage -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 #------------------------------------------------------------------------------