Advertisement
Guest User

int.f77

a guest
Sep 23rd, 2014
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.       FUNCTION SQRT_ITER(GUESS,X)
  2.       DOUBLE PRECISION SQRT_ITER,GUESS,X,IMPROVE
  3.       LOGICAL          GOOD_ENOUGH
  4.       EXTERNAL         GOOD_ENOUGH,IMPROVE
  5.    10 GUESS=IMPROVE(GUESS,X)
  6.       IF (.NOT.GOOD_ENOUGH(GUESS,X)) GOTO 10
  7.       SQRT_ITER=GUESS
  8.       END
  9.  
  10.       FUNCTION IMPROVE(GUESS,X)
  11.       DOUBLE PRECISION IMPROVE,GUESS,X,AVERAGE
  12.       EXTERNAL         AVERAGE
  13.       IMPROVE=AVERAGE(GUESS,X/GUESS)
  14.       END
  15.  
  16.       FUNCTION AVERAGE(X,Y)
  17.       DOUBLE PRECISION AVERAGE,X,Y
  18.       AVERAGE=(X+Y)/2.0D0
  19.       END
  20.  
  21.       FUNCTION GOOD_ENOUGH(GUESS,X)
  22.       LOGICAL          GOOD_ENOUGH
  23.       DOUBLE PRECISION GUESS,X,TOL
  24.       PARAMETER       (TOL=0.001D0)
  25.       GOOD_ENOUGH=DABS(GUESS*GUESS-X).LT.TOL
  26.       END
  27.  
  28.       FUNCTION MYSQRT(X)
  29.       DOUBLE PRECISION MYSQRT,X,GUESS,SQRT_ITER
  30.       EXTERNAL         SQRT_ITER
  31.       DOUBLE PRECISION ZERO,ONE
  32.       PARAMETER(ZERO=0.0D0,ONE=1.0D0)
  33. C
  34. C XXX COMPUTING THE SQRT OF ZERO RESULTS IN DIVIDE BY ZERO
  35. C
  36.       MYSQRT=ZERO
  37.       IF (X.EQ.ZERO) RETURN
  38.       IF (X.LT.ZERO) X=-X
  39.       GUESS=ONE
  40.       MYSQRT=SQRT_ITER(GUESS,X)
  41.       END
  42.  
  43.       IMPLICIT NONE
  44.       DOUBLE PRECISION REZ,X,XMIN,XMAX,STEP
  45.       DATA REZ/0.0D0/,STEP/.001D0/,XMIN/0.0D0,XMAX/10000.0D0/
  46.       DOUBLE PRECISION MYSQRT
  47.       EXTERNAL         MYSQRT
  48.       DO 10 X=XMIN,XMAX,STEP
  49.         REZ=REZ+MYSQRT(X)*STEP
  50.    10 CONTINUE
  51.       PRINT*,REZ
  52.       END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement