[Fortran] 纯文本查看 复制代码
program main
implicit none
character(*),parameter :: infile='Depth.01',outfile='Depth2.01'
integer :: i,j
real,dimension(521,1440):: m
real,dimension(521,1440):: b
OPEN(UNIT=20,FILE=infile)
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)
enddo
!赋值
do i=1,521
do j=4,1437
if(m(i,j)==-999) then
b(i,j)=1
else if(m(i,j)/=-999.and.m(i,j)==-999) then !999陆地
b(i,j)=2 !2 海岸线
b(i,j-1)=2 !1 海洋
b(i,j-2)=2
b(i,j-3)=2
else if(m(i,j)==-999 .and. m(i,j+1)/=-999) then
b(i,j)=2
b(i,j+1)=2
b(i,j+2)=2
b(i,j+3)=2
else if (m(i,j)<200) then
b(i,j)=2
else
b(i,j)=m(i,j)
endif
enddo
enddo
!写入新文件
do i=1,521
write(30,'(1440(I6))') (b(i,j),j=1,1440)
end do
99 stop
end program main
[Fortran] 纯文本查看 复制代码
program main
implicit none
Integer , parameter :: NX = 521 , NY = 1440 , SLAND = -999!//定义常量,以便容易修改
character(*),parameter :: infile='Depth.01',outfile='Depth2.01'
integer :: i,j
real,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,*,end=99) m(i,:)!//数组片段,简化代码
enddo
!赋值
do i=1,NX
do j=1+3,NY-3
if(m(i,j)==SLAND) then
b(i,j)=1
else if(m(i,j)/=SLAND.and.m(i,j+1)==SLAND) then!//此处是否m(i,j+1)??
b(i,j-3:j)=2!//数组片段,简化代码
else if(m(i,j)==SLAND .and. m(i,j+1)/=SLAND) then
b(i,j:j+3)=2!//数组片段,简化代码
else if (m(i,j)<200) then
b(i,j)=2
else
b(i,j)=m(i,j)
endif
enddo
enddo
!写入新文件
do i=1,NX
write(30,'(*(f13.4))') b(i,:)!// *(f13.4) 表示有多少个算多少个。
end do
99 close(20)!//良好的关闭文件习惯
close(30)
end program main
[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