Fortran ::(1)的OPEN语句中的语法错误 [英] Fortran :: Syntax error in OPEN statement at (1)

查看:298
本文介绍了Fortran ::(1)的OPEN语句中的语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试通过[diehard测试]测试我的加密算法( http://stat. fsu.edu/pub/diehard/),我意识到我的输入文件必须是未经格式化的直接访问文件. 因此,我尝试在Fortran中编写一个简单程序,以从文件读取并将其写入另一个文件.

I was trying to test my cryptography algorithm by [diehard tests] (http://stat.fsu.edu/pub/diehard/), that I realized my input file must be an unformatted and direct access file. So I tried to write a simple program in Fortran to read from a file and write it to another.

首先,这是制作未格式化或直接访问文件的唯一方法吗?

First of all, is it the only way to make an unformatted or direct access file ?

如果是这样,我会收到此错误

If it is so, I've got this Error

     open(unit=2, file='unf.BIN',RECL=rl , form='UNFORMATTED', access='direct')
                                                                 1

错误:(1)处的OPEN语句中的语法错误

Error: Syntax error in OPEN statement at (1)

我使用RECL是因为Open语句错误中缺少一些RECL参数.( Fortran 90,编译程序:错误消息)

I use RECL because of some missing RECL parameter in Open statement errors.(Fortran 90, Compiling program: Error messages)

这是我的Fortran代码:

Here is my Fortran code:

    program BinaryWriter
    implicit none

    integer :: i
    integer :: p

    open(unit=1,file='encout')
    open(unit=2, file='unf.BIN',RECL=rl , form='UNFORMATTED', access='direct')

    do i=1 ,256
        read (8,'(i1)') p
        write(*,*) p
    end do

    close(1)
    close(2)

    end program BinaryWriter

推荐答案

两件事:

1)请停止使用小于10的单元号.实际上,所有现代Fortran编译器现在都具有newunit标识符,该标识符代替了旧的unit实际选择了未使用的值,所以总是在那里使用变量.但是,即使您想使用unit,请将其设置为10或更大的值.

1) Please stop using unit numbers less than 10. Virtually all modern Fortran compilers do now have the newunit identifier, which, instead of the old unit actually picks an unused value, so always use a variable there. But even if you want to use unit, set it to a value of 10 or more.

2)对于直接访问,程序需要记录长度.因此,如果您有access="direct",则还需要一个recl=<some integer value>来告诉编译器新记录从何处开始.

2) For direct access, the program needs the record length. So if you have access="direct", you also need an recl=<some integer value> to tell the compiler where a new record starts.

在您的情况下,您现在在open语句中有一个RECL=rl条目,但是我看不到rl是什么.它必须是一个正整数.

Now in your case, you have a RECL=rl entry in the open statement, but I can't see what rl is. It needs to be a positive integer.

编辑添加:正如@IanH在问题下方的注释中指出的,您可能正在使用固定格式的fortran.这可能是由于您的源代码文件的文件扩展名是.f.f77.在这种情况下,您必须手动换行:

Edit to add: As @IanH pointed out in a comment below your question, it is possible that you are using fixed form fortran. This might be caused by the file extension of your source code file being .f or .f77. In that case, you'd have to wrap your lines manually:

      program dir
      implicit none
      integer :: rl

      open(unit=20, file='delme.bin', recl=<the record length>, 
     &     form='unformatted', access='direct')
      close(20)
      end program dir

请注意,&位于该行的第6位. Fortran 77代码通常在那里使用+,但是&也与较新的Fortran版本兼容,这就是为什么我更喜欢它. F77标准只是第6位的任何字符.

Note that the & is in the 6th position of the line. Fortran 77 code usually uses a + there, but & is also compatible with newer Fortran versions, that's why I prefer it. F77 standard is just any character in that 6th spot.

这篇关于Fortran ::(1)的OPEN语句中的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