Re: Namelist usage

From: Colin Watters (
Date: 12/03/04

  • Next message: Arnaud Desitter: "Re: Cray pointers"
    Date: 3 Dec 2004 02:45:04 -0800

    Rich Townsend <> wrote in message news:<colpka$b2o$>...
    > Colin Watters wrote:
    > > Rich Townsend <> wrote in message news:<coimq0$bnn$>...
    > >
    > >>Dear all,
    > >>
    > >>I've never got around to using namelists in my code, and I was wondering
    > >>whether anybody who *does* use them -- and find them helpful -- could
    > >>embark on a bit of advocacy in their favour. For instance, what sorts of
    > >>tasks do namelists help you tackle? What sort of coding idioms do you
    > >>employ with namelists?
    > >
    > >
    > > I find them Really Useful for printing the entire contents of a
    > > structure as an aid to debugging.
    > >
    > > My main application consists of a number of Windows DLLs. Some are
    > > called from C++ GUI programs written by my colleagues. The arguments
    > > are typically 2 or 3 structures (or should I say User-defined Types,
    > > this is Fortran after all) each having upwards of 50 member variables.
    > > With 2 lines of code I can get a complete dump of each structure,
    > > names and values, to a screen console or disk file.... invaluable for
    > > diagnosing known problems and spotting hidden ones. And I can do this
    > > on any machine, no Fortran compiler or developer studio needed.
    > How do you do this? Could you post some example code?
    > cheers,
    > Rich
    > >
    > > Qolin

    Ok here we go then. Various extraneous details removed, but what
    remains still compiles. ...well it would compile if I could get
    Google's message composer to play ball, some of the lines are getting
    wrapped. I think you'll work it out.

    The arguments ASTREAM and OSTREAM are of type STREAM, a structure that
    contains 100+ separate variables, all scalars, so they can be
    referenced in NAMELISTs directly, viz. /istreamdump/ and
    /ostreamdump/. ACOMP alas contains pointers so I copy the important
    sub-structures into locals CWOPTION and CIFP which are in thier own

    NTERM, if positive, is a Fortran unit connected to a console (see
    windoz API AllocConsole, available from CVF's DVWIN module). By
    setting a debug switch at runtime the console can be made to appear on
    the machine running the program. Debug switches are set using the
    command line and/or environment variables. Enjoy...

          SUBROUTINE completion_a_c (acomp,astream,ostream,results,rcode)
          !DEC$ attributes dllexport :: completion_a_c
    ! completion_a_c ... C-friendly wrapper for completion_a that has
    ! no optional arguments.
    ! Qolin 18/09/04 Added NAMELIST dumps of arguments to a console.
    ! Qolin 07/09/04 Created
          USE fluidman
          USE etc
          USE Completion_Internal
          TYPE(Completion_Main_Type ), TARGET :: acomp ! completion
          TYPE(fman_stream_type ), TARGET :: astream ! stream
          TYPE(fman_stream_type ), TARGET :: ostream ! output
    stream (out)
          TYPE(completion_results_type), TARGET :: results ! results
          INTEGER :: rcode ! error code
          include "pipesim/engines/components/completion/iounit.i"
          TYPE(Completion_ifp_type ) :: cifp
          TYPE(Completion_wcoption_type ) :: cwcoption

          character*256, save :: fname = ' '

          namelist /dump/ cwcoption, cifp
          namelist /istreamdump/ astream
          namelist /ostreamdump/ ostream
          namelist /resdump/ results

          rcode = 0
    !-----dump the input data to the screen, if there is one:
    ! use the namelist feature of Fortran
          if( then
            cwcoption = acomp%wcoption
            cifp = acomp%ifp
    ! ...<snip various extraneous details...>

    !-----do it
          call completion_b

    !-----dump results data to the screen, if there is one
          if( then
          END SUBROUTINE completion_a_c

  • Next message: Arnaud Desitter: "Re: Cray pointers"