FORTRAN - 子程序分配数组 [英] FORTRAN - allocatable array in subroutine

查看:365
本文介绍了FORTRAN - 子程序分配数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在子程序中使用的可分配数组,但编译器抱怨

 错误:虚参'LOCS在变量定义背景下INTENT(IN)(ALLOCATE对象)在(1)

我能找到的唯一的事情是,我应该使用一个明确的接口,我做的。在这里,有关code子例程:

 递推SUBROUTINE在一起(LOCS,LL,RL)    INTEGER,DIMENSION(:, :),可分配,意向(IN):: LOCS
    INTEGER,意向(IN):: LL,RL
    ALLOCATE(LOCS(LL,RL))
END SUBROUTINE在一起


解决方案

编译器的错误信息一个描述性的问题。随着 INTENT(IN)你是说这个对象将不会改变,但你去尝试 ALLOCATE 吧。

是的,一个显式接口将需要调用,但是这是没有问题的。

在2008年的Fortran标准说,在5.3.10节的


  

一个nonpointer意图(IN)属性对象不得出现在变量denition背景


分配就是这样的一个背景:部分16.6.7,点(11)

I'm trying to use an allocatable array in a subroutine but the compiler complains that

Error: Dummy argument 'locs' with INTENT(IN) in variable definition context (ALLOCATE object) at (1)

The only thing I could find was that I am supposed to use an explicit interface, which I am doing. Here the relevant code for the subroutine:

    RECURSIVE SUBROUTINE together(locs, LL, RL)

    INTEGER, DIMENSION(:,:), ALLOCATABLE, INTENT(IN)            :: locs
    INTEGER, INTENT(IN)                                         :: LL, RL


    ALLOCATE(locs(LL,RL))


END SUBROUTINE together

解决方案

The compiler's error message is one descriptive of the problem. With INTENT(IN) you are saying that the object will not change, but you then go on to attempt to ALLOCATE it.

Yes, an explicit interface will be required for the calling, but that isn't the problem.

The Fortran 2008 standard says in section 5.3.10 that

A nonpointer object with the INTENT (IN) attribute shall not appear in a variable denition context

Allocation is one such context: section 16.6.7, point (11).

这篇关于FORTRAN - 子程序分配数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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