C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C*************************
C**       FNCALC        **
C*************************
C
C
      DOUBLE PRECISION FUNCTION FNCALC(P,XI,DX,M,N,FVECC,XTEMP,
     +                                 CALFUN)
C
C Purpose: Calculate sum of squares function for line minimisation routine
C
      DOUBLE PRECISION P(N), XI(N), FVECC(M), XTEMP(N)
      DOUBLE PRECISION DX
      INTEGER M, N
      EXTERNAL CALFUN
C
C-------------------------------------------------------------------------------
C
      DO 10 I=1,N
         XTEMP(I)=P(I)+DX*XI(I)
10    CONTINUE
      CALL CALFUN(M,N,FVECC,XTEMP)
      FNCALC = 0.0
      DO 20 I=1,M
         FNCALC = FNCALC + FVECC(I)*FVECC(I)
20    CONTINUE
      RETURN
      END
