      subroutine deriv(n,time,t,f)
      implicit real*8 (a-h,o-y)
      dimension t(n),f(n)

      common /bio/np,mp
      common /bio1/rkout_on,rkout_off,
     &       rkout_min,rkmin,ec50,tau_a,tau_b      
      common /bio2/tstep,sig_height,sig_time

      out = t(1)
      a = t(2)
      b = t(3)
      
      f(1) = rkout_on * (a + b) *(1-out)
     &     -rkout_off*out + rkout_min      

      st = stimu(time)


      feeda = out**np /(out**np + ec50**np)
      feedb = out**mp /(out**mp + ec50**mp)

c      write(2,*) time, st,feeda,feedb



      f(2) = (st * feeda *(1-a) - a + rkmin)* tau_a

      f(3) = (st * feedb *(1-b) - b + rkmin)* tau_b

c      print*, rkout_on,rkout_off,rkout_min,tau_a,tau_b
c      print*, ec50,np,mp
c      stop

      return
      end


      real*8 function stimu(time)
      implicit real*8 (a-h,o-y)

      common /bio/np,mp
      common /bio1/rkout_on,rkout_off,
     &       rkout_min,rkmin,ec50,tau_a,tau_b      
      common /bio2/tstep,sig_height,sig_time

      if ( time.le.tstep.or.time.ge.tstep+sig_time) then
         stimu = 0
      else 
         stimu = sig_height
      endif



      return
      end
