Formatting 2D arrays in fortran namelist input file

Im a writing input-name file for Fortran code. I know that if you have a 1D array, you can fill in a range of elements,

&namelist
array(10) = 0, 1, 2, ......., n
&END

is equivalent

&namelist
array(10) = 0
array(11) = 1
array(12) = 2
...
array(10 + n) = n
&END

I need to write a 2d array. I want to make the shortest equivalent

&namelist
array2d(1,1) = 1
array2d(1,2) = 2
&END

Can i write it like

&namelist
array2d(1) = 1, 2
&END

or do I need to write this as

&namelist
array2d(1,1) = 1, 2
&END
+3
source share
1 answer

Wow, thanks for the question - I've never heard of stockholders before :) This is useful !! :) After some testing, older versions of gfortran have problems with this. Let's say you have

program nltest
  implicit none
  integer :: a(3,3)
  namelist /mylist/ a
  a = 0
  open(7, file='nlinput.txt')
  read(7, nml = mylist)
  write(*,*) a
end program nltest
  • read the whole array a=1,2,3,4,5,6,7,8,9: it works fine and reads (1,1), a (2,1), ... as expected, regardless of the compiler.
  • , . a(2,:)=1,2,3: ifort gfortran 4.6.1, gfortran 4.3 .

, , , array2d(1,:) = 1,2, .

+6

All Articles