#include "w3macros.h"
!/ ------------------------------------------------------------------- /
      MODULE W3OACPMD
!/
!/                  +-----------------------------------+
!/                  | WAVEWATCH III           NOAA/NCEP |
!/                  |           A. Thevenin             |
!/                  |                        FORTRAN 90 |
!/                  | Last update :         22-Mar-2021 |
!/                  +-----------------------------------+
!/
!/      July-2013 : Origination.                         ( version 4.18 )
!/                    For upgrades see subroutines.
!/     April-2016 : Add comments (J. Pianezze)           ( version 5.07 )
!/    25-Sep-2020 : Coupling at T+0 support              ( version 7.10 )
!/    22-Mar-2021 : Adds extra coupling fields           ( version 7.xx )
!/
!/    Copyright 2009-2012 National Weather Service (NWS),
!/       National Oceanic and Atmospheric Administration.  All rights
!/       reserved.  WAVEWATCH III is a trademark of the NWS. 
!/       No unauthorized use without permission.
!/
!  1. Purpose :
!
!     Generic Module used for coupling applications with OASIS3-MCT
!
!  2. Variables and types :
!
!  3. Subroutines and functions :
!
!      Name                Type  Scope    Description
!     ----------------------------------------------------------------
!      CPL_OASIS_INIT      Subr. Public   Initialize the coupling
!      CPL_OASIS_GRID      Subr. Public   Grids defintion
!      CPL_OASIS_DEFINE    Subr. Public   Partition definition
!      CPL_OASIS_SND       Subr. Public   Send fields to ocean/atmos model
!      CPL_OASIS_RCV       Subr. Public   Receive fields from ocean/atmos model
!      CPL_OASIS_FINALIZE  Subr. Public   Finalize the coupling  
!     ----------------------------------------------------------------
!
!  4. Subroutines and functions used :
!
!      Name                 Type    Module    Description
!     --------------------------------------------------------------------
!      GET_LIST_EXCH_FIELD  Subr.   W3OACPMD  List of the exchanged fields
!      STRSPLIT             Subr.   W3SERVMD  Splits string into words
!     --------------------------------------------------------------------
!
!  5. Remarks
!
!     Module adapted from WRF-OASIS routine implemented by
!     Sebastien Masson (IPSL), Guillaume Samson (Legos) and Eric Maisonnave (Cerfacs)
!
!  6. Switches :
!  7. Source code :
!
!/ ------------------------------------------------------------------- /
!
      USE MOD_OASIS                                      ! OASIS3-MCT module 
!
      IMPLICIT NONE
      PRIVATE
!
      INTEGER               :: IL_COMPID                 ! Component model ID returned by oasis_init_comp
      CHARACTER(LEN=6)      :: CL_MODEL_NAME = 'wwatch'  ! Model name (same as in namcouple)   
      INTEGER               :: IL_ERR                    ! Return error code
      INTEGER, PUBLIC       :: IL_NB_RCV, IL_NB_SND      ! Number of coupling fields    
      INTEGER, PARAMETER    :: IP_MAXFLD=50              ! Maximum number of coupling fields
      INTEGER               :: NNODES                    ! Total numbers of cell in the grid
!   
      TYPE, PUBLIC          :: CPL_FIELD                 ! Type for coupling field information
         CHARACTER(LEN = 8) :: CL_FIELD_NAME             ! Name of the coupling field   
         INTEGER            :: IL_FIELD_ID               ! Field ID
      END TYPE CPL_FIELD
!
      TYPE(CPL_FIELD), DIMENSION(IP_MAXFLD), PUBLIC :: RCV_FLD, SND_FLD   ! Coupling fields
!
      INTEGER, PUBLIC       :: ID_OASIS_TIME=0           ! time counter for coupling exchanges
!
      LOGICAL, PUBLIC       :: CPLT0                     ! Flag for coupling at T+0
!
! * Accessibility
      PUBLIC CPL_OASIS_INIT
      PUBLIC CPL_OASIS_GRID
      PUBLIC CPL_OASIS_DEFINE 
      PUBLIC CPL_OASIS_SND
      PUBLIC CPL_OASIS_RCV
      PUBLIC CPL_OASIS_FINALIZE
!
      CONTAINS
!/ ------------------------------------------------------------------- /
      SUBROUTINE CPL_OASIS_INIT(ID_LCOMM)
!/
!/                  +-----------------------------------+
!/                  | WAVEWATCH III           NOAA/NCEP |
!/                  |           A. Thevenin             |
!/                  |                        FORTRAN 90 |
!/                  | Last update :          April-2016 |
!/                  +-----------------------------------+
!/
!/     Jul-2013 : Origination.                    ( version 4.18 )
!/     April-2016 : Add comments (J. Pianezze)    ( version 5.07 )
!/
!  1. Purpose :
!
!     Initialize the coupling
!
!  2. Method :
!  3. Parameters :
!
!     Parameter list
!     ----------------------------------------------------------------
!     ID_LCOMM     Int.     O    MPI communicator
!     ----------------------------------------------------------------
!
!  4. Subroutines used :
!
!  5. Called by :
!
!      Name                Type     Module    Description
!     ----------------------------------------------------------------
!      WW3_SHEL            Prog.    -         Main program
!     ----------------------------------------------------------------
!
!  6. Error messages :
!  7. Remarks :
!  8. Structure :
!  9. Switches :
! 10. Source code :
!
!/ ------------------------------------------------------------------- /
!
! * Argument
      INTEGER, INTENT(OUT) :: ID_LCOMM                   ! Model local communicator
!   
!----------------------------------------------------------------------
! * Executable part
!
      !! Initialize the coupling
      CALL OASIS_INIT_COMP(IL_COMPID, CL_MODEL_NAME, IL_ERR)
      IF (IL_ERR /= 0) THEN
         CALL OASIS_ABORT(IL_COMPID, 'CPL_OASIS_INIT', 'Problem during oasis_init_comp')
      ENDIF
