Using allocatable / estimated size arrays with a namelist read entry

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 estimated size arrays with namelist read and write; however, I still get the error "The namelist-group object must not be an array of the expected size."

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 included F2003 semantics.

What am I missing?

+3


source to share


1 answer


This looks like a compiler error. The array grid

is considered a shape, not an intended size. Assumed shape arrays are allowed in the namelist since F2003, assumed size arrays remain disabled (at run time, the size of the assumed size array is not necessarily known, so operations that require knowing the size are not allowed).

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

      

+3


source







All Articles