Scripts in bin: improved script quality, option listing and

exit status on -help
This commit is contained in:
Chris Greenshields
2017-05-21 19:58:36 -04:00
parent 8fe9195c5f
commit a356adbfd8
12 changed files with 312 additions and 296 deletions

View File

@ -3,7 +3,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
@ -41,7 +41,7 @@
# by colons or whitespace
#------------------------------------------------------------------------------
usage() {
cat <<USAGE 1>&2
cat <<USAGE
Usage: ${0##*/} [OPTION] path [wildcard1] .. [wildcardN]
options:
-strip remove inaccessible directories
@ -58,6 +58,10 @@ options:
2 initial value of 'path' is empty
USAGE
}
error () {
usage 1>&2
exit 1
}
@ -68,12 +72,15 @@ while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help)
usage
usage && exit 0
;;
-strip)
strip=true
shift
;;
-*)
error
;;
*)
break
;;
@ -81,7 +88,7 @@ do
done
[ "$#" -ge 1 ] || usage
[ "$#" -ge 1 ] || error
dirList="$1"
shift

View File

@ -3,7 +3,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
@ -31,8 +31,6 @@
#
#------------------------------------------------------------------------------
usage() {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat <<USAGE
Usage: ${0##*/} [OPTION]
@ -45,7 +43,13 @@ Remove the contents of the constant/polyMesh directory as per the
Foam::polyMesh::removeFiles() method.
USAGE
exit 1
}
error () {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
usage
exit 1
}
unset caseDir regionName
@ -55,21 +59,21 @@ while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help)
usage
usage && exit 0
;;
-case)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
cd "$2" 2>/dev/null || usage "directory does not exist: '$2'"
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
cd "$2" 2>/dev/null || error "directory does not exist: '$2'"
caseDir=$2
shift 2
;;
-region)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
regionName=$2
shift 2
;;
*)
usage "unknown option/argument: '$*'"
error "unknown option/argument: '$*'"
;;
esac
done
@ -133,7 +137,7 @@ for i in \
surfaceIndex \
;
do
rm -rf $meshDir/$i $meshDir/$i.gz
rm -rf ${meshDir:?}/$i ${meshDir:?}/$i.gz
done
#------------------------------------------------------------------------------

View File

