SUBROUTINE RDFPINC(YDSPEC_INCR,YDGRID_INCR)

!**** *RDFPINC*  - reads in the TL trajectory of the model
!                  from ARPEGE/GRIB files.

!     Purpose.
!     --------
!        Read in the trajectory

!**   Interface.
!     ----------
!        *CALL* *RDFPINC

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

!        Implicit arguments :      The state variables of the model
!        --------------------

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

!     Externals.
!     ----------
!        SUINIF   - READ DATA FROM GRIB/ARPEGE FILES
!        CPGRIDF  - COPY GRID-POINT WORK FILES/BUFFERS
!        CHGRIDF  - ADD/SUB GRID-POINT WORK FILES/BUFFERS
!        WRSPBUF  - WRITE SPECTRAL WORK FILES/BUFFERS
!        RDSPBUF  - WRITE SPECTRAL WORK FILES/BUFFERS
!        CMAC     - NORMAL MODE INITIALIZATION
!        SPECRT   - CONVERT TV to T, or T to TV (Distributed Memory).
!        SYMTRANSIN - Nonlinear inverse transform of humidity control
!                     variable (LGPQ.and.LECMWF)
!        SUGPQLIM - Limit Q to between 0. and QSat (Dist Memory)
!        SUSPQLIM - Limit Q to between 0. and QSat (.NOT.LGPQ) (Dist Memory)

!     Reference.
!     ----------
!        ECMWF Research Department documentation of the IFS

!     Author.
!     -------
!        Jean-Noel Thepaut  *ECMWF*

!     Modifications.
!     --------------
!        Original    : 96-02-23
!     Erik Andersson : 96-04-25  Code for grid-point q and LSPRT
!     Lars Isaksen   : 96-05-05  Adapted for Message Passing
!     Erik Andersson : 96-07-08  Fujitsu vectorisation
!     Adrian Simmons : 96-11-25  No humidity increment if dry background
!     J.-N. Thepaut  : 97-03-12  No humidity increment above 300 hPa
!     F. Taillefer   : 98-03-28  Message Passing for MF
!     F.Bouttier/M.Hortal 98-01-23 Shrink LADJORO constructs to ease maintenance
!     E.Holm         : 98-06-28  Included grid-point ozone
!     Modified 98-08-10 by K. YESSAD: removal of LRPOLE option.
!          - removal of argument .FALSE. in 'CALL SPEREESM/DM'.
!     V.Casse        : 99-02     modification suspqlim
!     Adrian Simmons : 99-10-25  Reinstate humidity inc for dry background
!     JN Thepaut     : 00-06     disable suspqlim if canari called after 4dvar
!      D.Salmond     : 15-10-01  FULLIMP mods
!     Y.Tremolet     : 02-05-21  Form increment before adding to FG.
!     E. Holm        : 03-04-14  New humidity analysis removes SUGPQLIM
!                                and replaces it with nonlinear inverse
!                                transform from control variables to
!                                increments in SYMTRANSIN (only q so far).
!     M.Hamrud       : 03-08-01  GFL introduction
!        M.Hamrud      01-Oct-2003 CY28 Cleaning
!     E. Holm        : 04-01-26  Ozone nonlinear analysis version included
!                                in SYMTRANSIN.
!     G. Desroziers  : 04-02-18 restore possibility to read low res an and
!                               bg separately
!     JJMorcrette 20070226 prognostic aerosols
!     G. Radnoti     : 06-11-28 for model errors: increment as dummy
!     E. Holm        : 07-06-04 Remove zeroing and tapering off of increments
!                               at model top
!     E. Holm        : 08-06-09 For conserving interpolation, calculate
!                               global gridpoint ps on each processor
!                               in GRID_PSGLOBAL.
!     E. Holm        : 09-06-23 Add back scaling down of model top increments (NLEV_REDINC>0)
!     E. Holm        : 08-11-12 Add background reading (for symtransin) and
!                               clean GEMS contributions 
!     B. Chapnik     : 22-Sep-2008 Introduction of LELAM case
!     -------------------------------------------------------------------------

USE PARKIND1  ,ONLY : JPIM     ,JPRB
USE YOMHOOK   ,ONLY : LHOOK,   DR_HOOK
USE YOMLUN   , ONLY : NULOUT
USE YOMCT0   , ONLY : LSPRT    ,LCANARI  ,LELAM   , NINTERPINCR
USE YOMCT0B  , ONLY : LECMWF
USE YOMDIM   , ONLY : NFLEVL   ,NFLEVG   ,NPROMA   ,NGPBLKS   ,&
 & NFLSUR   ,NSPEC2   ,NS3D     ,NS2D  
USE YOMSP    , ONLY : SPA3     ,SPA2     ,SPT      ,SPQ      ,SPSP 
USE YOMPHY   , ONLY : LREASUR  ,LCONDWT
USE YOMGFL   , ONLY : GFL
USE YOM_YGFL , ONLY : YGFL     ,YGFLC    ,YQ       ,YO3, YI, YL, YR, YS, JPAERO, NACTAERO
USE YOMGEM   , ONLY : VBH      ,VAH      ,NGPTOT   ,NGPTOTG
USE YOMMP    , ONLY : NPSP, MYSETV, NPTRLL
USE YOMCMA   , ONLY : NRESUPD  
USE YOMVAR   , ONLY : NUPTRA   ,L3DFGAT, LREABVEC
USE YOMJG    , ONLY : LJB_NONLINEAR_CVHUM, LJB_NONLINEAR_CVO3, REDINC, NLEV_REDINC
USE YOMGRB   , ONLY : NGRBQ, NGRBO3, NGRBAERLG, NGRBGHG, NGRBGRG, &
      & NGRBAERMR01, NGRBAERMR02, NGRBAERMR03, NGRBAERMR04, NGRBAERMR05, NGRBAERMR06, &
      & NGRBAERMR07, NGRBAERMR08, NGRBAERMR09, NGRBAERMR10, NGRBAERMR11, NGRBAERMR12, &
      & NGRBAERMR13, NGRBAERMR14
USE YOMSP_PTRS,ONLY : MSPTR_T,  MSPTR_SP
USE YOM_GRID_BICONSERV , ONLY : RGPPRS_HR, RGPPRS_LR
USE YOMGC    , ONLY : GELAT
USE YOMCST   , ONLY : RPI
USE GRIDPOINT_FIELDS_MIX
USE SPECTRAL_FIELDS_MOD

!   ---------------------------------------------------------------------------
IMPLICIT NONE

TYPE(GRIDPOINT_FIELD), OPTIONAL, INTENT(INOUT) :: YDGRID_INCR
TYPE(SPECTRAL_FIELD),  OPTIONAL, INTENT(INOUT) :: YDSPEC_INCR

REAL(KIND=JPRB) :: ZPA35(NFLSUR,NSPEC2,NS3D), ZPA25(NSPEC2,NS2D)
REAL(KIND=JPRB) :: ZPA37(NFLSUR,NSPEC2,NS3D), ZPA27(NSPEC2,NS2D)
REAL(KIND=JPRB) :: ZFTDAT(NSPEC2)
REAL(KIND=JPRB) :: ZGFL5(NPROMA,NFLEVG,YGFL%NDIM0,NGPBLKS)
REAL(KIND=JPRB) :: ZGFL7(NPROMA,NFLEVG,YGFL%NDIM0,NGPBLKS)
REAL(KIND=JPRB) :: ZAERO(NPROMA,NFLEVG,NACTAERO,NGPBLKS)
REAL(KIND=JPRB) :: ZTAERINC(NPROMA,NFLEVG,NGPBLKS)
REAL(KIND=JPRB) :: ZTAER(NPROMA,NFLEVG,NGPBLKS)
REAL(KIND=JPRB) :: ZAEROFR(NPROMA,NFLEVG,NACTAERO,NGPBLKS)
REAL(KIND=JPRB), ALLOCATABLE :: ZSQOLD(:,:), ZZSQOLD(:)
REAL(KIND=JPRB), ALLOCATABLE :: ZSTREF(:), ZSQREF(:), ZFQDAT(:)
REAL(KIND=JPRB), ALLOCATABLE :: ZDTREF(:), ZDQREF(:)
REAL(KIND=JPRB), ALLOCATABLE :: ZSPGP0(:), ZTMIN(:)
REAL(KIND=JPRB), ALLOCATABLE :: ZAPA3(:,:,:), ZAPA2(:,:), ZAGFL(:,:,:,:)

INTEGER(KIND=JPIM) ::  ILEVI, JJLEV, JLEV, JSTGLO, ICEND, IBL, JAER, JL, JK
INTEGER(KIND=JPIM) :: JGFL, ILEVG
INTEGER(KIND=JPIM), DIMENSION(JPAERO) :: IGRBAER

