Allocatable arrays in fortran 77 and gfortran
Asked Answered
H

3

1

I'm trying to compile some old fortran77 programs with gfortran and getting error with allocatable arrays. If I define arrays in f90-style, like:

REAL*8,allocatable::somearray(:)

everything is fine, but in those old programs arrays defined as:

REAL*8  somearray[ALLOCATABLE](:)

which cause gfortran error output:

REAL*8,allocatable::somearray[ALLOCATABLE](:)                        
                             1
Fatal Error: Coarrays disabled at (1), use -fcoarray= to enable

I really wish to avoid rewriting whole programs to f90 style, so, could you please tell me, is there any way to force gfortran to compile it? Thanks a lot.

Hijoung answered 16/4, 2014 at 7:30 Comment(6)
Allocatable arrays are a Fortran 90 feature. The syntax in the code you show that causes the error is neither Fortran 77 or Fortran 90.Tappet
This is completely non-standard, I would not even call that Fortran.Niemeyer
gfortran thinks that [] indicates co-arrays, which is f90 or f95 feature. But I don't use co-arrays at all. Is there any way to force gfortran use only f77 syntax? All these programs are using f77 standard and were compiled with unknown compiler. They are all using array definition like I described above.Hijoung
Yes, search and replace will help, but I really wish to avoid modifying those programs because they still uses on Windows machines with that noname compiler which accepts such strange standard of arrays definition.Hijoung
This is NOT Fortran 77. This is not standard Fortran at all!Niemeyer
which compiler? He-Who-Must-Not-Be-Named?Shyster
S
0

For standard checking you can use -std flag

-std=std Specify the standard to which the program is expected to conform, which may be one of f95',f2003', f2008',gnu', or `legacy'.

To "force" gfortran to compile your code, you have to use syntax it recognizes

Shyster answered 16/4, 2014 at 8:5 Comment(0)
C
0

I'd probably go for search and replace. For example,

  sed 's/\(REAL\*8\)[[:blank:]]\+\([^[]\+\)\[ALLOCATABLE\]\(.*\)/\1, allocatable :: \2\3/' <old.source> > <new.source>

where sed is available.

Of course, be careful with sed :).

In any case, as it seems your code was written in some non-standard version of old Fortran, you'll probably need to make changes in any case.

Cavalcade answered 16/4, 2014 at 8:31 Comment(0)
B
0

For what it's worth the Intel Fortran compiler (v13.something) compiles the following micro-program without complaint. This executes and writes 10 to the terminal:

  REAL*8  somearray[ALLOCATABLE](:)
  allocate(somearray(10))
  print *, size(somearray)
  end

Given the history of the Intel compiler I suspect that the strange declaration is an extension provided by DEC Fortran, possibly an early implementation of what was later standardised in Fortran 90.

Biologist answered 16/4, 2014 at 8:42 Comment(1)
Yes, I think that it might be Intel Fortran compiler. Problem was that gfortran doesn't understand its syntax without -std=f95Hijoung

© 2022 - 2024 — McMap. All rights reserved.