SUBROUTINE JGNRI (KNUMB,KSTGLO,PGP3JB,PGP2JB)

!      JGNRI - Multiplication by forecast error standard deviations.

!     Arguments :
!     -----------
!     Input:
!       KNUMB    - number of grid columns for which computations
!                  are performed 
!       KSTGLO   - global offset
!     Input and output:
!       PGP3JB - 3d gridpoint fields (=transform of SPA3JB)
!       PGP2JB - 2d gridpoint fields (=transform of SPA2JB)

!     Author:  W. HECKLEY    *ECMWF*
!     -------

!     Modifications:
!     --------------
!     ORIGINAL 90-03-09.
!     MODIFIED W HECKLEY 91-01-20
!     Bill Heckley/Mats Hamrud 911015:Use MIOLIB for IO on forecast error files
!     Bill Heckley 04:02:92 - Use of either P or T as mass variable
!     Bill Heckley 10:03:92 - Projection onto vertical eigenvectors
!     Bill Heckley 30:03:92 - IO scheme
!     E Andersson  09:03:94 - Avoid IO if LNONSEP, u,v,P
!     M. Fisher    20:09:95 - Univariate tropics
!     Mats Hamrud  95-12-15   Remove NFGM .ne. 1, cleaning
!     Mats Hamrud  96-03-15   Preparation for message passing 
!     F. Bouttier  96-04-17   Modification of vertical correlations
!     J. Derber    96-07-17   Implement LJGBAL option
!     F. Bouttier  96-07-17   Correct comments
!     M. Fisher    01:08:96 - Normalize vorticity and divergence with
!                             vorticity errors rather than wind errors.
!     E.Andersson  96-10-15   Re-introduce LCFCE (=const bg errors)
!     M.Fisher     96-12-05   LCFCE now done by setting ZFCE constant
!     M.Fisher     97-10-17   Split JGNR and JGNRI and remove JGNRAD
!     E.Holm       98-01-12   Include ozone
!     E.Holm       01-10-02   Include gridpoint change of humidity variable
!                             and rewrite comments
!     E.Holm       05-06-03   Temporary reduction of stratospheric
!                             humidity errors and pure q analysis in
!                             stratosphere
!     M.Hamrud     03-08-01   GFL introduction
!     M.Hamrud     01-Oct-2003 CY28 Cleaning
!     M.Hamrud     01-Dec-2003 CY28R1 Cleaning
!     E.Holm       04-01-23   Include gridpoint change of ozone variable
!     L. Isaksen   28-06-04  Moved from scan2mtl to cvargptl; simplified
!     E.Holm       05-04-04   Smooth transition from tropospheric RH
!                             to stratospheric q control variable
!     E.Holm       05-10-20   Move variable transform to jbchvari
!     ------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
USE YOMDIM   , ONLY : NFLEVG   ,NPROMA
USE YOMJG    , ONLY : LJGNRSGP  ,NOFCEF   ,N_SPJB_VARS, SPJB_VARS_INFO
USE YOMFCEB  , ONLY : FCEBUF
USE YOMCVA  , ONLY : NVA3D, NVA2D
USE YOMGRB  , ONLY : NGRBO3, NGRBQ

IMPLICIT NONE


INTEGER(KIND=JPIM),INTENT(IN)    :: KNUMB 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTGLO 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGP3JB(NPROMA,NFLEVG,NVA3D) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGP2JB(NPROMA,NVA2D) 
REAL(KIND=JPRB) :: ZFCE(NPROMA,NOFCEF)

INTEGER(KIND=JPIM) :: IEND, IENDC, IST, ISTC, JROF, JLEV, &
                    & JFIELD, IPTJB, IOFF

LOGICAL :: LLNORMALIZE

REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "sc2rdg.intfb.h"
!     ------------------------------------------------------------------

IF (LHOOK) CALL DR_HOOK('JGNRI',0,ZHOOK_HANDLE)
IST   = 1
IEND  = KNUMB
ISTC  = 1
IENDC = KNUMB

CALL SC2RDG(FCEBUF,KSTGLO,ISTC,IENDC,ZFCE)

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

!*      1.  MULTIPLICATION BY FORECAST ERRORS

DO JFIELD=1,N_SPJB_VARS
  IPTJB=SPJB_VARS_INFO(JFIELD)%IPTJB
  IOFF =SPJB_VARS_INFO(JFIELD)%IPTFCE-1

  IF (SPJB_VARS_INFO(JFIELD)%IGRIBCODE==NGRBQ .OR. &
     &SPJB_VARS_INFO(JFIELD)%IGRIBCODE==NGRBO3) THEN
    LLNORMALIZE=.NOT.LJGNRSGP
  ELSE
    LLNORMALIZE=.TRUE.
  ENDIF

  IF (LLNORMALIZE) THEN
    IF (SPJB_VARS_INFO(JFIELD)%L_IN_SPA2) THEN
      DO JROF=IST,IEND
        PGP2JB(JROF,IPTJB) = PGP2JB(JROF,IPTJB)*ZFCE(JROF,IOFF+1)
      ENDDO
    ELSE
      DO JLEV=1,NFLEVG
        DO JROF=IST,IEND
          PGP3JB(JROF,JLEV,IPTJB) = &
              & PGP3JB(JROF,JLEV,IPTJB)*ZFCE(JROF,JLEV+IOFF)
        ENDDO
      ENDDO
    ENDIF
  ENDIF
ENDDO

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

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