C%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
C-->   Subroutine "nnumber" is used to get the number of       %%%%
C-->   element types in the structure file with format "vasp"  %%%%
C-->                           REFERENCE                       %%%%
C-->   1\ http://muchong.com/html/201011/2567206.html          %%%%
C-->      (note: writed by maomao1210)                         %%%%
C%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
      subroutine nnumber(In,
     &                   Channel,
     &                   ntype)

        Implicit None

        Integer In,Channel,ntype
        Character(Len=100) Temp
        Character(Len=100) Temp_here
        Integer Index_dicp(100)
        Integer Index_here(200)
        Integer Total(100)
        Integer Ldicp,IK,Idicp,Jdicp,Ihere

        Rewind(Channel)

        Do Jdicp=1,In-1
           Read(Channel,*)
        Enddo

        Read(Channel,'(A100)') Temp
        Ihere=Len_trim(Temp)
        
        Temp_here(2:Ihere+2)=Temp(1:Ihere+1)
        Temp_here(1:1)=' ' 
        
        Do Idicp=1,Ihere+2
           If(Temp_here(Idicp:Idicp).Eq.' ') Then    
                Index_here(Idicp)=-1
           Else   
                Index_here(Idicp)=1
           EndIf
        Enddo  
        
        IK=0
        Do Idicp=1,Ihere+2    
           If(Index_here(Idicp)*Index_here(Idicp+1).eq.-1) Then        
                IK=Ik+1
                Total(IK)=Idicp
           EndIf    
        Enddo

        ntype=IK/2
        
        return 
        End

C%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
C%%%%%                    End of nnumber.f                     %%%%
C%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%        
