From 3bc28f6cb0844bc4904eda96f9bf91a36f0eb25e Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@Germany> Date: Fri, 8 Aug 2008 23:15:28 +0200 Subject: [PATCH] foamUpdate scripts - avoid destroying soft-links or trashing existing {RAS,LES}Properties --- bin/foamUpdateCaseFileHeader | 13 +++++++------ bin/foamUpgradeTurbulenceProperties | 19 ++++++++++++------- .../constant/polyMesh/blockMeshDict.m4 | 2 +- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/bin/foamUpdateCaseFileHeader b/bin/foamUpdateCaseFileHeader index 6b7aa8439ff..805f4e128a7 100755 --- a/bin/foamUpdateCaseFileHeader +++ b/bin/foamUpdateCaseFileHeader @@ -121,17 +121,18 @@ do if grep FoamFile $caseFile >/dev/null 2>&1 then echo "Updating case file: $caseFile" - sed -n '/FoamFile/,/}/p' $caseFile > FoamFile + sed -n '/FoamFile/,/}/p' $caseFile > FoamFile.tmp - CLASS=`FoamFileAttribute class FoamFile` - OBJECT=`FoamFileAttribute object FoamFile` - FORMAT=`FoamFileAttribute format FoamFile` + CLASS=`FoamFileAttribute class FoamFile.tmp` + OBJECT=`FoamFileAttribute object FoamFile.tmp` + FORMAT=`FoamFileAttribute format FoamFile.tmp` printHeader $FORMAT $CLASS $OBJECT $NOTE > FoamFile.tmp sed '1,/}/d' $caseFile | sed '/./,/^$/!d' >> FoamFile.tmp - mv FoamFile.tmp $caseFile - rm FoamFile + # use cat to avoid removing/replace soft-links + [ -s FoamFile.tmp ] && cat FoamFile.tmp >| $caseFile + rm FoamFile.tmp else echo " Invalid case file: $caseFile" fi diff --git a/bin/foamUpgradeTurbulenceProperties b/bin/foamUpgradeTurbulenceProperties index 8c1437aca66..297b7e4e635 100755 --- a/bin/foamUpgradeTurbulenceProperties +++ b/bin/foamUpgradeTurbulenceProperties @@ -57,15 +57,20 @@ USAGE # convertDict() { - echo "Identified $1 turbulence model in '$3'" - outputPath=`dirname $3` + echo "Identified $1 turbulence model in '$3'" + outputPath=`dirname $3` - sed -e "s/turbulenceProperties/$1Properties/" \ - -e "s/$2/$1Model/" \ - -e "s/[a-zA-Z0-9]* [ ]*\[[0-9 ]*\]//" \ - $3 > "$outputPath/$1Properties" + if [ -e "$outputPath/$1Properties" ] + then + echo "Error: file already exists $outputPath/$1Properties'" + else + sed -e "s/turbulenceProperties/$1Properties/" \ + -e "s/$2/$1Model/" \ + -e "s/[a-zA-Z0-9]* [ ]*\[[0-9 ]*\]//" \ + $3 > "$outputPath/$1Properties" - echo " wrote $outputPath/$1Properties" + echo " wrote $outputPath/$1Properties" + fi } [ $# -ge 1 ] || usage diff --git a/tutorials/interDyMFoam/sloshingTank3D/constant/polyMesh/blockMeshDict.m4 b/tutorials/interDyMFoam/sloshingTank3D/constant/polyMesh/blockMeshDict.m4 index cc851f6503f..5e355fd7025 100644 --- a/tutorials/interDyMFoam/sloshingTank3D/constant/polyMesh/blockMeshDict.m4 +++ b/tutorials/interDyMFoam/sloshingTank3D/constant/polyMesh/blockMeshDict.m4 @@ -16,7 +16,7 @@ FoamFile // General m4 macros changecom(//)changequote([,]) -define(calc, [esyscmd(perl -e 'use Math::Trig; use POSIX; print ($1)')]) +define(calc, [esyscmd(perl -e 'use Math::Trig; use POSIX; printf ($1)')]) define(VCOUNT, 0) define(vlabel, [[// ]Vertex $1 = VCOUNT define($1, VCOUNT)define([VCOUNT], incr(VCOUNT))]) -- GitLab