Index: /palm/trunk/SOURCE/Makefile
===================================================================
--- /palm/trunk/SOURCE/Makefile	(revision 3736)
+++ /palm/trunk/SOURCE/Makefile	(revision 3737)
@@ -25,4 +25,8 @@
 # -----------------
 # $Id$
+# Enable mesoscale offline nesting for chemistry variables as well as 
+# initialization of chemistry via dynamic input file.
+# 
+# 3727 2019-02-08 14:52:10Z gronemeier
 # surface_data_output_mod depends on netcdf_interface_mod
 #
@@ -1357,4 +1361,5 @@
 	user_module.o
 nesting_offl_mod.o: \
+	chemistry_model_mod.o \
 	cpulog_mod.o \
 	mod_kinds.o \
Index: /palm/trunk/SOURCE/chemistry_model_mod.f90
===================================================================
--- /palm/trunk/SOURCE/chemistry_model_mod.f90	(revision 3736)
+++ /palm/trunk/SOURCE/chemistry_model_mod.f90	(revision 3737)
@@ -27,4 +27,8 @@
 ! -----------------
 ! $Id$
+! Enable mesoscale offline nesting for chemistry variables as well as 
+! initialization of chemistry via dynamic input file.
+! 
+! 3719 2019-02-06 13:10:18Z kanani
 ! Resolved cpu logpoint overlap with all progn.equations, moved cpu_log call
 ! to prognostic_equations for better overview
@@ -1408,7 +1412,15 @@
 !                                                           TRIM(chem_species(lsp)%name)       
             IF (av == 0) THEN
+            write(9,*) "before", TRIM(chem_species(lsp)%name), fill_value
+            flush(9)
                DO  i = nxl, nxr
                   DO  j = nys, nyn
                      DO  k = nzb_do, nzt_do
+!                      write(9,*) k, j, i
+!                      flush(9)
+!                      write(9) chem_species(lsp)%conc(k,j,i)
+!                      flush(9)
+!                      write(9) "fill", fill_value
+!                      flush(9)
                          local_pf(i,j,k) = MERGE(                             &
                                              chem_species(lsp)%conc(k,j,i),   &
@@ -1745,9 +1757,30 @@
     USE chem_emissions_mod,                                                    &
         ONLY:  chem_emissions_init
+        
+    USE netcdf_data_input_mod,                                                 &
+        ONLY:  init_3d
 
     IMPLICIT NONE
 
+    INTEGER(iwp) ::  i !< running index x dimension
+    INTEGER(iwp) ::  j !< running index y dimension
+    INTEGER(iwp) ::  n !< running index for chemical species
 
     IF ( do_emis )  CALL chem_emissions_init
+!
+!-- Chemistry variables will be initialized if availabe from dynamic 
+!-- input file. Note, it is possible to initialize only part of the chemistry
+!-- variables from dynamic input. 
+    IF ( INDEX( initializing_actions, 'inifor' ) /= 0 )  THEN
+       DO  n = 1, nspec
+          IF ( init_3d%from_file_chem(n) )  THEN
+             DO  i = nxlg, nxrg
+                DO  j = nysg, nyng
+                   chem_species(n)%conc(:,j,i) = init_3d%chem_init(:,n)
+                ENDDO
+             ENDDO
+          ENDIF
+       ENDDO
+    ENDIF
 
 
@@ -1764,12 +1797,13 @@
  SUBROUTINE chem_init_internal
 
-    USE control_parameters,                                                  &
+    USE control_parameters,                                                    &
         ONLY:  message_string, io_blocks, io_group, turbulent_inflow
-    USE arrays_3d,                                                           &
+    USE arrays_3d,                                                             &
         ONLY:  mean_inflow_profiles
     USE pegrid
 
     USE netcdf_data_input_mod,                                                 &
-        ONLY:  chem_emis, chem_emis_att, netcdf_data_input_chemistry_data
+        ONLY:  chem_emis, chem_emis_att, input_pids_dynamic, init_3d,          &
+               netcdf_data_input_chemistry_data
 
     IMPLICIT NONE
@@ -1839,11 +1873,23 @@
 !-- Initial concentration of profiles is prescribed by parameters cs_profile
 !-- and cs_heights in the namelist &chemistry_parameters
-    CALL chem_init_profiles      
+    CALL chem_init_profiles
+!    
+!-- In case there is dynamic input file, create a list of names for chemistry
+!-- initial input files. Also, initialize array that indicates whether the
+!-- respective variable is on file or not. 
+    IF ( input_pids_dynamic )  THEN    
+       ALLOCATE( init_3d%var_names_chem(1:nspec) )
+       ALLOCATE( init_3d%from_file_chem(1:nspec) )
+       init_3d%from_file_chem(:) = .FALSE.
+       
+       DO  lsp = 1, nspec
+          init_3d%var_names_chem(lsp) = init_3d%init_char // TRIM( chem_species(lsp)%name )
+       ENDDO
+    ENDIF
+
 
 
 !
 !-- Initialize model variables
-
-
     IF ( TRIM( initializing_actions ) /= 'read_restart_data'  .AND.            &
          TRIM( initializing_actions ) /= 'cyclic_fill' )  THEN
Index: /palm/trunk/SOURCE/nesting_offl_mod.f90
===================================================================
--- /palm/trunk/SOURCE/nesting_offl_mod.f90	(revision 3736)
+++ /palm/trunk/SOURCE/nesting_offl_mod.f90	(revision 3737)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Introduce mesoscale nesting for chemical species
+! 
+! 3705 2019-01-29 19:56:39Z suehring
 ! Formatting adjustments
 ! 
@@ -54,11 +57,14 @@
     USE arrays_3d,                                                             &
         ONLY:  dzw, e, diss, pt, pt_init, q, q_init, s, u, u_init, ug, v,      &
-               v_init, vg, w, zu, zw          
+               v_init, vg, w, zu, zw
+                 
+    USE chemistry_model_mod,                                                   &
+        ONLY:  chem_species
 
     USE control_parameters,                                                    &
-        ONLY:  bc_dirichlet_l, bc_dirichlet_n, bc_dirichlet_r, bc_dirichlet_s, &
-               dt_3d, dz, constant_diffusion, humidity, message_string,        &
-               nesting_offline, neutral, passive_scalar, rans_mode, rans_tke_e,&
-               time_since_reference_point, volume_flow
+        ONLY:  air_chemistry, bc_dirichlet_l, bc_dirichlet_n, bc_dirichlet_r,  &
+               bc_dirichlet_s, dt_3d, dz, constant_diffusion, humidity,        &
+               message_string, nesting_offline, neutral, passive_scalar,       &
+               rans_mode, rans_tke_e, time_since_reference_point, volume_flow
                
     USE cpulog,                                                                &
@@ -235,4 +241,5 @@
        INTEGER(iwp) ::  j !< running index y-direction
        INTEGER(iwp) ::  k !< running index z-direction
+       INTEGER(iwp) ::  n !< running index for chemical species
 
        REAL(wp) ::  fac_dt   !< interpolation factor
@@ -335,4 +342,19 @@
              ENDDO
           ENDIF
+          
+          IF ( air_chemistry )  THEN
+             DO  n = 1, UBOUND( chem_species, 1 )
+                IF ( nest_offl%chem_from_file_l(n) )  THEN                   
+                   DO  j = nys, nyn
+                      DO  k = nzb+1, nzt
+                         chem_species(n)%conc(k,j,-1) = interpolate_in_time(   &
+                                                  nest_offl%chem_left(0,k,j,n),&
+                                                  nest_offl%chem_left(1,k,j,n),&
+                                                  fac_dt                   )
+                      ENDDO
+                   ENDDO
+                ENDIF
+             ENDDO
+          ENDIF
 
        ENDIF
@@ -395,4 +417,19 @@
              ENDDO
           ENDIF
+          
+          IF ( air_chemistry )  THEN
+             DO  n = 1, UBOUND( chem_species, 1 )
+                IF ( nest_offl%chem_from_file_r(n) )  THEN  
+                   DO  j = nys, nyn
+                      DO  k = nzb+1, nzt
+                         chem_species(n)%conc(k,j,nxr+1) = interpolate_in_time(&
+                                                 nest_offl%chem_right(0,k,j,n),&
+                                                 nest_offl%chem_right(1,k,j,n),&
+                                                 fac_dt                       )
+                      ENDDO
+                   ENDDO
+                ENDIF
+             ENDDO
+          ENDIF
 
        ENDIF
@@ -458,4 +495,19 @@
              ENDDO
           ENDIF
+          
+          IF ( air_chemistry )  THEN
+             DO  n = 1, UBOUND( chem_species, 1 )
+                IF ( nest_offl%chem_from_file_s(n) )  THEN  
+                   DO  i = nxl, nxr
+                      DO  k = nzb+1, nzt
+                         chem_species(n)%conc(k,-1,i) = interpolate_in_time(   &
+                                                 nest_offl%chem_south(0,k,i,n),&
+                                                 nest_offl%chem_south(1,k,i,n),&
+                                                 fac_dt                    )
+                      ENDDO
+                   ENDDO
+                ENDIF
+             ENDDO
+          ENDIF
 
        ENDIF
@@ -520,4 +572,19 @@
              ENDDO
           ENDIF
+          
+          IF ( air_chemistry )  THEN
+             DO  n = 1, UBOUND( chem_species, 1 )
+                IF ( nest_offl%chem_from_file_n(n) )  THEN  
+                   DO  i = nxl, nxr
+                      DO  k = nzb+1, nzt
+                         chem_species(n)%conc(k,nyn+1,i) = interpolate_in_time(&
+                                                 nest_offl%chem_north(0,k,i,n),&
+                                                 nest_offl%chem_north(1,k,i,n),&
+                                                 fac_dt                       )
+                      ENDDO
+                   ENDDO
+                ENDIF
+             ENDDO
+          ENDIF
 
        ENDIF
@@ -579,4 +646,19 @@
           ENDDO
        ENDIF
+       
+       IF ( air_chemistry )  THEN
+          DO  n = 1, UBOUND( chem_species, 1 )
+             IF ( nest_offl%chem_from_file_t(n) )  THEN  
+                DO  i = nxl, nxr
+                   DO  j = nys, nyn
+                      chem_species(n)%conc(nzt+1,j,i) = interpolate_in_time(   &
+                                              nest_offl%chem_north(0,j,i,n),   &
+                                              nest_offl%chem_north(1,j,i,n),   &
+                                              fac_dt                       )
+                   ENDDO
+                ENDDO
+             ENDIF
+          ENDDO
+       ENDIF
 !
 !--    Moreover, set Neumann boundary condition for subgrid-scale TKE, 
@@ -607,4 +689,10 @@
        IF ( .NOT. neutral )  CALL exchange_horiz( pt, nbgp )
        IF ( humidity      )  CALL exchange_horiz( q,  nbgp )
+       IF ( air_chemistry )  THEN
+          DO  n = 1, UBOUND( chem_species, 1 )
+             CALL exchange_horiz( chem_species(n)%conc, nbgp )
+          ENDDO
+       ENDIF
+       
 !
 !--    In case of Rayleigh damping, where the profiles u_init, v_init
@@ -985,4 +1073,6 @@
 
        IMPLICIT NONE
+       
+       INTEGER(iwp) ::  n !< running index for chemical species
 
 
@@ -1000,4 +1090,6 @@
           IF ( humidity )       ALLOCATE( nest_offl%q_left(0:1,nzb+1:nzt,nys:nyn)  )
           IF ( .NOT. neutral )  ALLOCATE( nest_offl%pt_left(0:1,nzb+1:nzt,nys:nyn) )
+          IF ( air_chemistry )  ALLOCATE( nest_offl%chem_left(0:1,nzb+1:nzt,nys:nyn,&
+                                          1:UBOUND( chem_species, 1 )) )
        ENDIF
        IF ( bc_dirichlet_r )  THEN
@@ -1007,4 +1099,6 @@
           IF ( humidity )       ALLOCATE( nest_offl%q_right(0:1,nzb+1:nzt,nys:nyn)  )
           IF ( .NOT. neutral )  ALLOCATE( nest_offl%pt_right(0:1,nzb+1:nzt,nys:nyn) )
+          IF ( air_chemistry )  ALLOCATE( nest_offl%chem_right(0:1,nzb+1:nzt,nys:nyn,&
+                                          1:UBOUND( chem_species, 1 )) )
        ENDIF
        IF ( bc_dirichlet_n )  THEN
@@ -1014,4 +1108,6 @@
           IF ( humidity )       ALLOCATE( nest_offl%q_north(0:1,nzb+1:nzt,nxl:nxr)  )
           IF ( .NOT. neutral )  ALLOCATE( nest_offl%pt_north(0:1,nzb+1:nzt,nxl:nxr) )
+          IF ( air_chemistry )  ALLOCATE( nest_offl%chem_north(0:1,nzb+1:nzt,nxl:nxr,&
+                                          1:UBOUND( chem_species, 1 )) )
        ENDIF
        IF ( bc_dirichlet_s )  THEN
@@ -1021,4 +1117,6 @@
           IF ( humidity )       ALLOCATE( nest_offl%q_south(0:1,nzb+1:nzt,nxl:nxr)  )
           IF ( .NOT. neutral )  ALLOCATE( nest_offl%pt_south(0:1,nzb+1:nzt,nxl:nxr) )
+          IF ( air_chemistry )  ALLOCATE( nest_offl%chem_south(0:1,nzb+1:nzt,nxl:nxr,&
+                                          1:UBOUND( chem_species, 1 )) )
        ENDIF
        
@@ -1028,5 +1126,44 @@
        IF ( humidity )       ALLOCATE( nest_offl%q_top(0:1,nys:nyn,nxl:nxr)  )
        IF ( .NOT. neutral )  ALLOCATE( nest_offl%pt_top(0:1,nys:nyn,nxl:nxr) )
-
+       IF ( air_chemistry )  ALLOCATE( nest_offl%chem_top(0:1,nys:nyn,nxl:nxr, &
+                                       1:UBOUND( chem_species, 1 )) )
+!
+!--    For chemical species, create the names of the variables. This is necessary
+!--    to identify the respective variable and write it onto the correct array 
+!--    in the chem_species datatype.
+       IF ( air_chemistry )  THEN
+          ALLOCATE( nest_offl%chem_from_file_l(1:UBOUND( chem_species, 1 )) )
+          ALLOCATE( nest_offl%chem_from_file_n(1:UBOUND( chem_species, 1 )) )
+          ALLOCATE( nest_offl%chem_from_file_r(1:UBOUND( chem_species, 1 )) )
+          ALLOCATE( nest_offl%chem_from_file_s(1:UBOUND( chem_species, 1 )) )
+          ALLOCATE( nest_offl%chem_from_file_t(1:UBOUND( chem_species, 1 )) )
+          
+          ALLOCATE( nest_offl%var_names_chem_l(1:UBOUND( chem_species, 1 )) )
+          ALLOCATE( nest_offl%var_names_chem_n(1:UBOUND( chem_species, 1 )) )
+          ALLOCATE( nest_offl%var_names_chem_r(1:UBOUND( chem_species, 1 )) )
+          ALLOCATE( nest_offl%var_names_chem_s(1:UBOUND( chem_species, 1 )) )
+          ALLOCATE( nest_offl%var_names_chem_t(1:UBOUND( chem_species, 1 )) )
+!
+!--       Initialize flags that indicate whether the variable is on file or
+!--       not. Please note, this is only necessary for chemistry variables. 
+          nest_offl%chem_from_file_l(:) = .FALSE.
+          nest_offl%chem_from_file_n(:) = .FALSE.
+          nest_offl%chem_from_file_r(:) = .FALSE.
+          nest_offl%chem_from_file_s(:) = .FALSE.
+          nest_offl%chem_from_file_t(:) = .FALSE.
+          
+          DO  n = 1, UBOUND( chem_species, 1 )
+             nest_offl%var_names_chem_l(n) = nest_offl%char_l //               &
+                                                  TRIM(chem_species(n)%name)
+             nest_offl%var_names_chem_n(n) = nest_offl%char_n //               &
+                                                  TRIM(chem_species(n)%name)
+             nest_offl%var_names_chem_r(n) = nest_offl%char_r //               &
+                                                  TRIM(chem_species(n)%name)
+             nest_offl%var_names_chem_s(n) = nest_offl%char_s //               &
+                                                  TRIM(chem_species(n)%name)
+             nest_offl%var_names_chem_t(n) = nest_offl%char_t //               &
+                                                  TRIM(chem_species(n)%name)
+          ENDDO
+       ENDIF
 !
 !--    Read COSMO data at lateral and top boundaries
@@ -1041,5 +1178,13 @@
                                    nest_offl%pt_left(0,nzb+1:nzt,nys:nyn)
           IF ( humidity      )  q(nzb+1:nzt,nys:nyn,-1)  =                     &
-                                   nest_offl%q_left(0,nzb+1:nzt,nys:nyn) 
+                                   nest_offl%q_left(0,nzb+1:nzt,nys:nyn)
+          IF ( air_chemistry )  THEN
+             DO  n = 1, UBOUND( chem_species, 1 )
+                IF( nest_offl%chem_from_file_l(n) )  THEN
+                   chem_species(n)%conc(nzb+1:nzt,nys:nyn,-1) =                &
+                                   nest_offl%chem_left(0,nzb+1:nzt,nys:nyn,n)
+                ENDIF
+             ENDDO
+          ENDIF
        ENDIF
        IF ( bc_dirichlet_r )  THEN
@@ -1051,4 +1196,12 @@
           IF ( humidity      )  q(nzb+1:nzt,nys:nyn,nxr+1)  =                  &
                                    nest_offl%q_right(0,nzb+1:nzt,nys:nyn)
+          IF ( air_chemistry )  THEN
+             DO  n = 1, UBOUND( chem_species, 1 )
+                IF( nest_offl%chem_from_file_r(n) )  THEN
+                   chem_species(n)%conc(nzb+1:nzt,nys:nyn,nxr+1) =             &
+                                   nest_offl%chem_right(0,nzb+1:nzt,nys:nyn,n)
+                ENDIF
+             ENDDO
+          ENDIF
        ENDIF
        IF ( bc_dirichlet_s )  THEN
@@ -1060,4 +1213,12 @@
           IF ( humidity      )  q(nzb+1:nzt,-1,nxl:nxr)  =                     &
                                    nest_offl%q_south(0,nzb+1:nzt,nxl:nxr) 
+          IF ( air_chemistry )  THEN
+             DO  n = 1, UBOUND( chem_species, 1 )
+                IF( nest_offl%chem_from_file_s(n) )  THEN
+                   chem_species(n)%conc(nzb+1:nzt,-1,nxl:nxr) =                &
+                                   nest_offl%chem_south(0,nzb+1:nzt,nxl:nxr,n)
+                ENDIF
+             ENDDO
+          ENDIF
        ENDIF
        IF ( bc_dirichlet_n )  THEN
@@ -1069,4 +1230,12 @@
           IF ( humidity      )  q(nzb+1:nzt,nyn+1,nxl:nxr)  =                  &
                                    nest_offl%q_north(0,nzb+1:nzt,nxl:nxr)
+          IF ( air_chemistry )  THEN
+             DO  n = 1, UBOUND( chem_species, 1 )
+                IF( nest_offl%chem_from_file_n(n) )  THEN
+                   chem_species(n)%conc(nzb+1:nzt,nyn+1,nxl:nxr) =             &
+                                   nest_offl%chem_north(0,nzb+1:nzt,nxl:nxr,n)
+                ENDIF
+             ENDDO
+          ENDIF
        ENDIF
 !
Index: /palm/trunk/SOURCE/netcdf_data_input_mod.f90
===================================================================
--- /palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 3736)
+++ /palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 3737)
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! Enable mesoscale offline nesting for chemistry variables as well as 
+! initialization of chemistry via dynamic input file.
+! 
+! 3705 2019-01-29 19:56:39Z suehring
 ! Interface for attribute input of 8-bit and 32-bit integer 
 ! 
@@ -310,5 +314,16 @@
     TYPE nest_offl_type
 
-       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names
+       CHARACTER(LEN=16) ::  char_l = 'ls_forcing_left_'  !< leading substring for variables at left boundary 
+       CHARACTER(LEN=17) ::  char_n = 'ls_forcing_north_' !< leading substring for variables at north boundary  
+       CHARACTER(LEN=17) ::  char_r = 'ls_forcing_right_' !< leading substring for variables at right boundary  
+       CHARACTER(LEN=17) ::  char_s = 'ls_forcing_south_' !< leading substring for variables at south boundary 
+       CHARACTER(LEN=15) ::  char_t = 'ls_forcing_top_'   !< leading substring for variables at top boundary 
+    
+       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names         !< list of variable in dynamic input file
+       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names_chem_l  !< names of mesoscale nested chemistry variables at left boundary
+       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names_chem_n  !< names of mesoscale nested chemistry variables at north boundary
+       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names_chem_r  !< names of mesoscale nested chemistry variables at right boundary
+       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names_chem_s  !< names of mesoscale nested chemistry variables at south boundary
+       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names_chem_t  !< names of mesoscale nested chemistry variables at top boundary
 
        INTEGER(iwp) ::  nt     !< number of time levels in dynamic input file
@@ -319,4 +334,10 @@
 
        LOGICAL      ::  init         = .FALSE. !< flag indicating that offline nesting is already initialized
+       
+       LOGICAL, DIMENSION(:), ALLOCATABLE ::  chem_from_file_l !< flags inidicating whether left boundary data for chemistry is in dynamic input file  
+       LOGICAL, DIMENSION(:), ALLOCATABLE ::  chem_from_file_n !< flags inidicating whether north boundary data for chemistry is in dynamic input file 
+       LOGICAL, DIMENSION(:), ALLOCATABLE ::  chem_from_file_r !< flags inidicating whether right boundary data for chemistry is in dynamic input file 
+       LOGICAL, DIMENSION(:), ALLOCATABLE ::  chem_from_file_s !< flags inidicating whether south boundary data for chemistry is in dynamic input file 
+       LOGICAL, DIMENSION(:), ALLOCATABLE ::  chem_from_file_t !< flags inidicating whether top boundary data for chemistry is in dynamic input file 
 
        REAL(wp), DIMENSION(:), ALLOCATABLE ::  surface_pressure !< time dependent surface pressure
@@ -357,4 +378,10 @@
        REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  q_top    !< mixing ratio at top boundary
        REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pt_top   !< potentital temperautre at top boundary
+       
+       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  chem_left   !< chemical species at left boundary
+       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  chem_north  !< chemical species at left boundary
+       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  chem_right  !< chemical species at left boundary
+       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  chem_south  !< chemical species at left boundary
+       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  chem_top    !< chemical species at left boundary
 
     END TYPE nest_offl_type
@@ -362,5 +389,7 @@
     TYPE init_type
 
+       CHARACTER(LEN=16) ::  init_char = 'init_atmosphere_'          !< leading substring for init variables 
        CHARACTER(LEN=23) ::  origin_time = '2000-01-01 00:00:00 +00' !< reference time of input data
+       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names_chem !< list of chemistry variable names that can potentially be on file
 
        INTEGER(iwp) ::  lod_msoil !< level of detail - soil moisture
@@ -378,4 +407,6 @@
        INTEGER(iwp) ::  nzu       !< number of vertical levels on scalar grid in dynamic input file
        INTEGER(iwp) ::  nzw       !< number of vertical levels on w grid in dynamic input file
+       
+       INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  lod_chem !< level of detail - chemistry variables
 
        LOGICAL ::  from_file_msoil  = .FALSE. !< flag indicating whether soil moisture is already initialized from file
@@ -388,4 +419,6 @@
        LOGICAL ::  from_file_vg     = .FALSE. !< flag indicating whether ug is already initialized from file
        LOGICAL ::  from_file_w      = .FALSE. !< flag indicating whether w is already initialized from file
+       
+       LOGICAL, DIMENSION(:), ALLOCATABLE ::  from_file_chem !< flag indicating whether chemistry variable is read from file
 
        REAL(wp) ::  fill_msoil              !< fill value for soil moisture
@@ -403,4 +436,5 @@
        REAL(wp) ::  rotation_angle = 0.0_wp !< rotation angle of input data
 
+       REAL(wp), DIMENSION(:), ALLOCATABLE ::  fill_chem    !< fill value - chemistry variables
        REAL(wp), DIMENSION(:), ALLOCATABLE ::  msoil_1d     !< initial vertical profile of soil moisture
        REAL(wp), DIMENSION(:), ALLOCATABLE ::  pt_init      !< initial vertical profile of pt
@@ -415,4 +449,6 @@
        REAL(wp), DIMENSION(:), ALLOCATABLE ::  zu_atmos     !< vertical levels at scalar grid in dynamic input file, used for interpolation
        REAL(wp), DIMENSION(:), ALLOCATABLE ::  zw_atmos     !< vertical levels at w grid in dynamic input file, used for interpolation
+       
+       REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  chem_init  !< initial vertical profiles of chemistry variables
 
 
@@ -727,6 +763,6 @@
     CHARACTER(LEN=100) ::  input_file_uvem    = 'PIDS_UVEM'    !< Name of file which comprises static uv_exposure model input data
     CHARACTER(LEN=100) ::  input_file_vm      = 'PIDS_VM'      !< Name of file which comprises virtual measurement data
-
-    CHARACTER (LEN=25), ALLOCATABLE, DIMENSION(:)    ::  string_values  !< output of string variables read from netcdf input files
+    
+    CHARACTER(LEN=25), ALLOCATABLE, DIMENSION(:)    ::  string_values  !< output of string variables read from netcdf input files
 
     INTEGER(iwp)                                     ::  id_emis        !< NetCDF id of input file for chemistry emissions: TBD: It has to be removed
@@ -2713,5 +2749,6 @@
 
        USE control_parameters,                                                 &
-           ONLY:  bc_lr_cyc, bc_ns_cyc, humidity, message_string, neutral
+           ONLY:  air_chemistry, bc_lr_cyc, bc_ns_cyc, humidity,               &
+                  message_string, neutral
 
        USE indices,                                                            &
@@ -2725,4 +2762,5 @@
        
        INTEGER(iwp) ::  id_dynamic !< NetCDF id of dynamic input file
+       INTEGER(iwp) ::  n          !< running index for chemistry variables
        INTEGER(iwp) ::  num_vars   !< number of variables in netcdf input file
 
@@ -3078,4 +3116,51 @@
              CALL message( 'netcdf_data_input_mod', 'PA0544', 1, 2, 0, 6, 0 )
           ENDIF
+       ENDIF       
+!
+!--    Read chemistry variables.
+!--    Please note, for the moment, only LOD=1 is allowed
+       IF ( air_chemistry )  THEN
+!
+!--       Allocate chemistry input profiles, as well as arrays for fill values
+!--       and LOD's.
+          ALLOCATE( init_3d%chem_init(nzb:nzt+1,                               &
+                                      1:UBOUND(init_3d%var_names_chem, 1 )) )
+          ALLOCATE( init_3d%fill_chem(1:UBOUND(init_3d%var_names_chem, 1)) )    
+          ALLOCATE( init_3d%lod_chem(1:UBOUND(init_3d%var_names_chem, 1))  )  
+          
+          DO  n = 1, UBOUND(init_3d%var_names_chem, 1)
+             IF ( check_existence( var_names,                                  &
+                                   TRIM( init_3d%var_names_chem(n) ) ) )  THEN
+!
+!--             Read attributes for the fill value and level-of-detail
+                CALL get_attribute( id_dynamic, char_fill,                     &
+                                    init_3d%fill_chem(n),                      &
+                                    .FALSE.,                                   &
+                                    TRIM( init_3d%var_names_chem(n) ) )
+                CALL get_attribute( id_dynamic, char_lod,                      &
+                                    init_3d%lod_chem(n),                       &
+                                    .FALSE.,                                   &
+                                    TRIM( init_3d%var_names_chem(n) ) )
+!
+!--             Give message that only LOD=1 is allowed. 
+                IF ( init_3d%lod_chem(n) /= 1 )  THEN                
+                   message_string = 'For chemistry variables only LOD=1 is ' //&
+                                    'allowed.'
+                   CALL message( 'netcdf_data_input_mod', 'PA0586',            &
+                                 1, 2, 0, 6, 0 )
+                ENDIF
+!
+!--             level-of-detail 1 - read initialization profile
+                CALL get_variable( id_dynamic,                                 &
+                                   TRIM( init_3d%var_names_chem(n) ),          &
+                                   init_3d%chem_init(nzb+1:nzt,n) )
+!
+!--             Set bottom and top boundary condition (Neumann)
+                init_3d%chem_init(nzb,n)   = init_3d%chem_init(nzb+1,n)
+                init_3d%chem_init(nzt+1,n) = init_3d%chem_init(nzt,n)
+                
+                init_3d%from_file_chem(n) = .TRUE.
+             ENDIF
+          ENDDO
        ENDIF
 !
@@ -3326,7 +3411,7 @@
 
        USE control_parameters,                                                 &
-           ONLY:  bc_dirichlet_l, bc_dirichlet_n, bc_dirichlet_r,              &
-                  bc_dirichlet_s, humidity, neutral, nesting_offline,          &
-                  time_since_reference_point
+           ONLY:  air_chemistry, bc_dirichlet_l, bc_dirichlet_n,               &
+                  bc_dirichlet_r, bc_dirichlet_s, humidity, neutral,           &
+                  nesting_offline, time_since_reference_point
 
        USE indices,                                                            &
@@ -3336,4 +3421,5 @@
        
        INTEGER(iwp) ::  id_dynamic !< NetCDF id of dynamic input file
+       INTEGER(iwp) ::  n          !< running index for chemistry variables
        INTEGER(iwp) ::  num_vars   !< number of variables in netcdf input file
        INTEGER(iwp) ::  t          !< running index time dimension
@@ -3454,4 +3540,19 @@
                            nys+1, nzb+1, nest_offl%tind+1,                     &
                            nyn-nys+1, nest_offl%nzu, 2, .FALSE. )
+          ENDIF
+          
+          IF ( air_chemistry )  THEN
+             DO  n = 1, UBOUND(nest_offl%var_names_chem_l, 1)
+                IF ( check_existence( nest_offl%var_names,                     &
+                                      nest_offl%var_names_chem_l(n) ) )        &
+                THEN
+                   CALL get_variable( id_dynamic,                              &
+                              TRIM( nest_offl%var_names_chem_l(n) ),           &
+                              nest_offl%chem_left(0:1,nzb+1:nzt,nys:nyn,n),    &
+                              nys+1, nzb+1, nest_offl%tind+1,                  &
+                              nyn-nys+1, nest_offl%nzu, 2, .FALSE. )
+                   nest_offl%chem_from_file_l(n) = .TRUE.
+                ENDIF
+             ENDDO
           ENDIF
 
@@ -3485,4 +3586,19 @@
                            nys+1, nzb+1, nest_offl%tind+1,                     &
                            nyn-nys+1, nest_offl%nzu, 2, .FALSE. )
+          ENDIF
+          
+          IF ( air_chemistry )  THEN
+             DO  n = 1, UBOUND(nest_offl%var_names_chem_r, 1)
+                IF ( check_existence( nest_offl%var_names,                     &
+                                      nest_offl%var_names_chem_r(n) ) )        &
+                THEN
+                   CALL get_variable( id_dynamic,                              &
+                              TRIM( nest_offl%var_names_chem_r(n) ),           &
+                              nest_offl%chem_right(0:1,nzb+1:nzt,nys:nyn,n),   &
+                              nys+1, nzb+1, nest_offl%tind+1,                  &
+                              nyn-nys+1, nest_offl%nzu, 2, .FALSE. )
+                   nest_offl%chem_from_file_r(n) = .TRUE.
+                ENDIF
+             ENDDO
           ENDIF
        ENDIF
@@ -3517,4 +3633,19 @@
                            nxr-nxl+1, nest_offl%nzu, 2, .FALSE. )
           ENDIF
+          
+          IF ( air_chemistry )  THEN
+             DO  n = 1, UBOUND(nest_offl%var_names_chem_n, 1)
+                IF ( check_existence( nest_offl%var_names,                     &
+                                      nest_offl%var_names_chem_n(n) ) )        &
+                THEN
+                   CALL get_variable( id_dynamic,                              &
+                              TRIM( nest_offl%var_names_chem_n(n) ),           &
+                              nest_offl%chem_north(0:1,nzb+1:nzt,nxl:nxr,n),   &
+                              nxl+1, nzb+1, nest_offl%tind+1,                  &
+                              nxr-nxl+1, nest_offl%nzu, 2, .FALSE. )
+                   nest_offl%chem_from_file_n(n) = .TRUE.
+                ENDIF
+             ENDDO
+          ENDIF
        ENDIF
 
@@ -3547,4 +3678,19 @@
                            nxr-nxl+1, nest_offl%nzu, 2, .FALSE. )
           ENDIF
+          
+          IF ( air_chemistry )  THEN
+             DO  n = 1, UBOUND(nest_offl%var_names_chem_s, 1)
+                IF ( check_existence( nest_offl%var_names,                     &
+                                      nest_offl%var_names_chem_s(n) ) )        &
+                THEN
+                   CALL get_variable( id_dynamic,                              &
+                              TRIM( nest_offl%var_names_chem_s(n) ),           &
+                              nest_offl%chem_south(0:1,nzb+1:nzt,nxl:nxr,n),   &
+                              nxl+1, nzb+1, nest_offl%tind+1,                  &
+                              nxr-nxl+1, nest_offl%nzu, 2, .FALSE. )
+                   nest_offl%chem_from_file_s(n) = .TRUE.
+                ENDIF
+             ENDDO
+          ENDIF
        ENDIF
 
@@ -3577,4 +3723,18 @@
                                 nxl+1, nys+1, nest_offl%tind+1,                &
                                 nxr-nxl+1, nyn-nys+1, 2, .TRUE. )
+       ENDIF
+       
+       IF ( air_chemistry )  THEN
+          DO  n = 1, UBOUND(nest_offl%var_names_chem_t, 1)
+             IF ( check_existence( nest_offl%var_names,                     &
+                                   nest_offl%var_names_chem_t(n) ) )  THEN      
+                CALL get_variable( id_dynamic,                                 &
+                              TRIM( nest_offl%var_names_chem_t(n) ),           &
+                              nest_offl%chem_top(0:1,nys:nyn,nxl:nxr,n),       &
+                              nxl+1, nys+1, nest_offl%tind+1,                  &
+                              nxr-nxl+1, nyn-nys+1, 2, .TRUE. )
+                nest_offl%chem_from_file_t(n) = .TRUE.
+             ENDIF
+          ENDDO
        ENDIF
 
