#!/bin/csh
#
#  This script contains HydroBase and GMT commands necessary to create a
#  plot of salinity at the sea surface in March for the Subduction Area of the
#  eastern No Atlantic.
#
#  First, extract the March data from the climatological dataset....
#
set list = ( 7202 7203 7302 7303)
#
extract $list -D/d1/hbase/data -E.qc -Tm3 > subduc.mar
#
#  Next, create a 3-D gridded matrix representing 1-deg averages of 
#  pr, te, th, sa, and sigma-0 for a set of depths spanning the upper 1000 m of
#  the water column....
#
set bounds = -40/-20/20/40
#
grid3d subduc.mar -B$bounds -I1 -Ppr/te/th/sa/s0 -Csubduc.mar.cdf -S0sig0.list -S1sig1.list -Zdepths.list 

#  Project properties onto specified surfaces...
#
gridsurf subduc.mar.cdf -C -B$bounds -I1 -Pth/sa/s0 -Ssurf.list
#
#  Create xyz-files for each property and interpolate holes in the sea surface
#  matrix ...
#
smoothsurf -Ide0.mar.grid -Ode0mar. -Pth/sa/s0 -M3 -R2
#
#  Create a blanking matrix for masking coastlines...
#
preblank -Ide0.mar.grid -Ode0.blank -Ps0 -R2
#
#
#  We have all the components to generate maps with GMT:
#
echo "surface fitting..."
foreach i (th sa s0)
   echo -n "$i  "
   blockmean de0mar.${i}.xyz -I2 -R$bounds -N > de0mar.${i}.block
   surface de0mar.${i}.block -Gde0mar.${i}.grd -R$bounds -I1 -T.5
   \rm de0mar.${i}.block
end
echo ""
#
echo "setting up blanking grid..."
awk '{print $1, $2, -99}' de0.blank > de0.blank.xyz
#
set plotfile = subduc.mar.ps
if (-f $plotfile) then
   \rm $plotfile
endif
touch $plotfile
#
echo "creating basemap..."
psbasemap -Jm.15 -R$bounds -X.3 -Y2 -K >> $plotfile
#
echo "masking blanks..."
psmask de0.blank.xyz -I1 -Jm -R$bounds -N -O -K >> $plotfile
#
echo "contouring..."
grdcontour de0mar.th.grd -C1 -Wc4/0/0/0 -Wa8/0/0/0 -Jm -R -K -O >> $plotfile
#
# turn off the masking ...
psmask -I1 -R$bounds -Jm -S -O -K >> $plotfile
#
echo "drawing coastline..."
pscoast -R -Jm -Ba10f1:."Temperature":wESn -O -K -G0 >> $plotfile
#
#  now add salinity and sigma-theta maps next to temperature:
#
echo "plotting sa ..."
psbasemap -Jm.15 -R$bounds -X3.5 -K -O >> $plotfile
psmask de0.blank.xyz -I1 -Jm -R$bounds -N -O -K >> $plotfile
grdcontour de0mar.sa.grd -C.1 -Wc4/0/0/0 -Wa8/0/0/0 -Jm -R -K -O >> $plotfile
psmask -I1 -R$bounds -Jm -S -O -K >> $plotfile
pscoast -R -Jm -Ba10f1wESn:."Salinity":wESn -O -K -G0 -U"HydroBase March Climatology" >> $plotfile
#
echo "plotting sigma ..."
psbasemap -Jm.15 -R$bounds -X3.5 -K -O >> $plotfile
psmask de0.blank.xyz -I1 -Jm -R$bounds -N -O -K >> $plotfile
grdcontour de0mar.s0.grd -C.1 -Wc4/0/0/0 -Wa8/0/0/0 -Jm -R -K -O >> $plotfile
psmask -I1 -R$bounds -Jm -S -O -K >> $plotfile
pscoast -R -Jm -Ba10f1:."Sigma-0":wESn -O -G0   >> $plotfile
#
exit



