#! /bin/sh
########################################################################################################## 
#                                                                                          
#        Titile:   exhrly_realtime_mainpage.sh   
#
#        Author:   Venkata Rao Anne
#
#        Date:     06-26-2004
#
#        Task:     Creat a Master web html page for realtime data monitoring system by extracting 
#                  current processing hourly infomation from input files hly_latest, rap_latest,
#                  nam_latest, gfs_latest, gds_latest in the html_inp_files. Also create a html 
#                  table with model data types information another html table with model summary
#                  information.
#
# Usage - sh exhrly_realtime_mainpage.sh $output_dir $input_dir $model_sumtable
#         output_dir=/com/web/prod/realtime
#         input_dir=/com/web/prod/realtime
#
# $model = hly/rap/rap/gfs/gds
# Note: This script expects all the model_latest files such as
#       nam_latest  gds_latest  gfs_latest  hly_latest  rap_latest
#       in the /com/web/prod/realtime ($input_dir) directory. This script also copies
#       index.shtml corresponding to table.html file to $output_dir/$model/$cycle
#
# CHANGE LOG:
#
#	K. Malone 	05/2010		Modified script to underline the current hour as an additional
#          (Kempisty)			level of functionality to distinguish the current hour from all
#					all other hours.  Added magenta and dark turquoise to the color
#                                       code to represent shortages and overages of data types of
#					opportunity, respectively.  Modified the "Color Dump Text Summary"
#					pages to create separate tables for each level of data count
#					severity.  Added entry to each table - current count percentage
#					of the 30-day average count.
#       K. Kempisty      11/2011        Modified the script to replace the legacy RUC with the Rapid
#					Refresh (RAP)
#       
##########################################################################################################

### test the input files and extract the current processing hourly information.

set -x

