process (version 3.2)

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

##############################################################################
#
# SYNTAX: process
#
# BRIEFLY: Set up for processing and call the subroutines which process the data
#
# DESCRIPTION: This is the top level routine for the processing script.
# DESCRIPTION: It sources the setup script, opens and closes the log files,
# DESCRIPTION: and calls a number of subroutines to do the actual processing.
#
# VERSION: 3.2
#
# HISTORY: 0.0 -> 1.0 9/11/96
# HISTORY: Added images subroutine.
# HISTORY:
# HISTORY: 1.0 -> 1.1 9/27/96
# HISTORY: Added sources subroutine.
# HISTORY:
# HISTORY: 1.1 -> 1.2 10/8/96
# HISTORY: Added spectra subroutine.
# HISTORY:
# HISTORY: 1.2 -> 1.3 11/25/96
# HISTORY: Added lightcurves subroutine,
# HISTORY: 12/4/96 but commented it out pending further debugging.
# HISTORY: 12/9/96 Moved rev1trend to before filelists.
# HISTORY:
# HISTORY: 1.3 -> 1.4 12/30/96
# HISTORY: Uncommented lightcurves subroutine and added the information
# HISTORY: subroutine.
# HISTORY: 1/2/97 Added sourceevents subroutine.
# HISTORY: 1/3/97 Moved eventinfo to before header subroutine.
# HISTORY:
# HISTORY: 1.4 -> 1.5 2/7/97
# HISTORY: Added sourceinfo routine.
# HISTORY:
# HISTORY: 1.5 -> 1.6 2/25/97
# HISTORY: Added calsource routine.
# HISTORY:
# HISTORY: 1.6 -> 1.7 4/17/97
# HISTORY: Added earthevents routine.
# HISTORY:
# HISTORY: 1.7 -> 1.8 5/16/97
# HISTORY: Changed WHERE_THE_PARFILE_LIVES to PROCTOP.
# HISTORY:
# HISTORY: 1.8 -> 2.0 6/18/97
# HISTORY: Deleted rev1products and rev1trend subroutines for the change
# HISTORY: to rev2.
# HISTORY:
# HISTORY: 2.0 -> 3.0 10/10/97
# HISTORY: Now captures the stdout and stderr from each subroutine and send
# HISTORY: it to the log. This should  make debugging stray error messages
# HISTORY: much easier.
# HISTORY:
# HISTORY: 3.0 -> 3.1 12/15/97
# HISTORY: Added a fatal error flag to the job par.
# HISTORY:
# HISTORY: 3.1 -> 3.2 1/6/98
# HISTORY: Added a call to framedata.
# HISTORY: Added call to clean, but commented it out due to concerns
# HISTORY: about producing these files.
# HISTORY:
# HISTORY: 3.2 -> 3.3 1999-06-28
# HISTORY: Moved code to initialize error counting parameters to clear_logs.
# HISTORY: Modified to use $UTIL/run_subroutine.
# HISTORY:
# HISTORY: 3.3 -> 3.4 1999-07-16
# HISTORY: Added soft_quit signal handler for USR1 signal.
# HISTORY:
#
##############################################################################

trap "soft_quit" USR1

function soft_quit
{
    ###############################################################
    # Clear the command parameter, and set the "stopped" parameter
    ###############################################################
    $UTIL/set_parameter $JOBPAR proc_command ""
    $UTIL/set_parameter $JOBPAR stopped yes
    $UTIL/milestone "Processing suspended"
    exit 0
}



##############################
#############################
##
## Setup
##
##############################
##############################

PROCTOP=${0%/*}
if [ "$PROCTOP" = "$0" ]; then
    PROCTOP=$(which $0)
    PROCTOP=${0%/*}
fi

SETUP_SCRIPT=$PROCTOP/processing_setup

###################################
# Set things from the command line
###################################
WORKING_DIRECTORY=$1

#####################################################################
# Check the working directory and set it to the current directory if
# one isn't currently defined
#####################################################################
if [ -z "$WORKING_DIRECTORY" ]; then
    WORKING_DIRECTORY="."
fi

if [ ! -d "$WORKING_DIRECTORY" ]; then
    echo "Working directory $WORKING_DIRECTORY is not a directory at all."
    exit 3
fi

##############################
# Go to the working directory
##############################
cd $WORKING_DIRECTORY
if [ $? -ne 0 ]; then
    ##############
    # Didn't work
    ##############
    echo "Processing can\'t go to working directory: $WORKING_DIRECTORY"
    exit 3
fi


########################################################################
# Source the setup script to set the environment variables, path, etc.
########################################################################
. $SETUP_SCRIPT

##############################
# Check if this is a restart
##############################
stopped=$($FTOOL/pget ./$JOBPAR stopped 2>/dev/null)
if [ "$stopped" != "yes" ]; then
    #########################################
    # This is not a restart, so we
    # have to do a few initialization things
    #########################################
    $UTIL/clear_logs
    $UTIL/milestone "Processing started"

    $UTIL/add_parameter $JOBPAR proc_command "" s "Processing command signal"
    $UTIL/add_parameter $JOBPAR stopped no b "Was a job stopped in the middle"
    $UTIL/add_parameter $JOBPAR lastdone "" s "Last action performed"

fi

#########################################
#########################################
##
##  Start Processing
##
#########################################
#########################################

##################################################################
# Fetch, decompress and check telemetry attitude, and orbit files
##################################################################
$UTIL/run_subroutine telemetry
$UTIL/run_subroutine aspecting

#################################
# Create unfiltered  event files
#################################
$UTIL/run_subroutine readfrfs
$UTIL/run_subroutine combine
$UTIL/run_subroutine faint2bright
$UTIL/run_subroutine linearize
$UTIL/run_subroutine fixthings

##################################
# Create the filtered event files
##################################
$UTIL/run_subroutine makefilters
$UTIL/run_subroutine screen

########################
# Extract data products
########################
$UTIL/run_subroutine images
$UTIL/run_subroutine sources
$UTIL/run_subroutine spectra
$UTIL/run_subroutine lightcurves
$UTIL/run_subroutine sourceevents

#########################
# Extract trend products
#########################
$UTIL/run_subroutine framedata
$UTIL/run_subroutine calsource
$UTIL/run_subroutine earthevents

#############################################
# Create bookkeeping and documentation files
#############################################
$UTIL/run_subroutine information
$UTIL/run_subroutine eventinfo
$UTIL/run_subroutine header
$UTIL/run_subroutine sourceinfo
$UTIL/run_subroutine filelists


############
# Finish up
############
$UTIL/run_subroutine wrapup

$UTIL/close_logs

exit 0