#include "w3macros.h" 
!/ ------------------------------------------------------------------- /
      MODULE W3NAMLMD
!/
!/                  +-----------------------------------+
!/                  | WAVEWATCH III           NOAA/NCEP |
!/                  |           M. Accensi              |
!/                  |                                   |
!/                  |                        FORTRAN 90 |
!/                  | Last update :         09-Aug-2016 |
!/                  +-----------------------------------+
!/
!/    For updates see subroutines.
!/
!  1. Purpose :
!
!     Manages namelists from input *.nml files
!
!/ ------------------------------------------------------------------- /

  ! module defaults
  IMPLICIT NONE

  PUBLIC

  ! domain definition structure
  TYPE domain_def_t
    INTEGER                     :: nrinp
    INTEGER                     :: nrgrd
    INTEGER                     :: nmove
    LOGICAL                     :: unipts
    INTEGER                     :: iostyp
    LOGICAL                     :: upproc
    LOGICAL                     :: pshare
    LOGICAL                     :: flghg1
    LOGICAL                     :: flghg2
    CHARACTER(15)               :: start
    CHARACTER(15)               :: stop
  END TYPE domain_def_t



  ! model grid data structure
  TYPE model_forcing_t
    CHARACTER(13)               :: water_levels
    CHARACTER(13)               :: currents
    CHARACTER(13)               :: winds
    CHARACTER(13)               :: ice_conc
    CHARACTER(13)               :: ice_param1
    CHARACTER(13)               :: ice_param2
    CHARACTER(13)               :: ice_param3
    CHARACTER(13)               :: ice_param4
    CHARACTER(13)               :: ice_param5
    CHARACTER(13)               :: mud_density
    CHARACTER(13)               :: mud_thickness
    CHARACTER(13)               :: mud_viscosity
  END TYPE model_forcing_t
!
  TYPE model_assim_t
    CHARACTER(13)               :: mean
    CHARACTER(13)               :: spec1d
    CHARACTER(13)               :: spec2d
  END TYPE model_assim_t
!
  TYPE model_resource_t
    INTEGER                     :: rank_id
    INTEGER                     :: group_id
    INTEGER                     :: sibling_id
    REAL(4)                     :: comm_frac(2)
    LOGICAL                     :: bound_flag
  END TYPE model_resource_t
!
  TYPE model_grid_t 
    CHARACTER(13)               :: name
    TYPE(model_forcing_t)       :: forcing
    TYPE(model_assim_t)         :: assim
    TYPE(model_resource_t)      :: resource
  END TYPE model_grid_t



  ! input grid data structure
  TYPE input_forcing_t
    LOGICAL                     :: water_levels
    LOGICAL                     :: currents
    LOGICAL                     :: winds
    LOGICAL                     :: ice_conc
    LOGICAL                     :: ice_param1
    LOGICAL                     :: ice_param2
    LOGICAL                     :: ice_param3
    LOGICAL                     :: ice_param4
    LOGICAL                     :: ice_param5
    LOGICAL                     :: mud_density
    LOGICAL                     :: mud_thickness
    LOGICAL                     :: mud_viscosity
  END TYPE input_forcing_t
!
  TYPE input_assim_t
    LOGICAL                     :: mean
    LOGICAL                     :: spec1d
    LOGICAL                     :: spec2d
  END TYPE input_assim_t
!
  TYPE input_grid_t
    CHARACTER(13)               :: name
    TYPE(input_forcing_t)       :: forcing
    TYPE(input_assim_t)         :: assim
  END TYPE input_grid_t



  ! output TYPE structure
  TYPE point_t
    CHARACTER(13)               :: name
    CHARACTER(64)               :: file
  END TYPE point_t
!
  TYPE field_t
    CHARACTER(1024)             :: list
  END TYPE field_t
!
  TYPE track_t
    LOGICAL                     :: format
  END TYPE track_t
!
  TYPE partition_t
    INTEGER                     :: x0
    INTEGER                     :: xn
    INTEGER                     :: nx
    INTEGER                     :: y0
    INTEGER                     :: yn
    INTEGER                     :: ny
    LOGICAL                     :: format
  END TYPE partition_t
!
!/COU  TYPE coupling_t
!/COU    CHARACTER(1024)             :: list
!/COU  END TYPE coupling_t
!
  TYPE output_type_t
    TYPE(point_t)               :: point
    TYPE(field_t)               :: field
    TYPE(track_t)               :: track
    TYPE(partition_t)           :: partition
!/COU    TYPE(coupling_t)           :: coupling
  END TYPE output_type_t



  ! output date structure
  TYPE output_time_t 
    CHARACTER(15)               :: start
    CHARACTER(15)               :: stride
    CHARACTER(15)               :: stop
  END TYPE output_time_t
!
  TYPE output_date_t
    TYPE(output_time_t)         :: field
    TYPE(output_time_t)         :: point
    TYPE(output_time_t)         :: track
    TYPE(output_time_t)         :: restart
    TYPE(output_time_t)         :: boundary
    TYPE(output_time_t)         :: partition
!/COU    TYPE(output_time_t)         :: coupling
  END TYPE output_date_t



  ! homogeneous input structure
  TYPE homogeneous_field_t
    CHARACTER(15)               :: start
    REAL                        :: speed
    REAL                        :: direction
    REAL                        :: gradient    
  END TYPE homogeneous_field_t
!
  TYPE homogeneous_input_t
    TYPE(homogeneous_field_t)   :: moving
  END TYPE homogeneous_input_t



  ! miscellaneous
  CHARACTER(256)                :: msg



  CONTAINS
!/ ------------------------------------------------------------------- /
  SUBROUTINE NAMLMULTIDEF (MPI_COMM, NDSI, INFILE, domain_def, IERR)
!/
!/                  +-----------------------------------+
!/                  | WAVEWATCH III           NOAA/NCEP |
!/                  |           M. Accensi              |
!/                  |           F. Ardhuin              |
!/                  |                        FORTRAN 90 |
!/                  | Last update :         09-Aug-2016 |
!/                  +-----------------------------------+
!/
!/    09-Aug-2016 : Adding comments                     ( version 5.12 )
!
!  1. Purpose :
!
!     Reads the domain definition namelist to define the number of 
!     model and forcing grids
!
!  2. Method :
!
!     See source term routines.
!
!  3. Parameters :
!
!     Parameter list
!     ----------------------------------------------------------------
!      MPI_COMM   Int.  Public   Communicator used in the wave model.
!      NDSI       Int.
!      INFILE     Char.
!      DOMAIN_DEF type.
!      IERR       Int.
!     ----------------------------------------------------------------
!
!  4. Subroutines used :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      STRACE    Subr. W3SERVMD SUBROUTINE tracing.
!      read_domain_def_nml
!     ----------------------------------------------------------------
!
!  5. Called by :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      WMINITNML Subr.   N/A    Model configuration routine.
!     ----------------------------------------------------------------
!
!  6. Error messages :
!
!     None.
!
!  7. Remarks :
!
!  8. Structure :
!
!     See source code.
!
!  9. Switches :
!
!     !/MPI  Uses MPI communications
!     !/T  Enable test output.
!
! 10. Source code :
!
!/ ------------------------------------------------------------------- /
    USE WMMDATMD, ONLY: MDSE, MDSS, IMPROC, NMPLOG
!/MPI      USE WMMDATMD, ONLY: MPI_COMM_MWAVE
!/S      USE W3SERVMD, ONLY: STRACE

    IMPLICIT NONE

    INTEGER, INTENT(in)                       :: MPI_COMM, NDSI
    CHARACTER*(*), INTENT(in)                 :: INFILE
    TYPE(domain_def_t), INTENT(out)           :: domain_def 
    INTEGER, INTENT(out)                      :: IERR
