1

When transitioning from using the g95 compiler to gfortran I get the following error when I try to compile what previously had been a working code

Error: Allocatable array ' ' at (1) must have a deferred shape

This happens in all of my subroutines for all of my allocatable arrays. An example is below.

    SUBROUTINE TEST(name,ndimn,ntype,nelem,npoin,nface,inpoel,coord,face)

    IMPLICIT  NONE

    integer:: i, j,testing
    integer, INTENT(OUT)::ndimn,ntype,nelem,npoin,nface
    integer, allocatable, dimension(1:,1:), INTENT(OUT)::inpoel
    real::time, dummy
    real, allocatable, dimension(1:,1:), INTENT(OUT)::coord
    integer, allocatable, dimension(1:,1:), INTENT(OUT)::face

    character(len=13)::name
    character(len=11)::name3

    name='testgrid.dat'
    name3='testgeo.dat'

    open (unit=14, file='testgrid2.dat', status='old')

    read(14,*)
    read(14,*)
    read(14,*)
    read(14,*) ndimn, ntype
    read(14,*)
    read(14,*) nelem, npoin, nface
    read(14,*)

    allocate(inpoel(ntype,nelem+1),coord(ndimn,npoin+1),face(ntype,nface+1))

How can I make this code compile with gfortran?

4

1 回答 1

5

Fortran 2003(我认为是 90,95 和 2008)标准规定,dimension()可分配数组声明中子句括号内的表达式必须是 adeferred-shape-spec-list并且 adeferred-shape-spec-list是冒号列表,用,if分隔是列表中的多个元素。数组中的每一维都应该有一个冒号。

我建议你替换语句,例如

integer, allocatable, dimension(1:,1:), INTENT(OUT)::inpoel

带有诸如

integer, allocatable, dimension(:,:), INTENT(OUT)::inpoel

当您稍后分配此数组时,每个维度的下限默认为1. 另一方面,如果您想使用非默认范围分配它,您可以编写

allocate(inpoel(3:12,4:14))

显然,用您希望的任何值替换这些常量。

一个 Fortran 编译器可以接受的代码不能被另一个编译器接受,这并不奇怪。

于 2013-05-20T18:16:04.653 回答