#!/bin/sh
. ./dot_env
mylock $sixdeskstudy
###mylock $sixdeskwork
while read task
do
  problem=""
  Runnam=`echo $task | cut -d " " -f1`
  myrundir $Runnam Rundir
  taskid=`echo $task | cut -d " " -f2`
  grep '^'$Runnam'$' $sixdeskwork/completed_cases > /dev/null
  if test $? -eq 0
  then
    grep '^'$Runnam'$' $sixdeskwork/incomplete_cases > /dev/null
    if test $? -eq 0
    then
      if test "$problem" = ""
      then
        problem="yes"
        echo " "
        echo " Problem with $Runnam $Rundir $taskid"
        echo " "
      fi
      echo "$Runnam $Rundir $taskid in BOTH"
    fi
  fi
  if test -s "$sixdesktrack/$Rundir/fort.10.gz"
  then
    grep '^'$Runnam'$' $sixdeskwork/completed_cases > /dev/null
    if test $? -ne 0
    then
      if test "$problem" = ""
      then
        problem="yes"
        echo " "
        echo " Problem with $Runnam $Rundir $taskid"
        echo " "
      fi
      echo "$Runnam $Rundir $taskid is COMPLETE but NOT in completed_cases"
    fi
    grep '^'$Runnam'$' $sixdeskwork/incomplete_cases > /dev/null
    if test $? -eq 0
    then
      if test "$problem" = ""
      then
        problem="yes"
        echo " "
        echo " Problem with $Runnam $Rundir $taskid"
        echo " "
      fi
      echo "$Runnam $Rundir $taskid completed but IS IN incomplete_cases"
    fi
  else
    grep '^'$Runnam'$' $sixdeskwork/completed_cases > /dev/null
    if test $? -eq 0
    then
      if test "$problem" = ""
      then
        problem="yes"
        echo " "
        echo " Problem with $Runnam $Rundir $taskid"
        echo " "
      fi
      echo "$Runnam $Rundir $taskid is INCOMPLETE but in completed_cases"
    fi
    grep '^'$Runnam'$' $sixdeskwork/incomplete_cases > /dev/null
    if test $? -ne 0
    then
      if test "$problem" = ""
      then
        problem="yes"
        echo " "
        echo " Problem with $Runnam $Rundir $taskid"
        echo " "
      fi
      echo "$Runnam $Rundir $taskid IS incomplete but NOT in incomplete_cases"
    fi
  fi  
done < work/taskids
###myunlock $sixdeskwork
myunlock $sixdeskstudy
