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?
The Fortran 2003 (and, I think, the 90,95 and 2008) standard states that the expression inside the parentheses of the
dimension()
clause in the declaration of an allocatable array must be adeferred-shape-spec-list
and that adeferred-shape-spec-list
is a list of colons, separated by,
if there is more than one element in the list. There should be one colon for each dimension in the array.I suggest you replace statements such as
with statements such as
When you later allocate this array the lower bound on each dimension will be, by default,
1
. If, on the other hand you wanted to allocate it with non-default bounds you might writereplacing, obviously, those constants with whatever values you wish.
It's not terrifically surprising that code acceptable to one Fortran compiler is not acceptable to another.