! 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 maxobs,maxcurves
      parameter (maxobs=200,maxcurves=15)

      double precision anet_obs(maxobs),pco2i(maxobs),templeaf(maxobs),
     &aPPFDlf(maxobs),pres_air(maxobs),po2i(maxobs),chlflphips2(maxobs),
     &pco2ambient(maxobs),trmmol(maxobs),gswmeas(maxobs),vpdl(maxobs),
     &tempair(maxobs),eambient(maxobs),resiststomco2(maxobs),sumsquare,
     &pco2i_ori(maxobs),templeaf_ori(maxobs),aPPFDlf_ori(maxobs),
     &pres_air_ori(maxobs),po2i_ori(maxobs),chlflphips2_ori(maxobs),
     &pco2ambient_ori(maxobs),trmmol_ori(maxobs),gswmeas_ori(maxobs),
     &vpdl_ori(maxobs),tempair_ori(maxobs),eambient_ori(maxobs),
     &fo_pam(maxobs),fm_pam(maxobs),fs_pam(maxobs),
     &pam_measlight(maxobs),yield_ps2(maxobs),yield_npq(maxobs),
     &qlake(maxobs),qpuddle(maxobs),kps2_norm(maxobs),knpq_norm(maxobs),
     &resiststomco2_ori(maxobs),pco2i_pred(maxobs),anet_pred(maxobs),
     &PhiPSII_pred(maxobs),pco2c(maxobs),bestsumsquare,
     &subbestsumsquare(7),forcings(maxobs,10),weitforcings(maxobs,10),
     &responses(maxobs,5),weitresponses(maxobs,5),
     &pco2i_pred_flu(maxobs),anet_pred_flu(maxobs),
     &pco2c_pco2i_flu(maxobs),pco2c_anet_flu(maxobs),
     &PhiPSIIlights_pred(maxobs),templflights(maxobs),
     &aparlights(maxobs),flphips2lights(maxobs),flujmaxfval,

     &Fixedanet_obs(maxobs/4),Fixedpco2i(maxobs/4),
     &Fixedtempleaf(maxobs/4),FixedaPPFDlf(maxobs/4),
     &Fixedpres_air(maxobs/4),Fixedpo2i(maxobs/4),
     &Fixedchlflphips2(maxobs/4),Fixedpco2ambient(maxobs/4),
     &Fixedtrmmol(maxobs/4),Fixedgswmeas(maxobs/4),
     &Fixedvpdl(maxobs/4),Fixedtempair(maxobs/4),
     &Fixedeambient(maxobs/4),Fixedfo_pam(maxobs/4),
     &Fixedfm_pam(maxobs/4),Fixedfs_pam(maxobs/4),
     &Fixedpam_measlight(maxobs/4),Fixedyield_ps2(maxobs/4),
     &Fixedyield_npq(maxobs/4),Fixedqlake(maxobs/4),
     &Fixedqpuddle(maxobs/4),Fixedkps2_norm(maxobs/4),
     &Fixedknpq_norm(maxobs/4),Fixedresiststomco2(maxobs/4),

     &ACianet_obs0(maxobs/4,maxcurves),ACipco2i0(maxobs/4,maxcurves),
     &ACitempleaf0(maxobs/4,maxcurves),ACiaPPFDlf0(maxobs/4,maxcurves),
     &ACipres_air0(maxobs/4,maxcurves),ACipo2i0(maxobs/4,maxcurves),
     &ACichlflphips20(maxobs/4,maxcurves),
     &ACipco2ambient0(maxobs/4,maxcurves),
     &ACitrmmol0(maxobs/4,maxcurves),ACigswmeas0(maxobs/4,maxcurves),
     &ACivpdl0(maxobs/4,maxcurves),ACitempair0(maxobs/4,maxcurves),
     &ACieambient0(maxobs/4,maxcurves),ACifo_pam0(maxobs/4,maxcurves),
     &ACifm_pam0(maxobs/4,maxcurves),ACifs_pam0(maxobs/4,maxcurves),
     &ACipam_measlight0(maxobs/4,maxcurves),
     &ACiyield_ps20(maxobs/4,maxcurves),
     &ACiyield_npq0(maxobs/4,maxcurves),ACiqlake0(maxobs/4,maxcurves),
     &ACiqpuddle0(maxobs/4,maxcurves),ACikps2_norm0(maxobs/4,maxcurves),
     &ACiknpq_norm0(maxobs/4,maxcurves),
     &ACiresiststomco20(maxobs/4,maxcurves),
     &ACianet_obs(maxobs/4,maxcurves),ACipco2i(maxobs/4,maxcurves),
     &ACitempleaf(maxobs/4,maxcurves),ACiaPPFDlf(maxobs/4,maxcurves),
     &ACipres_air(maxobs/4,maxcurves),ACipo2i(maxobs/4,maxcurves),
     &ACichlflphips2(maxobs/4,maxcurves),
     &ACipco2ambient(maxobs/4,maxcurves),
     &ACitrmmol(maxobs/4,maxcurves),ACigswmeas(maxobs/4,maxcurves),
     &ACivpdl(maxobs/4,maxcurves),ACitempair(maxobs/4,maxcurves),
     &ACieambient(maxobs/4,maxcurves),ACifo_pam(maxobs/4,maxcurves),
     &ACifm_pam(maxobs/4,maxcurves),ACifs_pam(maxobs/4,maxcurves),
     &ACipam_measlight(maxobs/4,maxcurves),
     &ACiyield_ps2(maxobs/4,maxcurves),
     &ACiyield_npq(maxobs/4,maxcurves),ACiqlake(maxobs/4,maxcurves),
     &ACiqpuddle(maxobs/4,maxcurves),ACikps2_norm(maxobs/4,maxcurves),
     &ACiknpq_norm(maxobs/4,maxcurves),
     &ACiresiststomco2(maxobs/4,maxcurves),

     &ALightanet_obs0(maxobs/4,maxcurves),
     &ALightpco2i0(maxobs/4,maxcurves),
     &ALighttempleaf0(maxobs/4,maxcurves),
     &ALightaPPFDlf0(maxobs/4,maxcurves),
     &ALightpres_air0(maxobs/4,maxcurves),
     &ALightpo2i0(maxobs/4,maxcurves),
     &ALightchlflphips20(maxobs/4,maxcurves),
     &ALightpco2ambient0(maxobs/4,maxcurves),
     &ALighttrmmol0(maxobs/4,maxcurves),
     &ALightgswmeas0(maxobs/4,maxcurves),
     &ALightvpdl0(maxobs/4,maxcurves),
     &ALighttempair0(maxobs/4,maxcurves),
     &ALighteambient0(maxobs/4,maxcurves),
     &ALightfo_pam0(maxobs/4,maxcurves),
     &ALightfm_pam0(maxobs/4,maxcurves),
     &ALightfs_pam0(maxobs/4,maxcurves),
     &ALightpam_measlight0(maxobs/4,maxcurves),
     &ALightyield_ps20(maxobs/4,maxcurves),
     &ALightyield_npq0(maxobs/4,maxcurves),
     &ALightqlake0(maxobs/4,maxcurves),
     &ALightqpuddle0(maxobs/4,maxcurves),
     &ALightkps2_norm0(maxobs/4,maxcurves),
     &ALightknpq_norm0(maxobs/4,maxcurves),
     &ALightresiststomco20(maxobs/4,maxcurves),
     &ALightanet_obs(maxobs/4,maxcurves),
     &ALightpco2i(maxobs/4,maxcurves),
     &ALighttempleaf(maxobs/4,maxcurves),
     &ALightaPPFDlf(maxobs/4,maxcurves),
     &ALightpres_air(maxobs/4,maxcurves),
     &ALightpo2i(maxobs/4,maxcurves),
     &ALightchlflphips2(maxobs/4,maxcurves),
     &ALightpco2ambient(maxobs/4,maxcurves),
     &ALighttrmmol(maxobs/4,maxcurves),
     &ALightgswmeas(maxobs/4,maxcurves),
     &ALightvpdl(maxobs/4,maxcurves),
     &ALighttempair(maxobs/4,maxcurves),
     &ALighteambient(maxobs/4,maxcurves),
     &ALightfo_pam(maxobs/4,maxcurves),
     &ALightfm_pam(maxobs/4,maxcurves),
     &ALightfs_pam(maxobs/4,maxcurves),
     &ALightpam_measlight(maxobs/4,maxcurves),
     &ALightyield_ps2(maxobs/4,maxcurves),
     &ALightyield_npq(maxobs/4,maxcurves),
     &ALightqlake(maxobs/4,maxcurves),
     &ALightqpuddle(maxobs/4,maxcurves),
     &ALightkps2_norm(maxobs/4,maxcurves),
     &ALightknpq_norm(maxobs/4,maxcurves),
     &ALightresiststomco2(maxobs/4,maxcurves),

     &Freeanet_obs(maxobs/4),Freepco2i(maxobs/4),
     &Freetempleaf(maxobs/4),FreeaPPFDlf(maxobs/4),
     &Freepres_air(maxobs/4),Freepo2i(maxobs/4),
     &Freechlflphips2(maxobs/4),Freepco2ambient(maxobs/4),
     &Freetrmmol(maxobs/4),Freegswmeas(maxobs/4),
     &Freevpdl(maxobs/4),Freetempair(maxobs/4),
     &Freeeambient(maxobs/4),Freefo_pam(maxobs/4),
     &Freefm_pam(maxobs/4),Freefs_pam(maxobs/4),
     &Freepam_measlight(maxobs/4),Freeyield_ps2(maxobs/4),
     &Freeyield_npq(maxobs/4),Freeqlake(maxobs/4),
     &Freeqpuddle(maxobs/4),Freekps2_norm(maxobs/4),
     &Freeknpq_norm(maxobs/4),Freeresiststomco2(maxobs/4)

      integer ifitmode,ntotsamples,ntotphips2,nFixedPoints,numACicurves,
     &nACiPoints(maxcurves),numALightcurves,nALightPoints(maxcurves),
     &nFreePoints,Fixediphotolimit(maxobs),
     &ACiiphotolimit(maxobs/4,maxcurves),
     &ALightiphotolimit(maxobs/4,maxcurves),Freeiphotolimit(maxobs/4),
     &Prioriphotolimit(maxobs),Priorilimittype,Prioriknowlimit,
     &Currentiphotolimit(maxobs),Currentilimittype,Currentiknowlimit,
     &Postiphotolimit(maxobs),bestiphotolimit(maxobs),bestilimittype,
     &subbestiphotolimit(maxobs,7),nendaci(maxcurves),
     &nstartaci(maxcurves),nendalight(maxcurves),
     &nstartalight(maxcurves),ialightorder(maxcurves),ntotlights,
     &ialightrubpmin(maxcurves),ialightrubpmax(maxcurves),
     &ialightmin(maxcurves),ialightmax(maxcurves)

      common /dbleleafgasobservations/anet_obs,pco2i,templeaf,
     &aPPFDlf,pres_air,po2i,chlflphips2,pco2ambient,trmmol,gswmeas,
     &vpdl,tempair,eambient,resiststomco2,sumsquare,pco2i_ori,
     &templeaf_ori,aPPFDlf_ori,pres_air_ori,po2i_ori,chlflphips2_ori,
     &pco2ambient_ori,trmmol_ori,gswmeas_ori,vpdl_ori,tempair_ori,
     &eambient_ori,fo_pam,fm_pam,fs_pam,pam_measlight,yield_ps2,
     &yield_npq,qlake,qpuddle,kps2_norm,knpq_norm,
     &resiststomco2_ori,pco2i_pred,anet_pred,PhiPSII_pred,
     &pco2c,bestsumsquare,subbestsumsquare,forcings,weitforcings,
     &responses,weitresponses,pco2i_pred_flu,anet_pred_flu,
     &pco2c_pco2i_flu,pco2c_anet_flu,PhiPSIIlights_pred,templflights,
     &aparlights,flphips2lights,flujmaxfval,

     &Fixedanet_obs,Fixedpco2i,Fixedtempleaf,FixedaPPFDlf,Fixedpres_air,
     &Fixedpo2i,Fixedchlflphips2,Fixedpco2ambient,Fixedtrmmol,
     &Fixedgswmeas,Fixedvpdl,Fixedtempair,Fixedeambient,Fixedfo_pam,
     &Fixedfm_pam,Fixedfs_pam,Fixedpam_measlight,Fixedyield_ps2,
     &Fixedyield_npq,Fixedqlake,Fixedqpuddle,Fixedkps2_norm,
     &Fixedknpq_norm,Fixedresiststomco2,
     &ACianet_obs0,ACipco2i0,ACitempleaf0,ACiaPPFDlf0,ACipres_air0,
     &ACipo2i0,ACichlflphips20,ACipco2ambient0,ACitrmmol0,ACigswmeas0,
     &ACivpdl0,ACitempair0,ACieambient0,ACifo_pam0,ACifm_pam0,
     &ACifs_pam0,ACipam_measlight0,ACiyield_ps20,ACiyield_npq0,
     &ACiqlake0,ACiqpuddle0,ACikps2_norm0,ACiknpq_norm0,
     &ACiresiststomco20,ACianet_obs,
     &ACipco2i,ACitempleaf,ACiaPPFDlf,ACipres_air,ACipo2i,
     &ACichlflphips2,ACipco2ambient,ACitrmmol,ACigswmeas,ACivpdl,
     &ACitempair,ACieambient,ACifo_pam,ACifm_pam,ACifs_pam,
     &ACipam_measlight,ACiyield_ps2,ACiyield_npq,ACiqlake,ACiqpuddle,
     &ACikps2_norm,ACiknpq_norm,ACiresiststomco2,ALightanet_obs0,
     &ALightpco2i0,ALighttempleaf0,ALightaPPFDlf0,ALightpres_air0,
     &ALightpo2i0,ALightchlflphips20,ALightpco2ambient0,ALighttrmmol0,
     &ALightgswmeas0,ALightvpdl0,ALighttempair0,ALighteambient0,
     &ALightfo_pam0,ALightfm_pam0,ALightfs_pam0,ALightpam_measlight0,
     &ALightyield_ps20,ALightyield_npq0,ALightqlake0,ALightqpuddle0,
     &ALightkps2_norm0,ALightknpq_norm0,
     &ALightresiststomco20,ALightanet_obs,ALightpco2i,ALighttempleaf,
     &ALightaPPFDlf,ALightpres_air,ALightpo2i,ALightchlflphips2,
     &ALightpco2ambient,ALighttrmmol,ALightgswmeas,ALightvpdl,
     &ALighttempair,ALighteambient,ALightfo_pam,ALightfm_pam,
     &ALightfs_pam,ALightpam_measlight,ALightyield_ps2,
     &ALightyield_npq,ALightqlake,ALightqpuddle,ALightkps2_norm,
     &ALightknpq_norm,ALightresiststomco2,Freeanet_obs,
     &Freetempleaf,FreeaPPFDlf,Freepres_air,Freepo2i,Freechlflphips2,
     &Freepco2ambient,Freetrmmol,Freegswmeas,Freevpdl,Freetempair,
     &Freeeambient,Freefo_pam,Freefm_pam,Freefs_pam,Freepam_measlight,
     &Freeyield_ps2,Freeyield_npq,Freeqlake,Freeqpuddle,Freekps2_norm,
     &Freeknpq_norm,Freeresiststomco2

      common /intleafgasobservations/ifitmode,ntotsamples,ntotphips2,
     &nFixedPoints,numACicurves,nACiPoints,numALightcurves,
     &nALightPoints,nFreePoints,
     &Fixediphotolimit,ACiiphotolimit,ALightiphotolimit,Freeiphotolimit,
     &Prioriphotolimit,Priorilimittype,Prioriknowlimit,
     &Currentiphotolimit,Currentilimittype,Currentiknowlimit,
     &Postiphotolimit,bestiphotolimit,bestilimittype,subbestiphotolimit,
     &nendaci,nstartaci,nendalight,nstartalight,ialightorder,ntotlights,
     &ialightrubpmin,ialightrubpmax,ialightmin,ialightmax

      save /dbleleafgasobservations/,/intleafgasobservations/
!-------- End of list of common block variables ------------------
