C ===  Derivating with respect to: 
C     X(1) X(2) X(3) X(4)                                                  
C
      SUBROUTINE CALFUN(X,N,FF,INF)
      IMPLICIT REAL*8 (A-H,O-Z)
      DIMENSION X(4)
      INF = 0
      DO 1 I = 2, 4
        IF (X(I) .GT. 0.) GOTO 1
          INF = 1
  1   CONTINUE
      IF (INF .EQ. 1) RETURN
      FF_1=2*(X(1)-1.)**(2-1)+2*(X(1)-DSQRT(X(2)))**(2-1)
      FF_2=2*(X(1)-DSQRT(X(2)))**(2-1)*(-1./2./DSQRT(X(2)))
      FF_3=0.
      FF_4=0.
      FF = (X(1) - 1.)**2 + (X(1) - DSQRT(X(2)))**2
      FF_2=FF_2+2*(X(2)-DSQRT(X(3)))**(2-1)
      FF_3=FF_3+2*(X(2)-DSQRT(X(3)))**(2-1)*(-1./2./DSQRT(X(3)))+2*(X(3)
     :-DSQRT(X(4)))**(2-1)
      FF_4=FF_4+2*(X(3)-DSQRT(X(4)))**(2-1)*(-1./2./DSQRT(X(4)))
      FF = FF + (X(2) - DSQRT(X(3)))**2 + (X(3) - DSQRT(X(4)))**2
      RETURN
      END
