header (version 1.8)

You can also look at:
#! /usr/bin/ksh

###########################################################################
#
# SYNTAX: header
#
# BRIEFLY: Create an HTML header page.
#
# DESCRIPTION: This routine creates an HTML page which gives basic
# DESCRIPTION: information about the observation and processing.
# DESCRIPTION: This page also contains links to other information pages.
#
# VERSION: 1.8
#
# HISTORY: 0.0 -> 1.0 1/3/97
# HISTORY: Fixed spelling. Only "principal" is an adjective.
# HISTORY:
# HISTORY: 1.0 -> 1.1 2/4/97
# HISTORY: Converted from float... STOOLS to equals.
# HISTORY: Now explicitly states the processing revision number after the
# HISTORY: script version number.
# HISTORY: Now reads observation coordinates directly from job.par instead
# HISTORY: of recalculating them from the Euler angles.
# HISTORY: 2/20/97 Duration now given in kiloseconds.
# HISTORY:
# HISTORY: 1.1 -> 1.2 2/22/97
# HISTORY: Now rounds duration to nearest tenth of a kilosecond.
# HISTORY: 3/17/97 Straightened out galactic longitude and latitude.
# HISTORY:
# HISTORY: 1.2 -> 1.3 5/21/97
# HISTORY: Changed method for extracting FTOOLS version to accomodate
# HISTORY: the new bin directory structure in ftools.4.0 and later.
# HISTORY: Note that this is backwards-compatible.
# HISTORY:
# HISTORY: 1.3 -> 1.4 6/10/97
# HISTORY: Removed initial dot from FTOOLS version number.
# HISTORY:
# HISTORY: 1.4 -> 1.5 12/29/97
# HISTORY: Fixed the syntax of the exception call.
# HISTORY:
# HISTORY: 1.5 -> 1.6 1/13/97
# HISTORY: Added PI calibration file dates and changed processing date to
# HISTORY: give the full, unabbreviated month name.
# HISTORY:
# HISTORY: 1.6 -> 1.7 2/12/98
# HISTORY: Now reads the obsdate from the job.par instead of parsing the
# HISTORY: telemetry file name. The information subroutine does a more
# HISTORY: robust job of extracting this date and is y2k compliant.
# HISTORY: Also, now gives the percentage of SIS ISAS time which is saturated.
# HISTORY:
# HISTORY: 1.7 -> 1.8 4/13/98
# HISTORY: Now determine and report the total amount of time in telemetry
# HISTORY: gaps for the observation.
#
###########################################################################
#DEBUG=1

$UTIL/milestone "Creating sequence documentation"

##############
# Header page
##############
header=$(    $UTIL/generate_filename header    )
eventinfo=$( $UTIL/generate_filename eventinfo )
fileinfo=$(  $UTIL/generate_filename fileinfo  )
milestones=$($UTIL/generate_filename milestones)
sourceinfo=$($UTIL/generate_filename sourceinfo)
seq=$($UTIL/read_parfile $JOBPAR sequence)