!/MPI      INTEGER                                 :: IERR_MPI
!/S      INTEGER, SAVE                           :: IENT = 0

    IERR = 0
!/S      CALL STRACE (IENT, 'NAMLMULTIDEF')

!/MPI      MPI_COMM_MWAVE = MPI_COMM
!/MPI      CALL MPI_COMM_RANK ( MPI_COMM_MWAVE, IMPROC, IERR_MPI )
!/MPI      IMPROC = IMPROC + 1


    ! open input file
    OPEN (NDSI, file=TRIM(INFILE), form='formatted', status='old', iostat=IERR)
    IF (IERR.ne.0) THEN
      WRITE (MDSE,'(a)') 'ERROR: open input file '//TRIM(INFILE)//' failed'
      RETURN
    END IF

    ! read domain def namelist
    call read_domain_def_nml (NDSI, domain_def, IERR)
    IF (IERR.ne.0) THEN
      WRITE (MDSE,'(a)') 'ERROR: error occured in read_model_def_nml'
      RETURN
    END IF
!/T    IF ( IMPROC .EQ. NMPLOG ) call report_domain_def_nml (domain_def)

    ! close namelist file
    CLOSE (NDSI)

  END SUBROUTINE NAMLMULTIDEF


!/ ------------------------------------------------------------------- /
  SUBROUTINE NAMLMULTICONF (MPI_COMM, NDSI, INFILE, domain_def, &
                            input_grid, model_grid, output_type, output_date, &
                            homogeneous_input, IERR)
!/
!/                  +-----------------------------------+
!/                  | WAVEWATCH III           NOAA/NCEP |
!/                  |           M. Accensi              |
!/                  |           F. Ardhuin              |
!/                  |                        FORTRAN 90 |
!/                  | Last update :         09-Aug-2016 |
!/                  +-----------------------------------+
!/
!/    09-Aug-2016 : Adding comments                     ( version 5.12 )

!  1. Purpose :
!
!
!  2. Method :
!
!     See source term routines.
!
!  3. Parameters :
!
!     Parameter list
!     ----------------------------------------------------------------
!      MPI_COMM  Int.  Public   Communicator used in the wave model.
!      NDSI
!      INFILE
!      domain_def
!      input_grid
!      model_grid
!      output_type
!      output_date
!      homogeneous_input
!      IERR
!     ----------------------------------------------------------------
!
!  4. Subroutines used :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      STRACE    Subr. W3SERVMD SUBROUTINE tracing.
!      read_input_grid_nml
!      report_input_grid_nml
!      read_model_grid_nml
!      report_model_grid_nml
!      read_output_type_nml
!      report_output_type_nml
!      read_output_date_nml
!      report_output_date_nml
!      read_homogeneous_input_nml
!      report_homogeneous_input_nml
!     ----------------------------------------------------------------
!
!  5. Called by :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      WMINITNML Subr.   N/A    Model configuration routine.
!     ----------------------------------------------------------------
!
!  6. Error messages :
!
!     None.
!
!  7. Remarks :
!
!  8. Structure :
!
!     See source code.
!
!  9. Switches :
!
!     !/MPI  Uses MPI communications
!     !/T  Enable test output.
!
! 10. Source code :
!
!/ ------------------------------------------------------------------- /

    USE WMMDATMD, ONLY: MDSE, MDSS, IMPROC, NMPLOG
!/MPI      USE WMMDATMD, ONLY: MPI_COMM_MWAVE
!/S      USE W3SERVMD, ONLY: STRACE

    IMPLICIT NONE

    INTEGER, INTENT(in)                       :: MPI_COMM, NDSI
    CHARACTER*(*), INTENT(in)                 :: INFILE
    TYPE(domain_def_t), INTENT(inout)         :: domain_def
    TYPE(input_grid_t), INTENT(inout)         :: input_grid(:) 
    TYPE(model_grid_t), INTENT(inout)         :: model_grid(:) 
    TYPE(output_type_t), INTENT(inout)        :: output_type(:)
    TYPE(output_date_t), INTENT(inout)        :: output_date(:)
    TYPE(homogeneous_input_t), INTENT(inout)  :: homogeneous_input(:)
    INTEGER, INTENT(out)                      :: IERR
!/MPI      INTEGER                                 :: IERR_MPI
!/S      INTEGER, SAVE                           :: IENT = 0

    IERR = 0
!/S      CALL STRACE (IENT, 'NAMLMULTICONF')

!/MPI      MPI_COMM_MWAVE = MPI_COMM
!/MPI      CALL MPI_COMM_RANK ( MPI_COMM_MWAVE, IMPROC, IERR_MPI )
!/MPI      IMPROC = IMPROC + 1


    ! open input file
    open (NDSI, file=TRIM(INFILE), form='formatted', status='old', iostat=IERR)
    IF (IERR.ne.0) THEN
      WRITE (*,'(a)') 'ERROR: open input file '//TRIM(INFILE)//' failed'
      RETURN
    END IF

    ! read input grid namelist
    call read_input_grid_nml (NDSI, domain_def%nrinp, input_grid, IERR)
    IF (IERR.ne.0) THEN
      WRITE (MDSE,'(a)') 'ERROR: error occured in read_input_grid_nml'
      RETURN
    END IF
!/T    IF ( IMPROC .EQ. NMPLOG ) call report_input_grid_nml (domain_def%nrinp, input_grid)

    ! read model grid namelist
    call read_model_grid_nml (NDSI, domain_def%nrgrd, model_grid, IERR)
    IF (IERR.ne.0) THEN
      WRITE (MDSE,'(a)') 'ERROR: error occured in read_model_grid_nml'
      RETURN
    END IF
!/T    IF ( IMPROC .EQ. NMPLOG ) call report_model_grid_nml (domain_def%nrgrd, model_grid)

    ! read output TYPE namelist
    call read_output_type_nml (NDSI, domain_def%unipts, domain_def%nrgrd, output_type, IERR)
    IF (IERR.ne.0) THEN
      WRITE (MDSE,'(a)') 'ERROR: error occured in read_output_type_nml'
      RETURN
    END IF
!/T    IF ( IMPROC .EQ. NMPLOG ) call report_output_type_nml (domain_def%nrgrd, output_type)

    ! read output date namelist
    call read_output_date_nml (NDSI, domain_def%nrgrd, output_date, IERR)
    IF (IERR.ne.0) THEN
      WRITE (MDSE,'(a)') 'ERROR: error occured in read_output_date_nml'
      RETURN
    END IF
!/T    IF ( IMPROC .EQ. NMPLOG ) call report_output_date_nml (domain_def%nrgrd,output_date)

    ! read homogeneous input namelist
    call read_homogeneous_input_nml (NDSI, domain_def%nmove, homogeneous_input, IERR)
    IF (IERR.ne.0) THEN
      WRITE (MDSE,'(a)') 'ERROR: error occured in read_homogeneous_input_nml'
      RETURN
    END IF
!/T    IF ( IMPROC .EQ. NMPLOG ) call report_homogeneous_input_nml (domain_def%nmove, homogeneous_input)


    ! close namelist file
    CLOSE (NDSI)

  END SUBROUTINE NAMLMULTICONF

!/ ------------------------------------------------------------------- /




!/ ------------------------------------------------------------------- /

  SUBROUTINE read_domain_def_nml (NDSI, domain_def, IERR)
!/
!/                  +-----------------------------------+
!/                  | WAVEWATCH III           NOAA/NCEP |
!/                  |           M. Accensi              |
!/                  |           F. Ardhuin              |
!/                  |                        FORTRAN 90 |
!/                  | Last update :         09-Aug-2016 |
!/                  +-----------------------------------+
!/
!/    09-Aug-2016 : Adding comments                     ( version 5.12 )

!  1. Purpose :
!
!
!  2. Method :
!
!     See source term routines.
!
!  3. Parameters :
!
!     Parameter list
!     ----------------------------------------------------------------
!     ----------------------------------------------------------------
!
!  4. Subroutines used :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      STRACE    Subr. W3SERVMD SUBROUTINE tracing.
!     ----------------------------------------------------------------
!
!  5. Called by :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      NAMLMULTIDEF Subr.   N/A    Namelist configuration routine.
!     ----------------------------------------------------------------
!
!  6. Error messages :
!
!     None.
!
!  7. Remarks :
!
!  8. Structure :
!
!     See source code.
!
!  9. Switches :
!
!     !/MPI  Uses MPI communications
!     !/T  Enable test output.
!
! 10. Source code :
!
!/ ------------------------------------------------------------------- /

    USE WMMDATMD, ONLY: MDSE, MDSS
!/S      USE W3SERVMD, ONLY: STRACE

    IMPLICIT NONE

    INTEGER, INTENT(in)               :: NDSI
    TYPE(domain_def_t), INTENT(out)   :: domain_def
    INTEGER, INTENT(out)              :: IERR

    ! locals
    TYPE(domain_def_t) :: domain
    NAMELIST /domain_def_nml/ domain
!/S      INTEGER, SAVE                           :: IENT = 0

    IERR = 0
!/S      CALL STRACE (IENT, 'read_domain_def_nml')

    ! set default values for model definition data
    domain%nrinp  = 0
    domain%nrgrd  = 1
    domain%nmove  = 0
    domain%unipts = .false.
    domain%iostyp = 1
    domain%upproc = .false.
    domain%pshare = .false.
    domain%flghg1 = .false.
    domain%flghg2 = .false.
    domain%start  = '19680606 000000'
    domain%stop   = '19680607 000000'

    ! read model def namelist
    REWIND (NDSI)
    READ (NDSI, nml=domain_def_nml, iostat=IERR, iomsg=msg)
    IF (IERR.ne.0) THEN
      WRITE (MDSE,'(a,/a)') &
        'ERROR: read_domain_def_nml: namelist read error', &
        'ERROR: '//TRIM(msg)
      RETURN
    END IF

    ! set/check RETURN values
    IF (domain%nrinp.lt.0) THEN
      WRITE (MDSE,'(a,i3)') 'ERROR: bad nrinp input: ',domain%nrinp
      IERR = 1
      RETURN
    END IF
    IF (domain%nrgrd.le.0) THEN
      WRITE (MDSE,'(a,i3)') 'ERROR: bad nrgrd input: ',domain%nrgrd
      IERR = 1
      RETURN
    END IF
    IF (domain%iostyp.lt.0.or.domain%iostyp.gt.3) THEN
      WRITE (MDSE,'(a,i3)') 'ERROR: bad iostyp input: ',domain%iostyp
      IERR = 1
      RETURN
    END IF
    domain_def = domain

  END SUBROUTINE read_domain_def_nml

!/ ------------------------------------------------------------------- /

  SUBROUTINE read_input_grid_nml (NDSI, nrinp, input_grid, IERR)
!/
!/                  +-----------------------------------+
!/                  | WAVEWATCH III           NOAA/NCEP |
!/                  |           M. Accensi              |
!/                  |                        FORTRAN 90 |
!/                  | Last update :         09-Aug-2016 |
!/                  +-----------------------------------+
!/
!/    09-Aug-2016 : Adding comments                     ( version 5.12 )
!/
!  1. Purpose :
!
!
!  2. Method :
!
!     See source term routines.
!
!  3. Parameters :
!
!     Parameter list
!     ----------------------------------------------------------------
!     ----------------------------------------------------------------
!
!  4. Subroutines used :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      STRACE    Subr. W3SERVMD SUBROUTINE tracing.
!     ----------------------------------------------------------------
!
!  5. Called by :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      NAMLMULTICONF Subr.   N/A    Namelist configuration routine.
!     ----------------------------------------------------------------
!
!  6. Error messages :
!
!     None.
!
!  7. Remarks :
!
!  8. Structure :
!
!     See source code.
!
!  9. Switches :
!
!     !/MPI  Uses MPI communications
!     !/T  Enable test output.
!
! 10. Source code :
!
!/ ------------------------------------------------------------------- /

    USE WMMDATMD, ONLY: MDSE, MDSS
!/S      USE W3SERVMD, ONLY: STRACE

    IMPLICIT NONE

    INTEGER, INTENT(in)               :: NDSI, nrinp
    TYPE(input_grid_t), INTENT(inout) :: input_grid(nrinp)
    INTEGER, INTENT(out)              :: IERR

    ! locals
    INTEGER, parameter :: max_nrinp = 99
    TYPE(input_grid_t) :: input(max_nrinp)
    NAMELIST /input_grid_nml/ input
    INTEGER            :: i
!/S      INTEGER, SAVE                           :: IENT = 0

    IERR = 0
!/S      CALL STRACE (IENT, 'NAMLMULTICONF')

    ! test nrinp
    IF (nrinp.gt.max_nrinp) THEN
      WRITE (MDSE,'(a,/a,i6,/a,i6)') &
        'ERROR: read_input_grid_nml: nrinp > max_nrinp',      &
        'ERROR: read_input_grid_nml:     nrinp = ',    nrinp, &
        'ERROR: read_input_grid_nml: max_nrinp = ',max_nrinp
        IERR = 1
        RETURN
    END IF

    ! IF number of input grids == 0, THEN RETURN
    IF (nrinp.eq.0) RETURN

    ! set default values for grid input data
    DO i = 1,nrinp
      input(i)%name                  = 'unset'
      input(i)%forcing%water_levels  = .false.
      input(i)%forcing%currents      = .false.
      input(i)%forcing%winds         = .false.
      input(i)%forcing%ice_conc      = .false.
      input(i)%forcing%ice_param1    = .false.
      input(i)%forcing%ice_param2    = .false.
      input(i)%forcing%ice_param3    = .false.
      input(i)%forcing%ice_param4    = .false.
      input(i)%forcing%ice_param5    = .false.
      input(i)%forcing%mud_density   = .false.
      input(i)%forcing%mud_thickness = .false.
      input(i)%forcing%mud_viscosity = .false.
      input(i)%assim%mean            = .false.
      input(i)%assim%spec1d          = .false.
      input(i)%assim%spec2d          = .false.
    END DO

    ! read input grid namelist
    REWIND (NDSI)
    READ (NDSI, nml=input_grid_nml, iostat=IERR, iomsg=msg)
    IF (IERR.ne.0) THEN
      WRITE (MDSE,'(a,/a)') &
        'ERROR: read_input_grid_nml: namelist read error', &
        'ERROR: '//TRIM(msg)
      RETURN
    END IF

    ! set/check RETURN values
    DO i = 1,nrinp
      IF (TRIM(input(i)%name).eq.'unset') THEN
        WRITE (MDSE,10) 'ERROR: read_input_grid_nml: required input(',i,')%name not set'
        IERR = 1
      END IF
      input_grid(i) = input(i)
    END DO
10  format (a,i0,a)

  END SUBROUTINE read_input_grid_nml

!/ ------------------------------------------------------------------- /

  SUBROUTINE read_model_grid_nml (NDSI, nrgrd, model_grid, IERR)
!/
!/                  +-----------------------------------+
!/                  | WAVEWATCH III           NOAA/NCEP |
!/                  |           M. Accensi              |
!/                  |                        FORTRAN 90 |
!/                  | Last update :         09-Aug-2016 |
!/                  +-----------------------------------+
!/
!/    09-Aug-2016 : Adding comments                     ( version 5.12 )
!/
!  1. Purpose :
!
!
!  2. Method :
!
!     See source term routines.
!
!  3. Parameters :
!
!     Parameter list
!     ----------------------------------------------------------------
!     ----------------------------------------------------------------
!
!  4. Subroutines used :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      STRACE    Subr. W3SERVMD SUBROUTINE tracing.
!     ----------------------------------------------------------------
!
!  5. Called by :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      NAMLMULTICONF Subr.   N/A    Namelist configuration routine.
!     ----------------------------------------------------------------
!
!  6. Error messages :
!
!     None.
!
!  7. Remarks :
!
!  8. Structure :
!
!     See source code.
!
!  9. Switches :
!
!     !/MPI  Uses MPI communications
!     !/T  Enable test output.
!
! 10. Source code :
!
!/ ------------------------------------------------------------------- /

    USE WMMDATMD, ONLY: MDSE, MDSS
!/S      USE W3SERVMD, ONLY: STRACE

    IMPLICIT NONE

    INTEGER, INTENT(in)               :: NDSI, nrgrd
    TYPE(model_grid_t), INTENT(inout) :: model_grid(nrgrd)
    INTEGER, INTENT(out)              :: IERR

    ! locals
    INTEGER, parameter :: max_nrgrd = 99
    TYPE(model_grid_t) :: model(max_nrgrd)
    NAMELIST /model_grid_nml/ model
    INTEGER            :: i
!/S      INTEGER, SAVE                           :: IENT = 0

    IERR = 0
!/S      CALL STRACE (IENT, 'NAMLMULTICONF')

    ! test nrgrd
    IF (nrgrd.gt.max_nrgrd) THEN
      WRITE (MDSE,'(a,/a,i6,/a,i6)') &
        'ERROR: read_model_grid_nml: nrgrd > max_nrgrd',      &
        'ERROR: read_model_grid_nml:     nrgrd = ',    nrgrd, &
        'ERROR: read_model_grid_nml: max_nrgrd = ',max_nrgrd
        IERR = 1
        RETURN
    END IF

    ! set default values for model input data
    DO i = 1,nrgrd
      model(i)%name                  = 'unset'
      model(i)%forcing%water_levels  = 'no'
      model(i)%forcing%currents      = 'no'
      model(i)%forcing%winds         = 'no'
      model(i)%forcing%ice_conc      = 'no'
      model(i)%forcing%ice_param1    = 'no'
      model(i)%forcing%ice_param2    = 'no'
      model(i)%forcing%ice_param3    = 'no'
      model(i)%forcing%ice_param4    = 'no'
      model(i)%forcing%ice_param5    = 'no'
      model(i)%forcing%mud_density   = 'no'
      model(i)%forcing%mud_thickness = 'no'
      model(i)%forcing%mud_viscosity = 'no'
      model(i)%assim%mean            = 'no'
      model(i)%assim%spec1d          = 'no'
      model(i)%assim%spec2d          = 'no'
      model(i)%resource%rank_id      = i
      model(i)%resource%group_id     = 1
      model(i)%resource%sibling_id   = 0
      model(i)%resource%comm_frac    = (/0.00,1.00/)
      model(i)%resource%bound_flag   = .false.
    END DO

    ! read model model namelist
    REWIND (NDSI)
    READ (NDSI, nml=model_grid_nml, iostat=IERR, iomsg=msg)
    IF (IERR.ne.0) THEN
      WRITE (MDSE,'(a,/a)') &
        'ERROR: read_model_grid_nml: namelist read error', &
        'ERROR: '//TRIM(msg)
      RETURN
    END IF

    ! set/check RETURN values
    DO i = 1,nrgrd
      IF (TRIM(model(i)%name).eq.'unset') THEN
        WRITE (MDSE,10) 'ERROR: read_model_grid_nml: required model(',i,')%name not set'
        IERR = 1
      END IF
      model_grid(i) = model(i)
    END DO

10  format (a,i0,a)

  END SUBROUTINE read_model_grid_nml

!/ ------------------------------------------------------------------- /

  SUBROUTINE read_output_type_nml (NDSI, unipts, nrgrd, output_type, IERR)
!/
!/                  +-----------------------------------+
!/                  | WAVEWATCH III           NOAA/NCEP |
!/                  |           M. Accensi              |
!/                  |                        FORTRAN 90 |
!/                  | Last update :         09-Aug-2016 |
!/                  +-----------------------------------+
!/
!/    09-Aug-2016 : Adding comments                     ( version 5.12 )
!/
!  1. Purpose :
!
!
!  2. Method :
!
!     See source term routines.
!
!  3. Parameters :
!
!     Parameter list
!     ----------------------------------------------------------------
!     ----------------------------------------------------------------
!
!  4. Subroutines used :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      STRACE    Subr. W3SERVMD SUBROUTINE tracing.
!     ----------------------------------------------------------------
!
!  5. Called by :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      NAMLMULTICONF Subr.   N/A    Namelist configuration routine.
!     ----------------------------------------------------------------
!
!  6. Error messages :
!
!     None.
!
!  7. Remarks :
!
!  8. Structure :
!
!     See source code.
!
!  9. Switches :
!
!     !/MPI  Uses MPI communications
!     !/T  Enable test output.
!
! 10. Source code :
!
!/ ------------------------------------------------------------------- /

    USE WMMDATMD, ONLY: MDSE, MDSS
!/S      USE W3SERVMD, ONLY: STRACE

    IMPLICIT NONE

    INTEGER, INTENT(in)                :: NDSI, nrgrd
    LOGICAL, INTENT(in)                :: unipts
    TYPE(output_type_t), INTENT(inout) :: output_type(nrgrd)
    INTEGER, INTENT(out)               :: IERR

    ! locals
    INTEGER, parameter  :: max_nrgrd = 99
    TYPE(output_type_t) :: alltype
    TYPE(output_type_t) :: itype(max_nrgrd)
    NAMELIST /output_type_nml/ alltype, itype
    INTEGER             :: i, j
!/S      INTEGER, SAVE                           :: IENT = 0

    IERR = 0
!/S      CALL STRACE (IENT, 'NAMLMULTICONF')

    ! set default values for output TYPE data
    DO i=1,nrgrd
      itype(i)%point%name   = 'unset'
      itype(i)%point%file   = 'unset'
      itype(i)%field%list   = 'unset'
      itype(i)%track%format = .true.
      itype(i)%partition%x0 = 0
      itype(i)%partition%xn = 0
      itype(i)%partition%nx = 0
      itype(i)%partition%y0 = 0
      itype(i)%partition%yn = 0
      itype(i)%partition%ny = 0
      itype(i)%partition%format = .true.
!/COU      itype(i)%coupling%list   = 'unset'
    END DO
    alltype%point%name   = 'unset'
    alltype%point%file   = 'unset'
    alltype%field%list   = 'unset'
    alltype%track%format = .true.
    alltype%partition%x0 = 0
    alltype%partition%xn = 0
    alltype%partition%nx = 0
    alltype%partition%y0 = 0
    alltype%partition%yn = 0
    alltype%partition%ny = 0
    alltype%partition%format = .true.
!/COU    alltype%coupling%list   = 'unset'


    ! read output_TYPE namelist
    REWIND (NDSI)
    READ (NDSI, nml=output_type_nml, iostat=IERR, iomsg=msg)
    IF (IERR.ne.0) THEN
      WRITE (MDSE,'(a,/a)') &
        'ERROR: read_output_type_nml: namelist read error', &
        'ERROR: '//TRIM(msg)
      RETURN
    END IF

    DO i=1,nrgrd
      itype(i) = alltype
    END DO

    ! read output_TYPE namelist
    REWIND (NDSI)
    READ (NDSI, nml=output_type_nml, iostat=IERR, iomsg=msg)
    IF (IERR.ne.0) THEN
      WRITE (MDSE,'(a,/a)') &
        'ERROR: read_output_type_nml: namelist read error', &
        'ERROR: '//TRIM(msg)
      RETURN
    END IF

    DO i=1,nrgrd
      output_type(i) = itype(i)
    END DO
   
  END SUBROUTINE read_output_type_nml

!/ ------------------------------------------------------------------- /

  SUBROUTINE read_output_date_nml (NDSI, nrgrd, output_date, IERR)
!/
!/                  +-----------------------------------+
!/                  | WAVEWATCH III           NOAA/NCEP |
!/                  |           M. Accensi              |
!/                  |                        FORTRAN 90 |
!/                  | Last update :         09-Aug-2016 |
!/                  +-----------------------------------+
!/
!/    09-Aug-2016 : Adding comments                     ( version 5.12 )
!/
!  1. Purpose :
!
!
!  2. Method :
!
!     See source term routines.
!
!  3. Parameters :
!
!     Parameter list
!     ----------------------------------------------------------------
!     ----------------------------------------------------------------
!
!  4. Subroutines used :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      STRACE    Subr. W3SERVMD SUBROUTINE tracing.
!     ----------------------------------------------------------------
!
!  5. Called by :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      NAMLMULTICONF Subr.   N/A    Namelist configuration routine.
!     ----------------------------------------------------------------
!
!  6. Error messages :
!
!     None.
!
!  7. Remarks :
!
!  8. Structure :
!
!     See source code.
!
!  9. Switches :
!
!     !/MPI  Uses MPI communications
!     !/T  Enable test output.
!
! 10. Source code :
!
!/ ------------------------------------------------------------------- /

    USE WMMDATMD, ONLY: MDSE, MDSS
!/S      USE W3SERVMD, ONLY: STRACE

    IMPLICIT NONE

    INTEGER, INTENT(in)                :: NDSI, nrgrd
    TYPE(output_date_t), INTENT(inout) :: output_date(nrgrd)
    INTEGER, INTENT(out)               :: IERR

    ! locals
    INTEGER, parameter  :: max_nrgrd = 99
    TYPE(output_date_t) :: alldate
    TYPE(output_date_t) :: idate(max_nrgrd)
    NAMELIST /output_date_nml/ alldate, idate
    INTEGER             :: i
!/S      INTEGER, SAVE                           :: IENT = 0

    IERR = 0
!/S      CALL STRACE (IENT, 'NAMLMULTICONF')

    ! set default values for output_date input data
    DO i=1,nrgrd
      idate(i)%field%start = '19680606 000000'
      idate(i)%field%stride = '0'
      idate(i)%field%stop = '19680607 000000'
      idate(i)%point%start = '19680606 000000'
      idate(i)%point%stride = '0'
      idate(i)%point%stop = '19680607 000000'
      idate(i)%track%start = '19680606 000000'
      idate(i)%track%stride = '0'
      idate(i)%track%stop = '19680607 000000'
      idate(i)%restart%start = '19680606 000000'
      idate(i)%restart%stride = '0'
      idate(i)%restart%stop = '19680607 000000'
      idate(i)%boundary%start = '19680606 000000'
      idate(i)%boundary%stride = '0'
      idate(i)%boundary%stop = '19680607 000000'
      idate(i)%partition%start = '19680606 000000'
      idate(i)%partition%stride = '0'
      idate(i)%partition%stop = '19680607 000000'
!/COU      idate(i)%coupling%start = '19680606 000000'
!/COU      idate(i)%coupling%stride = '0'
!/COU      idate(i)%coupling%stop = '19680607 000000'
    END DO
    alldate%field%start = '19680606 000000'
    alldate%field%stride = '0'
    alldate%field%stop = '19680607 000000'
    alldate%point%start = '19680606 000000'
    alldate%point%stride = '0'
    alldate%point%stop = '19680607 000000'
    alldate%track%start = '19680606 000000'
    alldate%track%stride = '0'
    alldate%track%stop = '19680607 000000'
    alldate%restart%start = '19680606 000000'
    alldate%restart%stride = '0'
    alldate%restart%stop = '19680607 000000'
    alldate%boundary%start = '19680606 000000'
    alldate%boundary%stride = '0'
    alldate%boundary%stop = '19680607 000000'
    alldate%partition%start = '19680606 000000'
    alldate%partition%stride = '0'
    alldate%partition%stop = '19680607 000000'
!/COU    alldate%coupling%start = '19680606 000000'
!/COU    alldate%coupling%stride = '0'
!/COU    alldate%coupling%stop = '19680607 000000'


    ! read output_date namelist
    REWIND (NDSI)
    READ (NDSI, nml=output_date_nml, iostat=IERR, iomsg=msg)
    IF (IERR.ne.0) THEN
      WRITE (MDSE,'(a,/a)') &
        'ERROR: read_output_date_nml: namelist read error', &
        'ERROR: '//TRIM(msg)
      RETURN
    END IF

    DO i=1,nrgrd
      idate(i) = alldate
    END DO

    ! read output_date namelist
    REWIND (NDSI)
    READ (NDSI, nml=output_date_nml, iostat=IERR, iomsg=msg)
    IF (IERR.ne.0) THEN
      WRITE (MDSE,'(a,/a)') &
        'ERROR: read_output_date_nml: namelist read error', &
        'ERROR: '//TRIM(msg)
      RETURN
    END IF

    DO i=1,nrgrd
      output_date(i) = idate(i)
    END DO


  END SUBROUTINE read_output_date_nml

!/ ------------------------------------------------------------------- /

  SUBROUTINE read_homogeneous_input_nml (NDSI, nmove, homogeneous_input, IERR)
!/
!/                  +-----------------------------------+
!/                  | WAVEWATCH III           NOAA/NCEP |
!/                  |           M. Accensi              |
!/                  |                        FORTRAN 90 |
!/                  | Last update :         09-Aug-2016 |
!/                  +-----------------------------------+
!/
!/    09-Aug-2016 : Adding comments                     ( version 5.12 )
!/
!  1. Purpose :
!
!
!  2. Method :
!
!     See source term routines.
!
!  3. Parameters :
!
!     Parameter list
!     ----------------------------------------------------------------
!     ----------------------------------------------------------------
!
!  4. Subroutines used :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      STRACE    Subr. W3SERVMD SUBROUTINE tracing.
!     ----------------------------------------------------------------
!
!  5. Called by :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      NAMLMULTICONF Subr.   N/A    Namelist configuration routine.
!     ----------------------------------------------------------------
!
!  6. Error messages :
!
!     None.
!
!  7. Remarks :
!
!  8. Structure :
!
!     See source code.
!
!  9. Switches :
!
!     !/MPI  Uses MPI communications
!     !/T  Enable test output.
!
! 10. Source code :
!
!/ ------------------------------------------------------------------- /

    USE WMMDATMD, ONLY: MDSE, MDSS
!/S      USE W3SERVMD, ONLY: STRACE

    IMPLICIT NONE

    INTEGER, INTENT(in)                      :: NDSI, nmove
    TYPE(homogeneous_input_t), INTENT(inout) :: homogeneous_input(nmove)
    INTEGER, INTENT(out)                     :: IERR

    ! locals
    INTEGER, parameter        :: max_nmove = 99
    INTEGER                   :: i
    TYPE(homogeneous_input_t) :: homogeneous(max_nmove)
    NAMELIST /homogeneous_input_nml/ homogeneous
!/S      INTEGER, SAVE                           :: IENT = 0

    IERR = 0
!/S      CALL STRACE (IENT, 'NAMLMULTICONF')

    ! set default values for homogeneous input data
    DO i=1,nmove
      homogeneous(i)%moving%start     = '19680606 000000'
      homogeneous(i)%moving%speed     = 0.
      homogeneous(i)%moving%direction = 0.
      homogeneous(i)%moving%gradient  = 0.
    END DO

    ! read homogeneous_input namelist
    REWIND (NDSI)
    READ (NDSI, nml=homogeneous_input_nml, iostat=IERR, iomsg=msg)
    IF (IERR.ne.0) THEN
      WRITE (MDSE,'(a,/a)') &
        'ERROR: read_homogeneous_input_nml: namelist read error', &
        'ERROR: '//TRIM(msg)
      RETURN
    END IF

    DO i=1,nmove
      homogeneous_input(i) = homogeneous(i)
    END DO
    
  END SUBROUTINE read_homogeneous_input_nml

!/ ------------------------------------------------------------------- /








!/ ------------------------------------------------------------------- /

  SUBROUTINE report_domain_def_nml (domain_def)
!/
!/                  +-----------------------------------+
!/                  | WAVEWATCH III           NOAA/NCEP |
!/                  |           M. Accensi              |
!/                  |                        FORTRAN 90 |
!/                  | Last update :         09-Aug-2016 |
!/                  +-----------------------------------+
!/
!/    09-Aug-2016 : Adding comments                     ( version 5.12 )
!/
!  1. Purpose :
!
!
!  2. Method :
!
!     See source term routines.
!
!  3. Parameters :
!
!     Parameter list
!     ----------------------------------------------------------------
!     ----------------------------------------------------------------
!
!  4. Subroutines used :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      STRACE    Subr. W3SERVMD SUBROUTINE tracing.
!     ----------------------------------------------------------------
!
!  5. Called by :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      NAMLMULTICONF Subr.   N/A    Namelist configuration routine.
!     ----------------------------------------------------------------
!
!  6. Error messages :
!
!     None.
!
!  7. Remarks :
!
!  8. Structure :
!
!     See source code.
!
!  9. Switches :
!
!     !/MPI  Uses MPI communications
!     !/T  Enable test output.
!
! 10. Source code :
!
!/ ------------------------------------------------------------------- /

    USE WMMDATMD, ONLY: MDSE, MDSS
!/S      USE W3SERVMD, ONLY: STRACE

    IMPLICIT NONE

    TYPE(domain_def_t), INTENT(in) :: domain_def
!/S      INTEGER, SAVE                           :: IENT = 0

!/S      CALL STRACE (IENT, 'NAMLMULTICONF')

      WRITE (msg,'(a)') 'domain def :'
      WRITE (MDSS,'(a)')
      WRITE (MDSS,11) TRIM(msg),'nrinp  = ',domain_def%nrinp
      WRITE (MDSS,11) TRIM(msg),'nrgrd  = ',domain_def%nrgrd
      WRITE (MDSS,13) TRIM(msg),'unipts = ',domain_def%unipts
      WRITE (MDSS,11) TRIM(msg),'iostyp = ',domain_def%iostyp
      WRITE (MDSS,13) TRIM(msg),'upproc = ',domain_def%upproc
      WRITE (MDSS,13) TRIM(msg),'pshare = ',domain_def%pshare
      WRITE (MDSS,13) TRIM(msg),'flghg1 = ',domain_def%flghg1
      WRITE (MDSS,13) TRIM(msg),'flghg2 = ',domain_def%flghg2
      WRITE (MDSS,10) TRIM(msg),'start  = ',TRIM(domain_def%start)
      WRITE (MDSS,10) TRIM(msg),'stop   = ',TRIM(domain_def%stop)

10  format (a,2x,a,a)
11  format (a,2x,a,i1)
13  format (a,2x,a,l1)

  END SUBROUTINE report_domain_def_nml

!/ ------------------------------------------------------------------- /

  SUBROUTINE report_input_grid_nml (nrinp, input_grid)
!/
!/                  +-----------------------------------+
!/                  | WAVEWATCH III           NOAA/NCEP |
!/                  |           M. Accensi              |
!/                  |                        FORTRAN 90 |
!/                  | Last update :         09-Aug-2016 |
!/                  +-----------------------------------+
!/
!/    09-Aug-2016 : Adding comments                     ( version 5.12 )
!/
!  1. Purpose :
!
!
!  2. Method :
!
!     See source term routines.
!
!  3. Parameters :
!
!     Parameter list
!     ----------------------------------------------------------------
!     ----------------------------------------------------------------
!
!  4. Subroutines used :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      STRACE    Subr. W3SERVMD SUBROUTINE tracing.
!     ----------------------------------------------------------------
!
!  5. Called by :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      NAMLMULTICONF Subr.   N/A    Namelist configuration routine.
!     ----------------------------------------------------------------
!
!  6. Error messages :
!
!     None.
!
!  7. Remarks :
!
!  8. Structure :
!
!     See source code.
!
!  9. Switches :
!
!     !/MPI  Uses MPI communications
!     !/T  Enable test output.
!
! 10. Source code :
!
!/ ------------------------------------------------------------------- /

    USE WMMDATMD, ONLY: MDSE, MDSS
!/S      USE W3SERVMD, ONLY: STRACE

    IMPLICIT NONE

    INTEGER, INTENT(in)            :: nrinp
    TYPE(input_grid_t), INTENT(in) :: input_grid(nrinp)

    ! locals
    INTEGER              :: i
!/S      INTEGER, SAVE                           :: IENT = 0

!/S      CALL STRACE (IENT, 'NAMLMULTICONF')

    DO i = 1,nrinp
      WRITE (msg,'(a,i0.2,a)') 'input grid ',i,' :'
      WRITE (MDSS,'(a)')
      WRITE (MDSS,10) TRIM(msg),'name                     = ',TRIM(input_grid(i)%name)
      WRITE (MDSS,13) TRIM(msg),'forcing % water_levels   = ',input_grid(i)%forcing%water_levels
      WRITE (MDSS,13) TRIM(msg),'forcing % currents       = ',input_grid(i)%forcing%currents
      WRITE (MDSS,13) TRIM(msg),'forcing % wind           = ',input_grid(i)%forcing%winds
      WRITE (MDSS,13) TRIM(msg),'forcing % ice_conc       = ',input_grid(i)%forcing%ice_conc
      WRITE (MDSS,13) TRIM(msg),'forcing % ice_param1     = ',input_grid(i)%forcing%ice_param1
      WRITE (MDSS,13) TRIM(msg),'forcing % ice_param2     = ',input_grid(i)%forcing%ice_param2
      WRITE (MDSS,13) TRIM(msg),'forcing % ice_param3     = ',input_grid(i)%forcing%ice_param3
      WRITE (MDSS,13) TRIM(msg),'forcing % ice_param4     = ',input_grid(i)%forcing%ice_param4
      WRITE (MDSS,13) TRIM(msg),'forcing % ice_param5     = ',input_grid(i)%forcing%ice_param5
      WRITE (MDSS,13) TRIM(msg),'forcing % mud_density    = ',input_grid(i)%forcing%mud_density
      WRITE (MDSS,13) TRIM(msg),'forcing % mud_thickness  = ',input_grid(i)%forcing%mud_thickness
      WRITE (MDSS,13) TRIM(msg),'forcing % mud_viscosity  = ',input_grid(i)%forcing%mud_viscosity
      WRITE (MDSS,13) TRIM(msg),'assim % mean             = ',input_grid(i)%assim%mean
      WRITE (MDSS,13) TRIM(msg),'assim % spec1d           = ',input_grid(i)%assim%spec1d
      WRITE (MDSS,13) TRIM(msg),'assim % spec2d           = ',input_grid(i)%assim%spec2d
    END DO
    WRITE (*,*)

10  format (a,2x,a,a)
13  format (a,2x,a,l1)

  END SUBROUTINE report_input_grid_nml

!/ ------------------------------------------------------------------- /

  SUBROUTINE report_model_grid_nml (nrgrd, model_grid)
