      subroutine c4leafanetmodel(ilimittype,aPPFDlf,templeaf,pco2i,
     &pres_air,vcmax25,c4aparslope,c4kp25,rdlight25,anet_pred,
     &Postiphotolimit)
      implicit none
!------------ Inputs -------------------
!ilimittype=1: Rubisco,RuBp and TPU limitations
!ilimittype=2: Rubisco and RuBp limitations only
!ilimittype=3: Rubisco and TPU limitations only
!ilimittype=4: RuBp and TPU limitations only
!ilimittype=5: Rubisco limitation only
!ilimittype=6: RuBp limitation only
!ilimittype=7: TPU limitation only
!aPPFDlf:       Absorbed photosynthetic photon flux density by leaf (umol m-2 s-1)
!templeaf:      Leaf temperature [K]
!pco2i:         Intercellular air pressure [Pa]
!pres_air:      Ambient air pressure [Pa] 
!vcmax25:       Maximum RuBP saturated rate of carboxylation at 25oC
!                    of leaf temperature [umol m-2 s-1]
!c4aparslope:   Slope of the response of light-limited rate with respect
!                       to absorbed light
!c4kp25:        Slope of the response of the PEP carboxylase-limited
!                       rate of carboxylation for C4 plants 
!rdlight25:     Mitochondrial respiration rate in the light at 25oC
      double precision aPPFDlf,templeaf,pco2i,pres_air,
     &vcmax25,c4aparslope,c4kp25,rdlight25
!------------Output---------------------
!anet_pred:     Predicted net photosynthetic rate [umol m-2 s-1]
!Postiphotolimit: limit state indicator
!                       = 1 Rubisco-limited rate
!                       = 2 RuBP-regeneration limited rate
!                       = 3 Product-limited rate
      double precision anet_pred
      integer ilimittype,Postiphotolimit
!--------------------------------------
      double precision q10,fh,fl,frd,wc,wj,wp,rd,thetacj,thetaip,Ai
      q10=2.0d0
      fh=1.0d0+dexp(0.3d0*(templeaf-313.15d0))
      fl=1.0d0+dexp(0.2d0*(288.15d0-templeaf))
      frd=1.0d0+dexp(1.3d0*(templeaf-328.15d0))
      wc=vcmax25*(q10**((templeaf-298.15d0)/10.0d0))/(fh*fl)
      wj=c4aparslope*aPPFDlf
      wp=c4kp25*(q10**((templeaf-298.15)/10.0d0))*pco2i/pres_air
      rd=rdlight25*(q10**((templeaf-298.15d0)/10.0d0))/frd
      if((ilimittype.eq.1.and.wc.le.wj.and.wc.le.wp).or.
     &ilimittype.eq.5)then
        Postiphotolimit=1
        anet_pred=wc-rd
      endif
      if((ilimittype.eq.1.and.wj.le.wc.and.wj.le.wp).or.
     &ilimittype.eq.6)then
        Postiphotolimit=2
        anet_pred=wj-rd
      endif
      if((ilimittype.eq.1.and.wp.le.wc.and.wp.le.wj).or.
     &ilimittype.eq.7)then
        Postiphotolimit=3
        anet_pred=wp-rd
      endif
      if(ilimittype.eq.2.and.wc.le.wj)then
        Postiphotolimit=1
        anet_pred=wc-rd
      else
        Postiphotolimit=2
        anet_pred=wj-rd
      endif
      if(ilimittype.eq.3.and.wc.le.wp)then
        Postiphotolimit=1
        anet_pred=wc-rd
      else
        Postiphotolimit=3
        anet_pred=wp-rd
      endif
      if(ilimittype.eq.4.and.wj.le.wp)then
        Postiphotolimit=2
        anet_pred=wj-rd
      else
        Postiphotolimit=3
        anet_pred=wp-rd
      endif
      if(ilimittype.eq.1)then
        thetacj=0.8d0
        thetaip=0.95d0
        Ai=((wc+wj)-dsqrt((wc+wj)**2-4.0d0*thetacj*wc*wj))/
     &(2.0d0*thetacj)
        anet_pred=((Ai+wp)-dsqrt((Ai+wp)**2-4.0d0*thetaip*Ai*wp))/
     &(2.0d0*thetaip)-rd
      endif
      return
      end