if [ $# -ne 3 ]; then
   echo "error: no args\n"
   echo "Usage: `basename $0` output_director_name input_directory_name input_summary_file_name"
   exit 1
fi
                                                                                                  
if [ -d $1 ]; then
   out_dir=$1
else
   echo "output directory \"$1\" does not exist."
   exit 2
fi
                                                                                                  
if [ -d $2 ]; then
   inp_dir=$2
else
   echo "input directory \"$2\" does not exist."
   exit 3
fi

if [ -f $2/$3 ]; then
   summary_file=$3
   inp_model=`echo $3 |cut -c1-3`
   INP_MODEL_CAP=`echo $inp_model | tr "[a-z]" "[A-Z]"`
else
   echo "File \"$3\" does not exist."
   exit 4
fi

### check the input summary file name start with either hly/rap/nam/gfs/gds .

ANS=N
models='hly rap nam gfs gds'
for mod in $models
do
   if [ $mod = $inp_model ]; then
      ANS=Y
   fi
done
if [ "$ANS"  = "N" ]; then
   echo " summary file name: $summary_file "
   echo " Error. first 3 char of  summary file name does not start with either hly/rap/nam/gfs/gds "
   exit 5
fi

### check the all the current processing hourly job information files exist in the input directory.

for mod in $models
do
   file=$inp_dir/${mod}_latest
   if [ ! -f $file ]; then
      echo "File $file does not exist."
      exit 6
   fi
done

updated_year_day=`cat $inp_dir/${inp_model}_latest | cut -c1-8`
updated_hr=`cat $inp_dir/${inp_model}_latest | cut -c9-10`

### Here is where the HOURLY & RAP html table work in the Master web page gets done

type0='<th ALIGN="CENTER" COLSPAN="1" ><p><a HREF="'
type00='<th ALIGN="CENTER" COLSPAN="1"  bgcolor="#e6e6f6" ><p><u><a HREF="'
type1='/'
type2='/index.shtml" ><font COLOR="'
type3='">'
type4='</a></u></p></th>' 
type5='</a></p></th>' 
hr23=23

###################################################
##### "realtime_mainpage.html" generated here #####
###################################################

main_html=realtime_mainpage.html

### Create a GENERIC TITLE ###

echo "  " >> $main_html 
echo "<center>" >> $main_html
echo "<p><h1> <font COLOR=blue> NCEP REAL TIME DATA MONITORING SYSTEM </font> </h1></p>" >> $main_html
echo "</center>" >> $main_html

models='hly rap'
for mod in $models
do 
   echo "  " >> $main_html 
   echo "<center>" >> $main_html
   if [ $mod = "hly" ]; then
      subdir=hourly 
      lst_hr=`cat $inp_dir/${mod}_latest | cut -c9-10`
      echo "<h1>Hourly Data Dump Tables</h1>" >> $main_html
   else
      subdir=rap 
      lst_hr=`cat $inp_dir/${mod}_latest | cut -c9-10`
      echo "<h1>RAP Data Dump Tables</h1>" >> $main_html
   fi
   echo "</center>" >> $main_html
   echo "<center>" >> $main_html
   echo "<a href=\"$subdir/t${lst_hr}z/index.summary.shtml\" ><font size =\"3\" >View the latest $subdir text summary</font></a><br>" >> $main_html
   echo "</center>" >> $main_html
   echo "<table border=\"5\" ALIGN="center" WIDTH =\"80%\" cellpadding=\"5\" cellspacing=\"10\">" >> $main_html
   echo "<tr>" >> $main_html
   echo "<th ALIGN=\"CENTER\" COLSPAN=\"15\" ><p><b> <font COLOR=\"blue\">CLICK ON UNDERLINED HOUR / SHADED BOX FOR THE LATEST CYCLE</font></b></p></th>" >> $main_html
   echo "</tr>" >> $main_html
   echo "<tr>" >> $main_html
   hr=0
   while [ $hr -le $hr23 ]
   do
      if [ $hr -lt 10 ]; then
         hr1=0"$hr"
      else
         hr1="$hr"
      fi
      hrz="$hr1"z
      thrz=t"$hrz"
      if [ $hr1 = $lst_hr ]; then
         col="green"
         echo $type00$subdir$type1$thrz$type2$col$type3$hrz$type4 >> $main_html
      elif [ $hr -lt $lst_hr ]; then
         col="green"
         echo $type0$subdir$type1$thrz$type2$col$type3$hrz$type5 >> $main_html
      else
         col="black"
         echo $type0$subdir$type1$thrz$type2$col$type3$hrz$type5 >> $main_html
      fi
      hr=`expr $hr + 1`
      if [ $hr  -eq  12 ]; then
         echo "</tr>" >> $main_html
         echo "     " >> $main_html
         echo "<tr>" >> $main_html
      fi
   done
   echo "</tr>" >> $main_html
   echo "</table>" >> $main_html
done

### Here is where the NAM GFS GDS html table work in master web page gets done

echo "  " >> $main_html 
echo "<center>" >> $main_html 
echo "<h1>Model Data Dump Tables </h1>" >> $main_html 
echo "</center>" >> $main_html 
echo "<table ALIGN=center>" >> $main_html 
echo "<tr VALIGN=\"top\">" >> $main_html 
echo "<th  ALIGN=\"CENTER\" COLSPAN=\"1\" ><p><font COLOR=\"blue\"> View the latest model data text summary &nbsp;&nbsp;</font></p></th>" >> $main_html 

models='nam gfs gds'
times='00 06 12 18'
for mod in $models
do 
   lst_hr=`cat $inp_dir/${mod}_latest | cut -c9-10`
   MOD_CAP=`echo $mod | tr "[a-z]" "[A-Z]"`
   echo "<th COLSPAN=\"1\" ><p><a HREF=\"$mod/t${lst_hr}z/index.summary.shtml\" title=\"Summary for ${lst_hr}z $MOD_CAP\" ><font COLOR=\"green\">$MOD_CAP</a></p></th>" >> $main_html 
done

echo "</tr>" >> $main_html 
echo "</table>" >> $main_html 
echo "<table border=\"5\" ALIGN=\"center\" WIDTH =\"80%\" cellpadding=\"5\" cellspacing=\"10\">" >> $main_html 
echo "<tr>" >> $main_html 
echo "<th ALIGN=\"CENTER\" COLSPAN=\"15\" ><p><b> <font COLOR=\"blue\">CLICK ON UNDERLINED HOUR / SHADED BOX FOR THE LATEST CYCLE</font></b></p></th>" >> $main_html 
echo "</tr>" >> $main_html 
echo "<tr VALIGN=\"top\">" >> $main_html 

for mod in $models
do 
   MOD_CAP=`echo $mod | tr "[a-z]" "[A-Z]"`
   echo "<th COLSPAN=\"4\" ALIGN=\"center\"><font SIZE=\"+1\">  $MOD_CAP </font></th>" >> $main_html
done

echo "</tr> <tr VALIGN=\"top\">" >> $main_html

for mod in $models
do 
   lst_hr=`cat $inp_dir/${mod}_latest | cut -c9-10`
   for hr in $times
   do 
      hrz="$hr"z
      thrz=t"$hrz"
      if [ $hr = $lst_hr ]; then
         col="green"
         echo $type00$mod$type1$thrz$type2$col$type3$hrz$type4 >> $main_html
      elif [ $hr -lt $lst_hr ]; then
         col="green"
         echo $type0$mod$type1$thrz$type2$col$type3$hrz$type5 >> $main_html
      else
         col="black"
         echo $type0$mod$type1$thrz$type2$col$type3$hrz$type5 >> $main_html
      fi
   done
done

echo "</tr>" >> $main_html
echo "</table>" >> $main_html
echo "<p ALIGN =\"right\" ><a <font COLOR=\"BLUE\"> $INP_MODEL_CAP Updated: $updated_year_day t${updated_hr}z </font></a></p>" >> $main_html
echo "  " >> $main_html
echo "<table align=\"center\">" >> $main_html
echo "<tr VALIGN=\"top\">" >> $main_html
echo "<th ALIGN=\"center\" COLSPAN=\"1\"><p><b> <font COLOR=\"BLUE\">Explanation of Colors</font></b></p></th>" >> $main_html
echo "</tr>" >> $main_html
echo "</table>" >> $main_html
echo "<table  border=\"5\" align=\"center\">" >> $main_html
echo "<tr><th><p ALIGN = \"left\"><b> <font COLOR=\"red\">---- Abnormal shortage in critical data type - Investigate</font></b></p></th></tr>" >> $main_html
echo "<tr><th><p ALIGN = \"left\"><b> <font COLOR=\"orange\">---- Shortage in sub-critical data type - Monitor  </font></b></p></th></tr>" >> $main_html
echo "<tr><th><p ALIGN = \"left\"><b> <font COLOR=\"magenta\">---- Shortage in data type of opportunity - Monitor</font></b></p></th></tr>" >> $main_html
echo "<tr><th><p ALIGN = \"left\"><b> <font COLOR=\"purple\">---- Overage in critical data type - Investigate </font></b></p></th></tr>" >> $main_html
echo "<tr><th><p ALIGN = \"left\"><b> <font COLOR=\"blue\">---- Overage in sub-critical data type - Monitor</font></b></p></th></tr>" >> $main_html
echo "<tr><th><p ALIGN = \"left\"><b> <font COLOR=\"darkturquoise\">---- Overage in data type of opportunity - Monitor</font></b></p></th></tr>" >> $main_html
echo "<tr><th><p ALIGN = \"left\"><b> <font COLOR=\"green\">---- Critical data with normal counts</font></b></p></th></tr>" >> $main_html
echo "<tr><th><p ALIGN = \"left\"><b> <font COLOR=\"black\">---- Data of opportunity with normal counts</font></b></p></th></tr>" >> $main_html
echo "</table>" >> $main_html
echo "  " >> $main_html
#echo "<p ALIGN=\"center\"><a href=\"index.color_exp.shtml\"><font size=\"3\"><font color=\"BLUE\">Explanation of Colors</font></font></a></p>" >> $main_html
echo "  " >> $main_html

### Here is where the current model data types html table work gets done

model=$inp_model
MODEL=$INP_MODEL_CAP
if [ $model = "hly" ]; then
   model=hourly
   MODEL=HOURLY 
fi

nline=`wc -l $inp_dir/$summary_file | cut -c1-8`
thrz=t"$lst_hr"z
echo $inp_model $updated_year_day $lst_hr

##############################################################
##### Model table html "${NET}_table.html" file generated here  
##############################################################

tab_html=${inp_model}_table.html
echo "<head>" >> $tab_html
echo "<title>NWS/NCO/PMB RTDMS $summary_file</title>" >> $tab_html
echo "<head>" >> $tab_html
echo "<center>" >> $tab_html
echo "<p><h1> <font COLOR=\"BLUE\">$MODEL Dump Data Counts Time Series Plots</h1></p>" >> $tab_html
echo "<p><h2> <font COLOR=\"BLUE\">Valid $updated_year_day t${updated_hr}z </h2></p>" >> $tab_html
#echo "<table ALIGN=\"center\"> >> $tab_html
echo "<table border=\"5\" align=\"center\"  cellpadding=\"5\" cellspacing=\"10\">" >> $tab_html
echo "<tr VALIGN=\"top\">" >> $tab_html
echo "<th COLSPAN=\"1\" ><p ALIGN = \"left\"><a HREF=\"../../index.bufrdump.shtml\"><font COLOR=\"BLUE\">Explanation of Data Types </a></p></th>" >> $tab_html
#echo "<th COLSPAN=\"1\" ><p ALIGN = \"right\"><a HREF=\"index.summary.shtml\"><font COLOR=\"BLUE\">View $MODEL Data Text Summary </a></p></th>" >> $tab_html
echo "<th COLSPAN=\"1\" ><p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p></th>" >> $tab_html
#echo "<th COLSPAN=\"1\" ><p ALIGN = \"left\"><a HREF=\"../../bufr_dumplist.html\"><font COLOR=\"BLUE\">Explanation of Data Types </a></p></th>" >> $tab_html
echo "<th COLSPAN=\"1\" ><p ALIGN =\"right\"><a HREF=\"index.summary.shtml\"><font COLOR=\"BLUE\">View $MODEL Data Text Summary </a></p></th>" >> $tab_html
echo "</tr>" >> $tab_html
echo "</table>" >> $tab_html
echo "</center>" >> $tab_html
echo "<table border=\"5\" align=\"center\"  cellpadding=\"5\" cellspacing=\"10\">" >> $tab_html
echo "<tr>" >> $tab_html
echo "<th ALIGN=\"CENTER\" COLSPAN=\"15\" ><p><b> <font COLOR=\"BLUE\">Click on data types to view time series plots</font></b></p></th>" >> $tab_html
echo "</tr>" >> $tab_html
echo "<tr>" >> $tab_html
 
count=0
awk '{print $1" " $2" " $3}' $inp_dir/$summary_file > tmp
while  read data_type color_code plt_num
do 
   case "$color_code" in
      1)   col="purple"
           title="Overage in critical data type - Investigate";;
      2)   col="blue"
           title="Overage in sub-critical data type - Monitor";;
      3)   col="red"
           title="Abnormal shortage in critical data type - Investigate";;
      4)   col="orange"
           title="Shortage in sub-critical data type - Monitor";;
      5)   col="green" 
           title="Critical data with normal counts";;
      6)   col="black"
           title="Other data including data of opportunity";;
      7)   col="darkturquoise"
           title="Overage in data of opportunity - Monitor";;
      8)   col="magenta"
           title="Shortage in data of opportunity - Monitor";;
   esac
   count=`expr $count + 1`
   echo "<th COLSPAN=\"1\" ><p><a HREF=\"$inp_model.$plt_num.gif\" title=\"$data_type - $title\"><font COLOR=\"$col\" > $data_type </a></p></th>" >> $tab_html 
   if [ `expr $count % 9` -eq 0 ]; then
      if [ $count -lt $nline ]; then 
         echo "</tr>" >> $tab_html
         echo "     " >> $tab_html
         echo "<tr>" >> $tab_html
      fi
   fi
