#!/usr/bin/env bash # Based on GMT EXAMPLE 23 # edited by leiyang@fio.org.cn # Purpose: Plot distances from Beijing and draw shortest paths # GMT modules: grdmath, grdcontour, coast, plot, text, grdtrack # Unix progs: echo, cat, awk # gmt begin ex23 pdf,png # Position and name of central point: lon=116.40 lat=39.90 name="Beijing"
# Calculate distances (km) to all points on a global 1x1 grid gmt grdmath -Rg -I1 $lon$lat SDIST = dist.nc
# Location info for 5 other cities + label justification cat <<- END > cities.txt 105.87 21.02 LM HANOI 282.95 -12.1 LM LIMA 178.42 -18.13 LM SUVA 237.67 47.58 RM SEATTLE -74.00 40.70 LM NEWYORK 28.20 -25.75 LM PRETORIA END gmt coast -R0/360/-80/80 -JT330/-45/9i -Glightgreen -Slightblue -A1000 -Bg30 -B+t"Distances from $name to the World" -Wthinnest # gmt coast -Rg -JH140/9i -Glightgreen -Slightblue -A1000 -Bg30 -B+t"Distances from $name to the World" -Wthinnest
# For each of the cities, plot great circle arc to Beijing with gmt plot gmt plot -Wthickest,red -Fr$lon/$lat cities.txt cat cities.txt | grep 'NEW' | gmt plot -Wthickest,lightred,- -Fr$lon/$lat -A # Plot red squares at cities and plot names: gmt plot -Ss0.2 -Glightred -Wthinnest cities.txt
gmt text -Dj0.15/0 -F+f12p,Courier-Bold,red+j -N cities.txt grdinfo dist.nc -M --FORMAT_FLOAT_OUT=0:%g,1:%g,2:%.0f| grep 'z_m'| awk -F: '{print $4}' | awk '{print $5,$8,$1}'| gmt text -D0/-0.2i -N -Gwhite -W -C0.02i -F+f12p,Helvetica-Bold+jCT # Place a yellow star at Beijing grdinfo dist.nc -M | grep 'z_m'| awk -F= '{print $(NF-1),$NF}'|awk '{print $1,$3}'|gmt plot -Sc0.1 -Gred -Wthinnest echo"$lon$lat" | gmt plot -Sa0.2i -Gyellow -Wthin
# Sample the distance grid at the cities and use the distance in integer km for labels gmt grdtrack -Gdist.nc cities.txt -o0-2 --FORMAT_FLOAT_OUT=0:%g,1:%g,2:%.0f \ | gmt text -D0/-0.2i -N -Gwhite -W -C0.02i -F+f12p,Helvetica-Bold+jCT
# Clean up after ourselves: rm -f cities.txt gmt end show