1#!/usr/bin/env bash
2#
3# Show all splines and their derivatives for a basic data set
4ps=splines.ps
5cat << EOF > t.txt
60	0
71	1
82	1.5
93	1.25
104	1.5
114.5	3
125	2
136	2.5
14EOF
15# Splines
16gmt sample1d t.txt -T0/6/0.01 -Fc | gmt psxy -R-0.1/6.1/-0.1/3.1 -JX6i/3i -P -Bafg -By+l"u(x)" -BWSne -W1p -K -X1.5i > $ps
17gmt sample1d t.txt -T0/6/0.01 -Fl | gmt psxy -R -J -O -K -W1p,blue >> $ps
18gmt sample1d t.txt -T0/6/0.01 -Fa | gmt psxy -R -J -O -K -W1p,red >> $ps
19gmt sample1d t.txt -T0/6/0.01 -Fn | gmt psxy -R -J -O -K -W1p,darkgreen >> $ps
20gmt psxy -R -J -O -K t.txt -Sc0.1i -Gred -Wthin >> $ps
21gmt pslegend -R -J -O -K -DjTL+w1.9i+o0.1i -F+p1p+gwhite+s << EOF >> $ps
22S 0.2i - 0.3i - 1p 	0.5i Cubic spline
23S 0.2i - 0.3i - 1p,red	0.5i Akima spline
24S 0.2i - 0.3i - 1p,blue	0.5i Linear spline
25S 0.2i - 0.3i - 1p,darkgreen 0.5i Nearest neighbor
26EOF
27# Spline slopes
28gmt sample1d t.txt -T0/6/0.01 -Fc+1 | gmt psxy -R-0.1/6.1/-3.1/4.5 -J -Bafg -BWsne -By+l"u'(x)" -W1p -O -K -Y3.15i >> $ps
29gmt sample1d t.txt -T0/6/0.01 -Fl+1 | gmt psxy -R -J -W1p,blue -O -K >> $ps
30gmt sample1d t.txt -T0/6/0.01 -Fa+1 | gmt psxy -R -J -W1p,red -O -K >> $ps
31gmt sample1d t.txt -T0/6/0.01 -Fn+1 | gmt psxy -R -J -W1p,darkgreen -O -K >> $ps
32gmt pslegend -R -J -O -K -DjTL+w1.9i+o0.1i -F+p1p+gwhite+s << EOF >> $ps
33S 0.2i - 0.3i - 1p 	0.5i Cubic spline
34S 0.2i - 0.3i - 1p,red	0.5i Akima spline
35S 0.2i - 0.3i - 1p,blue	0.5i Linear spline
36S 0.2i - 0.3i - 1p,darkgreen 0.5i Nearest neighbor
37EOF
38# Spline curvatures
39gmt sample1d t.txt -T0/6/0.01 -Fc+2 | gmt psxy -R-0.1/6.1/-31/31 -J -Bafg  -By+l"u''(x)" -BWsne -W1p -O -K -Y3.15i >> $ps
40gmt sample1d t.txt -T0/6/0.01 -Fl+2 | gmt psxy -R -J -W1p,blue -O -K >> $ps
41gmt sample1d t.txt -T0/6/0.01 -Fa+2 | gmt psxy -R -J -W1p,red -O -K >> $ps
42gmt pslegend -R -J -O -DjTL+w1.9i+o0.1i -F+p1p+gwhite+s << EOF >> $ps
43S 0.2i - 0.3i - 1p 	0.5i Cubic spline
44S 0.2i - 0.3i - 1p,red	0.5i Akima spline
45S 0.2i - 0.3i - 1p,blue	0.5i Linear spline
46S 0.2i - 0.3i - 1p,darkgreen 0.5i Nearest neighbor
47EOF
48