       !************************************************************************
       !   A Subroutine of Main, reading in the Head Part of the PDB file      *
       !************************************************************************
       
       Subroutine HeadPDB(PDBid, PDBRecord, Line)

       Implicit None

! ---- Variables : -------------------------------------------------------------- !       
       Character*4  PDBid
       
       Character    CHead*6, CMark*3, CLine*80
       Integer      RecordType ! each section in PDB file is assigned a RecordType

       Character    PDBRecord(100,5000)*80 ! Recording the content of each line : PDBRecord(RecordType, Line#) 
       Integer      Line(100)              ! The line number of each RecordType : Line(RecordType)
       
       Integer      i
! ------------------------------------------------------------------------------- !
       
!===================================! Initializing

       Do i=1, 100
          Line(i)=0
       Enddo       
       
!+++++++++++++++++++++++++++++++++++! Begin Reading       

       Open(12, file=PDBid(1:4)//'.pdb')  
       

610	   READ(12,'(A6,1x,A3)',END=660) CHead, CMark

       IF( (CHead=='ATOM  ').OR.(CHead=='END   ').OR.(CHead=='ENDMDL') ) GOTO 660 !============End of File, jump to 660
       
       RecordType=0
       If ( (CHead=='HEADER').OR.(CHead=='TITLE ')                                            ) RecordType=1 ! Title Section
       If ( (CHead=='REMARK').AND.( CMark=='350' )                                            ) RecordType=2 ! /REMARK 350   BIOMT* **** ..../    
       If ( (CHead=='DBREF ').OR.(CHead=='SEQADV').OR.(CHead=='SEQRES').OR.(CHead=='MODRES')  ) RecordType=3 ! Primary Structure Section
       If ( (CHead=='HET   ').OR.(CHead=='HETNAM').OR.(CHead=='HETSYN').OR.(CHead=='FORMUL')  ) RecordType=4 ! Heterogen Section
       If ( (CHead=='HELIX ').OR.(CHead=='SHEET ').OR.(CHead=='TURN  ')                       ) RecordType=5 ! Secondary Structure Section
       If ( (CHead=='SSBOND').OR.(CHead=='LINK  ').OR.(CHead=='HYDBND').OR.(CHead=='SLTBRG')  ) RecordType=6 ! Connectivity Annotation Section
       If ( (CHead=='CISPEP')                                                                 ) RecordType=6 ! Connectivity Annotation Section
       If ( (CHead=='SITE  ').OR.(CHead=='CONECT').OR.(CHead=='TER   ').OR.(CHead=='SIGATM')  ) RecordType=7 ! Miscellaneous Features Section
       If ( (CHead=='ANISOU').OR.(CHead=='SIGUIJ')                                            ) RecordType=7 ! Miscellaneous Features Section
       
       If( RecordType==1) Then    !+++++++++++++++++  Title Section
            Backspace(12)
            Read(12, '(A80)') CLine
            Line(RecordType)=Line(RecordType)+1
            PDBRecord(RecordType, Line(RecordType))=CLine
       EndIF ! If( RecordType==1 )
        
       If( RecordType==2) Then    !+++++++++++++++++  REMARK 350   BIOMT
            Backspace(12)
            Read(12, '(A80)') CLine
            Line(RecordType)=Line(RecordType)+1
            PDBRecord(RecordType, Line(RecordType))=CLine
       EndIF ! If( RecordType==2 )
        
       If( RecordType==5 ) Then    !+++++++++++++++++  Secondary Structure 
            
            Backspace(12)
            Read(12, '(A80)') CLine
            Line(RecordType)=Line(RecordType)+1
            PDBRecord(RecordType, Line(RecordType))=CLine                                   
            
       EndIf ! If( RecordType==5 ) 
                 
       Goto 610

660    Continue       
       Close(12) ! file=PDBid(1:4)//'.pdb'       
       
       
       
! =====E==N===D================================================================== !
       Return
       End           
       
        
        
        
        
        
        
        
        
       