Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
openfoam
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
openfoam
Commits
d0536fcf
Commit
d0536fcf
authored
3 years ago
by
Kutalmış Berçin
Browse files
Options
Downloads
Patches
Plain Diff
ENH: foamMonitor: modernise and refactor for POSIX compliance (
#2202
)
ENH: add xrange option
parent
94889e78
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/foamMonitor
+82
-43
82 additions, 43 deletions
bin/foamMonitor
with
82 additions
and
43 deletions
bin/foamMonitor
+
82
−
43
View file @
d0536fcf
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
# \\/ M anipulation |
# \\/ M anipulation |
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Copyright (C) 2015 OpenFOAM Foundation
# Copyright (C) 2015 OpenFOAM Foundation
# Copyright (C) 2019 OpenCFD Ltd.
# Copyright (C) 2019
-2021
OpenCFD Ltd.
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# License
# License
# This file is part of OpenFOAM.
# This file is part of OpenFOAM.
...
@@ -34,35 +34,49 @@
...
@@ -34,35 +34,49 @@
# - requires gnuplot, gnuplot_x11
# - requires gnuplot, gnuplot_x11
#
#
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
usage
()
{
printHelp
()
{
exec
1>&2
while
[
"$#"
-ge
1
]
;
do
echo
"
$1
"
;
shift
;
done
cat
<<
USAGE
cat
<<
USAGE
Usage:
${
0
##*/
}
[OPTION] <file>
Usage:
${
0
##*/
}
[OPTIONS] <file>
options:
Options:
-h | -help prints the usage
-g | -grid Draw grid lines
-i | -idle <time> stops if <file> unchanging for <time> sec (default = 60)
-i | -idle <time> Stop if <file> unchanging for <time> sec (default = 60)
-l | -logscale plots data (y-axis) on log scale, e.g. for residuals
-l | -logscale Plot y-axis data on log scale
-r | -refresh <time> refreshes display every <time> sec (default = 10)
-r | -refresh <time> Refresh display every <time> sec (default = 10)
-y | -yrange <range> sets data (y-axis) <range>, format "[0:1]"
-x | -xrange <range> Set <range> of x-axis data, format "[0:1]"
-g | -grid draws grid lines on the plot
-y | -yrange <range> Set <range> of y-axis data, format "[0:1]"
-h | -help Display short help and exit
Monitor data with Gnuplot from time-value(s) graphs written by OpenFOAM
Monitor data with Gnuplot from time-value(s) graphs written by OpenFOAM
e.g. by functionObjects
e.g. by functionObjects. For example,
- requires gnuplot, gnuplot_x11
Example:
foamMonitor -l postProcessing/residuals/0/residuals.dat
foamMonitor -l postProcessing/residuals/0/residuals.dat
USAGE
USAGE
exit
0
# A clean exit
}
# Report error and exit
die
()
{
exec
1>&2
echo
echo
"Error encountered:"
while
[
"$#"
-ge
1
]
;
do
echo
"
$1
"
;
shift
;
done
echo
echo
"See '
${
0
##*/
}
-help' for usage"
echo
exit
1
exit
1
}
}
# Set Gnuplot header
plotFileHeader
()
{
plotFileHeader
()
{
cat
<<
EOF
cat
<<
EOF
set term x11 1 font "helvetica,17" linewidth 1.5 persist noraise
set term x11 1 font "helvetica,17" linewidth 1.5 persist noraise
$LOGSCALE
$LOGSCALE
$XRANGE
$YRANGE
$YRANGE
$GRID
$GRID
set title "Data Monitoring"
set title "Data Monitoring"
...
@@ -71,34 +85,49 @@ plot \\
...
@@ -71,34 +85,49 @@ plot \\
EOF
EOF
}
}
# Set Gnuplot footer
plotFileFooter
()
{
plotFileFooter
()
{
cat
<<
EOF
cat
<<
EOF
pause
$REFRESH
pause
$REFRESH
reread
reread
EOF
EOF
}
}
howMany
()
(
set
-f
;
set
--
$1
;
echo
$#
)
# Count number of tokens in a variable
howMany
()
{
(
set
-f
;
set
--
$1
;
echo
$#
)
}
#-------------------------------------------------------------------------------
IDLE
=
60
IDLE
=
60
REFRESH
=
10
REFRESH
=
10
LOGSCALE
=
""
LOGSCALE
=
""
XRANGE
=
""
YRANGE
=
""
YRANGE
=
""
GRID
=
""
GRID
=
""
GNUPLOT
=
$(
which gnuplot
)
GNUPLOT
=
$(
which gnuplot
)
!
[
"x
$GNUPLOT
"
=
"
x
"
]
||
usage
"
Gnuplot
not
installed"
[
!
"
$GNUPLOT
"
=
""
]
||
die
"foamMonitor requires
Gnuplot installed"
# parse options
#-------------------------------------------------------------------------------
# Parse options
while
[
"$#"
-gt
0
]
while
[
"$#"
-gt
0
]
do
do
case
"
$1
"
in
case
"
$1
"
in
-h
|
-help
*
)
-h
|
-help
*
)
usage
printHelp
;;
;;
-i
|
-idle
)
-i
|
-idle
)
[
"$#"
-ge
2
]
||
usage
"'
$1
' option requires an argument"
[
"$#"
-ge
2
]
||
die
"'
$1
' option requires an argument"
[
!
-z
"
${
2
##*[!0-9]*
}
"
]
&&
IDLE
=
$2
||
usage
"Argument of '
$1
' is not an integer: '
$2
'"
if
[
-n
"
${
2
##*[!0-9]*
}
"
]
then
IDLE
=
$2
else
die
"Argument of '
$1
' is not an integer: '
$2
'"
fi
shift
2
shift
2
;;
;;
-l
|
-logscale
)
-l
|
-logscale
)
...
@@ -106,12 +135,22 @@ do
...
@@ -106,12 +135,22 @@ do
shift
1
shift
1
;;
;;
-r
|
-refresh
)
-r
|
-refresh
)
[
"$#"
-ge
2
]
||
usage
"'
$1
' option requires an argument"
[
"$#"
-ge
2
]
||
die
"'
$1
' option requires an argument"
[
!
-z
"
${
2
##*[!0-9]*
}
"
]
&&
REFRESH
=
$2
||
usage
"Argument of '
$1
' is not an integer: '
$2
'"
if
[
-n
"
${
2
##*[!0-9]*
}
"
]
then
REFRESH
=
$2
else
die
"Argument of '
$1
' is not an integer: '
$2
'"
fi
shift
2
;;
-x
|
-xrange
)
[
"$#"
-ge
2
]
||
die
"'
$1
' option requires an argument"
XRANGE
=
"set xrange
$2
"
shift
2
shift
2
;;
;;
-y
|
-yrange
)
-y
|
-yrange
)
[
"$#"
-ge
2
]
||
usag
e
"'
$1
' option requires an argument"
[
"$#"
-ge
2
]
||
di
e
"'
$1
' option requires an argument"
YRANGE
=
"set yrange
$2
"
YRANGE
=
"set yrange
$2
"
shift
2
shift
2
;;
;;
...
@@ -120,7 +159,7 @@ do
...
@@ -120,7 +159,7 @@ do
shift
1
shift
1
;;
;;
-
*
)
-
*
)
usag
e
"unknown option: '
$*
'"
di
e
"unknown option: '
$*
'"
;;
;;
*
)
*
)
break
break
...
@@ -128,28 +167,28 @@ do
...
@@ -128,28 +167,28 @@ do
esac
esac
done
done
[
$#
-eq
1
]
||
usag
e
"Incorrect arguments specified"
[
"
$#
"
-eq
1
]
||
di
e
"Incorrect arguments specified"
[
-f
$1
]
||
usag
e
"File
$1
does not exit"
[
-f
"
$1
"
]
||
di
e
"File
$1
does not exit"
FILE
=
$1
FILE
=
"
$1
"
# Get KEYS from header
# Get KEYS from header
KEYS
=
$(
grep
-E
'^#'
$FILE
|
tail
-1
)
KEYS
=
$(
grep
-E
'^#'
"
$FILE
"
|
tail
-1
)
[
"
x
$KEYS
"
=
"
x
"
]
&&
KEYS
=
"# Step"
[
"
$KEYS
"
=
""
]
&&
KEYS
=
"# Step"
NKEYS
=
$(
howMany
"
$KEYS
"
)
NKEYS
=
$(
howMany
"
$KEYS
"
)
NCOLS
=
$(
tail
-1
$FILE
|
awk
'{ print NF}'
)
NCOLS
=
$(
grep
-m
1
'^[^#]'
"
$FILE
"
|
awk
'{ print NF
}'
)
# With full column labels, NKEYS = NCOLS + 1, since it includes "#"
# With full column labels, NKEYS = NCOLS + 1, since it includes "#"
# If NKEYS > NCOLS + 1, REMOVE EXCESS KEYS
# If NKEYS > NCOLS + 1, REMOVE EXCESS KEYS
NCOLSPONE
=
$(
expr
$
NCOLS
+
1
)
NCOLSPONE
=
$(
(
NCOLS
+
1
)
)
[
"
$NKEYS
"
-gt
"
$NCOLSPONE
"
]
&&
KEYS
=
$(
echo
$KEYS
|
cut
-d
" "
-f1-
$NCOLSPONE
)
[
"
$NKEYS
"
-gt
"
$NCOLSPONE
"
]
&&
KEYS
=
$(
echo
$KEYS
|
cut
-d
" "
-f1-
$NCOLSPONE
)
NKEYS
=
$(
howMany
"
$KEYS
"
)
NKEYS
=
$(
howMany
"
$KEYS
"
)
i
=
0
i
=
0
while
[
"
$NKEYS
"
-le
"
$NCOLS
"
]
while
[
"
$NKEYS
"
-le
"
$NCOLS
"
]
do
do
i
=
$(
expr
$i
+
1
)
i
=
$(
(
i+
1
)
)
KEYS
=
"
$KEYS
data
$i
"
KEYS
=
"
$KEYS
data
$i
"
NKEYS
=
$(
howMany
"
$KEYS
"
)
NKEYS
=
$(
howMany
"
$KEYS
"
)
done
done
...
@@ -159,33 +198,33 @@ XLABEL=$(echo $KEYS | cut -d " " -f2)
...
@@ -159,33 +198,33 @@ XLABEL=$(echo $KEYS | cut -d " " -f2)
KEYS
=
$(
echo
$KEYS
|
cut
-d
" "
-f3-
)
KEYS
=
$(
echo
$KEYS
|
cut
-d
" "
-f3-
)
GPFILE
=
$(
mktemp
)
GPFILE
=
$(
mktemp
)
plotFileHeader
>
$GPFILE
plotFileHeader
>
"
$GPFILE
"
i
=
1
i
=
1
for
field
in
$KEYS
for
field
in
$KEYS
do
do
i
=
$(
expr
$i
+
1
)
i
=
$(
(
i+
1
)
)
PLOTLINE
=
"
\"
$FILE
\"
using 1:
${
i
}
with lines title
\"
$field
\"
"
PLOTLINE
=
"
\"
$FILE
\"
using 1:
${
i
}
with lines title
\"
$field
\"
"
if
[
$i
-lt
$NCOLS
]
if
[
$i
-lt
$NCOLS
]
then
then
PLOTLINE
=
"
$PLOTLINE
,
\\
"
PLOTLINE
=
"
$PLOTLINE
,
\\
"
fi
fi
echo
$PLOTLINE
>>
$GPFILE
echo
$PLOTLINE
>>
"
$GPFILE
"
done
done
plotFileFooter
>>
$GPFILE
plotFileFooter
>>
"
$GPFILE
"
touch
$FILE
touch
"
$FILE
"
$GNUPLOT
$GPFILE
&
$GNUPLOT
"
$GPFILE
"
&
PID
=
$!
PID
=
$!
while
true
while
true
do
do
MODTIME
=
$(
stat
--format
=
%Y
$FILE
)
MODTIME
=
$(
stat
--format
=
%Y
$FILE
)
IDLEAGO
=
$(
expr
$(
date
+%s
)
-
$
IDLE
)
IDLEAGO
=
$(
(
$(
date
+%s
)
-
IDLE
)
)
test
"
$MODTIME
"
-gt
"
$IDLEAGO
"
||
break
test
"
$MODTIME
"
-gt
"
$IDLEAGO
"
||
break
sleep
$REFRESH
sleep
$REFRESH
done
done
kill
-9
$PID
kill
-9
$PID
rm
$GPFILE
rm
-f
"
$GPFILE
"
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment