Skip to content
Snippets Groups Projects
ini_lb.f90 53.3 KiB
Newer Older
!MNH_LIC Copyright 1994-2014 CNRS, Meteo-France and Universite Paul Sabatier
!MNH_LIC This is part of the Meso-NH software governed by the CeCILL-C licence
!MNH_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt  
!MNH_LIC for details. version 1.
!     ######################
      MODULE MODI_INI_LB
!     ######################
!
INTERFACE 
!
     KSIZELBX_ll,KSIZELBXU_ll,KSIZELBY_ll,KSIZELBYV_ll,                     &
     KSIZELBXTKE_ll,KSIZELBYTKE_ll,                                         &
     KSIZELBXR_ll,KSIZELBYR_ll,KSIZELBXSV_ll,KSIZELBYSV_ll,                 &
     HGETTKEM,HGETRVM,HGETRCM,HGETRRM,HGETRIM,HGETRSM,                      &
     HGETRGM,HGETRHM,HGETSVM,                                               &
     PLBXUM,PLBXVM,PLBXWM,PLBXTHM,PLBXTKEM,PLBXRM,PLBXSVM,                  &
     PLBYUM,PLBYVM,PLBYWM,PLBYTHM,PLBYTKEM,PLBYRM,PLBYSVM,                  &
     PLBXUMM,PLBXVMM,PLBXWMM,PLBXTHMM,PLBXTKEMM,PLBXRMM,PLBXSVMM,           &
     PLBYUMM,PLBYVMM,PLBYWMM,PLBYTHMM,PLBYTKEMM,PLBYRMM,PLBYSVMM,           &
     PLENG )
!
USE MODD_IO_ll, ONLY: TFILEDATA
!
TYPE(TFILEDATA),       INTENT(IN)   :: TPINIFILE ! Initial file
CHARACTER (LEN=*),     INTENT(IN)   :: HLUOUT    ! name for output-listing of nested models
LOGICAL,               INTENT(IN)   :: OLSOURCE  ! switch for the source term
! Larger Scale fields (source if OLSOURCE=T,  fields at time t-dt if OLSOURCE=F) :
INTEGER,               INTENT(IN)   :: KSV       ! number of passive variables
! sizes of the West-east total LB area
INTEGER, INTENT(IN) :: KSIZELBX_ll,KSIZELBXU_ll      ! for T,V,W and u 
INTEGER, INTENT(IN) :: KSIZELBXTKE_ll                ! for TKE 
INTEGER, INTENT(IN) :: KSIZELBXR_ll,KSIZELBXSV_ll    ! for Rx and SV    
! sizes of the North-south total LB area
INTEGER, INTENT(IN) :: KSIZELBY_ll,KSIZELBYV_ll      ! for T,U,W  and v
INTEGER, INTENT(IN) :: KSIZELBYTKE_ll                ! for TKE
INTEGER, INTENT(IN) :: KSIZELBYR_ll,KSIZELBYSV_ll    ! for Rx and SV
! Get indicators
CHARACTER (LEN=*),         INTENT(IN)  :: HGETTKEM,                          &
                                          HGETRVM,HGETRCM,HGETRRM,           &
                                          HGETRIM,HGETRSM,HGETRGM,HGETRHM
CHARACTER (LEN=*), DIMENSION(:),INTENT(IN)  :: HGETSVM
! LB  fields (source if OLSOURCE=T,  fields at time t-dt if OLSOURCE=F) :
REAL, DIMENSION(:,:,:),          INTENT(OUT) :: PLBXUM,PLBXVM,PLBXWM ! Wind
REAL, DIMENSION(:,:,:),          INTENT(OUT) :: PLBXTHM              ! Mass
REAL, DIMENSION(:,:,:),          INTENT(OUT) :: PLBYUM,PLBYVM,PLBYWM ! Wind
REAL, DIMENSION(:,:,:),          INTENT(OUT) :: PLBYTHM              ! Mass
REAL, DIMENSION(:,:,:),          INTENT(OUT) :: PLBXTKEM          ! TKE
REAL, DIMENSION(:,:,:),          INTENT(OUT) :: PLBYTKEM
REAL, DIMENSION(:,:,:,:),        INTENT(OUT) :: PLBXRM  ,PLBXSVM  ! Moisture and SV
REAL, DIMENSION(:,:,:,:),        INTENT(OUT) :: PLBYRM  ,PLBYSVM  ! in x and y-dir.
! LB arrays at time t-dt (if OLSOURCE=T) : 
REAL, DIMENSION(:,:,:), INTENT(IN), OPTIONAL  :: PLBXUMM,PLBXVMM,PLBXWMM ! Wind
REAL, DIMENSION(:,:,:),INTENT(IN), OPTIONAL  :: PLBXTHMM              ! Mass
REAL, DIMENSION(:,:,:),INTENT(IN), OPTIONAL  :: PLBYUMM,PLBYVMM,PLBYWMM ! Wind
REAL, DIMENSION(:,:,:),INTENT(IN), OPTIONAL  :: PLBYTHMM              ! Mass
REAL, DIMENSION(:,:,:),INTENT(IN), OPTIONAL  :: PLBXTKEMM           ! TKE
REAL, DIMENSION(:,:,:),INTENT(IN), OPTIONAL  :: PLBYTKEMM
REAL, DIMENSION(:,:,:,:),INTENT(IN), OPTIONAL  :: PLBXRMM  ,PLBXSVMM  ! Moisture and SV
REAL, DIMENSION(:,:,:,:),INTENT(IN), OPTIONAL  :: PLBYRMM  ,PLBYSVMM  ! in x and y-dir.
REAL,                  INTENT(IN),   OPTIONAL :: PLENG    ! Interpolation length
!
END SUBROUTINE INI_LB
!
END INTERFACE
!
END MODULE MODI_INI_LB
!     ############################################################
     KSIZELBX_ll,KSIZELBXU_ll,KSIZELBY_ll,KSIZELBYV_ll,            &
     KSIZELBXTKE_ll,KSIZELBYTKE_ll,                                &
     KSIZELBXR_ll,KSIZELBYR_ll,KSIZELBXSV_ll,KSIZELBYSV_ll,        &
     HGETTKEM,HGETRVM,HGETRCM,HGETRRM,HGETRIM,HGETRSM,             &
     HGETRGM,HGETRHM,HGETSVM,                                      &
     PLBXUM,PLBXVM,PLBXWM,PLBXTHM,PLBXTKEM,PLBXRM,PLBXSVM,         &
     PLBYUM,PLBYVM,PLBYWM,PLBYTHM,PLBYTKEM,PLBYRM,PLBYSVM,         &
     PLBXUMM,PLBXVMM,PLBXWMM,PLBXTHMM,PLBXTKEMM,PLBXRMM,PLBXSVMM,  &
     PLBYUMM,PLBYVMM,PLBYWMM,PLBYTHMM,PLBYTKEMM,PLBYRMM,PLBYSVMM,  &
     PLENG )
!     ############################################################
!
!!****  *INI_LB* - routine to initialize  LB fields
!!
!!    PURPOSE
!!    -------
!       The purpose of this routine is to read the LB fields and to distribute
! on subdomain which have a non-nul intersection with the LB areas.
!       In case of OLSOURCE=T, it initializes the LB sources instead of the
!   LB fields at time t-dt
!
!!**  METHOD
!!    ------
!!    The LB fields are read in file and distributed by FMREAD_LB
!!
!!    In case of OLSOURCE=T (INI_LB called by INI_CPL or LS_COUPLING), the LB sources
!!   are computed
!!     
!!
!!    EXTERNAL
!!    --------
!!      FMLOOK    : to retrieve logical number 
!!      FMREAD    : to read data in LFIFM file
!!      FMREAD_LB : to read LB data in LFIFM file
!!
!!    IMPLICIT ARGUMENTS
!!    ------------------ 
!!      Module MODD_CONF   : NVERB
!!
!!    REFERENCE
!!    ---------
!!      Book2 of the documentation (routine INI_LB)
!!      
!!
!!    AUTHOR
!!    ------
!!  	V. Ducrocq       * Meteo France *
!!      D. Gazen         L.A. 
!!
!!    MODIFICATIONS
!!    -------------
!!      Original        22/09/98    FMREAD_LB handle LBs fields
!!      J. Stein        18/09/99    problem with the dry case
!!      D. Gazen        22/01/01    treat NSV_* with floating indices
!!      F Gheusi        29/10/03    bug in LB sources for NSV
!!      J.-P. Pinty     06/05/04    treat NSV_* for C1R3 and ELEC
!!                      20/05/06    Remove KEPS
!!      C.Lac           20/03/08    Add passive pollutants
!!      M.Leriche       16/07/10    Add ice phase chemical species
!!      Pialat/tulet    15/02/12    Add ForeFire scalars 
!!      J.Escobar : 15/09/2015 : WENO5 & JPHEXT <> 1 
!!      M.Leriche       09/02/16    Treat gas and aq. chemicals separately
!!      J.Escobar : 27/04/2016 : bug , test only on ANY(HGETSVM({{1:KSV}})=='READ'
Gaelle TANGUY's avatar
Gaelle TANGUY committed
!!      J.-P. Pinty     09/02/16    Add LIMA that is LBC for CCN and IFN
!!      M.Leriche       09/02/16    Treat gas and aq. chemicals separately
!-------------------------------------------------------------------------------
!
!*       0.    DECLARATIONS
!

USE MODD_NSV
USE MODD_CONF
USE MODD_CTURB
USE MODD_DUST
USE MODD_SALT
USE MODD_CH_AEROSOL
Gaelle TANGUY's avatar
Gaelle TANGUY committed
USE MODD_PARAM_LIMA
USE MODD_PARAM_n
USE MODE_FIELD,           ONLY: TFIELDDATA,TYPELOG,TYPEREAL
USE MODE_FM
USE MODE_FMREAD
!
USE MODD_RAIN_C2R2_DESCR, ONLY: C2R2NAMES
USE MODD_ICE_C1R3_DESCR,  ONLY: C1R3NAMES
USE MODD_CH_M9_n,         ONLY: CNAMES, CICNAMES
USE MODD_LG,              ONLY: CLGNAMES
USE MODD_ELEC_DESCR,      ONLY: CELECNAMES
USE MODD_PARAMETERS,      ONLY: JPHEXT
Gaelle TANGUY's avatar
Gaelle TANGUY committed
USE MODD_PARAM_LIMA_WARM, ONLY: CLIMA_WARM_NAMES
USE MODD_PARAM_LIMA_COLD, ONLY: CLIMA_COLD_NAMES
IMPLICIT NONE
!
!*       0.1   declarations of arguments
!
!
!
TYPE(TFILEDATA),       INTENT(IN)   :: TPINIFILE ! Initial file
CHARACTER (LEN=*),     INTENT(IN)   :: HLUOUT    ! name for output-listing of nested models
LOGICAL,               INTENT(IN)   :: OLSOURCE  ! switch for the source term
! Larger Scale fields (source if OLSOURCE=T,  fields at time t-dt if OLSOURCE=F) :
INTEGER,               INTENT(IN)   :: KSV       ! number of passive variables
! sizes of the West-east total LB area
INTEGER, INTENT(IN) :: KSIZELBX_ll,KSIZELBXU_ll      ! for T,V,W and u 
INTEGER, INTENT(IN) :: KSIZELBXTKE_ll                !  for TKE 
INTEGER, INTENT(IN) :: KSIZELBXR_ll,KSIZELBXSV_ll    ! for Rx and SV    
! sizes of the North-south total LB area
INTEGER, INTENT(IN) :: KSIZELBY_ll,KSIZELBYV_ll      ! for T,U,W  and v
INTEGER, INTENT(IN) :: KSIZELBYTKE_ll                ! for TKE 
INTEGER, INTENT(IN) :: KSIZELBYR_ll,KSIZELBYSV_ll    ! for Rx and SV
! Get indicators
CHARACTER (LEN=*),         INTENT(IN)  :: HGETTKEM,                          &
                                          HGETRVM,HGETRCM,HGETRRM,           &
                                          HGETRIM,HGETRSM,HGETRGM,HGETRHM
CHARACTER (LEN=*), DIMENSION(:),INTENT(IN)  :: HGETSVM
! LB  fields (source if OLSOURCE=T,  fields at time t-dt if OLSOURCE=F) :
REAL, DIMENSION(:,:,:),          INTENT(OUT) :: PLBXUM,PLBXVM,PLBXWM ! Wind
REAL, DIMENSION(:,:,:),          INTENT(OUT) :: PLBXTHM              ! Mass
REAL, DIMENSION(:,:,:),          INTENT(OUT) :: PLBYUM,PLBYVM,PLBYWM ! Wind
REAL, DIMENSION(:,:,:),          INTENT(OUT) :: PLBYTHM              ! Mass
REAL, DIMENSION(:,:,:),          INTENT(OUT) :: PLBXTKEM          ! TKE
REAL, DIMENSION(:,:,:),          INTENT(OUT) :: PLBYTKEM          ! 
REAL, DIMENSION(:,:,:,:),        INTENT(OUT) :: PLBXRM  ,PLBXSVM  ! Moisture and SV
REAL, DIMENSION(:,:,:,:),        INTENT(OUT) :: PLBYRM  ,PLBYSVM  ! in x and y-dir.
! LB arrays at time t-dt (if OLSOURCE=T) : 
REAL, DIMENSION(:,:,:), INTENT(IN), OPTIONAL  :: PLBXUMM,PLBXVMM,PLBXWMM ! Wind
REAL, DIMENSION(:,:,:),INTENT(IN), OPTIONAL  :: PLBXTHMM              ! Mass
REAL, DIMENSION(:,:,:),INTENT(IN), OPTIONAL  :: PLBYUMM,PLBYVMM,PLBYWMM ! Wind
REAL, DIMENSION(:,:,:),INTENT(IN), OPTIONAL  :: PLBYTHMM              ! Mass
REAL, DIMENSION(:,:,:),INTENT(IN), OPTIONAL  :: PLBXTKEMM           ! TKE
REAL, DIMENSION(:,:,:),INTENT(IN), OPTIONAL  :: PLBYTKEMM
REAL, DIMENSION(:,:,:,:),INTENT(IN), OPTIONAL  :: PLBXRMM  ,PLBXSVMM  ! Moisture and SV
REAL, DIMENSION(:,:,:,:),INTENT(IN), OPTIONAL  :: PLBYRMM  ,PLBYSVMM  ! in x and y-dir.
REAL,                  INTENT(IN),   OPTIONAL :: PLENG    ! Interpolation length
!
!
!*       0.2   declarations of local variables
!
INTEGER             :: ILBSIZEX,ILBSIZEY   ! depth  of the LB area in the RIM direction 
                                           !  written in FM file
INTEGER       :: IL3DX,IL3DY ! Size of the LB arrays in FM file
                             ! in  the RIM direction
INTEGER       :: IL3DXU,IL3DYV  ! Size of the LB arrays in FM file
                                ! in  the RIM direction for the normal wind
INTEGER             :: IRIMX,IRIMY ! Total size of the LB area (for the RIM direction)
INTEGER             :: IRIMXU,IRIMYV ! Total size of the LB area (for the RIM direction)
                                     ! for the normal wind (spatial gradient needed)

INTEGER             :: JSV,JRR                    ! Loop index for MOIST AND 
                                                  !  additional scalar variables 
INTEGER             :: IRR                        !  counter for moist variables
INTEGER             :: IGRID,ILENCH,IRESP  !   File 
CHARACTER (LEN=16)  :: YRECFM              ! management
CHARACTER (LEN=100) :: YCOMMENT            ! variables  
CHARACTER (LEN=2)   :: YDIR
CHARACTER (LEN=4)   :: YDIRLB
INTEGER                :: ILUOUT   !  Logical unit number associated with HLUOUT
LOGICAL :: GHORELAX_UVWTH  ! switch for the horizontal relaxation for U,V,W,TH in the FM file 
LOGICAL :: GHORELAX_TKE    ! switch for the horizontal relaxation for tke in the FM file
LOGICAL :: GHORELAX_R, GHORELAX_SV ! switch for the horizontal relaxation 
                                   ! for moist and scalar variables
CHARACTER (LEN= LEN(HGETRVM)), DIMENSION (7) :: YGETRXM ! Arrays with  the get indicators 
                                                        !  for the moist variables
CHARACTER (LEN=1), DIMENSION (7) :: YC    ! array with the prefix of the moist variables
INTEGER :: IMASDEV                                                      
Gaelle TANGUY's avatar
Gaelle TANGUY committed
CHARACTER(LEN=2)  :: INDICE ! to index CCN and IFN fields of LIMA scheme
TYPE(TFIELDDATA)  :: TZFIELD
!-------------------------------------------------------------------------------
!
!
!*       0.    READ CPL_AROME to know which LB_fileds there are to read
!              --------------------
IF (IMASDEV > 48) THEN
ELSE
  LCPL_AROME=.FALSE.
ENDIF
!
!
!*       1.    SOME INITIALIZATIONS
!              --------------------
!
CALL FMLOOK_ll(HLUOUT,HLUOUT,ILUOUT,IRESP)
!
!
!-------------------------------------------------------------------------------
!
!*       2.    READ 2D "surfacic" LB fields 
!              ----------------------------
!
!*       2.1   read the number of available points for the horizontal relaxation
! for basic variables 
CALL IO_READ_FIELD(TPINIFILE,'RIMX',ILBSIZEX)
CALL IO_READ_FIELD(TPINIFILE,'RIMY',ILBSIZEY)
!
!*        2.2 Basic variables
! 
CALL IO_READ_FIELD(TPINIFILE,'HORELAX_UVWTH',GHORELAX_UVWTH)
                                !
IF (GHORELAX_UVWTH) THEN 
  IRIMX =(KSIZELBX_ll-2*JPHEXT)/2   
  IRIMXU=(KSIZELBXU_ll-2*JPHEXT)/2  
  IRIMY =(KSIZELBY_ll-2*JPHEXT)/2
  IRIMYV=(KSIZELBYV_ll-2*JPHEXT)/2
  IL3DX=2*ILBSIZEX+2*JPHEXT
  IL3DXU=IL3DX
  IL3DY=2*ILBSIZEY+2*JPHEXT
  IL3DYV=IL3DY
ELSE
  IRIMX=0
  IRIMXU=1
  IRIMY=0
  IRIMYV=1
  IL3DX=2*JPHEXT ! 2
  IL3DY=2*JPHEXT ! 2
  IL3DXU=2 + 2*JPHEXT ! 4 
  IL3DYV=2 + 2*JPHEXT ! 4 
ENDIF
!
IF (KSIZELBXU_ll/= 0) THEN
  CALL IO_READ_FIELD_LB(TPINIFILE,'LBXUM',IL3DXU,IRIMXU,PLBXUM)
END IF

IF ( KSIZELBX_ll /= 0) THEN
  CALL IO_READ_FIELD_LB(TPINIFILE,'LBXVM',IL3DX,IRIMX,PLBXVM)
IF ( KSIZELBX_ll /= 0) THEN
  CALL IO_READ_FIELD_LB(TPINIFILE,'LBXWM',IL3DX,IRIMX,PLBXWM)
IF ( KSIZELBY_ll /= 0) THEN
  CALL IO_READ_FIELD_LB(TPINIFILE,'LBYUM',IL3DY,IRIMY,PLBYUM)
END IF

IF ( KSIZELBYV_ll  /= 0) THEN
  CALL IO_READ_FIELD_LB(TPINIFILE,'LBYVM',IL3DYV,IRIMYV,PLBYVM)
END IF

IF (KSIZELBY_ll /= 0) THEN
  CALL IO_READ_FIELD_LB(TPINIFILE,'LBYWM',IL3DY,IRIMY,PLBYWM)
END IF

IF (KSIZELBX_ll /= 0) THEN
  CALL IO_READ_FIELD_LB(TPINIFILE,'LBXTHM',IL3DX,IRIMX,PLBXTHM)
END IF

IF ( KSIZELBY_ll /= 0) THEN
  CALL IO_READ_FIELD_LB(TPINIFILE,'LBYTHM',IL3DY,IRIMY,PLBYTHM)
END IF
!
!*        2.3  LB-TKE
!
SELECT CASE(HGETTKEM)                 
CASE('READ') 
  IF (.NOT. LCPL_AROME .AND. OLSOURCE) THEN
    IF (PRESENT(PLBXTKEMM).AND.PRESENT(PLBYTKEMM)) THEN
      WRITE ( ILUOUT,*) 'LBXTKES AND LBYTKES WILL BE INITIALIZED TO 0'
      PLBXTKEM(:,:,:) = PLBXTKEMM(:,:,:)    
      PLBYTKEM(:,:,:) = PLBYTKEMM(:,:,:)
    ELSE
      WRITE ( ILUOUT,*) 'PB TO INITIALIZE LBXTKES AND LBYTKES  '
!callabortstop
      CALL CLOSE_ll(HLUOUT,IOSTAT=IRESP)
      CALL ABORT
      STOP
    ENDIF
  ELSE
    YRECFM = 'HORELAX_TKE'
    YDIR='--'      
    CALL FMREAD(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIR,GHORELAX_TKE,IGRID,ILENCH,YCOMMENT,IRESP)        
    IF (GHORELAX_TKE) THEN 
      IRIMX=(KSIZELBXTKE_ll-2*JPHEXT)/2   
      IRIMY=(KSIZELBYTKE_ll-2*JPHEXT)/2
      IL3DX=2*ILBSIZEX+2*JPHEXT
      IL3DY=2*ILBSIZEY+2*JPHEXT
    ELSE
      IRIMX=0
      IRIMY=0
      IL3DX=2*JPHEXT ! 2
      IL3DY=2*JPHEXT ! 2
    ENDIF
!
    YRECFM='LBXTKEM'
    IF (KSIZELBXTKE_ll /= 0) THEN  
      YDIRLB='LBX'
      CALL FMREAD_LB(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIRLB,PLBXTKEM,IRIMX,IL3DX,IGRID,&
           & ILENCH,YCOMMENT,IRESP)
    END IF
!
    YRECFM='LBYTKEM'
    IF (KSIZELBYTKE_ll /= 0) THEN  
      YDIRLB='LBY'
      CALL FMREAD_LB(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIRLB,PLBYTKEM,IRIMY,IL3DY,IGRID,&
           & ILENCH,YCOMMENT,IRESP)
    END IF
  ENDIF
CASE('INIT')
  IF (SIZE(PLBXTKEM,1) /= 0) PLBXTKEM(:,:,:) = XTKEMIN
  IF (SIZE(PLBYTKEM,1) /= 0) PLBYTKEM(:,:,:) = XTKEMIN
END SELECT
!
! 
!*        2.5 LB-Rx
!
IF(KSIZELBXR_ll  > 0 ) THEN
  TZFIELD%CMNHNAME   = 'HORELAX_R'
  TZFIELD%CSTDNAME   = ''
  TZFIELD%CLONGNAME  = 'MesoNH: HORELAX_R'
  TZFIELD%CUNITS     = ''
  TZFIELD%CDIR       = '--'
  TZFIELD%CCOMMENT   = 'Switch to activate the HOrizontal RELAXation'
  TZFIELD%CLBTYPE    = 'NONE'
  TZFIELD%NGRID      = 1
  TZFIELD%NTYPE      = TYPELOG
  TZFIELD%NDIMS      = 0
  !
  CALL IO_READ_FIELD(TPINIFILE,TZFIELD,GHORELAX_R)
  !
  YGETRXM(:)=(/HGETRVM,HGETRCM,HGETRRM,HGETRIM,HGETRSM,HGETRGM,HGETRHM/)
  YC(:)=(/"V","C","R","I","S","G","H"/)
  IF (GHORELAX_R) THEN 
    IRIMX=(KSIZELBXR_ll-2*JPHEXT)/2  
    IRIMY= (KSIZELBYR_ll-2*JPHEXT)/2  
    IL3DX=2*ILBSIZEX+2*JPHEXT
    IL3DY=2*ILBSIZEY+2*JPHEXT
  ELSE
    IRIMX=0
    IRIMY=0
    IL3DX=2*JPHEXT ! 2
    IL3DY=2*JPHEXT ! 2
  !
  TZFIELD%CSTDNAME   = ''
  TZFIELD%CUNITS     = 'kg kg-1'
  TZFIELD%CDIR       = 'XY'
  TZFIELD%NGRID      = 1
  TZFIELD%NTYPE      = TYPEREAL
  TZFIELD%NDIMS      = 3
  !
  SELECT CASE(YGETRXM(1))                 
    CASE('READ') 
      IRR=IRR+1 
      IF ( KSIZELBXR_ll  /= 0 ) THEN
        TZFIELD%CMNHNAME   = 'LBXR'//YC(JRR)//'M'
        TZFIELD%CLONGNAME  = 'MesoNH: LBXR'//YC(JRR)//'M'
        TZFIELD%CLBTYPE    = 'LBX'
        TZFIELD%CCOMMENT   = '2_Y_Z_LBXR'//YC(JRR)//'M'
        CALL IO_READ_FIELD_LB(TPINIFILE,TZFIELD,IL3DX,IRIMX,PLBXRM(:,:,:,IRR))
      END IF
      !
      IF ( KSIZELBYR_ll /= 0 ) THEN
        TZFIELD%CMNHNAME   = 'LBYR'//YC(JRR)//'M'
        TZFIELD%CLONGNAME  = 'MesoNH: LBYR'//YC(JRR)//'M'
        TZFIELD%CLBTYPE    = 'LBY'
        TZFIELD%CCOMMENT   = '2_Y_Z_LBYR'//YC(JRR)//'M'
        CALL IO_READ_FIELD_LB(TPINIFILE,TZFIELD,IL3DY,IRIMY,PLBYRM(:,:,:,IRR))
      END IF
    CASE('INIT')
      IRR=IRR+1 
      IF ( SIZE(PLBXRM,1) /= 0 )  PLBXRM(:,:,:,IRR) = 0.
      IF ( SIZE(PLBYRM,1) /= 0 )  PLBYRM(:,:,:,IRR) = 0.
  END SELECT
    !
    !
  DO JRR=2,7
    SELECT CASE(YGETRXM(JRR))                 
    CASE('READ') 
      IRR=IRR+1 
      IF ( KSIZELBXR_ll  /= 0 ) THEN
        IF (.NOT. LCPL_AROME .AND. OLSOURCE) THEN
            IF (PRESENT(PLBXRMM)) THEN
              PLBXRM(:,:,:,IRR)=PLBXRMM(:,:,:,IRR)
              WRITE(ILUOUT,*) 'PLBXRS  will be initialized to 0 for LBXR'//YC(JRR)//'M'
              WRITE(ILUOUT,*) 'Pb to initialize PLBXRM for LBXR'//YC(JRR)//'M'
              !callabortstop
              CALL CLOSE_ll(HLUOUT,IOSTAT=IRESP)
              CALL ABORT
              STOP
            ENDIF
        ELSE
          TZFIELD%CMNHNAME   = 'LBXR'//YC(JRR)//'M'
          TZFIELD%CLONGNAME  = 'MesoNH: LBXR'//YC(JRR)//'M'
          TZFIELD%CLBTYPE    = 'LBX'
          TZFIELD%CCOMMENT   = '2_Y_Z_LBXR'//YC(JRR)//'M'
          CALL IO_READ_FIELD_LB(TPINIFILE,TZFIELD,IL3DX,IRIMX,PLBXRM(:,:,:,IRR))
        ENDIF
      END IF
      !
      IF ( KSIZELBYR_ll /= 0 ) THEN
        IF (.NOT. LCPL_AROME .AND. OLSOURCE) THEN
            IF (PRESENT(PLBYRMM)) THEN
              PLBYRM(:,:,:,IRR)=PLBYRMM(:,:,:,IRR)
              WRITE(ILUOUT,*) 'PLBYRS  will be initialized to 0 for LBYR'//YC(JRR)//'M'
              WRITE(ILUOUT,*) 'Pb to initialize PLBYRM for LBYR'//YC(JRR)//'M'
              !callabortstop
              CALL CLOSE_ll(HLUOUT,IOSTAT=IRESP)
              CALL ABORT
              STOP
            ENDIF
         ELSE
           TZFIELD%CMNHNAME   = 'LBYR'//YC(JRR)//'M'
           TZFIELD%CLONGNAME  = 'MesoNH: LBYR'//YC(JRR)//'M'
           TZFIELD%CLBTYPE    = 'LBY'
           TZFIELD%CCOMMENT   = '2_Y_Z_LBYR'//YC(JRR)//'M'
           CALL IO_READ_FIELD_LB(TPINIFILE,TZFIELD,IL3DY,IRIMY,PLBYRM(:,:,:,IRR))
         ENDIF
       END IF
    CASE('INIT')
      IRR=IRR+1 
      IF ( SIZE(PLBXRM,1) /= 0 )  PLBXRM(:,:,:,IRR) = 0.
      IF ( SIZE(PLBYRM,1) /= 0 )  PLBYRM(:,:,:,IRR) = 0.
    END SELECT
  END DO
END IF
!
!*        2.6    LB-Scalar Variables
!
IF (KSV > 0) THEN 
  IF (ANY(HGETSVM(1:KSV)=='READ')) THEN
    YRECFM = 'HORELAX_SV'
    YDIR='--'
    CALL FMREAD(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIR,GHORELAX_SV,IGRID,ILENCH,YCOMMENT,IRESP)  
    IF ( GHORELAX_SV ) THEN
      IRIMX=(KSIZELBXSV_ll-2*JPHEXT)/2   
      IRIMY=(KSIZELBYSV_ll-2*JPHEXT)/2
      IL3DX=2*ILBSIZEX+2*JPHEXT
      IL3DY=2*ILBSIZEY+2*JPHEXT
    ELSE
      IRIMX=0
      IRIMY=0
      IL3DX=2*JPHEXT !2
      IL3DY=2*JPHEXT !2
    END IF
  END IF
END IF
! User scalar variables
DO JSV = 1, NSV_USER     
  SELECT CASE(HGETSVM(JSV))
  CASE ('READ')
    IF ( KSIZELBXSV_ll /= 0 ) THEN
      WRITE(YRECFM,'(A6,I3.3)')'LBXSVM',JSV
      YDIRLB='LBX'
      CALL FMREAD_LB(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIRLB,PLBXSVM(:,:,:,JSV),IRIMX,IL3DX,&
           & IGRID,ILENCH,YCOMMENT,IRESP)
      IF ( SIZE(PLBXSVM,1) /= 0 ) THEN
        IF (IRESP/=0) THEN
          IF (PRESENT(PLBXSVMM)) THEN
            PLBXSVM(:,:,:,JSV)=PLBXSVMM(:,:,:,JSV)
            WRITE(ILUOUT,*) 'PLXYSVM   will be initialized to 0'
          ELSE
            WRITE(ILUOUT,*) 'Pb to initialze PLBXSVM '
!callabortstop
            CALL CLOSE_ll(HLUOUT,IOSTAT=IRESP)
            CALL ABORT
            STOP
          ENDIF
        END IF
      END IF
    END IF
!
    IF (KSIZELBYSV_ll  /= 0 ) THEN
      WRITE(YRECFM,'(A6,I3.3)')'LBYSVM',JSV
      YDIRLB='LBY'
      CALL FMREAD_LB(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIRLB,PLBYSVM(:,:,:,JSV),IRIMY,IL3DY,&
           & IGRID,ILENCH,YCOMMENT,IRESP)
      IF ( SIZE(PLBYSVM,1) /= 0 ) THEN
        IF (IRESP/=0) THEN
          IF (PRESENT(PLBYSVMM)) THEN
            PLBYSVM(:,:,:,JSV)=PLBYSVMM(:,:,:,JSV)
            WRITE(ILUOUT,*) 'PLBYSVM   will be initialized to 0'
          ELSE
            WRITE(ILUOUT,*) 'Pb to initialze PLBYSVM '
!callabortstop
            CALL CLOSE_ll(HLUOUT,IOSTAT=IRESP)
            CALL ABORT
            STOP
          ENDIF
        END IF
      END IF
    END IF
  CASE('INIT')
    IF ( SIZE(PLBXSVM,1) /= 0 ) PLBXSVM(:,:,:,JSV) = 0.
    IF ( SIZE(PLBYSVM,1) /= 0 ) PLBYSVM(:,:,:,JSV) = 0.
  END SELECT
END DO
! C2R2 scalar variables 
DO JSV = NSV_C2R2BEG, NSV_C2R2END
  SELECT CASE(HGETSVM(JSV))
  CASE ('READ')
    IF ( KSIZELBXSV_ll /= 0 ) THEN
      YRECFM='LBX_'//TRIM(C2R2NAMES(JSV-NSV_C2R2BEG+1))
      YDIRLB='LBX'
      CALL FMREAD_LB(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIRLB,PLBXSVM(:,:,:,JSV),IRIMX,IL3DX,&
           & IGRID,ILENCH,YCOMMENT,IRESP)
      IF ( SIZE(PLBXSVM,1) /= 0 ) THEN
        IF (IRESP/=0) THEN
          IF (PRESENT(PLBXSVMM)) THEN
            PLBXSVM(:,:,:,JSV)=PLBXSVMM(:,:,:,JSV)
            WRITE(ILUOUT,*) 'C2R2 PLBXSVM   will be initialized to 0'
          ELSE
            WRITE(ILUOUT,*) 'Pb to initialize C2R2 PLBXSVM '
!callabortstop
            CALL CLOSE_ll(HLUOUT,IOSTAT=IRESP)
            CALL ABORT
            STOP
          ENDIF
        END IF
      END IF
    END IF
!
    IF (KSIZELBYSV_ll  /= 0 ) THEN
      YRECFM='LBY_'//TRIM(C2R2NAMES(JSV-NSV_C2R2BEG+1))
      YDIRLB='LBY'
      CALL FMREAD_LB(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIRLB,PLBYSVM(:,:,:,JSV),IRIMY,IL3DY,&
           & IGRID,ILENCH,YCOMMENT,IRESP)
      IF ( SIZE(PLBYSVM,1) /= 0 ) THEN
        IF (IRESP/=0) THEN
          IF (PRESENT(PLBYSVMM)) THEN
            PLBYSVM(:,:,:,JSV)=PLBYSVMM(:,:,:,JSV)
            WRITE(ILUOUT,*) 'C2R2 PLBYSVM   will be initialized to 0'
          ELSE
            WRITE(ILUOUT,*) 'Pb to initialize C2R2 PLBYSVM '
!callabortstop
            CALL CLOSE_ll(HLUOUT,IOSTAT=IRESP)
            CALL ABORT
            STOP
          ENDIF
        END IF
      END IF
    END IF
  CASE('INIT')
    IF ( SIZE(PLBXSVM,1) /= 0 ) PLBXSVM(:,:,:,JSV) = 0.
    IF ( SIZE(PLBYSVM,1) /= 0 ) PLBYSVM(:,:,:,JSV) = 0.
  END SELECT
END DO
! C1R3 scalar variables 
DO JSV = NSV_C1R3BEG, NSV_C1R3END
  SELECT CASE(HGETSVM(JSV))
  CASE ('READ')
    IF ( KSIZELBXSV_ll /= 0 ) THEN
      YRECFM='LBX_'//TRIM(C1R3NAMES(JSV-NSV_C1R3BEG+1))
      YDIRLB='LBX'
      CALL FMREAD_LB(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIRLB,PLBXSVM(:,:,:,JSV),IRIMX,IL3DX,&
           & IGRID,ILENCH,YCOMMENT,IRESP)
      IF ( SIZE(PLBXSVM,1) /= 0 ) THEN
        IF (IRESP/=0) THEN
          IF (PRESENT(PLBXSVMM)) THEN
            PLBXSVM(:,:,:,JSV)=PLBXSVMM(:,:,:,JSV)
            WRITE(ILUOUT,*) 'C1R3 PLBXSVM   will be initialized to 0'
          ELSE
            WRITE(ILUOUT,*) 'Pb to initialize C1R3 PLBXSVM '
!callabortstop
            CALL CLOSE_ll(HLUOUT,IOSTAT=IRESP)
            CALL ABORT
            STOP
          ENDIF
        END IF
      END IF
    END IF
!
    IF (KSIZELBYSV_ll  /= 0 ) THEN
      YRECFM='LBY_'//TRIM(C1R3NAMES(JSV-NSV_C1R3BEG+1))
      YDIRLB='LBY'
      CALL FMREAD_LB(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIRLB,PLBYSVM(:,:,:,JSV),IRIMY,IL3DY,&
           & IGRID,ILENCH,YCOMMENT,IRESP)
      IF ( SIZE(PLBYSVM,1) /= 0 ) THEN
        IF (IRESP/=0) THEN
          IF (PRESENT(PLBYSVMM)) THEN
            PLBYSVM(:,:,:,JSV)=PLBYSVMM(:,:,:,JSV)
            WRITE(ILUOUT,*) 'C1R3 PLBYSVM   will be initialized to 0'
          ELSE
            WRITE(ILUOUT,*) 'Pb to initialize C1R3 PLBYSVM '
!callabortstop
            CALL CLOSE_ll(HLUOUT,IOSTAT=IRESP)
            CALL ABORT
            STOP
          ENDIF
        END IF
      END IF
    END IF
  CASE('INIT')
    IF ( SIZE(PLBXSVM,1) /= 0 ) PLBXSVM(:,:,:,JSV) = 0.
    IF ( SIZE(PLBYSVM,1) /= 0 ) PLBYSVM(:,:,:,JSV) = 0.
  END SELECT
END DO
Gaelle TANGUY's avatar
Gaelle TANGUY committed
!
! LIMA: CCN and IFN scalar variables
!
IF (CCLOUD=='LIMA' ) THEN
  DO JSV = NSV_LIMA_CCN_FREE,NSV_LIMA_CCN_FREE+NMOD_CCN-1
    SELECT CASE(HGETSVM(JSV))
    CASE ('READ')
      WRITE(INDICE,'(I2.2)')(JSV - NSV_LIMA_CCN_FREE + 1)
      IF ( KSIZELBXSV_ll /= 0 ) THEN
        YRECFM = 'LBX_'//TRIM(UPCASE(CLIMA_WARM_NAMES(3))//INDICE)
        YDIRLB='LBX'
        CALL FMREAD_LB(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIRLB,PLBXSVM(:,:,:,JSV),IRIMX,IL3DX,&
Gaelle TANGUY's avatar
Gaelle TANGUY committed
           & IGRID,ILENCH,YCOMMENT,IRESP)
        IF ( SIZE(PLBXSVM,1) /= 0 ) THEN
          IF (IRESP/=0) THEN
            IF (PRESENT(PLBXSVMM)) THEN
              PLBXSVM(:,:,:,JSV)=PLBXSVMM(:,:,:,JSV)
              WRITE(ILUOUT,*) 'CCN PLBXSVM   will be initialized to 0'
            ELSE
              WRITE(ILUOUT,*) 'Pb to initialize CCN PLBXSVM '
!callabortstop
              CALL CLOSE_ll(HLUOUT,IOSTAT=IRESP)
              CALL ABORT
              STOP
            ENDIF
          END IF
        END IF
      END IF
!
      IF (KSIZELBYSV_ll  /= 0 ) THEN
        YRECFM = 'LBY_'//TRIM(UPCASE(CLIMA_WARM_NAMES(3))//INDICE)
        YDIRLB='LBY'
        CALL FMREAD_LB(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIRLB,PLBYSVM(:,:,:,JSV),IRIMY,IL3DY,&
Gaelle TANGUY's avatar
Gaelle TANGUY committed
             & IGRID,ILENCH,YCOMMENT,IRESP)
        IF ( SIZE(PLBYSVM,1) /= 0 ) THEN
          IF (IRESP/=0) THEN
            IF (PRESENT(PLBYSVMM)) THEN
              PLBYSVM(:,:,:,JSV)=PLBYSVMM(:,:,:,JSV)
              WRITE(ILUOUT,*) 'CCN PLBYSVM   will be initialized to 0'
            ELSE
              WRITE(ILUOUT,*) 'Pb to initialize CCN PLBYSVM '
!callabortstop
              CALL CLOSE_ll(HLUOUT,IOSTAT=IRESP)
              CALL ABORT
              STOP
            ENDIF
          END IF
        END IF
      END IF
    CASE('INIT')
      IF ( SIZE(PLBXSVM,1) /= 0 ) PLBXSVM(:,:,:,JSV) = 0.
      IF ( SIZE(PLBYSVM,1) /= 0 ) PLBYSVM(:,:,:,JSV) = 0.
    END SELECT
  END DO
  DO JSV = NSV_LIMA_IFN_FREE,NSV_LIMA_IFN_FREE+NMOD_IFN-1
    SELECT CASE(HGETSVM(JSV))
    CASE ('READ')
      WRITE(INDICE,'(I2.2)')(JSV - NSV_LIMA_IFN_FREE + 1)
      IF ( KSIZELBXSV_ll /= 0 ) THEN
        YRECFM = 'LBX_'//TRIM(UPCASE(CLIMA_COLD_NAMES(2))//INDICE)
        YDIRLB='LBX'
        CALL FMREAD_LB(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIRLB,PLBXSVM(:,:,:,JSV),IRIMX,IL3DX,&
Gaelle TANGUY's avatar
Gaelle TANGUY committed
           & IGRID,ILENCH,YCOMMENT,IRESP)
        IF ( SIZE(PLBXSVM,1) /= 0 ) THEN
          IF (IRESP/=0) THEN
            IF (PRESENT(PLBXSVMM)) THEN
              PLBXSVM(:,:,:,JSV)=PLBXSVMM(:,:,:,JSV)
              WRITE(ILUOUT,*) 'IFN PLBXSVM   will be initialized to 0'
            ELSE
              WRITE(ILUOUT,*) 'Pb to initialize IFN'
!callabortstop
              CALL CLOSE_ll(HLUOUT,IOSTAT=IRESP)
              CALL ABORT
              STOP
            ENDIF
          END IF
        END IF
      END IF
!
      IF (KSIZELBYSV_ll  /= 0 ) THEN
        YRECFM = 'LBY_'//TRIM(UPCASE(CLIMA_COLD_NAMES(2))//INDICE)
        YDIRLB='LBY'
        CALL FMREAD_LB(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIRLB,PLBYSVM(:,:,:,JSV),IRIMY,IL3DY,&
Gaelle TANGUY's avatar
Gaelle TANGUY committed
           & IGRID,ILENCH,YCOMMENT,IRESP)
        IF ( SIZE(PLBYSVM,1) /= 0 ) THEN
          IF (IRESP/=0) THEN
            IF (PRESENT(PLBYSVMM)) THEN
              PLBYSVM(:,:,:,JSV)=PLBYSVMM(:,:,:,JSV)
              WRITE(ILUOUT,*) 'IFN PLBYSVM   will be initialized to 0'
            ELSE
              WRITE(ILUOUT,*) 'Pb to initialize IFN'
!callabortstop
              CALL CLOSE_ll(HLUOUT,IOSTAT=IRESP)
              CALL ABORT
              STOP
            ENDIF
          END IF
        END IF
      END IF
    CASE('INIT')
      IF ( SIZE(PLBXSVM,1) /= 0 ) PLBXSVM(:,:,:,JSV) = 0.
      IF ( SIZE(PLBYSVM,1) /= 0 ) PLBYSVM(:,:,:,JSV) = 0.
    END SELECT
  END DO
ENDIF
! ELEC scalar variables 
DO JSV = NSV_ELECBEG, NSV_ELECEND
  SELECT CASE(HGETSVM(JSV))
  CASE ('READ')
    IF ( KSIZELBXSV_ll /= 0 ) THEN
      YRECFM='LBX_'//TRIM(CELECNAMES(JSV-NSV_ELECBEG+1))
      YDIRLB='LBX'
      CALL FMREAD_LB(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIRLB,PLBXSVM(:,:,:,JSV),IRIMX,IL3DX,&
           & IGRID,ILENCH,YCOMMENT,IRESP)
      IF ( SIZE(PLBXSVM,1) /= 0 ) THEN
        IF (IRESP/=0) THEN
          IF (PRESENT(PLBXSVMM)) THEN
            PLBXSVM(:,:,:,JSV)=PLBXSVMM(:,:,:,JSV)
            WRITE(ILUOUT,*) 'ELEC PLBXSVM   will be initialized to 0'
          ELSE
            WRITE(ILUOUT,*) 'Pb to initialize ELEC PLBXSVM '
!callabortstop
            CALL CLOSE_ll(HLUOUT,IOSTAT=IRESP)
            CALL ABORT
            STOP
          ENDIF
        END IF
      END IF
    END IF
!
    IF (KSIZELBYSV_ll  /= 0 ) THEN
      YRECFM='LBY_'//TRIM(CELECNAMES(JSV-NSV_ELECBEG+1))
      YDIRLB='LBY'
      CALL FMREAD_LB(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIRLB,PLBYSVM(:,:,:,JSV),IRIMY,IL3DY,&
           & IGRID,ILENCH,YCOMMENT,IRESP)
      IF ( SIZE(PLBYSVM,1) /= 0 ) THEN
        IF (IRESP/=0) THEN
          IF (PRESENT(PLBYSVMM)) THEN
            PLBYSVM(:,:,:,JSV)=PLBYSVMM(:,:,:,JSV)
            WRITE(ILUOUT,*) 'ELEC PLBYSVM   will be initialized to 0'
          ELSE
            WRITE(ILUOUT,*) 'Pb to initialize ELEC PLBYSVM '
!callabortstop
            CALL CLOSE_ll(HLUOUT,IOSTAT=IRESP)
            CALL ABORT
            STOP
          ENDIF
        END IF
      END IF
    END IF
  CASE('INIT')
    IF ( SIZE(PLBXSVM,1) /= 0 ) PLBXSVM(:,:,:,JSV) = 0.
    IF ( SIZE(PLBYSVM,1) /= 0 ) PLBYSVM(:,:,:,JSV) = 0.
  END SELECT
END DO
! Chemical gas phase scalar variables
DO JSV = NSV_CHGSBEG, NSV_CHGSEND
  SELECT CASE(HGETSVM(JSV))
  CASE ('READ')
    IF ( KSIZELBXSV_ll /= 0 ) THEN
      YRECFM = 'LBX_'//TRIM(UPCASE(CNAMES(JSV-NSV_CHGSBEG+1)))
      YDIRLB='LBX'
      CALL FMREAD_LB(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIRLB,PLBXSVM(:,:,:,JSV),IRIMX,IL3DX,&
           & IGRID,ILENCH,YCOMMENT,IRESP)
      IF ( SIZE(PLBXSVM,1) /= 0 ) THEN
        IF (IRESP/=0) THEN
          IF (PRESENT(PLBXSVMM)) THEN
            PLBXSVM(:,:,:,JSV)=PLBXSVMM(:,:,:,JSV)
            WRITE(ILUOUT,*) 'Chemical PLBXSVM   will be initialized to 0'
          ELSE
            WRITE(ILUOUT,*) 'Pb to initialize gas phase Chemical PLBXSVM '
!callabortstop
            CALL CLOSE_ll(HLUOUT,IOSTAT=IRESP)
            CALL ABORT
            STOP
          ENDIF
        END IF
      END IF
    END IF
!
    IF (KSIZELBYSV_ll  /= 0 ) THEN
      YRECFM = 'LBY_'//TRIM(UPCASE(CNAMES(JSV-NSV_CHGSBEG+1)))
      YDIRLB='LBY'
      CALL FMREAD_LB(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIRLB,PLBYSVM(:,:,:,JSV),IRIMY,IL3DY,&
           & IGRID,ILENCH,YCOMMENT,IRESP)
      IF ( SIZE(PLBYSVM,1) /= 0 ) THEN
        IF (IRESP/=0) THEN
          IF (PRESENT(PLBYSVMM)) THEN
            PLBYSVM(:,:,:,JSV)=PLBYSVMM(:,:,:,JSV)
            WRITE(ILUOUT,*) 'Chemical PLBYSVM   will be initialized to 0'
          ELSE
            WRITE(ILUOUT,*) 'Pb to initialize gas phase Chemical PLBYSVM '
!callabortstop
            CALL CLOSE_ll(HLUOUT,IOSTAT=IRESP)
            CALL ABORT
            STOP
          ENDIF
        END IF
      END IF
    END IF
  CASE('INIT')
    IF ( SIZE(PLBXSVM,1) /= 0 ) PLBXSVM(:,:,:,JSV) = 0.
    IF ( SIZE(PLBYSVM,1) /= 0 ) PLBYSVM(:,:,:,JSV) = 0.
  END SELECT
END DO
! Chemical aqueous phase scalar variables
DO JSV = NSV_CHACBEG, NSV_CHACEND
  SELECT CASE(HGETSVM(JSV))
  CASE ('READ')
    IF ( KSIZELBXSV_ll /= 0 ) THEN
      YRECFM = 'LBX_'//TRIM(UPCASE(CNAMES(JSV-NSV_CHACBEG+NSV_CHGS+1)))
      YDIRLB='LBX'
      CALL FMREAD_LB(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIRLB,PLBXSVM(:,:,:,JSV),IRIMX,IL3DX,&
           & IGRID,ILENCH,YCOMMENT,IRESP)
      IF ( SIZE(PLBXSVM,1) /= 0 ) THEN
        IF (IRESP/=0) THEN
          IF (PRESENT(PLBXSVMM)) THEN
            PLBXSVM(:,:,:,JSV)=PLBXSVMM(:,:,:,JSV)
            WRITE(ILUOUT,*) 'Chemical PLBXSVM   will be initialized to 0'
          ELSE
            WRITE(ILUOUT,*) 'Pb to initialize aqueous phase chemical PLBXSVM '
!callabortstop
            CALL CLOSE_ll(HLUOUT,IOSTAT=IRESP)
            CALL ABORT
            STOP
          ENDIF
        END IF
      END IF
    END IF
!
    IF (KSIZELBYSV_ll  /= 0 ) THEN
      YRECFM = 'LBY_'//TRIM(UPCASE(CNAMES(JSV-NSV_CHACBEG+NSV_CHGS+1)))
      YDIRLB='LBY'
      CALL FMREAD_LB(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIRLB,PLBYSVM(:,:,:,JSV),IRIMY,IL3DY,&
           & IGRID,ILENCH,YCOMMENT,IRESP)
      IF ( SIZE(PLBYSVM,1) /= 0 ) THEN
        IF (IRESP/=0) THEN
          IF (PRESENT(PLBYSVMM)) THEN
            PLBYSVM(:,:,:,JSV)=PLBYSVMM(:,:,:,JSV)
            WRITE(ILUOUT,*) 'Chemical PLBYSVM   will be initialized to 0'
          ELSE
            WRITE(ILUOUT,*) 'Pb to initialize aqueous phase chemical PLBYSVM '
!callabortstop
            CALL CLOSE_ll(HLUOUT,IOSTAT=IRESP)
            CALL ABORT
            STOP
          ENDIF
        END IF
      END IF
    END IF
  CASE('INIT')
    IF ( SIZE(PLBXSVM,1) /= 0 ) PLBXSVM(:,:,:,JSV) = 0.
    IF ( SIZE(PLBYSVM,1) /= 0 ) PLBYSVM(:,:,:,JSV) = 0.
  END SELECT
END DO
! Chemical ice phase scalar variables
DO JSV = NSV_CHICBEG, NSV_CHICEND
  SELECT CASE(HGETSVM(JSV))
  CASE ('READ')
    IF ( KSIZELBXSV_ll /= 0 ) THEN
      YRECFM = 'LBX_'//TRIM(UPCASE(CICNAMES(JSV-NSV_CHICBEG+1)))
      YDIRLB='LBX'
      CALL FMREAD_LB(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIRLB,PLBXSVM(:,:,:,JSV),IRIMX,IL3DX,&
           & IGRID,ILENCH,YCOMMENT,IRESP)
      IF ( SIZE(PLBXSVM,1) /= 0 ) THEN
        IF (IRESP/=0) THEN
          IF (PRESENT(PLBXSVMM)) THEN
            PLBXSVM(:,:,:,JSV)=PLBXSVMM(:,:,:,JSV)
            WRITE(ILUOUT,*) 'Ice phase chemical PLBXSVM   will be initialized to 0'
          ELSE
            WRITE(ILUOUT,*) 'Pb to initialize ice phase chemical PLBXSVM '
!callabortstop
            CALL CLOSE_ll(HLUOUT,IOSTAT=IRESP)
            CALL ABORT
            STOP
          ENDIF
        END IF
      END IF
    END IF
!
    IF (KSIZELBYSV_ll  /= 0 ) THEN
      YRECFM = 'LBY_'//TRIM(UPCASE(CICNAMES(JSV-NSV_CHICBEG+1)))
      YDIRLB='LBY'
      CALL FMREAD_LB(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIRLB,PLBYSVM(:,:,:,JSV),IRIMY,IL3DY,&
           & IGRID,ILENCH,YCOMMENT,IRESP)
      IF ( SIZE(PLBYSVM,1) /= 0 ) THEN
        IF (IRESP/=0) THEN
          IF (PRESENT(PLBYSVMM)) THEN
            PLBYSVM(:,:,:,JSV)=PLBYSVMM(:,:,:,JSV)
            WRITE(ILUOUT,*) 'Ice phase chemical PLBYSVM   will be initialized to 0'
          ELSE
            WRITE(ILUOUT,*) 'Pb to initialize Ice phase chemical PLBYSVM '
!callabortstop
            CALL CLOSE_ll(HLUOUT,IOSTAT=IRESP)
            CALL ABORT
            STOP
          ENDIF
        END IF
      END IF
    END IF
  CASE('INIT')
    IF ( SIZE(PLBXSVM,1) /= 0 ) PLBXSVM(:,:,:,JSV) = 0.
    IF ( SIZE(PLBYSVM,1) /= 0 ) PLBYSVM(:,:,:,JSV) = 0.
  END SELECT
END DO
! Orilam aerosol scalar variables
DO JSV = NSV_AERBEG, NSV_AEREND
  SELECT CASE(HGETSVM(JSV))
  CASE ('READ')
    IF ( KSIZELBXSV_ll /= 0 ) THEN
      YRECFM = 'LBX_'//TRIM(UPCASE(CAERONAMES(JSV-NSV_AERBEG+1)))
      YDIRLB='LBX'
      CALL FMREAD_LB(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIRLB,PLBXSVM(:,:,:,JSV),IRIMX,IL3DX,&
           & IGRID,ILENCH,YCOMMENT,IRESP)
      IF ( SIZE(PLBXSVM,1) /= 0 ) THEN
        IF (IRESP/=0) THEN
          IF (PRESENT(PLBXSVMM)) THEN
            PLBXSVM(:,:,:,JSV)=PLBXSVMM(:,:,:,JSV)
            WRITE(ILUOUT,*) 'Aerosol PLBXSVM   will be initialized to 0'
          ELSE
            WRITE(ILUOUT,*) 'Pb to initialize Aerosol PLBXSVM '
!callabortstop
            CALL CLOSE_ll(HLUOUT,IOSTAT=IRESP)
            CALL ABORT
            STOP
          ENDIF
        END IF
      END IF
    END IF
!
    IF (KSIZELBYSV_ll  /= 0 ) THEN
      YRECFM = 'LBY_'//TRIM(UPCASE(CAERONAMES(JSV-NSV_AERBEG+1)))
      YDIRLB='LBY'
      CALL FMREAD_LB(TPINIFILE%CNAME,YRECFM,HLUOUT,YDIRLB,PLBYSVM(:,:,:,JSV),IRIMY,IL3DY,&
           & IGRID,ILENCH,YCOMMENT,IRESP)
      IF ( SIZE(PLBYSVM,1) /= 0 ) THEN
        IF (IRESP/=0) THEN
          IF (PRESENT(PLBYSVMM)) THEN