!
      !! Get the value of a local MPI communicator to be used by WW3 for its internal parallelisation
      CALL OASIS_GET_LOCALCOMM(ID_LCOMM, IL_ERR)
      IF (IL_ERR /= 0) THEN
         CALL OASIS_ABORT(IL_COMPID, 'CPL_OASIS_INIT', 'Problem during oasis_get_localcomm')
      ENDIF
!
!/ ------------------------------------------------------------------- /
      END SUBROUTINE CPL_OASIS_INIT
!/ ------------------------------------------------------------------- /
      SUBROUTINE CPL_OASIS_GRID(LD_MASTER,ID_LCOMM)
!/
!/                  +-----------------------------------+
!/                  | WAVEWATCH III           NOAA/NCEP |
!/                  |           A. Thevenin             |
!/                  |           V. Garnier              |
!/                  |           M. Accensi              |
!/                  |                        FORTRAN 90 |
!/                  | Last update :          April-2016 |
!/                  +-----------------------------------+
!/
!/    Jul-2013 : Origination.                    ( version 4.18 )
!/    April-2016 : Add comments (J. Pianezze)    ( version 5.07 )
!/    Sept-2016 : Correct bug MPI (J. Pianezze)  ( version 5.12 )
!/
!  1. Purpose :
!
!     Grid data file definition
!
!  2. Method :
!  3. Parameters :
!
!     Parameter list
!     ----------------------------------------------------------------
!     LD_MASTER         Bool.    I     Flag to know the master process
!     ID_LCOMM          Int.     I     MPI communicator
!     ----------------------------------------------------------------
!
!  4. Subroutines used :
!  5. Called by :
!
!      Name                Type     Module    Description
!     ----------------------------------------------------------------
!      WW3_SHEL            Prog.    -         Main program
!     ----------------------------------------------------------------
!
!  6. Error messages :
!  7. Remarks :
!  8. Structure :
!  9. Switches :
! 10. Source code :
!
!/ ------------------------------------------------------------------- /
!
      USE CONSTANTS, ONLY: RADIUS, DERA
      USE W3GDATMD,  ONLY: NX, NY, FLAGLL, XGRD, YGRD, MAPSTA, &
                           & HPFAC, HQFAC, GTYPE, &
                           & UNGTYPE, RLGTYPE, CLGTYPE
!/SMC      USE W3GDATMD,  ONLY: NSEA, X0, Y0, MRFct, SX, SY, IJKCel
!/MPI      INCLUDE "mpif.h"
!
!/ ------------------------------------------------------------------- /
!/ Parameter list
!/
      LOGICAL, INTENT(IN) :: LD_MASTER    ! MASTER process or not
      INTEGER, INTENT(IN) :: ID_LCOMM     ! Model local communicator
!
!/ ------------------------------------------------------------------- /
!/ Local parameters
!/
      INTEGER, ALLOCATABLE :: MASK(:,:)
      INTEGER              :: I, IX, IY, NXW, NXE, NYS, NYN, INODE, IERR_MPI
      REAL, ALLOCATABLE    :: LON(:,:),LAT(:,:),AREA(:,:),      &
                              CORLON(:,:,:),CORLAT(:,:,:)
      REAL                 :: FACTOR
      LOGICAL              :: RGLGRD = .TRUE.
!/SMC      REAL                 :: DLON, DLAT
!/ ------------------------------------------------------------------- /
!
      IF (LD_MASTER) THEN
!
!/SMC         RGLGRD = .FALSE.
         !
         ! 0. Create grids file
         ! --------------------------------
         CALL OASIS_START_GRIDS_WRITING(IERR_MPI)
         !
         ! 1. Get the lat/lon/corners,areas and masks
         ! -------------------------------------------
         IF (GTYPE .EQ. RLGTYPE .OR. GTYPE .EQ. CLGTYPE) THEN
!
           IF (RGLGRD) THEN
             IF (FLAGLL) THEN
               FACTOR = 1.
             ELSE
               FACTOR = 1. / (RADIUS * DERA)
             END IF
             !
             ! 1.1. regular and curvilinear grids
             ! ----------------------------------
             NNODES = NX*NY
             NXW=1
             NXE=NX
             NYS=1
             NYN=NY
             ! 
             ! lat/lon
             ALLOCATE ( LON(NNODES,1), LAT(NNODES,1) ) 
             I = 0
             DO IY = NYS, NYN
               DO IX = NXW, NXE
                 I = I+1
                 LON(I,1)=XGRD(IY,IX)*FACTOR
                 LAT(I,1)=YGRD(IY,IX)*FACTOR
               END DO
             END DO
             !
             ! areas, corners
             ALLOCATE ( AREA(NNODES,1), CORLON(NNODES,1,4), CORLAT(NNODES,1,4) )
             I = 0
             DO IY = NYS, NYN
               DO IX = NXW, NXE
                 I = I+1
                 CORLON(I,1,1)=LON(I,1)+HPFAC(IY,IX)/2.*FACTOR
                 CORLON(I,1,2)=LON(I,1)-HPFAC(IY,IX)/2.*FACTOR
                 CORLON(I,1,3)=LON(I,1)-HPFAC(IY,IX)/2.*FACTOR
                 CORLON(I,1,4)=LON(I,1)+HPFAC(IY,IX)/2.*FACTOR
                 CORLAT(I,1,1)=LAT(I,1)+HQFAC(IY,IX)/2.*FACTOR
                 CORLAT(I,1,2)=LAT(I,1)+HQFAC(IY,IX)/2.*FACTOR
                 CORLAT(I,1,3)=LAT(I,1)-HQFAC(IY,IX)/2.*FACTOR
                 CORLAT(I,1,4)=LAT(I,1)-HQFAC(IY,IX)/2.*FACTOR
                 AREA(I,1)=HPFAC(IY,IX)*HQFAC(IY,IX)
               END DO
             END DO
             !
             ! Model grid mask
             ALLOCATE ( MASK(NNODES,1) )
             I = 0
             DO IY = NYS, NYN
               DO IX = NXW, NXE
                 I = I+1
                 ! Get the mask : 0 - sea  / 1 - open boundary cells (the land is already excluded)
                 IF ((MAPSTA(IY,IX) .EQ. 1)) THEN
                   MASK(I,1) = 0
                 ELSE
                   MASK(I,1) = 1
                 END IF
               END DO
             END DO