done < tmp

rm tmp
echo "</tr>" >> $tab_html
echo "</table>" >> $tab_html
echo "  " >> $tab_html
echo "<br />" >> $tab_html
echo "<table align=\"center\">" >> $tab_html
echo "<tr VALIGN=\"top\">" >> $tab_html
echo "<th ALIGN=\"center\"><p><a href=\"../../index.tsg.shtml\" >Data Troubleshooting Guide </a></p></th>" >> $tab_html
echo "</tr>" >> $tab_html
echo "</table>" >> $tab_html
echo "  " >> $tab_html
echo "<br />" >> $tab_html
echo "<br />" >> $tab_html
echo "<table align=\"center\">" >> $tab_html
echo "<tr VALIGN=\"top\">" >> $tab_html
echo "<th ALIGN=\"center\" COLSPAN=\"1\"><p><b> <font COLOR=\"BLUE\">Explanation of Colors</font></b></p></th>" >> $tab_html
echo "</tr>" >> $tab_html
echo "</table>" >> $tab_html
echo "  " >> $tab_html
echo '<table  border="5" align="center">' >> $tab_html
if [ $inp_model = "nam" -o $inp_model = "gfs" -o $inp_model = "gds" ]; then
   echo  '<tr><th><p ALIGN = "left"><b> <font COLOR="red">---- Abnormal shortage in critical data type - Investigate</font></b></p></th></tr>' >> $tab_html
   echo  '<tr><th><p ALIGN = "left"><b> <font COLOR="purple">---- Overage in critical data type - Investigate </font></b></p></th></tr>' >> $tab_html
   echo  '<tr><th><p ALIGN = "left"><b> <font COLOR="orange">---- Shortage in sub-critical data type - Monitor  </font></b></p></th></tr>' >> $tab_html
   echo  '<tr><th><p ALIGN = "left"><b> <font COLOR="blue">---- Overage in sub-critical data type - Monitor</font></b></p></th></tr>' >> $tab_html
   echo  '<tr><th><p ALIGN = "left"><b> <font COLOR="magenta">---- Shortage in data type of opportunity - Monitor</font></b></p></th></tr>' >> $tab_html
   echo  '<tr><th><p ALIGN = "left"><b> <font COLOR="darkturquoise">---- Overage in data type of opportunity - Monitor</font></b></p></th></tr>' >> $tab_html
   echo  '<tr><th><p ALIGN = "left"><b> <font COLOR="green">---- Critical data with normal counts</font></b></p></th></tr>' >> $tab_html
   echo  '<tr><th><p ALIGN = "left"> <b> <font COLOR="black">---- Data of opportunity with normal counts</font></b></p></th></tr>' >> $tab_html
