[Fortran] 纯文本查看 复制代码
program main
implicit none
Integer , parameter :: NX = 521 , NY = 1440 , SLAND = -999
character(*),parameter :: infile='Depth.01',outfile='Depth2.01'
integer :: i,j
integer,dimension(NX,NY):: m, b
OPEN(UNIT=20,FILE=infile)
OPEN(UNIT=30,FILE=outfile,status='replace',action='write')
!读取文件
do i=1,NX
read(20,'(*(I6))',end=99) m(i,:) !//数组片段,简化代码
enddo
!赋值
do i=1,NX
do j=1,4
I if(m(i,j)==SLAND) then
b(i,j)=m(i,j)
else if(m(i,1)/=SLAND.and.m(i,2)==SLAND) then
b(i,1)=1
else if(m(i,2)/=SLAND.and.m(i,3)==SLAND) then
b(i,1:2)=1
else if(m(i,3)/=SLAND.and.m(i,4)==SLAND) then
b(i,1:3)=1
else if(m(i,1)==SLAND.and. m(i,2)/=SLAND) then
b(i,2:3)=1
else if(m(i,2)==SLAND.and. m(i,3)/=SLAND) then
b(i,3)=1
else if (m(i,j)<200) then
b(i,j)=1
else
b(i,j)=555
endif
enddo
enddo
do i=1,NX
do j=1+3,NY-3
if(m(i,j)==SLAND) then
b(i,j)=m(i,j)
else if(m(i,j)/=SLAND.and.m(i,j+1)==SLAND) then !//此处是否m(i,j+1)??
b(i,j-3:j)=1 !//数组片段,简化代码
else if(m(i,j)==SLAND .and. m(i,j+1)/=SLAND) then
b(i,j:j+3)=1 !//数组片段,简化代码
else if (m(i,j)<200) then
b(i,j)=1
else
b(i,j)=555
endif
enddo
enddo
do i=1,NX
do j=NY-3,NY
I if(m(i,j)==SLAND) then
b(i,j)=m(i,j)
else if(m(i,NY-2)/=SLAND.and.m(i,NY-1)==SLAND) then
b(i,NY-2)=1
else if(m(i,NY-1)/=SLAND.and.m(i,NY)==SLAND) then
b(i,NY-2:NY-1)=1
else if(m(i,NY-3)==SLAND.and. m(i,NY-3)/=SLAND) then
b(i,NY-2:NY)=1
else if(m(i,NY-2)==SLAND.and. m(i,NY-1)/=SLAND) then
b(i,NY-1:NY)=1
else if(m(i,NY-1)==SLAND.and. m(i,NY)/=SLAND) then
b(i,NY)=1
else if (m(i,j)<200) then
b(i,j)=1
else
b(i,j)=555
endif
enddo
enddo
!写入新文件
do i=1,NX
write(30,'(*(I6))') b(i,:)
end do
99 close(20)
close(30)
end program main