!/SMC           ELSE
!/SMC             !
!/SMC             ! 1.2. SMC grids
!/SMC             ! ----------------------------------
!/SMC             NNODES = NSEA
!/SMC             !
!/SMC             ! Calculate the smallest grid cell increments depending on the number of SMC levels 
!/SMC             DLON = SX / MRFct 
!/SMC             DLAT = SY / MRFct 
!/SMC             ! 
!/SMC             ALLOCATE ( LON(NNODES,1), LAT(NNODES,1) ) 
!/SMC             ALLOCATE ( AREA(NNODES,1), CORLON(NNODES,1,4), CORLAT(NNODES,1,4) )
!/SMC             ALLOCATE ( MASK(NNODES,1) )
!/SMC             DO I=1, NNODES
!/SMC               ! lat/lon
!/SMC               LON(I,1) = X0 + (IJKCel(1,I) + IJKCel(3,I)*0.5)*DLON
!/SMC               LAT(I,1) = Y0 + (IJKCel(2,I) + IJKCel(4,I)*0.5)*DLAT
!/SMC               ! corners
!/SMC               CORLON(I,1,1) = X0 + IJKCel(1,I)*DLON
!/SMC               CORLON(I,1,2) = X0 + (IJKCel(1,I) + IJKCel(3,I))*DLON
!/SMC               CORLON(I,1,3) = CORLON(I,1,2)
!/SMC               CORLON(I,1,4) = CORLON(I,1,1)
!/SMC               CORLAT(I,1,1) = Y0 + IJKCel(2,I)*DLAT
!/SMC               CORLAT(I,1,2)=CORLAT(I,1,1)
!/SMC               CORLAT(I,1,3) = Y0 + (IJKCel(2,I) + IJKCel(4,I))*DLAT
!/SMC               CORLAT(I,1,4)=CORLAT(I,1,3)
!/SMC               ! areas
!/SMC               AREA(I,1) = 0.25 * IJKCEL(3,I)*DLON * IJKCEL(4,I)*DLAT 
!/SMC               ! Model grid mask
!/SMC               MASK(I,1) = 1
!/SMC             ENDDO
           ENDIF
         ELSE
            !
            ! 1.3. Unstructured grids
            ! ----------------------------------
            WRITE(*,*) 'TO BE IMPLEMENT FOR UNSTRUCTURED GRIDS'
            STOP
         END IF
         !
         CALL OASIS_WRITE_GRID('ww3t',NNODES,1,LON,LAT)
         CALL OASIS_WRITE_CORNER('ww3t',NNODES,1,4,CORLON,CORLAT)
         CALL OASIS_WRITE_AREA('ww3t',NNODES,1,AREA)
         CALL OASIS_WRITE_MASK('ww3t',NNODES,1,MASK)
         !
         ! 2. Terminate grid writing
         ! -------------------------
         CALL OASIS_TERMINATE_GRIDS_WRITING()
         !
         DEALLOCATE(LON)
         DEALLOCATE(LAT)
         DEALLOCATE(CORLON)
         DEALLOCATE(CORLAT)
         DEALLOCATE(AREA)
         DEALLOCATE(MASK)
         !
      ENDIF
!
!/MPI      CALL MPI_BCAST(NNODES,1,MPI_INTEGER,0,ID_LCOMM,IERR_MPI)
!
!/ ------------------------------------------------------------------- /
      END SUBROUTINE CPL_OASIS_GRID
!/ ------------------------------------------------------------------- /
      SUBROUTINE CPL_OASIS_DEFINE(NDSO,RCV_STR,SND_STR)
!/
!/                  +-----------------------------------+
!/                  | WAVEWATCH III           NOAA/NCEP |
!/                  |           A. Thevenin             |
!/                  |           V. Garnier              |
!/                  |           M. Accensi              |
!/                  |                        FORTRAN 90 |
!/                  | Last update :         08-Jun-2018 |
!/                  +-----------------------------------+
!/
!/      Jul-2013 : Origination.                         ( version 4.18 )
!/    April-2016 : Add coupling for unstructured grids  ( version 5.07 )
!/                   (R. Baraille & J. Pianezze)
!/    April-2016 : Add comments (J. Pianezze)           ( version 5.07 )
!/    08-Jun-2018 : use INIT_GET_ISEA                   ( version 6.04 )
!/
!  1. Purpose :
!
!     Partition definition and coupling fields declaration
!
!  2. Method :
!  3. Parameters :
!
!     Parameter list
!     ----------------------------------------------------------------
!     NDSO             Int.      I      Id. of the output file
!     RCV_STR          Char.     I      Name of receive fields
!     SND_STR          Char.     I      Name of send fields
!     ----------------------------------------------------------------
!
!  4. Subroutines used :
!
!      Name                 Type    Module    Description
!     ----------------------------------------------------------------
!      GET_LIST_EXCH_FIELD  Subr.   W3OACPMD  List of the exchanged fields
!     ----------------------------------------------------------------
!
!  5. Called by :
!
!      Name                Type     Module    Description
!     ----------------------------------------------------------------
!      WW3_SHEL            Prog.    -         Main program
!     ----------------------------------------------------------------
!
!  6. Error messages :
!  7. Remarks :
!  8. Structure :
!  9. Switches :
! 10. Source code :
!
!/ ------------------------------------------------------------------- /
!
      USE W3GDATMD, ONLY: NSEAL,NSEA, NX, NY, MAPSTA, MAPSF, GTYPE, &
                        & UNGTYPE, RLGTYPE, CLGTYPE
      USE W3ODATMD, ONLY: NAPROC, IAPROC
      USE W3PARALL, ONLY : INIT_GET_ISEA
