information (version 1.6)

You can also look at:
#!/usr/bin/ksh
###########################################################################
#
# BRIEFLY: Calculate various pieces of information
#
# SYNTAX: information
#
# DESCRIPTION: This routine calculates various pieces of "meta-data"
# DESCRIPTION: which are intended for web page generation and general
# DESCRIPTION: record-keeping by the ASCA Processing Team.
# DESCRIPTION: The data are recorded in the job parameter file.
#
# VERSION: 1.6
#
# HISTORY: 0.0 -> 1.0 1/22/97
# HISTORY: Changed rm info.tmp to rm -f info.tmp.
# HISTORY:
# HISTORY: 1.0 -> 1.1 5/8/97
# HISTORY: Now stores observation start and stop times and dates in the job.par.
# HISTORY:
# HISTORY: 1.1 -> 1.2 1/12/97
# HISTORY: Added code to record GIS and SIS PI calibration file dates.
# HISTORY:
# HISTORY: 1.2 -> 1.3 2/12/97
# HISTORY: A few minor changes to improve y2k robustness.
# HISTORY: Simplified isas_time code to no longer merge GTIs from multiple
# HISTORY: filter files.
# HISTORY: Also, now calculates the unsaturated ISAS time for the SIS
# HISTORY: so that this number may later be compared with the
# HISTORY: filtered file times to avoid unnecessary error messages.
# HISTORY:
# HISTORY: 1.3 -> 1.4 2/28/97
# HISTORY: Fixed a problem with the unsaturated time calculation,
# HISTORY: where we were copying a criteria file and then appending to it,
# HISTORY: but the file didn't have write permission.
# HISTORY:
# HISTORY: 1.4 -> 1.5 7/10/98
# HISTORY: Changed observation start and end date extraction to use
# HISTORY: $UTIL/read_fits_date.
# HISTORY:
# HISTORY: 1.5 -> 1.6 1998-08-06
# HISTORY: Moved the code which calculated the observation start and end dates
# HISTORY: and times to $SUBS/telemetry.
# HISTORY: Also now read calibration file time stamps in ascatime and then
# HISTORY: convert to a date in order to be robustly y2k compliant
#
###########################################################################
#DEBUG=1

$UTIL/milestone "Determining information about this observation"


##################
# Processing date
##################
$UTIL/add_parameter $JOBPAR procdate $(date +'%Y-%m-%d') s "Date processed"

############################
# Processing script version
############################
version=$($UTIL/read_parfile $PARFILE version)
$UTIL/add_parameter $JOBPAR procscriptver $version s "Processing script version"

###########
# Duration
###########
duration=0.0
for file in $(ls ft*[0-9] 2>/dev/null); do

    mtime0=$($UTIL/read_fits_keyword $file[1] MTIME0)
    mtime1=$($UTIL/read_fits_keyword $file[1] MTIME1)
    duration=$($STOOL/equals "$mtime1 - $mtime0 + $duration")

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

done

$UTIL/add_parameter $JOBPAR duration $duration r \
                    "Total observation duration in seconds"