REAL(KIND=JPRB) :: ZLATAERO
LOGICAL :: LLAER_ZERO_INC
INTEGER(KIND=JPIM) ::  JLAT, ILEV0

LOGICAL :: LLCOR,  LLREASUR, LLSPRT
INTEGER(KIND=JPIM) :: INREQIN(YGFL%NUMFLDS)
REAL(KIND=JPRB) :: ZPREF, ZPTEST
REAL(KIND=JPRB) :: ZHOOK_HANDLE

#include "esperee.intfb.h"
#include "gpnorm_gfl.intfb.h"
#include "gpnorm3.intfb.h"
#include "grid_psglobal.intfb.h"
#include "specrt.intfb.h"
#include "speree.intfb.h"
#include "spnorm.intfb.h"
#include "sugpqlim.intfb.h"
#include "suinif.intfb.h"
#include "suspqlim.intfb.h"
#include "symtransin.intfb.h"
#include "model2moderr.intfb.h"
#include "abor1.intfb.h"
!     ------------------------------------------------------------------

IF (LHOOK) CALL DR_HOOK('RDFPINC',0,ZHOOK_HANDLE)
LLCOR=.NOT.YQ%LGP .AND..NOT.LECMWF.AND..NOT.(LCANARI.AND.NRESUPD>1)


!*    1.    OLD SPECTRAL ARRAY (FG-HR)
!           --------------------------

WRITE(NULOUT,*) ' RDFPINC: NORMS OF HIGH-RES FG'
CALL SPNORM(0)
CALL GPNORM_GFL

IF(LLCOR) THEN

!*    COMPUTE THE CRITICAL LEVEL TO APPLY Q CORRECTION

  ILEVI=0
  ZPTEST=30000._JPRB
  ZPREF=100000._JPRB

  DO JLEV=0,NFLEVG
    IF((VAH(JLEV)+VBH(JLEV)*ZPREF) <= ZPTEST) THEN
      ILEVI=ILEVI+1
    ENDIF
  ENDDO

  WRITE(NULOUT,*) 'RDFPINC: ILEVI = ', ILEVI

!*    SAVE FG-HR OF HUMIDITY

  ALLOCATE(ZSQOLD(ILEVI+1,NSPEC2))
  DO JLEV=1,ILEVI+1
    ZSQOLD(JLEV,:)=SPQ(JLEV,:)
  ENDDO
ENDIF

!*    1.2   Convert FG-HR TV to T if necessary.

IF (LSPRT) THEN
  CALL SPECRT(1)
ENDIF
LLSPRT=LSPRT
LSPRT=.FALSE.

IF (NUPTRA>0 .OR. LREABVEC) THEN

!*    1.3   Save FG-HR

  ZPA35(:,:,:)=SPA3(:,:,:)
  IF(NPSP == 1) ZPA25(:,:)=SPA2(:,:)
  
!*    1.4   FOR CONSERVING INTERPOLATION, CREATE GLOBAL
!*          GRIDPOINT FG-HR SURFACE PRESSURE ON EACH PROCESSOR.

  IF (NINTERPINCR==3) THEN
    IF (.NOT.ALLOCATED(RGPPRS_HR)) ALLOCATE(RGPPRS_HR(NGPTOTG))
    CALL GRID_PSGLOBAL(ZPA25(1,MSPTR_SP))
  ENDIF

!*    1.5   SAVE GRID-POINT GFL (FG-HR)

  DO JGFL=1,YGFL%NUMFLDS
    IF(YGFLC(JGFL)%LGP) THEN
      DO JSTGLO=1,NGPTOT,NPROMA
        ICEND=MIN(NPROMA,NGPTOT-JSTGLO+1)
        IBL=(JSTGLO-1)/NPROMA+1
        ZGFL5(1:ICEND,1:NFLEVG,YGFLC(JGFL)%MP,IBL)=&
         & GFL(1:ICEND,1:NFLEVG,YGFLC(JGFL)%MP,IBL) 
      ENDDO
    ENDIF
  ENDDO

!*    1.6 SAVE AEROSOL MIXING RATIOS/FRACTIONS SEPARATELY

  IF(NACTAERO > 0) THEN
    IGRBAER(:) = (/NGRBAERMR01, NGRBAERMR02, NGRBAERMR03, NGRBAERMR04, &
    & NGRBAERMR05, NGRBAERMR06, NGRBAERMR07, NGRBAERMR08, NGRBAERMR09, &
    & NGRBAERMR10, NGRBAERMR11, NGRBAERMR12, NGRBAERMR13, NGRBAERMR14, &
    & NGRBAERLG/)
    ZAERO  (:,:,:,:) = 0.0_JPRB
    ZTAER  (:,:,:)   = 0.0_JPRB
    ZAEROFR(:,:,:,:) = 0.0_JPRB
    DO JGFL=1,YGFL%NUMFLDS
      DO JAER=1,NACTAERO
        IF(YGFLC(JGFL)%LGP .AND. YGFLC(JGFL)%IGRBCODE == IGRBAER(JAER) ) THEN
          DO JSTGLO=1,NGPTOT,NPROMA
            ICEND=MIN(NPROMA,NGPTOT-JSTGLO+1)
            IBL=(JSTGLO-1)/NPROMA+1
            ZAERO(1:ICEND,1:NFLEVG,JAER,IBL) = &
                               &  ZGFL5(1:ICEND,1:NFLEVG,YGFLC(JGFL)%MP,IBL)
            ZTAER(1:ICEND,1:NFLEVG,IBL) = ZTAER(1:ICEND,1:NFLEVG,IBL) &
                               & +ZGFL5(1:ICEND,1:NFLEVG,YGFLC(JGFL)%MP,IBL)
          ENDDO
        ENDIF
      ENDDO
    ENDDO
    DO JAER=1,NACTAERO
      DO JSTGLO=1,NGPTOT,NPROMA
        ICEND=MIN(NPROMA,NGPTOT-JSTGLO+1)
        IBL=(JSTGLO-1)/NPROMA+1
        DO JK=1,NFLEVG
          DO JL=1,ICEND
            IF(ZTAER(JL,JK,IBL) > 0.0_JPRB ) THEN
              ZAEROFR(JL,JK,JAER,IBL) = ZAERO(JL,JK,JAER,IBL)/ZTAER(JL,JK,IBL)
            ENDIF
          ENDDO
        ENDDO
      ENDDO
    ENDDO
  ENDIF

!*    2.    READ HIGH RES BACKGROUND (for symtransin)
!           ------------------------

! Surface fields not needed and not read
  LLREASUR=LREASUR
  LREASUR=.FALSE.
  IF(LECMWF) THEN
    DO JGFL=1,YGFL%NUMFLDS
!     Add needed gridpoint fields here
      IF(YGFLC(JGFL)%LGP) THEN
        INREQIN(JGFL)=YGFLC(JGFL)%NREQIN
        IF( YGFLC(JGFL)%IGRBCODE == NGRBQ  .OR. &
          & YGFLC(JGFL)%IGRBCODE == NGRBO3 ) THEN
          YGFLC(JGFL)%NREQIN=1
        ELSE
          YGFLC(JGFL)%NREQIN=0
        ENDIF
      ENDIF
    ENDDO
    CALL SUINIF(12)
    ZPA37(:,:,:)=SPA3(:,:,:)
    IF (NPSP == 1) ZPA27(:,:)=SPA2(:,:)
    DO JGFL=1,YGFL%NUMFLDS
      IF(YGFLC(JGFL)%LGP) THEN
        DO JSTGLO=1,NGPTOT,NPROMA
          ICEND=MIN(NPROMA,NGPTOT-JSTGLO+1)
          IBL=(JSTGLO-1)/NPROMA+1
          ZGFL7(1:ICEND,1:NFLEVG,YGFLC(JGFL)%MP,IBL)=&
           & GFL(1:ICEND,1:NFLEVG,YGFLC(JGFL)%MP,IBL) 
        ENDDO
      ENDIF
    ENDDO
  ENDIF   


!*    3.    READ LOW RES INCREMENT
!           ----------------------

!*    3.1   We're only going to read upper-air fields, LR-INC.
!           Not cloud fields. Only total aerosol mixing ratio.

  IF (.NOT. LCONDWT .OR. .NOT. LCANARI .OR. L3DFGAT) THEN
    DO JGFL=1,YGFL%NUMFLDS
      IF(YGFLC(JGFL)%LGP) THEN
        INREQIN(JGFL)=YGFLC(JGFL)%NREQIN
        IF (   YGFLC(JGFL)%IGRBCODE == NGRBQ       .OR. &
         &     YGFLC(JGFL)%IGRBCODE == NGRBO3      .OR. &
         & ANY(YGFLC(JGFL)%IGRBCODE == NGRBGHG(:)) .OR. &
         & ANY(YGFLC(JGFL)%IGRBCODE == NGRBGRG(:)) .OR. &
         &     YGFLC(JGFL)%IGRBCODE == NGRBAERLG        &
         &   ) THEN
          YGFLC(JGFL)%NREQIN=1
        ELSE
          YGFLC(JGFL)%NREQIN=0
        ENDIF
      ENDIF
    ENDDO
  ENDIF

