! mm
! ----------------------------------------------------------------------- !
      SUBROUTINE rdfile(nproc) 
! ----------------------------------------------------------------------- !
! Purpose: Reading in of data for multi-component calculations and
!          spawning of atomic kinetic elements
!
! ----------------------------------------------------------------------- !
      USE communicate          ! cmytid
      USE gmm
      USE ttime
      USE stopwatch
     
      implicit none

      integer :: i
      integer :: nproc
      integer :: unitnum
      character(len=30)  ctemp
      character(len=70)  envstring
      character(len=10)  cmytid
      external fbuff
      external envarc

      cmytid = get_cmytid()
      istdout = 1
      i = 0
      ilast = 0
      nproc = 0
      sumfrac=0.0   
      dne = 0.0
      itimesteps = 0

      envstring = 'WORKDIR'
      unitnum = 20
      ctemp = 'srmacm.in'
!     write(istdout,*) '**************************************************'
      call openf(unitnum,ctemp,envstring)    ! OPEN(unit=20)

      READ(20,*)
      if(itd.eq.1)then 

        envstring = 'WORKDIR'
        unitnum = 26
        ctemp = 'srmacm.out'//cmytid
        call openf(unitnum,ctemp,envstring)  ! OPEN(unit=26) 

        envstring = 'WORKDIR'
        unitnum = 21
        ctemp = 'srmac.col.out'//cmytid
        call openf(unitnum,ctemp,envstring)  ! OPEN(unit=21)

        WRITE(21,'(a45)')'# itimesteps  dna  dne  te  Time(nsec)  ztot '

      endif 

      READ(20,'(I5)') maxiter
!     WRITE(istdout,*) 'maxiter=',maxiter
      READ(20,'(I5)') idiag
!     WRITE(istdout,*) 'idiag=',idiag
      READ(20,'(E14.7)') eps
!     WRITE(istdout,*) 'eps=',eps
      READ(20,'(E14.7)') t
!     WRITE(istdout,*) 't=',t
      READ(20,'(E14.7)') dna
!     WRITE(istdout,*) 'dna=',dna
      READ(20,'(E14.7)') hnu1
!     WRITE(istdout,*) 'hnu1=',hnu1
      READ(20,'(E14.7)') hnu2
!     WRITE(istdout,*) 'hnu2=',hnu2
      READ(20,'(E14.7)') fwhm
!     WRITE(istdout,*) 'fwhm=',fwhm
      READ(20,'(1x,i1)') itd 
!     WRITE(istdout,*) 'itd=',itd 
10    CONTINUE      
         READ(20,*,END=20)
         READ(20,'(1x,a2)',END=20) auxelmt
!        WRITE(istdout,*)'auxelmt= ',auxelmt
         elmt((i*2+1):(i*2+2)) = auxelmt
         READ(20,'(E14.7)',END=20) zbarinit(i)
!        WRITE(istdout,*) 'zbarinit(',i,')=',zbarinit(i)
         READ(20,'(E14.7)',END=20) fracspec(i)
!        WRITE(istdout,*) 'fracspec(',i,')=',fracspec(i)
!        dne = dne+(dna*fracspec(i)) * zbarinit(i)
!        fdna(i)=dna*fracspec(i)
!        sumfrac = sumfrac+fracspec(i)
         nproc = nproc + 1
         i=i+1
      GOTO 10
20    CONTINUE
!     write(istdout,*) '**************************************************'
      CLOSE(20)

! -- Time Dependent Input

      IF(itd .EQ. 1)THEN

          iprint = 1
          nnn = 1
          
          envstring = 'WORKDIR'
          unitnum = 20
          ctemp = 'srmacm_td.in'
          call openf(unitnum,ctemp,envstring)    ! OPEN(unit=20)

          READ(20,*)
          READ(20,'(1x,1pe14.7)') tinitial
!         WRITE(istdout,*) 'tinitial=',tinitial 
          READ(20,'(1x,1pe14.7)') tfinal
!         WRITE(istdout,*) 'tfinal=',tfinal
          READ(20,'(1x,i5)') nprints
!         WRITE(istdout,*) 'nprints=',nprints 
          READ(20,'(1x,i5)') ntsteps
!         WRITE(istdout,*)'ntsteps=',ntsteps
          READ(20,'(1x,1pe15.8)') dne
!         WRITE(istdout,*)
          WRITE(istdout,*) '!!!!  WARN: CHECK DNE VALUE  !!!!'
          WRITE(istdout,'(6x,a5,1pe14.7)') ' dne= ',dne
          WRITE(istdout,*) '!!!!  WARN: CHECK DNE VALUE  !!!!'
!         WRITE(istdout,*)'   '
!         WRITE(istdout,*)'Reading srmacm_td.in complete'
!         WRITE(istdout,*)'   '
          CLOSE(20)

          steptp=(tfinal-tinitial)/(nprints-1)
          DO i=1,nprints
             timep(i)=tinitial+(i-1)*steptp
             WRITE(istdout,*)'timep(',i,')=',timep(i)
          ENDDO

! -- Read in sub timehist
          envstring = 'WORKDIR'
          unitnum = 22
          ctemp = 'srmacm_thist.in'
          call openf(unitnum,ctemp,envstring) ! OPEN(unit=22) 

          CALL timehist(tinitial,tfinal)
!         WRITE(istdout,*)'    '
!         WRITE(istdout,*)'Reading Time History Complete'
!         WRITE(istdout,*)'    '
          CLOSE(22)

          deltat=(timep(iprint+1)-timep(iprint))/ntsteps
          time=timep(iprint)+nnn*deltat
      ENDIF
!     WRITE(istdout,*)'deltat =',deltat
!     WRITE(istdout,*)'dne    =',dne
!     WRITE(istdout,*)'time   =',time
!     call fbuff () 
      end
