SUBROUTINE SIPC_READ_MODEL(KINDEX,KDIM,CDJOBNAM_R,KINFOS,PINP_FIELD)  
!****
!**** *SIPC_Read_Model*  

!     Purpose:
!     -------
!     READ model input field and infos from field-specific pool

!**   Interface:
!     ---------
!       *CALL*  *SIPC_Read_Model (kindex, kdim, cdjobnam_r, kinfos, pinp_field)

!     Input:
!     -----
!          kindex : index of field to be read in total number of input fields
!          kdim   : dimension of field to be read 

!     Output:
!     ------
!          cdjobnam_r   :  Experiment name (character)
!          kinfos(1)    :  Initial date (integer)
!          kinfos(2)    :  Iteration number (integer)
!          kinfos(3)    :  Time since start (integer)
!          pinp_field   :  Field read

!     Workspace:
!     ---------
!     None

!     External
!     ---------
!     SVIPC_read

!     History:
!     -------
!       Version   Programmer     Date      Description
!       -------   ----------     ----      -----------  
!       2.2       S. Valcke      97/08/25  created
!                 S. Valcke      98/06/02  adapted in F90 for arpege

! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

!* ---------------------------- MODULE inclusion --------------------------

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK

USE YOM_OAS   , ONLY : cpmodinf
USE PAR_SIPC  , ONLY : jpbyteint, jpbyterea, jpbytecha
USE YOM_INPC  , ONLY : mpoolread
USE YOMLUN    , ONLY : NULOUT

!* ---------------------------- Argument declarations -------------------

IMPLICIT NONE

INTEGER(KIND=JPIM) ,INTENT(IN)    :: KDIM 
INTEGER(KIND=JPIM) ,INTENT(IN)    :: KINDEX 
CHARACTER (LEN = 3),INTENT(OUT)   :: CDJOBNAM_R
INTEGER(KIND=JPIM) ,INTENT(OUT)   :: KINFOS(3)
REAL(KIND=JPRB)    ,INTENT(OUT)   :: PINP_FIELD(KDIM)
!* ---------------------------- Local declarations ---------------------
INTEGER(KIND=JPIM) :: isizeinp, imrc
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "abor1.intfb.h"

!* ---------------------------- Poema verses ----------------------------

! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

!*    1. Initializations
!        ---------------

IF (LHOOK) CALL DR_HOOK('SIPC_READ_MODEL',0,ZHOOK_HANDLE)
WRITE (NULOUT,*) ' '
WRITE (NULOUT,*) &
 & '           ROUTINE SIPC_Read_Model '  
WRITE (NULOUT,*) &
 & '           ***********************'  
WRITE (NULOUT,*) ' '

!*    2. Read encapsulated infos in field-specific shared memory pool
!        (experiment name, initial date, time since start, iteration number)
!        -------------------------------------------------------------------

IF(cpmodinf == 'YES') then
  imrc = 0
  isizeinp = 3*jpbytecha
  CALL SVIPC_read(mpoolread(kindex), cdjobnam_r, isizeinp, imrc)
  isizeinp = 3*jpbyteint
  CALL SVIPC_read(mpoolread(kindex), kinfos, isizeinp, imrc)

!*        Find error if any

  IF (imrc < 0) THEN
    WRITE(NULOUT,*)&
     & 'Problem in reading encapsulated infos for field',&
     & kindex   
    CALL ABOR1('STOP in SIPC_Read_Model')
  ENDIF
ENDIF

!*    3. Read field in field-specific shared memory pool
!        -----------------------------------------------
isizeinp = kdim*jpbyterea
CALL SVIPC_read(mpoolread(kindex), pinp_field, isizeinp, imrc)

!*    Find error and STOP if any

IF (imrc < 0) THEN
  WRITE(NULOUT,*) &
   & 'Problem in reading in the SHM pool for field',&
   & kindex   
  CALL ABOR1('STOP in SIPC_Read_Model')
ENDIF

WRITE(NULOUT,*) 'Read the SHM pool for field:', kindex, cdjobnam_r
WRITE(NULOUT,*)  pinp_field(1), pinp_field(kdim)

!*    4. End of routine
!        --------------

WRITE (NULOUT,*) ' '
WRITE (NULOUT,*) ' --- End of routine SIPC_Read_model ---'
CALL FLUSH(NULOUT)
IF (LHOOK) CALL DR_HOOK('SIPC_READ_MODEL',1,ZHOOK_HANDLE)
END SUBROUTINE SIPC_READ_MODEL
