        subroutine CKPULS
      include 'SIZE.INC'
      include 'GLOBAL.INC'
      include 'LOCAL.INC'
      include 'UNITS.INC'
      include 'INPAR.INC'
      include 'LOCAL1.INC'
        real TEST, XTEMP
        integer I, IA, IB, IC, ITEMP(4), J, NTEST
      if (MODEG.eq.1) go to 660
      if (BATCH.gt.0) go to 170
      NDAYS(2) = 29
      do 160 I = 1, MAXMAS
         TEST = float(ISEGG(I)+ICHEMG(I)+IMONG(I)+IDAYG(I))+IMASSG(I)
         if (TEST.eq.0.0) go to 160
         if (ISEGG(I).gt.0.and.ISEGG(I).le.KOUNT) go to 100
         write (TTYOUT(MACHNO),5010) ISEGG(I)
         write (TTYOUT(MACHNO),5000)
         go to 150
100      continue
         if (ICHEMG(I).gt.0.and.ICHEMG(I).le.KCHEM) go to 110
         write (TTYOUT(MACHNO),5020) ICHEMG(I)
         write (TTYOUT(MACHNO),5000)
         go to 150
110      continue
         if (IMASSG(I).gt.0.0) go to 120
         write (TTYOUT(MACHNO),5030) IMASSG(I)
         write (TTYOUT(MACHNO),5000)
         go to 150
120      continue
         if (MODEG.eq.2) go to 140
         if (IMONG(I).gt.0.and.IMONG(I).le.12) go to 130
         write (TTYOUT(MACHNO),5040) IMONG(I)
         write (TTYOUT(MACHNO),5000)
         go to 150
130      continue
         if (IDAYG(I).gt.0.and.IDAYG(I).le.NDAYS(IMONG(I))) go to 160
         write (TTYOUT(MACHNO),5050) IDAYG(I),IMONG(I)
         write (TTYOUT(MACHNO),5000)
         go to 150
140      continue
         IMONG(I) = 0
         IDAYG(I) = 0
         go to 160
150      continue
         ICHEMG(I) = 0
         ISEGG(I) = 0
         IMONG(I) = 0
         IDAYG(I) = 0
         IMASSG(I) = 0.0
