Fortran模块读取文件

时间:2018-02-21 20:16:25

标签: fortran

我正在尝试编写一个包含所有数据的模块。并且数据存储在txt文件中。我想知道每次我在主程序中使用模块时,模块是否会再次读取文件?我希望模块在第一次调用模块时只读取文件一次并将其存储为全局变量。因此,我可以通过减少打开和阅读文件的时间浪费来加快我的主程序。我可以知道如何实现这一目标吗?谢谢!

MODULE DATA

implicit none

contains

Subroutine readfile(indexnum, filename1, filename2, filename3, rootpath,b1, 
b2, SOFX, SOFY, Lx, Ly)

Character(400) ::indexnum, filename1, filename2, filename3, rootpath
real ::b1, b2, SOFX, SOFY, Lx, Ly


Open(unit = 11, file = "D:\rootpath.txt")

Read (11,*) rootpath

close (unit = 11)



filename1 = trim(rootpath)//"\index number.txt"

Open (unit = 51, file = filename1)

read (51, *) indexnum

close (unit = 51)



filename1 = trim(rootpath)//"\SOFandN.txt"

Open (unit = 72, file = filename1)

read (72, *) SOFX, SOFY, Lx, Ly

close (unit = 72)
return

End subroutine readfile
End module data

0 个答案:

没有答案