JiscMail Logo
Email discussion lists for the UK Education and Research communities

Help for COMP-FORTRAN-90 Archives


COMP-FORTRAN-90 Archives

COMP-FORTRAN-90 Archives


COMP-FORTRAN-90@JISCMAIL.AC.UK


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

COMP-FORTRAN-90 Home

COMP-FORTRAN-90 Home

COMP-FORTRAN-90  June 2012

COMP-FORTRAN-90 June 2012

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Re: iterate through several NAMELISTs

From:

Stefan Mauerberger <[log in to unmask]>

Reply-To:

Fortran 90 List <[log in to unmask]>

Date:

Fri, 8 Jun 2012 20:37:02 +0200

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (129 lines)

Hi Neil, 

seek_to_namelist() seems to be interesting. This could shorten my code a
bit. 

Attached, there is a sample code which does what I want just for one
group. I could simply copy it for all occurring groups. This, however,
is very redundant due to the fact that just the NAMELIST-group and '! do
some stuff' needs to be changed. 

Cheers, Stefan 

PROGRAM main 

IMPLICIT NONE
write
INTEGER :: i, ios, n_groups
REAL, DIMENSION(3) :: coord

TYPE inpp
    REAL, DIMENSION( 3 ) :: coord
END TYPE inpp  

TYPE(inpp), DIMENSION(:), ALLOCATABLE :: inps

NAMELIST /inp/ coord 


n_groups = 0
OPEN( 99, FILE='conf.nml' )
DO
    READ( 99, IOSTAT=ios , NML=inp )
    IF ( ios == 0 ) THEN
        n_groups = n_groups + 1         
    ELSE
        EXIT
    END IF
END DO

ALLOCATE( inps( n_groups ) )

REWIND( 99 )
DO i=1, SIZE( inps ) 
    READ( 99, NML=inp )
    ! do some stuff
END DO

CLOSE( 99 )

! do the same for a whole bunch of other groups 
    
END PROGRAM main 



On Fri, 2012-06-08 at 10:42 -0600, Neil Carlson wrote:
> I don't fully understand what you need to do (the answer to your
> specific question is no)
> but I can suggest another approach that might apply.  One code I deal
> with uses namelists
> for its input.  There are many of them, can appear in any order, and
> some can appear
> multiple times (each instance having a distinct effect).  The key to
> parsing this input
> file is a subroutine 
> 
> SUBROUTINE SEEK_TO_NAMELIST (UNIT, NML, FOUND [, IOSTAT])
>   INTEGER, INTENT(IN) :: UNIT
>   CHARACTER(*), INTENT(IN) :: NML
>   LOGICAL, INTENT(OUT) :: FOUND
>   INTEGER, INTENT(OUT), OPTIONAL :: IOSTAT
> 
> that scans forward through the input file looking for the next
> occurrence of the specified
> namelist (as a string).  Using this together with the REWIND statement
> makes parsing
> the input file pretty easy, with stanzas of code like
> 
> namelist /foo/ x, y, z
> rewind(unit)
> do
>   call seek_to_namelist (unit, 'foo', found)
>   if (.not.found) exit
>   real(unit, nml=foo)
>   ! do something with the namelist variable values
> end do
> 
> I can send you the implementation of seek_to_namelist if you're
> interested.
> It's a bit tricky to ensure that you find a valid namelist opening,
> and only valid
> ones, and then you need to leave the input file properly positioned.
> 
> -Neil
> 
> On Fri, Jun 8, 2012 at 7:30 AM, Stefan Ano
> <[log in to unmask]> 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.
> 

Top of Message | Previous Page | Permalink

JISCMail Tools


RSS Feeds and Sharing


Advanced Options


Archives

April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
July 2013
June 2013
May 2013
April 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
August 2010
July 2010
June 2010
March 2010
February 2010
January 2010
December 2009
October 2009
August 2009
July 2009
June 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
January 2007
2006
2005
2004
2003
2002
2001
2000
1999
1998
1997


WWW.JISCMAIL.AC.UK

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager