C   10/10/79 202222230  MEMBER NAME  MUDCHK   (JADEMUS)     FORTRAN
C
C LAST CHANGE 13.30 22/02/82 HUGH MCCANN - FOR IMPROVED ERROR OUTPUT.
C                                          ONLY GET O/P FOR MUPRIN>=5.
C      CHANGE 17.15  01/10/81  HUGH MCCANN  - PROTECT MUFFLE SQRTS.
C      CHANGE 06.27  24/04/80  JOHN ALLISON - TO PRINT ONLY IF DESCREP-
C                               -ANCY IS LARGE.
C      CHANGE 14.52  01/04/80  HUGH MCCANN (PRINT OPTION) .
C      CHANGE 10.35  29/03/80  JOHN ALLISON. (D -> DHARRY!!!!)
C      CHANGE 14.00  15/03/80  HARRISON PROSPER
      SUBROUTINE MUDCHK(I)
#include "cmufwork.for"
      COMMON/CMUPRN/MUPRIN
      U = DCX*DCX + DCY*DCY + DCZ*DCZ
      DHARRY = ABS(1.0 - U)
      IF  ( DHARRY.LT.0.001)  GO TO 600
C
C  PRINT OUT MESSAGE IF PRINT FLAG IS SET.
C
      IF(MUPRIN.LT.5)GO TO 500
C
C PRINT ONLY IN CASE OF LARGE DECREPANCY.
C
      IF(DHARRY.LT.0.1)GO TO 500
C
      WRITE(6,100) I
 100  FORMAT('0DIRECTION COSINE CHECK AT POSITION ',I2)
      WRITE(6,200)
 200  FORMAT(1X,9X,'    L ....... M ....... N',6X,'  MAGNITUDE')
      WRITE(6,300) DCX,DCY,DCZ,U
 300  FORMAT(1X,6X,3F10.6,10X,F10.6/)
C
 500  CONTINUE
C.....RENORMALISE DIRECTION COSINES
      DCX = DCX/SQRT(U)
      DCY = DCY/SQRT(U)
      DCZ = DCZ/SQRT(U)
C
C PROTECT MUFFLE SQRTS.
  600 IF(DCX*DCX.GT.1.000001)DCX=SIGN(1.0,DCX)
      IF(DCY*DCY.GT.1.000001)DCY=SIGN(1.0,DCY)
      IF(DCZ*DCZ.GT.1.000001)DCZ=SIGN(1.0,DCZ)
      RETURN
      END
