简体   繁体   中英

Using allocatable/assumed-size arrays with namelist read write

I am using VS2012 and 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; however, I am still getting the error "A namelist-group-object must not be an assumed-size array".

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.

What am I missing?

That looks like a compiler bug. The array grid is assumed shape , not assumed size . 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).

A simple workaround is to rename the dummy argument to something else and then copy its value into a local allocatable named 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM