       !************************************************************************
       !   A Subroutine of Main, reading in the eigenvalues and eigenvectors   *
       !************************************************************************
       
       Subroutine Readeigen (PDBid, SITE, MEIG, vx, vy, vz)
       
       Implicit None
       
! ---- Variables : ---------------------------------------------------------------------------------- !       
       CHARACTER    PDBid*4
       Character    InputPath*200
       Integer      SITE, MEIG
       Real         vx(1:SITE, 1:MEIG), vy(1:SITE, 1:MEIG), vz(1:SITE, 1:MEIG)
       Real         W(1:MEIG) 
       

       Logical      eigvEXIT, slwXEXIT, slwYEXIT, slwZEXIT
       Real         egvlu
       Integer      ios
       
       Real         max, ds
       Integer      i,j, k, jj, ct

! ==== Body of the Subroutine : ===================================================================== !

!       INQUIRE ( FILE=PDBid(1:4)//'.eigvals', EXIST=eigvEXIT, DEFAULTFILE=InputPath )
!       INQUIRE ( FILE=PDBid(1:4)//'.eigvals', EXIST=eigvEXIT )
!       INQUIRE ( FILE=PDBid(1:4)//'.slwX'   , EXIST=slwXEXIT, DEFAULTFILE=InputPath )
       INQUIRE ( FILE=PDBid(1:4)//'.slwX'   , EXIST=slwXEXIT )
!       INQUIRE ( FILE=PDBid(1:4)//'.slwY'   , EXIST=slwYEXIT, DEFAULTFILE=InputPath )
       INQUIRE ( FILE=PDBid(1:4)//'.slwY'   , EXIST=slwYEXIT )
!       INQUIRE ( FILE=PDBid(1:4)//'.slwZ'   , EXIST=slwZEXIT, DEFAULTFILE=InputPath )
       INQUIRE ( FILE=PDBid(1:4)//'.slwZ'   , EXIST=slwZEXIT )
       
!       If(eigvEXIT==.FALSE.) Write(*,'(A,A)') 'ERROR! CAN NOT FIND THE EIGENVALUES  FILE : ', PDBid(1:4)//'.eigvals'
       If(slwXEXIT==.FALSE.) Write(*,'(A,A)') 'ERROR! CAN NOT FIND THE EIGENVECTORS FILE : ', PDBid(1:4)//'.slwX'
       If(slwYEXIT==.FALSE.) Write(*,'(A,A)') 'ERROR! CAN NOT FIND THE EIGENVECTORS FILE : ', PDBid(1:4)//'.slwY'
       If(slwZEXIT==.FALSE.) Write(*,'(A,A)') 'ERROR! CAN NOT FIND THE EIGENVECTORS FILE : ', PDBid(1:4)//'.slwZ'
       
       If( (slwXEXIT==.FALSE.) .OR. (slwYEXIT==.FALSE.) .OR. (slwZEXIT==.FALSE.) ) Stop 
       
!	   OPEN(30, FILE=PDBid(1:4)//'.eigvals', DEFAULTFILE=InputPath)
!	   OPEN(31, FILE=PDBid(1:4)//'.slwX'   , DEFAULTFILE=InputPath)
!	   OPEN(32, FILE=PDBid(1:4)//'.slwY'   , DEFAULTFILE=InputPath)
!       OPEN(33, FILE=PDBid(1:4)//'.slwZ'   , DEFAULTFILE=InputPath)
       
!	   OPEN(30, FILE=PDBid(1:4)//'.eigvals' )
	   OPEN(31, FILE=PDBid(1:4)//'.slwX'    )
	   OPEN(32, FILE=PDBid(1:4)//'.slwY'    )
       OPEN(33, FILE=PDBid(1:4)//'.slwZ'    )       
              
!       READ (30,*) k,egvlu
!       If( (k.NE.1) .or. (egvlu>1.0E-6) ) Stop 'Error! Check the eigenvalue file [xxxx.eigvals] ! (1)'
!       READ (30,*) k,egvlu
!       If( (k.NE.2) .or. (egvlu>1.0E-6) ) Stop 'Error! Check the eigenvalue file [xxxx.eigvals] ! (2)'
!       READ (30,*) k,egvlu
!       If( (k.NE.3) .or. (egvlu>1.0E-6) ) Stop 'Error! Check the eigenvalue file [xxxx.eigvals] ! (3)'
!       READ (30,*) k,egvlu
!       If( (k.NE.4) .or. (egvlu>1.0E-6) ) Stop 'Error! Check the eigenvalue file [xxxx.eigvals] ! (4)'
!       READ (30,*) k,egvlu
!       If( (k.NE.5) .or. (egvlu>1.0E-6) ) Stop 'Error! Check the eigenvalue file [xxxx.eigvals] ! (5)'
!       READ (30,*) k,egvlu
!       If( (k.NE.6) .or. (egvlu>1.0E-6) ) Stop 'Error! Check the eigenvalue file [xxxx.eigvals] ! (6)'
       
!       
!       ios=0
!       ct=0
!       Do while ( ios==0 .AND. ct<MEIG )
!       
!          READ (30,*, iostat=ios) k, egvlu 
!       
!          If( egvlu>1.0E-6 .AND. ios==0 ) Then
!             ct=ct+1
!             W(ct)=egvlu
!          EndIf
!          
!       Enddo
!       
!       If(ct<MEIG) Then
!          Write(*,'(A,I3,A,I4)') 'Warning! The nonzero eigenvalues, ', ct, ' are less than MEIG, ', MEIG
!          Write(*,*) '                      '
!          MEIG=ct
!       EndIf
       
       
!       DO I=1,MEIG
!          READ (30,*, iostat=ios) k, egvlu
!          If(ios.NE.0) Stop 'Error! Check the eigenvalue file [xxxx.eigvals] !'    
!          If( egvlu<1.0E-6 ) Stop 'Error! Check the eigenvalue file [xxxx.eigvals] !'          
!          W(I) = egvlu
!       ENDDO       
       
!       Close(30) ! PDBid(1:4)//'.eigvals'
        
       DO I=1,SITE
           read(31,*) jj, (vx(i,j),j=1,MEIG)
           read(32,*) jj, (vy(i,j),j=1,MEIG)
           read(33,*) jj, (vz(i,j),j=1,MEIG)
       Enddo
	   
	   Close(31) ! PDBid(1:4)//'.slwX'
	   Close(32) ! PDBid(1:4)//'.slwY'
	   Close(33) ! PDBid(1:4)//'.slwZ'
	   
	   Do j=1, MEIG ! N-N-N-N-N-N-N-N-N : Normalization the eigenvectors
	   
	      max = 0.0
	      Do i=1, SITE
	         max =  max + vx(i,j)*vx(i,j) + vy(i,j)*vy(i,j) + vz(i,j)*vz(i,j) 
	      Enddo
	      
	      Do i=1, SITE
	         vx(i,j)=vx(i,j)/Sqrt(max)
	         vy(i,j)=vy(i,j)/Sqrt(max)
	         vz(i,j)=vz(i,j)/Sqrt(max)
	      Enddo
	      
	   Enddo ! j
	   
	   Write(*,'(A)') 'Successfully read in the eigenvectors and eigenvalues files : '
!	   Write(*,'(A)')  PDBid(1:4)//'.eigvals'
	   Write(*,'(A)')  PDBid(1:4)//'.slwX'
	   Write(*,'(A)')  PDBid(1:4)//'.slwY'
	   Write(*,'(A)')  PDBid(1:4)//'.slwZ'
	   Write(*,*) '                      '
! = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 	   
	   Return
	   
	   End
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   
	   