simple.f 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. PROGRAM OUTLETS
  2. IMPLICIT NONE
  3. INTEGER I, SUCC, PRED
  4. INTEGER N
  5. PARAMETER (N = 9)
  6. DOUBLE PRECISION L, XP(9), C, P(9), S(9), PRF(9), PRFTOT(9)
  7. INTEGER F(9)
  8. C = 1.0D0
  9. L = 10.D0
  10. DO 3, I = 1, 9
  11. 3 XP(I) = L / 9.D0
  12. F(1) = 1
  13. F(2) = 2
  14. F(3) = 3
  15. F(4) = 3
  16. F(5) = 2
  17. F(6) = 1
  18. F(7) = 2
  19. F(8) = 1
  20. F(9) = 3
  21. CALL OUTLET(N, F, XP, C, P, S, PRF, PRFTOT)
  22. END
  23. SUBROUTINE OUTLET(N, F, XP, C, P, S, PRF, PRFTOT)
  24. IMPLICIT NONE
  25. INTEGER N, F(N)
  26. INTEGER IPIV(N), WORK(N), LWORK, INFO, PRED
  27. DOUBLE PRECISION II(N)
  28. DOUBLE PRECISION XP(N), C, P(N), S(N), PRF(N), PRFTOT(N)
  29. DOUBLE PRECISION A(N,N), B(N)
  30. DOUBLE PRECISION ZERO, ONE, TWO
  31. INTEGER I, J
  32. ONE = 1.0D0
  33. TWO = 2.0D0
  34. LWORK = N
  35. II = ONE
  36. DO 1, I = 1, N - 1
  37. 1 IF(F(I).EQ.F(I+1)) II(I) = TWO
  38. A = ZERO
  39. DO 5, I = 1, N
  40. A(I,I) = TWO*( XP(PRED(I,N)) + XP(I) ) / ( XP(PRED(I,N)) * XP(I) )
  41. 5 B(I) = C * ( XP(PRED(I,N)) + XP(I) )
  42. DO 7, I = 1, N - 1
  43. A(I+1,I) = - II(I) / XP(I)
  44. 7 A(I,I+1) = - II(I) / XP(I)
  45. A(1,N) = - II(N) / XP(1)
  46. A(N,1) = - II(N) / XP(1)
  47. DO 8, I = 1, N
  48. 8 PRINT '(I5,10F7.1)', I, (A(I,J), J=1,N), B(I)
  49. C CALL DSYSV('U', N, 1, A, N, IPIV, B, N, WORK, LWORK, INFO)
  50. CALL DGESV(N,1,A,N,IPIV,B,N,INFO)
  51. PRINT*
  52. PRINT*, INFO
  53. DO 10, I = 1, N
  54. S(I) = (XP(PRED(I,N)) + XP(I))/TWO +
  55. & (B(PRED(I,N))/XP(PRED(I,N))+B(PRED(I,N))/XP(PRED(I,N)))/(TWO*C)
  56. 10 PRF(I) = (B(I)-C) * S(I)
  57. DO 30, I = 1, N
  58. 30 PRINT '(2I5,3F9.3)', I, F(I), B(I), S(I), PRF(I)
  59. RETURN
  60. END
  61. FUNCTION SUCC(I,N)
  62. INTEGER SUCC, I, N
  63. IF (I.LT.N) SUCC = I + 1
  64. IF (I.EQ.N) SUCC = 1
  65. RETURN
  66. END
  67. FUNCTION PRED(I,N)
  68. INTEGER PRED, I, N
  69. IF (I.EQ.1) PRED = N
  70. IF (I.GT.1) PRED = I - 1
  71. RETURN
  72. END