#!/bin/csh
#
# Run test for shr_file_mod module.
#
#set echo
set cwd = `pwd`
echo "Make test"
setenv GMAKE gmake
if ( `uname -s` == "Darwin" ) setenv GMAKE "make FC=g95"
$GMAKE test_shr_file
if ( $status != 0 )then
   echo "Test failed"
   exit 999
endif
echo "make stdio namelists"
foreach i ( "cpl" "ice" "ocn" )
   cat << EOF > ${i}_stdio.nml
&stdio
 dir    = "$cwd/nl"
 stdout = "${i}.log"
 stdin  = "${i}.stdin"
/
EOF
end
foreach i ( "atm" "lnd" )
   cat << EOF > ${i}_stdio.nml
&stdio
 dir    = "$cwd/nl"
 stdout = "${i}.log"
 nlfile = "${i}.stdin"
/
EOF
end
echo "Softlink namelist files appropriately"
foreach i ( "atm" "lnd" "cpl" "ice" "ocn" )
   \ln -f -s $cwd/{$i}_stdio.nml $cwd/nl/.
end
echo "run test"
test_shr_file
cat test_shr_file.log
if ( $status != 0 )then
   echo "Test failed"
   exit 999
endif
echo "Check test output.."
egrep "<<<<<<<<This should go to the .* stdout file>>>>>>>>>>" test_shr_file.log
if ( $status == 0 )then
   echo "Test failed test_shr_file.log has string expected for model log files""
   exit 999
endif
foreach i ( "atm" "lnd" "cpl" "ice" "ocn" )
   grep "<<<<<<<<This should go to the ${i} stdout file>>>>>>>>>>" nl/${i}.log
   if ( $status != 0 )then
      echo "Test failed $i log does not have expected string"
      exit 999
   endif
end
echo "Test passed"
echo "clean up..."
$GMAKE clean
foreach i ( "atm" "lnd" "cpl" "ice" "ocn" )
   \rm ${i}_stdio.nml nl/${i}.log
end
echo
echo
echo

echo "PASS"
