两个数组的计算问题
两组数据分别在两个文件中。格式一摸一样。第一行是半径坐标,第一列是角度坐标,剩下的是对应的数值,共721行,161列要算的是把两组数据的平方和开根号生成在一个新的文件中,坐标轴不变,写的代码问题很大,求大佬指导·。感觉还是没学明白循环和定义,有没有大佬指条明路啊
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
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
!-----------------------------
循环不明白,你连教材都没看吧,静下心来看半小时就足够足够的了 necrohan 发表于 2019-12-2 16:24
循环不明白,你连教材都没看吧,静下心来看半小时就足够足够的了
感觉连基本的认识都没有啊,看教材感觉有时候看不太明白 wawewen 发表于 2019-12-2 16:37
感觉连基本的认识都没有啊,看教材感觉有时候看不太明白
如果不能看进去,以后问题只会更多 necrohan 发表于 2019-12-3 11:05
如果不能看进去,以后问题只会更多
又除了彭国伦的书,大佬有没有推荐的教材 wawewen 发表于 2019-12-3 15:29
又除了彭国伦的书,大佬有没有推荐的教材
随便找一本
http://pan.fcode.cn/
页:
[1]