Re: Namelist usage
From: Colin Watters (qolin_at_slb.com)
Date: 12/03/04
- Previous message: cedric: "Re: Convert Program into Subroutine???"
- In reply to: Rich Townsend: "Re: Namelist usage"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 3 Dec 2004 02:45:04 -0800
Rich Townsend <rhdt@barVOIDtol.udel.edu> wrote in message news:<colpka$b2o$1@scrotar.nss.udel.edu>...
> Colin Watters wrote:
> > Rich Townsend <rhdt@barVOIDtol.udel.edu> wrote in message news:<coimq0$bnn$1@scrotar.nss.udel.edu>...
> >
> >>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
Namelists.
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
IMPLICIT NONE
TYPE(Completion_Main_Type ), TARGET :: acomp ! completion
(in)
TYPE(fman_stream_type ), TARGET :: astream ! stream
(in)
TYPE(fman_stream_type ), TARGET :: ostream ! output
stream (out)
TYPE(completion_results_type), TARGET :: results ! results
(out)
INTEGER :: rcode ! error code
(out)
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(nterm.gt.0) then
cwcoption = acomp%wcoption
cifp = acomp%ifp
write(nterm,dump)
write(nterm,istreamdump)
endif
! ...<snip various extraneous details...>
!-----do it
call completion_b
(acomp,astream,-1001,rcode,ostream,fname,results)
!-----dump results data to the screen, if there is one
if(nterm.gt.0) then
write(nterm,resdump)
write(nterm,ostreamdump)
endif
END SUBROUTINE completion_a_c
- Previous message: cedric: "Re: Convert Program into Subroutine???"
- In reply to: Rich Townsend: "Re: Namelist usage"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|