      subroutine UnivParamsAlloc(iswitch)
      implicit none
      include '../testarea/LeafGasParams.h'
      include '../testarea/LeafGasHybridFit.h'
      integer iswitch,i
!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
!iswitch=1: initilize the array of univparams
!iswitch=2: allcoate the array of univparams to corresponding parameters
      if(iswitch.eq.2)then
        resistwp25=univparams(1)
        resistch25=univparams(2)
        rdlight25=univparams(3)
        stargamma25=univparams(4)
        vcmax25=univparams(5)
        fkc25=univparams(6)
	fko25=univparams(7)  
        fjmax25=univparams(8)
        tpu25=univparams(9)
        alpha25=univparams(10)
        phifactor=univparams(11)
        thetafactor=univparams(12)
        betaPSII=univparams(13)
        ha_darkresp=univparams(14)
        ha_stargamma=univparams(15)
        ha_vcmax=univparams(16)
        ha_jmax=univparams(17)
        ha_tpu=univparams(18)
        ha_gmeso=univparams(19)
        return
      else
        do i=1,ntotunivparams
!Initialize ifixunivparams to keep all parameters unchanged
          ifixunivparams(i)=0
        enddo
!
        if(Currentiknowlimit.eq.-1)then
!Fluorescence only fit
          if(idorwp.eq.1)ifixunivparams(1)=1
          if(idorch.eq.1)ifixunivparams(2)=1
          if(idord.eq.1)ifixunivparams(3)=1
          if(idostargamma.eq.1)ifixunivparams(4)=1
          if(idobetaPSII.eq.1)ifixunivparams(13)=1
          if(idoha_darkresp.eq.1)ifixunivparams(14)=1
          if(idoha_stargamma.eq.1)ifixunivparams(15)=1
          if(idoha_gmeso.eq.1)ifixunivparams(19)=1
          return
        endif
!
        if(idorwp.eq.1)ifixunivparams(1)=1
        if(idorch.eq.1)ifixunivparams(2)=1
        if(idord.eq.1)ifixunivparams(3)=1
        if(idostargamma.eq.1)ifixunivparams(4)=1
        if(Currentilimittype.le.3.or.Currentilimittype.eq.5)then
!Rubisco limit involved
          ifixunivparams(5)=1
          if(idokc.eq.1)ifixunivparams(6)=1
          if(idoko.eq.1)ifixunivparams(7)=1
          if(idoha_vcmax.eq.1)ifixunivparams(16)=1
        endif
        if(Currentilimittype.le.2.or.Currentilimittype.eq.4.or.
     &Currentilimittype.eq.6)then
!RuBp limit involved
          ifixunivparams(8)=1
          if(idoha_jmax.eq.1)ifixunivparams(17)=1
          if(idophifactor.eq.1)ifixunivparams(11)=1
          if(idothetafactor.eq.1)ifixunivparams(12)=1
          if(idobetaPSII.eq.1)ifixunivparams(13)=1
        endif
        if(Currentilimittype.eq.1.or.Currentilimittype.eq.3.or.
     &Currentilimittype.eq.4.or.Currentilimittype.eq.7)then
!tpu limit involved
          ifixunivparams(9)=1
          if(idoalpha.eq.1)ifixunivparams(10)=1
          if(idoha_tpu.eq.1)ifixunivparams(18)=1
        endif
        if(idoha_darkresp.eq.1)ifixunivparams(14)=1
        if(idoha_stargamma.eq.1)ifixunivparams(15)=1
        if(idoha_gmeso.eq.1)ifixunivparams(19)=1
        return
      endif
      end subroutine UnivParamsAlloc
