      subroutine DRIVM3(Y,RUNOPT)
      include 'SIZE.INC'
      include 'GLOBAL.INC'
      include 'LOCAL.INC'
      include 'UNITS.INC'
      include 'INPAR.INC'
      include 'LOCAL1.INC'
      include 'WORK.INC'
        double precision Y, TOFF, RELER, ABSER
        dimension Y(KOUNT,KCHEM)
        integer IBUFF(VARIEC), RUNOPT, IMOVE
        integer I, I1, J, K, MON1, NYR
        integer PFIRST, PLAST, ITEST
        character DUMMY*1
5000  format (/1X,'Integrator diagnostics now switched on (IUNIT=1).')
5010  format (/1X,'Integrator failure during ',A4,' of year ',I4,'.'/1X,
     &   'Evaluate results before CONTINUing.')
      RELER = RELERR
      ABSER = ABSERR
      if (IUNITG.ne.0) then
         IUNIT = IUNITG
      else
         IUNIT = 0
      endif
      IMOVE = TTYOUT(MACHNO)
      if (MODEG.ge.3) go to 100
      if (ISOO.eq.1) call ADMINT (KEQN,Y,WORK,TINIT,TENDL,TINCRL,RELER,
     &   ABSER,IUNIT,T,IFLAG,TPRINT,IMOVE,FOURU,NPRINT)
      if (ISOO.eq.2) call STFINT (KEQN,Y,WORK,IWORK,TINIT,TENDL,TINCRL,
     &   RELER,ABSER,IUNIT,T,IFLAG,TPRINT,IMOVE,FOURU,NPRINT)
      go to 510
100   continue
      if (RUNOPT.eq.0) STIFEQ = .false.
      ABEXIT = .false.
      if (NYEARG.le.0) NYEARG = 1
      TCODEG = 2
      CINTG = 1.0
      TINCRL = 2.4D+01
      TFACTR = 24.0
      KDTIME = TCODEG
      if (IFLAG.gt.2) go to 180
      FLUXCT = 0.0
      YCOUNT = 0.0
      do 170 K = 1, KCHEM
         YEXPO(K) = 0.0
         YVOLK(K) = 0.0
         YHYDR(K) = 0.0
         YOXID(K) = 0.0
         YPHOT(K) = 0.0
         YS1O2(K) = 0.0
         YRED(K) = 0.0
         YBIOW(K) = 0.0
         YBIOS(K) = 0.0
         YGWAT(K) = 0.0
         do 150 J = 1, KOUNT
            do 120 I = 1, 10
               do 110 I1 = 1, 3
                  YTEST(I1,I,J,K) = 0.0
110            continue
               do 115 I1 = 1,21
                  STKBEG(I1,I,J,K) = 0.0
                  STKEND(I1,I,J,K) = 0.0
115            continue
               STKBEG(0,I,J,K) = 0.0
               STKBEG(22,I,J,K) = 0.0
               STKBEG(23,I,J,K) = 0.0
120         continue
            do 130 I = 1, 3
               YTOT(I,J,K) = 0.0
130         continue
            do 140 I = 1, 32
               YSUMS(I,J,K) = 0.0
140         continue
150      continue
         do 160 I = 1, 10
            MAXSEG(I,K) =  0
            MINSEG(I,K) =  0
            YMIN96(I,K) = 1.0E20
            YMIN21(I,K) = 1.0E20
            YMINLT(I,K) = 1.0E20
            YBAR96(I,K) = -1.0
            YBAR21(I,K) = -1.0
            YBARLT(I,K) = -1.0
            PEAK96(I,K) = -1.0
            PEAK21(I,K) = -1.0
            PEAKLT(I,K) = -1.0
160      continue
170   continue
180   continue
      if (RUNOPT.gt.0) go to 190
      T = 0.0D+00
      MON1 = 1
      if (YEAR1G.le.1) YEAR1G = 1
      FRSTYR = YEAR1G
      LASTYR = FRSTYR+NYEARG-1
      go to 210
190   continue
      if (IFLAG.gt.2) go to 200
      FRSTYR = OLDYR+1
      LASTYR = OLDYR+NYEARG
      MON1 = 1
      IFLAG = 1
      go to 210
200   continue
      if (IFLAG.eq.10) go to 490
      MON1 = MONTHL
      FRSTYR = OLDYR
      IFLAG = 2
      ABEXIT = .true.
210   continue
      do 460 NYR = FRSTYR, LASTYR
         NDAYS(2) = 28
         if (mod(NYR,4).eq.0) NDAYS(2) = 29
         OLDYR = NYR
         if (ABEXIT) go to 220
         IPULSL = 1
         DONE = .true.
         if (IMONG(1).ne.0) DONE = .false.
         call TABE (NYR)
