汇总输出
Summarize output
我在这上面卡了一段时间。我运行在堡垒运行90模拟。
program epidemic
implicit none
!!!variable declaration
integer, parameter::n=625
real, dimension(1:n)::x,y
real :: alpha, beta, epsilon, dist, prob, u
integer, dimension(1:n) :: infections
integer:: T, I1, I2, I3, i, j, K2, infperiod, k, tmax
!!!!!!!!!! paramater value
tmax=11
alpha=0.4
gamma=9
!!Generate population!!
I3=1
Do I1=1, 25, 1
Do I2=1,25,1
x(I3)=REAL(I1)
y(I3)=REAL(I2)
Infections(I3)=0
I3=I3+1
ENDDO
ENDDO
!!!INITIAL INFECTION!!!
call random_number(u)
k2=1+aint(u)*n
infections(k2)=1
!!!! initial infection !!!!!!
call random_number(u)
IF (prob >= u) THEN
END IF
END IF
ENDDO
enddo
!!! output data
!!! writing and saving
Do i= 1, n
write(*,*) i, x(i), y(i)
ENDDO
end program epidemic
我的模拟结果是一个看起来像这样的数据框
1 1.00000000 1.00000000 1
2 1.00000000 2.00000000 4
3 1.00000000 3.00000000 3
4 1.00000000 4.00000000 4
5 1.00000000 5.00000000 4
6 1.00000000 6.00000000 4
7 1.00000000 7.00000000 4
8 1.00000000 8.00000000 2
9 1.00000000 9.00000000 4
10 1.00000000 10.0000000 4
11 1.00000000 11.0000000 5
12 1.00000000 12.0000000 5
13 1.00000000 13.0000000 4
14 1.00000000 14.0000000 5
15 1.00000000 15.0000000 6
第一列代表个体使得i=1, 625,第二列和第三列代表矩阵索引[i,j]。第四列代表感染的(时间)(1:15 天)。我希望能够 table 将输出分成两列。
为了说明,我想创建一个新变量来显示这一天有多少人被感染。
所以,625行的输出变成这样
AT Day=1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Total of infected individual =3 5 6 7 11 8 0 1 ...........
非常非常感谢
这应该让你开始......
...
INTEGER, DIMENSION(31) :: Sums
!day is the 4th column from 1:625...
...
Sums(:) = 0
...
DO Entry = 1, 625
Sums(Thedayindex) = Sums(Thedayindex) + Day(Entry)
ENDDO
...
既然你已经清楚了,试试这个:
添加新声明
integer, dimension(15) :: infection_day
并且,在现有循环 do T ...
之后,插入类似
的内容
do i = 1, 15
infection_day(i) = count(infections==i)
end do
总结您的数据。
我在这台机器上没有 Fortran,所以没有测试这个代码片段,但它应该会让你走上正轨。
我在这上面卡了一段时间。我运行在堡垒运行90模拟。
program epidemic
implicit none
!!!variable declaration
integer, parameter::n=625
real, dimension(1:n)::x,y
real :: alpha, beta, epsilon, dist, prob, u
integer, dimension(1:n) :: infections
integer:: T, I1, I2, I3, i, j, K2, infperiod, k, tmax
!!!!!!!!!! paramater value
tmax=11
alpha=0.4
gamma=9
!!Generate population!!
I3=1
Do I1=1, 25, 1
Do I2=1,25,1
x(I3)=REAL(I1)
y(I3)=REAL(I2)
Infections(I3)=0
I3=I3+1
ENDDO
ENDDO
!!!INITIAL INFECTION!!!
call random_number(u)
k2=1+aint(u)*n
infections(k2)=1
!!!! initial infection !!!!!!
call random_number(u)
IF (prob >= u) THEN
END IF
END IF
ENDDO
enddo
!!! output data
!!! writing and saving
Do i= 1, n
write(*,*) i, x(i), y(i)
ENDDO
end program epidemic
我的模拟结果是一个看起来像这样的数据框
1 1.00000000 1.00000000 1
2 1.00000000 2.00000000 4
3 1.00000000 3.00000000 3
4 1.00000000 4.00000000 4
5 1.00000000 5.00000000 4
6 1.00000000 6.00000000 4
7 1.00000000 7.00000000 4
8 1.00000000 8.00000000 2
9 1.00000000 9.00000000 4
10 1.00000000 10.0000000 4
11 1.00000000 11.0000000 5
12 1.00000000 12.0000000 5
13 1.00000000 13.0000000 4
14 1.00000000 14.0000000 5
15 1.00000000 15.0000000 6
第一列代表个体使得i=1, 625,第二列和第三列代表矩阵索引[i,j]。第四列代表感染的(时间)(1:15 天)。我希望能够 table 将输出分成两列。
为了说明,我想创建一个新变量来显示这一天有多少人被感染。
所以,625行的输出变成这样
AT Day=1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Total of infected individual =3 5 6 7 11 8 0 1 ...........
非常非常感谢
这应该让你开始......
...
INTEGER, DIMENSION(31) :: Sums
!day is the 4th column from 1:625...
...
Sums(:) = 0
...
DO Entry = 1, 625
Sums(Thedayindex) = Sums(Thedayindex) + Day(Entry)
ENDDO
...
既然你已经清楚了,试试这个:
添加新声明
integer, dimension(15) :: infection_day
并且,在现有循环 do T ...
之后,插入类似
do i = 1, 15
infection_day(i) = count(infections==i)
end do
总结您的数据。
我在这台机器上没有 Fortran,所以没有测试这个代码片段,但它应该会让你走上正轨。