简体   繁体   English

如何读取FORTRAN 77中数据文件中的特定行

[英]How to read a specific line in a data file in FORTRAN 77

I have an external data file which contains several lines with values of parameters. 我有一个外部数据文件,其中包含几行参数值。 This file is used as input data file for several FORTRAN codes. 该文件用作多个FORTRAN代码的输入数据文件。 However, each code does not need all the data. 但是,每个代码都不需要所有数据。 Currently, all codes read the entire data file and keep each one whatever is needed. 目前,所有代码都读取整个数据文件,并保留每个代码。 But, I want to improve this. 但是,我想改进这一点。 Each code reads the external data file using the following commands 每个代码使用以下命令读取外部数据文件

OPEN(UNIT=10,FILE='input.par',STATUS='UNKNOWN')
READ(10,*)val1
READ(10,*)val2
READ(10,*)val3
..............
READ(10,*)valn
CLOSE(10)

So, how can I OPEN the data file and read, let's say for example, only line 4 or lines 1 and 7? 那么,我怎样才能OPEN数据文件并读取,例如,只说第4行或第1行和第7行?

Many thanks in advance. 提前谢谢了。

For example, to read just the first and seventh numbers: 例如,只读取第一个和第七个数字:

read (10, *) val1

do i=1, 5
   read (10, *)
end do

read (10, *) val7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM