#! /bin/csh -f
#
# Shellscript to create TIFF image of data in grd file
# Created by macro mbm_grdtiff
#
# This shellscript created by following command line:
# mbm_grdtiff -I UppermostCanyonTopoMB.grd -OUppermostCanyonSlope -G5 -S -V -D0/1
#
# Define shell variables used in this script:
set TIFF_FILE       = UppermostCanyonSlope.tif
set CPT_FILE        = UppermostCanyonSlope.cpt
set MAP_REGION      = -121.88/-121.79/36.743/36.85
#
# Save existing GMT defaults
echo Saving GMT defaults...
gmtdefaults -L > gmtdefaults$$
#
# Set new GMT defaults
echo Setting new GMT defaults...
gmtset COLOR_BACKGROUND 0/0/0
gmtset COLOR_FOREGROUND 255/255/255
gmtset COLOR_NAN 255/255/255
gmtset DEGREE_FORMAT 3
#
# Make color pallette table file
echo Making color pallette table file...
echo -421.777  37  57 175 -231.251  40 127 251 > $CPT_FILE
echo -231.251  40 127 251 -158.945  50 190 255 >> $CPT_FILE
echo -158.945  50 190 255 -114.609 106 235 255 >> $CPT_FILE
echo -114.609 106 235 255 -85.4484 138 236 174 >> $CPT_FILE
echo -85.4484 138 236 174 -75.0306 205 255 162 >> $CPT_FILE
echo -75.0306 205 255 162 -64.6463 240 236 121 >> $CPT_FILE
echo -64.6463 240 236 121 -54.2414 255 189  87 >> $CPT_FILE
echo -54.2414 255 189  87 -42.4456 255 161  68 >> $CPT_FILE
echo -42.4456 255 161  68 -31.6344 255 186 133 >> $CPT_FILE
echo -31.6344 255 186 133 -11.1967 255 255 255 >> $CPT_FILE
#
# Define data files to be plotted:
set DATA_FILE        = UppermostCanyonTopoMB.grd
set INTENSITY_FILE   = 
#
# Get slope array
echo Getting slope array...
echo Running grdgradient to get x component of the gradient...
grdgradient $DATA_FILE -A90 -G$DATA_FILE.drvx -M
echo Running grdgradient to get y component of the gradient...
grdgradient $DATA_FILE -A0 -G$DATA_FILE.drvy -M
echo Running grdmath to get slope magnitude...
grdmath $DATA_FILE.drvx 2.0 POW \
	$DATA_FILE.drvy 2.0 POW ADD SQRT \
	-1 MUL \
	= $DATA_FILE.slope
/bin/rm -f $DATA_FILE.drvx $DATA_FILE.drvy 
#
# Make tiff image
echo Running mbgrdtiff...
mbgrdtiff -I $DATA_FILE \
	-O $TIFF_FILE \
	-R$MAP_REGION \
	-C $CPT_FILE \
	-K $DATA_FILE.slope \
	-V 
#
# 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 xv
echo Running xv in background...
xv UppermostCanyonSlope.tif &
#
# All done!
echo All done!
