SUBROUTINE SUARPIO(KIND)

!**** *SUARPIO*  - INITIALIZE ARPEGE INPUT-OUTPUT

!     Purpose.
!     --------
!           ARPEGE file.

!**   Interface.
!     ----------
!        *CALL* *SUARPIO*

!        Explicit arguments :
!        --------------------

!        Implicit arguments :
!        --------------------

!     Externals.
!     ----------

!     Reference.
!     ----------

!     Author.
!     -------
!        MPP Group *METEO-FRANCE*

!     Modifications.
!     --------------
!        Original: 96-01-26
!        R. El Khatib 02-05-16 : verboose control
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!     ------------------------------------------------------------------

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

USE YOMLUN   , ONLY : NULOUT
USE YOMMP    , ONLY : LSPLITOUT,NSTRIN   ,NSTROUT
USE YOMCT0   , ONLY : NPROC    ,LOUTPUT  ,NPRINTLEV
USE YOMOP    , ONLY : NAGDIO   ,MAXFIELD

IMPLICIT NONE

INTEGER(KIND=JPIM),INTENT(IN)    :: KIND 
LOGICAL        :: LLFRSTIN=.TRUE.
LOGICAL        :: LLFRSTOUT=.TRUE.

INTEGER(KIND=JPIM) :: ISTR, J
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "abor1.intfb.h"

!-----------------------------------------------------------------------

IF (LHOOK) CALL DR_HOOK('SUARPIO',0,ZHOOK_HANDLE)
IF (.NOT.ALLOCATED(NAGDIO)) THEN
  ALLOCATE(NAGDIO(1,MAXFIELD))
  WRITE(NULOUT,9990) 'NAGDIO   ',SIZE(NAGDIO),SHAPE(NAGDIO)
ENDIF

!-----------------------------------------------------------------------

IF (KIND == 1.AND. LLFRSTIN) THEN         ! INPUT

  ISTR=NSTRIN
  ISTR=MIN(NSTRIN,NPROC)
  IF (ISTR <= 0) THEN
    ISTR=NPROC
  ENDIF
  NSTRIN=ISTR
  WRITE(NULOUT,*) 'INPUT STREAMS = ',NSTRIN
  LLFRSTIN=.FALSE.

ELSEIF (KIND == 2.AND. LLFRSTOUT) THEN   ! OUTPUT

  IF (LSPLITOUT) THEN
    CALL ABOR1('LSPLITOUT NOT IMPLEMENTED')
  ENDIF
  WRITE(NULOUT,*) 'LSPLITOUT = ',LSPLITOUT
  WRITE(NULOUT,*) 'OUPUT STREAMS = ',NSTROUT
  LLFRSTOUT=.FALSE.

ENDIF

NAGDIO=-999

IF (KIND == 1) THEN   ! INPUT

  DO J=1,MAXFIELD
    NAGDIO(1,J)=MOD(J-1,NSTRIN)+1
  ENDDO

ELSE                  ! OUTPUT

  DO J=1,MAXFIELD
    NAGDIO(1,J)=MOD(J-1,NSTROUT)+1
  ENDDO

ENDIF

IF (LOUTPUT.AND.NPRINTLEV>1) THEN
  WRITE(NULOUT,*) 'NAGDIO'
  WRITE(NULOUT,'(15(1X,I4))') NAGDIO
ENDIF

!-----------------------------------------------------------------------
9990 FORMAT(1X,'ARRAY ',A10,' ALLOCATED ',8I8)

IF (LHOOK) CALL DR_HOOK('SUARPIO',1,ZHOOK_HANDLE)
END SUBROUTINE SUARPIO
