#!/bin/csh 
#------------------------------------------------------------------------
#                          REVISION HISTORY                             -
#                                                                       -
#------------------------------------------------------------------------
#  MOD            PR                                                    -
# LEVEL   DATE   NUMBER  USER     DESCRIPTION
# ----- -------- ------  -------  ------------------------------------  -
#  000  10/11/02 46773   J.Baum  Initial version 
#------------------------------------------------------------------------
#
# Module:	move_file.csh
#
#------------------------------------------------------------------------
# DESCRIPTION:
#
#  This script moves a file based on four variables $INPATH, $OSF_DATASET,
#  $EXTENSION and $MOVE_PATH. These are required variables. If the INPATH or
#  MOVE_PATH is invalid, the process will go absent. If no file exists, then
#  a warning message is generated but the process returns a success status. 
#  If the file exists but it cannot be moved to the MOVE_PATH , then 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 MOVE_PATH
if (!(-d $MOVE_PATH)) then
   echo -n `\date +"%Y%j%H%M%S"`
   echo "-F-FATAL ERROR: invalid directory - $MOVE_PATH"
   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
mv $file_spec $MOVE_PATH
if (-e $file_spec) then
   echo -n `\date +"%Y%j%H%M%S"`
   echo "-E-ERROR: cannot move $file_spec"
   exit $return_failure
else
   echo -n `\date +"%Y%j%H%M%S"`
   echo "-I-SUCCESS: moved $file_spec to $MOVE_PATH"
endif
exit $return_success
