从 g95 移动到 gfortran 时,“可分配数组必须具有延迟形状" [英] `Allocatable array must have deferred shape` when moving from g95 to gfortran
问题描述
从使用 g95 编译器转换到 gfortran 时,当我尝试编译以前的工作代码时出现以下错误
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))
我怎样才能用 gfortran 编译这段代码?
How can I make this code compile with gfortran?
推荐答案
Fortran 2003(我认为是 90,95 和 2008)标准规定 dimension()<可分配数组声明中的/code> 子句必须是
deferred-shape-spec-list
并且 deferred-shape-spec-list
是冒号列表, 如果列表中有多个元素,则用 ,
分隔.数组中的每一维都应该有一个冒号.
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 a deferred-shape-spec-list
and that a deferred-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.
我建议你替换诸如
integer, allocatable, dimension(1:,1:), INTENT(OUT)::inpoel
with 语句如
integer, allocatable, dimension(:,:), INTENT(OUT)::inpoel
当您稍后分配此数组时,每个维度的下限默认为 1
.另一方面,如果您想使用非默认范围分配它,您可以编写
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 write
allocate(inpoel(3:12,4:14))
显然,用您希望的任何值替换这些常量.
replacing, obviously, those constants with whatever values you wish.
一个 Fortran 编译器可以接受的代码不能被另一个编译器接受,这并不奇怪.
It's not terrifically surprising that code acceptable to one Fortran compiler is not acceptable to another.
这篇关于从 g95 移动到 gfortran 时,“可分配数组必须具有延迟形状"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!