Fortran Coder

查看: 22557|回复: 15
打印 上一主题 下一主题

[文件读写] Fortran读取文本文件出错

[复制链接]

490

帖子

4

主题

0

精华

大宗师

F 币
3298 元
贡献
1948 点

水王勋章元老勋章热心勋章

楼主
发表于 2018-1-5 14:34:15 | 显示全部楼层
有open无close,自然会出错

490

帖子

4

主题

0

精华

大宗师

F 币
3298 元
贡献
1948 点

水王勋章元老勋章热心勋章

沙发
发表于 2018-1-7 15:00:39 | 显示全部楼层
本帖最后由 pasuka 于 2018-1-7 15:04 编辑
向着光亮 发表于 2018-1-5 15:34
并不是这个问题,请您仔细看问题,OPEN和close并没有直接绝对关系

少年,有open无close这样的陋习,早晚会栽跟头!
Python有with关键字,光open就行,可惜fortran没有open的说明文档
https://docs.oracle.com/cd/E1995 ... j4m0vnaf/index.html
If you open a unit that is already open without specifying a file name (or with the previous file name), FORTRAN thinks you are reopening the file to change parameters. The file position is not changed. The only parameters you are allowed to change are BLANK (NULL or ZERO) and FORM (FORMATTED or PRINT). To change any other parameters, you must close, then reopen the file.
怎么能说没有关系呢?

490

帖子

4

主题

0

精华

大宗师

F 币
3298 元
贡献
1948 点

水王勋章元老勋章热心勋章

板凳
发表于 2018-1-8 10:27:28 | 显示全部楼层
向着光亮 发表于 2018-1-7 19:57
而且我打开的是有文件名的文件,只是读取数据出错了

之前就有人指出了,数据量不够
截图一行只有12个数据,数据a有13数据
http://tpcg.io/1VGH45
[Fortran] 纯文本查看 复制代码
program hello
implicit none
character(len=255):: src
real(kind=4):: a(13)
a=0.0E0
src = "20.332 12.1 0.063 429.0 "
!! Not enough data
!read(src, *)a
!! 4 float number in src
read(src, *)a(1:4)
write(*, *)"a = ", a

end program Hello

您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-3 11:36

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表