@ -3,7 +3,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
# \\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
@ -33,38 +33,42 @@
#
#------------------------------------------------------------------------------
usage() {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE
Usage: ${0##*/} [OPTION] <sourceCase> <targetCase>
Usage: ${0##*/} [OPTION] <source case> <target name>
options:
-l | -latestTime clone the latest time directory
-h | -help print the usage
-latestTime clone the latest time directory
-help print the usage
Create a new <targetCase> case directory that includes time, system and constant
directories of <sourceCase> directory.
The time directory is the first time directory by default.
USAGE
}
error () {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
usage
exit 1
}
TIME_OPTION="head -1"
time_option="head -1"
# parse options
while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help)
usage
usage && exit 0
;;
-l | -latestTime)
TIME_OPTION="tail -1"
time_option="tail -1"
shift 1
;;
-*)
usage "unknown option: '$*'"
error "unknown option: '$*'"
;;
*)
break
@ -72,19 +76,18 @@ do
esac
done
[ $# -eq 2 ] || usage "Incorrect arguments specified"
if [ "$(foamListTimes -case $1 2>&1 >/dev/null | grep 'FOAM FATAL ERROR')" ]
then
usage "$1 is not does not a valid case directory"
fi
! [ -e $2 ] || usage "$2 file/directory already exists, delete and re-run"
[ $# -eq 2 ] || error "Incorrect arguments specified"
foamListTimes -case "$1" >/dev/null 2>&1 || \
error "'$1' is not a valid case directory"
! [ -e "$2" ] || error "'$2' file/directory already exists, delete and re-run"
echo "Making $2 case directory"
mkdir $2
mkdir "$2"
TIME_DIR="$(foamListTimes -withZero -case $1 | $TIME_OPTION)"
time_dir="$(foamListTimes -withZero -case "$1" | $time_option)"
echo "Copying case directories from $1 to $2"
cp -r $1/system $1/constant $1/${TIME_DIR} $2
cp -r "$1"/system "$1"/constant "$1"/"${time_dir}" "$2"
#------------------------------------------------------------------------------

View File

@ -3,7 +3,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation
# \\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
@ -32,19 +32,17 @@
#------------------------------------------------------------------------------
usage () {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat <<USAGE
Usage: ${0##*/} [OPTIONS] ...
options:
-d | -dir <dir> directory containing png images (default local dir)
-f | -fps <fps> frames per second (default = 10)
-h | -help help
-i | -image <name> name of image sequence (default = image)
-o | -out <name> name of output video file (default = video)
-s | -start <frame> specify the start frame number for avconv
-w | -webm WebM output video file format
-dir | -d <dir> directory containing png images (default local dir)
-fps | -f <fps> frames per second (default = 10)
-help | -h help
-image | -i <name> name of image sequence (default = image)
-out | -o <name> name of output video file (default = video)
-start | -s <frame> specify the start frame number for avconv
-webm | -w WebM output video file format
Creates a video file from a sequence of PNG images
- A sequence named "image" will expect files image.0000.png, image.0001.png, etc
@ -55,56 +53,55 @@ Creates a video file from a sequence of PNG images
Requires avconv or mencoder for MPEG-4 output, avconv for WebM output
USAGE
}
error () {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
usage
exit 1
}
# Default settings
DIR='.'
IMAGE='image'
VIDEO='video'
FPS=10
FMT='mp4'
START_NUMBER=''
dir=.
image=image
video=video
fps=10
fmt=mp4
while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help)
usage
usage && exit 0
;;
-d | -directory)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
DIR=$2
-d | -dir)
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
dir=$2
shift 2
;;
-f | -fps)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
FPS=$2
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
fps=$2
shift 2
;;
-i | -image)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
IMAGE=$2
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
image=$2
shift 2
;;
-o | -out)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
VIDEO=$2
shift 2
;;
-s | -start)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
START_NUMBER="-start_number $2"
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
video=$2
shift 2
;;
-w | -webm)
FMT=webm
echo "Selected $FMT format, requires avconv..."
fmt=webm
echo "Selected $fmt format, requires avconv..."
shift
;;
-*)
usage "invalid option '$1'"
error "invalid option '$1'"
;;
*)
break
@ -116,37 +113,36 @@ done
# MAIN
#
[ -f "$(ls -1 $DIR/$IMAGE.*.png | head -1)" ] || usage "Cannot find first file in image sequence"
[ -f "$(find "$dir" -name "$image.*.png" | sort | head -1)" ] || \
error "Cannot find first file in image sequence"
if [ "$FMT" = "webm" ] ; then
if [ "$fmt" = "webm" ] ; then
if command -v avconv >/dev/null 2>&1 ; then
echo "Creating image with avconv..."
avconv \
-framerate $FPS \
$START_NUMBER \
-i ${DIR}/${IMAGE}.%04d.png \
-framerate "$fps" \
-i "${dir}/${image}.%04d.png" \
-c:v libvpx -crf 15 -b:v 1M \
$VIDEO.$FMT
"$video.$fmt"
else
usage "Please install avconv"
error "Please install avconv"
fi
else
if command -v avconv >/dev/null 2>&1 ; then
if ! command -v avconv >/dev/null 2>&1 ; then
echo "Creating image with avconv..."
avconv \
-framerate $FPS \
$START_NUMBER \
-i ${DIR}/${IMAGE}.%04d.png \
-framerate "$fps" \
-i "${dir}/${image}.%04d.png" \
-c:v libx264 -pix_fmt yuv420p \
$VIDEO.$FMT
"$video.$fmt"
elif command -v mencoder >/dev/null 2>&1 ; then
echo "Creating image with mencoder..."
mencoder \
"mf://$DIR/$IMAGE.*.png" \
-mf fps=$FPS \
-o $VIDEO.$FMT \
"mf://$dir/$image.*.png" \
-mf fps="$fps" \
-o "$video.$fmt" \
-ovc x264
else
usage "Please install avconv or mencoder"
error "Please install avconv or mencoder"
fi
fi

View File