else
   echo  '<tr><th><p ALIGN = "left"><b> <font COLOR="red">---- Abnormal shortage in critical data type - Investigate</font></b></p></th></tr>' >> $tab_html
   echo  '<tr><th><p ALIGN = "left"><b> <font COLOR="orange">---- Shortage in sub-critical data type - Monitor  </font></b></p></th></tr>' >> $tab_html
   echo  '<tr><th><p ALIGN = "left"><b> <font COLOR="magenta">---- Shortage in data type of opportunity - Monitor</font></b></p></th></tr>' >> $tab_html
   echo  '<tr><th><p ALIGN = "left"><b> <font COLOR="green">---- Critical data with normal counts</font></b></p></th></tr>' >> $tab_html
   echo  '<tr><th><p ALIGN = "left"> <b> <font COLOR="black">---- Data of opportunity with normal counts</font></b></p></th></tr>' >> $tab_html
fi
echo "</table>" >> $tab_html
echo "  " >> $tab_html
echo '<p ALIGN="right"><a href="../../index.shtml" >Go back to realtime mainpage </a><br></p>' >> $tab_html

### Here is where the summary model data types html table work gets done

### Here is where the HLY, RAP, NAM, GFS, GDS html table  work  gets done

if [ $inp_model = "hly" ]; then
   pmodel=HOURLY
