gpt4 book ai didi

io - 使用可分配/假定大小的数组和名单读写

转载 作者:行者123 更新时间:2023-12-02 17:48:48 24 4
gpt4 key购买 nike

我正在使用 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 语义。

我错过了什么?

最佳答案

这看起来像是一个编译器错误。数组网格假定的形状,而不是假定的大小。自 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

关于io - 使用可分配/假定大小的数组和名单读写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30902646/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com