我正在使用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
一個行中的第一個號碼是一個不是零,所以我不知道爲什麼會發生這種情況。
如果我從讀語句刪除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)
所以我想在讀語句添加end=3
我在這裏讀了一些答案,也結束我的文字文件末尾有空行。 end=3
給出了一個錯誤,說3不是一個定義的標籤,並在文本文件中放置一個空白行什麼也不做。
我使用的是Ubuntu 16.04 LTS和Gfortran編譯器。
謝謝你的回答,但我沒有讀過這個,並使用我如何閱讀,直到一個文件(EOF)結束?這個Wiki Fortran的一部分(http://fortranwiki.org/fortran/show/FAQ)。我改變了代碼使它運行,但我以前嘗試過。 –