!/
!/                  +-----------------------------------+
!/                  | WAVEWATCH III           NOAA/NCEP |
!/                  |           M. Accensi              |
!/                  |                        FORTRAN 90 |
!/                  | Last update :         09-Aug-2016 |
!/                  +-----------------------------------+
!/
!/    09-Aug-2016 : Adding comments                     ( version 5.12 )
!/
!  1. Purpose :
!
!
!  2. Method :
!
!     See source term routines.
!
!  3. Parameters :
!
!     Parameter list
!     ----------------------------------------------------------------
!     ----------------------------------------------------------------
!
!  4. Subroutines used :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      STRACE    Subr. W3SERVMD SUBROUTINE tracing.
!     ----------------------------------------------------------------
!
!  5. Called by :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      NAMLMULTICONF Subr.   N/A    Namelist configuration routine.
!     ----------------------------------------------------------------
!
!  6. Error messages :
!
!     None.
!
!  7. Remarks :
!
!  8. Structure :
!
!     See source code.
!
!  9. Switches :
!
!     !/MPI  Uses MPI communications
!     !/T  Enable test output.
!
! 10. Source code :
!
!/ ------------------------------------------------------------------- /

    USE WMMDATMD, ONLY: MDSE, MDSS
!/S      USE W3SERVMD, ONLY: STRACE

    IMPLICIT NONE

    INTEGER, INTENT(in)            :: nrgrd
    TYPE(model_grid_t), INTENT(in) :: model_grid(nrgrd)

    ! locals
    INTEGER              :: i
!/S      INTEGER, SAVE                           :: IENT = 0

!/S      CALL STRACE (IENT, 'NAMLMULTICONF')

    DO i = 1,nrgrd
      WRITE (msg,'(a,i0.4,a)') 'model grid ',i,' :'
      WRITE (MDSS,'(a)')
      WRITE (MDSS,10) TRIM(msg),'name                     = ',TRIM(model_grid(i)%name)
      WRITE (MDSS,10) TRIM(msg),'forcing % water_levels   = ',TRIM(model_grid(i)%forcing%water_levels)
      WRITE (MDSS,10) TRIM(msg),'forcing % currents       = ',TRIM(model_grid(i)%forcing%currents)
      WRITE (MDSS,10) TRIM(msg),'forcing % winds          = ',TRIM(model_grid(i)%forcing%winds)
      WRITE (MDSS,10) TRIM(msg),'forcing % ice_conc       = ',TRIM(model_grid(i)%forcing%ice_conc)
      WRITE (MDSS,10) TRIM(msg),'forcing % ice_param1     = ',TRIM(model_grid(i)%forcing%ice_param1)
      WRITE (MDSS,10) TRIM(msg),'forcing % ice_param2     = ',TRIM(model_grid(i)%forcing%ice_param2)
      WRITE (MDSS,10) TRIM(msg),'forcing % ice_param3     = ',TRIM(model_grid(i)%forcing%ice_param3)
      WRITE (MDSS,10) TRIM(msg),'forcing % ice_param4     = ',TRIM(model_grid(i)%forcing%ice_param4)
      WRITE (MDSS,10) TRIM(msg),'forcing % ice_param5     = ',TRIM(model_grid(i)%forcing%ice_param5)
      WRITE (MDSS,10) TRIM(msg),'forcing % mud_density    = ',TRIM(model_grid(i)%forcing%mud_density)
      WRITE (MDSS,10) TRIM(msg),'forcing % mud_thickness  = ',TRIM(model_grid(i)%forcing%mud_thickness)
      WRITE (MDSS,10) TRIM(msg),'forcing % mud_viscosity  = ',TRIM(model_grid(i)%forcing%mud_viscosity)
      WRITE (MDSS,10) TRIM(msg),'assim % mean             = ',TRIM(model_grid(i)%assim%mean)
      WRITE (MDSS,10) TRIM(msg),'assim % spec1d           = ',TRIM(model_grid(i)%assim%spec1d)
      WRITE (MDSS,10) TRIM(msg),'assim % spec2d           = ',TRIM(model_grid(i)%assim%spec2d)
      WRITE (MDSS,11) TRIM(msg),'resource % rank_id       = ',model_grid(i)%resource%rank_id
      WRITE (MDSS,11) TRIM(msg),'resource % group_id      = ',model_grid(i)%resource%group_id
      WRITE (MDSS,11) TRIM(msg),'resource % sibling_id    = ',model_grid(i)%resource%sibling_id
      WRITE (MDSS,12) TRIM(msg),'resource % comm_frac     = ',model_grid(i)%resource%comm_frac(1), &
                                                              model_grid(i)%resource%comm_frac(2)
      WRITE (MDSS,13) TRIM(msg),'resource % bound_flag    = ',model_grid(i)%resource%bound_flag
    END DO
    WRITE (MDSS,'(a)')

10  format (a,2x,a,a)
11  format (a,2x,a,i1)
12  format (a,2x,a,'(',f5.2,',',f5.2,' )')
13  format (a,2x,a,l1)

  END SUBROUTINE report_model_grid_nml

!/ ------------------------------------------------------------------- /

  SUBROUTINE report_output_type_nml (nrgrd, output_type)
!/
!/                  +-----------------------------------+
!/                  | WAVEWATCH III           NOAA/NCEP |
!/                  |           M. Accensi              |
!/                  |                        FORTRAN 90 |
!/                  | Last update :         09-Aug-2016 |
!/                  +-----------------------------------+
!/
!/    09-Aug-2016 : Adding comments                     ( version 5.12 )
!/
!  1. Purpose :
!
!
!  2. Method :
!
!     See source term routines.
!
!  3. Parameters :
!
!     Parameter list
!     ----------------------------------------------------------------
!     ----------------------------------------------------------------
!
!  4. Subroutines used :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      STRACE    Subr. W3SERVMD SUBROUTINE tracing.
!     ----------------------------------------------------------------
!
!  5. Called by :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      NAMLMULTICONF Subr.   N/A    Namelist configuration routine.
!     ----------------------------------------------------------------
!
!  6. Error messages :
!
!     None.
!
!  7. Remarks :
!
!  8. Structure :
!
!     See source code.
!
!  9. Switches :
!
!     !/MPI  Uses MPI communications
!     !/T  Enable test output.
!
! 10. Source code :
!
!/ ------------------------------------------------------------------- /

    USE WMMDATMD, ONLY: MDSE, MDSS
!/S      USE W3SERVMD, ONLY: STRACE

    IMPLICIT NONE

    INTEGER, INTENT(in)             :: nrgrd
    TYPE(output_type_t), INTENT(in) :: output_type(nrgrd)

    ! locals
    INTEGER              :: i
!/S      INTEGER, SAVE                           :: IENT = 0

!/S      CALL STRACE (IENT, 'NAMLMULTICONF')

    DO i=1,nrgrd
      WRITE (msg,'(a,i1,a)') 'output TYPE model grid',i, ' :'
      WRITE (MDSS,'(a)')
      WRITE (MDSS,10) TRIM(msg),'point % name         = ',TRIM(output_type(i)%point%name)
      WRITE (MDSS,10) TRIM(msg),'point % file         = ',TRIM(output_type(i)%point%file)
      WRITE (MDSS,10) TRIM(msg),'field % list         = ',TRIM(output_type(i)%field%list)
      WRITE (MDSS,13) TRIM(msg),'track % format       = ',output_type(i)%track%format
      WRITE (MDSS,11) TRIM(msg),'partition % x0       = ',output_type(i)%partition%x0
      WRITE (MDSS,11) TRIM(msg),'partition % xn       = ',output_type(i)%partition%xn
      WRITE (MDSS,11) TRIM(msg),'partition % nx       = ',output_type(i)%partition%nx
      WRITE (MDSS,11) TRIM(msg),'partition % y0       = ',output_type(i)%partition%y0
      WRITE (MDSS,11) TRIM(msg),'partition % yn       = ',output_type(i)%partition%yn
      WRITE (MDSS,11) TRIM(msg),'partition % ny       = ',output_type(i)%partition%ny
      WRITE (MDSS,13) TRIM(msg),'partition % format   = ',output_type(i)%partition%format
