Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • openfoam openfoam
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 425
    • Issues 425
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 8
    • Merge requests 8
  • Deployments
    • Deployments
    • Releases
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • Development
  • openfoamopenfoam
  • Issues
  • #2202
Closed
Open
Issue created Sep 08, 2021 by s1291@samir1291

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

Edited Sep 08, 2021 by s1291
Assignee
Assign to
Time tracking