      subroutine ALightCombinatorial()
      implicit none
      include '../testarea/LeafGasHybridFit.h'
      integer i,ilastrubp1,ilastrubis1,ilastrubp2,ilastrubis2,
     &ilastrubp3,ilastrubis3,ilastrubp4,ilastrubis4,
     &ilastrubp5,ilastrubis5,ilastrubp6,ilastrubis6,
     &ilastrubp7,ilastrubis7,ilastrubp8,ilastrubis8,
     &ilastrubp9,ilastrubis9,ilastrubp10,ilastrubis10,
     &ilastrubp11,ilastrubis11,ilastrubp12,ilastrubis12,
     &ilastrubp13,ilastrubis13,ilastrubp14,ilastrubis14,
     &ilastrubp15,ilastrubis15
!common block variables: numALightcurves,nALightPoints(numALightcurves),
!ALightiphotolimit(nALightPoints,numALightcurves)

      if(numALightcurves.eq.0)then
!no conventional A/Light curves. go to free-style measurements directly and then return
        call FreeCombinatorial()
        return
      endif
!(before 17/09/2014 remarks.) Assume rubp, rubisco and tpu limitations in the order of (rubp, rubisco, tpu) but any limitation can be missing in any light response curves
!the nALightPoints data in each light response curve must be ordered from low to high PAR. When ordered in such, the three limitation states
!should occur in the order of (rubp, rubisco, tpu)
!
!17/09/2014 Wenting found (RuBP, TPU, Rubisco) is more likely for A/Light curves if Ci decreases with increased light. Thus the following
!changes are made:
!we generally assume the points of an A/Light curve are lined up in a sequence of (RuBP, TPU and Rubisco), which is indicated by
!ialightorder=0. However, if Ci increases steadily from nstartalight to the end, we assume a sequence of (RuBP, Rubisco and TPU),
!which is indicated by ialightorder=2.
      do ilastrubp1=nstartalight(1),nendalight(1)
        do i=1,ilastrubp1
          ALightiphotolimit(i,1)=2
        enddo
      do 1 ilastrubis1=ilastrubp1,nALightPoints(1)
        do i=ilastrubp1+1,ilastrubis1
          ALightiphotolimit(i,1)=3-ialightorder(1)
        enddo
        do i=ilastrubis1+1,nALightPoints(1)
          ALightiphotolimit(i,1)=1+ialightorder(1)
        enddo
        if(numALightcurves.eq.1)then
          call FreeCombinatorial()
          goto 1
        endif

      do ilastrubp2=nstartalight(2),nendalight(2)
        do i=1,ilastrubp2
          ALightiphotolimit(i,2)=2
        enddo
      do 2 ilastrubis2=ilastrubp2,nALightPoints(2)
        do i=ilastrubp2+1,ilastrubis2
          ALightiphotolimit(i,2)=3-ialightorder(2)
        enddo
        do i=ilastrubis2+1,nALightPoints(2)
          ALightiphotolimit(i,2)=1+ialightorder(2)
        enddo
        if(numALightcurves.eq.2)then
          call FreeCombinatorial()
          goto 2
        endif

      do ilastrubp3=nstartalight(3),nendalight(3)
        do i=1,ilastrubp3
          ALightiphotolimit(i,3)=2
        enddo
      do 3 ilastrubis3=ilastrubp3,nALightPoints(3)
        do i=ilastrubp3+1,ilastrubis3
          ALightiphotolimit(i,3)=3-ialightorder(3)
        enddo
        do i=ilastrubis3+1,nALightPoints(3)
          ALightiphotolimit(i,3)=1+ialightorder(3)
        enddo
        if(numALightcurves.eq.3)then
          call FreeCombinatorial()
          goto 3
        endif

      do ilastrubp4=nstartalight(4),nendalight(4)
        do i=1,ilastrubp4
          ALightiphotolimit(i,4)=2
        enddo
      do 4 ilastrubis4=ilastrubp4,nALightPoints(4)
        do i=ilastrubp4+1,ilastrubis4
          ALightiphotolimit(i,4)=3-ialightorder(4)
        enddo
        do i=ilastrubis4+1,nALightPoints(4)
          ALightiphotolimit(i,4)=1+ialightorder(4)
        enddo
        if(numALightcurves.eq.4)then
          call FreeCombinatorial()
          goto 4
        endif

      do ilastrubp5=nstartalight(5),nendalight(5)
        do i=1,ilastrubp5
          ALightiphotolimit(i,5)=2
        enddo
      do 5 ilastrubis5=ilastrubp5,nALightPoints(5)
        do i=ilastrubp5+1,ilastrubis5
          ALightiphotolimit(i,5)=3-ialightorder(5)
        enddo
        do i=ilastrubis5+1,nALightPoints(5)
          ALightiphotolimit(i,5)=1+ialightorder(5)
        enddo
        if(numALightcurves.eq.5)then
          call FreeCombinatorial()
          goto 5
        endif

      do ilastrubp6=nstartalight(6),nendalight(6)
        do i=1,ilastrubp6
          ALightiphotolimit(i,6)=2
        enddo
      do 6 ilastrubis6=ilastrubp6,nALightPoints(6)
        do i=ilastrubp6+1,ilastrubis6
          ALightiphotolimit(i,6)=3-ialightorder(6)
        enddo
        do i=ilastrubis6+1,nALightPoints(6)
          ALightiphotolimit(i,6)=1+ialightorder(6)
        enddo
        if(numALightcurves.eq.6)then
          call FreeCombinatorial()
          goto 6
        endif

      do ilastrubp7=nstartalight(7),nendalight(7)
        do i=1,ilastrubp7
          ALightiphotolimit(i,7)=2
        enddo
      do 7 ilastrubis7=ilastrubp7,nALightPoints(7)
        do i=ilastrubp7+1,ilastrubis7
          ALightiphotolimit(i,7)=3-ialightorder(7)
        enddo
        do i=ilastrubis7+1,nALightPoints(7)
          ALightiphotolimit(i,7)=1+ialightorder(7)
        enddo
        if(numALightcurves.eq.7)then
          call FreeCombinatorial()
          goto 7
        endif

      do ilastrubp8=nstartalight(8),nendalight(8)
        do i=1,ilastrubp8
          ALightiphotolimit(i,8)=2
        enddo
      do 8 ilastrubis8=ilastrubp8,nALightPoints(8)
        do i=ilastrubp8+1,ilastrubis8
          ALightiphotolimit(i,8)=3-ialightorder(8)
        enddo
        do i=ilastrubis8+1,nALightPoints(8)
          ALightiphotolimit(i,8)=1+ialightorder(8)
        enddo
        if(numALightcurves.eq.8)then
          call FreeCombinatorial()
          goto 8
        endif

      do ilastrubp9=nstartalight(9),nendalight(9)
        do i=1,ilastrubp9
          ALightiphotolimit(i,9)=2
        enddo
      do 9 ilastrubis9=ilastrubp9,nALightPoints(9)
        do i=ilastrubp9+1,ilastrubis9
          ALightiphotolimit(i,9)=3-ialightorder(9)
        enddo
        do i=ilastrubis9+1,nALightPoints(9)
          ALightiphotolimit(i,9)=1+ialightorder(9)
        enddo
        if(numALightcurves.eq.9)then
          call FreeCombinatorial()
          goto 9
        endif

      do ilastrubp10=nstartalight(10),nendalight(10)
        do i=1,ilastrubp10
          ALightiphotolimit(i,10)=2
        enddo
      do 10 ilastrubis10=ilastrubp10,nALightPoints(10)
        do i=ilastrubp10+1,ilastrubis10
          ALightiphotolimit(i,10)=3-ialightorder(10)
        enddo
        do i=ilastrubis10+1,nALightPoints(10)
          ALightiphotolimit(i,10)=1+ialightorder(10)
        enddo
        if(numALightcurves.eq.10)then
          call FreeCombinatorial()
          goto 10
        endif

      do ilastrubp11=nstartalight(11),nendalight(11)
        do i=1,ilastrubp11
          ALightiphotolimit(i,11)=2
        enddo
      do 11 ilastrubis11=ilastrubp11,nALightPoints(11)
        do i=ilastrubp11+1,ilastrubis11
          ALightiphotolimit(i,11)=3-ialightorder(11)
        enddo
        do i=ilastrubis11+1,nALightPoints(11)
          ALightiphotolimit(i,11)=1+ialightorder(11)
        enddo
        if(numALightcurves.eq.11)then
          call FreeCombinatorial()
          goto 11
        endif

      do ilastrubp12=nstartalight(12),nendalight(12)
        do i=1,ilastrubp12
          ALightiphotolimit(i,12)=2
        enddo
      do 12 ilastrubis12=ilastrubp12,nALightPoints(12)
        do i=ilastrubp12+1,ilastrubis12
          ALightiphotolimit(i,12)=3-ialightorder(12)
        enddo
        do i=ilastrubis12+1,nALightPoints(12)
          ALightiphotolimit(i,12)=1+ialightorder(12)
        enddo
        if(numALightcurves.eq.12)then
          call FreeCombinatorial()
          goto 12
        endif

      do ilastrubp13=nstartalight(13),nendalight(13)
        do i=1,ilastrubp13
          ALightiphotolimit(i,13)=2
        enddo
      do 13 ilastrubis13=ilastrubp13,nALightPoints(13)
        do i=ilastrubp13+1,ilastrubis13
          ALightiphotolimit(i,13)=3-ialightorder(13)
        enddo
        do i=ilastrubis13+1,nALightPoints(13)
          ALightiphotolimit(i,13)=1+ialightorder(13)
        enddo
        if(numALightcurves.eq.13)then
          call FreeCombinatorial()
          goto 13
        endif

      do ilastrubp14=nstartalight(14),nendalight(14)
        do i=1,ilastrubp14
          ALightiphotolimit(i,14)=2
        enddo
      do 14 ilastrubis14=ilastrubp14,nALightPoints(14)
        do i=ilastrubp14+1,ilastrubis14
          ALightiphotolimit(i,14)=3-ialightorder(14)
        enddo
        do i=ilastrubis14+1,nALightPoints(14)
          ALightiphotolimit(i,14)=1+ialightorder(14)
        enddo
        if(numALightcurves.eq.14)then
          call FreeCombinatorial()
          goto 14
        endif

      do ilastrubp15=nstartalight(15),nendalight(15)
        do i=1,ilastrubp15
          ALightiphotolimit(i,15)=2
        enddo
      do 15 ilastrubis15=ilastrubp15,nALightPoints(15)
        do i=ilastrubp15+1,ilastrubis15
          ALightiphotolimit(i,15)=3-ialightorder(15)
        enddo
        do i=ilastrubis15+1,nALightPoints(15)
          ALightiphotolimit(i,15)=1+ialightorder(15)
        enddo
        if(numALightcurves.eq.15)then
          call FreeCombinatorial()
          goto 15
        endif
15    continue
      enddo
14    continue
      enddo
13    continue
      enddo
12    continue
      enddo
11    continue
      enddo
10    continue
      enddo
9     continue
      enddo
8     continue
      enddo
7     continue
      enddo
6     continue
      enddo
5     continue
      enddo
4     continue
      enddo
3     continue
      enddo
2     continue
      enddo
1     continue
      enddo
      return
      end subroutine ALightCombinatorial