!/COU      WRITE (MDSS,10) TRIM(msg),'coupling % list         = ',TRIM(output_type(i)%coupling%list)
    END DO
    WRITE (MDSS,'(a)')

10  format (a,2x,a,a)
11  format (a,2x,a,i1)
13  format (a,2x,a,l1)

  END SUBROUTINE report_output_type_nml

!/ ------------------------------------------------------------------- /

  SUBROUTINE report_output_date_nml (nrgrd, output_date)
!/
!/                  +-----------------------------------+
!/                  | WAVEWATCH III           NOAA/NCEP |
!/                  |           M. Accensi              |
!/                  |                        FORTRAN 90 |
!/                  | Last update :         09-Aug-2016 |
!/                  +-----------------------------------+
!/
!/    09-Aug-2016 : Adding comments                     ( version 5.12 )
!/
!  1. Purpose :
!
!
!  2. Method :
!
!     See source term routines.
!
!  3. Parameters :
!
!     Parameter list
!     ----------------------------------------------------------------
!     ----------------------------------------------------------------
!
!  4. Subroutines used :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      STRACE    Subr. W3SERVMD SUBROUTINE tracing.
!     ----------------------------------------------------------------
!
!  5. Called by :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      NAMLMULTICONF Subr.   N/A    Namelist configuration routine.
!     ----------------------------------------------------------------
!
!  6. Error messages :
!
!     None.
!
!  7. Remarks :
!
!  8. Structure :
!
!     See source code.
!
!  9. Switches :
!
!     !/MPI  Uses MPI communications
!     !/T  Enable test output.
!
! 10. Source code :
!
!/ ------------------------------------------------------------------- /

    USE WMMDATMD, ONLY: MDSE, MDSS
!/S      USE W3SERVMD, ONLY: STRACE

    IMPLICIT NONE

    INTEGER, INTENT(in)             :: nrgrd
    TYPE(output_date_t), INTENT(in) :: output_date(nrgrd)

    ! locals
    INTEGER              :: i
!/S      INTEGER, SAVE                           :: IENT = 0

!/S      CALL STRACE (IENT, 'NAMLMULTICONF')

    DO i=1,nrgrd
      WRITE (msg,'(a,i1,a)') 'output date model grid',i, ' :'
      WRITE (MDSS,'(a)')
      WRITE (MDSS,10) TRIM(msg),'field start        = ',TRIM(output_date(i)%field%start)
      WRITE (MDSS,10) TRIM(msg),'field stride       = ',TRIM(output_date(i)%field%stride)
      WRITE (MDSS,10) TRIM(msg),'field stop         = ',TRIM(output_date(i)%field%stop)
      WRITE (MDSS,10) TRIM(msg),'point start        = ',TRIM(output_date(i)%point%start)
      WRITE (MDSS,10) TRIM(msg),'point stride       = ',TRIM(output_date(i)%point%stride)
      WRITE (MDSS,10) TRIM(msg),'point stop         = ',TRIM(output_date(i)%point%stop)
      WRITE (MDSS,10) TRIM(msg),'track start        = ',TRIM(output_date(i)%track%start)
      WRITE (MDSS,10) TRIM(msg),'track stride       = ',TRIM(output_date(i)%track%stride)
      WRITE (MDSS,10) TRIM(msg),'track stop         = ',TRIM(output_date(i)%track%stop)
      WRITE (MDSS,10) TRIM(msg),'restart start      = ',TRIM(output_date(i)%restart%start)
      WRITE (MDSS,10) TRIM(msg),'restart stride     = ',TRIM(output_date(i)%restart%stride)
      WRITE (MDSS,10) TRIM(msg),'restart stop       = ',TRIM(output_date(i)%restart%stop)
      WRITE (MDSS,10) TRIM(msg),'boundary start     = ',TRIM(output_date(i)%boundary%start)
      WRITE (MDSS,10) TRIM(msg),'boundary stride    = ',TRIM(output_date(i)%boundary%stride)
      WRITE (MDSS,10) TRIM(msg),'boundary stop      = ',TRIM(output_date(i)%boundary%stop)
      WRITE (MDSS,10) TRIM(msg),'partition start    = ',TRIM(output_date(i)%partition%start)
      WRITE (MDSS,10) TRIM(msg),'partition stride   = ',TRIM(output_date(i)%partition%stride)
      WRITE (MDSS,10) TRIM(msg),'partition stop     = ',TRIM(output_date(i)%partition%stop)
!/COU      WRITE (MDSS,10) TRIM(msg),'coupling start    = ',TRIM(output_date(i)%coupling%start)
!/COU      WRITE (MDSS,10) TRIM(msg),'coupling stride   = ',TRIM(output_date(i)%coupling%stride)
!/COU      WRITE (MDSS,10) TRIM(msg),'coupling stop     = ',TRIM(output_date(i)%coupling%stop)
    END DO
    WRITE (MDSS,'(a)')

10  format (a,2x,a,a)

  END SUBROUTINE report_output_date_nml

!/ ------------------------------------------------------------------- /

  SUBROUTINE report_homogeneous_input_nml (nmove, homogeneous_input)
!/
!/                  +-----------------------------------+
!/                  | WAVEWATCH III           NOAA/NCEP |
!/                  |           M. Accensi              |
!/                  |                        FORTRAN 90 |
!/                  | Last update :         09-Aug-2016 |
!/                  +-----------------------------------+
!/
!/    09-Aug-2016 : Adding comments                     ( version 5.12 )
!/
!  1. Purpose :
!
!
!  2. Method :
!
!     See source term routines.
!
!  3. Parameters :
!
!     Parameter list
!     ----------------------------------------------------------------
!     ----------------------------------------------------------------
!
!  4. Subroutines used :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      STRACE    Subr. W3SERVMD SUBROUTINE tracing.
!     ----------------------------------------------------------------
!
!  5. Called by :
!
!      Name      TYPE  Module   Description
!     ----------------------------------------------------------------
!      NAMLMULTICONF Subr.   N/A    Namelist configuration routine.
!     ----------------------------------------------------------------
!
!  6. Error messages :
!
!     None.
!
!  7. Remarks :
!
!  8. Structure :
!
!     See source code.
!
!  9. Switches :
!
!     !/MPI  Uses MPI communications
!     !/T  Enable test output.
!
! 10. Source code :
!
!/ ------------------------------------------------------------------- /

    USE WMMDATMD, ONLY: MDSE, MDSS
!/S      USE W3SERVMD, ONLY: STRACE

    IMPLICIT NONE

    INTEGER, INTENT(in)                   :: nmove
    TYPE(homogeneous_input_t), INTENT(in) :: homogeneous_input(nmove)

    ! locals
    INTEGER              :: i
!/S      INTEGER, SAVE                           :: IENT = 0

!/S      CALL STRACE (IENT, 'NAMLMULTICONF')

    WRITE (msg,'(a)') 'homogeneous input :'
    WRITE (MDSS,'(a)')
    DO i=1,nmove
      WRITE (MDSS,10) TRIM(msg),'moving start      = ',TRIM(homogeneous_input(i)%moving%start)
      WRITE (MDSS,14) TRIM(msg),'moving speed      = ',homogeneous_input(i)%moving%speed
      WRITE (MDSS,14) TRIM(msg),'moving direction  = ',homogeneous_input(i)%moving%direction
      WRITE (MDSS,'(a)')
    END DO

10  format (a,2x,a,a)
14  format (a,2x,a,f5.2)

  END SUBROUTINE report_homogeneous_input_nml

!/ ------------------------------------------------------------------- /





END MODULE W3NAMLMD

!/ ------------------------------------------------------------------- /
