!      %***************************************************************************************%
!      *             Subroutine of Main, locating the common range of structure A & B          *
!      %***************************************************************************************%

       Subroutine CommonRange ( lmtA, lmtB, lmtC, SITE_A, SITE_B, SITE )
       
       Implicit None
       
! ---- Variables : ---------------------------------------------------------------------------------- !       
       Integer     lmtA(4,2)   ! Range of Structure A
       Integer     lmtB(4,2)   ! Range of Structure B
       Integer     lmtC(4,2)   ! Range of Common 
       
       Integer     SITE_A, SITE_B, SITE
        
! ---- Variables : ---------------------------------------------------------------------------------- !       
       Integer     MinModel_A, MinChain_A, MinResidue_A, MinAtom_A  ! The initial Min value is set to an extreme big value
       Integer     MaxModel_A, MaxChain_A, MaxResidue_A, MaxAtom_A  ! The initial Max value is set to an extreme small value

       Integer     MinModel_B, MinChain_B, MinResidue_B, MinAtom_B  ! The initial Min value is set to an extreme big value
       Integer     MaxModel_B, MaxChain_B, MaxResidue_B, MaxAtom_B  ! The initial Max value is set to an extreme small value
       
       Integer     MinModel, MinChain, MinResidue, MinAtom  ! The initial Min value is set to an extreme big value
       Integer     MaxModel, MaxChain, MaxResidue, MaxAtom  ! The initial Max value is set to an extreme small value
       
       
! ---- Variables : ---------------------------------------------------------------------------------- !       
       Integer     k, j, i, s, ct, n
       
       
! ==== Body of Subroutine CommonRange =============================================================== !
     
       MinModel_A    =  lmtA(1,1)
       MaxModel_A    =  lmtA(1,2)
       MinChain_A    =  lmtA(2,1)
       MaxChain_A    =  lmtA(2,2)
       MinResidue_A  =  lmtA(3,1)
       MaxResidue_A  =  lmtA(3,2)
       MinAtom_A     =  lmtA(4,1)
       MaxAtom_A     =  lmtA(4,2)
                       
       MinModel_B    =  lmtB(1,1)
       MaxModel_B    =  lmtB(1,2)
       MinChain_B    =  lmtB(2,1)
       MaxChain_B    =  lmtB(2,2)
       MinResidue_B  =  lmtB(3,1)
       MaxResidue_B  =  lmtB(3,2)
       MinAtom_B     =  lmtB(4,1)
       MaxAtom_B     =  lmtB(4,2)
                                               
       If( MinModel_A<MinModel_B ) Then
             MinModel = MinModel_B
       Else
             MinModel = MinModel_A
       EndIF

       If( MaxModel_A<MaxModel_B ) Then
             MaxModel = MaxModel_A
       Else
             MaxModel = MaxModel_B
       EndIF
       
       If( MinChain_A<MinChain_B ) Then
             MinChain = MinChain_B
       Else
             MinChain = MinChain_A
       EndIF

       If( MaxChain_A<MaxChain_B ) Then
             MaxChain = MaxChain_A
       Else
             MaxChain = MaxChain_B
       EndIF
         
       If( MinResidue_A<MinResidue_B ) Then
             MinResidue = MinResidue_B
       Else
             MinResidue = MinResidue_A
       EndIF

       If( MaxResidue_A<MaxResidue_B ) Then
             MaxResidue = MaxResidue_A
       Else
             MaxResidue = MaxResidue_B
       EndIF

       If( MinAtom_A<MinAtom_B ) Then
             MinAtom = MinAtom_B
       Else
             MinAtom = MinAtom_A
       EndIF

       If( MaxAtom_A<MaxAtom_B ) Then
             MaxAtom = MaxAtom_A
       Else
             MaxAtom = MaxAtom_B
       EndIF
     
       If( SITE_A < SITE_B ) Then
             SITE=SITE_B
       Else
             SITE=SITE_A
       ENDIF
       

       
       Write(*,*) '                                                           '
       Write(*,'(A)') '==============================================================='
       Write(*,'(A,I5,A,I5)') 'Model   Range  : ', MinModel,  ' to ', MaxModel
       Write(*,'(A,I5,A,I5)') 'Chain   Range  : ', MinChain,  ' to ', MaxChain
       Write(*,'(A,I5,A,I5)') 'Residue Range  : ', MinResidue,' to ', MaxResidue
       Write(*,'(A,I5,A,I5)') 'Atom    Range  : ', MinAtom,   ' to ', MaxAtom
       Write(*,'(A)') '==============================================================='
       Write(*,*) '                                                           '       
       
       lmtC(1,1)=MinModel
       lmtC(1,2)=MaxModel
       lmtC(2,1)=MinChain
       lmtC(2,2)=MaxChain
       lmtC(3,1)=MinResidue
       lmtC(3,2)=MaxResidue
       lmtC(4,1)=MinAtom
       lmtC(4,2)=MaxAtom
       
       
       
! =====E==N===D====================================================================================== !
       Return
       End           
       
