It appears that all of the namelists are intended to be visible in the
same program unit. In that case, it might be easier to have just one
namelist that contained all of the variables. In the input file, the
namelist records do not have to specify all of the items in the
namelist. The first record could include only the first "set" of
variables, etc. In a particular namelist read, if one of the namelist
items does not appear, it's status does not change. You can include
comments in each of the records to indicate which set it is defining. In
the program just repeatedly read specifying the same namelist name until
you hit end-of-file.
Here's a simple example:
> cat test.f90
program test
use,intrinsic :: iso_fortran_env
implicit none
real :: a,b
namelist /nlist/ a,b
integer :: ios
open (unit=10, file="test.nml")
do
read (10,nml=nlist,iostat=ios)
if (ios == 0) cycle
if (ios == IOSTAT_END) exit
print *, "Error in reading file, iostat = ",ios
stop
end do
print *, a,b
end program test
> cat test.nml
&nlist ! First set
a = 1.2
/
&nlist ! Second set
b = 3.4
/
>
Cheers,
Bill
On 6/8/12 8:30 AM, Stefan Ano wrote:
> Hi There,
>
> right now I stuck with Fortran's NAMELISTs. My objective is to simply
> parse a config-file containing several groups, each multiple times.
> Well, this is not so very hard, however, I am looking for a
> sophisticated way iterating through all the NAMELISTs using Fortran 95.
>
> Sure, I start just by defining all my NAMELISTs. As a second Step - and
> this is where I stuck - I would like iterate through all those
> NAMELISTs. Is there a way to put NAMELISTs into an array or so? My idea
> is having a code like:
> DO i=1, SIZE( lists )
> READ( 99, NMT=lists(i) )
> ...
> END DO
> Any suggestions how to put all the NAMELISTs into one 'container' I
> could iterate through?
> (Another even more sophisticate approach might be to figure out how to
> pass a NAMELIST as a function argument. Any ideas? )
>
> Cheers,
> Stefan
>
> Btw.: I am using gfortran on Debian Lenny.
--
Bill Long [log in to unmask]
Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9142
Cray Inc./Cray Plaza, Suite 210/380 Jackson St./St. Paul, MN 55101
|