質問編集履歴
1
コードを追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -13,3 +13,115 @@
|
|
13
13
|
というエラーが出ています。
|
14
14
|
|
15
15
|
モヂュールとメインプログラムで1つのtxtファイル(data14-1)を読み込んだところ、エラーが出ました。
|
16
|
+
|
17
|
+
```fortran
|
18
|
+
|
19
|
+
コードmodule hh
|
20
|
+
|
21
|
+
implicit none
|
22
|
+
|
23
|
+
contains
|
24
|
+
|
25
|
+
function h(kupper, x_c) result(value)
|
26
|
+
|
27
|
+
implicit none
|
28
|
+
|
29
|
+
integer i
|
30
|
+
|
31
|
+
real(8) kupper, x_c, value
|
32
|
+
|
33
|
+
real(8) :: x(0:199)
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
open(11, file='data14-1.txt', status='old')
|
38
|
+
|
39
|
+
value = 0.5*(x_c-2.0)*(x_c-2.0)
|
40
|
+
|
41
|
+
do i = 0, 199
|
42
|
+
|
43
|
+
read(11, *) x(i)
|
44
|
+
|
45
|
+
value = value + 0.5*kupper*(x(i)-x_c)*(x(i)-x_c)
|
46
|
+
|
47
|
+
enddo
|
48
|
+
|
49
|
+
close(11)
|
50
|
+
|
51
|
+
end function h
|
52
|
+
|
53
|
+
end module hh
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
program metropolis2
|
58
|
+
|
59
|
+
use hh
|
60
|
+
|
61
|
+
implicit none
|
62
|
+
|
63
|
+
integer i, j
|
64
|
+
|
65
|
+
real(8) :: epsi1(0:99), epsi2(0:99), x(0:199)
|
66
|
+
|
67
|
+
real(8) :: r(0:99)
|
68
|
+
|
69
|
+
real(8) :: h_prime, x_c = 1.0, kupper = 5.0
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
open(11, file='data14-1.txt', status='old')
|
74
|
+
|
75
|
+
open(12, file='data14-2.txt', status='old')
|
76
|
+
|
77
|
+
open(13, file='data14-3.txt', status='old')
|
78
|
+
|
79
|
+
open(14, file='data14-4.txt', status='old')
|
80
|
+
|
81
|
+
open(15, file='metropolis2.dat', status='replace')
|
82
|
+
|
83
|
+
do i = 0, 99
|
84
|
+
|
85
|
+
read(12,*) epsi1(i)
|
86
|
+
|
87
|
+
read(13,*) epsi2(i)
|
88
|
+
|
89
|
+
read(11,*) x(i)
|
90
|
+
|
91
|
+
x_c = x_c + epsi1(i)
|
92
|
+
|
93
|
+
kupper = kupper + epsi2(i)
|
94
|
+
|
95
|
+
h_prime = h(kupper, x_c)
|
96
|
+
|
97
|
+
read(14,*) r(i)
|
98
|
+
|
99
|
+
if (r(i) <= exp(h(kupper-epsi2(i), x_c-epsi1(i))-h_prime)) then
|
100
|
+
|
101
|
+
continue
|
102
|
+
|
103
|
+
else
|
104
|
+
|
105
|
+
x_c = x_c - epsi1(i)
|
106
|
+
|
107
|
+
kupper = kupper - epsi2(i)
|
108
|
+
|
109
|
+
endif
|
110
|
+
|
111
|
+
write(15, *) i, kupper, x_c
|
112
|
+
|
113
|
+
enddo
|
114
|
+
|
115
|
+
close(11)
|
116
|
+
|
117
|
+
close(12)
|
118
|
+
|
119
|
+
close(13)
|
120
|
+
|
121
|
+
close(14)
|
122
|
+
|
123
|
+
close(15)
|
124
|
+
|
125
|
+
end program metropolis2
|
126
|
+
|
127
|
+
```
|