        subroutine BEER(LIGHTL,J,K2,ILM)
      include 'SIZE.INC'
      include 'GLOBAL.INC'
      include 'LOCAL.INC'
      include 'LOCAL1.INC'
      include 'LOCAL2.INC'
      include 'LOCAL3.INC'
        double precision WTEMP(46), XXX, XIZERO
        real CMPET, LIGHTL(NPX), XLBOT, XINT, XTES, TOTAVE, TOTTOP
        integer IBOT, ILM(7), J, K2, ION, LAMKNT
        real WATETA(46),PIGETA(46),DOCETA(46),SEDETA(46)
        data WATETA /.288,.268,.249,.231,.215,.194,.174,.157,.141,.133
     &,.126,.119,.105,.0994,.0952,.0903,.0844,.0793,.0678,.0561,.0463
     &,.0379,.0300,.0220,.0191,.0171,.0162,.0153,.0144,.0145,.0145
     &,.01566,.0156,.0176,.0196,.0295,.0492,.0638,.0940,.244,.314,.349
     &,.440,.768,2.47,2.07/
        data PIGETA/145.,138.,132.,126.,120.,115.,109.,106.,101.,95.,
     & 90.,85.,80.,78.,75.,72.,70.,68.,64.,59.,
     & 55.,55.,51.,46.,42.,41.,39.,38.,35.,32.,31.,28.,26.,24.,22.,
     & 19.,14.,10.,8.,6.,5.,8.,13.,3.,2.,0./
        data DOCETA/7.90,7.65,7.41,7.18,6.95,6.73,6.52,6.30,6.12,
     & 5.94,5.76,5.57,5.39,5.22,5.06,4.90,4.74,4.56,4.17,3.64,3.15,
     & 2.74,2.34,2.00,1.64,1.39,1.19,1.02,.870,.753,.654,.573,.504,
     & .444,.396,.357,.282,.228,.188,.158,6*0./
        data SEDETA/46*0.34/
        data XTES/87.0/
      do 190 ION = 1, 7
         if (SPFLGG(ION,K2).eq.0) go to 190
         if (ILM(ION).gt.0) go to 180
         if (LAMAXG(ION,K2).ge.278.75.and.LAMAXG(ION,K2).le.825.) go to
     &      100
         ILM(ION) = 9
         go to 180
100      continue
         if (LAMAXG(ION,K2).ge.321.25) go to 110
         IBOT = 1
         XLBOT = 278.75
         XINT = 2.5
         go to 170
110      continue
         if (LAMAXG(ION,K2).gt.325.) go to 120
         ILM(ION) = 18
         go to 180
120      continue
         if (LAMAXG(ION,K2).ge.495.) go to 130
         IBOT = 19
         XLBOT = 325.
         XINT = 10.
         go to 170
130      continue
         if (LAMAXG(ION,K2).gt.512.5) go to 140
         ILM(ION) = 36
         go to 180
140      continue
         if (LAMAXG(ION,K2).ge.687.5) go to 150
         IBOT = 37
         XLBOT = 512.5
         XINT = 25.
         go to 170
150      continue
         if (LAMAXG(ION,K2).ge.725.) go to 160
         ILM(ION) = 44
         go to 180
160      continue
         if (LAMAXG(ION,K2).le.775.) ILM(ION) = 45
         if (LAMAXG(ION,K2).gt.775.) ILM(ION) = 46
         go to 180
170      continue
         ILM(ION) = IBOT+int((LAMAXG(ION,K2)-XLBOT)/XINT)
180      continue
         CMPET = SEDETA(ILM(ION))*SUSEDG(J,NDAT)+WATETA(ILM(ION))+PIGETA
     &      (ILM(ION))*CHLG(J,NDAT)+DOCETA(ILM(ION))*DOCG(J,NDAT)
         if (DFACG(J,NDAT).lt.1..or.DFACG(J,NDAT).gt.2.) DFACG(J,NDAT) =
     &       1.19
         XIZERO = 1.0
         if (TCELG(J,NDAT).le.0.0) XIZERO = 0.0
         if (J.gt.1.and.TYPEG(J-1).ne.'B') XIZERO = BOTLIT
         XXX = CMPET*DEPTHG(J)*DFACG(J,NDAT)
         if (XXX.gt.XTES) then
            BOTLIT = 0.0
         else
            BOTLIT = XIZERO*exp(-XXX)
         endif
         AVELIT(ION) = (XIZERO-BOTLIT)/XXX
190   continue
      do 200 LAMKNT = 1, 46
         TOTETA(LAMKNT) = DFACG(J,NDAT)*(WATETA(LAMKNT)+PIGETA(LAMKNT)*
     &      CHLG(J,NDAT)+DOCETA(LAMKNT)*DOCG(J,NDAT)+SEDETA(LAMKNT)*
     &      SUSEDG(J,NDAT))
200   continue
      if (J.eq.1) go to 210
      if (TYPEG(J-1).ne.'B') go to 230
210   continue
      do 220 LAMKNT = 1, 46
         WTEMP(LAMKNT) = WLAML(LAMKNT)
         if (TCELG(J,NDAT).le.0.0) WTEMP(LAMKNT) = 0.0
220   continue
      go to 250
230   continue
      do 240 LAMKNT = 1, 46
         WTEMP(LAMKNT) = BOTLAM(LAMKNT)
240   continue
250   continue
      do 260 LAMKNT = 1, 46
         XXX = TOTETA(LAMKNT)*DEPTHG(J)
         if (XXX.gt.XTES) then
            BOTLAM(LAMKNT) = 0.0
         else
            BOTLAM(LAMKNT) = WTEMP(LAMKNT)*exp(-XXX)
         endif
         WAVEL(LAMKNT) = (WTEMP(LAMKNT)-BOTLAM(LAMKNT))/XXX
260   continue
      if (LIGHTL(J).ne.0.0) go to 280
      TOTTOP = 0.
      TOTAVE = 0.
      do 270 LAMKNT = 1, 25
         TOTTOP = TOTTOP+WLAML(LAMKNT)
         TOTAVE = TOTAVE+WAVEL(LAMKNT)
270   continue
      if (TOTTOP.gt.0.0) LIGHTL(J) = TOTAVE/TOTTOP
280   continue
      return
      end
