怎么 循环读取二维数组并赋值?
program mainimplicit none
character(*),parameter :: infile='Depth.txt',outfile='Depth2.txt'
integer :: i,j
real,dimension(521,1440):: m
OPEN(UNIT=20,FILE=infile,STATUS='OLD',ACTION='read')
OPEN(UNIT=30,FILE=outfile,status='replace',action='write')
do i=1,521
READ(20,'(1440(I6))',end=99) (m(i,j),j=1,1440)
If(m(i,j)/=-999 .and. m(i,j+1)==-999) then
m(i,j)=2 ! 1 represents ocean
m(i,j-1)=2 ! 2 represents coastline
m(i,j-2)=2 ! -999 represents land
m(i,j-3)=2
else if(m(i,j)==-999 .and. m(i,j+1)/=-999) then
m(i,j)=2
m(i,j+1)=2
m(i,j+2)=2
m(i,j+3)=2
else if (m(i,j)<200) then
m(i,j)=2
else
m(i,j)=1
End if
write(30,'(1440(I6))') (m(i,j),j=1,1440)
end do
!100 format (1440I6)
99 stop
end program main
在 if 条件判断那里出了问题,不知道能不能这样读?请大家帮忙看看,读写都没问题,循环读取 赋值就开始出错
请大家帮忙看看,读写都没问题,循环读取 赋值就开始出错 吃饭叫我 发表于 2018-9-28 10:54
请大家帮忙看看,读写都没问题,循环读取 赋值就开始出错
do i=1,521
READ(20,'(1440(I6))',end=99) (m(i,j),j=1,1440)
If(m(i,j)/=-999 .and. m(i,j+1)==-999) then ! variable "j" undefined do i=1,521
READ(20,'(1440(I6))',end=99) (m(i,j),j=1,1440)
DO j = (1+3), (1440-3)
if(m(i,j)/=-999 .and. m(i,j+1)==-999) then
m(i,j)=2 ! 1 represents ocean
m(i,j-1)=2 ! 2 represents coastline
m(i,j-2)=2 ! -999 represents land
m(i,j-3)=2
else if(m(i,j)==-999 .and. m(i,j+1)/=-999) then
m(i,j)=2
m(i,j+1)=2
m(i,j+2)=2
m(i,j+3)=2
else if (m(i,j)<200) then
m(i,j)=2
else
m(i,j)=1
end if
END DO
write(30,'(1440(I6))') (m(i,j),j=1,1440)
end do chiangtp 发表于 2018-9-28 14:38
do i=1,521
READ(20,'(1440(I6))',end=9 ...
C:\Users\zhou\Desktop\QQ截图20181007205518.png
谢谢,这个确实是我疏忽了,不过改了之后变成了这样。循环读取和赋值 的结果都变成了 * 是格式不对吗
页:
[1]