      SUBROUTINE CALC(BANGLE,XYZ,RADDEG,VALUE)                          CALC001
C-----------------------------------------------------------------------CALC002
C                                                                       CALC003
C  SUBROUTINE CALC  -  Calculate the required bond length/angle and     CALC004
C                      return the value                                 CALC005
C                                                                       CALC006
C----------------------------------------------------------------------+CALC007
                                                                        CALC008
CVAX      IMPLICIT NONE                                                 CALC009
                                                                        CALC010
      INTEGER       ICOORD                                              CALC011
      LOGICAL       BANGLE                                              CALC012
      REAL          COSANG, DIFF1, DIFF2, DIFF3, DIST1, DIST2, DIST3,   CALC013
     &              RADDEG, XYZ(3,3), VALUE                             CALC014
                                                                        CALC015
C---- Calculate the value of the angle                                  CALC016
      IF (BANGLE) THEN                                                  CALC017
                                                                        CALC018
C----     Calculate distances between atoms 1->2, 2->3, 3->1            CALC019
          DIST1 = 0                                                     CALC020
          DIST2 = 0                                                     CALC021
          DIST3 = 0                                                     CALC022
          DO 300, ICOORD = 1, 3                                         CALC023
              DIFF1 = XYZ(ICOORD,2) - XYZ(ICOORD,1)                     CALC024
              DIFF2 = XYZ(ICOORD,3) - XYZ(ICOORD,2)                     CALC025
              DIFF3 = XYZ(ICOORD,1) - XYZ(ICOORD,3)                     CALC026
              DIST1 = DIST1 + DIFF1 * DIFF1                             CALC027
              DIST2 = DIST2 + DIFF2 * DIFF2                             CALC028
              DIST3 = DIST3 + DIFF3 * DIFF3                             CALC029
300       CONTINUE                                                      CALC030
                                                                        CALC031
C----     Calculate angle                                               CALC032
          IF (DIST1.GT.0.0 .AND. DIST2.GT.0.0 .AND.                     CALC033
     &        DIST3.GE.0.0) THEN                                        CALC034
              DIST1 = SQRT(DIST1)                                       CALC035
              DIST2 = SQRT(DIST2)                                       CALC036
              DIST3 = SQRT(DIST3)                                       CALC037
              COSANG = (DIST3 * DIST3 - DIST1 * DIST1                   CALC038
     &            - DIST2 * DIST2) / (-2.0 * DIST1 * DIST2)             CALC039
              IF (ABS(COSANG).LE.1.0) THEN                              CALC040
                  VALUE = RADDEG * ACOS(COSANG)                         CALC041
              ENDIF                                                     CALC042
          ENDIF                                                         CALC043
                                                                        CALC044
C---- Calculate value of bond length                                    CALC045
      ELSE                                                              CALC046
          DIST1 = 0                                                     CALC047
          DO 400, ICOORD = 1, 3                                         CALC048
              DIFF1 = XYZ(ICOORD,2) - XYZ(ICOORD,1)                     CALC049
              DIST1 = DIST1 + DIFF1 * DIFF1                             CALC050
400       CONTINUE                                                      CALC051
          VALUE = SQRT(DIST1)                                           CALC052
      ENDIF                                                             CALC053
                                                                        CALC054
      RETURN                                                            CALC055
      END                                                               CALC056
