Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
`当从g95移动到gfortran时,可分配数组必须具有延迟形状_Fortran_Gfortran_Allocatable Array_G95 - Fatal编程技术网

`当从g95移动到gfortran时,可分配数组必须具有延迟形状

`当从g95移动到gfortran时,可分配数组必须具有延迟形状,fortran,gfortran,allocatable-array,g95,Fortran,Gfortran,Allocatable Array,G95,当从使用g95编译器过渡到gfortran时,当我尝试编译以前的工作代码时,会出现以下错误 Error: Allocatable array ' ' at (1) must have a deferred shape 这发生在所有可分配数组的所有子例程中。下面是一个例子 SUBROUTINE TEST(name,ndimn,ntype,nelem,npoin,nface,inpoel,coord,face) IMPLICIT NONE integer:: i, j

当从使用g95编译器过渡到gfortran时,当我尝试编译以前的工作代码时,会出现以下错误

Error: Allocatable array ' ' at (1) must have a deferred shape
这发生在所有可分配数组的所有子例程中。下面是一个例子

    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编译此代码?

Fortran 2003(我认为,90、95和2008)标准规定
维度()括号内的表达式可分配数组声明中的
子句必须是一个延迟形状规范列表,
延迟形状规范列表
是一个冒号列表,如果列表中有多个元素,则用分隔。数组中的每个维度都应该有一个冒号

我建议您替换以下语句:

integer, allocatable, dimension(1:,1:), INTENT(OUT)::inpoel
integer, allocatable, dimension(:,:), INTENT(OUT)::inpoel
声明如下:

integer, allocatable, dimension(1:,1:), INTENT(OUT)::inpoel
integer, allocatable, dimension(:,:), INTENT(OUT)::inpoel
稍后分配此数组时,默认情况下,每个维度的下限为
1
。另一方面,如果您想用非默认边界分配它,您可以编写

allocate(inpoel(3:12,4:14))
显然,用您想要的值替换这些常量

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

Fortran 2003(以及,我认为,90、95和2008)标准规定,
维度()括号内的表达式可分配数组声明中的
子句必须是一个延迟形状规范列表,
延迟形状规范列表
是一个冒号列表,如果列表中有多个元素,则用分隔。数组中的每个维度都应该有一个冒号

我建议您替换以下语句:

integer, allocatable, dimension(1:,1:), INTENT(OUT)::inpoel
integer, allocatable, dimension(:,:), INTENT(OUT)::inpoel
声明如下:

integer, allocatable, dimension(1:,1:), INTENT(OUT)::inpoel
integer, allocatable, dimension(:,:), INTENT(OUT)::inpoel
稍后分配此数组时,默认情况下,每个维度的下限为
1
。另一方面,如果您想用非默认边界分配它,您可以编写

allocate(inpoel(3:12,4:14))
显然,用您想要的值替换这些常量


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

这确实解决了这个问题。那么,不在数据减速中定义下限,而是在分配语句中定义下限,这是一种好的做法吗?谢谢你的帮助!这不是一个好的或坏的做法的问题。一个编译器允许在声明时指定(任何)可分配数组的边界,就像g95对原始代码所做的那样,这是一个错误。这确实解决了这个问题。那么,不在数据减速中定义下限,而是在分配语句中定义下限,这是一种好的做法吗?谢谢你的帮助!这不是一个好的或坏的做法的问题。一个编译器允许在声明时指定(任何)可分配数组的边界,就像g95对原始代码所做的那样,它是错误的。