Scripts in bin: improved script quality, option listing and
exit status on -help
This commit is contained in:
@ -78,7 +78,9 @@ reread
|
||||
EOF
|
||||
}
|
||||
|
||||
howMany() ( set -f; set -- $1; echo $# )
|
||||
howMany() ( echo "$1" | awk '{ print NF }' )
|
||||
#howMany() ( echo "$1" | set -f; set -- $1; echo $# )
|
||||
|
||||
isInteger() {
|
||||
[ ! -z "${1##*[!0-9]*}" ] && echo "$1" && return 0
|
||||
}
|
||||
@ -125,7 +127,7 @@ do
|
||||
done
|
||||
|
||||
[ $# -eq 1 ] || error "Incorrect arguments specified"
|
||||
[ -f "$1" ] || error "File $1 does not exit"
|
||||
[ -f "$1" ] || error "File $1 does not exit"
|
||||
file=$1
|
||||
|
||||
# Get keys from header
|
||||
@ -155,7 +157,7 @@ done
|
||||
xlabel=$(echo "$keys" | cut -d " " -f2)
|
||||
keys=$(echo "$keys" | cut -d " " -f3-)
|
||||
|
||||
gp_file=$(mktemp)
|
||||
gp_file=$(mktemp /tmp/tmp.XXXXXX)
|
||||
plotFileHeader > "$gp_file"
|
||||
i=1
|
||||
for field in $keys
|
||||
@ -166,7 +168,7 @@ do
|
||||
then
|
||||
plot_line="$plot_line, \\"
|
||||
fi
|
||||
echo $plot_line >> "$gp_file"
|
||||
echo "$plot_line" >> "$gp_file"
|
||||
done
|
||||
plotFileFooter >> "$gp_file"
|
||||
|
||||
|
||||
@ -30,47 +30,53 @@
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
Script=${0##*/}
|
||||
DIR="$FOAM_ETC/codeTemplates/app"
|
||||
dir="$FOAM_ETC/codeTemplates/app"
|
||||
|
||||
usage() {
|
||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||
cat<<USAGE
|
||||
Usage: $Script [-h | -help] <applicationName>
|
||||
Usage: $Script [OPTIONS] <application>
|
||||
options:
|
||||
-help | -h help
|
||||
|
||||
* Create directory with source and compilation files for a new application
|
||||
<applicationName> (dir)
|
||||
- <applicationName>.C
|
||||
Create directory with source and compilation files for a new application
|
||||
<application> (dir)
|
||||
- <application>.C
|
||||
- Make (dir)
|
||||
- files
|
||||
- options
|
||||
Compiles an executable named <applicationName> in \$FOAM_USER_APPBIN:
|
||||
Compiles an executable named <application> in \$FOAM_USER_APPBIN:
|
||||
$FOAM_USER_APPBIN
|
||||
USAGE
|
||||
}
|
||||
|
||||
error() {
|
||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||
usage
|
||||
exit 1
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
(-h | -help)
|
||||
usage
|
||||
(-help | -h)
|
||||
usage && exit 0
|
||||
;;
|
||||
-*)
|
||||
usage "$1 is not a valid filename"
|
||||
error "$1 is not a valid filename"
|
||||
;;
|
||||
esac
|
||||
|
||||
[ "$#" -eq 1 ] || usage "Wrong number of arguments"
|
||||
[ -d "$1" ] && usage "$1 directory already exists, aborting..."
|
||||
[ "$#" -eq 1 ] || error "Wrong number of arguments"
|
||||
[ -d "$1" ] && error "$1 directory already exists, aborting..."
|
||||
|
||||
NAME=$1
|
||||
YEAR=$(date +%Y)
|
||||
app=$1
|
||||
year=$(date +%Y)
|
||||
|
||||
echo "Creating application code directory $NAME" && mkdir $NAME
|
||||
sed -e "s#NAME#${NAME}#g" \
|
||||
-e "s#YEAR#${YEAR}#g" \
|
||||
${DIR}/app.C > $NAME/$NAME.C
|
||||
echo "Creating application code directory ${app}" && mkdir "${app}"
|
||||
sed -e "s#NAME#${app}#g" \
|
||||
-e "s#YEAR#${year}#g" \
|
||||
"${dir}/app.C" > "${app}/${app}.C"
|
||||
|
||||
echo "Creating Make subdirectory" && mkdir $NAME/Make
|
||||
sed "s#NAME#${NAME}#g" ${DIR}/Make/files > $NAME/Make/files
|
||||
cp ${DIR}/Make/options $NAME/Make
|
||||
echo "Creating Make subdirectory" && mkdir "${app}/Make"
|
||||
sed "s#NAME#${app}#g" "${dir}/Make/files" > "${app}/Make/files"
|
||||
cp "${dir}/Make/options" "${app}/Make"
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
@ -38,7 +38,7 @@ Usage: $Script [OPTIONS] <base> <type> <boundaryConditionName>
|
||||
options:
|
||||
-help | -h help
|
||||
|
||||
* Create directory of source and compilation files for a new boundary condition
|
||||
Create directory of source and compilation files for a new boundary condition
|
||||
<boundaryConditionName> (dir)
|
||||
- .C and .H source files
|
||||
- Make (dir)
|
||||
|
||||
@ -31,54 +31,64 @@
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
Script=${0##*/}
|
||||
DIR="$FOAM_ETC/codeTemplates/functionObject"
|
||||
dir="$FOAM_ETC/codeTemplates/functionObject"
|
||||
|
||||
error() {
|
||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||
usage
|
||||
exit 1
|
||||
}
|
||||
|
||||
usage() {
|
||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||
cat<<USAGE
|
||||
Usage: $Script [-h | -help] <functionObjectName>
|
||||
cat<<USAGE
|
||||
Usage: $Script [OPTIONS] <functionObject>
|
||||
options:
|
||||
-help | -h help
|
||||
|
||||
* Create directory with source and compilation files for a new function object
|
||||
<functionObjectName> (dir)
|
||||
- <functionObjectName>.H
|
||||
- <functionObjectName>.C
|
||||
- IO<functionObjectName>.H
|
||||
Create directory with source and compilation files for a new function object
|
||||
<functionObject> (dir)
|
||||
- <functionObject>.H
|
||||
- <functionObject>.C
|
||||
- IO<functionObject>.H
|
||||
- Make (dir)
|
||||
- files
|
||||
- options
|
||||
Compiles a library named lib<functionObjectName>FunctionObject.so in
|
||||
Compiles a library named lib<functionObject>FunctionObject.so in
|
||||
\$FOAM_USER_LIBBIN:
|
||||
$FOAM_USER_LIBBIN
|
||||
USAGE
|
||||
exit 1
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
(-h | -help)
|
||||
usage
|
||||
usage && exit 0
|
||||
;;
|
||||
-*)
|
||||
usage "$1 is not a valid option/filename"
|
||||
error "$1 is not a valid option/filename"
|
||||
;;
|
||||
esac
|
||||
|
||||
[ "$#" -eq 1 ] || usage "Wrong number of arguments"
|
||||
[ -d "$1" ] && usage "$1 directory already exists, aborting..."
|
||||
[ "$#" -eq 1 ] || error "Wrong number of arguments"
|
||||
[ -d "$1" ] && error "$1 directory already exists, aborting..."
|
||||
|
||||
NAME=$1
|
||||
YEAR=$(date +%Y)
|
||||
func=$1
|
||||
year=$(date +%Y)
|
||||
|
||||
echo "Creating function object code directory $NAME" && mkdir $NAME
|
||||
for F in $(ls ${DIR}/*.*)
|
||||
echo "Creating function object code directory $func" && mkdir "${func}"
|
||||
|
||||
tmp=$(mktemp tmp.XXXXXX)
|
||||
find "${dir}" -name '*.*' > "$tmp"
|
||||
while IFS= read -r template_file
|
||||
do
|
||||
FILE=$(basename $F | sed "s#FUNCTIONOBJECT#${NAME}#g")
|
||||
sed -e "s#FUNCTIONOBJECT#${NAME}#g" \
|
||||
-e "s#YEAR#${YEAR}#g" \
|
||||
${F} > ${NAME}/${FILE}
|
||||
done
|
||||
file=$(basename "$template_file" | sed "s#FUNCTIONOBJECT#${func}#g")
|
||||
sed -e "s#FUNCTIONOBJECT#${func}#g" \
|
||||
-e "s#YEAR#${year}#g" \
|
||||
"$template_file" > "${func}/${file}"
|
||||
done < "$tmp"
|
||||
rm "$tmp"
|
||||
|
||||
echo "Creating Make subdirectory" && mkdir $NAME/Make
|
||||
sed "s#FUNCTIONOBJECT#${NAME}#g" ${DIR}/Make/files > $NAME/Make/files
|
||||
cp ${DIR}/Make/options $NAME/Make
|
||||
echo "Creating Make subdirectory" && mkdir "$func/Make"
|
||||
sed "s#FUNCTIONOBJECT#${func}#g" "${dir}/Make/files" > "$func/Make/files"
|
||||
cp "${dir}/Make/options" "$func/Make"
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
# ========= |
|
||||
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
# \\ / O peration |
|
||||
# \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
||||
# \\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation
|
||||
# \\/ M anipulation |
|
||||
#-------------------------------------------------------------------------------
|
||||
# License
|
||||
@ -35,56 +35,59 @@
|
||||
Script=${0##*/}
|
||||
|
||||
usage() {
|
||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||
cat<<USAGE
|
||||
Usage: $Script [OPTIONS] <directory> <keyword> <file>
|
||||
|
||||
Options:
|
||||
-c | -count prefix lines by the number of occurrences
|
||||
-h | -help help
|
||||
Usage: $Script [OPTIONS] <directory> <filename> <keyword>
|
||||
options:
|
||||
-count | -c prefix lines by the number of occurrences
|
||||
-help | -h help
|
||||
|
||||
* Searches the <directory> for files named <file> and extracts entries with
|
||||
<keyword>. Sorts result into a list of unique entries (removing repeats).
|
||||
Searches the <directory> for files named <filename> and extracts entries with
|
||||
<keyword>. Sorts result into a list of unique entries (removing repeats).
|
||||
|
||||
Examples:
|
||||
Examples:
|
||||
* Default ddtSchemes entries in the fvSchemes files in all tutorials:
|
||||
foamSearch $FOAM_TUTORIALS ddtSchemes.default fvSchemes
|
||||
foamSearch $FOAM_TUTORIALS fvSchemes ddtSchemes.default
|
||||
* Relaxations factors for U in fvSolutions files in all tutorials:
|
||||
foamSearch -c $FOAM_TUTORIALS relaxationFactors.equations.U fvSolution
|
||||
|
||||
foamSearch -c $FOAM_TUTORIALS fvSolution relaxationFactors.equations.U
|
||||
USAGE
|
||||
}
|
||||
|
||||
error() {
|
||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||
usage
|
||||
exit 1
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
(-c | -count)
|
||||
COUNT="-c"
|
||||
count="-c"
|
||||
shift
|
||||
;;
|
||||
(-h | -help)
|
||||
usage
|
||||
usage && exit 0
|
||||
;;
|
||||
-*)
|
||||
usage "$1 is not a valid option/filename"
|
||||
error "$1 is not a valid option/filename"
|
||||
;;
|
||||
esac
|
||||
|
||||
[ "$#" -eq 3 ] || usage "Wrong number of arguments: expected 3, found $#"
|
||||
[ -d "$1" ] || usage "$1 is not a directory"
|
||||
[ "$#" -eq 3 ] || error "Wrong number of arguments: expected 3, found $#"
|
||||
[ -d "$1" ] || error "$1 is not a directory"
|
||||
|
||||
TEMP=temp.$$
|
||||
FILES=$(find $1 -name $3)
|
||||
[ -n "$FILES" ] || usage "No file $3 found in $1"
|
||||
tmp=$(mktemp tmp.XXXXXX)
|
||||
files=$(find "$1" -name "$3")
|
||||
[ -n "$files" ] || error "No file $3 found in $1"
|
||||
|
||||
for F in $FILES
|
||||
for f in $files
|
||||
do
|
||||
foamDictionary -entry $2 $F 2>/dev/null >> $TEMP
|
||||
foamDictionary -entry "$2" "$f" 2>/dev/null >> "$tmp"
|
||||
done
|
||||
|
||||
[ -s "$TEMP" ] && \
|
||||
sort $TEMP | uniq $COUNT | sed '/^[\t 1-9]*$/d' || \
|
||||
[ -s "$tmp" ] && \
|
||||
sort "$tmp" | uniq $count | sed '/^[\t 1-9]*$/d' || \
|
||||
echo "No keyword $2 found in $3 files"
|
||||
|
||||
rm $TEMP 2>/dev/null
|
||||
rm "$tmp" 2>/dev/null
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
@ -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,54 +33,58 @@
|
||||
# - Default directory name for VTK files is postProcessing
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
usage () {
|
||||
error() {
|
||||
exec 1>&2
|
||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||
cat <<USAGE
|
||||
usage
|
||||
exit 1
|
||||
}
|
||||
|
||||
usage() {
|
||||
cat <<USAGE
|
||||
|
||||
Usage: ${0##*/} [OPTIONS] ...
|
||||
options:
|
||||
-c | -case <dir> specify case directory (default = local dir)
|
||||
-d | -dir <dir> post-processing directory <dir> (default = postProcessing)
|
||||
-h | -help help
|
||||
-o | -out <dir> output links directory <dir> (default = sequencedVTK)
|
||||
options:
|
||||
-case | -c <dir> specify case directory (default = local dir)
|
||||
-dir | -d <dir> post-processing directory <dir> (default = postProcessing)
|
||||
-help | -h help
|
||||
-out | -o <dir> output links directory <dir> (default = sequencedVTK)
|
||||
|
||||
Creates symbolic links to all VTK files in a post-processing directory
|
||||
Links form a sequence like name.0000.vtk, name.0001.vtk, etc.
|
||||
Paraview recognises the link names as a sequence which can be opened and played.
|
||||
The sequence of links to images can be used to create a video from the images.
|
||||
- Default directory name for VTK files is postProcessing
|
||||
|
||||
USAGE
|
||||
exit 1
|
||||
}
|
||||
|
||||
DIR=postProcessing
|
||||
OUT=sequencedVTK
|
||||
dir=postProcessing
|
||||
out=sequencedVTK
|
||||
|
||||
while [ "$#" -gt 0 ]
|
||||
do
|
||||
case "$1" in
|
||||
-c | -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
|
||||
;;
|
||||
-d | -dir)
|
||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
||||
DIR=$2
|
||||
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
|
||||
dir=$2
|
||||
shift 2
|
||||
;;
|
||||
-h | -help)
|
||||
usage
|
||||
usage && exit 0
|
||||
;;
|
||||
-o | -out)
|
||||
[ "$#" -ge 2 ] || usage "'$1' option requires an argument"
|
||||
OUT=$2
|
||||
[ "$#" -ge 2 ] || error "'$1' option requires an argument"
|
||||
out=$2
|
||||
shift 2
|
||||
;;
|
||||
-*)
|
||||
usage "invalid option '$1'"
|
||||
error "invalid option '$1'"
|
||||
;;
|
||||
*)
|
||||
break
|
||||
@ -88,39 +92,36 @@ do
|
||||
esac
|
||||
done
|
||||
|
||||
if [ ! -d $DIR ]; then
|
||||
echo "Cannot find postProcessing directory, exiting."
|
||||
exit 0
|
||||
fi
|
||||
[ ! -d "$dir" ] && error "Cannot find postProcessing directory, exiting."
|
||||
|
||||
FILES=$(find $DIR -type f -name *vtk)
|
||||
NAMES=$(for f in $FILES; do basename $f .vtk; done | sort -u)
|
||||
files=$(find "$dir" -type f -name "*vtk")
|
||||
names=$(for f in $files; do basename "$f" .vtk; done | sort -u)
|
||||
|
||||
if [ -d $OUT ]; then
|
||||
echo "$OUT directory already exists. Deleting links within it..."
|
||||
rm -rf $OUT/*
|
||||
if [ -d "$out" ]; then
|
||||
echo "$out directory already exists. Deleting links within it..."
|
||||
rm "${out:?}"/* 2>/dev/null
|
||||
else
|
||||
echo "Creating $OUT directory..."
|
||||
mkdir $OUT
|
||||
echo "Creating $out directory..."
|
||||
mkdir "$out"
|
||||
fi
|
||||
|
||||
for N in $NAMES
|
||||
for n in $names
|
||||
do
|
||||
echo "Sequencing all VTK files named $N.vtk"
|
||||
echo "Sequencing all VTK files named $n.vtk"
|
||||
|
||||
# Create list of VTK files, ordered by time step
|
||||
FILE_LIST=$(echo $FILES | \
|
||||
file_list=$(echo "$files" | \
|
||||
tr " " "\n" | \
|
||||
grep $N.vtk | \
|
||||
grep "$n.vtk" | \
|
||||
awk -F'/' '{print($(NF-1)" "$0)}' | \
|
||||
sort -k 1 -g | \
|
||||
cut -d' ' -f2)
|
||||
|
||||
i=0
|
||||
for F in $FILE_LIST
|
||||
for f in $file_list
|
||||
do
|
||||
i=$(expr $i + 1) # Relies on ordered list of $sourceFiles
|
||||
LINK=$(printf "${N}.%04d.vtk" $i)
|
||||
ln -s ../$F $OUT/$LINK
|
||||
i=$(( i + 1 )) # Relies on ordered list of files
|
||||
link=$(printf "${n}.%04d.vtk" $i)
|
||||
ln -s "../$f" "$out/$link"
|
||||
done
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user