CHECK v.3.2-->                                                          MKAN001
C      subroutine mkangl (mcaaat, mcangs, atomin, chnsz,  chnct,  caonlyMKAN002
C     +                   seqlen, scaaat, scatin, seqcod, aacod3, hetcodMKAN003
C     +                   sx2,    sx,     ntot,   hist,   hismin, ave,  MKAN004
C     +                   sd)                                           MKAN005
      subroutine mkangl (mcaaat, mcangs, atomin, chnsz,  chnct,  caonly,MKAN001
     &                   scaaat, scatin, seqcod, aacod3, hetcod,        MKAN002
     &                   sx2,    sx,     ntot,   hist,   hismin, ave,   MKAN003
     &                   sd)                                            MKAN004
CHECK v.3.2<--                                                          MKAN005
c     Procedure to calculate the main chain dihedral angles             MKAN006
c     if all the atoms are present.                                     MKAN007
c                                                                       MKAN008
      include 'brkcln.par'                                              MKAN009
c                                                                       MKAN010
      character aacod3*(3*abetsz), hetcod*63, wkres*3                   MKAN011
c                                                                       MKAN012
      real      mcaaat(ncoord,mnchna,maxres), mcangs(nmnang,maxres),    MKAN013
     &          scaaat(ncoord,sdchna,maxres), sx2, sx                   MKAN014
c                                                                       MKAN015
      logical   atomin(mnchna,maxres), caonly, scatin(sdchna,maxres)    MKAN016
c                                                                       MKAN017
CHECK v.3.2-->                                                          MKAN018
C      integer   seqlen, chnsz(maxchn), chnct, seqcod(maxres), ntot,    MKAN019
C     +          hist(17)                                               MKAN020
      integer   chnsz(maxchn), chnct, seqcod(maxres), ntot,             MKAN021
     &          hist(17)                                                MKAN022
CHECK v.3.2<--                                                          MKAN023
c                                                                       MKAN024
c     local variables                                                   MKAN025
c                                                                       MKAN026
      real      dihed                                                   MKAN027
c                                                                       MKAN028
      integer   angrng(3), angatm(4), angoff(4), angchn, i, nxres,      MKAN029
     &          chnst, nxchn, hismin(17)                                MKAN030
c                                                                       MKAN031
c     integer   j, stang, finang                                        MKAN032
c                                                                       MKAN033
      real      ave, sd                                                 MKAN034
c                                                                       MKAN035
      save angchn, angoff, angatm, angrng                               MKAN036
c                                                                       MKAN037
      data angrng(1) / 1 /                                              MKAN038
      data angrng(2) / 0 /                                              MKAN039
      data angrng(3) / impld /                                          MKAN040
      data angatm(1) / calph /                                          MKAN041
      data angatm(2) / nmain /                                          MKAN042
      data angatm(3) / carb /                                           MKAN043
      data angatm(4) / cbeta /                                          MKAN044
      data angoff(1) / 0 /                                              MKAN045
      data angoff(2) / 0 /                                              MKAN046
      data angoff(3) / 0 /                                              MKAN047
      data angoff(4) / 0 /                                              MKAN048
      data angchn / 1 /                                                 MKAN049
c                                                                       MKAN050
 2000 format (' Average value of CA-N-C-CB angle is ',F6.2,/,           MKAN051
     &        ' Standard deviation is               ',F6.2)             MKAN052
CHECK v.3.0.1-->                                                        MKAN053
C 2001 format (' Unusual CA-N-C-CB torsion angle ', f5.1, ' residue ',  MKAN054
C     + 1x, i4, 1x, a3)                                                 MKAN055
CHECK v.3.0.1<--                                                        MKAN056
c                                                                       MKAN057
      if (.not. caonly) then                                            MKAN058
         chnst = 0                                                      MKAN059
         do 3000 nxchn = 1,chnct                                        MKAN060
         if (chnsz(nxchn) .lt. angchn) then                             MKAN061
            do 1000 nxres = chnst+1, chnst+chnsz(nxchn)                 MKAN062
            mcangs(angrng(3),1) = null                                  MKAN063
 1000       continue                                                    MKAN064
         else                                                           MKAN065
            do 2100 nxres = chnst+angrng(1),                            MKAN066
     &                      chnst+chnsz(nxchn)+angrng(2)                MKAN067
            if (atomin(angatm(1),nxres+angoff(1)) .and.                 MKAN068
     &          atomin(angatm(2),nxres+angoff(2)) .and.                 MKAN069
     &          atomin(angatm(3),nxres+angoff(3)) .and.                 MKAN070
     &          scatin(angatm(4),nxres+angoff(4))) then                 MKAN071
               mcangs(angrng(3),nxres) = dihed(1,                       MKAN072
     &                              mcaaat(1,angatm(1),nxres+angoff(1)),MKAN073
     &                              mcaaat(1,angatm(2),nxres+angoff(2)),MKAN074
     &                              mcaaat(1,angatm(3),nxres+angoff(3)),MKAN075
     &                              scaaat(1,angatm(4),nxres+angoff(4)))MKAN076
               do 2005 i = 1, 17                                        MKAN077
               if ( mcangs(1,nxres) .ge. real(hismin(i)) .and.          MKAN078
     &              mcangs(1,nxres) .lt. real(hismin(i) + 10) ) then    MKAN079
                  hist(i) = hist(i) + 1                                 MKAN080
                  goto 2010                                             MKAN081
               end if                                                   MKAN082
 2005          continue                                                 MKAN083
 2010          continue                                                 MKAN084
               if (mcangs(1,nxres) .lt. 23.0 .or.                       MKAN085
     &             mcangs(1,nxres). gt. 45.0) then                      MKAN086
                  if (seqcod(nxres) .le. abetsz) then                   MKAN087
                     wkres = aacod3((seqcod(nxres)*3)-2:                MKAN088
     &                               seqcod(nxres)*3)                   MKAN089
                  else                                                  MKAN090
                     wkres = hetcod(((seqcod(nxres)-abetsz)*3)-2:       MKAN091
     &                               (seqcod(nxres)-abetsz)*3)          MKAN092
                  end if                                                MKAN093
                                                                        MKAN094
CHECK v.1.0-->                                                          MKAN095
C                  write (logfi, 2001) mcangs(1,nxres), nxres, wkres    MKAN096
CHECK v.1.0<--                                                          MKAN097
                                                                        MKAN098
               end if                                                   MKAN099
            else                                                        MKAN100
               mcangs(angrng(3),nxres) = null                           MKAN101
            end if                                                      MKAN102
 2100       continue                                                    MKAN103
         end if                                                         MKAN104
         do 2400 nxres = chnst+1, chnst+angrng(1)-1                     MKAN105
         mcangs(angrng(3),nxres) = null                                 MKAN106
 2400    continue                                                       MKAN107
         do 2600 nxres = chnst+chnsz(nxchn)+angrng(2)+1,                MKAN108
     &                   chnst+chnsz(nxchn)                             MKAN109
         mcangs(angrng(3),nxres) = null                                 MKAN110
 2600    continue                                                       MKAN111
         chnst = chnst + chnsz(nxchn)                                   MKAN112
 3000    continue                                                       MKAN113
         call avevar (mcangs, chnst, ave, sd)                           MKAN114
CHECK v.2.1.3-->                                                        MKAN115
C         write (logfi, 2000) ave, sd                                   MKAN116
         write (*, 2000) ave, sd                                        MKAN117
CHECK v.2.1.3<--                                                        MKAN118
         call totave (mcangs, chnst, sx2, sx, ntot)                     MKAN119
      end if                                                            MKAN120
      end                                                               MKAN121
