在fortran中读取多个文件 [英] reading multiple files in fortran

查看:920
本文介绍了在fortran中读取多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有数百个文件名为fort.1,fort.2,fort.3的文件,依此类推直到fort。5000。
我想要的是打开每个文件并操作该文件并关闭。然后继续下一个文件。我想在Fortran 90中做到这一点。

I have hundreds of files with file name fort.1, fort.2, fort.3 and so on until fort.5000. What I want is to open each file and operate that file and close. Then go on with next file. I want to do this in Fortran 90.

我浏览过但无法获得我想要的内容。我看到一个线索开放,但它对我没有多大帮助。

I have browsed but could not get what I want. I saw one thread for opening but it doesn't help me much.

我试着写``b
$ b

I tried writing `

program openFile
IMPLICIT none
INTEGER(I-N), REAL*8(A-H,O-Z)
real,dimension(2000) :: angle           
CHARACTER(len=10) FN
integer::I, k
integer,parameter :: N=102  
DO I=101,N
!WRITE(FN,10) I
!WRITE(6,*) FN
OPEN(1,FILE=FN)
do k=1,200
read(1,'(F8.3)') angle(k)
print*,
end do      
CLOSE(1)
enddo 
10 FORMAT(5Hfort.I3)
STOP
END

`
但似乎不起作用。这可能让我得到一些帮助吗?
在此先感谢。

` But seems it doesn't work. Is that possible me getting some help? Thanks in advance.

推荐答案

该方法是在字符串中创建文件名。对于你的名字风格:

The approach is to create the filename in a string. For your style of names:

write (filename, '("fort.", I0)' )  FileNum

然后使用文件名打开每个文件,就像您在做的一样。

Then open each file using the filename, as you are doing.

相关问题: https://stackoverflow.com/questions/13048441 /写入文件在fortran与增加数字

这篇关于在fortran中读取多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