CHECK v.1.0-->                                                          MKAN001
C      Subroutine MkAngl(McAAat, McAngs, Atomin, chnsz, chnct, caonly,  MKAN002
C     +                  Seqlen)                                        MKAN003
      Subroutine MkAngl(McAAat, McAngs, Atomin, chnsz, chnct, caonly,   MKAN001
     &                  Seqlen, scaaat, scatin)                         MKAN002
CHECK v.1.0<--                                                          MKAN003
                                                                        MKAN004
c                                                                       MKAN005
c     Procedure to calculate the main chain dihedral angles             MKAN006
c     if all the atoms are present.                                     MKAN007
c                                                                       MKAN008
      INCLUDE 'sstruc.par'                                              MKAN009
                                                                        MKAN010
      Real    McAAat(ncoord,mnchna,maxres), McAngs(nmnang,maxres)       MKAN011
      Logical Atomin(mnchna,maxres), caonly                             MKAN012
      Integer Seqlen, chnsz(maxchn), chnct                              MKAN013
      Real    Dihed                                                     MKAN014
                                                                        MKAN015
CHECK v.1.0-->                                                          MKAN016
      real      scaaat(ncoord,sdchna,maxres)                            MKAN017
      logical   scatin(sdchna,maxres)                                   MKAN018
CHECK v.1.0<--                                                          MKAN019
                                                                        MKAN020
c                                                                       MKAN021
c     local variables                                                   MKAN022
c                                                                       MKAN023
CHECK v.3.2-->                                                          MKAN024
      SAVE angrng, angatm, angoff, angchn                               MKAN025
CHECK v.3.2<--                                                          MKAN026
      Integer angrng(nmnang,3), angatm(nmnang,4), angoff(nmnang,4),     MKAN027
     &        angchn(nmnang), I, j, Nxres, Nxset, chnst, nxchn, stang,  MKAN028
     &        finang                                                    MKAN029
                                                                        MKAN030
CHECK v.1.0-->                                                          MKAN031
C      data ((angrng(I,j),j=1,3), i=1,nmnang)                           MKAN032
C     +      /2, 0, phi, 1, -1, psi, 1, -1, omega, 2, -2, chiral,       MKAN033
C     +       3, -2, kappa, 2, 0, tco/                                  MKAN034
C      data ((angatm(I,j),j=1,4), i=1,nmnang)                           MKAN035
C     +     /carb, nmain, calph, carb, nmain, calph, carb, nmain,       MKAN036
C     +      calph, carb, nmain, calph, calph, calph, calph, calph,     MKAN037
C     +      calph, calph, calph, calph, carb, oxyg, carb, oxyg/        MKAN038
C      data ((angoff(I,j),j=1,4), i=1,nmnang)                           MKAN039
C     +     /-1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, -1, 0, 1, 2,          MKAN040
C     +      -2, 0, 0, 2, 0, 0, -1, -1/                                 MKAN041
C      data angchn / 2, 2, 2, 4, 5, 2/                                  MKAN042
CHECK v.1.0<--                                                          MKAN043
                                                                        MKAN044
CHECK v.1.0-->                                                          MKAN045
      data ((angrng(I,j),j=1,3), i=1,nmnang)                            MKAN046
     &      /2, 0, phi, 1, -1, psi, 1, -1, omega, 2, -2, chiral,        MKAN047
     &       1, 0, IMPLD, 3, -2, kappa, 2, 0, tco /                     MKAN048
      data ((angatm(I,j),j=1,4), i=1,nmnang)                            MKAN049
     &     /carb, nmain, calph, carb, nmain, calph, carb, nmain,        MKAN050
     &      calph, carb, nmain, calph, calph, calph, calph, calph,      MKAN051
     &      CALPH, NMAIN, CARB, MCBETA,                                 MKAN052
     &      calph, calph, calph, calph, carb, oxyg, carb, oxyg /        MKAN053
      data ((angoff(I,j),j=1,4), i=1,nmnang)                            MKAN054
     &     /-1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, -1, 0, 1, 2,           MKAN055
     &       0, 0, 0, 0,-2, 0, 0, 2, 0, 0, -1, -1 /                     MKAN056
      data angchn / 2, 2, 2, 4, 1, 5, 2 /                               MKAN057
