      subroutine bupdate(nwater,Hpst)

c  Performs updating of biological particles, uses mid-point
c  leap frog method.

#include "gloparam.F.h"
#include "ostate.F.h"
#include "ogrid.F.h"
#include "definebio.h"
#include "combarr.h"
      real        TIMEFAC   ! Time filtering coefficient
      parameter ( TIMEFAC = 0.05 )
      real Hpst(len,km)

c  Loop to update
c   indexes are mixed because new H has already been computed
c   in update.F, but P has not been updated yet
      m1 = indext1
      m2 = indext2
      do n = 1,ntyp
       do k = 1,km
        do i = 1,nwater
c               "past" P     "past" H
         Pnew = (P(i,k,m2,n)*Hpst(i,k) 
     *          + P_tend(i,k,n)*Area_h_r(i)*c2dt)/H(i,k,m2)
c                                                 "future" H
c        "present" P 
         P(i,k,m1,n) = P(i,k,m1,n)*(1.0-TIMEFAC)
     *                 + (P(i,k,m2,n) + Pnew)*TIMEFAC*0.5
c                       "past" P       "future" P
         P(i,k,m2,n) = Pnew
        enddo
       enddo
      enddo


#if SPINUP
c  Reset all to lower limit if 0
c      do n = 1,ntyp
c       do k = 1,km
c        do i = 1,nwater
c         P(i,k,m2,n) = max(P(i,k,m2,n),0.0)
c        enddo
c       enddo
c      enddo
c  Reset diatoms to lower limit to make sure Si is being used up
      do k = 1,km-4
       do i = 1,nwater
        P(i,k,m2,nnut+1) = max(P(i,k,m2,nnut+1),0.001)
       enddo
      enddo
#endif

      return
      end
