        subroutine TABB
      include 'SIZE.INC'
      include 'GLOBAL.INC'
      include 'LOCAL.INC'
      include 'UNITS.INC'
      include 'INPAR.INC'
      include 'LOCAL1.INC'
      include 'LOCAL2.INC'
        real OUT1(NCON), OUT2(NCON), OUT3(NCON), OUT4(6)
        integer LOC1(NCON), LOC2(NCON), NFIRST, NLAST
        logical MEAN
        character KOUT*2, NMON*4, TAG*2
        common/TABLES/ OUT1, OUT2, OUT3, OUT4
     &, LOC1, LOC2, NFIRST, NLAST, MEAN
        common /TABLE2/ KOUT, NMON, TAG
        integer I, J, K, NBLOCL, III, IV, VRAIL
        character OUTLIN*64
5000  format ('1','Exposure Analysis Modeling System -- EXAMS Version ',
     &   F4.2,', Mode',I2/' Ecosystem: ',50A1)
5010  format (1X,63('-'))
5020  format (1X,63('-')/2X,'* Segment types: Littoral, Epilimnetic, Hyp
     &olimnetic, Benthic.')
5030  format (1X,A2,' Average of 12 monthly mean values.')
      III = VRAIL(ECONAM)
      if (.not.(PRSWG.eq.1.and.MODEG.eq.3)) go to 100
      MEAN = .false.
      TAG = '  '
100   continue
      do 200 NBLOCL = NFIRST, NLAST
         write (RPTLUN(MACHNO),5000) VERSN,MODEG,(ECONAM(IV),IV=1,III)
         write (RPTLUN(MACHNO),5010)
         if (MODEG.ne.3.or.PRSWG.ne.1) go to 110
         NMON = NAMONG(NBLOCL)
         if (NBLOCL.ne.13) go to 110
         MEAN = .true.
         TAG = '**'
110      continue
         write (KOUT,5040) NBLOCL
5040     format (I2)
         if (KOUT(1:1).eq.' ') KOUT(1:1) = '0'
         write (RPTLUN(MACHNO),5050) KOUT,NMON,TAG
5050  format (' Table 6.',A2,'.  ',A4,' environmental inputs: ','sedimen
     &t properties.',A2)
         write (RPTLUN(MACHNO),5010)
         write (RPTLUN(MACHNO),5060)
5060  format (1X,'Seg  T*',4X,'SUSED',4X,'BULKD',4X,'PCTWA',4X,'FROC',6X
     &,'CEC',7X,'AEC'/2X,'#',3X,'y ',4X,'mg/L',5X,'g/cm3',6X,'%',16X,'me
     &q/100g (dry)')
         write (RPTLUN(MACHNO),5010)
         do 190 J = 1, KOUNT
            if (.not.MEAN) go to 150
            do 120 I = 1, 6
               OUT4(I) = 0.0
120         continue
            do 130 I = 1, 12
               if (TYPEG(J).eq.'B') then
                  OUT4(2) = OUT4(2)+BULKDG(J,I)
                  OUT4(3) = OUT4(3)+PCTWAG(J,I)
               else
                  OUT4(1) = OUT4(1)+SUSEDG(J,I)
               endif
               OUT4(4) = OUT4(4)+FROCG(J,I)
               OUT4(5) = OUT4(5)+CECG(J,I)
               OUT4(6) = OUT4(6)+AECG(J,I)
130         continue
            do 140 I = 1, 6
               OUT4(I) = OUT4(I)/12.
140         continue
            SUSEDG(J,13) = OUT4(1)
            BULKDG(J,13) = OUT4(2)
            PCTWAG(J,13) = OUT4(3)
            FROCG(J,13) = OUT4(4)
            CECG(J,13) = OUT4(5)
            AECG(J,13) = OUT4(6)
150         continue
            if (FROCG(J,NBLOCL).eq.0.0) FROCG(J,NBLOCL) = 0.0001
            if (CECG(J,NBLOCL).eq.0.0) CECG(J,NBLOCL) = 0.01
            if (AECG(J,NBLOCL).eq.0.0) AECG(J,NBLOCL) = 0.01
            if (TYPEG(J).ne.'B'.and.SUSEDG(J,NBLOCL).eq.0.0) SUSEDG(J,
     &         NBLOCL) = 0.001
            if (TYPEG(J).ne.'B'.or.BULKDG(J,NBLOCL).ne.0.0) go to 160
            write (TTYOUT(MACHNO),5070) NBLOCL
5070        format (/1X,'In month ',I2,':')
            write (TTYOUT(MACHNO),5080) J
5080        format (1X,'Bulk density of benthic segment',I4,' is zero.'/
     &         1X,'RUN will abort.')
            IFLAG = 8
160         continue
            if (TYPEG(J).ne.'B'.or.PCTWAG(J,NBLOCL).gt.100.0) go to 170
            IFLAG = 8
            write (TTYOUT(MACHNO),5070) NBLOCL
            write (TTYOUT(MACHNO),5090) J
5090  format (1X,'The percent water (PCTWA) data for segment ',I4/1X,'is
     & not in proper form.  Please re-enter the data as:'/12X,'100*(Fres
     &h Weight/Dry Weight)'/1X,'with weights in the same',' units.  RUN 
     &will abort.')
170         continue
            if (TYPEG(J).eq.'B') then
               OUT4(1) = 0.0
               OUT4(2) = BULKDG(J,NBLOCL)
               OUT4(3) = PCTWAG(J,NBLOCL)
            else
               OUT4(1) = SUSEDG(J,NBLOCL)
               OUT4(2) = 0.0
               OUT4(3) = 0.0
            endif
            OUT4(4) = FROCG(J,NBLOCL)
            OUT4(5) = CECG(J,NBLOCL)
            OUT4(6) = AECG(J,NBLOCL)
            write (OUTLIN,5100) J,TYPEG(J),(OUT4(I),I=1,6)
5100        format (1X,I3,2X,A1,3X,1PE9.2,5E9.2)
            K = 1
            do 180 I = 11, 56, 9
               if (OUT4(K).eq.0.0) OUTLIN(I:I+8) = '         '
               if (OUTLIN(I+5:I+8).eq.'E+00') OUTLIN(I+5:I+8) = '    '
               K = K+1
180         continue
            write (RPTLUN(MACHNO),5110) OUTLIN
5110        format (A64)
190      continue
         write (RPTLUN(MACHNO),5020)
         if (TAG(1:1).eq.'*') write (RPTLUN(MACHNO),5030) TAG
200   continue
      write (RPTLUN(MACHNO),5000) VERSN,MODEG,(ECONAM(IV),IV=1,III)
      write (RPTLUN(MACHNO),5010)
      write (RPTLUN(MACHNO),5120)
5120  format (' Table 7.  Environmental input data: physical geometry.')
      write (RPTLUN(MACHNO),5010)
      write (RPTLUN(MACHNO),5130)
5130  format (1X,'Seg  T*',3X,'VOLume',4X,'AREA',5X,'DEPTH',4X,'XSA',6X,
     &'LENGth',3X,'WIDTH'/2X,'#',3X,'y ',5X,'m3',7X,'m2',8X,'m',7X,'m2',
     &8X,'m',8X,'m')
      write (RPTLUN(MACHNO),5010)
      do 220 J = 1, KOUNT
         OUT4(1) = VOLG(J)
         OUT4(2) = AREAG(J)
         OUT4(3) = DEPTHG(J)
         OUT4(4) = XSAG(J)
         OUT4(5) = LENGG(J)
         OUT4(6) = WIDTHG(J)
         write (OUTLIN,5100) J,TYPEG(J),(OUT4(I),I=1,6)
         K = 1
         do 210 I = 11, 56, 9
            if (OUT4(K).eq.0.0) OUTLIN(I:I+8) = '         '
            if (OUTLIN(I+5:I+8).eq.'E+00') OUTLIN(I+5:I+8) = '    '
            K = K+1
210      continue
         write (RPTLUN(MACHNO),5110) OUTLIN
220   continue
      write (RPTLUN(MACHNO),5020)
      if (.not.(PRSWG.eq.1.and.MODEG.eq.3)) go to 230
      MEAN = .false.
      TAG = '  '
230   continue
      do 340 NBLOCL = NFIRST, NLAST
         write (RPTLUN(MACHNO),5000) VERSN,MODEG,(ECONAM(IV),IV=1,III)
         write (RPTLUN(MACHNO),5010)
         if (MODEG.ne.3.or.PRSWG.ne.1) go to 240
         NMON = NAMONG(NBLOCL)
         if (NBLOCL.ne.13) go to 240
         MEAN = .true.
         TAG = '**'
240      continue
         write (KOUT,5040) NBLOCL
         if (KOUT(1:1).eq.' ') KOUT(1:1) = '0'
         write (RPTLUN(MACHNO),5140) KOUT,NMON,TAG
5140     format (' Table 8.',A2,'.  ',A4,' miscellaneous environmental',
     &      ' input data.',A2)
         write (RPTLUN(MACHNO),5010)
         write (RPTLUN(MACHNO),5150)
5150  format (1X,'Seg  T*',4X,'DFAC',5X,'DISO2',5X,'KO2',5X,'WIND',5X,'D
     &OC',5X,'CHL pgmt',/2X,'#',3X,'y ',4X,'m/m',6X,'mg/L',4X,'cm/hr@20'
     &,1X,'m/s@10cm',2X,'mg/L',6X,'mg/L')
         write (RPTLUN(MACHNO),5010)
         do 330 J = 1, KOUNT
            if (.not.MEAN) go to 290
            do 250 I = 1, 6
               OUT4(I) = 0.0
250         continue
            do 270 I = 1, 12
               OUT4(5) = OUT4(5)+DOCG(J,I)
               if (TYPEG(J).eq.'B') go to 270
               if (J.eq.1) go to 260
               if (TYPEG(J-1).eq.'B') go to 260
               KO2G(J,I) = 0.0
               WINDG(J,I) = 0.0
260            continue
               OUT4(1) = OUT4(1)+DFACG(J,I)
               OUT4(2) = OUT4(2)+DISO2G(J,I)
               OUT4(3) = OUT4(3)+KO2G(J,I)
               OUT4(4) = OUT4(4)+WINDG(J,I)
               OUT4(6) = OUT4(6)+CHLG(J,I)
270         continue
            do 280 I = 1, 6
               OUT4(I) = OUT4(I)/12.
280         continue
            DFACG(J,13) = OUT4(1)
            DISO2G(J,13) = OUT4(2)
            KO2G(J,13) = OUT4(3)
            WINDG(J,13) = OUT4(4)
            DOCG(J,13) = OUT4(5)
            CHLG(J,13) = OUT4(6)
290         continue
            if (J.eq.1) go to 300
            if (TYPEG(J-1).eq.'B'.and.TYPEG(J).ne.'B') go to 300
            KO2G(J,NBLOCL) = 0.0
            WINDG(J,NBLOCL) = 0.0
300         continue
            if (TYPEG(J).ne.'B') go to 310
            DFACG(J,NBLOCL) = 0.0
            DISO2G(J,NBLOCL) = 0.0
            CHLG(J,NBLOCL) = 0.0
310         continue
            OUT4(1) = DFACG(J,NBLOCL)
            OUT4(2) = DISO2G(J,NBLOCL)
            OUT4(3) = KO2G(J,NBLOCL)
            OUT4(4) = WINDG(J,NBLOCL)
            OUT4(5) = DOCG(J,NBLOCL)
            OUT4(6) = CHLG(J,NBLOCL)
            write (OUTLIN,5100) J,TYPEG(J),(OUT4(I),I=1,6)
            K = 1
            do 320 I = 11, 56, 9
               if (OUT4(K).eq.0.0) OUTLIN(I:I+8) = '         '
               if (OUTLIN(I+5:I+8).eq.'E+00') OUTLIN(I+5:I+8) = '    '
               K = K+1
320         continue
            write (RPTLUN(MACHNO),5110) OUTLIN
330      continue
         write (RPTLUN(MACHNO),5020)
         if (TAG(1:1).eq.'*') write (RPTLUN(MACHNO),5030) TAG
340   continue
      return
      end
