MODULE YOMSKF

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

!*     Global arrays and variables for the Simplified Kalman Filter

!         LSKF     = .true. => Invoke simplified Kalman filter
!         L_SCALE_Y = .true. => Extract the eigenvalue from the GRIB header
!                               of each singular vector and use to scale the Y
!                               vector. (Use .true. for RRKF, .false. for ROKF.)
!         LROKF    = .true. => propagate covariances for Farrell/Ioannou reduced-order KF
!         LWRISKF  = .true. => write SKF vector (from sv calculation)
!         LTWSKFY  = internal flag to make wrmlppg write a 'y' vector
!         LTWSKFZ  = internal flag to make wrmlppg write a 'z' vector
!         NSKFVECS = number of vectors defining the unstable subspace
!         NWRISKF  = timestep at which to write the SKF vector
!         MSKFVEC  = internal counter to tell wrmlppg what to write
!         YSKFROT   = vectors defining the rotation matrix
!         YSKFMAT   = inverse background error matrix for the subspace
!         SKFSUBMAT= Copy of first NSKFVECS elements of YSKFMAT
!         CINSKFY  = Name of INPUT 'y' vector
!         CINSKFZ  = Name of INPUT 'z' vector
!         NCOVARVECS = Number of input pairs of vectors for COVAR
!         CINCOVARX  = Name of INPUT 'x' vector for COVAR
!         CINCOVARY  = Name of INPUT 'y' vector for COVAR
!         COUTCOVARZ = Name of OUTPUT 'z' vector for COVAR

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

USE PARKIND1  ,ONLY : JPIM     ,JPRB

USE CONTROL_VECTORS, ONLY: control_vector

IMPLICIT NONE

SAVE

LOGICAL :: LSKF
LOGICAL :: L_SCALE_Y
LOGICAL :: LROKF
LOGICAL :: LWRISKF
INTEGER(KIND=JPIM) :: NSKFVECS
INTEGER(KIND=JPIM) :: NWRISKF
INTEGER(KIND=JPIM) :: MSKFVEC
INTEGER(KIND=JPIM) :: NCOVARVECS
#ifdef RS6K
! xlf90 bug
TYPE(control_vector), ALLOCATABLE, SAVE :: YSKFROT(:)
TYPE(control_vector), ALLOCATABLE, SAVE :: YSKFMAT(:)
#else
TYPE(control_vector), ALLOCATABLE :: YSKFROT(:)
TYPE(control_vector), ALLOCATABLE :: YSKFMAT(:)
#endif
REAL(KIND=JPRB), ALLOCATABLE:: SKFSUBMAT(:,:)
CHARACTER (LEN = 16) ::  CINSKFY
CHARACTER (LEN = 16) ::  CINSKFZ
CHARACTER (LEN = 16) ::  CINCOVARX
CHARACTER (LEN = 16) ::  CINCOVARY
CHARACTER (LEN = 16) ::  COUTCOVARZ

LOGICAL :: LTWSKFY
LOGICAL :: LTWSKFZ
END MODULE YOMSKF
