【发布时间】:2016-07-25 16:46:30
【问题描述】:
我是Fortran新手,需要写一些比较简单的代码。
我有一些文件(各种,例如 200 个文件);特定节点的每个文件,经过一些简化,每个文件包含:
T(i), X(i)
这些是我的输入,我希望输出文件包含:
T(i) X(i)1 X(i)2 ... X(i)n
问题是我无法将输出文件不同列中的数据分开,它们在 1 列中一个接一个地出现。
我的代码是:
PROGRAM Output
implicit none
integer ::nn,n,i,j,l
real,dimension(:),allocatable::t,x,y,z
character(len=10)::TD
open(11,file='outputX.txt')
allocate (t(1000),x(1000),y(1000),z(1000))
n=5 ! Number of Files
nn=50 ! Number of Rows in each File
Do i=1,n ! loop for opening different files
write(TD,10)i
write(*,*)TD
open(1,file=TD)
Do l=1,nn ! loop for reading rows in each file
read(1,*)t(j),x(j)
write(11,*)x(j) !!!! This is my PROBLEM, all the data shows in
! one column, I want each file in separately
Enddo
Enddo
10 format('100',i3.3,'')
deallocate(x,y,z,t)
END PROGRAM Output
我得到的输出是这样的:
11
12
13
21
22
23
31
32
33
但其实我想要:
11 21 31
12 22 32
13 23 33
【问题讨论】:
-
每个
write都会产生一行(“记录”)。您需要将编写的各种值组合到单个输出语句中。比如this question 和this question。