#!/bin/sh
# autopkgtest check
# (C) 2014 Anton Gladky

set -e

WORKDIR=$(mktemp -d)
trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM
cd $WORKDIR

cat <<EOF > 1.dat
#
-20.000000 -3.041676
-19.000000 -3.036427
-18.000000 -3.030596
-17.000000 -3.024081
-16.000000 -3.016755
-15.000000 -3.008456
-14.000000 -2.998978
-13.000000 -2.988049
-12.000000 -2.975310
-11.000000 -2.960273
-10.000000 -2.942255
-9.000000 -2.920278
-8.000000 -2.892883
-7.000000 -2.857799
-6.000000 -2.811295
-5.000000 -2.746802
-4.000000 -2.651635
-3.000000 -2.498092
-2.000000 -2.214297
-1.000000 -1.570796
0.000000 0.000000
1.000000 1.570796
2.000000 2.214297
3.000000 2.498092
4.000000 2.651635
5.000000 2.746802
6.000000 2.811295
7.000000 2.857799
8.000000 2.892883
9.000000 2.920278
10.000000 2.942255
11.000000 2.960273
12.000000 2.975310
13.000000 2.988049
14.000000 2.998978
15.000000 3.008456
16.000000 3.016755
17.000000 3.024081
18.000000 3.030596
19.000000 3.036427
EOF

cat <<EOF > 2.dat
#
#
#
-20.000000 -6.083352
-19.000000 -6.072853
-18.000000 -6.061191
-17.000000 -6.048162
-16.000000 -6.033510
-15.000000 -6.016913
-14.000000 -5.997955
-13.000000 -5.976098
-12.000000 -5.950620
-11.000000 -5.920546
-10.000000 -5.884511
-9.000000 -5.840556
-8.000000 -5.785765
-7.000000 -5.715597
-6.000000 -5.622591
-5.000000 -5.493603
-4.000000 -5.303271
-3.000000 -4.996183
-2.000000 -4.428595
-1.000000 -3.141593
0.000000 0.000000
1.000000 3.141593
2.000000 4.428595
3.000000 4.996183
4.000000 5.303271
5.000000 5.493603
6.000000 5.622591
7.000000 5.715597
8.000000 5.785765
9.000000 5.840556
10.000000 5.884511
11.000000 5.920546
12.000000 5.950620
13.000000 5.976098
14.000000 5.997955
15.000000 6.016913
16.000000 6.033510
17.000000 6.048162
18.000000 6.061191
19.000000 6.072853
EOF

cat <<EOF > 3.dat
#
#
#
-20.000000 -9.125028
-19.000000 -9.109280
-18.000000 -9.091787
-17.000000 -9.072243
-16.000000 -9.050265
-15.000000 -9.025369
-14.000000 -8.996933
-13.000000 -8.964147
-12.000000 -8.925931
-11.000000 -8.880819
-10.000000 -8.826766
-9.000000 -8.760835
-8.000000 -8.678648
-7.000000 -8.573396
-6.000000 -8.433886
-5.000000 -8.240405
-4.000000 -7.954906
-3.000000 -7.494275
-2.000000 -6.642892
-1.000000 -4.712389
0.000000 0.000000
1.000000 4.712389
2.000000 6.642892
3.000000 7.494275
4.000000 7.954906
5.000000 8.240405
6.000000 8.433886
7.000000 8.573396
8.000000 8.678648
9.000000 8.760835
10.000000 8.826766
11.000000 8.880819
12.000000 8.925931
13.000000 8.964147
14.000000 8.996933
15.000000 9.025369
16.000000 9.050265
17.000000 9.072243
18.000000 9.091787
19.000000 9.109280
EOF

cat <<EOF > arrowstyle.dat
-1000	37	-41
-959	11	-49
-918	-16	-48
-877	-42	-39
-836	-60	-24
-795	-69	-5
-755	-66	14
-714	-52	32
-673	-30	44
-632	-2	49
-591	24	46
-551	48	35
-510	64	18
-469	69	0
-428	63	-20
-387	46	-37
-346	22	-47
-306	-5	-49
-265	-32	-44
-224	-54	-31
-183	-67	-13
-142	-68	7
-102	-59	26
-61	-39	40
-20	-14	48
20	14	48
61	39	40
102	59	26
142	68	7
183	67	-13
224	54	-31
265	32	-44
306	5	-49
346	-22	-47
387	-46	-37
428	-63	-20
469	-69	-0
510	-64	18
551	-48	35
591	-24	46
632	2	49
673	30	44
714	52	32
755	66	14
795	69	-5
836	60	-24
877	42	-39
918	16	-48
959	-11	-49
1000	-37	-41
EOF

