Debian Codegraph @

test/greenspline/gspline_3.sh

raw
1 #!/usr/bin/env bash
2 #
3
4 ps=gspline_3.ps
5
6 # Figure 4 in Wessel, P. (2009), A general-purpose Green's function-based
7 # interpolator, Computers & Geosciences, 35, 1247-1254.
8
9 # Create synthetic data used in Lancaster & Salkauskas using C code on the fly
10
11 D=0.04
12 method=r
13 tension=0.998
14 cat << EOF > ks.c
15 #include <stdio.h>
16 #include <math.h>
17
18 int main () {
19 double x, y, z, d, r;
20
21 while (scanf ("%lf %lf", &x, &y) != EOF) {
22 d = y - x;
23 if (d >= 0.5)
24 z = 1.0;
25 else if (d >= 0.0 && d <= 0.5)
26 z = 2.0 * d;
27 else {
28 r = hypot (x - 1.5, y - 0.5);
29 z = (r <= 0.25) ? 0.5 * (cos (4.0 * M_PI * r) + 1.0) : -0.01;
30 }
31 printf ("%g\t%g\t%g\n", x, y, z);
32 }
33 }
34 EOF
35 # Make figure 4a showing the synthetic input data gmt surface and sample points
36 gcc ks.c -lm -o ks
37 gmt grdmath -R0/2/0/1 -I$D -r 0 = z.nc
38 gmt grdmath -R0/2/0/1 -I0.01 -r 0 = zfine.nc
39 gmt makecpt -Crainbow -T0/1/0.2 > tt.cpt
40 gmt grd2xyz z.nc | cut -f1,2 | ./ks | gmt xyz2grd -R0/2/0/1 -I$D -Gls.nc -r
41 gmt grd2xyz zfine.nc | cut -f1,2 | ./ks | gmt xyz2grd -R0/2/0/1 -I0.01 -Glsfine.nc -r
42 gmt grdview ls.nc -Jx2.5i -JZ1.75 -p155/30 -Ctt.cpt -Wc1p -Qm/lightgray -Bx0.5 -By0.2 -Bz0.2 -BwSEnZ -K --PS_SCALE_X=0.8 --PS_SCALE_Y=0.8 > $ps
43
44 gmt blockmean @gspl_random.txt -R -I$D > use.xyz
45 gmt grdcontour lsfine.nc -Jx2.8i -O -Bx0.5 -By0.2 -BWSne -C0.2 -A0.2 -K -Y4.25i -GlLT/1/0,1.5/0.5/1.5/1 >> $ps
46 gmt psxy use.xyz -R -J -O -K -Sc0.05i -Gblack >> $ps
47 echo "0 1 a)" | gmt pstext -R -J -O -K -N -F+jBR+f24p -Dj0.1i/0.3i >> $ps
48 # For Fig 4b, use the sampled points to grid with regularized spline in tension
49 gmt greenspline use.xyz -R0/2/0/1 -I$D -Gsplined.nc -S${method}${tension} -Z1
50 gmt greenspline use.xyz -R0/2/0/1 -I0.01 -Ggrad.nc -S${method}${tension} -Q135 -Z1
51 gmt grdview splined.nc -Jx2.5i -JZ1.75 -p155/30 -Ctt.cpt -Wc1p -Qm/lightgray -O -Bx0.5 -By0.2 -Bz0.2 -BwSEnZ -K -X6.5i -Y-4.25i >> $ps
52 gmt makecpt -Cpolar -T-5/5 -D > tt.cpt
53 gmt grdimage grad.nc -Ctt.cpt -Jx2.8i -M -Bx0.5 -By0.2 -BWSne -Y4.25i -O -K >> $ps
54 gmt grdcontour splined.nc -Jx2.8i -O -Bx0.5 -By0.2 -BWSne -C0.2 -A0.2 -K -GlLT/1/0,1.5/0.5/1.5/1 >> $ps
55 gmt psxy use.xyz -R -J -O -K -Sc0.05i -Gblack >> $ps
56 echo "0 1 b)" | gmt pstext -R -J -O -N -F+jBR+f24p -Dj0.1i/0.3i >> $ps