!
!/ ------------------------------------------------------------------- /
!/ Parameter list
!/
      INTEGER, INTENT(IN)                          :: NDSO
      CHARACTER(LEN=1024), INTENT(IN)              :: RCV_STR,SND_STR
!/
!/ ------------------------------------------------------------------- /
!/ Local parameters
!/
      INTEGER                 :: IB_I,I
      INTEGER                 :: IL_PART_ID      ! PartitionID
      INTEGER, ALLOCATABLE, DIMENSION(:)   :: ILA_PARAL       ! Description of the local partition in the global index space
      INTEGER, DIMENSION(4)   :: ILA_SHAPE       ! Vector giving the min & max index for each dim of the fields
      INTEGER, DIMENSION(2)   :: ILA_VAR_NODIMS  ! rank of fields & number of bundles (1 with OASIS3-MCT)
      INTEGER                 :: ISEA, JSEA, IX, IY
      INTEGER                 :: NHXW, NHXE, NHYS, NHYN  ! size of the halo at the western, eastern, southern, northern boundaries
      LOGICAL                 :: LL_MPI_FILE     ! to check if there an mpi.txt file for domain decompasition
      LOGICAL                 :: RGLGRD = .TRUE.
!/
!/ ------------------------------------------------------------------- /
!/ Executable part
!/
!/SMC      RGLGRD = .FALSE.
!
      IF (GTYPE .EQ. RLGTYPE .OR. GTYPE .EQ. CLGTYPE) THEN 
        IF (RGLGRD) THEN
          !
          ! 1.1. regular and curvilinear grids
          ! ----------------------------------
          NHXW = 1 ; NHXE = NX ; NHYS = 1 ; NHYN = NY
          NHXW = NHXW - 1
          NHXE = NX - NHXE
          NHYS = NHYS - 1
          NHYN = NY - NHYN
          !
          ALLOCATE(ILA_PARAL(2+NSEAL*2))
          !
          ! * Define the partition : OASIS ORANGE partition
          ILA_PARAL(1) = 3
          !
          ! * total number of segments of the global domain
          ILA_PARAL(2) = NSEAL
          !
          DO JSEA=1, NSEAL
            CALL INIT_GET_ISEA(ISEA,JSEA)
   
             IX = MAPSF(ISEA,1)
             IY = MAPSF(ISEA,2)
             ILA_PARAL(JSEA*2+1) = (IY - NHYN -1)*(NX - NHXE - NHXW) + (IX - NHXW - 1)
             ILA_PARAL(JSEA*2+2) = 1
          END DO
!/SMC        ELSE
!/SMC          !
!/SMC          ! 1.2. SMC grids
!/SMC          ! ----------------------------------
!/SMC          ALLOCATE(ILA_PARAL(2+NSEAL))
!/SMC          !
!/SMC          ! * Define the partition : OASIS POINTS partition
!/SMC          ILA_PARAL(1) = 4
!/SMC          !
!/SMC          ! * total number of segments of the global domain
!/SMC          ILA_PARAL(2) = NSEAL
!/SMC          !
!/SMC          DO JSEA=1, NSEAL
!/SMC            ILA_PARAL(JSEA+2) = IAPROC + (JSEA-1)*NAPROC
!/SMC          ENDDO
        ENDIF
        !
      ELSE
         !
         ! 1.3. Unstructured grids
         ! ----------------------------------
         WRITE(*,*) 'TO BE VERIFIED FOR UNSTRUCTURED GRIDS'
         STOP
         !
         DO JSEA=1,NSEAL
            ILA_PARAL(JSEA*2+1) = (IAPROC-1) + (JSEA-1)*NAPROC
            ILA_PARAL(JSEA*2+2) = 1
         END DO
         !
      ENDIF
      !
      ! 2. Partition definition
      ! ----------------------------------
      CALL OASIS_DEF_PARTITION(IL_PART_ID, ILA_PARAL,IL_ERR,NNODES)
      IF(IL_ERR /= 0) THEN
         CALL OASIS_ABORT(IL_COMPID, 'CPL_OASIS_DEFINE', 'Problem during oasis_def_partition')
      ENDIF
      !
      ! 3. Coupling fields declaration
      ! ----------------------------------      
      ILA_SHAPE(:) = (/1, NSEAL, 1, 1 /)
      !
      ILA_VAR_NODIMS(1) = 2    ! rank of fields array
      ILA_VAR_NODIMS(2) = 1    ! always 1 with OASIS3-MCT 2.0
      !
      CALL GET_LIST_EXCH_FIELD(NDSO, RCV_FLD, SND_FLD, IL_NB_RCV, IL_NB_SND, RCV_STR, SND_STR)
      !
      ! 3.1 Send coupling fields
      ! ---------------------------------- 
      DO IB_I = 1, IL_NB_SND
         CALL OASIS_DEF_VAR (SND_FLD(IB_I)%IL_FIELD_ID     &
              &            , SND_FLD(IB_I)%CL_FIELD_NAME   &
              &            , IL_PART_ID                    & 
              &            , ILA_VAR_NODIMS                &
              &            , OASIS_OUT                     &
              &            , ILA_SHAPE                     &
              &            , OASIS_REAL                    &
              &            , IL_ERR )
      
         IF (IL_ERR /= 0) THEN
            CALL OASIS_ABORT(IL_COMPID, 'CPL_OASIS_DEFINE', 'Problem during oasis_def_var')
         ENDIF         
      ENDDO
      !   
      ! 3.2 Received coupling fields
      ! ---------------------------------- 
      DO IB_I = 1, IL_NB_RCV
         CALL OASIS_DEF_VAR (RCV_FLD(IB_I)%IL_FIELD_ID    &
              &            , RCV_FLD(IB_I)%CL_FIELD_NAME  &
              &            , IL_PART_ID                   & 
              &            , ILA_VAR_NODIMS               &
              &            , OASIS_IN                     &
              &            , ILA_SHAPE                    &
              &            , OASIS_REAL                   &
              &            , IL_ERR )
         !      
         IF (IL_ERR /= 0) THEN
            CALL OASIS_ABORT(IL_COMPID, 'CPL_OASIS_DEFINE', 'Problem during oasis_def_var')
         ENDIF         
      ENDDO   
      !
      ! 4. End of definition phase
      ! ---------------------------------- 
      CALL OASIS_ENDDEF(IL_ERR)

      IF (IL_ERR /= 0) THEN
         CALL OASIS_ABORT(IL_COMPID, 'CPL_OASIS_DEFINE', 'Problem during oasis_enddef')
      ENDIF         
