      FUNCTION ERRCAL(NA,NP)
C
C CALCULATE STANDARD DEVIATION FOR CONSTRAINED PARAMETERS
C
	PARAMETER MAXX=200
C
      DIMENSION LISPAR(MAXX),DERI(MAXX),LDEGN(MAXX)
      INCLUDE 'E.INC'
      INCLUDE 'RFINE.PRM'
      INCLUDE 'LSMAT.INC'
      INCLUDE 'CNSTRS.INC'
      EQUIVALENCE (LDEGN(1),AA(1))
C
      I5(K)=IAND(K,65535)
      I6(K)=IAND(ISHFT(K,-16),65535)
C
      IP=0
      IF(MDEGN.LE.0)GO TO 310
C CALCULATE PARAMETER NUMBER
      IJ=JPPA(NA)+NP
C LOOP THROUGH CONSTRAINTS
      DO 300 I=1,MDEGN,2
      IK=I5(LDEGN(I))
C SKIP IF THIS CONSTRAINT NOT FOR THIS ATOM
      IF(IK.NE.IJ)GO TO 300
      IP=IP+1
      IF(IP.GT.MAXX)STOP 'TOO MANY IN ERRCAL'
      LISPAR(IP)=I6(KDEGN(I))
      IF((LISPAR(IP).LE.0).OR.(LISPAR(IP).GT.MRANK))THEN
c Ignore initializing constants
        if (lispar(ip).ne.0)WRITE(IOUT,2)LISPAR(IP),KDEGN(I)
2       FORMAT(' UNEXPECTED VALUE OF ',I8,' FOR LISPAR, KDEGN =',I8)
        ERRCAL=0.0
        RETURN
      ENDIF
      DERI(IP)=AA(I+1)
  300 CONTINUE
  310 IF(IP.EQ.0)THEN
        ERRCAL=0.
        RETURN
      END IF
      SUM=0.
      DO 330 I=1,IP
        DO 320 J=I,IP
          II=LISPAR(I)
          JJ=LISPAR(J)
          KK=MDEGN+((II-1)*(2*MRANK-II+2))/2+JJ-II+1
          TERM=DERI(I)*DERI(J)*A(KK)
          IF(I.NE.J)SUM=SUM+TERM
          SUM=SUM+TERM
  320   CONTINUE
  330 CONTINUE
      IF(SUM.LT.0.)SUM=0.
      ERRCAL=SQRT(SUM)
      RETURN
      END
