Forward compatibility: flex
[foam-extend-3.2.git] / bin / foamProbe
blob50fd60b73014f3017cce3211ff3c6b0f7e3ee68d
1 #!/bin/bash
2 #------------------------------------------------------------------------------
3 # ========= |
4 # \\ / F ield | foam-extend: Open Source CFD
5 # \\ / O peration |
6 # \\ / A nd | For copyright notice see file Copyright
7 # \\/ M anipulation |
8 #------------------------------------------------------------------------------
9 # License
10 # This file is part of foam-extend.
12 # foam-extend is free software: you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by the
14 # Free Software Foundation, either version 3 of the License, or (at your
15 # option) any later version.
17 # foam-extend is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 # General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 # Script
26 # foamProbe
28 # Description
29 # Proccess a scalar, vetorial or tensorial field of OpenFOAM
30 # probe file (for monitoring points). The original file will not be changed
31 # and the fields of each monitoring point will be stored in a new
32 # directory named probe<Name> (where <Name> is the field name) in the
33 # directory where are the original probes files.
34 # The fourth optional parameter can be used to create xmgrace sequentially
35 # graphs (case is 0)
36 # for monitoring points or automatically create eps figures (case is 1).
39 # Author:
40 # Jovani L. Favero, J. F. Mitre (2009)
42 #------------------------------------------------------------------------------
44 if [ $# -lt 3 ]; then
45 echo "Usage: foamProbe [<probes files directory> <numbers of monitoring points> <field name> <optional value: 0 - open in xmgrace, 1 - save to eps file>]"
46 exit 1
49 # File name, NAME.
50 NAME=$(basename "$1")
51 DNAME="$1"
52 shift
54 # Number of points, P.
55 P="$1"
56 shift
58 NAME=$(basename "$1")
59 CNAME="$1"
60 shift
61 xmgrace=0
63 if [ $# -eq 1 ]; then
64 # Choose to save eps.
65 save="$1"
66 xmgrace=1
69 if [ ! -d "$DNAME" ]; then
70 echo "Directory $DNAME does not exist."
71 exit 1
74 if [ $P -lt 1 ]; then
75 echo "Can not be less than 1 single monitoring point."
76 exit 1
79 cd $DNAME
81 if [ ! -f "$CNAME" ]; then
82 echo "Field $CNAME does not exist."
83 exit 1
86 # Screen information
87 echo ""
88 echo "Wait: Processing $P point(s) in $CNAME file ...."
90 # Base directory to place processed files
91 DIR="./probe$NAME/"
92 if [ ! -d "$DIR" ]; then
93 mkdir "$DIR"
95 sed -e "s/ *(/\t/g" -e 's/)//g' "$CNAME" >"$DIR/$NAME"
96 cd $DIR
97 column=1
98 while [ "$column" -le "$P" ]; do
99 point=$column
100 column=`expr $column + 1`
101 cut -f 1,$column "$NAME" |sed -e "s/\t/ /g" -e '/^#/d' >$NAME.base
102 echo -e "# Time \t Point_$point" >$NAME\_$point
103 cat $NAME.base >>$NAME\_$point
104 rm -f $NAME.base
105 done
106 cd - &>/dev/null
108 if [ "$xmgrace" = 1 ]; then
109 cd probe$CNAME/
110 field=1
111 underscore=_
112 while [ "$field" -le "$P" ]; do
113 point=$field
114 field=`expr $field + 1`
115 echo " Opening file $CNAME$underscore$point"
116 if [ "$save" = 0 ]; then
117 echo " Opened $CNAME$underscore$point"
118 xmgrace -nxy $CNAME\_$point -noask
121 if [ "$save" -ne 0 ]; then
122 xmgrace -nxy $CNAME\_$point -hardcopy -printfile $CNAME\_$point.eps -hdevice EPS
123 echo " Saving file $CNAME$underscore$point.eps"
125 echo " Closing file $CNAME$underscore$point"
126 echo ""
127 done
130 echo ""
131 echo "Done!!!"
132 echo ""
134 exit 0