cat <<EOF > arrowstyle.dem
#
#
#
set terminal postscript eps color 
set xrange [-1000:1000]
set yrange [-178:86]
set tics scale 0

set style line 1 lt 1 lw 2
set style line 2 lt 3 lw 2

set style arrow 1 head filled size screen 0.025,30,45 ls 1
set style arrow 2 head nofilled size screen 0.03,15 ls 2
set style arrow 3 head filled size screen 0.03,15,45 ls 1
set style arrow 4 head filled size screen 0.03,15 ls 2
set style arrow 5 heads filled size screen 0.03,15,135 ls 1
set style arrow 6 head empty size screen 0.03,15,135 ls 2
set style arrow 7 nohead ls 1
set style arrow 8 heads size screen 0.008,90 ls 2

print ' We have defined the following arrowstyles:'
show style arrow

set arrow from -500,-100 to 500,-100 as 1
set arrow from -500,-110 to 500,-110 as 2
set arrow from -500,-120 to 500,-120 as 3
set arrow from -500,-130 to 500,-130 as 4
set arrow from -500,-140 to 500,-140 as 5
set arrow from -500,-150 to 500,-150 as 6
set arrow from -500,-160 to 500,-160 as 7
set arrow from -500,-170 to 500,-170 as 8

set label 'arrowstyle 1:' at -520,-100 right
set label 'arrowstyle 2:' at -520,-110 right
set label 'arrowstyle 3:' at -520,-120 right
set label 'arrowstyle 4:' at -520,-130 right
set label 'arrowstyle 5:' at -520,-140 right
set label 'arrowstyle 6:' at -520,-150 right
set label 'arrowstyle 7:' at -520,-160 right
set label 'arrowstyle 8:' at -520,-170 right

set title 'Top: plot with vectors arrowstyle 1, Bottom: explicit arrows'
plot \
     'arrowstyle.dat' using 1:2:(0):3 notitle with vectors arrowstyle 1

set title 'Top: plot with vectors arrowstyle 2, Bottom: explicit arrows'
plot \
     'arrowstyle.dat' using 1:2:(0):3 notitle with vectors arrowstyle 2

set title 'Top: plot with vectors arrowstyle 3, Bottom: explicit arrows'
plot \
     'arrowstyle.dat' using 1:2:(0):3 notitle with vectors arrowstyle 3

set title 'Top: plot with vectors arrowstyle 4, Bottom: explicit arrows'
plot \
     'arrowstyle.dat' using 1:2:(0):3 notitle with vectors arrowstyle 4

set title 'Top: plot with vectors arrowstyle 5, Bottom: explicit arrows'
plot \
     'arrowstyle.dat' using 1:2:(0):3 notitle with vectors arrowstyle 5

set title 'Top: plot with vectors arrowstyle 6, Bottom: explicit arrows'
plot \
     'arrowstyle.dat' using 1:2:(0):3 notitle with vectors arrowstyle 6

set title 'Top: plot with vectors arrowstyle 7, Bottom: explicit arrows'
plot \
     'arrowstyle.dat' using 1:2:(0):3 notitle with vectors arrowstyle 7

set title 'Top: plot with vectors arrowstyle 8, Bottom: explicit arrows'
plot \
     'arrowstyle.dat' using 1:2:(0):3 notitle with vectors arrowstyle 8

#reset

#
# Show plot with data style vectors
#
set title "Plot 'file' with vectors <arrowstyle>"
set key box opaque
set xrange [*:*]
set yrange [*:10]
set for [i=1:8] style arrow i lc i
plot '1.dat' using 1:2:(+1):(+1) with vectors lt 4 filled title 'filled', \
     '2.dat' using 1:2:(+1):(+1) with vectors lt 1 heads title 'double-headed', \
     '2.dat' using (\$1):(2-\$2/3):(+1):(+2.5):(int(\$0)%8 + 1) with vectors as var ti 'arrowstyle variable'
#
#
reset
EOF

gnuplot < arrowstyle.dem

echo "run: OK"