CHECK v.1.0<--                                                          MKAN058
                                                                        MKAN059
CHECK v.3.2-->                                                          MKAN060
C      SAVE angrng, angatm, angoff, angchn                              MKAN061
CHECK v.3.2<--                                                          MKAN062
c                                                                       MKAN063
                                                                        MKAN064
CHECK v.1.0-->                                                          MKAN065
      DO 100, NXRES = 1, SEQLEN                                         MKAN066
          ATOMIN(MCBETA,NXRES) = SCATIN(CBETA,NXRES)                    MKAN067
          MCAAAT(1,MCBETA,NXRES) = SCAAAT(1,CBETA,NXRES)                MKAN068
          MCAAAT(2,MCBETA,NXRES) = SCAAAT(2,CBETA,NXRES)                MKAN069
          MCAAAT(3,MCBETA,NXRES) = SCAAAT(3,CBETA,NXRES)                MKAN070
 100  CONTINUE                                                          MKAN071
CHECK v.1.0<--                                                          MKAN072
                                                                        MKAN073
      stang = 1                                                         MKAN074
      finang = nmnang                                                   MKAN075
      if (caonly) then                                                  MKAN076
         stang = chiral                                                 MKAN077
         finang = kappa                                                 MKAN078
      end if                                                            MKAN079
      do 4000, Nxset = stang, finang                                    MKAN080
      chnst = 0                                                         MKAN081
      do 3000, nxchn = 1, chnct                                         MKAN082
      if (chnsz(nxchn) .lt. angchn(nxset)) then                         MKAN083
         do 1000, nxres = chnst + 1, chnst + chnsz(nxchn)               MKAN084
         McAngs(angrng(nxset,3),Nxres) = Null                           MKAN085
 1000    continue                                                       MKAN086
      else                                                              MKAN087
         do 2000, Nxres = chnst + angrng(nxset,1),                      MKAN088
     &                    chnst + chnsz(nxchn) + angrng(nxset,2)        MKAN089
         If (atomin(angatm(nxset,1), nxres+angoff(nxset,1)) .and.       MKAN090
     &      atomin(angatm(nxset,2), nxres+angoff(nxset,2)) .and.        MKAN091
     &      atomin(angatm(nxset,3), nxres+angoff(nxset,3)) .and.        MKAN092
     &      atomin(angatm(nxset,4), nxres+angoff(nxset,4))) then        MKAN093
            McAngs(angrng(nxset,3),Nxres) = Dihed(nxset,                MKAN094
     &          Mcaaat(1,angatm(nxset,1), nxres+angoff(nxset,1)),       MKAN095
     &          Mcaaat(1,angatm(nxset,2), nxres+angoff(nxset,2)),       MKAN096
     &          Mcaaat(1,angatm(nxset,3), nxres+angoff(nxset,3)),       MKAN097
     &          Mcaaat(1,angatm(nxset,4), nxres+angoff(nxset,4)))       MKAN098
         else                                                           MKAN099
            McAngs(angrng(nxset,3),Nxres) = Null                        MKAN100
         end if                                                         MKAN101
 2000    continue                                                       MKAN102
         do 2400, nxres = chnst + 1, chnst + angrng(nxset,1) - 1        MKAN103
         McAngs(angrng(nxset,3),nxres) = Null                           MKAN104
 2400    continue                                                       MKAN105
         do 2600, nxres = chnst + chnsz(nxchn) + angrng(nxset,2) + 1,   MKAN106
     &                    chnst + chnsz(nxchn)                          MKAN107
         McAngs(angrng(nxset,3),nxres) = Null                           MKAN108
 2600    continue                                                       MKAN109
      end if                                                            MKAN110
      chnst = chnst + chnsz(nxchn)                                      MKAN111
 3000 continue                                                          MKAN112
 4000 continue                                                          MKAN113
      END                                                               MKAN114
