I am using GNU Fortran (GCC) 4.8.2
I want to read allocatable arrays from a namelist. But I don't know in advance how many elements have to be read into the allocatable array, so I cannot allocate it before to read the namelist.
This is my namelist: namelist.nml:
&SECTION_1
intList = 5,6,7
/ ! End of SECTION_1
And this is my program: namelist.f08:
program namelist
implicit none
integer, allocatable :: intList(:)
integer :: U ! Unit to read the namelist file
namelist /SECTION_1/ intList
!allocate(intList(3)) ! <-- If I uncomment this, the program works.
open(NEWUNIT=U, file="namelist.nml", status='OLD', recl=80, delim='APOSTROPHE')
rewind(U)
read(U, nml=SECTION_1)
close(U)
write (*,*) intList
end program namelist
If I uncomment the labeled line, the program works, but, as I said before, I cannot allocate before to read the namelist. Does anybody know how to accomplish this?.