!
!/ ------------------------------------------------------------------- /
      END SUBROUTINE CPL_OASIS_DEFINE
!/ ------------------------------------------------------------------- /
      SUBROUTINE CPL_OASIS_SND(ID_NB, ID_TIME, RDA_FIELD, LD_ACTION)
!/
!/                  +-----------------------------------+
!/                  | WAVEWATCH III           NOAA/NCEP |
!/                  |           A. Thevenin             |
!/                  |                        FORTRAN 90 |
!/                  | Last update :          April-2016 |
!/                  +-----------------------------------+
!/
!/    Jul-2013 : Origination.                    ( version 4.18 )
!/    April-2016 : Add comments (J. Pianezze)    ( version 5.07 )
!/
!  1. Purpose :
!
!     In the model time step loop, each process sends its parts of the coupling field
!
!  2. Method :
!  3. Parameters :
!
!     Parameter list
!     ----------------------------------------------------------------
!     ID_NB           Int.      I       Number of the field to be send
!     ID_TIME         Int.      I       Atmosphere time-step in seconds
!     RDA_FIELD       Real      I       Coupling field array to be send
!     LD_ACTION       Bool.     O       Action performed
!     ----------------------------------------------------------------
!
!  4. Subroutines used :
!  5. Called by :
!
!      Name                  Type    Module     Description
!     ----------------------------------------------------------------
!      SND_FIELDS_TO_ATMOS   Subr.   W3AGCMMD   Send fields to atmos. model
!      SND_FIELDS_TO_OCEAN   Subr.   W3OGCMMD   Send fields to ocean model
!      SND_FIELDS_TO_ICE     Subr.   W3IGCMMD   Send fields to ice model
!     ----------------------------------------------------------------
!
!  6. Error messages :
!  7. Remarks :
!  8. Structure :
!  9. Switches :
! 10. Source code :
!
!/ ------------------------------------------------------------------- /
!/ Parameter list
!/
      INTEGER, INTENT(IN)   :: ID_NB                         ! Number of the field to be send
      INTEGER, INTENT(IN)   :: ID_TIME                       ! Atmosphere time-step in seconds
      REAL(KIND=8), DIMENSION(:,:), INTENT(IN) :: RDA_FIELD  ! Coupling field array to be send
      LOGICAL, INTENT(OUT)  :: LD_ACTION                     ! Action performed
!/
!/ ------------------------------------------------------------------- /
!/ Local parameters
!/
      INTEGER :: IL_INFO                                     ! OASIS3-MCT info argument
!/
!/ ------------------------------------------------------------------- /
!/ Executable part
!/
      CALL OASIS_PUT ( SND_FLD(ID_NB)%IL_FIELD_ID &
      &              , ID_TIME                    &
      &              , RDA_FIELD                  &
      &              , IL_INFO                    &
      &                )

      LD_ACTION = IL_INFO == OASIS_SENT     .OR. IL_INFO == OASIS_TOREST .OR.   &
      &           IL_INFO == OASIS_SENTOUT  .OR. IL_INFO == OASIS_TORESTOUT

!/ ------------------------------------------------------------------- /
     END SUBROUTINE CPL_OASIS_SND    
!/ ------------------------------------------------------------------- /
     SUBROUTINE CPL_OASIS_RCV(ID_NB, ID_TIME, RDA_FIELD, LD_ACTION)
!/
!/                  +-----------------------------------+
!/                  | WAVEWATCH III           NOAA/NCEP |
!/                  |           A. Thevenin             |
!/                  |                        FORTRAN 90 |
!/                  | Last update :          April-2016 |
!/                  +-----------------------------------+
!/
!/    Jul-2013 : Origination.                    ( version 4.18 )
!/    April-2016 : Add comments (J. Pianezze)    ( version 5.07 )
!/
!  1. Purpose :
!
!     In the model time step loop, each process receives its parts of the coupling field
!
!  2. Method :
!  3. Parameters :
!
!     Parameter list
!     ----------------------------------------------------------------
!     ID_NB           Int.      I       Number of the field to be received
!     ID_TIME         Int.      I       Ocean time-step in seconds
!     RDA_FIELD       Real      I       Coupling field array to be received
!     LD_ACTION       Bool.     O       Action performed
!     ----------------------------------------------------------------
!
!  4. Subroutines used :
!  5. Called by :
!
!      Name                  Type    Module     Description
!     ----------------------------------------------------------------
!      RCV_FIELDS_FROM_ATMOS   Subr.   W3AGCMMD   Receive fields from atmos. model
!      RCV_FIELDS_FROM_OCEAN   Subr.   W3OGCMMD   Receive fields from ocean model
!      RCV_FIELDS_FROM_ICE     Subr.   W3IGCMMD   Receive fields from ice model
!     ----------------------------------------------------------------
!
!  6. Error messages :
!  7. Remarks :
!  8. Structure :
!  9. Switches :
! 10. Source code :
!
!/ ------------------------------------------------------------------- /
!/ Parameter list
!/
      INTEGER, INTENT(IN)   :: ID_NB                          ! Number of the field to be received
      INTEGER, INTENT(IN)   :: ID_TIME                        ! Ocean time-step in seconds
      REAL(KIND=8), DIMENSION(:,:), INTENT(OUT) :: RDA_FIELD    ! Coupling field array to be received
      LOGICAL, INTENT(OUT)  :: LD_ACTION                      ! Action performed
