Using allocatable/assumed-size arrays with namelist read write

1.2k views Asked by At

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?

1

There are 1 answers

3
IanH On BEST ANSWER

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