eventinfo (version 2.6)

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

###########################################################################
#
# SYNTAX: eventinfo
#
# BRIEFLY: Create a descriptive list of all of the event files.
#
# DESCRIPTION: This routine creates an HTML page giving detailed
# DESCRIPTION: information about the event files.
# DESCRIPTION: The files are sorted by instrument, mode and bit-rate.
# DESCRIPTION: The following information is given for each file:
# DESCRIPTION: <UL>
# DESCRIPTION: <LI> Exposure (not dead-time corrected)
# DESCRIPTION: <LI> Counts
# DESCRIPTION: <LI> Count rate
# DESCRIPTION: <LI> A list of modal keyword values. All keywords
# DESCRIPTION:      whose values change within a particular
# DESCRIPTION:      mode/bitrate group are listed.
# DESCRIPTION: </UL>
#
# VERSION: 2.6
#
# HISTORY: 0.0 -> 1.0 9/23/96
# HISTORY: Now includes TLM_FILE among the unique keywords to be listed.
# HISTORY:
# HISTORY: 1.0 -> 1.1 1/3/97
# HISTORY: Now records total exposure times and number events in the job par.
# HISTORY:
# HISTORY: 1.1 -> 1.2 2/4/97
# HISTORY: Added quotes to add_parameter arguments.
# HISTORY: Converted from floatint and floatdiv STOOLS to equals.
# HISTORY:
# HISTORY: 1.2 -> 1.3 3/18/97
# HISTORY: Added a check for consistency between evt time and isas_time.
# HISTORY:
# HISTORY: 1.3 -> 1.4 4/22/97
# HISTORY: Added ORIGMODE to the unique SIS keywords.
# HISTORY:
# HISTORY: 1.4 -> 1.5 5/9/97
# HISTORY: Now reports all times in kiloseconds.
# HISTORY:
# HISTORY: 1.5 -> 1.6 5/13/97
# HISTORY: Supplied missing parenthesis when calculating kunftime and kevttime.
# HISTORY:
# HISTORY: 1.6 -> 2.0 7/8/97
# HISTORY: Rewrote the script to use the get_uniq_keys STOOL instead of
# HISTORY: reading all of the keywords in the script. Also, rearranged things
# HISTORY: so that the times and events in each event file are read only
# HISTORY: once. All this should make this subroutine run much faster.
# HISTORY: The only noticable difference in the output is that the keywords
# HISTORY: listed will also give the Comments in the FITS header for each
# HISTORY: keyword.
# HISTORY: Also reformatted the keyword list as an HTML table.
# HISTORY:
# HISTORY: 2.0 -> 2.1 9/16/97
# HISTORY: Added "nowrap" to keyword table comment column.
# HISTORY: Also fixed a bug that wasn't reporting the totalled events or rates
# HISTORY: properly ("tot" was not prefixed to the variable names).
# HISTORY:
# HISTORY: 2.1 -> 2.2 9/25/97
# HISTORY: Made more silent when there are no .unf files for a given
# HISTORY: instrument.
# HISTORY:
# HISTORY: 2.2 -> 2.3 12/29/97
# HISTORY: Fixed the syntax of several exception calls.
# HISTORY:
# HISTORY: 2.3 -> 2.4 2/26/98
# HISTORY: Now compares sis evt time with unsaturated ISAS time instead of
# HISTORY: sis_isas_time.
# HISTORY: Also, now rounds count rates to the nearest thousandth.
# HISTORY:
# HISTORY: 2.4 -> 2.5 4/8/98
# HISTORY: Now missing time warnings are only given if the "ISAS time" is
# HISTORY: greater than 10 kiloseconds
# HISTORY:
# HISTORY: 2.5 -> 2.6 1998-08-25
# HISTORY: Eliminated "double rounding" of total exposure times where they
# HISTORY: were rounded first to the nearest second and then to the nearest
# HISTORY: kilosecond.
#
###########################################################################
#DEBUG=1

$UTIL/milestone "Generating event file information page"

evttimetoll=$($UTIL/read_parfile $PARFILE evttimetoll)

eventinfo=$($UTIL/generate_filename eventinfo)
header=$(   $UTIL/generate_filename header   )

##############
# Title, etc.
##############
seq=$($UTIL/read_parfile $JOBPAR sequence)

rm -f $eventinfo
echo "<HTML>"                                                     >>$eventinfo
echo "<!-- This page generated by $0 on $(date) -->"              >>$eventinfo
echo "<HEAD>"                                                     >>$eventinfo
echo "<TITLE>ASCA Sequence $seq Event File Info</TITLE>"          >>$eventinfo
echo "</HEAD>"                                                    >>$eventinfo
echo "<BODY>"                                                     >>$eventinfo
echo "<H1>ASCA Sequence $seq Event File Info</H1>"                >>$eventinfo

echo "This page lists the filtered and"                           >>$eventinfo
echo "unfiltered event files sorted by instrument and mode."      >>$eventinfo
echo "Exposure times (not dead time corrected) and count rates"   >>$eventinfo
echo "are given for each file along with a list of FITS keywords" >>$eventinfo
echo "describing the observation mode."                           >>$eventinfo
echo "Where two values are separated by a slash, the first value" >>$eventinfo
echo "refers to the filtered event file and the"                  >>$eventinfo
echo "second to the corresponding unfiltered file."               >>$eventinfo
echo "<P>"                                                        >>$eventinfo

echo "The following information is also available:"               >>$eventinfo
echo "<UL>"                                                       >>$eventinfo
echo "  <LI><STRONG><A HREF=\"${header}\">The processing header" \
     "page</A></STRONG>"                                          >>$eventinfo
echo "</UL>"                                                      >>$eventinfo

echo "Here is in index of the event files for each instrument:"   >>$eventinfo
echo "<UL>"                                                       >>$eventinfo
echo "  <LI><A HREF=\"#s0\">SIS 0</A>"                            >>$eventinfo
echo "  <LI><A HREF=\"#s1\">SIS 1</A>"                            >>$eventinfo
echo "  <LI><A HREF=\"#g2\">GIS 2</A>"                            >>$eventinfo
echo "  <LI><A HREF=\"#g3\">GIS 3</A>"                            >>$eventinfo
echo "</UL>"                                                      >>$eventinfo


######################
# Group by instrument
######################
for inst in s0 s1 g2 g3; do

    $UTIL/log_entry "Summing time and events for $inst event files"

    case "$inst" in
    s?)
        ######
        # SIS
        ######
        display=SIS${inst#s}
        modes="02 12 01 03"
        ;;
    g?)
        ######
        # GIS
        ######
        display=GIS${inst#g}
        modes="70 71"
        ;;
    *) $UTIL/exception $0 1 "Unknown instrument $inst";;
    esac


    ############################
    # Initialize totals to zero
    ############################
    totunfevents=0
    totevtevents=0

    totunftime=0.
    totevttime=0.

    totunffiles=0
    totevtfiles=0


    ###################
    # Individual files
    ###################

    ##################################
    # Loop through modes and bitrates
    ##################################
    rm -f info.tmp

    for mode in $modes; do

        ########################
        # Display name for mode
        ########################
        case "$mode" in
        01) modename="FAINT";;
        02) modename="BRIGHT";;
        12) modename="BRIGHT2";;
        03) modename="FAST";;
        70) modename="PH";;
        71) modename="MPC";;
        *) $UTIL/exception $0 1 "Unknown mode $mode";;
        esac

        for bitrate in h m l; do

            ###########################
            # Display name for bitrate
            ###########################
            case "$bitrate" in
            h) ratename="HIGH";;
            m) ratename="MEDIUM";;
            l) ratename="LOW";;
            *) $UTIL/exception $0 1 "Unknown bitrate $bitrate";;
            esac

            #####################################
            # Get a list of the unfiltered files
            #####################################
            list=$($UTIL/generate_filename unfiltered \
                                           $inst any $mode $bitrate)

            rm -f files.tmp
            ls $list >files.tmp 2>/dev/null

            ###############################################################
            # If no files for this mode and bitrate just go on to the next
            ###############################################################
            if [ ! -s files.tmp ]; then
                rm -f files.tmp
                continue
            fi
            ##########
            # Heading
            ##########
            echo "<H3>${display} $modename mode event files" >>info.tmp
            echo "with $ratename bit rate</H3>"              >>info.tmp
            echo "<UL>"                                      >>info.tmp

            ######################################
            # Determine which keywords are unique
            ######################################
            $STOOL/get_uniq_keys files.tmp $LISTS/${inst%?}is_unique_keys \
                                 >stdout.log 2>stderr.log
            code=$?
            rm -f key.tmp
            cp stdout.log key.tmp
            $UTIL/stool_test get_uniq_keys $code $0 2 stdout.log stderr.log

            ############################
            # List the individual files
            ############################
            for unfiltered in $(cat files.tmp); do

                $UTIL/log_entry "listing $unfiltered"

                ##############################
                # Corresponding filtered file
                ##############################
                index=$($UTIL/parse_filename index $unfiltered)
                filtered=$($UTIL/generate_filename event \
                                                   $inst $index $mode $bitrate)

                ############
                # File name
                ############
                if [ -s "$filtered" ]; then
                    echo "  <LI> <TT>${filtered}</TT> /" \
                         "<TT>$unfiltered</TT>"           >>info.tmp
                else
                    echo "  <LI> <TT>$unfiltered</TT>"    >>info.tmp
                fi

                echo "<UL>"                                >>info.tmp

                ###################
                # Times and events
                ###################

                #############
                # Unfiltered
                #############
                unfevents=$($UTIL/read_fits_keyword $unfiltered[0] NEVENTS)
                unftime=$(  $UTIL/read_fits_keyword $unfiltered[0] ONTIME )

                if [ "$mode" != "01" -a "$mode" != "12" ]; then
                    ###############################################
                    # Don't sum over FAINT or BRIGHT2 mode files,
                    # to avoid double-counting the FAINT -> BRIGHT
                    # converted files
                    ###############################################
                    let totunfevents=$totunfevents+$unfevents
                    totunftime=$($STOOL/equals "$totunftime + $unftime")
                    let totunffiles=$totunffiles+1
                fi

                ###########
                # Filtered
                ###########
                evtevents=0
                evttime=0.
                if [ -s $filtered ]; then
                    ########################################################
                    # filtered file exists and has something in it
                    ########################################################
                    evtevents=$($UTIL/read_fits_keyword $filtered[0] NEVENTS)
                    evttime=$(  $UTIL/read_fits_keyword $filtered[0] ONTIME )

                    if [ "$mode" != "01" -a "$mode" != "12" ]; then
                        ###############################################
                        # Don't sum over FAINT or BRIGHT2 mode files,
                        # to avoid double-counting the FAINT -> BRIGHT
                        # converted files
                        ###############################################
                        let totevtevents=$totevtevents+$evtevents
                        totevttime=$($STOOL/equals "$totevttime+$evttime")
                        let totevtfiles=$totevtfiles+1
                    fi
                fi

                unfrate=$($STOOL/equals "int($unfevents/$unftime*1000+.5)/1000")
                evtrate=$($STOOL/equals "int($evtevents/$evttime*1000+.5)/1000")

                kevttime=$($STOOL/equals "int($evttime/100+.5)/10")
                kunftime=$($STOOL/equals "int($unftime/100+.5)/10")


                echo "  <LI><STRONG>Exposure:</STRONG>"          >>info.tmp
                echo "  ${kevttime} / ${kunftime} kiloseconds"   >>info.tmp

                echo "  <LI><STRONG>Events:</STRONG> "           >>info.tmp
                echo "  ${evtevents} / ${unfevents} events"      >>info.tmp

                echo "  <LI><STRONG>Count Rate:</STRONG>"        >>info.tmp
                echo "  ${evtrate} / ${unfrate} events per second" \
                                                                 >>info.tmp

                ###########
                # Keywords
                ###########
                echo "  <LI><STRONG>Selected FITS Keywords:</STRONG>" \
                                                                 >>info.tmp

                echo "  <TABLE>"                                 >>info.tmp

                awk -F'|' '$1 == word \
             {print "  <TR><TD>"$2"=</TD><TD>"$3"</TD><TD NOWRAP>/ "$4"</TD><TR>"}'\
                word=$unfiltered key.tmp       >>info.tmp

                echo "  </TABLE>"                                >>info.tmp

                ########################################
                # Close list of bullets describing file
                ########################################
                echo "  </UL><P>" >>info.tmp

            done ;# file loop

            #################################################
            # End of list of files for this mode and bitrate
            #################################################
            echo "</UL>" >>info.tmp

            rm -f files.tmp
            rm -f key.tmp

        done ;# bitrate loop

    done ;# mode loop

    ###############################################
    # Print header information for this instrument
    ###############################################
    round_totevttime=$($STOOL/equals "int($totevttime +.5)")
    round_totunftime=$($STOOL/equals "int($totunftime +.5)")

    totunfrate=$($STOOL/equals "int($totunfevents/$totunftime*1000+.5)/1000")
    totevtrate=$($STOOL/equals "int($totevtevents/$totevttime*1000+.5)/1000")

    ############################
    # Record totals in par file
    ############################
    $UTIL/add_parameter $JOBPAR ${inst}unftime "$round_totunftime" r \
                        "total exposure in $inst unfiltered event files"
    $UTIL/add_parameter $JOBPAR ${inst}evttime "$round_totevttime" r \
                        "total exposure in $inst filtered event files"

    $UTIL/add_parameter $JOBPAR ${inst}unfevents "$totunfevents" r \
                        "total events in $inst unfiltered event files"
    $UTIL/add_parameter $JOBPAR ${inst}evtevents "$totevtevents" r \
                        "total events in $inst filtered event files"

    ########################################
    # Check for consistency with ISAS times
    ########################################
    case "$inst" in
    g[23]) isas_time=$($UTIL/read_parfile $JOBPAR gis_isas_time);;
    s[01]) isas_time=$($UTIL/read_parfile $JOBPAR unsat_isas_time);;
    esac

    err=$($STOOL/equals "($totevttime - $isas_time)/$isas_time ")
    if [ $($STOOL/floatcmp $err $evttimetoll) = "lt" -a \
         $($STOOL/floatcmp $isas_time 10000.) = "gt" ]; then

        per=$($STOOL/equals "int(.5 - $err*100)")
        $UTIL/exception $0 2 \
                      "Filtered $display exposure is ${per}% less than nominal"
        $UTIL/find_missing_time $inst
    fi

    ###############################
    # Convert times to kiloseconds
    ###############################
    kunftime=$($STOOL/equals "int($totunftime /100 +.5)/10")
    kevttime=$($STOOL/equals "int($totevttime /100 +.5)/10")

    echo "<HR>"                                                   >>$eventinfo
    echo "<H2><A NAME=\"$inst\">${display}:</A></H2>"             >>$eventinfo
    echo "<STRONG>Total Exposure:</STRONG>"                       >>$eventinfo
    echo "${kevttime} / ${kunftime} kiloseconds<BR>"              >>$eventinfo

    echo "<STRONG>Total Events:</STRONG>"                         >>$eventinfo
    echo "${totevtevents} / ${totunfevents} events<BR>"           >>$eventinfo

    echo "<STRONG>Mean Count Rate:</STRONG>"                      >>$eventinfo
    echo "${totevtrate} / ${totunfrate} events per second<BR>"    >>$eventinfo

    echo "<STRONG>Number of Files:</STRONG>"                      >>$eventinfo
    echo "${totevtfiles} / ${totunffiles} "                       >>$eventinfo


    ##########################################################################
    # Dump all of the HTML stuff in info.tmp which lists the individual files
    ##########################################################################
    if [ -s info.tmp ]; then
        cat info.tmp >>$eventinfo
    fi
    rm -f info.tmp

done #; inst loop

echo "</BODY>" >>$eventinfo
echo "</HTML>" >>$eventinfo


exit 0