#!/bin/csh
#
# Script to cleanup selected files under path = $1
#
# History 23-Nov-1992
# 	   4-Dec-1992	change argument 2 definition (dont write file)
#
# Calling Sequence:
#	cleanpath.src pathname [fileage]	

#	(optional 2nd parameter:
#	(files not accessed in fileage days are deleted, default=1)
#	(use zero (0) to delete all (Warning, may be active!)
#	(all core files are removed)
#
# The following files are identified and removed:
#	idl plot files		idl.ps 		
#	emacs backup files	,filename,
#	TPU journal files	*.tjl
#	core files		core
#	zero block files	* (where nblocks = 0)
#
if ($#argv == 0) then
   echo No path supplied, exiting
   exit
endif

if (!(-d $1) ) then 
   echo Illegal pathname supplied, exiting
   exit
endif

# argument 2 may contain 
if ($#argv == 2) then 
    set fage=$2
    @ fage = $fage - 1
else
    set fage=1
endif 

echo Checking for emacs files on $1 
set emacs=(`find $1/* -name \,\* -atime +$fage -print`)
if ($#emacs >= 1) then
   echo removing $#emacs emacs files from $1 
   echo $emacs 
   rm -f $emacs
endif

echo Checking for TPU files on $1 
set tpu=(`find $1/* -name \*.tjl -atime +$fage -print`)
if ($#tpu >= 1) then 
   echo removing $#tpu tpu files from $1 
   echo $tpu 
   rm -f $tpu
endif


echo Checking for core files on $1 
set core =(`find $1/* -name core -print`)
if ($#core >= 1) then
   echo removing $#core core files from $1 
   echo $core 
   rm -f $core
endif

echo Checking for idl.ps files on $1 
set idlps=(`find $1/* -name idl.ps -atime +$fage -print`)
if ($#idlps >= 1) then
   echo removing $#idlps idl.ps files from $1 
   echo $idlps 
   rm -f $idlps
endif

echo Checking for 0 block files on $1 
set zerob=(`find $1/* -size 0 -atime +$fage -print`)
if ($#zerob >= 1) then
   echo removing $#zerob zero block files from $1 
   echo $zerob 
   rm -f $zerob
endif
exit
