      subroutine rread1(trad,xlum,lwri,lpri,r,t,xpx,p,lcdd,numrec,npass,
     $ nlimd,rmax,xpxcol,xi,zeta,lfix,
     $ lun11,abel,cfrac,emult,taumax,xeemin,spectype,specfile,specunit,
     $ kmodelname,nloopctl,critf,vturbi,eptmp,zrtmp,numcon2,ncn2,radexp)
c
c     this routine handles reading of the input data.
c     author:  T. Kallman
c
      implicit none
c
      include './PARAM'
c
      real eptmp(ncn),zrtmp(ncn),abel(nl),abel2(30)
      character*8 stringst,kblnk8
      character*80 specfile,spectype,stringsl,kblnk80,stringst2
      character*30 kmodelname
      integer nloopctl,specunit,ierr,ll,lcdd2,lun13,nenergy,ncn2,mm
      integer lwri,lpri,lcdd,numrec,npass,nlimd,lfix,lun11,numcon2
      real trad,xlum,r,t,xpx,p,rmax,xpxcol,xi,zeta,cfrac,emult,taumax,
     $     xeemin,critf,vturbi,ccc,xlum2,xpcol,r19,radexp
c
      data kblnk8/'        '/
      data kblnk80/
     $'                                                                 
     $               '/ 
c
            ierr=0
            call uclgsr('cfrac',cfrac,ierr)
c
c           temperature
            call uclgsr('temperature',t,ierr)
c
c           pressure/density switch
            call uclgsi('lcpres',lcdd2,ierr)
            lcdd=1-lcdd2
c
c           pressure
            call uclgsr('pressure',p,ierr)
c
c           density
            call uclgsr('density',xpx,ierr)
c
c           spectrum
            specfile=kblnk80
            spectype=kblnk80
            stringst2=kblnk80
            specunit=0
            stringst=kblnk8
            call uclgst('spectrum',spectype,ierr)
            xlum=1.
            read (spectype(1:8),'(a8)')stringst
            if (stringst.eq.'file    ') then
              specfile=kblnk80
              call uclgst('spectrum_file',specfile,ierr)
              read (specfile(1:80),'(a80)')stringst2
              call getlun(lun13)
              open (unit=lun13,file=stringst2,status='unknown')
              call uclgsi('spectun',specunit,ierr)
              read (lun13,*)nenergy
              numcon2 = nenergy
              do ll=1,nenergy
                read (lun13,*)eptmp(ll),zrtmp(ll)
                if (specunit.eq.1) zrtmp(ll)=zrtmp(ll)*eptmp(ll)
                enddo
              endif
c
c           trad
            call uclgsr('trad',trad,ierr)
c
c           luminosity
            call uclgsr('rlrad38',xlum,ierr)
c
c           column density
            call uclgsr('column',xpcol,ierr)
c
c           ionization parameter
            call uclgsr('rlogxi',zeta,ierr)
c
c           number of steps
            call uclgsi('nsteps',numrec,ierr)
c
c           number of iterations
            call uclgsi('niter',nlimd,ierr)
c
c           write switch
            call uclgsi('lwrite',lwri,ierr)
c
c           print switch
            call uclgsi('lprint',lpri,ierr)
c
c           step size choice
            call uclgsi('lstep',lfix,ierr)
c
c           abundances
            call uclgsr('habund',abel2(1),ierr)
            call uclgsr('heabund',abel2(2),ierr)
            call uclgsr('liabund',abel2(3),ierr)
            call uclgsr('beabund',abel2(4),ierr)
            call uclgsr('babund',abel2(5),ierr)
            call uclgsr('cabund',abel2(6),ierr)
            call uclgsr('nabund',abel2(7),ierr)
            call uclgsr('oabund',abel2(8),ierr)
            call uclgsr('fabund',abel2(9),ierr)
            call uclgsr('neabund',abel2(10),ierr)
            call uclgsr('naabund',abel2(11),ierr)
            call uclgsr('mgabund',abel2(12),ierr)
            call uclgsr('alabund',abel2(13),ierr)
            call uclgsr('siabund',abel2(14),ierr)
            call uclgsr('pabund',abel2(15),ierr)
            call uclgsr('sabund',abel2(16),ierr)
            call uclgsr('clabund',abel2(17),ierr)
            call uclgsr('arabund',abel2(18),ierr)
            call uclgsr('kabund',abel2(19),ierr)
            call uclgsr('caabund',abel2(20),ierr)
            call uclgsr('scabund',abel2(21),ierr)
            call uclgsr('tiabund',abel2(22),ierr)
            call uclgsr('vabund',abel2(23),ierr)
            call uclgsr('crabund',abel2(24),ierr)
            call uclgsr('mnabund',abel2(25),ierr)
            call uclgsr('feabund',abel2(26),ierr)
            call uclgsr('coabund',abel2(27),ierr)
            call uclgsr('niabund',abel2(28),ierr)
            call uclgsr('cuabund',abel2(29),ierr)
            call uclgsr('znabund',abel2(30),ierr)
            do mm=1,nl
              abel(mm)=abel2(mm)
              enddo
c
c
            call uclgsi('npass',npass,ierr)
C           Test if npass is even.  If it is, change it to next lowest odd
c            if(mod(npass,2) .eq. 0) then
c              write(lun11,*)'rread1: npass should always be odd.'
c              write(lun11,*)'rread1: resetting to ',npass-1
c              npass=npass-1
c            endif

            stringsl=kblnk80
            call uclgst('modelname',stringsl,ierr)
            read (stringsl(1:30),'(a30)')kmodelname
c
c
c           step parameters
            call uclgsr('emult',emult,ierr)
            call uclgsr('taumax',taumax,ierr)
c
c           min xee
            call uclgsr('xeemin',xeemin,ierr)
c
c           critf
            call uclgsr('critf',critf,ierr)
c
c           vturbi
            call uclgsr('vturbi',vturbi,ierr)
c
c           ncn2
            call uclgsi('ncn2',ncn2,ierr)
            ncn2=max(999,min(99999,ncn2))
            if (ierr.ne.0) ncn2=9999
c
c           radexp
            call uclgsr('radexp',radexp,ierr)
            if (ierr.ne.0) radexp=0.
c
            call uclgsi('loopcontrol',nloopctl,ierr)
c
c
            ccc = 3.e+10
            xlum2=xlum
            xpxcol=xpcol
            xi=10.**zeta
            if (lcdd.ne.1) then
               xpx = p/1.38e-12/amax1(t,1.e-24)
               r19 = sqrt(xlum2/12.56/ccc/amax1(1.e-24,p*xi))
            else
               r19 = sqrt(xlum2/amax1(1.e-24,xpx*xi))
            endif
            rmax = xpxcol/(amax1(xpx,1.e-36))
            r = r19*(1.e+19)
c
      return
      end
