-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPLOT
executable file
·410 lines (317 loc) · 10.4 KB
/
PLOT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
#!/bin/bash
##################################################################
echo "--- PLOT v5.3 ---"
echo "Type \"PLOT -h\" for help. "
##################################################################
# S u b r o u t i n e s
##################################################################
adddefinedcolors()
{
local file=$1
local count=$2
local a=1
local b=""
# echo "set palette defined (0 \"dark-blue\", 1 \"blue\", 2 \"light-blue\", 3 \"light-green\", 4 \"green\", 5 \"dark-green\", 6 \"light-red\", 7 \"red\", 8 \"dark-red\" )" >> $file
cat <<EOF >>$file
set palette defined (\
0 "dark-blue", 1 "blue", 2 "light-blue", \
3 "light-green", 4 "green", 5 "dark-green", \
6 "light-red", 7 "red", 8 "dark-red" )
unset colorbox
EOF
for (( a=1; a <= count; a++ ))
{
b=$(echo "$a $count" | awk '{ printf("%f\n", $1/$2) }')
# echo "set style line $a linetype 1 linecolor palette fraction $b linewidth 1.000" >> $file
cat <<EOF >>$file
set style line $a lt 1 lc palette fraction $b lw 1
EOF
}
}
gnuplot_setup()
{
cat > $1 <<EOF
set grid lw 0.5
$plot
$grid
$xlabel
$ylabel
$logscale
set title "$datum"
$addoptions
EOF
}
check_perlstat()
{
if [[ ! -e $1 || ! -x $1 ]]; then
echo "Cannot find or execute $perlstat. Exiting."
exit 0;
fi
}
check_argument()
{
local option=$1
if [ -p "$OPTARG" ]; then
echo " -$1 requires a filename as argument"
exit 1;
fi
}
##################################################################
# Main program
##################################################################
datum=$(date +"%a %d.%m.%y %k:%M")
perlstat=$(which PERLSTAT)
# people may plot data in directories in which they are not
# allowed to write temporary files.
psfile="/home/$(whoami)/gnuplot.ps.$$"
inpfile="/home/$(whoami)/gnuplot.inp.$$"
regfile="/home/$(whoami)/gnuplot.reg.$$"
# default values
plot=""
xrange="[]"
yrange="[]"
using="1:2:"
logscale=""
smooth=""
type="w l" # short for: with lines
plotarg=""
printer="-Php2727nf"
addoptions=""
xlabel=""
ylabel=""
##################################################################
# Parser
##################################################################
while getopts "abcCd:ghl:m:M:no:p:P:t:T:x:y:X:Y:" option
do
case $option in
a) smooth="smooth acsplines";;
b) smooth="smooth bezier";;
c) smooth="smooth csplines";;
C) colorbox=1;;
d) using="$OPTARG:";;
g) grid="unset grid";;
h) perldoc PLOT
exit ;;
l) if [ $OPTARG = "x" ]; then
logscale="$logscale; set logscale x"
elif [ $OPTARG = "y" ]; then
logscale="$logscale; set logscale y"
elif [ $OPTARG = "xy" ]; then
logscale="set logscale x; set logscale y"
fi;;
m) statfile="a"
lopt="l"
l="$OPTARG"
check_perlstat $perlstat;;
M) statfile="a"
lopt="x"
l="$OPTARG"
check_perlstat $perlstat;;
n) normalize=1
echo " -> Normalizing with the first value of the 2nd column";;
o) addoptions="$OPTARG"
echo " -> Additional options: $addoptions";;
p) if [ -p "$OPTARG" ]; then
echo " -p requires a filename as argument"
exit 1;
else
psfile="$OPTARG"
fi
echo " -> Output $psfile"
plot="set term postscript color enhanced 10 solid; set output \"$psfile\"";;
P) printer="-P $OPTARG"
plot="set term postscript color enhanced 10 solid; set output \"$psfile\""
qprint="true";;
t) type="$OPTARG";;
T) plotarg="$OPTARG"
echo "$plotarg";;
x) xrange="[$OPTARG]";;
y) yrange="[$OPTARG]";;
X) xlabel="set xlabel \"$OPTARG\"";;
Y) ylabel="set ylabel \"$OPTARG\"";;
esac
done
shift $(($OPTIND - 1))
##################################################################
# Creating gnuplot script
##################################################################
if [ $# == 0 ]; then
if [ $plotarg ]; then
gnuplot_setup $inpfile
graph="plot $xrange $yrange $plotarg $type"
echo "$graph">>$inpfile
echo "pause -1">>$inpfile
echo "Evoking gnuplot ..."
gnuplot $inpfile
fi
exit
else
gnuplot_setup $inpfile
fi
##################################################################
# Perlstat
##################################################################
if [ $statfile ]; then
dateien="Plotting data files and respective regression equation: \n"
else
dateien="Plotting files:"
fi
if [ $colorbox ];
then
lsi=1
adddefinedcolors $inpfile ${#@}
fi
# also see http://www.gnuplot.info/docs_4.0/gnuplot.html
graph="plot $xrange $yrange"
# plotting (and computing regression) of all column-pairs specified in $using
ny=1
while [ ${#using} != 0 ]
do
ycolumn=${using%%:*}
using=${using#*:}
if [ $ny = 1 ]; then
xcolumn=$ycolumn
else
for Datei in "$@"
do
dateien="$dateien $Datei"
if [ $normalize ]; then
Datei="<awk '{if(FNR==1)norm=\$2}{print \$1,\$2/norm}' $Datei"
fi
if [ $statfile ]; then
echo "Executing $perlstat -f $Datei -r $xcolumn:$ycolumn -$lopt $l ..."
$perlstat -f $Datei -r $xcolumn:$ycolumn -$lopt $l > $regfile
m=` grep 'm =' $regfile | awk '/[0-9]/ {print $3}' `
b=` grep 'm =' $regfile | awk '/[0-9]/ {print $6}' `
rm $regfile
dateien="$dateien \t\t y = $m * x + $b \n"
echo "y = $m * x + $b"
# graph="$graph $m*x+$b linecolor rgb \"light-gray\", "
graph="$graph $m*x+$b linecolor rgb \"light-gray\""
graph="$graph title \"$m*x+$b for lines $l\", "
fi
if [ $colorbox ]; then
# graph="$graph \"$Datei\" u $xcolumn:$ycolumn $smooth $type ls $lsi, "
graph="$graph \"$Datei\" u $xcolumn:$ycolumn $smooth $type ls $lsi, "
let "lsi+=1"
else
graph="$graph \"$Datei\" u $xcolumn:$ycolumn $smooth $type, "
fi
done
fi
let "ny +=1"
done
if [ "$plotarg" ]; then graph="$graph $plotarg"; fi
echo "${graph%%, }">>$inpfile
#printf "%s " $graph >>$inpfile
if [ -z "$plot" ];then
echo "pause -1">>$inpfile
fi
echo "Plotting files: "
for file in $@
do
echo $file
done
echo
#echo -e "$dateien"
echo "Evoking gnuplot ..."
gnuplot $inpfile
if [ -n "$qprint" ]; then
# lpr $printer gnuplot.ps
echo; echo "I DID NOT PRINT!"
echo "-------------- the gnuplot script ----------------"
cat $inpfile
echo "-------------- ------------------ ----------------"
fi
#echo "Remove input file ..."
rm $inpfile
##################################################################
# Documentation
##################################################################
# Use a : NOOP and doc to embed documentation
# (vossen, newham: bash cookbook: p85)
: << 'END_OF_DOCS'
=head1 NAME
PLOT v5.0 --- plots faster (with gnuplot)
(c) 2008 Michael Haberler, Christian Schroeder
SEE ALSO: http://gnuplot.sourceforge.net/demo_4.0/
=head1 SYNOPSIS
PLOT [OPTIONS] <file(s)>
=head1 OPTIONS
-a = Smoothing of curve by fit to acsplines
in the gnuplot script:
gnuplot command: plot 'my.dat' smooth acsplines
-b = Smoothing of curve by fit to bezier curves
gnuplot command: plot 'my.dat' smooth bezier
-c = Smoothing of curve by fit to csplines
gnuplot command: plot 'my.dat' smooth csplines
-C = Color graph according to palette (see script) in the gnuplot script:
gnuplot command: set palette defined ( 0 "green", 1 "blue" )
gnuplot command: plot "graph.dat" linecolor palette fraction 0.1
-d [xvalues:yvalues[:yvalues2[:yvalues3]...]]
= Use columns "xvalues" and "yvalues" (and "yvalues1" and ...) of <file>
for plot.
gnuplot command: plot ... using [xvalues:yvalues[:yvalues2]...]
-g = gnuplot command: unset grid lw .5
-lx, -ly, -lxy
= Logarithmic x-, y-, or x- and y-scale
gnuplot command: set logscale x
gnuplot command: set logscale y
-M [xrange1:xrange2]
= Compute and plot linear regression from xrange1 to xrange2 using
"PERLSTAT".
-m [line1:line2]
= Compute and plot linear regression from line1 to line2 using "PERLSTAT".
It is also possible to only give the start line: "-m 1:".
-n = Normalize with the first value of the second column (ie. divide all values by the first one).
(TODO: Normalize with the first value of the actually plotted column!)
-o [options]
= Directly enter gnuplot commands. eg.: -o "set key bottom right"
Examples:
gnuplot command: set key bottom right
gnuplot command: set xtics ('-2pi' -6.283,'-3pi/2' -4.712,'-pi' -3.1415,'-pi/2' -1.5708,'0' 0,'pi/2' 1.5708,'pi' 3.1415,'3pi/2' 4.712,'2pi' 6.283)
gnuplot command: set xtics ('-pi' -3.1415,'-3pi/4' -2.3561,'-pi/2' -1.5708,'-pi/4' -0.7853,'0' 0,'pi/4' 0.7853,'pi/2' 1.5708,'3pi/4' 2.3561,'pi' 3.1415)
gnuplot command: set format y "%2.1t{/Symbol \327}10^{%L}"
gnuplot command: set lmargin 0; set rmargin 0; set tmargin 0; set bmargin 0;
gnuplot command: set xtics rotate by 90
-p [file]
= Save plot as [file] in PostScript format. If file="" the default file name
/home/user/gnuplot.ps is used.
gnuplot command: set term postscript color enhanced 10; set output '[file]'
-P [anything]
= Print gnuplot.gp file to stdout. (Used to print plot directy on printer
[anything].)
-t [type]
= prints lines with specified type. Default value is -t "with lines".
gnuplot command: plot [type]
Examples:
gnuplot command: plot title "f(x)"
gnuplot command: plot w points
gnuplot command: plot w linepoints
gnuplot command: plot w impulses
gnuplot command: plot w boxes fs solid 0.1 (in conjunction with -o 'set boxwidth 1.0 relative)
gnuplot command: plot w l lw 2
-T [function]
= gnuplot command: plot [function]
Example:
gnuplot command: plot 3.2*exp(-x/35.5)
-x [xrange1:xrange2]
= gnuplot command: set xrange [xrange1:xrange2]
-y [yrange1:yrange2]
= gnuplot command: set yrange [yrange1:yrange2]
-X [label]
= gnuplot command: set xlabel [label]
-Y [label]
= gnuplot command: set ylabel [label]
=head1 EXAMPLES
Witty, witty workaround to add things to: plot "<file>" with [type]:
---------------------------------------------------------------------
PLOT -p interaction_zn-s-o_1-3.dat.ps -X 'E(ZN2-CYD8)/kcal/mole' -Y 'r(ZN-S(green),ZN-O(red))/A' -t "with linespoints, \"interaction_zn-s-o_1-3.dat\" using 3:5 with linespoints" -d 4:5 interaction_zn-s-o_1-3.dat
PLOT -T 3*x+5 -x0:10 -g -t"w p lw 2.5" -o 'set sample 10; set key t l'
=head1 TODO
=over 2
=item * Explain connection between options and gnuplot commands, so that it is possible for gnuplot-savvys to get more out of PLOT!
=back
=cut
END_OF_DOCS