Allocatable arrays in fortran 77 and gfortran

2019-08-15 07:59发布

问题:

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.

回答1:

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



回答2:

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.



回答3:

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.