SUBROUTINE SAVE_EVECS

!     Purpose.
!     --------
!        Save eigenvectors.

!     Author.
!     -------
!        Y.Tremolet

!     Modifications.
!     --------------
!        Original : 03-Nov-2004
! ------------------------------------------------------------------

USE PARKIND1, ONLY: JPIM, JPRB
USE YOMHOOK , ONLY: LHOOK, DR_HOOK
USE YOMLUN  , ONLY: NULOUT
USE YOMCT0  , ONLY: CNMEXP
USE YOMCVA  , ONLY: YVAZX
USE YOMVAR  , ONLY: LEVECCNTL, NUPTRA
USE YOMVCGL , ONLY: NVCGLEV, YVCGLEV, NVCGLPC, YVCGLPC, NSAVEPC, NSAVEEV

IMPLICIT NONE

INTEGER(KIND=JPIM) :: jj,ivecs
CHARACTER(LEN=12) :: clfile
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "write_ctlvec_grib.intfb.h"
#include "abor1.intfb.h"

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

IF (LHOOK) CALL DR_HOOK('SAVE_EVECS',0,ZHOOK_HANDLE)

IF (.NOT.LEVECCNTL) CALL ABOR1('SAVE_EVECS: Cannot save EV in model space')

! Control vector
! --------------
WRITE(NULOUT,*)"SAVE_EVECS: Saving control vector."
clfile="CV"//CNMEXP(1:4)//"XXX000"
WRITE(clfile( 7: 9),'(I3.3)') NUPTRA
CALL WRITE_CTLVEC_GRIB(clfile,YVAZX)

! Preconditioning vectors
! -----------------------
ivecs=MIN(NVCGLPC,NSAVEPC)
WRITE(NULOUT,*)"SAVE_EVECS: Saving",ivecs,"preconditioning vectors", &
             & " out of",NVCGLPC,"."
DO jj=1,ivecs
  clfile="PC"//CNMEXP(1:4)//"XXXXXX"
  WRITE(clfile( 7: 9),'(I3.3)') NUPTRA
  WRITE(clfile(10:12),'(I3.3)') jj
  CALL WRITE_CTLVEC_GRIB(clfile,YVCGLPC(jj))
ENDDO

! Eigenvectors
! ------------
ivecs=MIN(NVCGLEV,NSAVEEV)
WRITE(NULOUT,*)"SAVE_EVECS: Saving",ivecs,"eigenvectors", &
             & " out of",NVCGLEV,"."
DO jj=1,ivecs
  clfile="EV"//CNMEXP(1:4)//"XXXXXX"
  WRITE(clfile( 7: 9),'(I3.3)') NUPTRA
  WRITE(clfile(10:12),'(I3.3)') jj
  CALL WRITE_CTLVEC_GRIB(clfile,YVCGLEV(jj))
ENDDO

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