!/
!/ ------------------------------------------------------------------- /
!/ Local parameters
!/
      INTEGER :: IL_INFO                                      ! OASIS3-MCT info argument
!/
!/ ------------------------------------------------------------------- /
!/ Executable part
!/
      CALL OASIS_GET ( RCV_fld(ID_NB)%IL_FIELD_ID &
      &              , ID_TIME                    &
      &              , RDA_FIELD                  &
      &              , IL_INFO                    &
      &                )
!   
      LD_ACTION = IL_INFO == OASIS_RECVD   .OR. IL_INFO == OASIS_FROMREST .OR.   &
      &           IL_INFO == OASIS_RECVOUT .OR. IL_INFO == OASIS_FROMRESTOUT
!
!/ ------------------------------------------------------------------- /
      END SUBROUTINE CPL_OASIS_RCV
!/ ------------------------------------------------------------------- /
      SUBROUTINE CPL_OASIS_FINALIZE
!/
!/                  +-----------------------------------+
!/                  | WAVEWATCH III           NOAA/NCEP |
!/                  |           A. Thevenin             |
!/                  |                        FORTRAN 90 |
!/                  | Last update :          April-2016 |
!/                  +-----------------------------------+
!/
!/    Jul-2013 : Origination.                    ( version 4.18 )
!/  April-2016 : Add comments (J. Pianezze)      ( version 5.07 )
!/
!  1. Purpose :
!
!     Terminate the coupling
!
!  2. Method :
!  3. Parameters :
!  4. Subroutines used :
!  5. Called by :
!
!      Name                Type     Module    Description
!     ----------------------------------------------------------------
!      WW3_SHEL            Prog.    -         Main program
!     ----------------------------------------------------------------
!
!  6. Error messages :
!  7. Remarks :
!  8. Structure :
!  9. Switches :
! 10. Source code :
!
!/ ------------------------------------------------------------------- /
!/ Executable part
!/
      CALL OASIS_TERMINATE(IL_ERR)
!   
      IF (IL_ERR /= 0) THEN
         CALL OASIS_ABORT(IL_COMPID, 'CPL_OASIS_FINALIZE', 'Problem during oasis_terminate')
      ENDIF  
!
!/ ------------------------------------------------------------------- /
      END SUBROUTINE CPL_OASIS_FINALIZE
!/ ------------------------------------------------------------------- /
      SUBROUTINE GET_LIST_EXCH_FIELD(NDSO, RCV, SND, ID_NB_RCV, ID_NB_SND, RCV_STR, SND_STR)
!/
!/                  +-----------------------------------+
!/                  | WAVEWATCH III           NOAA/NCEP |
!/                  |           A. Thevenin             |
!/                  |           V. Garnier              |
!/                  |           A.C. Bennis             |
!/                  |                        FORTRAN 90 |
!/                  | Last update :         22-Mar-2021 |
!/                  +-----------------------------------+
!/
!/    Jul-2013 : Origination.                               ( version 4.18 )
!/    Mar-2014 : J. Pianezze (LPO) : Add atmospheric fields ( version 5.07 )
!/    Apr-2015 : M. Accensi  (LPO) : Add fields selection   ( version 5.07 )
!/    Apr-2016 : Add comments (J. Pianezze)                 ( version 5.07 )
!/ 22-Mar-2021 : Adds extra coupling fields                 ( version 7.xx )
!/
!  1. Purpose :
!
!     Provides the list of coupling fields
!
!  2. Method :
!  3. Parameters :
!
!     Parameter list
!     ----------------------------------------------------------------
!     NDSO         Int.      I       Id. of the output file
!     RCV          Type     I/O      Received variables
!     SND          Type     I/O      Send variables
!     ID_NB_RCV    Int.     I/O      Number of received variables
!     ID_NB_SND    Int.     I/O      Number of send variables 
!     RCV_STR      Char.     I       Name of the received variables
!     SND_STR      Char      I       Name of the send variables 
!     ----------------------------------------------------------------
!
!  4. Subroutines used :
!
!      Name                Type    Module     Description
!     ----------------------------------------------------------------
!      STRSPLIT            Subr.   W3SERVMD   Splits string into words
!     ----------------------------------------------------------------
!
!  5. Called by :
!
!      Name                Type    Module     Description
!     ----------------------------------------------------------------
!      CPL_OASIS_DEFINE    Subr.   W3OACPMD   Partition definition
!     ----------------------------------------------------------------
!
!  6. Error messages :
!  7. Remarks :
!  8. Structure :
!  9. Switches :
! 10. Source code :
!
!/ ------------------------------------------------------------------- /
!
      USE W3SERVMD, ONLY: STRSPLIT
!
!/ ------------------------------------------------------------------- /
!/ Parameter list
!/
      TYPE(CPL_FIELD), DIMENSION(IP_MAXFLD), INTENT (INOUT)   :: RCV, SND
      INTEGER, INTENT(INOUT)                                  :: ID_NB_RCV, ID_NB_SND 
      INTEGER, INTENT(IN)                                     :: NDSO
      CHARACTER(LEN=1024), INTENT(IN)                         :: RCV_STR, SND_STR
!/
!/ ------------------------------------------------------------------- /
!/ Local parameters
!/
      CHARACTER(LEN=100)                                      :: OUT_NAMES(50), TESTSTR
      INTEGER                                                 :: IOUT
!/
!/ ------------------------------------------------------------------- /
!/ Executable part
!/
      !
      ! 1. Coupling fields received by WW3
      ! ----------------------------------
      ID_NB_RCV = 0
      !
      OUT_NAMES(:)=''
      CALL STRSPLIT(RCV_STR,OUT_NAMES)
      IOUT=0
      DO WHILE (LEN_TRIM(OUT_NAMES(IOUT+1)).NE.0)
         TESTSTR=OUT_NAMES(IOUT+1)
         SELECT CASE(TRIM(TESTSTR(1:6)))
              !
