我正在使用VS2012和Intel Visual Fortran 2015。

根据https://software.intel.com/en-us/forums/topic/269585,现在允许使用可分配和假定大小的数组,且具有读取和写入的名称列表;但是,我仍然收到错误“名称列表组对象不能为假定大小的数组”。

示例代码:

subroutine writeGrid(fname, grid)

    character*(*) :: fname
    real*8, dimension(:,:) :: grid

    namelist /gridNML/ grid

    open(1, file=fname)
    write(1, nml=gridNML)
    close(1)

end subroutine writeGrid


我启用了F2003语义。

我想念什么?

最佳答案

看起来像是编译器错误。数组grid是假定的形状,而不是假定的大小。从F2003开始,假定名称列表中允许使用形状数组,但假定的尺寸数组保持被禁止的状态(在运行时不一定知道假定的尺寸数组的大小,因此禁止要求了解尺寸的操作)。

一个简单的解决方法是将伪参数重命名为其他名称,然后将其值复制到名为grid的本地可分配地址中。

subroutine writeGrid(fname, grid_renamed)
  character*(*) :: fname
  real, dimension(:,:) :: grid_renamed
  real, dimension(:,:), allocatable :: grid

  namelist /gridNML/ grid

  open(1, file=fname)
  allocate(grid, source=grid_renamed)
  write(1, nml=gridNML)
  close(1)
end subroutine writeGrid

07-25 23:38