FORTRAN - allocatable array in subroutine

无人久伴 提交于 2019-11-29 07:57:06

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).

The locs dummy argument is allocatable, and has the INTENT(IN) attribute - the intent attribute here indicating that the calling procedure is providing information to the subroutine.

A consequence of the INTENT(IN) attribute is that you cannot change the allocation status (or value) of locs. Your ALLOCATE statement is attempting to do just that.

Try allocating your array in your main program, then when locs is pushed to your subroutine, use INTENT(INOUT) to tell the compiler you also want to change the contents of your array.

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