      program EXAMS
      include 'SIZE.INC'
      include 'GLOBAL.INC'
      include 'INPAR.INC'
      include 'LOCAL.INC'
      include 'UNITS.INC'
      double precision Y
      dimension Y(NPX,NCHEM)
      real SUM
      integer CMD,OUTLUN,HOPT,RUNOPT,III,IV,VRAIL,I,IT,IS,MODIFY,ONE
      character FNAME*52,DIR*40
      data ONE/1/
      LOGICAL NOKILL
      NOKILL = .TRUE.
      call under0(NOKILL)
      if (MACHNO.eq.11) then
         FNAME = 'F:\EXAMS\DFINICON\EXAMDAF.DSI'
      else
         FNAME = 'EXAMS.DAF'
      endif
      call ZERO (Y,ONE)
      call ANNOUN
         open (unit=RANUNT(MACHNO),file=FNAME,status='old',
     &   recl=LENREC, access='direct', form='UNformatted')
      do 110 I = 1, NCHEM
         call UNPAK (ONE,I)
110   continue
      call UNPENV (ONE)
      call UNPLDS (ONE)
      call UNPPRO (ONE)
      IRUN = 0
120   continue
      call WHTCMD (CMD)
      if (CMD.lt.1.or.CMD.gt.26) go to 130
      go to (140,150,170,180,220,230,250,260,280,290,300,310,320,330,
     &   340,350,360,370,280,410,430,440,450,460,470,480), CMD
130   continue
      write (TTYOUT(MACHNO),9110)
9110  format (/' EXAMS system error.  Please try again.')
140   continue
      call NEWNAM (0)
      go to 120
150   continue
      call SHOW (IT,IS)
      if (IT.eq.8) go to 400
      if (IS.ne.0) go to 160
      if (IT.ne.0) then
         BATCH = 1
         call CONTRL (Y,RUNOPT,IT)
         go to 120
      endif
160   continue
      call PRTMSG (IS+4)
      go to 120
170   continue
      go to 220
180   continue
      call RUNIT (Y,SUM)
      RUNOPT = 0
      if (IRUN.eq.1) go to 190
      write (TTYOUT(MACHNO),9120)
9120  format (' Simulation not executed.')
      go to 120
190   continue
200   continue
      III = VRAIL(ECONAM)
      write (TTYOUT(MACHNO),9130) (ECONAM(IV),IV=1,III)
9130  format (/' Simulation beginning for: '/' Environment: ',50A1)
      do 210 I = 1, KCHEM
         III = VRAIL(CHEMNA(1,I))
         write (TTYOUT(MACHNO),9140) I,(CHEMNA(IV,I),IV=1,III)
9140     format (' Chemical ',I2,': ',50A1)
210   continue
      close (unit=RANUNT(MACHNO))
      BATCH = 0
      call CONTRL (Y,RUNOPT,0)
         open (unit=RANUNT(MACHNO), file=FNAME, status='old',
     &   recl=LENREC, access='direct', form='UNformatted')
      write (TTYOUT(MACHNO),9150)
9150  format (/' RUN command completed.'/)
      FIXFIL = 1
      IRUN = 1
      go to 120
220   continue
      go to 490
230   continue
      HOPT = 0
240   continue
      call HELP (HOPT)
      go to 120
250   continue
      if (FIXFIL.eq.0) go to 400
      OUTLUN = PRINTR(MACHNO)
      IT = 1
      go to 270
260   continue
      if (FIXFIL.eq.0) go to 400
      OUTLUN = TTYOUT(MACHNO)
      IT = 0
270   continue
      call LIST (OUTLUN,IT)
      go to 120
280   continue
      IT = MODIFY(I)
      call PRTMSG (IT+4)
      go to 120
290   continue
      if (FIXFIL.eq.0) go to 400
      call PLOTX (FIXFIL,MCHEMG)
      go to 120
300   continue
      call NEWNAM (1)
      go to 120
310   continue
      HOPT = 1
      go to 240
320   continue
      call STORE
      go to 120
330   continue
      call RECALL
      go to 120
340   continue
      call ERASE
      go to 120
350   continue
      call AUDOPT
      go to 120
360   continue
      call ZERO (Y,0)
      go to 120
370   continue
      if (MODEG.eq.2.or.MODEG.eq.3) go to 380
      write (TTYOUT(MACHNO),9160)
9160  format (//' The CONTINUE command cannot be issued until'/         
     &   ' MODE 2 or 3 has been selected.'//)
      go to 120
380   continue
      if (IRUN.eq.1) go to 390
      write (TTYOUT(MACHNO),9170)
9170  format (//' A simulation must be RUN before the'/                 
     &   ' CONTINUE command can be issued.'/)
      go to 120
390   continue
      call CONTIN (I)
      if (I.eq.1) go to 120
      RUNOPT = 1
      go to 200
400   continue
      write (TTYOUT(MACHNO),9180)
9180  format (/                                                         
     &' A PRINT, LIST, or PLOT command was issued before executing'/    
     &' a RUN.  If results exist from a previous simulation, these'/    
     &' can be accessed after issuing the command:'//                   
     &10X,' SET FIXFIL TO 1'//)
      go to 120
410   continue
      if (DOFLAG.eq.0) go to 420
      write (TTYOUT(MACHNO),9190)
9190  format (//' Nesting of DO files not supported.'//)
      go to 120
420   continue
      call DOIT
      go to 120
430   continue
      call NEWNAM (3)
      go to 120
440   continue
      call NEWNAM (2)
      go to 120
450   continue
      call CATLG
      go to 120
460   continue
      call READER
      go to 120
470   continue
      call WRITER
      go to 120
480   continue
      call SETPSW
      go to 120
490   continue
      stop
      end