!
! OCEAM MODEL VARIABLES
!
!/OASOCM      CASE('DRY')
!/OASOCM         ! wet-drying at the middle of the cell
!/OASOCM         ID_NB_RCV=ID_NB_RCV+1
!/OASOCM         RCV(ID_NB_RCV)%CL_FIELD_NAME='WW3_OWDH'
!
!/OASOCM         ! wet-drying at u-location
!/OASOCM         ID_NB_RCV=ID_NB_RCV+1
!/OASOCM         RCV(ID_NB_RCV)%CL_FIELD_NAME='WW3_OWDU'
!  
!/OASOCM         ! wet-drying at v-location
!/OASOCM         ID_NB_RCV=ID_NB_RCV+1
!/OASOCM         RCV(ID_NB_RCV)%CL_FIELD_NAME='WW3_OWDV'
!
!/OASOCM      CASE('SSH')
!/OASOCM         ! ssh : sea surface height (m)
!/OASOCM         ID_NB_RCV=ID_NB_RCV+1
!/OASOCM         RCV(ID_NB_RCV)%CL_FIELD_NAME='WW3__SSH'
!
!/OASOCM      CASE('CUR')
!/OASOCM         ! uz : sea surface zonal currents (m.s-1)
!/OASOCM         ID_NB_RCV=ID_NB_RCV+1
!/OASOCM         RCV(ID_NB_RCV)%CL_FIELD_NAME='WW3_OSSU'
!
!/OASOCM         ! vz : sea surface meridional currents (m.s-1)
!/OASOCM         ID_NB_RCV=ID_NB_RCV+1
!/OASOCM         RCV(ID_NB_RCV)%CL_FIELD_NAME='WW3_OSSV'
!

!
! ATMOSPHERE MODEL VARIABLES
!
!/OASACM      CASE('WND')
!/OASACM         ! U10 : 10m u-wind speed (m.s-1)
!/OASACM         ID_NB_RCV=ID_NB_RCV+1
!/OASACM         RCV(ID_NB_RCV)%CL_FIELD_NAME='WW3__U10'
!
!/OASACM         ! V10 : 10m v-wind speed (m.s-1)
!/OASACM         ID_NB_RCV=ID_NB_RCV+1
!/OASACM         RCV(ID_NB_RCV)%CL_FIELD_NAME='WW3__V10'
!
!/OASACM      CASE('TAU')
!/OASACM         ! UTAUA : u-momentum (m2.s-2)
!/OASACM         ID_NB_RCV=ID_NB_RCV+1
!/OASACM         RCV(ID_NB_RCV)%CL_FIELD_NAME='WW3_UTAU'
!
!/OASACM         ! V10 : v-momentum speed (m2.s-2)
!/OASACM         ID_NB_RCV=ID_NB_RCV+1
!/OASACM         RCV(ID_NB_RCV)%CL_FIELD_NAME='WW3_VTAU'
!
!/OASACM      CASE('RHO')
!/OASACM         ! rhoa : air density (kg.m-3)
!/OASACM         ID_NB_RCV=ID_NB_RCV+1
!/OASACM         RCV(ID_NB_RCV)%CL_FIELD_NAME='WW3_RHOA'
!

!
! ICE MODEL VARIABLES
!
!/OASICM      CASE('IC1')
!/OASICM         ! IC1 : ice thickness (m)
!/OASICM         ID_NB_RCV=ID_NB_RCV+1
!/OASICM         RCV(ID_NB_RCV)%CL_FIELD_NAME='WW3__IC1'
!
!/OASICM      CASE('IC5')
!/OASICM         ! ICEF : ice floe diameters (m)
!/OASICM         ID_NB_RCV=ID_NB_RCV+1
!/OASICM         RCV(ID_NB_RCV)%CL_FIELD_NAME='WW3__IC5'
!
!/OASICM      CASE('ICE')
!/OASICM         ! ICE : ice concentration (n.d)
!/OASICM         ID_NB_RCV=ID_NB_RCV+1
!/OASICM         RCV(ID_NB_RCV)%CL_FIELD_NAME='WW3__ICE'
!

         CASE DEFAULT
            WRITE (NDSO,1001) TRIM(TESTSTR(1:6))
         END SELECT
         IOUT=IOUT+1
      END DO 
      !
      ! 2. Coupling fields sent by WW3
      ! ----------------------------------
      ID_NB_SND = 0   
      !
      OUT_NAMES(:)=''
      CALL STRSPLIT(SND_STR,OUT_NAMES)
      IOUT=0
      DO WHILE (LEN_TRIM(OUT_NAMES(IOUT+1)).NE.0)
         TESTSTR=OUT_NAMES(IOUT+1)
         SELECT CASE(TRIM(TESTSTR(1:6)))
                 !
