      subroutine CONTRL(Y,RUNOPT,IT)
      include 'SIZE.INC'
      include 'GLOBAL.INC'
      include 'LOCAL.INC'
      include 'UNITS.INC'
      include 'INPAR.INC'
      include 'LOCAL1.INC'
      double precision Y(KOUNT,KCHEM)
      integer RUNOPT,IT,K,J
      character DUMMY*1
      if (BATCH.ne.0) then
         call GHOST(Y,IT)
         go to 160
      endif
      if (RUNOPT.eq.0) then
         if (MACHNO.eq.11) then
            open (unit=RPTLUN(MACHNO),status='new',access='sequential',
     &         form='formatted',FILE='REPORT.XMS',err=140)
         else
      open (unit=RPTLUN(MACHNO),status='unknown',access='sequential',
     &form='formatted',FILE='REPORT.XMS',err=140)
            if (.not.(TOPOPN(MACHNO))) rewind RPTLUN(MACHNO)
         endif
         do 100 K = 1, KCHEM
            do 100 J = 1, KOUNT
               Y(J,K) = 0.0D+00
100      continue
      elseif (RUNOPT.eq.1) then
         open (unit=RPTLUN(MACHNO),status='old',access='sequential',form
     &      ='formatted',FILE='REPORT.XMS',err=140)
         if (TOPOPN(MACHNO)) then
110         continue
            read (RPTLUN(MACHNO),5000,end=120) DUMMY
            go to 110
120         continue
            backspace RPTLUN(MACHNO)
5000        format (1A1)
         endif
      else
         write (TTYOUT(MACHNO),5010) RUNOPT
5010  format (' System processing error in "contrl"--"runopt" =',I2,'!'/
     &' Command cancelled; please report the',/' problem to the author.'
     &)
         go to 160
      endif
      open (WRKLUN(MACHNO),access='direct',form='unformatted',status='sc
     &ratch',recl=LENREC,err=150)
      call GHOST (Y,IT)
      if (IFLAG.ge.8) go to 130
      call DRIVER (Y,RUNOPT)
      if (IFLAG.gt.2.and.MODEG.ne.1) then
         write (TTYOUT(MACHNO),5020) IFLAG
5020     format (' Results cannot be analyzed; IFLAG =',I2)
         go to 130
      endif
      if (MODEG.eq.1) then
         call SUMUP
      elseif (MODEG.eq.2) then
         call M2AVE (Y)
         call M2FLUX (Y)
      elseif (MODEG.eq.3) then
         call M3AVE
         call M3FLUX
      else
         write (TTYOUT(MACHNO),5030) MODEG
5030     format (' Results cannot be analyzed; MODE =',I2)
      endif
130   continue
      close (unit=WRKLUN(MACHNO))
      endfile RPTLUN(MACHNO)
      close (unit=RPTLUN(MACHNO))
      go to 160
140   continue
      write (TTYOUT(MACHNO),5040)
5040  format (' Error opening report file; command cancelled.')
      go to 160
150   write (TTYOUT(MACHNO),5050)
5050  format (' Error opening working files; command cancelled.')
      close (unit=RPTLUN(MACHNO))
160   return
      end
