diff --git a/bin/foamMonitor b/bin/foamMonitor index fda9121b9..df5aca2da 100755 --- a/bin/foamMonitor +++ b/bin/foamMonitor @@ -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" diff --git a/bin/foamNewApp b/bin/foamNewApp index e960ea0b7..f6ffea72b 100755 --- a/bin/foamNewApp +++ b/bin/foamNewApp @@ -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: $Script [OPTIONS] +options: + -help | -h help -* Create directory with source and compilation files for a new application - (dir) - - .C +Create directory with source and compilation files for a new application + (dir) + - .C - Make (dir) - files - options - Compiles an executable named in \$FOAM_USER_APPBIN: + Compiles an executable named 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" #------------------------------------------------------------------------------ diff --git a/bin/foamNewBC b/bin/foamNewBC index 5abaabef1..3725e4ff9 100755 --- a/bin/foamNewBC +++ b/bin/foamNewBC @@ -38,7 +38,7 @@ Usage: $Script [OPTIONS] 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 (dir) - .C and .H source files - Make (dir) diff --git a/bin/foamNewFunctionObject b/bin/foamNewFunctionObject index 244553757..326a9255d 100755 --- a/bin/foamNewFunctionObject +++ b/bin/foamNewFunctionObject @@ -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< + cat< +options: + -help | -h help -* Create directory with source and compilation files for a new function object - (dir) - - .H - - .C - - IO.H +Create directory with source and compilation files for a new function object + (dir) + - .H + - .C + - IO.H - Make (dir) - files - options - Compiles a library named libFunctionObject.so in + Compiles a library named libFunctionObject.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" #------------------------------------------------------------------------------ diff --git a/bin/foamSearch b/bin/foamSearch index e458385db..560aafdf0 100755 --- a/bin/foamSearch +++ b/bin/foamSearch @@ -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< -Options: --c | -count prefix lines by the number of occurrences --h | -help help +Usage: $Script [OPTIONS] +options: + -count | -c prefix lines by the number of occurrences + -help | -h help -* Searches the for files named and extracts entries with - . Sorts result into a list of unique entries (removing repeats). +Searches the for files named and extracts entries with +. 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 #------------------------------------------------------------------------------ diff --git a/bin/foamSequenceVTKFiles b/bin/foamSequenceVTKFiles index 86e512228..a6815b529 100755 --- a/bin/foamSequenceVTKFiles +++ b/bin/foamSequenceVTKFiles @@ -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 < specify case directory (default = local dir) - -d | -dir post-processing directory (default = postProcessing) - -h | -help help - -o | -out output links directory (default = sequencedVTK) +options: + -case | -c specify case directory (default = local dir) + -dir | -d post-processing directory (default = postProcessing) + -help | -h help + -out | -o output links directory (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