!
! OCEAM MODEL VARIABLES
!
!/OASOCM         CASE('OHS')
!/OASOCM            ! Significant wave height (m)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3__OHS'
!
!/OASOCM         CASE('DRY')
!/OASOCM            ! mask to manage wet-drying
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_ODRY'
!
!/OASOCM         CASE('T0M1')
!/OASOCM            ! T0M1 / wave_t0m1 : mean period (s)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_T0M1'
!
!/OASOCM         CASE('T01')
!/OASOCM            ! T01 / wave_t01 : mean period (s)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3__T01'
!
!/OASOCM         CASE('DIR')
!/OASOCM            ! THM / wave_thm : cosinus of mean direction (n/a)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_CDIR'
!
!/OASOCM            ! THM / wave_thm : sinus of mean direction (n/a)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_SDIR'
!
!/OASOCM         CASE('BHD')
!/OASOCM            ! BHD / wave_bhd : wave-induced Bernoulli head pressure (bhd in N.m-1)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3__BHD'
!
!/OASOCM         CASE('TWO')
!/OASOCM            ! tauox / wave_tauox : x-component of the wave-ocean momentum flux (tauox in m2.s-2)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_TWOX'
!
!/OASOCM            ! tauoy / wave_tauoy : y-component of the wave-ocean momentum flux (tauox in m2.s-2)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_TWOY'
!
!/OASOCM         CASE('TOC')
!/OASOCM            ! tauocx / wave_tauocx : x-component of the total wave-ocean momentum flux (tauocx in m2.s-2)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_TOCX'
!
!/OASOCM            ! tauocy / wave_tauocy : y-component of the total wave-ocean momentum flux (tauocx in m2.s-2)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_TOCY'
!
!/OASOCM         CASE('FOC')
!/OASOCM            ! phioc / wave_phioc : Wave-to-ocean TKE flux (phioc in W.m-2)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3__FOC'
!
!/OASOCM         CASE('TBB')
!/OASOCM            ! Momentum flux due to bottom friction, u component (m2.s-2)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_TBBX'
!
!/OASOCM            ! Momentum flux due to bottom friction, v component (m2.s-2)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_TBBY'
!
!/OASOCM         CASE('FBB')
!/OASOCM            ! phibbl / wave_phibbl : Energy flux due to bottom friction (phioc in W.m-2)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3__FBB'
!
!/OASOCM         CASE('UBR')
!/OASOCM            ! uba / wave_ubrx : x component of the rms amplitude of orbital velocity of the waves (m/s)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_UBRX'
!
!/OASOCM            ! uba / wave_ubry : y component of the rms amplitude of orbital velocity of the waves (m/s)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_UBRY'
!
!/OASOCM         CASE('TAW')
!/OASOCM            ! tauwix / wave_tauwix : Net wave-supported stress, u component (tauwix in m2.s-2)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_TAWX'
!
!/OASOCM            ! tauwiy / wave_tauwiy : ! Net wave-supported stress, v component (tauwix in m2.s-2)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_TAWY'
!
!/OASOCM         CASE('LM')
!/OASOCM            ! wlm / wave_wlm : mean length wave (m)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3___LM'
!
!/OASOCM         CASE('WNM')
!/OASOCM            ! wnmean / wave_wnmean : mean wave number (m-1)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3__WNM'
!
!/OASOCM         CASE('TUS')
!/OASOCM            ! Volume transport associated to Stokes drift, u component (m2.s-1)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_TUSX'
!
!/OASOCM            ! Volume transport associated to Stokes drift, v component (m2.s-1)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_TUSY'
!
!/OASOCM         CASE('USS')
!/OASOCM            ! Surface Stokes drift, u component (m.s-1)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_USSX'
!
!/OASOCM            ! Surface Stokes drift, v component (m.s-1)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_USSY'
!
!/OASOCM         CASE('OCHA')
!/OASOCM            ! Charnock Coefficient (-)
!/OASOCM            ID_NB_SND = ID_NB_SND +1
!/OASOCM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_OCHA'

!
! ATMOSPHERE MODEL VARIABLES
!
!/OASACM         CASE('AHS')
!/OASACM            ! Significant wave height (m)
!/OASACM            ID_NB_SND = ID_NB_SND +1
!/OASACM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3__AHS'
!
!/OASACM         CASE('CUR')
!/OASACM            ! Ocean sea surface current (m.s-1)
!/OASACM            ID_NB_SND = ID_NB_SND +1
!/OASACM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_WSSU'
!
!/OASACM            ! Ocean sea surface current (m.s-1)
!/OASACM            ID_NB_SND = ID_NB_SND +1
!/OASACM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_WSSV'
!
!/OASACM         CASE('ACHA')
!/OASACM            ! Charnock Coefficient (-)
!/OASACM            ID_NB_SND = ID_NB_SND +1
!/OASACM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_ACHA'
!
!/OASACM         CASE('FP')
!/OASACM            ! Peak frequency (s-1)
!/OASACM            ID_NB_SND = ID_NB_SND +1
!/OASACM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3___FP'
!
!/OASACM         CASE('TP')
!/OASACM            ! Peak period (s)
!/OASACM            ID_NB_SND = ID_NB_SND +1
!/OASACM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3___TP'
!
!/OASACM         CASE('FWS')
!/OASACM            ! Wind_sea_mean_period_T0M1 (s)
!/OASACM            ID_NB_SND=ID_NB_SND+1
!/OASACM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3__FWS'
!

!
! ICE MODEL VARIABLES
!
!/OASICM         CASE('IC5')
!/OASICM            ! Ice floe diameters (m)
!/OASICM            ID_NB_SND = ID_NB_SND +1
!/OASICM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_ICEF'
!
!/OASICM         CASE('TWI')
!/OASICM            ! TWIX : x stress to ice , u component (twix in m2.s-2)
!/OASICM            ID_NB_SND = ID_NB_SND +1
!/OASICM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_TWIX'
!
!/OASICM            ! TWIY : y stress to ice , v component (twiy in m2.s-2)
!/OASICM            ID_NB_SND = ID_NB_SND +1
!/OASICM            SND(ID_NB_SND)%CL_FIELD_NAME='WW3_TWIY'
                    !
         CASE DEFAULT
            WRITE (NDSO,1002) TRIM(TESTSTR(1:6))
         END SELECT
         IOUT=IOUT+1
      END DO 
!
! Formats
!
 1001 FORMAT (/' *** WAVEWATCH III WARNING IN W3OACPMD : '/                       &
               '     REQUESTED COUPLING RECEIVED FIELD ',A,' WAS NOT RECOGNIZED.'/)
!
 1002 FORMAT (/' *** WAVEWATCH III WARNING IN W3OACPMD : '/                       &
               '     REQUESTED COUPLING SENT FIELD ',A,' WAS NOT RECOGNIZED.'/)
!/
!/ ------------------------------------------------------------------- /
      END SUBROUTINE GET_LIST_EXCH_FIELD
!/ ------------------------------------------------------------------- /
!/
      END MODULE W3OACPMD
!/
!/ ------------------------------------------------------------------- /