!*    3.2   READ ARPEGE OR GRIB DATA (INCR. IF LECMWF=.T., AN IF LECMWF=.F.), 
!           T not RT.

  IF (PRESENT(YDSPEC_INCR) .AND. .NOT. PRESENT(YDGRID_INCR)) &
  &  CALL ABOR1('RDFPINC:PRESENT(YDSPEC_INCR) .AND. .NOT. PRESENT(YDGRID_INCR)')
  IF (PRESENT(YDGRID_INCR) .AND. .NOT. PRESENT(YDSPEC_INCR)) &
  &  CALL ABOR1('RDFPINC:PRESENT(YDGRID_INCR) .AND. .NOT. PRESENT(YDSPEC_INCR)')

  IF (PRESENT(YDSPEC_INCR)) THEN
    CALL MODEL2MODERR(-1,YDSPEC_INCR,YDGRID_INCR)
!gr: TV-->T for the increments, provided that they are Tv on input
!    this is a bit dirty because nothing guarantees that the minimization
!    was also with LSPRT=T, the clean way would be to do the Tv-->T conversion
!    in wrmoderr and the T-->Tv in rdmoderr, controlled by LSPRT, just like in
!    suinif, etc....
    IF (LLSPRT) CALL SPECRT(1)
  ELSE
    CALL SUINIF(7)
    IF (ALLOCATED(RGPPRS_HR)) DEALLOCATE(RGPPRS_HR)
    IF (ALLOCATED(RGPPRS_LR)) DEALLOCATE(RGPPRS_LR)
  ENDIF
  IF(.NOT.LECMWF) THEN

!*    3.3   SAVE ARPEGE LOW RES ANALYSIS

    ALLOCATE(ZAPA3(NFLSUR,NSPEC2,NS3D))
    ALLOCATE(ZAPA2(NSPEC2,NS2D))
    ALLOCATE(ZAGFL(NPROMA,NFLEVG,YGFL%NDIM0,NGPBLKS))

    ZAPA3(:,:,:)=SPA3(:,:,:)
    IF (NPSP == 1) ZAPA2(:,:)=SPA2(:,:)

    DO JGFL=1,YGFL%NUMFLDS
      IF(YGFLC(JGFL)%LGP) THEN
        ZAGFL(1:NPROMA,1:NFLEVG,YGFLC(JGFL)%MP,1:NGPBLKS)=&
         & GFL(1:NPROMA,1:NFLEVG,YGFLC(JGFL)%MP,1:NGPBLKS)
      ENDIF
    ENDDO

!*    3.4   READ ARPEGE LOW RES BACKROUND

    CALL SUINIF(6)

!*    3.5   COMPUTE LOW RES INCREMENT

    SPA3(:,:,:) = ZAPA3(:,:,:) - SPA3(:,:,:)
    IF (NPSP == 1) SPA2(:,:) = ZAPA2(:,:) - SPA2(:,:)
    
    DO JGFL=1,YGFL%NUMFLDS
        IF(YGFLC(JGFL)%MP == YQ%MP .OR. YGFLC(JGFL)%MP == YO3%MP &
   &  .OR. YGFLC(JGFL)%MP == YL%MP .OR. YGFLC(JGFL)%MP == YI%MP  &
   &  .OR. YGFLC(JGFL)%MP == YR%MP .OR. YGFLC(JGFL)%MP == YS%MP) THEN
        IF(YGFLC(JGFL)%LGP) THEN
          GFL(1:NPROMA,1:NFLEVG,YGFLC(JGFL)%MP,1:NGPBLKS)= &
           & ZAGFL(1:NPROMA,1:NFLEVG,YGFLC(JGFL)%MP,1:NGPBLKS)-&
           & GFL(1:NPROMA,1:NFLEVG,YGFLC(JGFL)%MP,1:NGPBLKS)
        ENDIF
      ENDIF
    ENDDO
      
    DEALLOCATE(ZAPA3)
    DEALLOCATE(ZAPA2)
    DEALLOCATE(ZAGFL)
    
  ENDIF

