在FORTRAN阵列格式写 [英] write in array format in fortran
问题描述
我试着写用的 n×n的的矩阵格式的输出FILE.DAT。
我写的code,但输出值f的一列。
现在的问题是:如何更改文件的输出格式写入
?来自:
1
2
4
五
...
要:1,2,3,4 //
5,6,8,... //
程序网加入收藏
隐无
整数参数::格= 800
整数:: I,J,K,N,M
真正的* 8,可分配:: F(:, :)
真正的* 8 :: XX(网格),YY(网格),MVAL,Mxval
真正的* 8,可分配:: X(:),Y(:) 开(10,文件='3d_disk.txt')
N = 0
做
READ(10,* END = 100)
N = N + 1
END DO 100继续
倒带(10) 分配(X(N),Y(N)) 做I = 1,N
读(10,*)×(i)中,Y(I)
做到底
MVAL = -20。
Mxval = 20。
做I = 1,电网
XX(ⅰ)= MVAL +((Mxval - MVAL)*(I-1))/(栅-1)
YY(ⅰ)= MVAL +((Mxval - MVAL)*(I-1))/(栅-1)
做到底 开(20,文件='3d_map.dat') 分配(F(N,N))
F = 0
做I = 1,电网
做J = 1,电网
m = 0时。
做K = 1,N
如果(X(k)的方式> XX(ⅰ)。而X(k)的和所述; XX第(i + 1)。而与放大器;
&安培; Y(K)> YY(J)。和。 Y(K)< YY第(j + 1)),然后
M = M + 1! CONTA IL NUMERO DI PARTICELLE
万一
做到底
F(I,J)=浮子第(m + 1)
我的事情,该修改必须在这里从这个:
写(20,*)F(I,J)
做到底
写(20 *)
打印*,我
做到底
结束程序网加入收藏
到
我= 1,电网
做J = 1,电网
写(20,*)F(I,J)
做到底
做到底做到底
写(20 *)
打印*,我
做到底 结束程序网加入收藏
本声明
写(20,*)F(I,J)
会写的F(I,J)
然后移动到下一行,所以你得到的文件正是你的code是什么样的价值指定。如果你想要的文件包含 N
行,每行以 N
值尝试
写(20,*)F(I,:)
这应该成为一个好刺在整排 I
数组的写入到输出文件的单行。当然,这使你遍历Ĵ
多余的,所以你可以将其删除。
I try to write an output file.dat with an nxn matrix format .
I write the code but the output is a column of value f.
Now the problem is: how can i change the output-format of the file to write?
from: 1 2 4 5 ...
to: 1,2,3,4 // 5,6,8,.. //
program eccen
implicit none
integer, parameter:: grid=800
integer::i,j,k,n,m
real*8,allocatable::f(:,:)
real*8::xx(grid),yy(grid),mval,Mxval
real*8,allocatable::x(:),y(:)
open(10,file='3d_disk.txt')
n=0
DO
READ(10,*,END=100)
n=n+1
END DO
100 continue
rewind(10)
allocate(x(n),y(n))
do i=1, n
read(10,*) x(i),y(i)
end do
mval=-20.
Mxval=20.
do i=1, grid
xx(i) = mval + ((Mxval - mval)*(i-1))/(grid-1)
yy(i) = mval + ((Mxval - mval)*(i-1))/(grid-1)
end do
open(20,file='3d_map.dat')
allocate(f(n,n))
f=0
do i=1,grid
do j=1,grid
m=0.
do k=1, n
if (x(k) > xx(i) .and. x(k) < xx(i+1) .and. &
& y(k) > yy(j) .and. y(k) < yy(j+1)) then
m=m+1 ! CONTA IL NUMERO DI PARTICELLE
end if
end do
f(i,j)=float(m+1)
I thing that the modification must be here from this:
write(20,*) f(i,j)
end do
write(20,*)
print *,i
end do
end program eccen
to:
do i=1,grid
do j=1,grid
write(20,*) f(i,j)
end do
end do
end do
write(20,*)
print *,i
end do
end program eccen
This statement
write(20,*) f(i,j)
will write the value of f(i,j)
then move to the next line, so the file you're getting is exactly what your code is specifying. If you want the file to contain n
rows each with n
values try
write(20,*) f(i,:)
which ought to make a good stab at writing the whole of row i
of the array to a single line in the output file. Of course, this makes your loop over j
redundant so you can remove it.
这篇关于在FORTRAN阵列格式写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!