Allocatable arrays in fortran 77 and gfortran

2019-08-15 07:23发布

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.

3条回答
叼着烟拽天下
2楼-- · 2019-08-15 07:50

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楼-- · 2019-08-15 07:55

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.

查看更多
我命由我不由天
4楼-- · 2019-08-15 08:03

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

查看更多
登录 后发表回答