#!/usr/bin/ksh

export WEB_ROOT=/webdata/web/www/htdocs

check_input()
{

   case $input in
      east_info)
           file="rteast.html"
           WEBPATH="${WEB_ROOT}/datacenter"
           title="East Information "
           CR="NO"
           PRE="NO"
           ;;
      mad_for)
           file=".zone.txt"
           WEBPATH="${WEB_ROOT}/localweather"
           title="Madison Forecast"
           CR="NO"
           PRE="NO"
           ;;
      wi_for)
           file=".state.txt"
           WEBPATH="${WEB_ROOT}/localweather"
           title="Wisconsin State Forecast"
           CR="NO"
           PRE="NO"
           ;;
      mad_now)
           file=".forecast.txt"
           WEBPATH="${WEB_ROOT}/localweather"
           title="Madison NOWCast"
           CR="NO"
           PRE="NO"
           ;;
      clim)
           file=".climate.txt"
           WEBPATH="${WEB_ROOT}/localweather"
           title="Madison Climate Summary"
           CR="YES"
           PRE="YES"
           ;;
      sfc)
           file=".saodata.txt"
           WEBPATH="${WEB_ROOT}/localweather"
           title="Surface Aviation Observations "
           CR="YES"
           PRE="YES"
           ;;
      rtf)
           file=".ftdata.txt"
           WEBPATH="${WEB_ROOT}/localweather"
           title="Regional Terminal Forecasts "
           CR="YES"
           PRE="YES"
           ;;
      mrf)
           file=".foxc.txt"
           WEBPATH="${WEB_ROOT}/localweather"
           title="MRF Long Range Forecast "
           CR="YES"
           PRE="YES"
           #LINK='<br>Decoding the <A HREF="/localweather/decode.html#mrf">MRF</A>.'
           LINK='<br>Decoding the <A HREF="http://www.nws.noaa.gov/tdl/synop/mexcard.htm">MRF</A>.'
           ;;
      mos)
           file=".fo14.txt"
           WEBPATH="${WEB_ROOT}/localweather"
           title="MOS Guidance for Madison "
           CR="YES"
           PRE="YES"
           LINK=''
           ;;
      fdus)
           file=".fdus.txt"
           WEBPATH="${WEB_ROOT}/localweather"
           title="Regional Winds Aloft Forecasts  "
           CR="YES"
           PRE="YES"
           ;;
      st_obs)
           file=".obs.txt"
           WEBPATH="${WEB_ROOT}/localweather"
           title="Wisconsin State Observations"
           CR="YES"
           PRE="YES"
           ;;
      mad_met)
           file="/localweather/.mgmsn.gif"
           WEBPATH="${WEB_ROOT}/localweather"
           title="Madison Meteorogram "
           caption="To update, reload while holding down the SHIFT key"
           IMG="YES"
           ;;
      ww)
           file="/localweather/ww.gif"
           WEBPATH="${WEB_ROOT}/localweather"
           title="Current Wisconsin Watches and Warnings "
           caption="To update, reload while holding down the SHIFT key"
           IMG="YES"
           ;;
      mid_plot)
           file="/localweather/.wxplot.gif"
           WEBPATH="${WEB_ROOT}/localweather"
           title="Midwest Weather Plot "
           caption="To update, reload while holding down the SHIFT key"
           IMG="YES"
           ;;
      manam)
           file="MANAM"
           WEBPATH="${WEB_ROOT}/datacenter"
           title="GMS Schedule (MANAM)"
           CR="YES"
           PRE="YES"
           ;;
   esac

}
html_head()
{
 # Echo HTML header
  echo "Content-type: text/html"
  echo
  echo '<HTML>'
  echo '<HEAD>'
  echo '<TITLE>'$title'</TITLE>'
  echo '</HEAD>'
  echo '<BODY bgcolor="#FFFFFF" text="#000000" link="#0014ff" vlink="#ff0000">'

  echo '<CENTER>'
  echo '<table>'
  echo '<tr>'
  echo '<td><IMG  SRC="http://www.ssec.wisc.edu/ssecsm.gif" ALT="SSEC Globe Logo"></td>'
  echo '<td><!--<IMG SRC="http://www.ssec.wisc.edu/ssecblue.gif" ALT="Space Science and Engineering Center (SSEC)">--><h1>Space Science and Engineering Center</h1></td>'
  echo '</tr>'
  echo '</table>'

  echo '<p>'
   echo '<table border=0 width=575>'
   echo '<tr>'
   echo '<TD>'
   echo '<H1>'$title'</H1>'


}


html_tail()
{
 # Echo HTML tail
   echo '</td></tr>'
   echo '</table>'
   if [[ -n $caption ]]; then
       echo '<br><i>'
       echo $caption
       echo '<br></i>'
   fi
   echo '</center>'

   echo '</BODY>'

   echo '</HTML>'

}

html_body()
{
   if [[ $IMG = "YES" ]]; then
       echo '<IMG  SRC="'$file'" ALT="'$title'">'
   elif [[ $PRE = "YES" ]]; then
       echo '<PRE>'
       cat ${WEBPATH}/$file
       echo '</PRE>'
   else
      cat ${WEBPATH}/$file|
      while read line; do
         case $line in
             FPUS*|SFP*|WIZ*|'$$')
              noop=1
             ;;
          "WISCONSIN STATE FORECAST")
              noop=1
             ;;
          '.'*...*)
              echo $line |awk -F"." {'print $2 '}|read before 
              echo ${line##.${before}...} |read after 
              echo '<br><br><font size=+1><B>'$before'...</B></font>'${after}
              ;;
             *)
              if [[ $CR = "YES" ]]; then
                 echo ${line}'<br>'
              else
                 echo ${line}
              fi
              ;;
         esac
      done
   fi
   echo $LINK

  if [[ $input = "mos" ]]; then
    echo 'Decoding the <a href="http://www.ssec.wisc.edu/localweather/decode.html">MOS Guidance</a>.'
  fi

}


# start Main
#######################

input=$1
WEBPATH="/home/web/localweather"
title="ERROR"
file=error

check_input

html_head
html_body
html_tail


exit