!*    3.6   SPECIAL PRE-PROCESSING OF INCREMENTS

!     3.6.1  Scale down increments near model top before adding to FG-HR  

  IF(LECMWF.AND.NLEV_REDINC > 0 ) THEN
    ILEV0=NPTRLL(MYSETV) - 1
    DO JLEV=1,NFLEVL
      ILEVG=ILEV0+JLEV
      IF(ILEVG <= NLEV_REDINC) THEN
        SPA3(JLEV,:,:)=SPA3(JLEV,:,:)*REDINC(ILEVG)
      ENDIF
    ENDDO
    DO JGFL=1,YGFL%NUMFLDS
      IF(YGFLC(JGFL)%LGP) THEN
        DO JSTGLO=1,NGPTOT,NPROMA
          ICEND=MIN(NPROMA,NGPTOT-JSTGLO+1)
          IBL=(JSTGLO-1)/NPROMA+1
          DO JLEV=1,NLEV_REDINC
            GFL(1:ICEND,JLEV,YGFLC(JGFL)%MP,IBL)= &
             & GFL(1:ICEND,JLEV,YGFLC(JGFL)%MP,IBL)*REDINC(JLEV)
          ENDDO
        ENDDO
      ENDIF
    ENDDO
  ENDIF

!     3.6.2 Zero GEMS ozone (GO3) increments in the top 5 model levels

  DO JGFL=1,YGFL%NUMFLDS
    IF(YGFLC(JGFL)%LGP .AND. YGFLC(JGFL)%IGRBCODE == 210203) THEN
      DO JSTGLO=1,NGPTOT,NPROMA
        ICEND=MIN(NPROMA,NGPTOT-JSTGLO+1)
        IBL=(JSTGLO-1)/NPROMA+1
        GFL(1:ICEND,1:5,YGFLC(JGFL)%MP,IBL)= 0.0_JPRB
      ENDDO
    ENDIF
  ENDDO

!     3.6.3 Save increments in total aerosol mixing ratio to a specific array
!           Optionally zero out total aerosol increments above ZLATAERO

  LLAER_ZERO_INC = .FALSE. ! Set to true to zero out increments above ZLATAERO
  ZLATAERO= 60._JPRB*RPI/180._JPRB ! 60 degrees
  ZTAERINC(:,:,:) = 0.0_JPRB
  DO JGFL=1,YGFL%NUMFLDS
    IF(YGFLC(JGFL)%LGP .AND. YGFLC(JGFL)%IGRBCODE == NGRBAERLG) THEN
      DO JSTGLO=1,NGPTOT,NPROMA
        ICEND=MIN(NPROMA,NGPTOT-JSTGLO+1)
        IBL=(JSTGLO-1)/NPROMA+1
        IF(LLAER_ZERO_INC) THEN
          DO JL=1,ICEND
            JLAT=JSTGLO - 1 + JL
            IF(ABS(GELAT(JLAT)) > ZLATAERO) THEN
             GFL(JL,1:NFLEVG,YGFLC(JGFL)%MP,IBL) = 0.0_JPRB
            ENDIF
          ENDDO
        ENDIF
        ZTAERINC(1:ICEND,1:NFLEVG,IBL)= &
           & GFL(1:ICEND,1:NFLEVG,YGFLC(JGFL)%MP,IBL)
      ENDDO
    ENDIF
  ENDDO

!*    3.7   NORMS

  WRITE(NULOUT,*) ' RDFPINC: NORMS OF LOW-RES INC'
  CALL SPNORM(0)
  DO JGFL=1,YGFL%NUMFLDS
    IF(YGFLC(JGFL)%LGP.AND.(YGFLC(JGFL)%NREQIN==1)) THEN
      CALL GPNORM3 (GFL,YGFL%NDIM,JGFL,YGFLC(JGFL)%CNAME)
    ENDIF
  ENDDO

!*    4.    ADD LOW RES INCR AND HIGH RES FG
!           --------------------------------


