2013-09-18 09:24:19 +00:00
#!/bin/bash
#------------------------------------------------------------------------------
# ========= |
2014-06-01 11:15:18 +00:00
# \\ / F ield | foam-extend: Open Source CFD
2018-05-29 07:35:20 +00:00
# \\ / O peration | Version: 4.1
2016-06-20 15:00:40 +00:00
# \\ / A nd | Web: http://www.foam-extend.org
# \\/ M anipulation | For copyright notice see file Copyright
2013-09-18 09:24:19 +00:00
#------------------------------------------------------------------------------
# License
2014-06-01 11:15:18 +00:00
# This file is part of foam-extend.
2013-09-18 09:24:19 +00:00
#
2014-06-01 11:15:18 +00:00
# foam-extend is free software: you can redistribute it and/or modify it
2013-09-18 09:24:19 +00:00
# under the terms of the GNU General Public License as published by the
2014-06-01 11:15:18 +00:00
# Free Software Foundation, either version 3 of the License, or (at your
2013-09-18 09:24:19 +00:00
# option) any later version.
#
2014-06-01 11:15:18 +00:00
# foam-extend is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
2013-09-18 09:24:19 +00:00
#
# You should have received a copy of the GNU General Public License
2014-06-01 11:15:18 +00:00
# along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
2013-09-18 09:24:19 +00:00
#
# Script
# foamProbe
#
# Description
2014-06-01 18:12:52 +00:00
# Proccess a scalar, vetorial or tensorial field of OpenFOAM
2013-09-18 09:24:19 +00:00
# probe file (for monitoring points). The original file will not be changed
# and the fields of each monitoring point will be stored in a new
# directory named probe<Name> (where <Name> is the field name) in the
# directory where are the original probes files.
# The fourth optional parameter can be used to create xmgrace sequentially
2014-06-01 18:12:52 +00:00
# graphs (case is 0)
2013-09-18 09:24:19 +00:00
# for monitoring points or automatically create eps figures (case is 1).
#
2014-06-01 18:12:52 +00:00
# Author:
# Jovani L. Favero, J. F. Mitre (2009)
2013-09-18 09:24:19 +00:00
#
#------------------------------------------------------------------------------
if [ $# -lt 3 ]; then
echo "Usage: foamProbe [<probes files directory> <numbers of monitoring points> <field name> <optional value: 0 - open in xmgrace, 1 - save to eps file>]"
exit 1
fi
# File name, NAME.
NAME=$(basename "$1")
DNAME="$1"
shift
# Number of points, P.
P="$1"
shift
NAME=$(basename "$1")
CNAME="$1"
shift
xmgrace=0
if [ $# -eq 1 ]; then
# Choose to save eps.
save="$1"
xmgrace=1
fi
if [ ! -d "$DNAME" ]; then
echo "Directory $DNAME does not exist."
exit 1
fi
if [ $P -lt 1 ]; then
echo "Can not be less than 1 single monitoring point."
exit 1
fi
cd $DNAME
if [ ! -f "$CNAME" ]; then
echo "Field $CNAME does not exist."
exit 1
fi
# Screen information
echo ""
echo "Wait: Processing $P point(s) in $CNAME file ...."
# Base directory to place processed files
DIR="./probe$NAME/"
if [ ! -d "$DIR" ]; then
mkdir "$DIR"
fi
sed -e "s/ *(/\t/g" -e 's/)//g' "$CNAME" >"$DIR/$NAME"
cd $DIR
column=1
while [ "$column" -le "$P" ]; do
point=$column
column=`expr $column + 1`
cut -f 1,$column "$NAME" |sed -e "s/\t/ /g" -e '/^#/d' >$NAME.base
echo -e "# Time \t Point_$point" >$NAME\_$point
cat $NAME.base >>$NAME\_$point
rm -f $NAME.base
done
cd - &>/dev/null
if [ "$xmgrace" = 1 ]; then
cd probe$CNAME/
field=1
underscore=_
while [ "$field" -le "$P" ]; do
point=$field
field=`expr $field + 1`
echo " Opening file $CNAME$underscore$point"
if [ "$save" = 0 ]; then
echo " Opened $CNAME$underscore$point"
2014-06-01 18:12:52 +00:00
xmgrace -nxy $CNAME\_$point -noask
2013-09-18 09:24:19 +00:00
fi
if [ "$save" -ne 0 ]; then
xmgrace -nxy $CNAME\_$point -hardcopy -printfile $CNAME\_$point.eps -hdevice EPS
echo " Saving file $CNAME$underscore$point.eps"
fi
echo " Closing file $CNAME$underscore$point"
echo ""
done
fi
echo ""
echo "Done!!!"
echo ""
exit 0