! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Function: ChainIndex(A)
!       Function, return a number for a given chain ID       
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Function: ChainIndex(A)
 
        Function ChainIndex(A) 
        
        Character*1 A
        Integer     ChainIndex
        Integer     Ichain
       
        Ichain=ICHAR(A)
        If( (65<=Ichain) .AND. (Ichain<=90) ) Then
   	        Ichain=ICHAR(A)-64 
        Else If ((48<=Ichain) .AND. (Ichain<=57) ) Then
   	        Ichain=ICHAR(A)-21
        Else If (A==' ') Then
            IChain=1
        Else
   	        Ichain=0
        EndIf
        
        ChainIndex=Ichain
        
        Return
        End
! # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Function: ChainIndex(A)
        

! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=Function: ChainName(I)
!       Function, return a Letter for a given chain number
! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=Function: ChainName(I)
 
        Function ChainName(I) 
        
        Character*1 ChainName
        Integer     I
               
        If( (1<=I) .AND. (I<=26) ) Then
   	        ChainName=CHAR(I+64)
        Else If ( (27<=I) .AND. (I<=36) ) Then
   	        ChainName=CHAR(I+21)
        Else
   	        ChainName=CHAR(63)
        EndIf        
        
        Return
        End
! +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=Function: ChainName(I)
        


! ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^ Function: SheetIndex(SheetID,MaxSheet,SheetName)
!       Fuction, return a Sheet number, for a given SheetID
! ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^ Function: SheetIndex(SheetID,MaxSheet,SheetName)

        Function SheetIndex(ID,MaxSheet,SheetName)
        
        Implicit None
        
        Integer      SheetIndex          ! Fuction, return a Sheet number, for a given ID
        Character*3  ID                  ! Sheet identifier.
        Integer      MaxSheet
        Character*3  SheetName(MaxSheet) ! The database for storing the sheet ID
        
        Integer      flag, exist, i, k
        
        exist=2
        flag=1
        i=0
        Do while(flag==1)
           
           i=i+1
           
           If(i>MaxSheet) Stop 'Error! MaxSheet too small! In the scanning part you need set up a higher Possiable Max Sheet value! '        
           
           If(SheetName(i)==ID) Then
              exist=1
              flag=0
           EndIF
           
           IF(SheetName(i)=='***') Then
              SheetName(i)=ID
              flag=0
              exist=0
           EndIF
           
        Enddo
        
        
        IF( (exist==1).OR.(exist==0) )Then
        
           Do k=1, MaxSheet
             If( ID==SheetName(k) ) SheetIndex=k
           Enddo           
           
        Else  
        
           Stop 'Error! In the function of SheetIndex! (ID,MaxSheet,SheetName) '
           
        EndIF
        
        Return
        End
! ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^ Function: SheetIndex(SheetID,MaxSheet,SheetName)
         