###################
# Debugging output
###################
if [ -n "$DEBUG" ]; then
    echo ${0##*/}: header=$header
fi

rm -f $header

##############
# Title, etc.
##############

echo "<HTML>"                                                         >>$header
echo "<!-- This page generated by $0 on $(date) -->"                  >>$header
echo "<HEAD>"                                                         >>$header
echo "<TITLE>ASCA Sequence $seq Header Page</TITLE>"                  >>$header
echo "</HEAD>"                                                        >>$header

echo "<BODY>"                                                         >>$header
echo "<H1>ASCA Sequence $seq Header Page</H1>"                        >>$header

echo "This page gives a basic description of this sequence"           >>$header
echo "and references to more detailed information."                   >>$header
echo "<P>"                                                            >>$header

echo "The following information is also available:"                   >>$header
echo "<UL>"                                                           >>$header
echo "  <LI><A HREF=\"${eventinfo}\">Details of each event file</A>"  >>$header
echo "  <LI><A HREF=\"${sourceinfo}\">A list of detected sources</A>" >>$header
echo "  <LI><A HREF=\"${fileinfo}\">A list of all files</A>"          >>$header
echo "  <LI><A HREF=\"${milestones}\">The processing log index</A>"   >>$header
echo "</UL>"                                                          >>$header

echo "<HR>"                                                           >>$header

##############
# Observation
##############
object=$($UTIL/read_parfile $JOBPAR object)

ra=$( $UTIL/read_parfile $JOBPAR ra )
dec=$($UTIL/read_parfile $JOBPAR dec)

Lii=$($UTIL/read_parfile $JOBPAR glon)
Bii=$($UTIL/read_parfile $JOBPAR glat)

ra=$( $STOOL/equals "int(${ra}  * 1000 +.5)/1000 ")
dec=$($STOOL/equals "int(${dec} * 1000 +.5)/1000 ")

Lii=$($STOOL/equals "int(${Lii} * 1000 +.5)/1000 ")
Bii=$($STOOL/equals "int(${Bii} * 1000 +.5)/1000 ")

####################
# Observation date
####################
obsdate=$($UTIL/read_parfile $JOBPAR obsdate)
obsdate=$($UTIL/iso_date_to_words $obsdate  )

###########
# Duration
###########
duration=0.
totgaps=0
for telem in $(ls ft??????_????.????); do

    time0=$($UTIL/read_fits_keyword $telem[1] MTIME0)
    time1=$($UTIL/read_fits_keyword $telem[1] MTIME1)
    time=$($STOOL/equals "$time1 - $time0")
    duration=$($STOOL/equals "$duration + $time")

    ###################
    # Debugging output
    ###################
    if [ -n "$DEBUG" ]; then
        echo ${0##*/}: telem=$telem
        echo ${0##*/}: time0=$time0
        echo ${0##*/}: time1=$time1
        echo ${0##*/}: time=$time
        echo ${0##*/}: duration=$duration
    fi

    ############################
    # gaps in the telemetry
    ############################
    $STOOL/telemgap $telem >stdout.log 2>stderr.log
    code=$?
    gap=$(tail -1 stdout.log)
    let totgaps=$totgaps+$gap
    $UTIL/stool_test telemgap $code $0 1 stdout.log stderr.log

done

duration=$($STOOL/equals "int($duration/100+.5)/10")

#############
# ISAS times
#############
sis_isas_time=$($UTIL/read_parfile $JOBPAR sis_isas_time)
gis_isas_time=$($UTIL/read_parfile $JOBPAR gis_isas_time)
unsat_isas_time=$($UTIL/read_parfile $JOBPAR unsat_isas_time)

sat_fraction=$($STOOL/equals "int( 100*(1.-$unsat_isas_time/$sis_isas_time))")


sis_isas_time=$($STOOL/equals "int($sis_isas_time/100+.5)/10")
gis_isas_time=$($STOOL/equals "int($gis_isas_time/100+.5)/10")

echo "<H2>Observation Information</H2>"                               >>$header
echo "<UL>"                                                           >>$header
echo "  <LI><STRONG>Object:</STRONG> $object"                         >>$header
echo "  <LI><STRONG>Nominal Pointing</STRONG> (degrees)"              >>$header
echo "  <UL>"                                                         >>$header
echo "    <LI><STRONG>R.A.=</STRONG>$ra <STRONG>Dec.=</STRONG>$dec"   >>$header
echo "    <LI><STRONG>Lii=</STRONG>$Lii <STRONG>Bii=</STRONG>$Bii"    >>$header
echo "  </UL>"                                                        >>$header
echo "  <LI><STRONG>Observation Date:</STRONG> $obsdate"              >>$header
echo "  <LI><STRONG>Duration:</STRONG> $duration kiloseconds"         >>$header
echo "       (with $totgaps kiloseconds of telemetry gaps)"           >>$header

echo "  <LI><STRONG>Approximate SIS Exposure:</STRONG>"               >>$header
echo "  $sis_isas_time kiloseconds"                                   >>$header
echo "  (approximately ${sat_fraction}% with telemetry saturated)"    >>$header

echo "  <LI><STRONG>Approximate GIS Exposure:</STRONG>"               >>$header
echo "  $gis_isas_time kiloseconds"                                   >>$header

echo "</UL>"                                                          >>$header

#############
# Processing
#############
seqver=$($UTIL/read_parfile $JOBPAR seqprocnum)
procver=$($UTIL/read_parfile $PARFILE version)

ftools=$(echo $FTOOL | sed -e's|/|\
|g' | grep ftools\.)
ftools=${ftools#ftools}
ftools=${ftools#.}

case "$procver" in
6.*) rev="(Revision 1+)";;
7.*) rev="(Revision 2)" ;;
*) rev="" ;;
esac

gis_temp_date=$($UTIL/read_parfile $JOBPAR gis_temp_date)
gis_map_date=$( $UTIL/read_parfile $JOBPAR gis_map_date )
sis_cti_date=$( $UTIL/read_parfile $JOBPAR sis_cti_date )

gis_temp_date=$($UTIL/iso_date_to_words $gis_temp_date)
gis_map_date=$( $UTIL/iso_date_to_words $gis_map_date )
sis_cti_date=$( $UTIL/iso_date_to_words $sis_cti_date )

echo "<H2>Processing Information</H2>"                               >>$header
echo "<UL>"                                                          >>$header
echo "  <LI><STRONG>Sequence Version:</STRONG> $seqver"              >>$header
echo "  <LI><STRONG>Processing Version:</STRONG> $procver"           >>$header
echo "  $rev"                                                        >>$header
echo "  <LI><STRONG>FTOOLS Version:</STRONG> $ftools"                >>$header
echo "  <LI><STRONG>Processing Date:</STRONG> $(date +'%B %e, %Y')"  >>$header
echo "  <LI><STRONG>GIS Secular Gain Calibration Date:</STRONG> $gis_temp_date"\
                                                                     >>$header

echo "  <LI><STRONG>GIS Gain Map Calibration Date:</STRONG> $gis_map_date"\
                                                                     >>$header

echo "  <LI><STRONG>SIS CTI Calibration Date:</STRONG> $sis_cti_date"\
                                                                     >>$header

echo "</UL>"                                                         >>$header


########
# US PI
########
echo "<H2>US Principal Investigator</H2>"                            >>$header
for param in uspiname \
            uspiaddr1 uspiaddr2 uspiaddr3 uspiaddr4 uspiaddr5 \
             uspiemail; do

    line=$($UTIL/read_parfile $JOBPAR $param)
    if [ -n "$line" ]; then
        echo "$line <BR>"                                            >>$header
    fi

done

##############
# Japanese PI
##############
echo "<H2>Japan Principal Investigator</H2>"                         >>$header
for param in jppiname \
             jppiaddr1 jppiaddr2 jppiaddr3 jppiaddr4 jppiaddr5 \
             jppiemail; do

    line=$($UTIL/read_parfile $JOBPAR $param)
    if [ -n "$line" ]; then
        echo "$line <BR>"                                            >>$header
    fi

done

##########
# Closing
##########
echo "</BODY>"                                                       >>$header
echo "</HTML>"                                                       >>$header


exit 0