已解决,修改后的代码附上 |
IDCY 发表于 2023-9-12 15:43 subroutine read_data(filename,data) implicit none integer i,j integer,parameter:: nx=21,ny=4 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) end do close(10) end subroutine read_data subroutine write_data(filename,data) implicit none integer i,j integer,parameter:: nx=21,ny=4 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) end do close(10) end subroutine write_data |
好了 ,我已经改好了 是其中的j=2,ny的问题 应该是j=1,ny |
program main implicit none integer,parameter:: nx=21,ny=4 real::er(nx,ny),ef(nx,ny),e(nx,ny) integer i,j call read_data("C:\Users\20455\Desktop\error\result.dat",er) call read_data("C:\Users\20455\Desktop\error\Riemann.dat",ef) do i=1,nx do j=2,ny e(i,j)= abs(er(i,j)-ef(i,j)) end do end do e(:,1)=er(:,1) call write_data("C:\Users\20455\Desktop\error\error.dat",e) end program main subroutine read_data(filename,data) implicit none integer i,j integer,parameter:: nx=21,ny=4 character*(*),intent(in)::filename real,intent(out)::data(nx,ny) open(10,file=filename) do i=1,nx do j=2,ny read(10,*)(data(i,j)) end do end do close(10) end subroutine read_data subroutine write_data(filename,data) implicit none integer i,j integer,parameter:: nx=21,ny=4 character*(*),intent(in)::filename real,intent(in)::data(nx,ny) open(10,file=filename) do i=1,nx do j=1,ny write(10,*)(data(i,j)) end do end do close(10) end subroutine write_data |
捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )
GMT+8, 2024-11-22 01:35