#!/bin/bash
file=${1-tmp}
#
# convert data in $file.dat to gridded representation using GMT surface
#
reg=-R-45/45/-45/45		# region
proj=-JH0/7			# projection for plotting
inc=-I1/1			# resolution of grid file

# limit output
#options="-Lld -Lud"

# grid using two choices of surface
surface $file.data $reg $inc -G$file.spline.grd -T1 $options # harmonic spline
surface $file.data $reg $inc -G$file.bc.grd -T0 $options	   # smoothest, bicubic
# make colormap
grd2cpt -E21 -T= $file.spline.grd -Chaxby > $file.cpt

# mask all regions outside data 
grdmask $reg $inc -S500K $file.data -NNaN/1/1 -Gmask.grd
grdmath mask.grd $file.bc.grd MUL = $file.bc.masked.grd

for s in spline bc bc.masked;do
    grdimage -Y0 -K $file.$s.grd -C$file.cpt $reg $proj -Ba45f5WeSn:."$s": > $file.$s.ps
    psxy $file.data -Sc0.02 -G0 -O $reg $proj  >> $file.$s.ps
done
