我有一个程序来读取和分层多元正态总体与(x,y)值的R文件。我想将人口分成两组,其中分部是基于如果x和y高于或低于特定数字。划分人口Fortran - 接收零
当我做Fortran进行分层,我没有得到任何结果,但零x和y,这样的事情
total number of individuals 1551
0.00000000 0.00000000
0.00000000 0.00000000
0.00000000 0.00000000
0.00000000 0.00000000
0.00000000 0.00000000
0.00000000 0.00000000
0.00000000 0.00000000
0.00000000 0.00000000
0.00000000 0.00000000
0.00000000 0.00000000
.
.
.
原始数据看起来像这样
755,885
656,841
742,844
747,829
776,861
696,809
782,891
771,867
760,826
812,830
711,792
736,840
738,873
793,833
751,836
747,871
796,830
711,868
747,843
758,835
760,824
759,839
696,868
I have attached the file to the original data from R as well
program test
implicit none
real, dimension(:), allocatable :: x,y
real, dimension(:,:), allocatable :: s1, s2, s3, s4
integer:: io, l1, l2, l3,l4,n,i
open(33, file = '', status = 'old', action = 'read')
n = 0
DO
READ(33,*,iostat=io)
IF (io/=0) EXIT
n = n + 1
END DO
allocate(x(n) ,y(n))
rewind(33)
DO i =1,n
READ(33,*) x(i), y(i)
END DO
allocate(s1(n,2))
allocate(s2(n,2))
allocate(s3(n,2))
allocate(s4(n,2))
s1=0
s2=0
s3=0
s4=0
l1=1
l2=1
l3=1
l4=1
do i = 1 , n
if (x(i) >=0 .AND. x(i)<=500) then
if(y(i) >= 0 .AND. y(i) <=500) then
s1(l1, :)=(/x(i), y(i) /)
l1=l1+1
end if
else if (x(i) > 500 .AND. x(i) <= 1000) then
if (y(i) > 0 .AND. y(i) < 500) then
s2(l2, :)=(/x(i), y(i) /)
l2=l2+1
end if
end if
write(*,*) s1(l1, :)
end do !iloop
end program test
我不知道我在这里做什么错。
它是数据中的逗号 - 将其更改为空格 – cup
欢迎。一定要去[巡回]。针对所有Fortran问题使用标签[tag:fortran]。如果您的问题是版本特定的,您可以为特定版本添加标签。但是你的问题不是特定于版本的。 –
你的程序很难阅读。当你的代码应该被别人查看时,请使用一致的行缩进。它会帮助你更好地看到结构。 –