fortran - 在 Fortran 90 中打开多个文件

标签 fortran fortran90

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

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

结束

此代码应该生成从 abc24000abc35000 的文件,但它在中途停止了

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

Fortran runtime error: Too many open files

我需要做什么来修复上述代码?

最佳答案

此限制由您的操作系统设置。如果您使用的是 Unix/Linux 变体,则可以使用 ulimit -n 从命令行检查限制,并使用 ulimit -n 16384 提高限制。您需要设置大于 10000 的限制,以允许 shell 打开的所有其他文件。您可能还需要管理员权限才能执行此操作。

我经常将运行 Fortran 程序的限制提高到 2048,但从未高达 10000。但是,我同意其他答案,如果可能的话,最好重组程序以在打开下一个文件之前关闭每个文件。

关于fortran - 在 Fortran 90 中打开多个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7611360/

相关文章:

fortran - 对不同形状的数组使用单个虚拟参数

linux - 如何调试 "Program received signal SIGSEGV: Segmentation fault"的错误

pointers - 具有可分配或指针属性的无限多态虚拟参数?

math - 二维抛物线 PDE 的有限差分

Fortran:管道到程序

python - 将 Fortran 对象导入 Python

fortran - FORTRAN 77 程序比 Fortran 90 程序更快吗?

arrays - Fortran 中是否有用于将数组初始化为零的内在函数?

python - 使用 python-ctypes 将 fortran 与 python 接口(interface)

linux - IMSL 和 MPI 之间的冲突