#!/bin/csh
#
#  This script uses HydroBase and GMT commands to create plots of temperature
#  and depth of three density surfaces as a function of time.
#
#  First extract the an area from the subpolar gyre...
#
ms5sort /d1/hbase/data/7505.qc -N.dat -T 
#
#  Compute properties on a set of surfaces at each station with time information
#
timeprop 7505_2.dat -Ppr/th/sa <<ENDLIST
s0 27.70 sig2770.time
s_ 1500 34.64 sig3464.time
s2 37.00 sig3700.time
end
ENDLIST
#
#  Use the UNIX sort command to sort the data by year for easy viewing...
foreach i (2770 3464 3700)
   sort -k1,2 sig${i}.time > sig${i}.sort
end
#
#  Use the UNIX command awk to extract year/property pairs for making x-y plots
#
foreach i (2770 3464 3700)
echo "awking sig$i ..."
awk '{print $1, $5}' sig$i.sort > sig${i}.pr.xy
awk '{print $1, $6}' sig$i.sort > sig${i}.th.xy
awk '{print $1, $7}' sig$i.sort > sig${i}.sa.xy
end
#
#  GMT part
#

set red = (255/0/0)
set green = (0/255/0)
set blue = (0/0/255)

set surf1 = 2770
set surf2 = 3464
set surf3 = 3700

set ylen = -4
set xlen = 6
set range = 1920/1990/0/3000
set plotfile = script3.ps

if (-f $plotfile) then
\rm $plotfile
endif

psxy sig${surf1}.pr.xy -JX${xlen}/${ylen} -R$range -Ba10f1g10/a500f100g500:" Pressure":WeSn:."Density Surfaces in Subpolar Gyre": -Sx.05 -W2/$red -L -X1 -Y6 -P -K > $plotfile 

psxy sig${surf2}.pr.xy -JX -R -St.04 -W2/$green -L -O -K >> $plotfile

psxy sig${surf3}.pr.xy -JX -R -Ss.04 -W2/$blue -L -O -K >> $plotfile

set range = 1920/1990/2/5
set ylen = 4
psxy sig${surf1}.th.xy -JX${xlen}/${ylen} -R$range -Ba10f1g10/a1f.1g1:" Theta":WeSn -Sx.05 -W2/$red -L -Y-5 -P -O -K >> $plotfile 

psxy sig${surf2}.th.xy -JX -R -St.04 -W2/$green -L -O -K >> $plotfile
psxy sig${surf3}.th.xy -JX -R -Ss.04 -W2/$blue -L -O >> $plotfile

gs $plotfile
exit


