        subroutine CKLOAD
      include 'SIZE.INC'
      include 'GLOBAL.INC'
      include 'LOCAL.INC'
      include 'UNITS.INC'
      include 'LOCAL1.INC'
      include 'LOCAL2.INC'
        dimension BETA(7),CHECK(7),DISFUN(14)
        real BETA, CHECK, DISFUN, MOLTST, SATTST, SUMFUN, TESTLD, TKEL
     &,      TMPLOD, TOTCON
        real HPLUS, HPLSQ, HPLCUB, HYDRX, HYDSQ, HYDCUB
        integer I, III, IV, IPRFLG, J, K, K2, NLOAD, VRAIL
        character NMON*4
      IPRFLG = 0
      NLOAD = NDAT
      if (PRSWG.eq.0.and.MODEG.lt.3) NLOAD = 13
      NMON = NAMONG(NLOAD)
      do 130 J = 1, KOUNT
         TKEL = 273.15+TCELG(J,NDAT)
         do 120 K2 = 1, KCHEM
            do 110 I = 1, 7
               YSATL(I,J,K2) = 0.0
               if (SPFLGG(I,K2).eq.0) go to 110
               YSATL(I,J,K2) = SOLG(I,K2)
               if (ESOLG(I,K2).eq.0.) go to 100
               if (MWTG(K2).le.0.) then
                  IFLAG = 8
                  III = VRAIL(CHEMNA(1,K2))
                  write (TTYOUT(MACHNO),5000) (CHEMNA(IV,K2),IV=1,III)
                  go to 360
