Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Fortran 读符号指数_Fortran_Gfortran_Exponential - Fatal编程技术网

Fortran 读符号指数

Fortran 读符号指数,fortran,gfortran,exponential,Fortran,Gfortran,Exponential,我在使用Fortran从文本文件中读取指数时遇到问题 文本文件中的条目如下所示 0.02547163e+06-0.04601176e+01 0.02500000e+02 0.00000000e+00 0.00000000e+00 3 read(iunit,'(ES20.8,ES20.8,ES20.8,ES20.8,ES20.8,I2)') dummy1, dummy2, Thermo_DB_Coeffs_LowT(iS,1:3),temp 我使用的代码如下所示 0.02

我在使用Fortran从文本文件中读取指数时遇到问题

文本文件中的条目如下所示

  0.02547163e+06-0.04601176e+01 0.02500000e+02 0.00000000e+00 0.00000000e+00    3
   read(iunit,'(ES20.8,ES20.8,ES20.8,ES20.8,ES20.8,I2)') dummy1, dummy2, Thermo_DB_Coeffs_LowT(iS,1:3),temp 
我使用的代码如下所示

  0.02547163e+06-0.04601176e+01 0.02500000e+02 0.00000000e+00 0.00000000e+00    3
   read(iunit,'(ES20.8,ES20.8,ES20.8,ES20.8,ES20.8,I2)') dummy1, dummy2, Thermo_DB_Coeffs_LowT(iS,1:3),temp 
我得到的错误是

Fortran运行时错误:浮点读取期间的值错误


如何读取这些值

当手工编辑文件太痛苦时,我通常会这样做

CHARACTER(LEN=256)   :: Line
INTEGER, PARAMETER   :: Start = 1
INTEGER              :: Fin, Trailing_Int, I
DOUBLE, DIMENSION(6) :: Element
...

Ingest_All_Rows: DO WHILE(.TRUE.)
  READ(...) Line  ! Into a character-string
  <if we get to the end of the file, then 'EXIT Ingest_All_Rows'>

  Start =1
  Single_Row_Ingest: DO I = 1, 6
    Fin = SCAN(Line,'eE')+3  !or maybe it is 4?
    IF(I ==6) Fin = LEN_TRIM(Line)
    READ(Line(Start:Fin),*) Element(I)   !fron the string(len-string) to the double.
    Line = Line((Fin+1):)
    IF(I ==6) Trailing_Int = Element(6)
  ENDDO Single_Row_Ingest

  <Here we shove the row's 5 elements into some array, and the trailing int somewhere>
ENDDO Ingest_All_Rows
字符(LEN=256)::行
整数,参数::Start=1
整数::Fin,training_Int,I
双精度,尺寸(6)::元件
...
摄取所有行:执行WHILE(.TRUE.)
读(…)行!转换为字符串
开始=1
单行摄取:I=1,6吗
Fin=扫描(线,'eE')+3!或者可能是4?
如果(I==6)Fin=LEN_修剪(直线)
读取(行(起始:Fin),*)元素(I)!从字符串(len字符串)到双精度字符串。
行=行((Fin+1):)
如果(I==6)尾随元素(6)
ENDDO单排摄入

reals的字段宽度是20,但这不适合输入。你能检查一下这里的输入是否正确吗?我会使用一些文本处理工具(例如
sed
)在文件中的f-p值一起运行的地方加上空格,然后用列表定向输入读取。试试
15.8
。而且我不认为
S
对输入有任何作用,所以只要
E15.8
。去和那些创建了这样一个文件的人谈谈吧,这个文件中的数字是同时运行的,没有分隔符的。@agentp说,使用
ES
输入就像使用
E
输入一样。这进一步被视为
F
。此外,您不应使用
F15.8
,而应使用
F15.0
(或任何字段宽度)。通常应避免格式化
读取
,因为它不提供任何功能,并且只会导致故障,具体取决于要读取的数据。我同意HPF,数据文件需要修改(通过
sed
或编辑器中的宏),以便用空格分隔数字(一个空格就足够了,但您可以添加更多,这并不重要)。然后
read(iunit,*)
就可以完美地完成这项工作。虽然我总是使用格式化打印,但除了寻找潜在的麻烦外,我真的看不到任何使用格式化阅读的理由。