简体   繁体   English

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

[英]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.

相关问题 有没有一种方法可以使用名称列表I / O功能读取具有可分配组件的派生类型? - Is there a way to use the namelist I/O feature to read in a derived type with allocatable components? 如何使用名称列表以派生类型编写可分配数组? - How to write an allocatable array in a derived type using namelists? 在读取Fortran名称列表期间是否可以读取最大数量的数据? - Is there a maximum amount of data that can be read during a Fortran namelist read? 如何读取和写入numpy数组到受保护的文件 - How to read and write numpy arrays to protected file 当文件变大时,小文件的读写速度是否变慢? - Is small size file read/write slower when the file gets bigger? 使用Pipes在Haskell中读取和写入二进制数据 - Using Pipes to read and write binary data in Haskell 使用Java测量磁盘写入/读取速度 - Measure disk write/read speed using java 使用mysqldump导入数据后,为什么写入的块大小固定? - Why is there a fixed block size write after importing data using mysqldump? 将可分配数组传递给子例程 - Passing allocatable array into a subroutine 使用I / O流从一个文件读取并写入另一个文件 - Using I/O streams to read from one file and write to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM