Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

gspline_3.sh 2.2 KB

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

Press p or to see the previous file or, n or to see the next file

Comments

Loading...