!*    4.1   Add INC-LR to FG-HR
!*          For humidity, use nonlinear inversion of the
!*          control variable

  SPA3(:,:,:) = SPA3(:,:,:) + ZPA35(:,:,:)
  IF (NPSP == 1) SPA2(:,:) = SPA2(:,:) + ZPA25(:,:)

  DO JGFL=1,YGFL%NUMFLDS
    IF(YGFLC(JGFL)%LGP) THEN
      IF(YGFLC(JGFL)%NREQIN==1) THEN
        DO JSTGLO=1,NGPTOT,NPROMA
          ICEND=MIN(NPROMA,NGPTOT-JSTGLO+1)
          IBL=(JSTGLO-1)/NPROMA+1
          GFL(1:ICEND,1:NFLEVG,YGFLC(JGFL)%MP,IBL) =  &
             &    GFL(1:ICEND,1:NFLEVG,YGFLC(JGFL)%MP,IBL)&
             & +ZGFL5(1:ICEND,1:NFLEVG,YGFLC(JGFL)%MP,IBL)
          IF(YGFLC(JGFL)%IGRBCODE == NGRBAERLG) THEN
            GFL(1:ICEND,1:NFLEVG,YGFLC(JGFL)%MP,IBL) = &
               & MAX(0.0_JPRB, GFL(1:ICEND,1:NFLEVG,YGFLC(JGFL)%MP,IBL))
          ENDIF
          IF(ANY(YGFLC(JGFL)%IGRBCODE == NGRBGRG(:))) THEN
            GFL(1:ICEND,1:NFLEVG,YGFLC(JGFL)%MP,IBL) = &
               & MAX(1.E-14_JPRB, GFL(1:ICEND,1:NFLEVG,YGFLC(JGFL)%MP,IBL))
          ENDIF
        ENDDO
      ELSE
        DO JSTGLO=1,NGPTOT,NPROMA
          ICEND=MIN(NPROMA,NGPTOT-JSTGLO+1)
          IBL=(JSTGLO-1)/NPROMA+1
          GFL(1:ICEND,1:NFLEVG,YGFLC(JGFL)%MP,IBL)= &
             & ZGFL5(1:ICEND,1:NFLEVG,YGFLC(JGFL)%MP,IBL)
        ENDDO
      ENDIF
    ENDIF
  ENDDO

!*    4.2   SPECIAL POST-PROCESSING OF ANALYSIS

!     4.2.1 Redistribute increments in total aerosol mixing ratio into increment
!           in aerosol mixing ratio according to ZAEROFR saved earlier.

  DO JGFL=1,YGFL%NUMFLDS
    DO JAER=1,NACTAERO
      IF(YGFLC(JGFL)%LGP .AND. YGFLC(JGFL)%IGRBCODE == IGRBAER(JAER)) THEN
        DO JSTGLO=1,NGPTOT,NPROMA
          ICEND=MIN(NPROMA,NGPTOT-JSTGLO+1)
          IBL=(JSTGLO-1)/NPROMA+1
          GFL(1:ICEND,1:NFLEVG,YGFLC(JGFL)%MP,IBL) = &
            &      GFL(1:ICEND,1:NFLEVG,YGFLC(JGFL)%MP,IBL) &
            & +ZAEROFR(1:ICEND,1:NFLEVG,JAER,IBL)*ZTAERINC(1:ICEND,1:NFLEVG,IBL)
          GFL(1:ICEND,1:NFLEVG,YGFLC(JGFL)%MP,IBL) = &
            & MAX(0.0_JPRB, GFL(1:ICEND,1:NFLEVG,YGFLC(JGFL)%MP,IBL))
        ENDDO
      ENDIF
    ENDDO
  ENDDO

!     4.2.2 Nonlinear inverse transform of humidity (and optionally ozone)

  IF (YQ%LGP) THEN
    IF (LJB_NONLINEAR_CVHUM .OR. LJB_NONLINEAR_CVO3) THEN
      WRITE(NULOUT,*) ' RDFPINC: NORMS BEFORE NONLINEAR CVHUM/O3'
      CALL SPNORM(0)
      CALL GPNORM_GFL
      IF (.NOT. LECMWF) THEN
!       MF need to provide HR BG here, for now use FG
        ZPA37(:,:,MSPTR_T)=ZPA35(:,:,MSPTR_T)
        ZPA27(:, MSPTR_SP)=ZPA25(:, MSPTR_SP)
        ZGFL7(:,:,:,:)=ZGFL5(:,:,:,:)
      ENDIF
      CALL SYMTRANSIN(ZPA35(1,1,MSPTR_T),ZGFL5,ZPA25(1,MSPTR_SP),&
                     &ZPA37(1,1,MSPTR_T),ZGFL7,ZPA27(1,MSPTR_SP))
    ENDIF
  ENDIF

