#!/bin/csh 
#------------------------------------------------------------------------
#                          REVISION HISTORY                             -
#                                                                       -
#------------------------------------------------------------------------
#  MOD            PR                                                    -
# LEVEL   DATE   NUMBER  USER     DESCRIPTION
# ----- -------- ------  -------  ------------------------------------  -
#  000  10/25/01 43967   J.Baum  Initial version 
#  001  10/11/02 46773   J.Baum  Remove -x option 
#  002  04/26/03 47061   J.Baum  Add check for INDEX_EXT and delete index
#                                and fix comment typos
#------------------------------------------------------------------------
#
# Module:	eng_delete.csh
#
#------------------------------------------------------------------------
# DESCRIPTION:
#
#  This script deletes a file based on three variables $INPATH, $OSF_DATASET,
#  $EXTENSION, and optionally INDEX_EXT. If the INPATH is invalid, the
#  process will go absent. If no file exists a warning message is generated but
#  the process returns a success status. If the file exists but it cannot be
#  deleted a failure status is returned. The non-existence, failure or success
#  is logged.
#
#*********************************************************************
#
set go_absent=102          #this exit status is in the FATAL range for XPOLL
set return_success=0       #completed or no file
set return_failure=1       #cannot delete file
#
# Validate INPATH
if (!(-d $INPATH)) then
   echo -n `\date +"%Y%j%H%M%S"`
   echo "-F-FATAL ERROR: invalid directory - $INPATH"
   exit $go_absent
endif
#
# Validate file
set file_spec = $INPATH/$OSF_DATASET$EXTENSION
if (!(-e $file_spec)) then
   echo -n `\date +"%Y%j%H%M%S"`
   echo "-W-WARNING: file not found - $file_spec"
   exit $return_success
endif
rm $file_spec
if (-e $file_spec) then
   echo -n `\date +"%Y%j%H%M%S"`
   echo "-E-ERROR: cannot delete $file_spec"
   exit $return_failure
else
   echo -n `\date +"%Y%j%H%M%S"`
   echo "-I-SUCCESS: deleted $file_spec"
endif
#
# Check for index file to be deleted also
if ($?INDEX_EXT) then
   set file_spec = $INPATH/$OSF_DATASET$INDEX_EXT
   if (!(-e $file_spec)) then
      echo -n `\date +"%Y%j%H%M%S"`
      echo "-W-WARNING: file not found - $file_spec"
      exit $return_success
   endif
   rm $file_spec
   if (-e $file_spec) then
      echo -n `\date +"%Y%j%H%M%S"`
      echo "-E-ERROR: cannot delete $file_spec"
      exit $return_failure
   else
      echo -n `\date +"%Y%j%H%M%S"`
      echo "-I-SUCCESS: deleted $file_spec"
   endif
endif
exit $return_success