@ -3,7 +3,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
@ -48,8 +48,6 @@
#
#------------------------------------------------------------------------------
usage() {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE
Usage: ${0##*/} [OPTION] <application> ...
@ -64,6 +62,12 @@ options:
* run a particular OpenFOAM version of <application>
USAGE
}
error () {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
usage
exit 1
}
@ -88,21 +92,21 @@ while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help)
usage
usage && exit 0
;;
-m | -mode)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile
shift
;;
-p | -prefix)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile
prefixDir="$2"
shift
;;
-v | -version)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile
version="$2"
shift
@ -112,7 +116,7 @@ do
break
;;
-*)
usage "invalid option '$1'"
error "invalid option '$1'"
;;
*)
break
@ -139,7 +143,7 @@ sourceRc()
}
[ "$#" -ge 1 ] || usage "no application specified"
[ "$#" -ge 1 ] || error "no application specified"
sourceRc
exec "$@"

View File

@ -3,7 +3,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
# \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
@ -31,8 +31,6 @@
#
#------------------------------------------------------------------------------
usage() {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE
Usage: ${0##*/} [OPTION] <application> ...
@ -49,6 +47,12 @@ options:
Redirects the output to 'log' in the case directory
USAGE
}
error () {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
usage
exit 1
}
@ -58,14 +62,14 @@ echoArgs() {
for stringItem in "$@"; do
echo -n "${addSpace}"
printf "%s" "${addSpace}"
if [ "${stringItem##* }" = "$stringItem" ]
then
echo -n "$stringItem"
printf "%s" "$stringItem"
addSpace=" "
else
echo -n "'$stringItem'"
printf "%s" "'$stringItem'"
addSpace=" "
fi
@ -76,38 +80,11 @@ echoArgs() {
unset version
# Replacement for possibly buggy 'which'
findExec() {
case "$1" in
*/*)
if [ -x "$1" ]
then
echo "$1"
return 0
fi
;;
esac
oldIFS=$IFS
IFS=':'
for d in $PATH
do
# echo "testing: $d/$1" 1>&2
if [ -x "$d/$1" -a ! -d "$d/$1" ]
then
# echo "Found exec: $d/$1" 1>&2
IFS=$oldIFS
echo "$d/$1"
return 0
fi
done
IFS=$oldIFS
echo ""
return 1
which "$1" 2>/dev/null
command -v "$1" >/dev/null 2>&1
}
# Main script
#~~~~~~~~~~~~
unset parallelOpt screenOpt waitOpt
@ -118,11 +95,11 @@ while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help)
usage
usage && exit 0
;;
-case)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
cd "$2" 2>/dev/null || usage "directory does not exist: '$2'"
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
cd "$2" 2>/dev/null || error "directory does not exist: '$2'"
shift 2
;;
-p | -parallel)
@ -142,7 +119,7 @@ do
shift
;;
-v | -version)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
version="$2"
shift 2
;;
@ -151,7 +128,7 @@ do
break
;;
-*)
usage "invalid option '$1'"
error "invalid option '$1'"
;;
*)
break
@ -159,7 +136,7 @@ do
esac
done
[ "$#" -ge 1 ] || usage "No application specified"
[ "$#" -ge 1 ] || error "No application specified"
# Use foamExec for a specified version
@ -169,11 +146,11 @@ then
# When possible, determine if application even exists
if [ -z "$version" ]
then
findExec $1 >/dev/null || usage "Application '$1' not found"
findExec "$1" >/dev/null || error "Application '$1' not found"
fi
# Use foamExec for dispatching
APPLICATION=`findExec foamExec` || usage "'foamExec' not found"
APPLICATION=$(findExec foamExec) || error "'foamExec' not found"
[ -n "$version" ] && APPLICATION="$APPLICATION -version $version"
@ -184,7 +161,7 @@ then
fi
else
APPLICATION=`findExec $1` || usage "Application '$1' not found"
APPLICATION=$(findExec "$1") || error "Application '$1' not found"
echo "Application : $1"
shift
fi
@ -200,7 +177,7 @@ then
#
if [ -r "processor0" ]
then
NPROCS="`/bin/ls -1d processor* | wc -l`"
NPROCS="$(/bin/ls -1d processor* | wc -l)"
else
echo "Case is not currently decomposed"
if [ -r system/decomposeParDict ]
@ -218,7 +195,7 @@ then
#
# Find mpirun
#
mpirun=`findExec mpirun` || usage "'mpirun' not found"
mpirun=$(findExec mpirun) || error "'mpirun' not found"
mpiopts="-np $NPROCS"
#

View File

@ -3,7 +3,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
@ -35,11 +35,10 @@ siteDir=${WM_PROJECT_SITE:-${WM_PROJECT_INST_DIR:-<unknown>}/site}
userDir=$HOME/.OpenFOAM
usage() {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat <<USAGE
Usage: $Script [OPTIONS] <log>
Usage: $Script [OPTIONS] <log file>
options:
-list lists but does not extract
-n create single column files with the extracted data only
-quiet quiet operation
@ -49,13 +48,13 @@ Usage: $Script [OPTIONS] <log>
$Script - extracts xy files from OpenFOAM logs.
USAGE
exit 1
}
#------------------------------------------------------------------------------
printHelp() {
cat <<HELP
usage
cat <<HELP
-----------------------------------------------------------------------------
The default is to extract for all the 'Solved for' variables the initial
residual, the final residual and the number of iterations. Additionally, a
@ -96,8 +95,13 @@ Option -q suppresses the default information and only prints the extracted
variables.
-----------------------------------------------------------------------------
HELP
}
usage
error () {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
usage
exit 1
}

View File

@ -3,7 +3,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
# \\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
@ -32,17 +32,15 @@
#
#------------------------------------------------------------------------------
usage() {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE
Usage: ${0##*/} [OPTION] <file>
options:
-h | -help print the usage
-i | -idle <time> stops if <file> unchanging for <time> sec (default = 60)
-l | -logscale plots data (y-axis) on log scale, e.g. for residuals
-r | -refresh <time> refreshes display every <time> sec (default = 10)
-y | -yrange <range> sets data (y-axis) <range>, format "[0:1]"
-help | -h print the usage
-idle | -i <time> stops if <file> unchanging for <time> sec (default 60s)
-logscale | -l plots data (y-axis) on log scale, e.g. for residuals
-refresh | -r <time> refreshes display every <time> sec (default 10s)
-yrange | -y <range> sets data (y-axis) <range>, format "[0:1]"
Monitor data with Gnuplot from time-value(s) graphs written by OpenFOAM
e.g. by functionObjects
@ -52,16 +50,22 @@ Example:
foamMonitor -l postProcessing/residuals/0/residuals.dat
USAGE
}
error() {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
usage
exit 1
}
plotFileHeader() {
cat<<EOF
set term x11 1 font "helvetica,17" linewidth 1.5 persist noraise
$LOGSCALE
$YRANGE
$logscale
$yrange
set title "Data Monitoring"
set xlabel "$XLABEL"
set xlabel "$xlabel"
plot \\
EOF
}
@ -69,48 +73,50 @@ EOF
plotFileFooter() {
cat<<EOF
pause $REFRESH
pause $refresh
reread
EOF
}
howMany() ( set -f; set -- $1; echo $# )
isInteger() {
[ ! -z "${1##*[!0-9]*}" ] && echo "$1" && return 0
}
IDLE=60
REFRESH=10
LOGSCALE=""
YRANGE=""
GNUPLOT=$(which gnuplot)
! [ "x$GNUPLOT" = "x" ] || usage "Gnuplot not installed"
idle=60
refresh=10
logscale=""
yrange=""
command -v gnuplot >/dev/null 2>&1 || error "Gnuplot not installed"
# parse options
while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help)
usage
usage && exit 0
;;
-i | -idle)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
[ ! -z "${2##*[!0-9]*}" ] && IDLE=$2 || usage "Argument of '$1' is not an integer: '$2'"
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
idle=$(isInteger "$2") || error "Argument of '$1' is not an integer: '$2'"
shift 2
;;
-l | -logscale)
LOGSCALE="set logscale y"
logscale="set logscale y"
shift 1
;;
-r | -refresh)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
[ ! -z "${2##*[!0-9]*}" ] && REFRESH=$2 || usage "Argument of '$1' is not an integer: '$2'"
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
refresh=$(isInteger "$2") || error "Argument of '$1' is not an integer: '$2'"
shift 2
;;
-y | -yrange)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
YRANGE="set yrange $2"
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
yrange="set yrange $2"
shift 2
;;
-*)
usage "unknown option: '$*'"
error "unknown option: '$*'"
;;
*)
break
@ -118,64 +124,65 @@ do
esac
done
[ $# -eq 1 ] || usage "Incorrect arguments specified"
[ -f $1 ] || usage "File $1 does not exit"
FILE=$1
[ $# -eq 1 ] || error "Incorrect arguments specified"
[ -f "$1" ] || error "File $1 does not exit"
file=$1
# Get KEYS from header
KEYS=$(grep -E '^#' $FILE | tail -1)
# Get keys from header
keys=$(grep -E '^#' "$file" | tail -1)
[ "x$KEYS" = "x" ] && KEYS="# Step"
NKEYS=$(howMany "$KEYS")
NCOLS=$(tail -1 $FILE | awk '{ print NF}')
[ "x$keys" = "x" ] && keys="# Step"
n_keys=$(howMany "$keys")
n_cols=$(tail -1 "$file" | awk '{ print NF }')
# With full column labels, NKEYS = NCOLS + 1, since it includes "#"
# With full column labels, n_keys = n_cols + 1, since it includes "#"
# If NKEYS > NCOLS + 1, REMOVE EXCESS KEYS
NCOLSPONE=$(expr $NCOLS + 1)
[ "$NKEYS" -gt "$NCOLSPONE" ] && KEYS=$(echo $KEYS | cut -d" " -f1-$NCOLSPONE)
NKEYS=$(howMany "$KEYS")
# If n_keys > n_cols + 1, REMOVE EXCESS keys
n_cols_pone=$(( n_cols + 1 ))
[ "$n_keys" -gt "$n_cols_pone" ] && \
keys=$(echo "$keys" | cut -d" " -f1-$n_cols_pone)
n_keys=$(howMany "$keys")
i=0
while [ "$NKEYS" -le "$NCOLS" ]
while [ "$n_keys" -le "$n_cols" ]
do
i=$(expr $i + 1)
KEYS="$KEYS data$i"
NKEYS=$(howMany "$KEYS")
i=$(( i + 1 ))
keys="$keys data$i"
n_keys=$(howMany "$keys")
done
# Remove # and Time keys
XLABEL=$(echo $KEYS | cut -d " " -f2)
KEYS=$(echo $KEYS | cut -d " " -f3-)
xlabel=$(echo "$keys" | cut -d " " -f2)
keys=$(echo "$keys" | cut -d " " -f3-)
GPFILE=$(mktemp)
plotFileHeader > $GPFILE
gp_file=$(mktemp)
plotFileHeader > "$gp_file"
i=1
for field in $KEYS
for field in $keys
do
i=$(expr $i + 1)
PLOTLINE="\"$FILE\" using 1:${i} with lines title \"$field\""
if [ $i -lt $NCOLS ]
i=$(( i + 1 ))
plot_line="\"$file\" using 1:${i} with lines title \"$field\""
if [ $i -lt "$n_cols" ]
then
PLOTLINE="$PLOTLINE, \\"
plot_line="$plot_line, \\"
fi
echo $PLOTLINE >> $GPFILE
echo $plot_line >> "$gp_file"
done
plotFileFooter >> $GPFILE
plotFileFooter >> "$gp_file"
touch $FILE
$GNUPLOT $GPFILE &
PID=$!
touch "$file"
gnuplot "$gp_file" &
pid=$!
while true
do
MODTIME=$(stat --format=%Y $FILE)
IDLEAGO=$(expr $(date +%s) - $IDLE)
test "$MODTIME" -gt "$IDLEAGO" || break
sleep $REFRESH
mod_time=$(stat --format=%Y "$file")
idle_ago=$(( $(date +%s) - idle ))
test "$mod_time" -gt "$idle_ago" || break
sleep "$refresh"
done
kill -9 $PID
rm $GPFILE
kill -9 $pid
rm "$gp_file"
#------------------------------------------------------------------------------

View File

@ -30,12 +30,13 @@
#
#------------------------------------------------------------------------------
Script=${0##*/}
DIR="$FOAM_ETC/codeTemplates/BC"
dir="$FOAM_ETC/codeTemplates/BC"
usage() {
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE
Usage: $Script [-h | -help] <base> <type> <boundaryConditionName>
Usage: $Script [OPTIONS] <base> <type> <boundaryConditionName>
options:
-help | -h help
* Create directory of source and compilation files for a new boundary condition
<boundaryConditionName> (dir)
@ -62,8 +63,14 @@ USAGE
exit 1
}
error() {
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
usage
exit 1
}
cap() {
echo $1 | sed -e 's/^./\U&/'
echo "$1" | sed -e 's/^./\U&/'
}
# Implicitly covers a lone -help
@ -71,105 +78,107 @@ cap() {
case "$1" in
(-h | -help)
usage
usage && exit 0
;;
(-f | -fixedValue | fixedValue)
BASE=fixedValue
base=fixedValue
;;
(-m | -mixed | mixed )
BASE=mixed
base=mixed
;;
(*)
usage "Unknown <base> condition '$1'"
error "Unknown <base> condition '$1'"
;;
esac
shift
case "$1" in
(-a | -all | all | template)
TYPE=Type
UNIT='VALUE-or-(VALUE 0 0)'
type=Type
unit='VALUE-or-(VALUE 0 0)'
;;
(-s | -scalar | scalar)
TYPE=scalar
UNIT=VALUE
type=scalar
unit=VALUE
;;
(-v | -vector | vector)
TYPE=vector
UNIT='(VALUE 0 0)'
type=vector
unit='(VALUE 0 0)'
;;
(-t | -tensor | tensor)
TYPE=tensor
UNIT='(VALUE 0 0 0 0 0 0 0 0)'
type=tensor
unit='(VALUE 0 0 0 0 0 0 0 0)'
;;
(-symmTensor | symmTensor)
TYPE=symmTensor
UNIT='(VALUE 0 0 0 0 0)'
type=symmTensor
unit='(VALUE 0 0 0 0 0)'
;;
(-sphericalTensor | sphericalTensor)
TYPE=sphericalTensor
UNIT=VALUE
type=sphericalTensor
unit=VALUE
;;
(*)
usage "Unknown <type> option '$1'"
error "Unknown <type> option '$1'"
;;
esac
shift
[ "$#" -eq 1 ] || usage "Wrong number of arguments"
NAME=$1
[ "$#" -eq 1 ] || error "Wrong number of arguments"
name=$1
# Prevents over-writing of existing directory
[ -d $NAME ] && usage "$NAME directory already exists, aborting..."
echo "Creating $NAME directory" && mkdir $NAME
[ -d "$name" ] && error "$name directory already exists, aborting..."
echo "Creating $name directory" && mkdir "$name"
# Establish meta template files to copy
FILES=$(cd ${DIR} && ls *.*)
[ "$TYPE" = "Type" ] || FILES=$(cd ${DIR} && ls BC.[CH])
files=$(find "${dir}" -name "*.*" -type f -exec basename {} \;)
[ "$type" = "Type" ] || \
files=$(find "${dir}" -name "BC.[CH]" -type f -exec basename {} \;)
# Substitutions for meta-template files
FIELD="Field<${TYPE}>"
[ "$TYPE" = "Type" ] || FIELD=${TYPE}Field
field="Field<${type}>"
[ "$type" = "Type" ] || field=${type}Field
FVPATCHF=fvPatch$(cap $FIELD)
CLASS=$NAME$(cap $FVPATCHF)
PARENT=$BASE$(cap $FVPATCHF)
CONSTRUCT=$(echo $CLASS | sed 's/<Type>//g')
YEAR=$(date +%Y)
fvpatchf=fvPatch$(cap $field)
class=$name$(cap "$fvpatchf")
parent=$base$(cap "$fvpatchf")
construct=$(echo "$class" | sed 's/<Type>//g')
year=$(date +%Y)
# Create some example values for the Description
n=0
for N in $(echo "ZERO ONE TWO THREE FOUR")
for N in zero one two three four
do
eval $(expr $N='$(echo $UNIT | sed "s#VALUE#$n#g")')
n=$(( $n + 1 ))
eval $N="$(echo \"$unit\" | sed "s#VALUE#$n#g")"
n=$(( n + 1 ))
done
# Make substitutions to meta-template files
for F in $FILES
for f in $files
do
EXT=$(echo $F | sed "s#BC##")
NEWFILE=${CONSTRUCT}${EXT}
echo " Adding file ${NEWFILE}..."
ext=$(echo "$f" | sed "s#BC##")
new_file=${construct}${ext}
echo " Adding file ${new_file}..."
# Adds readScalar function when TYPE = scalar
sed -e "s#TYPE#${TYPE}#g" \
-e "s#NAME#${NAME}#g" \
-e "s#BASE#${BASE}#g" \
-e "s#CONSTRUCT#${CONSTRUCT}#g" \
-e "s#YEAR#${YEAR}#g" \
-e "s#CLASS#${CLASS}#g" \
-e "s#FIELD#${FIELD}#g" \
-e "s#FVPATCHF#${FVPATCHF}#g" \
-e "s#PARENT#${PARENT}#g" \
-e "s#ZERO#${ZERO}#g" \
-e "s#ONE#${ONE}#g" \
-e "s#TWO#${TWO}#g" \
-e "s#THREE#${THREE}#g" \
-e "s#FOUR#${FOUR}#g" \
# Adds readScalar function when type = scalar
# shellcheck disable=SC2154
sed -e "s#TYPE#${type}#g" \
-e "s#NAME#${name}#g" \
-e "s#BASE#${base}#g" \
-e "s#CONSTRUCT#${construct}#g" \
-e "s#YEAR#${year}#g" \
-e "s#CLASS#${class}#g" \
-e "s#FIELD#${field}#g" \
-e "s#FVPATCHF#${fvpatchf}#g" \
-e "s#PARENT#${parent}#g" \
-e "s#ZERO#${zero}#g" \
-e "s#ONE#${one}#g" \
-e "s#TWO#${two}#g" \
-e "s#THREE#${three}#g" \
-e "s#FOUR#${four}#g" \
-e 's/>>/>>/g' \
${DIR}/${F} > ${NAME}/${NEWFILE}
"${dir}/${f}" > "${name}/${new_file}"
case $BASE in
case $base in
fixedValue)
# refValue(), refGrad(), valueFraction() removed
# phip removed
@ -178,7 +187,7 @@ do
-e '/refGrad/d' \
-e '/valueFraction/d' \
-e '/const scalarField\& phip/,/);/d' \
${NAME}/${NEWFILE}
"${name}/${new_file}"
;;
mixed)
# evaluate() removed
@ -186,15 +195,15 @@ do
sed -i \
-e '/evaluate/d' \
-e 's/operator==/refValue() =/g' \
${NAME}/${NEWFILE}
"${name}/${new_file}"
;;
esac
case $TYPE in
case $type in
Type)
# Build Macro removed (in ..Fields.C)
sed -i -e '/Build Macro/,/^}/d' \
${NAME}/${NEWFILE}
"${name}/${new_file}"
;;
*)
# template<class Type> removed
@ -206,13 +215,15 @@ do
-e 's/this->//g' \
-e 's/\.template[\t ]*\([a-Z]\)/\.\1/g' \
-e '/#ifdef NoRepository/,/\/\/ */d' \
${NAME}/${NEWFILE}
"${name}/${new_file}"
;;
esac
done
echo "Creating Make subdirectory" && cp -r ${DIR}/Make ${NAME}
COMPILED=$(cd ${NAME} && ls -r1 *C | head -1) # ...Fields.C for template class
sed -i -e "s#NAME#${NAME}#g" -e "s#COMPILED.*#${COMPILED}#g" ${NAME}/Make/files
echo "Creating Make subdirectory" && cp -r "${dir}/Make" "${name}"
# Get ...Fields.C for template class, otherwise ...Field.C
compiled=$(find "${name}" -name "*.C" -exec basename {} \; | sort | tail -1)
sed -i -e "s#NAME#${name}#g" -e "s#COMPILED.*#${compiled}#g" "${name}/Make/files"
#------------------------------------------------------------------------------