220      continue
         do 450 NDAT = MON1, 12
            MONTHL = NDAT
            call UNPSCR (IBUFF,ABEXIT,NYR)
            if (ABEXIT) go to 360
            NDAYL = 1
            do 230 K = 1, KCHEM
               do 230 J = 1, KOUNT
                  YSUM(J,K) = 0.0
230         continue
            YMONCT = 0.0
240         continue
            if (NDAYS(2).eq.29) go to 260
250         continue
            if (IMONG(IPULSL).ne.2.or.IDAYG(IPULSL).ne.29) go to 260
            IPULSL = IPULSL+1
            if (IMONG(IPULSL).ne.0.and.IPULSL.le.MAXMAS) go to 250
            DONE = .true.
260         continue
            if (DONE.or.IMONG(IPULSL).ne.NDAT) go to 330
            if (IDAYG(IPULSL)-NDAYL) 480, 270, 340
270         continue
            PFIRST = IPULSL
280         continue
            if (IPULSL-MAXMAS) 290, 310, 480
290         continue
            if (IMONG(IPULSL+1).ne.NDAT) go to 300
            if (IDAYG(IPULSL).ne.IDAYG(IPULSL+1)) go to 320
            IPULSL = IPULSL+1
            go to 280
300         continue
            if (IMONG(IPULSL+1)-0) 480, 310, 320
310         continue
            DONE = .true.
320         continue
            PLAST = IPULSL
            IPULSL = IPULSL+1
            call CKICM3 (Y,NYR,PFIRST,PLAST)
            if (IFLAG.eq.10) go to 500
            if (DONE) go to 350
            if (IMONG(IPULSL)-NDAT) 480, 340, 350
330         continue
            TENDL = T+dble(float(24*NDAYS(NDAT)))
            NDAYL = NDAYS(NDAT)
            go to 360
340         continue
            TENDL = T+dble(float(24*(IDAYG(IPULSL)-NDAYL)))
            NDAYL = IDAYG(IPULSL)
            go to 360
350         continue
            TENDL = T+dble(float(24*(NDAYS(NDAT)-NDAYL+1)))
            NDAYL = NDAYS(NDAT)
360         continue
            TINIT = T
            if (.not.ABEXIT) go to 370
            if (int(TENDL-T)) 470, 400, 370
370         continue
            if (STIFEQ) go to 380
            call ADMINT (KEQN,Y,WORK,TINIT,TENDL,TINCRL,RELER,ABSER,
     &         IUNIT,T,IFLAG,TPRINT,IMOVE,FOURU,NPRINT)
            if (IFLAG.eq.2) go to 400
            if (IFLAG.eq.6) go to 380
            go to 470
380         continue
            STIFEQ = .true.
            if (int(TENDL-T)) 470, 400, 390
390         continue
            TINIT = T
            call STFINT (KEQN,Y,WORK,IWORK,TINIT,TENDL,TINCRL,RELER,
     &         ABSER,IUNIT,T,IFLAG,TPRINT,IMOVE,FOURU,NPRINT)
            if (IFLAG.eq.2) go to 400
            go to 470
400         continue
            if (NDAYL-NDAYS(NDAT)) 240, 420, 410
410         continue
            if (NDAYL.ne.29) go to 480
420         continue
            ITEST = 0
            do 430 I = 1, NDAT
               ITEST = ITEST+NDAYS(I)
430         continue
            TOFF = 8760.0D+00*dble(float(NYR-YEAR1G))+dble(float(24*
     &         ((NYR-YEAR1G+mod(YEAR1G+3,4))/4)))
            TOFF = TOFF+dble(float(24*ITEST))
            if (int(T-TOFF)) 240, 440, 480
440         continue
            call ENDMON
450      continue
         call PRICL (NYR)
460   continue
      go to 500
470   continue
      write (TTYOUT(MACHNO),5010) NAMONG(NDAT),NYR
      IUNITG = 1
      write (TTYOUT(MACHNO),5000)
      go to 500
480   continue
      write (TTYOUT(MACHNO),5020)
5020  format (/' System processing error in DRIVM3; RUN aborted.')
      go to 500
490   continue
      write (TTYOUT(MACHNO),5030)
5030  format (' Simulation cannot be CONTINued, because the'/' chemical 
     &loads are so high that the assumptions used to'/' design the EXAMS
     & code have been violated.  The problem'/' must be reRUN with small
     &er chemical loadings.')
500   continue
      ISOO = 0
510   continue
      return
      end
