#! /bin/csh -f
#
# Shellscript to create Postscript plot of data in grd file
# Created by macro mbm_grdplot
#
# This shellscript created by following command line:
# mbm_grdplot -I$day$segment.grd -G1 -C -D -V -LFile $day$segment.grd - Bathymetry Grid:Depth (m)
#
# Define shell variables used in this script:
set day=206
set segment=b
set PS_FILE         = $day$segment.grd.ps
set CPT_FILE        = $day$segment.grd.cpt
set DATA_FILE        = $day$segment.grd
echo $DATA_FILE
set MAP_PROJECTION  = m
set MAP_SCALE       = 4.1148
set MAP_REGION      = -67.7557/-67.1087/-60.9929/-60.0952
set X_OFFSET        = 2.9188
set Y_OFFSET        = 2
set annot="a10mf2m/a5mf1m"
set day=$day
set times="0910-1410"
set cruise=NBP0104
set legend_xoffset=6
set legend_yoffset=0
set orientation=PORTRAIT
set uoffset=.25
set CellSize="250m X 250m"
set Matrix="143 X 401"
set psscale=-D2.500/-0.5000/3.0000/0.1500h
set small_font=8
set large_font=10
set tick_len=.075
set paper_width=8.5
set paper_max=11
set contour=100
set contour_annot=100
set annot_dist=2.5
set contour_label=$contour"m"
set min_max=2913.29/4296.66
#
# Make color pallette table file
echo Making color pallette table file...
echo   2850 255 255 255   3000 255 186 133 L > $CPT_FILE
echo   3000 255 186 133   3150 255 161  68 >> $CPT_FILE
echo   3150 255 161  68   3300 255 189  87 L >> $CPT_FILE
echo   3300 255 189  87   3450 240 236 121 >> $CPT_FILE
echo   3450 240 236 121   3600 205 255 162 L >> $CPT_FILE
echo   3600 205 255 162   3750 138 236 174 >> $CPT_FILE
echo   3750 138 236 174   3900 106 235 255 L >> $CPT_FILE
echo   3900 106 235 255   4050  50 190 255 >> $CPT_FILE
echo   4050  50 190 255   4200  40 127 251 L >> $CPT_FILE
echo   4200  40 127 251   4350  37  57 175 U >> $CPT_FILE

#


########## you shouldn't need to change below here **********
#
# Save existing GMT defaults
echo Saving GMT defaults...
gmtdefaults -L > gmtdefaults$$
#
# Set new GMT defaults
echo Setting new GMT defaults...
gmtset PAGE_ORIENTATION $orientation
gmtset MEASURE_UNIT inch
gmtset PAPER_WIDTH $paper_width
gmtset ANOT_FONT Helvetica
gmtset LABEL_FONT Helvetica
gmtset HEADER_FONT Helvetica
gmtset ANOT_FONT_SIZE $small_font
gmtset LABEL_FONT_SIZE $small_font
gmtset HEADER_FONT_SIZE $large_font
gmtset FRAME_WIDTH $tick_len
gmtset TICK_LENGTH $tick_len
gmtset COLOR_BACKGROUND 0/0/0
gmtset COLOR_FOREGROUND 255/255/255
gmtset COLOR_NAN 255/255/255


#
# Define data files to be plotted:
set INTENSITY_FILE   = 
#
# Make color image
echo Running grdimage...
echo $DATA_FILE
grdimage $DATA_FILE -J$MAP_PROJECTION$MAP_SCALE \
	-R$MAP_REGION -C$CPT_FILE \
	-X$X_OFFSET -Y$Y_OFFSET -K -V >! $PS_FILE
#
# Make contour plot
echo Running grdcontour...
grdcontour $DATA_FILE -J$MAP_PROJECTION$MAP_SCALE \
	-R$MAP_REGION \
	-C$contour -A$contour_annot"f4" -G$annot_dist \
	-L$min_max -Wa1c1\
	-K -O -V >> $PS_FILE
#
# Make color scale
echo Running psscale...
psscale -C$CPT_FILE \
	$psscale \
	-B":Depth (m):" \
	-K -O -V >> $PS_FILE
#
# Make basemap
echo Running psbasemap...
psbasemap -J$MAP_PROJECTION$MAP_SCALE \
	-R$MAP_REGION \
	-B"$annot":".$cruise SeaBeam Edited Data - Day $day": -K \
	-O -V >> $PS_FILE
#echo plotting coastline
#pscoast -J$MAP_PROJECTION$MAP_SCALE -R$MAP_REGION -Df -V -W2/0/0/0 -G200/200/200 -O -K >>$PS_FILE
echo plotting track
pstrack $day.nav -J$MAP_PROJECTION$MAP_SCALE -R$MAP_REGION -Ma1ht15m -O -K -W2/255/0/0 -V >>$PS_FILE
echo plotting text
pstext -Jx1 -R0/$paper_max/0/$paper_max -X-$X_OFFSET -Y-$Y_OFFSET -O -V -U/$uoffset/$uoffset/"K. Gavahan, RPSC" <<END >>$PS_FILE
$legend_xoffset $legend_yoffset.6 8 0 0 5 Gridded Data Day $day $times
$legend_xoffset $legend_yoffset.5 8 0 0 5 Contour Interval=$contour_label
$legend_xoffset $legend_yoffset.4 8 0 0 5 Grid Cell Size=$CellSize
$legend_xoffset $legend_yoffset.3 8 0 0 5 $Matrix Matrix
END

#
# Delete surplus files
echo Deleting surplus files...
/bin/rm -f $CPT_FILE
#
# Reset GMT default fonts
echo Resetting GMT fonts...
/bin/mv gmtdefaults$$ .gmtdefaults
#
# Run ghostview
echo Running ghostview in background...
ghostview  $day$segment.grd.ps &
#
# All done!
echo All done!
