【发布时间】:2016-10-16 20:48:36
【问题描述】:
我正在使用 Fortran 制作一个用于 CFD 浅水软件的子程序。
我编写了这段代码来读取和使用存储的值。
PROGRAM hieto
! Calcula la precipitacion efectiva en funcion del tiempo
!IMPLICIT NONE
real::a
!Abrir CSV
!OPEN(UNIT=10,FILE="datos.txt",FORM="formatted",STATUS="replace",ACTION="readwrite",ACCESS='sequential')
open(unit=10, file='datos.txt')
!Leer el archivo
read(10, *, iostat=ios)a
print*,ios
print*, a
close (UNIT=10)
END PROGRAM hieto
我的文本文件datos,看起来像这样
1
2
3
当我按原样运行代码时,我得到以下输出
-1
0.0000000000
Process return 0 (0x0) execution time: 0.002 s
第一行的第一个数字不是零,所以我不知道为什么会这样。
如果我从 read 语句中删除 iostat=ios,我会收到以下错误:
At ine 13 (the line od the read stament) of file /home/Dropbox/scripts_tesis/fortran/hieto_telemac.f90 (unit=10, file=datos.txt')
Fortran runtime error: end of file.
Proceess returned 2 (0x2)
我已经在这里阅读了一些答案,所以我尝试在 read 语句中添加end=3,并在我的文本文件末尾添加一个空行。
end=3 给出一个错误,指出 3 不是定义的标签,并且在文本文件中放置一个空白行没有任何作用。
我正在使用 ubuntu 16.04 LTS 和 Gfortran 编译器。
【问题讨论】:
-
感谢您的回答,但我确实阅读了此内容,并使用如何阅读直到文件结尾 (EOF)?本 Wiki Fortran (fortranwiki.org/fortran/show/FAQ) 的一部分。我更改了代码以使其运行,但我之前曾尝试过。