! This file contains common blocks used in the optimization runs.
!
! ------ Optimization variables common Blocks ---------------------
! maxobs: the maximum number of observations
! maxpsnparam: the maximum number of parameters to be optimized
! aPPFDlf: PAR absorbed by leaf (umol m-2 s-1)
! templeaf: leaf temperature (K)
! xpco2i: Intercellular CO2 partial pressure (Pa)
! po2i:      Intercellular oxygen partial pressure (Pa)
! obs_psn:   net photosynthetic rate (umol m-2 s-1)
! psnparamx: parameters in the leaf photosynthetic model
! nobs: integer, the actual number of observations
! IFIXBcp: the index for the parameters in psnparams that are being
!                optimized (0= not optimized; 1= optimized)
! ilimittype: indicator for the choice of limitation types 
!         = 1, Rubisco+RuBP+TPU'
!         = 2, Rubisco+RuBP
!         = 3, Rubisco+TPU
!         = 4, RuBP+TPU
!         = 5, Rubisco Only
!         = 6, RuBP Only
!         = 7, TPU Only
! betamin: the lower bound of the parameters to be optimized
! betamax: the upper bound of the parameters to be optimized
!resistwp: =rwp, resistance to CO2 via cell walls and plasmalemma (Pa s m2 umol-1). If less than zero, set to zero.
!resistch: =rch, resistance to CO2 via chloroplast envelope and stroma (Pa s m2 umol-1). If less than zero, set to zero.
!idorwp,       =0 zero rwp
!              =1 fit for rwp
!              =2 keep input rwp and don't optimize it
!idorch,       =0 zero rch
!              =1 fit for rch
!              =2 keep input rch and don't optimize it
! ntotparams: the total number of optimized and unoptimized parameters
! isitgridsearch=0, in optimization mode (cij+cic is the transition RuBp-TPU CO2i threshold) 
!               =1, in grid search mode (cij is the transition RuBp-TPU CO2i threshold)   

      integer maxpsnparam
      parameter (maxpsnparam=50)

      double precision univparams(maxpsnparam),
     &univparamsmin(maxpsnparam),univparamsmax(maxpsnparam),
     &betamin(maxpsnparam),betamax(maxpsnparam),resistwp25,resistch25,
     &rdlight25,stargamma25,vcmax25,fkc25,fko25,fjmax25,tpu25,alpha25,
     &bestunivparams(maxpsnparam),resistwp25_ori,resistch25_ori,
     &rdlight25_ori,stargamma25_ori,vcmax25_ori,fkc25_ori,fko25_ori,
     &fjmax25_ori,tpu25_ori,alpha25_ori,gascon,ha_vcmax,hd_vcmax,
     &sv_vcmax,ha_jmax,hd_jmax,sv_jmax,ha_tpu,hd_tpu,sv_tpu,
     &ha_gmeso,hd_gmeso,sv_gmeso,ha_darkresp,ha_stargamma,ha_kc,ha_ko,
     &abspt_lf_par,resistwp25min,resistch25min,rdlight25min,
     &stargamma25min,vcmax25min,fkc25min,fko25min,fjmax25min,tpu25min,
     &alpha25min,resistwp25max,resistch25max,rdlight25max,
     &stargamma25max,vcmax25max,fkc25max,fko25max,fjmax25max,tpu25max,
     &alpha25max,gacontrol(maxpsnparam),
     &subbestunivparams(maxpsnparam,7),phifactor,phifactormin,
     &phifactormax,thetafactor,thetafactormin,thetafactormax,
     &phifactor_ori,thetafactor_ori,betaPSII,betaPSIImin,betaPSIImax,
     &betaPSII_ori,ha_darkrespmin,ha_darkrespmax,ha_darkresp_ori,
     &ha_stargammamin,ha_stargammamax,ha_stargamma_ori,ha_vcmaxmin,
     &ha_vcmaxmax,ha_vcmax_ori,ha_jmaxmin,ha_jmaxmax,ha_jmax_ori,
     &ha_tpumin,ha_tpumax,ha_tpu_ori,ha_gmesomin,ha_gmesomax,
     &ha_gmeso_ori,c4aparslope,c4aparslope_ori,c4kp25,c4kp25_ori

      integer minimumrubis,minimumfj,minimumvt,idorwp,idorch,idord,
     &idostargamma,idoalpha,idokc,idoko,ifixunivparams(maxpsnparam),
     &ntotunivparams,bestnumrubis,bestnumrubp,bestnumtpu,isitbounded,
     &idophifactor,idothetafactor,idobetaPSII,idoha_darkresp,
     &idoha_stargamma,idoha_vcmax,idoha_jmax,idoha_tpu,idoha_gmeso

      common /dbleleafparams/univparams,univparamsmin,univparamsmax,
     &betamin,betamax,resistwp25,resistch25,rdlight25,stargamma25,
     &vcmax25,fkc25,fko25,fjmax25,tpu25,alpha25,bestunivparams,
     &resistwp25_ori,resistch25_ori,rdlight25_ori,stargamma25_ori,
     &vcmax25_ori,fkc25_ori,fko25_ori,fjmax25_ori,tpu25_ori,alpha25_ori,
     &gascon,ha_vcmax,hd_vcmax,sv_vcmax,ha_jmax,hd_jmax,sv_jmax,ha_tpu,
     &hd_tpu,sv_tpu,ha_gmeso,hd_gmeso,sv_gmeso,ha_darkresp,ha_stargamma,
     &ha_kc,ha_ko,abspt_lf_par,resistwp25min,resistch25min,rdlight25min,
     &stargamma25min,vcmax25min,fkc25min,fko25min,fjmax25min,tpu25min,
     &alpha25min,resistwp25max,resistch25max,rdlight25max,
     &stargamma25max,vcmax25max,fkc25max,fko25max,fjmax25max,tpu25max,
     &alpha25max,gacontrol,subbestunivparams,phifactor,phifactormin,
     &phifactormax,thetafactor,thetafactormin,thetafactormax,
     &phifactor_ori,thetafactor_ori,betaPSII,betaPSIImin,betaPSIImax,
     &betaPSII_ori,ha_darkrespmin,ha_darkrespmax,ha_darkresp_ori,
     &ha_stargammamin,ha_stargammamax,ha_stargamma_ori,ha_vcmaxmin,
     &ha_vcmaxmax,ha_vcmax_ori,ha_jmaxmin,ha_jmaxmax,ha_jmax_ori,
     &ha_tpumin,ha_tpumax,ha_tpu_ori,ha_gmesomin,ha_gmesomax,
     &ha_gmeso_ori,c4aparslope,c4aparslope_ori,c4kp25,c4kp25_ori

      common /intleafparams/minimumrubis,minimumfj,minimumvt,idorwp,
     &idorch,idord,idostargamma,idoalpha,idokc,idoko,ifixunivparams,
     &ntotunivparams,bestnumrubis,bestnumrubp,bestnumtpu,isitbounded,
     &idophifactor,idothetafactor,idobetaPSII,idoha_darkresp,
     &idoha_stargamma,idoha_vcmax,idoha_jmax,idoha_tpu,idoha_gmeso

      save /dbleleafparams/,/intleafparams/
!-------- End of list of common block variables ------------------
