`Allocatable array must have deferred shape` when moving from g95 to gfortran

℡╲_俬逩灬. 提交于 2019-12-02 11:02:34

问题


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?


回答1:


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.

I suggest you replace statements such as

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

with statements such as

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

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.

It's not terrifically surprising that code acceptable to one Fortran compiler is not acceptable to another.



来源:https://stackoverflow.com/questions/16654519/allocatable-array-must-have-deferred-shape-when-moving-from-g95-to-gfortran

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!