foamMonitor: Get the correct number of columns and allow the usage of process substitution pipes
Hello,
In the foamMonitor script, we can see in the line 140 that NCOLS will be 0 if the input file contains trailing blank lines. So instead, I propose the following patch:
NCOLS=$(tac $FILE | grep -m 1 '.' | awk '{ print NF}')
This will guarantee to return the right number of columns without sacrificing performance (I've tested it with an input file with ~ 40 million lines, and the execution time is similar to the previous case using tail command).
In addition, in line 132
Why should one restrict that to regular files only? We can use the -e
flag instead to allow pipes using process substitution, for instance. (This is very useful when you plot over ssh). So line 132 should be:
[ -e $1 ] || usage "File $1 does not exit"
EDIT: Because reading from a pipe is a destructive operation, we need to add the following if condition after line 132:
# check if the input is a named pipe
if [ -p "$1" ]
then
# store the pipe to a temporary file
FILE=$(mktemp)
cat "$1" > "$FILE"
else
FILE="$1"
fi
Thanks,
S.OUCHENE