#!/bin/sh
#
# createpage.sh: this is a HTTP Common Gateway Interface compilient script
# that builds sequence processing sumary HTML pages on the fly. As input,
# this script expects the QUERY_STRING environment variable to be set to
# the sequence of interest XXXXXXXX.VVV
#

# get the command line argument from the CGI QUERY_STRING environment variable
seq=$QUERY_STRING

# construct the name of the sequence summary file
dir="/aps/sequence_science_times/"
name=$dir'ad'$seq'_header_page.txt'
if test ! -r $name
then
  tmp=`echo $1 | awk 'BEGIN{FS = "."}{print $1}'`
  name=$dir'ad'$tmp'_header_page.txt'
fi
if test ! -r $name
then
  tmp=`echo $1 | awk 'BEGIN{FS = "."}{print $1}'`
  ext=`echo $1 | awk 'BEGIN{FS = "."}{print $2}'`
  name=$dir'ad'$tmp'_'$ext'_header_page.txt'
fi
if test ! -r $name
then
  tmp=`echo $1 | awk 'BEGIN{FS = "."}{print $1}'`
  ext=`echo $1 | awk 'BEGIN{FS = "."}{printf"%03d",$2}'`
  name=$dir'ad'$tmp'_'$ext'_header_page.txt'
fi

# send the HTTP server the content-type directive so that it knows we are
# creating an HTML page; note the blank line sent right after the directive
echo "Content-type: text/html"
echo ""
# now construct the HTML page
echo "< TITLE > Processing Summary for Sequence $seq < /TITLE >"  
echo "< PRE >" 
/bin/cat $name  
echo "< /PRE >" 
echo ""

# The HTML page is complete; exit the script
exit 0