#!/bin/sh
#
# Simple sh(1) script to start GrADS and make_ctl_gs, exiting from GrADS
# upon completion.
#
# Revision history:
#
# 08jan09   da Silva  First crack. 
#                       lats4d --> lats4d.sh
#
#-------------------------------------------------------------------------

# Use full patch names if you wish

gradsbin="gradsdap" # must use grads v2
make_ctlgs="make_ctl.gs"

if [ $#0 -lt 1 ]; then
	echo "          "
	echo "NAME"
	echo "     make_ctl - creates GrADS control files"
	echo "          "
        echo "SYNOPSIS"
        echo "     make_ctl [-upper] in_url [out_filename]"
	echo "          "
	echo "DESCRIPTION"
	echo "     make_ctl is a command line interface to GrADS"
        echo "     and the make_ctl.gs script. It starts either"
        echo "     gradshdf or gradsnc depending on the -hdf/-nc"
        echo "     option specified, runs make_ctl.gs, and exits"
	echo "     from GrADS upon completion.     "
	echo "          "
	echo "     For additional information on MAKE_CTL enter: make_ctl -h"
	echo "          "
	echo "OPTIONS"
	echo " -nc        for producing GRIB or NetCDF  files"
	echo " -hdf       for producing GRIB or HDF-SDS files (default)"
	echo " -dods      for reading OPeNDAP URLs with gradsdods (v1.9)"
	echo " -dap       for reading OPeNDAP URLs with gradsdap (v2.0)"
	echo " option(s)  for a list of make_ctl options enter: make_ctl -h"
	echo "          "
	echo "IMPORTANT"
	echo "     You must specify the input file name with "
        echo "     the \"-i\" option."
	echo "          "
        echo "SEE ALSO  "
        echo "     http://gmao.gsfc.nasa.gov/software/make_ctl"
	echo "          "
	exit 1
fi

if [ "$1" = "-nc" ];  then
	gradsbin="gradsnc"
	shift
elif [ "$1" = "-hdf" ]; then
	gradsbin="gradshdf"
	shift
elif [ "$1" = "-dods" ]; then
	gradsbin="gradsdods"
	shift
elif [ "$1" = "-dap" ]; then
	gradsbin="gradsdap"
	shift
fi

echo $gradsbin -blc \'run $make_ctlgs  $@ \'
eval $gradsbin -blc \'run $make_ctlgs  $@ \'
