我有一個程序來讀取和分層多元正態總體與(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]。如果您的問題是版本特定的,您可以爲特定版本添加標籤。但是你的問題不是特定於版本的。 –
你的程序很難閱讀。當你的代碼應該被別人查看時,請使用一致的行縮進。它會幫助你更好地看到結構。 –