从g95移至gfortran时,“可分配数组必须具有延迟的形状" [英] `Allocatable array must have deferred shape` when moving from g95 to gfortran

查看:107
本文介绍了从g95移至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()子句的括号内的表达式可分配数组的必须是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

带有诸如

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编译器可接受的代码不被另一个Fortran编译器接受就不足为奇了.

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

这篇关于从g95移至gfortran时,“可分配数组必须具有延迟的形状"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