View File

@ -3,7 +3,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
@ -33,8 +33,6 @@
# undefined behaviour
#------------------------------------------------------------------------------
usage() {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE
Usage: ${0##*/} [OPTION] [PARAVIEW_OPTION]
@ -47,12 +45,17 @@ options:
-touchAll create .blockMesh, .OpenFOAM files (and for all regions)
-help print the usage
paraview options start with a double dashes
* start paraview $ParaView_VERSION with the OpenFOAM libraries
USAGE
}
error() {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
usage
exit 1
}
@ -77,7 +80,7 @@ while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help)
usage
usage && exit 0
;;
-block | -blockMesh)
extension=blockMesh
@ -89,12 +92,12 @@ do
shift
;;
-case)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
cd "$2" 2>/dev/null || usage "directory does not exist: '$2'"
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
cd "$2" 2>/dev/null || error "directory does not exist: '$2'"
shift 2
;;
-region)
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
regionName=$2
shift 2
;;
@ -116,13 +119,13 @@ do
break # Stop here, treat this and balance as paraview options
;;
*)
usage "unknown option/argument: '$*'"
error "unknown option/argument: '$*'"
;;
esac
done
# Check that reader module has been built
if [ $requirePV -eq 1 -a ! -f $PV_PLUGIN_PATH/libPVFoamReader_SM.so ]
if [ $requirePV -eq 1 -a ! -f "$PV_PLUGIN_PATH/libPVFoamReader_SM.so" ]
then
cat<< BUILDREADER
@ -153,7 +156,7 @@ hasDataArg()
done
}
hasDataArg $@
hasDataArg "$@"
# Get a sensible caseName from the directory name
@ -163,7 +166,7 @@ fvControls="system"
if [ -n "$regionName" ]
then
if [ ! -d constant/$regionName ]
if [ ! -d constant/"$regionName" ]
then
echo "FATAL ERROR: Region $regionName does not exist"
exit 1
@ -186,7 +189,7 @@ all)
# Discover probable regions
for region in constant/*
do
if [ -d $region -a -d $region/polyMesh ]
if [ -d "$region" -a -d "$region"/polyMesh ]
then
regionName=${region##*/}
touch "$caseName{$regionName}.$extension"
@ -258,14 +261,14 @@ else
[ -n "$warn" ] || {
echo "Cannot locate OpenFOAM-format case files"
echo -n "Would you like to open ParaView anyway <Y|n>:"
printf "Would you like to open ParaView anyway <Y|n>:"
read open
[ "$open" = "" ] || echo $open | grep -iqE "^y" && paraview
[ "$open" = "" ] || echo "$open" | grep -iqE "^y" && paraview
exit
}
# Only create/remove caseFile if it didn't already exist
[ -e $caseFile ] || {
[ -e "$caseFile" ] || {
trap "rm -f $caseFile 2>/dev/null; exit 0" EXIT TERM INT
touch "$caseFile"
echo "Created temporary '$caseFile'"

View File

@ -3,7 +3,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
# \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
@ -46,7 +46,7 @@ do
if [ -d "$i" ]
then
echo "removing all core files: $i"
find $i \( -type f -name 'core' -o -name 'core.[1-9]*' -o -name 'vgcore.*' \) -print | xargs -t rm 2>/dev/null
find $i \( -type f -name 'core' -o -name 'core.[1-9]*' -o -name 'vgcore.*' \) -print0 | xargs -t rm 2>/dev/null
else
echo "no directory: $i" 1>&2
fi

View File

@ -3,7 +3,7 @@
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
# \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
@ -46,7 +46,7 @@ do
if [ -d "$i" ]
then
echo "removing all *~ files: $i"
find $i \( -name '*~' -o -name '.*~' \) -print | xargs -t rm 2>/dev/null
find $i \( -name '*~' -o -name '.*~' \) -print0 | xargs -t rm 2>/dev/null
else
echo "no directory: $i" 1>&2
fi