Fortran Coder

楼主: mao
打印 上一主题 下一主题

[文件读写] open打开已有文件出错,segmentation fault, invalid memory reference

[复制链接]

490

帖子

4

主题

0

精华

大宗师

F 币
3298 元
贡献
1948 点

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

11#
发表于 2018-2-5 13:40:02 | 只看该作者
本帖最后由 pasuka 于 2018-2-5 13:42 编辑
mao 发表于 2018-2-5 13:35
谢谢。
看过OPEN的说明,我的代码应该是对的吧,现在的问题是:Status=‘OLD’时候, 文件存在会出错。 ...

文档不是说了吗?'OLD'-- The file already exists (nonexistence is an error). 文件若是不存在则报错
程序代码没有问题,不能推导出程序要打开的文件及其路径也没问题啊?
再说,Stack Overflow上面的帖子已经给出参考代码,为啥不试着跑跑呢?
师傅领进门,修行在自身。

17

帖子

2

主题

0

精华

入门

F 币
94 元
贡献
58 点

规矩勋章

10#
 楼主| 发表于 2018-2-5 13:35:34 | 只看该作者
pasuka 发表于 2018-2-5 10:23
Fortran规范写得很明白,传送门https://docs.oracle.com/cd/E19957-01/805-4939/6j4m0vnaf/index.html

Sta ...

谢谢。
看过OPEN的说明,我的代码应该是对的吧,现在的问题是:Status=‘OLD’时候, 文件存在会出错。

490

帖子

4

主题

0

精华

大宗师

F 币
3298 元
贡献
1948 点

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

9#
发表于 2018-2-5 10:23:53 | 只看该作者
Fortran规范写得很明白,传送门https://docs.oracle.com/cd/E1995 ... j4m0vnaf/index.html
STATUS=sta
The STATUS=sta clause is optional. sta is a character expression. Possible values are: 'OLD', 'NEW', 'UNKNOWN', or 'SCRATCH'.
'OLD'-- The file already exists (nonexistence is an error). For example: STATUS='OLD'.
'NEW' -- The file doesn't exist (existence is an error). If 'FILE=name' is not specified, then a file named 'fort.n' is opened, where n is the specified logical unit.
'UNKNOWN' -- Existence is unknown. This is the default.
'SCRATCH' -- For a file opened with STATUS='SCRATCH', a temporary file with a name of the form tmp.FAAAxnnnnn is opened. Any other STATUS specifier without an associated file name results in opening a file named 'fort.n', where n is the specified logical unit number. By default, a scratch file is deleted when closed or during normal termination. If the program aborts, then the file may not be deleted. To prevent deletion, CLOSE with STATUS='KEEP'.
The FORTRAN 77 Standard prohibits opening a named file as scratch: if OPEN has a FILE=name option, then it cannot have a STATUS='SCRATCH' option. This FORTRAN extends the standard by allowing opening named files as scratch. @ Such files are normally deleted when closed or at normal termination.
TMPDIR: FORTRAN programs normally put scratch files in the current working directory. If the TMPDIR environment variable is set to a writable directory, then the program puts scratch files there. @

Stack Overflow上面的类似问题以及解决建议
https://stackoverflow.com/questi ... and-the-append-data

17

帖子

2

主题

0

精华

入门

F 币
94 元
贡献
58 点

规矩勋章

8#
 楼主| 发表于 2018-2-5 10:06:04 | 只看该作者
vvt 发表于 2018-2-5 09:55
不需要额外设置。那您就换个编译器吧

谢谢

我今天在另外两台电脑上都试了,同样的设置与代码,同样的错误,感觉是个共性问题。肯定是那个地方没弄好。不然不会这样的。只是不是到原因。。。

954

帖子

0

主题

0

精华

大师

F 币
184 元
贡献
75 点

规矩勋章元老勋章新人勋章水王勋章热心勋章

QQ
7#
发表于 2018-2-5 09:55:41 | 只看该作者
不需要额外设置。那您就换个编译器吧

17

帖子

2

主题

0

精华

入门

F 币
94 元
贡献
58 点

规矩勋章

6#
 楼主| 发表于 2018-2-5 00:19:55 | 只看该作者
vvt 发表于 2018-2-4 10:47
我帮不了你了,我自己测试过了,没有问题。我不知道在你的计算机上发生了什么。 ...

测试在FTN95(plato)里面一切正常,所以估计 电脑本身软件冲突 和 语句方面没有问题,是不是codeblocks使用前需要什么特别的设置??

我是如下这样的(基本按照长安大学李博士PPT第一章设置的):
(1) codeblocks软件源: http://www.codeblocks.org/downloads/26, 直接下载的 codeblocks-17.12mingw_fortran-setup.exe

(2) 设置: 按照 http://fcode.cn/guide-39-1.html, “Code::blocks + GFortran开发环境设置方法”

没有其余动作。请问: 可能还需要其他设置么?谢谢。

17

帖子

2

主题

0

精华

入门

F 币
94 元
贡献
58 点

规矩勋章

5#
 楼主| 发表于 2018-2-4 23:21:54 | 只看该作者
vvt 发表于 2018-2-4 10:47
我帮不了你了,我自己测试过了,没有问题。我不知道在你的计算机上发生了什么。 ...

谢谢你。这个问题很让人很奔溃,我再看看吧,谢谢

954

帖子

0

主题

0

精华

大师

F 币
184 元
贡献
75 点

规矩勋章元老勋章新人勋章水王勋章热心勋章

QQ
地板
发表于 2018-2-4 10:47:54 | 只看该作者
我帮不了你了,我自己测试过了,没有问题。我不知道在你的计算机上发生了什么。

17

帖子

2

主题

0

精华

入门

F 币
94 元
贡献
58 点

规矩勋章

板凳
 楼主| 发表于 2018-2-3 23:26:04 | 只看该作者
vvt 发表于 2018-1-3 08:24
我用 Code::Blocks 试了一下,没有问题。不会出错。
你想想看,是不是操作上有问题?比如修改了代码但没有 ...

谢谢您的回答。操作应该是对的。各种反复都能重复问题。
我提问后,后来想是不是设置或者什么别的有问题,可能我没有看到。所以就跟着彭国伦老师的书从头一直做到文件操作这部分,期间也没有发现有什么注意事项需要的,所以现在还是有同样的问题。
* 原路径没有文件的话一切正常,可写入。
* 原路径只要有同名文件,status是old, new, replace都是同样的错误。
不知道为什么这样? 权限也该没有问题,管理员权限。
谢谢。

954

帖子

0

主题

0

精华

大师

F 币
184 元
贡献
75 点

规矩勋章元老勋章新人勋章水王勋章热心勋章

QQ
沙发
发表于 2018-1-3 08:24:49 | 只看该作者
我用 Code::Blocks 试了一下,没有问题。不会出错。
你想想看,是不是操作上有问题?比如修改了代码但没有重新编译链接,或者编译链接出错,而运行了原来的程序?
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

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

GMT+8, 2024-5-19 23:00

Powered by Tencent X3.4

© 2013-2024 Tencent

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