[Fortran] 纯文本查看 复制代码
program main
implicit none
real,dimension(721,161)::er
real,dimension(721,161)::ef
real,dimension(721,161)::e
integer i,j
open(unit=10,file="C:\Users\zklz\Desktop\er.csv")
open(unit=20,file="C:\Users\zklz\Desktop\ef.csv")
open(unit=30,file="C:\Users\zklz\Desktop\e.txt")
do i=1,721
read(10,*)(er(i,j),j=1,161)
read(20,*)(ef(i,j),j=1,161)
end do
close(10)
close(20)
do j=1,161
do i=1,721
if(i==1.or.j==1)then
e(i,j)=er(i,j)
else if(i/=1.and.j/=1)then
e(i,j)=sqrt(er(i,j)**2+ef(i,j)**2)
end if
end do
write(30,*)(e(i,j),i=1,721)
end do
close(30)
end
[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
!-----------------------------