!*    4.3   End of LR-INC read. Re-set temporary switches.

  IF (.NOT. LCONDWT .OR. .NOT. LCANARI .OR. L3DFGAT) THEN
    DO JGFL=1,YGFL%NUMFLDS
      IF(YGFLC(JGFL)%LGP) THEN
        YGFLC(JGFL)%NREQIN=INREQIN(JGFL)
      ENDIF
    ENDDO
  ENDIF
  LREASUR=LLREASUR

ENDIF   ! NUPTRA

!     ------------------------------------------------------------------
!*    5.    Adjust Grid-Point specific humidity if LGPQ
!*          otherwise spectral Q.
!           -------------------------------------------

IF (.NOT. LJB_NONLINEAR_CVHUM) THEN
  IF (YQ%LGP) THEN
    CALL SUGPQLIM
  ELSE

  !*    5.1   OVERWRITE ZSQREF BY THE HUMIDITY INCREMENT AT LEVEL I.
  !*          ZSQREF CONTAINS NOW THE CORRECTION TERM
  !*          ZSTREF CONTAINS THE REFERENCE LEVEL TEMPERATURE

    IF (LLCOR) THEN
      ALLOCATE(ZSTREF(NSPEC2))
      ALLOCATE(ZSQREF(NSPEC2))
  
      ALLOCATE(ZSPGP0(NGPTOT))
      ALLOCATE(ZDTREF(NGPTOT))
      ALLOCATE(ZDQREF(NGPTOT))

      ZSTREF(:)=SPT(ILEVI+1,:)
      ZSQREF(:)=SPQ(ILEVI+1,:)-ZSQOLD(ILEVI+1,:)

    IF (LELAM) THEN
      CALL ESPEREE(1,1,SPSP,ZSPGP0)
      CALL ESPEREE(1,1,ZSTREF,ZDTREF)
      CALL ESPEREE(1,1,ZSQREF,ZDQREF)
    ELSE
      CALL SPEREE(1,1,SPSP,ZSPGP0)
      CALL SPEREE(1,1,ZSTREF,ZDTREF)
      CALL SPEREE(1,1,ZSQREF,ZDQREF)
    ENDIF

      DEALLOCATE(ZSQREF)
      DEALLOCATE(ZSTREF)
      ALLOCATE(ZFQDAT(NSPEC2))
      ALLOCATE(ZZSQOLD(NSPEC2))
      ALLOCATE(ZTMIN(NGPTOT))

  !* ATTENTION la boucle doit etre dans ce sens !!!
      DO JLEV=NFLEVG,1,-1
        ZFTDAT(:)=SPT(JLEV,:)
        ZFQDAT(:)=SPQ(JLEV,:)
        JJLEV = MIN(JLEV, ILEVI+1)
        ZZSQOLD(:)=ZSQOLD(JJLEV,:)

  !*    5.2   Modify spectral q so that RH is between 0 and 1 (+ smoothing above 375).
        
        IF (.NOT. LELAM) THEN
        CALL SUSPQLIM(ZFTDAT,ZFQDAT,ZSPGP0,ZDQREF,&
         & ZDTREF,ZZSQOLD,JLEV,ILEVI,ZTMIN)  
        SPQ(JLEV,:)=ZFQDAT(:)
        ENDIF
      ENDDO

      DEALLOCATE(ZFQDAT)
      DEALLOCATE(ZSPGP0)
      DEALLOCATE(ZDQREF)
      DEALLOCATE(ZDTREF)
      DEALLOCATE(ZZSQOLD)
      DEALLOCATE(ZSQOLD)
      DEALLOCATE(ZTMIN)
    ENDIF
  ENDIF
ENDIF

!*    5.3   Convert to RT from T, if necessary.

LSPRT = LLSPRT
IF (LSPRT) THEN
  CALL SPECRT(0)
ENDIF

!     ------------------------------------------------------------------
!*    6.    Finished
!           --------

WRITE(NULOUT,*) ' RDFPINC: NORMS OF HIGH-RES AN'
CALL SPNORM(0)
CALL GPNORM_GFL

!     ------------------------------------------------------------------
IF (LHOOK) CALL DR_HOOK('RDFPINC',1,ZHOOK_HANDLE)
END SUBROUTINE RDFPINC