160   continue
5000  format (' This entry has been deleted from the pulse',' load vecto
     &rs.')
5010  format (' Warning: a pulse was specified for segment ',I5,'.')
5020  format (' Warning: a pulse was specified for chemical ',I5,'.')
5030  format (' Warning: a pulse load of ',1PG9.2,' was requested.')
5040  format (' Warning: a pulse was specified for month ',I5,'.')
5050  format (' Warning: a pulse was specified on day ',I5,' of month ',
     &   I5,'.')
170   continue
      NPULSE = 0
      do 180 I = 1, MAXMAS
         TEST = float(ISEGG(I)+ICHEMG(I)+IMONG(I)+IDAYG(I))+IMASSG(I)
         if (TEST.ne.0) NPULSE = NPULSE+1
180   continue
      if (NPULSE.eq.0) go to 660
      if (NPULSE.gt.1) go to 200
      do 190 I = 1, MAXMAS
         TEST = float(ISEGG(I)+ICHEMG(I)+IMONG(I)+IDAYG(I))+IMASSG(I)
         if (TEST.eq.0) go to 190
         ISEGG(1) = ISEGG(I)
         ICHEMG(1) = ICHEMG(I)
         IMONG(1) = IMONG(I)
         IDAYG(1) = IDAYG(I)
         IMASSG(1) = IMASSG(I)
         go to 660
190   continue
200   continue
      if (BATCH.gt.0) go to 620
      if (MODEG.eq.2) go to 210
      if (MODEG.eq.3) go to 340
      write (TTYOUT(MACHNO),5060) MODEG
5060  format (' System failure in subroutine CKPULS: MODEG is ',I5/1X,'R
     &UN aborted.')
      IFLAG = 8
      go to 670
210   continue
      do 220 I = 1, MAXMAS
         if (ICHEMG(I).eq.0) ICHEMG(I) = 9999
220   continue
      do 250 I = 1, MAXMAS-1
         do 240 J = I+1, MAXMAS
            if (ICHEMG(I)-ICHEMG(J)) 240, 230, 260
230         continue
            if (ISEGG(I)-ISEGG(J)) 240, 240, 260
240      continue
250   continue
      go to 510
260   continue
      do 330 I = 2, MAXMAS
         IA = 1
         IB = I
270      continue
         if (IA.gt.IB) go to 310
         IC = (IA+IB)/2
         if (ICHEMG(IC)-ICHEMG(I)) 300, 280, 290
280      continue
         if (ISEGG(IC)-ISEGG(I)) 300, 300, 290
290      continue
         IB = IC-1
         go to 270
300      continue
         IA = IC+1
         go to 270
310      continue
         IC = IA
         if (IC.ge.I) go to 330
         XTEMP = IMASSG(I)
         ITEMP(1) = ICHEMG(I)
         ITEMP(2) = ISEGG(I)
         do 320 J = I, IC+1, -1
            IMASSG(J) = IMASSG(J-1)
            ICHEMG(J) = ICHEMG(J-1)
            ISEGG(J) = ISEGG(J-1)
320      continue
         IMASSG(IC) = XTEMP
         ICHEMG(IC) = ITEMP(1)
         ISEGG(IC) = ITEMP(2)
330   continue
      go to 510
340   continue
      do 350 I = 1, MAXMAS
         if (IMONG(I).eq.0) IMONG(I) = 9999
350   continue
      do 400 I = 1, MAXMAS-1
         do 390 J = I+1, MAXMAS
            if (IMONG(I)-IMONG(J)) 390, 360, 410
360         continue
            if (IDAYG(I)-IDAYG(J)) 390, 370, 410
370         continue
            if (ICHEMG(I)-ICHEMG(J)) 390, 380, 410
380         continue
            if (ISEGG(I)-ISEGG(J)) 390, 390, 410
390      continue
400   continue
      go to 510
410   continue
      do 500 I = 2, MAXMAS
         IA = 1
         IB = I
420      continue
         if (IA.gt.IB) go to 480
         IC = (IA+IB)/2
         if (IMONG(IC)-IMONG(I)) 470, 430, 460
430      continue
         if (IDAYG(IC)-IDAYG(I)) 470, 440, 460
440      continue
         if (ICHEMG(IC)-ICHEMG(I)) 470, 450, 460
450      continue
         if (ISEGG(IC)-ISEGG(I)) 470, 470, 460
460      continue
         IB = IC-1
         go to 420
470      continue
         IA = IC+1
         go to 420
480      continue
         IC = IA
         if (IC.ge.I) go to 500
         XTEMP = IMASSG(I)
         ITEMP(1) = IMONG(I)
         ITEMP(2) = IDAYG(I)
         ITEMP(3) = ICHEMG(I)
         ITEMP(4) = ISEGG(I)
         do 490 J = I, IC+1, -1
            IMASSG(J) = IMASSG(J-1)
            IMONG(J) = IMONG(J-1)
            IDAYG(J) = IDAYG(J-1)
            ICHEMG(J) = ICHEMG(J-1)
            ISEGG(J) = ISEGG(J-1)
490      continue
         IMASSG(IC) = XTEMP
         IMONG(IC) = ITEMP(1)
         IDAYG(IC) = ITEMP(2)
         ICHEMG(IC) = ITEMP(3)
         ISEGG(IC) = ITEMP(4)
500   continue
510   continue
      do 520 I = 1, MAXMAS
         if (ICHEMG(I).eq.9999) ICHEMG(I) = 0
         if (IMONG(I).eq.9999) IMONG(I) = 0
520   continue
      if (MODEG.ne.2) go to 570
      do 560 I = 1, MAXMAS-1
530      continue
         if (ICHEMG(I).ne.ICHEMG(I+1)) go to 550
         if (ISEGG(I).ne.ISEGG(I+1)) go to 550
         IMASSG(I) = IMASSG(I)+IMASSG(I+1)
         do 540 J = I+1, NPULSE-1
            ICHEMG(J) = ICHEMG(J+1)
            ISEGG(J) = ISEGG(J+1)
            IMASSG(J) = IMASSG(J+1)
540      continue
         ICHEMG(NPULSE) = 0
         ISEGG(NPULSE) = 0
         IMASSG(NPULSE) = 0.0
         NPULSE = NPULSE-1
         go to 530
550      continue
         if (I.ge.(NPULSE-1)) go to 660
560   continue
      go to 660
570   continue
      do 610 I = 1, MAXMAS-1
580      continue
         if (IMONG(I).ne.IMONG(I+1)) go to 600
         if (IDAYG(I).ne.IDAYG(I+1)) go to 600
         if (ICHEMG(I).ne.ICHEMG(I+1)) go to 600
         if (ISEGG(I).ne.ISEGG(I+1)) go to 600
         IMASSG(I) = IMASSG(I)+IMASSG(I+1)
         do 590 J = I+1, NPULSE-1
            IMONG(J) = IMONG(J+1)
            IDAYG(J) = IDAYG(J+1)
            ICHEMG(J) = ICHEMG(J+1)
            ISEGG(J) = ISEGG(J+1)
            IMASSG(J) = IMASSG(J+1)
590      continue
         IMONG(NPULSE) = 0
         IDAYG(NPULSE) = 0
         ICHEMG(NPULSE) = 0
         ISEGG(NPULSE) = 0
         IMASSG(NPULSE) = 0.0
         NPULSE = NPULSE-1
         go to 580
600      continue
         if (I.ge.(NPULSE-1)) go to 660
610   continue
      go to 660
620   continue
      NTEST = 0
      do 650 I = 1, MAXMAS-1
         TEST = float(ISEGG(I)+ICHEMG(I)+IMONG(I)+IDAYG(I))+IMASSG(I)
         if (TEST.ne.0.0) go to 640
         do 630 J = I, MAXMAS-1
            IMASSG(J) = IMASSG(J+1)
            IMONG(J) = IMONG(J+1)
            IDAYG(J) = IDAYG(J+1)
            ICHEMG(J) = ICHEMG(J+1)
            ISEGG(J) = ISEGG(J+1)
630      continue
         IMASSG(MAXMAS) = 0.0
         IMONG(MAXMAS) = 0
         IDAYG(MAXMAS) = 0
         ICHEMG(MAXMAS) = 0
         ISEGG(MAXMAS) = 0
         go to 620
640      continue
         NTEST = NTEST+1
         if (NTEST.ge.NPULSE) go to 660
650   continue
660   continue
      if (NPULSE.lt.1) NPULSE = 0
      call PRPULS
670   continue
      return
      end