#################################################################
# ISAS exposure times.
# These are the times used by ISAS
# as criteria for whether an observation is complete or not.
# This code was adapted from a ksh script written by Koji Mukai.
#################################################################
for inst in sis gis; do

    $UTIL/log_entry "Calculating ISAS time for $inst"

    typeset -i i=1;
    time=0.
    unsat_time=0.
    for filter in $(ls *.mkf 2>/dev/null); do

        gti=gti.tmp
        rm -f $gti

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

        $UTIL/setup_parfile $FTOOL/maketime.par             \
                            infile=${filter}                \
                            outfile=${gti}                  \
                            expr="@$LISTS/${inst}_isas.cri" \
                            name=NAME                       \
                            value=VALUE                     \
                            time=TIME                       \
                            start=START                     \
                            stop=STOP                       \
                            compact=no                      \
                            histkw=yes

        $FTOOL/maketime >stdout.log 2>stderr.log
        $UTIL/ftool_test maketime $? $0 2 stdout.log stderr.log

        this_time=$($STOOL/compute_exposure ${gti}[1])
        time=$($STOOL/equals $time + $this_time)

        case "$inst" in
        sis)
            ######################################################
            # For SIS, calculate the unsaturated telemetry time
            # this is used later when comparing with the filtered
            # time to avoid all those unnecessary errors
            #######################################################
            rm -f criteria.tmp
            cat  $LISTS/sis_isas.cri > criteria.tmp

            echo "&& S0_SATF0!=1 && S0_SATF1!=1" >>criteria.tmp
            echo "&& S0_SATF2!=1 && S0_SATF3!=1" >>criteria.tmp
            echo "&& S1_SATF0!=1 && S1_SATF1!=1" >>criteria.tmp
            echo "&& S1_SATF2!=1 && S1_SATF3!=1" >>criteria.tmp

            rm -f $gti
            $UTIL/setup_parfile $FTOOL/maketime.par          \
                                infile=${filter}             \
                                outfile=${gti}               \
                                expr="@criteria.tmp"         \
                                name=NAME                    \
                                value=VALUE                  \
                                time=TIME                    \
                                start=START                  \
                                stop=STOP                    \
                                compact=no                   \
                                histkw=yes

            $FTOOL/maketime >stdout.log 2>stderr.log
            $UTIL/ftool_test maketime $? $0 2 stdout.log stderr.log

            this_unsat_time=$($STOOL/compute_exposure ${gti}[1])
            unsat_time=$($STOOL/equals $unsat_time + $this_unsat_time)

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

            rm -f criteria.tmp
            ;;
        esac

        rm -f $gti

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

        let i=$i+1

    done


    #########################
    # Record time in job par
    #########################
    $UTIL/add_parameter $JOBPAR ${inst}_isas_time "$time" r \
                        "$inst exposure time as calculated by ISAS"

    case "$inst" in
    sis)
        ##################################
        # Record unsaturated time for SIS
        ##################################
        $UTIL/add_parameter $JOBPAR unsat_isas_time "$unsat_time" r \
                     "unsaturated SIS exposure time as calc. by ISAS"
        ;;
    esac

done

######################################
# Stop dates for PI calibration files
######################################
$UTIL/log_entry "Recording dates of PI calibration files"

temp2gain=$($UTIL/read_parfile $PARFILE gainhist)
if [ -a "$temp2gain" ]; then
    #############################################
    # GIS temperature (overall gain) variability
    #############################################
    naxis2=$($UTIL/read_fits_keyword $temp2gain[1] NAXIS2)
    stop=$($UTIL/read_bintable $temp2gain[1] STOP $naxis2)
    $UTIL/date_from_ascatime $stop | read stop dum

    $UTIL/add_parameter $JOBPAR "gis_temp_date" "$stop" s \
                        "GIS temperature gain calibration file date"

    ##########################
    # GIS gain map variations
    ##########################
    naxis2=$($UTIL/read_fits_keyword $temp2gain[2] NAXIS2)
    stop=$($UTIL/read_bintable $temp2gain[2] STOP $naxis2)
    $UTIL/date_from_ascatime $stop | read stop dum

    $UTIL/add_parameter $JOBPAR "gis_map_date" "$stop" s \
                        "GIS gain map calibration file date"
else
    #######################################################
    # Calibration file doesn't exist so enter dummy values
    #######################################################
    $UTIL/add_parameter $JOBPAR "gis_temp_date" "0000-00-00" s \
                        "GIS temperature gain calibration file date"

    $UTIL/add_parameter $JOBPAR "gis_map_date" "0000-00-00" s \
                        "GIS gain map calibration file date"
fi

########################################
# SIS CTI (ph2pi) calibration file date
########################################
sispical=$($UTIL/read_parfile $PARFILE sispical)
if [ -a "$sispical" ]; then
    ###############################################################
    # File exists.
    # Take the second to last line, since the last line is a dummy
    # extrapolated into the future.
    ###############################################################
    naxis2=$($UTIL/read_fits_keyword $sispical[1] NAXIS2)
    let naxis2=$naxis2-1
    time=$($UTIL/read_bintable $sispical[1] TIME $naxis2)
    $UTIL/date_from_ascatime $time | read date dum

    $UTIL/add_parameter $JOBPAR "sis_cti_date" "$date" s \
                        "SIS CTI calibration file date"
else
    ##############################################
    # Cal file does not exist, so use dummy value
    ##############################################
    $UTIL/add_parameter $JOBPAR "sis_cti_date" "0000-00-00" s \
                        "SIS CTI calibration file date"
fi


exit 0