      subroutine countinun(q,d,inun,numinun,n1,n2,mm,nn,dry)
      implicit none
      integer n1,n2,mm,nn
      real*8 d(mm,nn), q(mm,nn), dry
      integer*4 i,j,inun(mm,nn), numinun
      
      numinun = 0
      do i = 1,n1
        do j = 1,n2
          if (d(i,j) .lt. 0) then
            if ( q(i,j) .ge. dry) then
              inun(i,j) = 1
!              numinun = numinun + 1 ! this line for "every-timestep threshold check"
            endif
          endif
          numinun = numinun + inun(i,j) ! or this line for "run-total threshold check"
        end do
      end do

      return
      end
