Fortran Coder

寻求帮助

查看数: 876 | 评论数: 4 | 收藏 0
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2023-9-12 11:19

正文摘要:

本帖最后由 IDCY 于 2023-9-12 15:47 编辑 假设两个txt文件 txt1 t=    x=   y= 0     1      2 0     2     ...

回复

IDCY 发表于 2023-9-12 16:07:50
已解决,修改后的代码附上
IDCY 发表于 2023-9-12 16:06:06
IDCY 发表于 2023-9-12 15:43
program main
implicit none
integer,parameter:: nx=21,ny=4

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
IDCY 发表于 2023-9-12 16:05:22
好了 ,我已经改好了
是其中的j=2,ny的问题 应该是j=1,ny
IDCY 发表于 2023-9-12 15:43:05
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-5-18 06:05

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表