      subroutine READER
      include 'SIZE.INC'
      include 'GLOBAL.INC'
      include 'LOCAL.INC'
      include 'UNITS.INC'
      include 'INPAR.INC'
      double precision YDUMMY(NPX,NCHEM)
      integer WHICH, NORESP(5), MNRESP(5), NUMANS(2), MINANS(2), EOF
     &, TWO, THREE, FOUR, FIVE, INUNIT, IMBED, MATCH, RSPSIZ, ANSIZ
      logical CHEM, ENV, PRZM
      character CHEM1(NCHEM)*3, QQQ*3, ANSWER(8)*1, RESP(31)*1, BLANK*1
      character REQFMT(2)*61
      data REQFMT(1)
     &/'(/1X,''Enter Environment, Chemical, PRZM, Help, or Quit-> ''  )'
     &/
      data REQFMT(2)
     &/'(/1X,''Enter name of file, Help, or Quit-> ''           )'/
      data RESP  /'C','H','E','M','I','C','A','L'
     &,'E','N','V','I','R','O','N','M','E','N','T'
     &,'P','R','Z','M'
     &,'H','E','L','P', 'Q','U','I','T'/
      data BLANK /' '/
      data NORESP, MNRESP,RSPSIZ /8,11,4,4,4, 1,1,1,1,1, 31/
      data CHEM1(1), QQQ /'QQQ','QQQ'/
      data ANSWER/'H','E','L','P', 'Q','U','I','T'/
      data NUMANS, MINANS, ANSIZ /4,4, 1,1, 8/
      data TWO, THREE, FOUR, FIVE /2, 3, 4, 5/
      CHEM = .false.
      ENV  = .false.
      PRZM = .false.
      INUNIT = TTYIN(MACHNO)
      REQFMT(1)(59:60) = CRSTOP(MACHNO)
      REQFMT(2)(44:45) = CRSTOP(MACHNO)
      START = IMBED(INPUT,STOPIT)
      if (START.ne.-999) go to 110
100   continue
      write (TTYOUT(MACHNO),REQFMT(1))
      call INREC (EOF,INUNIT,INPUT)
      if (EOF.eq.1) go to 180
      START = IMBED(INPUT,0)
      if (START.eq.-999) go to 100
110   continue
      call SKAN (INPUT,START,STOPIT,TYPE,BLANK,1)
      if (TYPE.eq.100) STOPIT = 81
      WHICH = MATCH(FIVE,RSPSIZ,NORESP,RESP,MNRESP)
      if (WHICH.eq.0) then
         write (TTYOUT(MACHNO),5000)
5000     format (/' Response not recognized, please try again...')
         go to 100
      endif
      go to (130,130,130,120,200), WHICH
120   continue
      write (TTYOUT(MACHNO),5010)
5010  format (/                                                         
     &' The READ command is used to load the Activity Data Base (ADB,'/ 
     &' or foreground memory) from a special data file on your disk.'/  
     &' In response to the prompt, indicate one of the following'//     
     &' C to load Chemical data,'/                                      
     &' E to load Environmental data,'/                                 
     &' P to load a PRZM output file as EXAMS loadings,'/               
     &' or Quit to return to the EXAMS prompt.')
      go to 100
130   continue
      if (WHICH.eq.1) then
         CHEM = .true.
      elseif (WHICH.eq.2) then
         ENV = .true.
      else
         PRZM = .true.
      endif
      START = IMBED(INPUT,STOPIT)
      if (START.ne.-999) go to 150
140   continue
      write (TTYOUT(MACHNO),REQFMT(2))
      call INREC (EOF,INUNIT,INPUT)
      if (EOF.eq.1) go to 180
      START = IMBED(INPUT,0)
      if (START.eq.-999) go to 140
150   continue
      call SKAN (INPUT,START,STOPIT,TYPE,BLANK,1)
      if (TYPE.eq.100) STOPIT = 81
      WHICH = 1+MATCH(TWO,ANSIZ,NUMANS,ANSWER,MINANS)
      go to (170,160,200), WHICH
160   continue
      write (TTYOUT(MACHNO),5020)
5020  format (/' In response to the prompt, enter the full name of the'/
     &' file you want to READ into the ADB.  If you want to'/' terminate
     & the READ and return to the EXAMS prompt,'/' instead respond to th
     &e prompt with "Quit".')
      if (MACHIN.eq.'IBM') then
         if (CHEM) write (TTYOUT(MACHNO),5030)
         if (ENV) write (TTYOUT(MACHNO),5040)
      endif
5030  format (' You can only read files that have been allocated in your
     &'/' JCL.  If you are using the JCL supplied with the program,'/' f
     &iles of chemical data should be named CHEMn,'/' where "n" is any i
     &nteger.')
5040  format (' You can only read files that have been allocated in your
     &'/' JCL.  If you are using the JCL supplied with the program,'/' f
     &iles of environmental data should be named ENVIRn,'/' where "n" is
     & any integer.')
      go to 140
170   continue
      FILNAM(2) = INPUT(START:STOPIT-1)
      if (CHEM) then
         open (unit=CHELUN(MACHNO),status='OLD',access='SEQUENTIAL',form
     &      ='FORMATTED',err=190,FILE=FILNAM(2))
         if (.not.(TOPOPN(MACHNO))) rewind CHELUN(MACHNO)
         call INITL (YDUMMY,TWO)
         call CHEMIN (CHEM1)
      elseif (ENV) then
         open (unit=ENVLUN(MACHNO),status='OLD',access='SEQUENTIAL',form
     &      ='FORMATTED',err=190,FILE=FILNAM(2))
         if (.not.(TOPOPN(MACHNO))) rewind ENVLUN(MACHNO)
         call INITL (YDUMMY,THREE)
         call ENVIN (QQQ)
      elseif (PRZM) then
         open (unit=PRZLUN(MACHNO),status='OLD',access='SEQUENTIAL',form
     &      ='FORMATTED',err=190,FILE=FILNAM(2))
         if (.not.(TOPOPN(MACHNO))) rewind PRZLUN(MACHNO)
         call INITL (YDUMMY,FOUR)
         call PRZMIN
      endif
      go to 200
180   continue
      write (TTYOUT(MACHNO),5050)
5050  format (/' End-of-file marker encountered while reading input.')
      go to 200
190   continue
      write (TTYOUT(MACHNO),5060)
5060  format (/' Error opening disk file; command aborted.')
200   continue
      return
      end
