把txt文档中的每一列数据按每一行固定数据个数输出
本帖最后由 wawewen 于 2019-11-25 16:10 编辑文件如图1所示,纵轴是角度,横轴是半径,现在要将每个半径下的数据生成到另一个txt文档中,按每行十个数据输出,每组数据之前要有对应的半径,如图2所示
写的代码却只输出了第一列也就是角度的数据,还是按列输出如图3,请大佬指正
program main
implicit none
real,dimension(721,604)::a
integer i,j
open(unit=10,file="C:\Users\Lenovo\Desktop\1.csv")
open(unit=20,file="C:\Users\Lenovo\Desktop\BMap.txt")
do j=2,604
do i=1,721
read(10,*,end=1)a(i,j)
if(i==1)then
write(20,*)a(i,j)
else if(i/=1)then
write(20,100)a(i,j)
100format(10f9.2)
end if
end do
end do
1 close(10)
close(20)
end
第一个把end=1去掉后提示end-of-file during read数据是721行,604列用第二个写了一下运行后提示array bounds exceeded
program main
implicit none
real,dimension(721,604)::a
integer i,j
open(unit=10,file="C:\Users\Lenovo\Desktop\1.csv")
open(unit=20,file="C:\Users\Lenovo\Desktop\BMap.txt")
do j=1,604
read(10,*,end=1)(a(i,j),i=1,721)
if(j==1)cycle
if(i==1)then
write(20,*)a(i,j)
else if(i/=1)then
write(20,100)a(i,j)
100 format(10f9.2)
end if
end do
1 close(10)
close(20)
end
本帖最后由 necrohan 于 2019-11-26 12:17 编辑
program main
implicit none
integer,parameter::nx=721,ny=604
real::a(nx,ny)
integer i,j
! 读入全部数据
open(10,file="C:\Users\Lenovo\Desktop\1.csv")
do j=1,ny
read(10,*,end=1)(a(i,j),i=1,nx)
enddo
close(10)
! 输出
open(20,file="C:\Users\Lenovo\Desktop\BMap.txt")
do i=2,nx
write(20,*)a(i,1)
write(20,'((10f9.2))')(a(i,j),j=1,ny)
enddo
close(20)
1 continue
end necrohan 发表于 2019-11-26 12:16
program main
implicit none
integer,parameter::nx=721,ny=604
多谢指点,已经完成了
页:
[1]