5000  format (' The chemical input data contains an inconsistency that'/
     &' must be remedied before a RUN can be completed:'/' The molar sol
     &ubility of'/1X,50A1/' is given as a function of temperature, but i
     &ts molecular'/' weight is not specified in the chemical data base.
     &')
               endif
               YSATL(I,J,K2) = (10.**(SOLG(I,K2)-((1000.*ESOLG(I,K2))/
     &            (4.58*TKEL))))*MWTG(K2)*1000.
100            continue
               if (I.eq.1.or.YSATL(I,J,K2).gt.0.0) go to 110
               YSATL(I,J,K2) = 5000.*YSATL(1,J,K2)
               if (IPRFLG.gt.0) go to 110
               write (TTYOUT(MACHNO),5010)
               IPRFLG = 1
110         continue
120      continue
130   continue
5010  format (' Solubility of ionic species estimated from that of'/' th
     &e neutral molecule: ion solubility is not listed'/' in the input d
     &ata.')
      do 330 K2 = 1, KCHEM
         MOLTST = 0.01*MWTG(K2)
         do 320 J = 1, KOUNT
            TOTLDL(J,K2) = STRLDG(J,K2,NLOAD)+NPSLDG(J,K2,NLOAD)+PCPLDG(
     &         J,K2,NLOAD)+DRFLDG(J,K2,NLOAD)+SEELDG(J,K2,NLOAD)
            if (TOTLDL(J,K2).eq.0.) go to 320
            do 140 I = 1, 7
               CHECK(I) = 0.50*YSATL(I,J,K2)
140         continue
            if (CHECK(1).gt.MOLTST) CHECK(1) = MOLTST
            HPLUS = 10.**(-PHG(J,NDAT))
            HYDRX = 10.**(-POHG(J,NDAT))
            HPLSQ = HPLUS*HPLUS
            HYDSQ = HYDRX*HYDRX
            HPLCUB = HPLUS*HPLSQ
            HYDCUB = HYDRX*HYDSQ
            DISFUN(1) = 1.0
            DISFUN(2) = KB1L(J,K2)/HYDRX
            DISFUN(3) = KB1L(J,K2)*KB2L(J,K2)/HYDSQ
            DISFUN(4) = KB1L(J,K2)*KB2L(J,K2)*KB3L(J,K2)/HYDCUB
            DISFUN(5) = KA1L(J,K2)/HPLUS
            DISFUN(6) = KA1L(J,K2)*KA2L(J,K2)/HPLSQ
            DISFUN(7) = KA1L(J,K2)*KA2L(J,K2)*KA3L(J,K2)/HPLCUB
            if (SEELDG(J,K2,NLOAD).eq.0.0.and.PCPLDG(J,K2,NLOAD).eq.0.0)
     &          go to 220
            SUMFUN = 0.
            do 150 I = 1, 7
               SUMFUN = SUMFUN+DISFUN(I)
150         continue
            do 160 I = 1, 7
               BETA(I) = DISFUN(I)/SUMFUN
160         continue
            if (SEELDG(J,K2,NLOAD).eq.0.0) go to 190
            if (SEEPSL(J).eq.0.0) go to 180
            TOTCON = 1.E6*SEELDG(J,K2,NLOAD)/SEEPSL(J)
            do 170 I = 1, 7
               if (SPFLGG(I,K2).eq.0) go to 170
               SATTST = BETA(I)*TOTCON
               if (SATTST.le.CHECK(I)) go to 170
               TMPLOD = CHECK(I)*SEEPSL(J)/(2.E6*BETA(I))
               if (SEELDG(J,K2,NLOAD).gt.TMPLOD) SEELDG(J,K2,NLOAD) =
     &             TMPLOD
               write (TTYOUT(MACHNO),5020) NMON
               write (TTYOUT(MACHNO),5030) J
170         continue
5020        format (1X,A4,' interflow loading')
5030  format (' exceeded solubility limit in segment ',I3,'.'/' Load has
     & been adjusted.')
            go to 190
180         continue
            SEELDG(J,K2,NLOAD) = 0.
            write (TTYOUT(MACHNO),5040) NMON,J
5040  format (1X,A4,' interflow load entered for segment',I3,','/' which
     & receives no interflow.  The load has been removed.')
190         continue
            if (PCPLDG(J,K2,NLOAD).eq.0.0) go to 220
            if (RAINFL(J).eq.0.) go to 210
            TOTCON = 1.E6*PCPLDG(J,K2,NLOAD)/RAINFL(J)
            do 200 I = 1, 7
               if (SPFLGG(I,K2).eq.0) go to 200
               SATTST = BETA(I)*TOTCON
               if (SATTST.le.CHECK(I)) go to 200
               TMPLOD = CHECK(I)*RAINFL(J)/(2.E6*BETA(I))
               if (PCPLDG(J,K2,NLOAD).gt.TMPLOD) PCPLDG(J,K2,NLOAD) =
     &             TMPLOD
               write (TTYOUT(MACHNO),5050) NMON
               write (TTYOUT(MACHNO),5030) J
200         continue
5050        format (1X,A4,' rainfall loading')
            go to 220
210         continue
            PCPLDG(J,K2,NLOAD) = 0.0
            write (TTYOUT(MACHNO),5060) NMON,J
5060  format (1X,A4,' rainfall loading entered for segment ',I3,','/' wh
     &ich gets no rain.  The load has been removed.')
220         continue
            if (STRLDG(J,K2,NLOAD).eq.0..and.NPSLDG(J,K2,NLOAD).eq.0.)
     &          go to 320
            if (STRLDG(J,K2,NLOAD).eq.0.) go to 270
            if (STRMFL(J).eq.0.) go to 260
            TOTCON = 1.E6*STRLDG(J,K2,NLOAD)/STRMFL(J)
            DISFUN(8) = KPSL(1,J,K2)*STSCOL(J)
            DISFUN(9) = DISFUN(2)*KPSL(2,J,K2)*STSCOL(J)
            DISFUN(10) = DISFUN(3)*KPSL(3,J,K2)*STSCOL(J)
            DISFUN(11) = DISFUN(4)*KPSL(4,J,K2)*STSCOL(J)
            DISFUN(12) = DISFUN(5)*KPSL(5,J,K2)*STSCOL(J)
            DISFUN(13) = DISFUN(6)*KPSL(6,J,K2)*STSCOL(J)
            DISFUN(14) = DISFUN(7)*KPSL(7,J,K2)*STSCOL(J)
            SUMFUN = 0.
            do 230 K = 1, 14
               SUMFUN = SUMFUN+DISFUN(K)
230         continue
            do 240 K = 1, 7
               BETA(K) = DISFUN(K)/SUMFUN
240         continue
            do 250 I = 1, 7
               if (SPFLGG(I,K2).eq.0) go to 250
               SATTST = BETA(I)*TOTCON
               if (SATTST.le.CHECK(I)) go to 250
               TMPLOD = CHECK(I)*STRMFL(J)/(2.E6*BETA(I))
               if (STRLDG(J,K2,NLOAD).gt.TMPLOD) STRLDG(J,K2,NLOAD) =
     &             TMPLOD
               write (TTYOUT(MACHNO),5070) NMON
               write (TTYOUT(MACHNO),5030) J
250         continue
5070        format (1X,A4,' stream loading')
            go to 270
260         continue
            STRLDG(J,K2,NLOAD) = 0.
            write (TTYOUT(MACHNO),5080) NMON,J
5080  format (1X,A4,' streamflow loading entered for segment ',I3,','/1X
     &,'which receives no stream flow.  The load has been ','removed.')
270         continue
            if (NPSLDG(J,K2,NLOAD).eq.0.) go to 320
            if (NPSFL(J).eq.0.) go to 310
            TOTCON = 1.E6*NPSLDG(J,K2,NLOAD)/NPSFL(J)
            DISFUN(8) = KPSL(1,J,K2)*NPSCOL(J)
            DISFUN(9) = DISFUN(2)*KPSL(2,J,K2)*NPSCOL(J)
            DISFUN(10) = DISFUN(3)*KPSL(3,J,K2)*NPSCOL(J)
            DISFUN(11) = DISFUN(4)*KPSL(4,J,K2)*NPSCOL(J)
            DISFUN(12) = DISFUN(5)*KPSL(5,J,K2)*NPSCOL(J)
            DISFUN(13) = DISFUN(6)*KPSL(6,J,K2)*NPSCOL(J)
            DISFUN(14) = DISFUN(7)*KPSL(7,J,K2)*NPSCOL(J)
            SUMFUN = 0.
            do 280 K = 1, 14
               SUMFUN = SUMFUN+DISFUN(K)
280         continue
            do 290 K = 1, 7
               BETA(K) = DISFUN(K)/SUMFUN
290         continue
            do 300 I = 1, 7
               if (SPFLGG(I,K2).eq.0) go to 300
               SATTST = BETA(I)*TOTCON
               if (SATTST.le.CHECK(I)) go to 300
               TMPLOD = CHECK(I)*NPSFL(J)/(2.E6*BETA(I))
               if (NPSLDG(J,K2,NLOAD).gt.TMPLOD) NPSLDG(J,K2,NLOAD) =
     &             TMPLOD
               write (TTYOUT(MACHNO),5090) NMON
               write (TTYOUT(MACHNO),5030) J
300         continue
5090        format (1X,A4,' non-point-source loading')
            go to 320
310         continue
            NPSLDG(J,K2,NLOAD) = 0.0
            write (TTYOUT(MACHNO),5100) NMON,J
5100  format (1X,A4,' non-point-source loading entered for segment ',I3/
     &' without a non-point source.  The load has been removed.')
320      continue
330   continue
      TESTLD = 0.0
      do 350 K2 = 1, KCHEM
         SYSLDL(K2) = 0.0
         do 340 J = 1, KOUNT
            TOTLDL(J,K2) = SEELDG(J,K2,NLOAD)+STRLDG(J,K2,NLOAD)+NPSLDG(
     &         J,K2,NLOAD)+PCPLDG(J,K2,NLOAD)+DRFLDG(J,K2,NLOAD)
            SYSLDL(K2) = SYSLDL(K2)+TOTLDL(J,K2)
340      continue
         TESTLD = TESTLD+SYSLDL(K2)
350   continue
      if (TESTLD.gt.0..or.MODEG.gt.1) go to 360
      IFLAG = 8
      write (TTYOUT(MACHNO),5110)
5110  format (1X,'No allochthonous chemical loadings.'/' Steady-state co
     &mputations cancelled.')
360   continue
      return
      end
