[英]Using allocatable/assumed-size arrays with namelist read write
I am using VS2012 and Intel Visual Fortran 2015. 我正在使用VS2012和Intel Visual Fortran 2015。
According to https://software.intel.com/en-us/forums/topic/269585 , it is now allowed to use allocatable and assumed-size arrays with namelist read and write; 根据https://software.intel.com/en-us/forums/topic/269585 ,现在允许使用带有名称列表读取和写入的可分配和假定大小的数组; however, I am still getting the error "A namelist-group-object must not be an assumed-size array".
但是,我仍然收到错误“namelist-group-object不能是假定大小的数组”。
example code: 示例代码:
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
I have enabled F2003 Semantics. 我启用了F2003语义。
What am I missing? 我错过了什么?
That looks like a compiler bug. 这看起来像编译器错误。 The array
grid
is assumed shape , not assumed size . 假设阵列
grid
是形状 ,而不是假设的大小 。 Assumed shape arrays are permitted in namelist as of F2003, assumed size arrays remain prohibited (at runtime the size of an assumed size array is not necessarily known, so operations that require knowledge of the size are prohibited). 从F2003开始,在名单中允许假定的形状数组,假设大小数组仍然被禁止(在运行时,假定大小数组的大小不一定是已知的,因此禁止需要知道大小的操作)。
A simple workaround is to rename the dummy argument to something else and then copy its value into a local allocatable named grid
. 一个简单的解决方法是将伪参数重命名为其他内容,然后将其值复制到本地可分配的命名
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.