[Fortran] 纯文本查看 复制代码
program main
implicit none
integer,parameter::nx=721,ny=604
real::er(nx,ny),ef(nx,ny),e(nx,ny)
integer i,j
! 读入数据
call read_data("C:\Users\zklz\Desktop\er.csv",er)
call read_data("C:\Users\zklz\Desktop\ef.csv",ef)
! 计算
do i=2,721
do j=2,161
e(i,j)=sqrt(er(i,j)**2+ef(i,j)**2)
enddo
enddo
e(1,:)=er(1,:); e(:,1)=er(:,1) ! 保存第一行、第一列
! 输出
call write_data("C:\Users\zklz\Desktop\e.txt",e)
end program main
!-----------------------------
subroutine read_data(filename,data)
implicit none
integer,parameter::nx=721,ny=604
character*(*),intent(in)::filename
real,intent(out)::data(nx,ny)
open(10,file=filename)
do i=1,nx
read(10,*)(data(i,j),j=1,ny)
enddo
close(10)
end subroutine read_data
!-----------------------------
subroutine write_data(filename,data)
implicit none
integer,parameter::nx=721,ny=604
character*(*),intent(in)::filename
real,intent(in)::data(nx,ny)
open(10,file=filename)
do i=1,nx
write(10,*)(data(i,j),j=1,ny)
enddo
close(10)
end subroutine write_data
!-----------------------------