在CARRIAGECONTROL =处使用gfortran的OPEN语句中的语法错误 [英] Syntax error in OPEN statement with gfortran at CARRIAGECONTROL=

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

问题描述

当我尝试使用Cygwin编译一个名为'zone_b.f'的Fortran源文件来产生可执行程序时,遇到一些错误。



Fortran文件是从网上下载。确切的代码可以从 here < a>。



当我尝试使用以下命令进行编译时,它会产生以下错误:

  $ gfortran zone_b.f 
zone_b.f:54:72:

call getzone(zone_start,zone_end,selection_on,line(3:76))
1
错误:在(1)
的SUBSTRING规范中出现语法错误zone_b.f:61:28:

& form ='FORMATTED',carriagecontrol ='LIST',
1
错误:在(1)处的OPEN语句中出现语法错误

我怀疑这是因为Fortran文件是旧格式,但是当我尝试从

 $ 




pre code> C:\F\York> g77 zone_b.f -o zone_b.exe
zone_b.f:在程序`zone_b'中:
zone_b.f:60:
打开(5,status ='OLD',file =行,
^

在(^)不支持的OPEN控制项目 - ACTION =,ASSOCIATEVARIABLE =,
BLOCKSIZE =, BUFFERCOUNT =,CARRIAGECONTROL =,DEFAULTFILE = DELIM = DISPOSE =
EXTENDSIZE = INITIALSIZE = KEY = MAXREC = NOSPANBLOCKS ORGANIZATION = PAD = =,SHARED =和USEROPEN =不支持

如何解决这些问题问题?

第一个错误可能意味着该行太长。固定格式源只允许72个字符长的行。您可以使用特殊标志,如 - 固定行长度n ,其中 n 是一个数字。您可以使用 -ffixed-line-length-0 作为无限长度。在这个网站上有很多类似的问题。






CARRIAGECONTROL = 说明符在 OPEN 语句中不是标准的。
从open语句中删除可能会很好。我肯定会为我自己的代码做这件事。



第60-62行:

  open(5,status ='OLD',file = line,
& form ='FORMATTED',carriagecontrol ='LIST',
& READONLY,err = 400)

可以更改为

  open(5,status ='OLD',file = line,
& form ='FORMATTED',err = 400)
pre>

,代码会在旧版本的gfortran中编译(我试过4.8到6)。

你也可以添加 ACTION =读取但它并不是真的有必要。请注意,在单元5中打开外部文件是不可取的,因为单元通常预先连接到标准输入,但现在没关系。




对于其他人的代码,正如tim18在他的评论中指出的那样,目前的gfortran版本确实支持这些扩展。但是,您必须使用 -fdec 启用它们,默认情况下它们未启用。



手册



< blockquote>

GNU Fortran支持额外的传统I / O说明符
CARRIAGECONTROL,READONLY和SHARE,其编译标志为-fdec,兼容



CARRIAGECONTROL

  CARRIAGECONTROL说明符允许用户控制输出记录之间的线路终端设置/ O单元。 

说明符对只读文件没有意义。当CARRAIGECONTROL在打开格式化书写单元时指定的
时,准确的
CARRIAGECONTROL设置决定在
输出记录之间写入的字符。语法是:

  OPEN(...,CARRIAGECONTROL = cc)

其中cc是字符表达式,其值为以下值之一:
'LIST'记录之间的一个换行符(默认值)
'FORTRAN'第一个字符的传统解释(见下文)
'NONE'记录之间没有分隔符







<我下载了这个文件。这太可怕了。不要使用制表符而不是固定形式的Fortran中的空格。真的不要!这个文件是一个不好的例子。



但是没有使用我已经提到的两个选项进行编译:



gfortran-7 -fdec -ffixed-line-length-0 zone_b.f



并且您报告的错误消失。

您需要gfortran版本7 !版本6是不够的。


I encounter some error when i try to compile a Fortran source file named 'zone_b.f' using Cygwin, to produce an executable program.

The Fortran file is download from web. The exact code can be viewed from here.

When I try to compile using the following command it produces the following error:

$ gfortran zone_b.f
zone_b.f:54:72:

      call getzone(zone_start, zone_end, selection_on, line(3:76))
                                                                    1
 Error: Syntax error in SUBSTRING specification at (1)
 zone_b.f:61:28:

 &     form='FORMATTED', carriagecontrol='LIST',
                        1
 Error: Syntax error in OPEN statement at (1)

I suspect it is because the Fortran file is older format, but when I try the g77 compiler downloaded from this website I encounter another issue:

C:\F\York>g77 zone_b.f  -o zone_b.exe
zone_b.f: In program `zone_b':
zone_b.f:60:
          open(5, status='OLD', file=line,
          ^

Unsupported OPEN control item at (^) -- ACTION=, ASSOCIATEVARIABLE=, 
   BLOCKSIZE=, BUFFERCOUNT=, CARRIAGECONTROL=, DEFAULTFILE=, DELIM=, DISPOSE=, 
   EXTENDSIZE=, INITIALSIZE=, KEY=, MAXREC=, NOSPANBLOCKS, ORGANIZATION=, PAD=, 
   POSITION=, READONLY=, RECORDTYPE=, SHARED=, and USEROPEN= are not supported

How do I solve these problems?

解决方案

The first error likely means the line is too long. Fixed form source allows only 72 character long lines. You can use more with special flags like -ffixed-line-length-n where n is a number. You can use -ffixed-line-length-0 for unlimited length. There are many similar questions on this site.


The CARRIAGECONTROL= specifier in the OPEN statement is not standard. It may be just fine to delete it from the open statement. I would certainly do that for my own code.

Namely lines 60-62:

       open(5, status='OLD', file=line,
 &     form='FORMATTED', carriagecontrol='LIST',
 &          READONLY,  err=400)

can be changed to just

       open(5, status='OLD', file=line,
 &     form='FORMATTED', err=400)

and the code will compile in older versions of gfortran (I tried 4.8 to 6).

You can also add ACTION="read" but it is not really necessary. Note that opening external files in unit 5 is not advisable, because the unit is normally pre-connected to standard input, but now it does not matter.


For someone else's code, as tim18 points out in his comment, current gfortran version does support these extensions. However, you must enable them with -fdec, they are not enabled by default.

From the manual:

GNU Fortran supports the additional legacy I/O specifiers CARRIAGECONTROL, READONLY, and SHARE with the compile flag -fdec, for compatibility.

CARRIAGECONTROL

The CARRIAGECONTROL specifier allows a user to control line termination settings between output records for an I/O unit. The

specifier has no meaning for readonly files. When CARRAIGECONTROL is specified upon opening a unit for formatted writing, the exact CARRIAGECONTROL setting determines what characters to write between output records. The syntax is:

OPEN(..., CARRIAGECONTROL=cc)

Where cc is a character expression that evaluates to one of the following values:
'LIST'    One line feed between records (default)
'FORTRAN' Legacy interpretation of the first character (see below)
'NONE'    No separator between recordsg


I downloaded the file. It is horrible. Don't use tabs instead of spaces in fixed form Fortran. Really don't! This file is a bad example.

But it does compile with the two options I already mentioned:

gfortran-7 -fdec -ffixed-line-length-0 zone_b.f

and the errors you reported go away.

You need gfortran version 7! Version 6 is not enough.

这篇关于在CARRIAGECONTROL =处使用gfortran的OPEN语句中的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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