#!/bin/csh -f

# December 26, 2002.  Added some debugging lines to output to /tmp/debug.tmp
# trying to understand why it is failing with the Southern Ocean CTD data.
# Evidence points to something within the build-opt-env file.  R. Groman

echo "Content-type: text/html"
echo ""

if ( -e /tmp/debug.tmp ) then
rm -f /tmp/debug.tmp
endif

cat << DEBUG1 > /tmp/debug.tmp
At beginning of plotmap  before call to source build-opt-env
DEBUG1

cat build-opt-env >> /tmp/debug.tmp

source build-opt-env

cat << DEBUG2 >> /tmp/debug.tmp
At beginning of plotmap  after call to source build-opt-env
DEBUG2

cd ${USETEMPDIR}

#unsetenv PATH_INFO

cat << DEBUG3 >> /tmp/debug.tmp
At beginning of plotmap  before set POSTSTR
DEBUG3

set POSTSTR=(`${OPTHOME}/bin/poststring proj cent_lat cent_lon shift_lat mag grid sym siz`)
echo "$POSTSTR" > mapopt

cat << XXSTUFF > map.var
projection=$POSTSTR[1]
cent_lat=$POSTSTR[2]
cent_lon=$POSTSTR[3]
shift_lat=$POSTSTR[4]
mag=$POSTSTR[5]
XXSTUFF

switch ( "$POSTSTR[7]" )
case "line":
  setenv SYM ""
  breaksw
case "+":
  setenv SYM "-sym 4"
  breaksw
case "x":
  setenv SYM "-sym 6"
  breaksw
case "o":
  setenv SYM "-sym 2"
  breaksw
case "+(connected)":
  setenv SYM "+sym 4"
  breaksw
case "x(connected)":
  setenv SYM "+sym 6"
  breaksw
case "o(connected)":
  setenv SYM "+sym 2"
  breaksw
endsw

setenv TMP `date '+%H%M%S'`

${OPTHOME}/bin/ch plot.var xmin=-1.4 ymin=-1 xmax=1.4 ymax=1 xvmin=0 yvmin=0 xvmax=100 yvmax=100
rm -f *.gif
${OPTHOME}/bin/pl "optmap(grid($POSTSTR[6]))" lon lat > tmp.tek
${OPTHOME}/bin/pl "/coast" lon lat >> tmp.tek
setenv LONVAR `${OPTHOME}/bin/listvar "${OBJECT}" | grep ' *lon'`
${OPTHOME}/bin/pl "optmap(${OBJECT})" $LONVAR lat $SYM -siz $POSTSTR[8] >> tmp.tek

${OPTHOME}/bin/tekgif tmp.tek > temp$TMP.gif

if ( "${SUBSELS}x" == "x" ) then
  set DISPFULL=${OBJECT}
else
  set DISPFULL="${OBJECT}(${DISPSS})"
endif

if ( ! -z temp$TMP.gif ) then
# You can place a title for the Map here
  cat <<XXstuffXX
  <h2>Locations for $DISPFULL</h2>
  <p>
  <img src="${USETEMPDIR}/temp$TMP.gif">
  <p>
XXstuffXX
else
  cat <<XXSTUFFXX
  <H2> No image was created.</h2>
  <b> Check that the data being used has lat,lon values.</b>   
XXSTUFFXX
endif
