#! /bin/bash
# FIXME: assumes that the "cm tiles" have already been made. See call to makeAllCmTiles below
if [ "$#" != "7" ]; then
	echo "usage: `basename $0` xyziFileNameStem W E S N incInSec oDir"
	echo "  example: `basename $0` w135n45 -135 -120 45 3 /Volumes/publicSonarData/test.3c"
    exit
fi

gmtset VERBOSE = FALSE

stem=$1;   			shift
((w=$1));			shift
((e=$1));			shift
((s=$1));			shift
((n=$1));			shift
((incInSec=$1));	shift
oDir=$1;		shift


#
# makeAllCmTiles.csh ../../seasat2/data/public ../../seasat2/data/private ../arctic/ver1_netcdf_geo.grd 79 80 00099 ..
#


# need lots of sig figs to keep surface from moaning

gmtset D_FORMAT = %.16lg

# hardcode arctic bathymetry sid and bounds

minArctic=69
maxPred=70
arcticSid=00099
MOA_public=/Volumes/publicSonarData/seasat2/data/public
MOA_private=/Volumes/publicSonarData/seasat2/data/private
arcticGrd='../arctic/IBCAO_ver2_23_GEO_netCDF_1min_trimmed.grd'

# FIXME: next few lines are debug / reminder...
# set incInSec=15
# set stem=w165n30
# set w=-158
# set e=-155
# set s=17
# set n=22
# set oDir='/Volumes/publicSonarData/test.15c'

img='../img/topo.img'
imgIncInSec=60


mkdir -p $oDir/tmp


#--------------------- UNCOMMENT this line if the cmTile dir has not been created...
#
# makeAllCmTiles.csh $MOA_public $MOA_private $arcticGrd $minArctic $maxPred $arcticSid $oDir
#
#---------------------

mkdir -p $oDir/predTile
makePredictedTile.csh $img $imgIncInSec $arcticGrd $oDir/predTile/$stem.grd $w $e $s $n $incInSec $minArctic $maxPred $arcticSid $oDir

mkdir -p $oDir/grd
makeBathymetryTile.csh $oDir/cmTile/$stem.xyzi `expr $w - 1` `expr $e + 1` `expr $s - 1` `expr $n + 1` $incInSec $oDir
# makeBathymetryTile.csh $oDir/cmTile/$stem.xyzi $w $e $s $n $incInSec $oDir

mkdir -p $oDir/srtm/grd
mergeBathymetryWithSrtmTile.csh $stem $incInSec $oDir

#--------------------- Make a plot just to double check it worked...
scaleFactor=0.25
scaleFactor=1.0

mkdir -p $oDir/plots
plotTile.csh $stem $w $e $s $n $scaleFactor $incInSec $oDir -P
