在Fortran 90中打开多个文件 [英] Opening multiple files in Fortran 90

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

问题描述

我想打开10,000个文件,文件名从 abc25000 直到 abc35000 ,并将一些信息复制到每个文件中文件。我写的代码如下:

  PROGRAM puppy 
IMPLICIT NONE

integer ::
CHARACTER(len = 3):: n1
CHARACTER(len = 5):: cnum
CHARACTER(len = 8):: n2

loop1:do i = 25000,35000!in a frame

n1 ='abc'
write(cnum,'(i5)')i
n2 = n1 // cnum
print *,n2
open(unit = i,file = n2)

enddo loop1

end

此代码应该生成从 abc24000 直到 abc35000 ,但它大约停止了一半说


在文件的第17行test-openFile.f90(unit = 26021,file ='')



Fortran运行时错误:打开的文件太多


我需要做些什么来修复上面的代码?

解决方案

一次处理一个文件(或者不超过li的小组)由操作系统强加的)。对于每个文件,

 

打开文件
写入
关闭文件


I would like to open 10,000 files with file names starting from abc25000 until abc35000 and copy some information into each file. The code I have written is as below:

PROGRAM puppy
IMPLICIT NONE

integer :: i
CHARACTER(len=3) :: n1
CHARACTER(len=5) :: cnum
CHARACTER(len=8) :: n2

loop1: do i = 25000 ,35000  !in one frame

  n1='abc'
  write(cnum,'(i5)') i
  n2=n1//cnum
  print*, n2
  open(unit=i ,file=n2)

enddo loop1

end

This code is supposed to generate files starting from abc24000 until abc35000 but it stops about half way saying that

At line 17 of file test-openFile.f90 (unit = 26021, file = '')

Fortran runtime error: Too many open files

What do I need to do to fix the above code?

解决方案

You need to work on the files one at a time (or in small groups that do not exceed the limitation imposed by the operating system).

for each file:
  open file
  write
  close file

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

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