#!/bin/csh -f

#----------------------------------------

if ( $#argv > 1 ) then
  cat << EOF

NAME   

      ccsm_check_lockedfiles - check that any files in the $CASEROOT/LockedFiles directory
      match those in the $CASEROOT directory 
      (assumes that this utility exists in $CASEROOT/Tools)


SYNOPSIS 

      ccsm_check_lockedfiles 

EOF
exit;
endif

./xmlchange -file env_build.xml -id BUILD_STATUS -val 0
foreach i (LockedFiles/*)
   set file = $i:t
   set file = $file:r    
   if !(-f $file) then
     echo "Locked file $file cannot be found"
     exit -1
   endif
   cmp -s $i $file 
   if ($status != 0 ) then
     echo "$i has been modified and is different than the LockedFiles version"
     if ($file =~ *env_build* ) then
         echo "env_build file has changed, setting BUILD_COMPLETE to FALSE"
         ./xmlchange -file env_build.xml -id BUILD_COMPLETE -val FALSE
         ./xmlchange -file env_build.xml -id BUILD_STATUS -val 1
     else if ($file =~ *Macros* ) then
         echo "Macros file has changed, setting BUILD_COMPLETE to FALSE"
         ./xmlchange -file env_build.xml -id BUILD_COMPLETE -val FALSE
         ./xmlchange -file env_build.xml -id BUILD_STATUS -val 1
     else if ($file =~ *env_mach*) then
         echo "Invoke configure -cleanmach followed by a configure -case"
         exit -1
     else if ($file =~ *env_conf* ) then
         echo "Invoke configure -cleannamelist followed by a configure -case"
         exit -1
     else
         echo "Cannot change $file, please recover the original copy from LockedFiles"
         exit -1
     endif
   endif
end
