使用带有名称列表的allocatable / assume-size数组读写

时间:2015-06-17 21:23:58

标签: io fortran intel-fortran fortran2003

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

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

示例代码:

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语义。

我错过了什么?

1 个答案:

答案 0 :(得分:3)

这看起来像编译器错误。数组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
相关问题