Hello,
I am trying to use the namelists to effectively probe if a variable <varname>
belongs to a certain defined namelist, without specifying a value of the variable.
The idea is to write a string like line = &my_nml <varname> /
and then trying to read it into nml as: read(line, nml=my_nml, iostat=ios, iomsg=msg)
. I expect the ios
to be zero when <varname>
is part of my_nml
, and nonzero otherwise.
I found this works with gfortran, but for ifx i need to add an =
sign after the <varname>
, so the string looks something like line = &my_nml <varname> = /
. So far so good.
Now switching back to gfortran, with the =
sign after the variable name however, seems to cause a segmentation fault at the moment of reading the nml, for real, allocatable
variables, but not for integer, allocatable
.
I also tried to put two commas after the =
sign but i get the same crash with gfortran.
Anybody have some idea what i’m doing wrong?
The full toy program where you can input the variable name in stdin, and print the ios
and iomsg
after trying to read that name from the nml is pasted below.
program main
implicit none
integer :: i
integer, allocatable :: i1d(:), i2d(:,:)
real :: r
real, allocatable :: r1d(:), r2d(:,:)
namelist/this_nml/i, i1d, i2d, r, r1d, r2d
character(len=128) :: line, msg, inp
integer :: ios
do while( .true. )
!! read from stdin
read(*,"(a128)") inp
if( trim(inp) == "exit" ) exit
!! write nml format in line
line = "&this_nml "//trim(inp)//" / "
write(*,*) "nml line is:", line
!! read nml from line
read(line, nml=this_nml, iostat=ios, iomsg=msg)
write(*,*) "ios :",ios
if( ios /= 0 ) then
write(*,*) "iomsg :",msg
end if
end do
end program main```