SUBROUTINE SU_SUBSPACE

!**** *SU_SUBSPACE* - reads vectors in YV_SUBSPACE

!     Purpose.
!     --------
!           in order to define a projection operator used in OPK
!           The projection operator projects into
!           the orthogonal complement of span(v1...vn), where
!           v1...vn are the vectors in YV_SUBSPACE using
!           the inner product associated with the initial time
!           norm in the SV computation

!**   Interface.
!     ----------
!        *CALL* *SU_SUBSPACE

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

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

!     Method.
!     -------
!        See documentation

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

!        RDTLLCZ

!     Reference.
!     ----------
!        ECMWF research department documentation of the IFS

!     Author.
!     -------
!        Martin Leutbecher    *ECMWF*

!     Modifications.
!     --------------
!        Original       : 04-05-07
!        M.Hamrud      01-May-2006 Generalized IO scheme
!     ------------------------------------------------------------------

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

USE YOMLCZ   , ONLY : N_DIM_SUBSPACE, YV_SUBSPACE
USE YOMCVA   , ONLY : YSCALPSQRT
USE IOSTREAM_MIX , ONLY : SETUP_IOSTREAM,TYPE_IOSTREAM,CLOSE_IOSTREAM
USE CONTROL_VECTORS

IMPLICIT NONE


TYPE(control_vector) :: YL_ZVEC
TYPE(TYPE_IOSTREAM)  :: YL_IOSTR_SUBSP

INTEGER(KIND=JPIM) :: J, IOMASTER

REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "rdtllcz.intfb.h"

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

CALL ALLOCATE_CTLVEC(YL_ZVEC)

ALLOCATE (YV_SUBSPACE(N_DIM_SUBSPACE))
DO J =1,N_DIM_SUBSPACE
  CALL ALLOCATE_CTLVEC (YV_SUBSPACE(J))
ENDDO

IOMASTER=1
CALL SETUP_IOSTREAM(YL_IOSTR_SUBSP,'CIO','sv_subspace',CDMODE='r',KIOMASTER=IOMASTER,LDNOHELP=.TRUE.)

DO J=1, N_DIM_SUBSPACE
  CALL RDTLLCZ(YL_IOSTR_SUBSP,YL_ZVEC)
  !
  ! from IFS-variables to pseudo-variables 
  !   the initial time metric is the Euclidean metric.
  !   
  YL_ZVEC%data = YL_ZVEC%data * YSCALPSQRT%data
  YV_SUBSPACE(J) = YL_ZVEC
ENDDO

CALL CLOSE_IOSTREAM(YL_IOSTR_SUBSP)
CALL DEALLOCATE_CTLVEC(YL_ZVEC)


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