      subroutine input

      include 'global.inc'

! READ-IN:
! *** **************************************************************
      open(5,file='gcmc_H2.dat',status='old')
     
      Read (5,*) Tmas        ! molar mass (in kg)
      READ (5,*) TEMP 
      READ (5,*) PBAR 	          ! pressure in Bars   
          PRESS = PBAR / (0.138033e3)	  ! Convert press (in kbar) to (K/A**3)
      READ (5,*) N           ! number of molecules in MC pore (initial)
      IF (N.LE.0) STOP 'Error: Number of molecules not correct !!!'

         npart = N           ! npart - current number of molecules
	                           
      READ (5,*)				! empty
      READ (5,*) nexc 		! nexc  - number of attempts to exchange
      READ (5,*) ncycle		! ncycle - number of cycles per step
      READ (5,*) NSTEP	! number of steps per bin  
      READ (5,*) NBIN		! NBIN - number of bins.The output after bin.

	if(NBIN.gt.NBmax) NBIN=NBmax ! check of maximum bin number

      READ (5,*)				! empty
      READ (5,*) TD   		! stepsize for a translational atom move
      READ (5,*) OD			! stepsize for a orientational moves
      READ (5,*) STEPTST
      READ (5,*) CTOF	        ! the CUT-OFF range (in angstroms)

      close(5)

!		STEPTST - a test to stop moving the step size 
!               when the final averages are done
!               to maintain a uniform sampling of space.
!               STEPTST.LT.0.01 implies STOP

		TD2 = TD + TD
		OD2 = OD + OD


		CTOFS = CTOF * CTOF            

! *** ***************************************************************
! *** READ-IN: additional INPUT parameters file

      open(5,file='gcmc_H2_par.dat',status='old')

      READ (5,*) ISEED 	   ! initial seed for random number generator
      READ (5,*) UPDATENB	   ! number of steps to be updated
      READ (5,*) MX		   ! if Mx.ne.0 we exchange particles
      READ (5,*)				! empty

      READ (5,*) xpore		!xpore, ypore and zpore (in Angtroms)
	READ (5,*) ypore		!the MC pore size 
      READ (5,*) zpore	   
      READ (5,*)				! empty

	READ (5,*) n_inter     ! number of intermolecular splines
	READ (5,*) n_wall      ! number of wall splines
	READ (5,*) n_Molec     ! number of atoms in molecule
							! if =0 or 1, UAtom model 
	close(5)

! *** *********************************************************
! READ-IN the coordinates of gas molecules  xC,yC,zC 	 

      open(15,file='pos_inp.dat', status='old')

	read(15,*) N_in				 ! number of positions in the file
	Nnew_in = 0
      do I = 1,N_in 

         READ (15,*) xcmp,ycmp,zcmp   ! in A 
	   if((abs(xC(I)).lt.xpore).and.(abs(yC(I)).lt.ypore))then
	   if((zcmp.lt.(zpore-2.5)).and.(zcmp.gt.2.5))then
	     Nnew_in = Nnew_in + 1 
	   	 xC(Nnew_in) = xcmp		  !only the positions in the box
	   	 yC(Nnew_in) = ycmp		  !are taken into account
	   	 zC(Nnew_in) = zcmp		  !as initial
	   endif
	   endif
	     
      enddo   
	Npart = Nnew_in
      close(15)

	N_if_orn = 0          ! if it stays 0, no molecule
      if(n_Molec.ge.2) then
        open(18,file='orn_inp.dat', status='old')
	  read(15,*) N_if_orn		
        do I = 1,Nnew_in 
	    read (18,*) u(i),v(i),w(i)
	  enddo
	  close(18)
	endif

! *** *********************************************************
! READ-IN spline coefficients for inter-particle interaction

      open(16, file='spline_H2.inp',status='old')
      open(17, file='spline_wall.inp',status='old')

!      read(16,*) Msp
!	if(Msp.gt.MS) Stop 'Error: spline parameter Msp exeeds MS'
	Msp = MS

	do k = 1,n_inter
      do i = 1,Msp
        read(16,*)R2(i,k) ,(CS(j,i,k) ,j=1,4)  ! input in A**2   
	enddo
	enddo

	do k = 1,n_wall
      do i = 1,Msp
        read(17,*)R2w(i,k),(CSw(j,i,k),j=1,4)  ! input in A**2   
	enddo
	enddo

      close(16)
	close(17)

       print *, ' read-in spline'


      end