else
   pmodel=$INP_MODEL_CAP
fi

#########################################################################
##### Model text summary in table format "${NET}_summary_table.html" file
##### generated here
#########################################################################

sum_html=${inp_model}_summary_table.html
echo "<head>" >> $sum_html
echo "<title>NWS/NCO/SIB RTDMS $summary_file</title>" >> $sum_html
echo "<head>" >> $sum_html
echo "<center>" >> $sum_html
echo "<p><h2> <font COLOR=\"BLUE\">$pmodel Color Dump Text Summary for $updated_year_day t${updated_hr}z </h2></p>" >> $sum_html
echo " " >> $sum_html
nline=`wc -l $inp_dir/$summary_file | cut -c1-8`
echo "total number of data types in $inp_dir/$summary_file : $nline "

color_codes='3 4 1 2 8 7 5 6 0'
for color_code in $color_codes
do
   case "$color_code" in
      1)   awk ' $2 == 1 ' $inp_dir/$summary_file > tmp ;;
      2)   awk ' $2 == 2 ' $inp_dir/$summary_file > tmp ;;
      3)   awk ' $2 == 3 ' $inp_dir/$summary_file > tmp ;;
      4)   awk ' $2 == 4 ' $inp_dir/$summary_file > tmp ;;
      5)   awk ' $2 == 5 ' $inp_dir/$summary_file > tmp ;;
      6)   awk ' $2 == 6 ' $inp_dir/$summary_file > tmp ;;
      7)   awk ' $2 == 7 ' $inp_dir/$summary_file > tmp ;;
      8)   awk ' $2 == 8 ' $inp_dir/$summary_file > tmp ;;
      0)   awk ' $2 == 0 ' $inp_dir/$summary_file > tmp ;;
   esac
   nline=`wc -l tmp | cut -c1-8`
   echo "$nline data types with color code $color_code "
   if [ $nline -gt 0 ]; then
      echo "<table width=100% cellSpacing=\"0\" cellPadding=\"2\" border=\"1\">" >> $sum_html
      case "$color_code" in
         1)   col="purple"
              echo "<tr><th ALIGN=\"center\" COLSPAN=\"15\"><b> <font COLOR=\"$col\">Abnormal Excess in Critical Types - Investigation Required </font></b></th></tr>" >> $sum_html
              ;;
         2)   col="blue"
              echo "<tr><th ALIGN=\"center\" COLSPAN=\"15\"><b> <font COLOR=\"$col\">Suspect Excess in Critical Types - Monitor </font></b></th></tr>" >> $sum_html
              ;;
         3)   col="red"
              echo "<tr><th ALIGN=\"center\" COLSPAN=\"15\"><b> <font COLOR=\"$col\">Abnormal Data Shortage in Critical Types - Investigation Required </font></b></th></tr>" >> $sum_html
              ;;
         4)   col="orange"
              echo "<tr><th ALIGN=\"center\" COLSPAN=\"15\"><b> <font COLOR=\"$col\">Suspect Data Shortages in Critical Types - Monitor </font></b></th></tr>" >> $sum_html
              ;;
         5)   col="green"
              echo  "<tr><th ALIGN=\"center\" COLSPAN=\"15\"><b> <font COLOR=\"$col\">Critical Data with Normal Counts </font></b></th></tr>" >> $sum_html
              ;;
         7)   col="darkturquoise"
              echo "<tr><th ALIGN=\"center\" COLSPAN=\"15\"><b> <font COLOR=\"$col\">Excess in Data Type of Opportunity - Monitor </font></b></th></tr>" >> $sum_html
              ;;
         8)   col="magenta"
              echo "<tr><th ALIGN=\"center\" COLSPAN=\"15\"><b> <font COLOR=\"$col\">Shortage in Data Type of Opportunity - Monitor </font></b></th></tr>" >> $sum_html
              ;;
         6)   col="black"
              echo "<tr><th ALIGN=\"center\" COLSPAN=\"15\"><b> <font COLOR=\"$col\">Data Types of Opportunity with Normal Counts </font></b></th></tr>" >> $sum_html
              ;;
         *)   col="black"
              echo "<tr><th ALIGN=\"center\" COLSPAN=\"15\"><b> <font COLOR=\"$col\">Data with no Type  </font></b></th></tr>" >> $sum_html
              ;;
      esac
      if [ $inp_model = "hly" -o $inp_model = "rap" ]; then
         echo "<tr VALIGN=\"top\"><td><font COLOR=\"black\">Type</font></td><td><font COLOR=\"black\">Description</font></td><td><font COLOR=\"black\">Hourly Count</font></td><td><font COLOR=\"black\">Monthly Average</font></td><td><font COLOR=\"black\">Percent (%) of Monthly Mean</font></td><td><font COLOR=\"black\">UTC Time Window</font></td></tr>" >> $sum_html
      else
         echo "<tr VALIGN=\"top\"><td><font COLOR=\"black\">Type</font></td><td><font COLOR=\"black\">Description</font></td><td><font COLOR=\"black\">Hourly Count</font></td><td><font COLOR=\"black\">Monthly Average</font></td><td><font COLOR=\"black\">Percent (%) of Monthly Mean</font></td></tr>" >> $sum_html
      fi
      if [ $inp_model = "hly" -o $inp_model = "rap" ]; then
         while  read data_type col_code plt_num hly_cnt mn_cnt pct_avg time_win des
         do
            echo "<tr VALIGN=\"top\">" >> $sum_html
            echo "<td COLSPAN=\"1\" ><p><a HREF=\"$inp_model.$plt_num.gif\"><font COLOR=\"blue\" > $data_type </font></a></p></td>" >> $sum_html
            echo "<td COLSPAN=\"1\" ><p> <font COLOR=$col > $des </font></p></td>" >> $sum_html
            echo "<td COLSPAN=\"1\" ><p ALIGN = \"right\"> <font COLOR=\"$col\" > $hly_cnt </font></p></td>" >> $sum_html
            echo "<td COLSPAN=\"1\" ><p ALIGN =\"right\"> <font COLOR=\"$col\" > $mn_cnt </font></p></td>" >> $sum_html
            if [ $pct_avg -ne 999.0 ]; then
               echo "<td COLSPAN=\"1\" ><p ALIGN =\"right\"> <b><font COLOR=\"$col\" > $pct_avg % </font></b></p></td>" >> $sum_html
            else
               echo "<td COLSPAN=\"1\" ><p ALIGN =\"right\"> <font COLOR=\"$col\" > n/a </font></p></td>" >> $sum_html
            fi
            echo "<td COLSPAN=\"1\" ><p> <font COLOR=\"$col\" > $time_win </font></p></td>" >> $sum_html
            echo "</tr>" >> $sum_html
         done < tmp
      elif [ $inp_model = "gds" -o $inp_model = "gfs" -o $inp_model = "nam" ]; then
         while  read data_type col_code plt_num hly_cnt mn_cnt pct_avg des
         do
            echo "<tr VALIGN=\"top\">" >> $sum_html
            echo "<td COLSPAN=\"1\" ><p><a HREF=\"$inp_model.$plt_num.gif\"><font COLOR=\"blue\" > $data_type </font></a></p></td>" >> $sum_html
            echo "<td COLSPAN=\"1\" ><p> <font COLOR=\"$col\" > $des </font></p></td>" >> $sum_html
            echo "<td COLSPAN=\"1\" ><p ALIGN = \"right\"> <font COLOR=\"$col\" > $hly_cnt </font></p></td>" >> $sum_html
            echo "<td COLSPAN=\"1\" ><p ALIGN = \"right\"> <font COLOR=\"$col\" > $mn_cnt </font></p></td>" >> $sum_html
            if [ $pct_avg -ne 999.0 ]; then
               echo "<td COLSPAN=\"1\" ><p ALIGN = \"right\"> <b><font COLOR=\"$col\" > $pct_avg % </font></b></p></td>" >> $sum_html
            else
               echo "<td COLSPAN=\"1\" ><p ALIGN = \"right\"> <font COLOR=\"$col\" > n/a </font></p></td>" >> $sum_html
            fi
            echo "</tr>" >> $sum_html
         done < tmp
      fi
      echo "</table>" >> $sum_html
      echo "<br />" >> $sum_html
      echo "<br />" >> $sum_html
   fi
   rm tmp
done

echo '<p ALIGN=\"right\"><a href="../../index.shtml" >Go back to realtime mainpage </a><br></p>' >> $sum_html
mv $main_html $out_dir  
mv $tab_html $out_dir  
mv $sum_html $out_dir

#####################################################################
# GOOD RUN
# set +x
echo "************** exhrly_realtime_mainpage.sh COMPLETED NORMALLY ON THE IBM"
echo "************** exhrly_realtime_mainpage.sh COMPLETED NORMALLY ON THE IBM"
echo "************** exhrly_realtime_mainpage.sh COMPLETED NORMALLY ON THE IBM"
set -x
#####################################################################

msg="HAS COMPLETED NORMALLY!"
echo $msg
#postmsg "$jlogfile" "$msg"
############## END OF SCRIPT #######################
