Shawn
Shawn

Reputation: 21

Syntax error in OPEN statement with gfortran at CARRIAGECONTROL=

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?

Upvotes: 0

Views: 1742

Answers (1)

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.

Upvotes: 1

Related Questions