Index: palm/trunk/SOURCE/Makefile
===================================================================
--- palm/trunk/SOURCE/Makefile	(revision 2772)
+++ palm/trunk/SOURCE/Makefile	(revision 2773)
@@ -25,4 +25,7 @@
 # -----------------
 # $Id$
+# Nesting of chemical species
+# 
+# 2718 2018-01-02 08:49:38Z maronga
 # Corrected "Former revisions" section
 # 
@@ -630,6 +633,6 @@
 mod_kinds.o: mod_kinds.f90
 mod_particle_attributes.o: mod_particle_attributes.f90 mod_kinds.o
-netcdf_data_input_mod.o: modules.o mod_kinds.o pmc_interface_mod.o
-netcdf_interface_mod.o: netcdf_interface_mod.f90 modules.o mod_kinds.o \
+netcdf_data_input_mod.o: modules.o mod_kinds.o
+netcdf_interface_mod.o: modules.o mod_kinds.o \
    chemistry_model_mod.o land_surface_model_mod.o radiation_model_mod.o \
    spectra_mod.o turbulence_closure_mod.o urban_surface_mod.o uv_exposure_model_mod.o
@@ -645,5 +648,6 @@
 plant_canopy_model_mod.o: modules.o mod_kinds.o netcdf_data_input_mod.o surface_mod.o
 pmc_interface_mod.o: modules.o mod_kinds.o pmc_child_mod.o pmc_general_mod.o \
-	pmc_handle_communicator_mod.o pmc_mpi_wrapper_mod.o pmc_parent_mod.o surface_mod.o
+   pmc_handle_communicator_mod.o pmc_mpi_wrapper_mod.o pmc_parent_mod.o surface_mod.o \
+   chem_modules.o chemistry_model_mod.o
 pmc_child_mod.o: mod_kinds.o pmc_general_mod.o pmc_handle_communicator_mod.o \
    pmc_mpi_wrapper_mod.o
Index: palm/trunk/SOURCE/check_parameters.f90
===================================================================
--- palm/trunk/SOURCE/check_parameters.f90	(revision 2772)
+++ palm/trunk/SOURCE/check_parameters.f90	(revision 2773)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Check for consistent initialization in nesting mode added.
+! 
+! 2766 2018-01-22 17:17:47Z kanani
 ! Removed preprocessor directive __chem
 ! 
@@ -666,4 +669,5 @@
     INTEGER(iwp) ::  lsp                             !< running index for chem spcs.
 
+    LOGICAL     ::  check_nest                       !< flag used to check initialization in case of nesting
     LOGICAL     ::  found                            !<
 
@@ -1340,4 +1344,26 @@
        CALL message( 'check_parameters', 'PA0033', 1, 2, 0, 6, 0 )
     ENDIF
+!
+!-- In case of nested run assure that all domains are initialized the same
+!-- way, i.e. if at least at one domain is initialized with soil and 
+!-- atmospheric data provided by COSMO, all domains must be initialized the 
+!-- same way, to assure that soil and atmospheric quantities are 
+!-- consistent. 
+    IF ( nested_run )  THEN
+       check_nest = .TRUE.
+#if defined( __parallel )
+       CALL MPI_ALLREDUCE( TRIM( initializing_actions ) == 'inifor',           &
+                           check_nest, 1, MPI_LOGICAL,                         &
+                           MPI_LAND, MPI_COMM_WORLD, ierr )
+
+       IF ( TRIM( initializing_actions ) == 'inifor'  .AND.                    &
+            .NOT.  check_nest )  THEN
+          message_string = 'In case of nesting, if at least in one ' //        &
+                           'domain initializing_actions = inifor, '  //        &
+                           'all domains need to be initialized that way.'
+          CALL message( 'netcdf_data_input_mod', 'PA0430', 3, 2, 0, 6, 0 )
+       ENDIF
+#endif
+    ENDIF
 
     IF ( cloud_physics  .AND.  .NOT.  humidity )  THEN
Index: palm/trunk/SOURCE/chemistry_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/chemistry_model_mod.f90	(revision 2772)
+++ palm/trunk/SOURCE/chemistry_model_mod.f90	(revision 2773)
@@ -27,4 +27,7 @@
 ! -----------------
 ! $Id$
+! Declare variables required for nesting as public
+! 
+! 2772 2018-01-29 13:10:35Z suehring
 ! Bugfix in string handling
 ! 
@@ -152,5 +155,6 @@
    PUBLIC nspec
    PUBLIC nvar       
-   PUBLIC spc_names  
+   PUBLIC spc_names
+   PUBLIC spec_conc_2  
 
 !- Interface section
Index: palm/trunk/SOURCE/flow_statistics.f90
===================================================================
--- palm/trunk/SOURCE/flow_statistics.f90	(revision 2772)
+++ palm/trunk/SOURCE/flow_statistics.f90	(revision 2773)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Timeseries output of surface temperature.
+! 
+! 2753 2018-01-16 14:16:49Z suehring
 ! Tile approach for spectral albedo implemented. 
 ! 
@@ -709,61 +712,76 @@
 !
 !--          2D-arrays (being collected in the last column of sums_l)
-             IF ( surf_def_h(0)%end_index(j,i) >=                                 &
+             IF ( surf_def_h(0)%end_index(j,i) >=                              &
                   surf_def_h(0)%start_index(j,i) )  THEN
                 m = surf_def_h(0)%start_index(j,i)
-                sums_l(nzb,pr_palm,tn)   = sums_l(nzb,pr_palm,tn) +               &
+                sums_l(nzb,pr_palm,tn)   = sums_l(nzb,pr_palm,tn) +            &
                                         surf_def_h(0)%us(m)   * rmask(j,i,sr)
-                sums_l(nzb+1,pr_palm,tn) = sums_l(nzb+1,pr_palm,tn) +             &
+                sums_l(nzb+1,pr_palm,tn) = sums_l(nzb+1,pr_palm,tn) +          &
                                         surf_def_h(0)%usws(m) * rmask(j,i,sr)
-                sums_l(nzb+2,pr_palm,tn) = sums_l(nzb+2,pr_palm,tn) +             &
+                sums_l(nzb+2,pr_palm,tn) = sums_l(nzb+2,pr_palm,tn) +          &
                                         surf_def_h(0)%vsws(m) * rmask(j,i,sr)
-                sums_l(nzb+3,pr_palm,tn) = sums_l(nzb+3,pr_palm,tn) +             &
+                sums_l(nzb+3,pr_palm,tn) = sums_l(nzb+3,pr_palm,tn) +          &
                                         surf_def_h(0)%ts(m)   * rmask(j,i,sr)
                 IF ( humidity )  THEN
-                   sums_l(nzb+12,pr_palm,tn) = sums_l(nzb+12,pr_palm,tn) +        &
+                   sums_l(nzb+12,pr_palm,tn) = sums_l(nzb+12,pr_palm,tn) +     &
                                             surf_def_h(0)%qs(m)   * rmask(j,i,sr)
                 ENDIF
                 IF ( passive_scalar )  THEN
-                   sums_l(nzb+13,pr_palm,tn) = sums_l(nzb+13,pr_palm,tn) +        &
+                   sums_l(nzb+13,pr_palm,tn) = sums_l(nzb+13,pr_palm,tn) +     &
                                             surf_def_h(0)%ss(m)   * rmask(j,i,sr)
                 ENDIF
+!
+!--             Summation of surface temperature.
+                sums_l(nzb+14,pr_palm,tn) = sums_l(nzb+14,pr_palm,tn)   +      &
+                                            surf_def_h(0)%pt_surface(m) *      &
+                                            rmask(j,i,sr)
              ENDIF
              IF ( surf_lsm_h%end_index(j,i) >= surf_lsm_h%start_index(j,i) )  THEN
                 m = surf_lsm_h%start_index(j,i)
-                sums_l(nzb,pr_palm,tn)   = sums_l(nzb,pr_palm,tn) +               &
+                sums_l(nzb,pr_palm,tn)   = sums_l(nzb,pr_palm,tn) +            &
                                         surf_lsm_h%us(m)   * rmask(j,i,sr)
-                sums_l(nzb+1,pr_palm,tn) = sums_l(nzb+1,pr_palm,tn) +             &
+                sums_l(nzb+1,pr_palm,tn) = sums_l(nzb+1,pr_palm,tn) +          &
                                         surf_lsm_h%usws(m) * rmask(j,i,sr)
-                sums_l(nzb+2,pr_palm,tn) = sums_l(nzb+2,pr_palm,tn) +             &
+                sums_l(nzb+2,pr_palm,tn) = sums_l(nzb+2,pr_palm,tn) +          &
                                         surf_lsm_h%vsws(m) * rmask(j,i,sr)
-                sums_l(nzb+3,pr_palm,tn) = sums_l(nzb+3,pr_palm,tn) +             &
+                sums_l(nzb+3,pr_palm,tn) = sums_l(nzb+3,pr_palm,tn) +          &
                                         surf_lsm_h%ts(m)   * rmask(j,i,sr)
                 IF ( humidity )  THEN
-                   sums_l(nzb+12,pr_palm,tn) = sums_l(nzb+12,pr_palm,tn) +        &
+                   sums_l(nzb+12,pr_palm,tn) = sums_l(nzb+12,pr_palm,tn) +     &
                                             surf_lsm_h%qs(m)   * rmask(j,i,sr)
                 ENDIF
                 IF ( passive_scalar )  THEN
-                   sums_l(nzb+13,pr_palm,tn) = sums_l(nzb+13,pr_palm,tn) +        &
+                   sums_l(nzb+13,pr_palm,tn) = sums_l(nzb+13,pr_palm,tn) +     &
                                             surf_lsm_h%ss(m)   * rmask(j,i,sr)
                 ENDIF
+!
+!--             Summation of surface temperature.
+                sums_l(nzb+14,pr_palm,tn) = sums_l(nzb+14,pr_palm,tn)   +      &
+                                            surf_lsm_h%pt_surface(m)    *      &
+                                            rmask(j,i,sr)
              ENDIF
              IF ( surf_usm_h%end_index(j,i) >= surf_usm_h%start_index(j,i) )  THEN
                 m = surf_usm_h%start_index(j,i)
-                sums_l(nzb,pr_palm,tn)   = sums_l(nzb,pr_palm,tn) +               &
+                sums_l(nzb,pr_palm,tn)   = sums_l(nzb,pr_palm,tn) +            &
                                         surf_usm_h%us(m)   * rmask(j,i,sr)
-                sums_l(nzb+1,pr_palm,tn) = sums_l(nzb+1,pr_palm,tn) +             &
+                sums_l(nzb+1,pr_palm,tn) = sums_l(nzb+1,pr_palm,tn) +          &
                                         surf_usm_h%usws(m) * rmask(j,i,sr)
-                sums_l(nzb+2,pr_palm,tn) = sums_l(nzb+2,pr_palm,tn) +             &
+                sums_l(nzb+2,pr_palm,tn) = sums_l(nzb+2,pr_palm,tn) +          &
                                         surf_usm_h%vsws(m) * rmask(j,i,sr)
-                sums_l(nzb+3,pr_palm,tn) = sums_l(nzb+3,pr_palm,tn) +             &
+                sums_l(nzb+3,pr_palm,tn) = sums_l(nzb+3,pr_palm,tn) +          &
                                         surf_usm_h%ts(m)   * rmask(j,i,sr)
                 IF ( humidity )  THEN
-                   sums_l(nzb+12,pr_palm,tn) = sums_l(nzb+12,pr_palm,tn) +        &
+                   sums_l(nzb+12,pr_palm,tn) = sums_l(nzb+12,pr_palm,tn) +     &
                                             surf_usm_h%qs(m)   * rmask(j,i,sr)
                 ENDIF
                 IF ( passive_scalar )  THEN
-                   sums_l(nzb+13,pr_palm,tn) = sums_l(nzb+13,pr_palm,tn) +        &
+                   sums_l(nzb+13,pr_palm,tn) = sums_l(nzb+13,pr_palm,tn) +     &
                                             surf_usm_h%ss(m)   * rmask(j,i,sr)
                 ENDIF
+!
+!--             Summation of surface temperature.
+                sums_l(nzb+14,pr_palm,tn) = sums_l(nzb+14,pr_palm,tn)   +      &
+                                            surf_usm_h%pt_surface(m)    *      &
+                                            rmask(j,i,sr)
              ENDIF
           ENDDO
@@ -1804,4 +1822,6 @@
                                     ngp_2dh(sr)
        sums(nzb+13,pr_palm)       = sums(nzb+13,pr_palm)       / &    ! ss
+                                    ngp_2dh(sr)
+       sums(nzb+14,pr_palm)       = sums(nzb+14,pr_palm)       / &    ! surface temperature
                                     ngp_2dh(sr)
 !--    eges, e*
@@ -2088,5 +2108,5 @@
        ts_value(15,sr) = hom(nzb+1,1,16,sr)         ! w'pt'   at k=1
        ts_value(16,sr) = hom(nzb+1,1,18,sr)         ! wpt     at k=1
-       ts_value(17,sr) = hom(nzb,1,4,sr)            ! pt(0)
+       ts_value(17,sr) = hom(nzb+14,1,pr_palm,sr)   ! pt(0)
        ts_value(18,sr) = hom(nzb+1,1,4,sr)          ! pt(zp)
        ts_value(19,sr) = hom(nzb+1,1,pr_palm,sr)    ! u'w'    at k=0
Index: palm/trunk/SOURCE/netcdf_data_input_mod.f90
===================================================================
--- palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 2772)
+++ palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 2773)
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! - Enable initialization with 3D topography.
+! - Move check for correct initialization in nesting mode to check_parameters.
+! 
+! 2772 2018-01-29 13:10:35Z suehring
 ! Initialization of simulation independent on land-surface model.
 ! 
@@ -1699,35 +1703,35 @@
 !--             If available, also read 3D building information. If both are
 !--             available, use 3D information.
-!                 IF ( check_existence( var_names, 'buildings_3D' ) )  THEN
-!                    buildings_f%from_file = .TRUE. 
-!                    CALL get_attribute( id_topo, char_lod, buildings_f%lod,     &
-!                                        .FALSE., 'buildings_3D' )     
-! 
-!                    CALL get_attribute( id_topo, char_fill,                     &
-!                                        buildings_f%fill2,                      &
-!                                        .FALSE., 'buildings_3D' )
-! 
-!                    CALL get_dimension_length( id_topo, buildings_f%nz, 'z' )
-!  
-!                    IF ( buildings_f%lod == 2 )  THEN
-!                       ALLOCATE( buildings_f%var_3d(nzb:buildings_f%nz,         &
-!                                                    nys:nyn,nxl:nxr) )
-!                       buildings_f%var_3d = 0
-! !
-! !--                   Read data PE-wise. Read yz-slices.
-!                       DO  i = nxl, nxr
-!                          DO  j = nys, nyn
-!                             CALL get_variable( id_topo, 'buildings_3D',        &
-!                                                i, j,                           &
-!                                                buildings_f%var_3d(:,j,i) )
-!                          ENDDO
-!                       ENDDO
-!                    ELSE 
-!                       message_string = 'NetCDF attribute lod ' //              &
-!                                        '(level of detail) is not set properly.'
-!                       CALL message( 'netcdf_data_input_mod', 'PA0999',         &
-!                                      1, 2, 0, 6, 0 )
-!                    ENDIF
-!                 ENDIF
+                IF ( check_existence( var_names, 'buildings_3D' ) )  THEN
+                   buildings_f%from_file = .TRUE. 
+                   CALL get_attribute( id_topo, char_lod, buildings_f%lod,     &
+                                       .FALSE., 'buildings_3D' )     
+
+                   CALL get_attribute( id_topo, char_fill,                     &
+                                       buildings_f%fill2,                      &
+                                       .FALSE., 'buildings_3D' )
+
+                   CALL get_dimension_length( id_topo, buildings_f%nz, 'z' )
+ 
+                   IF ( buildings_f%lod == 2 )  THEN
+                      ALLOCATE( buildings_f%var_3d(nzb:buildings_f%nz,         &
+                                                   nys:nyn,nxl:nxr) )
+                      buildings_f%var_3d = 0
+!
+!--                   Read data PE-wise. Read yz-slices.
+                      DO  i = nxl, nxr
+                         DO  j = nys, nyn
+                            CALL get_variable( id_topo, 'buildings_3D',        &
+                                               i, j,                           &
+                                               buildings_f%var_3d(:,j,i) )
+                         ENDDO
+                      ENDDO
+                   ELSE 
+                      message_string = 'NetCDF attribute lod ' //              &
+                                       '(level of detail) is not set properly.'
+                      CALL message( 'netcdf_data_input_mod', 'PA0999',         &
+                                     1, 2, 0, 6, 0 )
+                   ENDIF
+                ENDIF
 !
 !--             Read building IDs and its FillValue attribute. Further required 
@@ -2691,10 +2695,5 @@
            ONLY:  initializing_actions, forcing, message_string
 
-       USE pmc_interface,                                                      &
-           ONLY:  nested_run
-
        IMPLICIT NONE
-
-       LOGICAL      ::  check_nest !< flag indicating if a check passed 
 
 !
@@ -2714,26 +2713,4 @@
                            TRIM( coupling_char )
           CALL message( 'netcdf_data_input_mod', 'PA0430', 1, 2, 0, 6, 0 )
-       ENDIF
-!
-!--    In case of nested run assure that all domains are initialized the same
-!--    way, i.e. if at least at one domain is initialized with soil and 
-!--    atmospheric data provided by COSMO, all domains must be initialized the 
-!--    same way, to assure that soil and atmospheric quantities are 
-!--    consistent. 
-       IF ( nested_run )  THEN
-          check_nest = .TRUE.
-#if defined( __parallel )
-          CALL MPI_ALLREDUCE( TRIM( initializing_actions ) == 'inifor',        &
-                              check_nest, 1, MPI_LOGICAL,                      &
-                              MPI_LAND, MPI_COMM_WORLD, ierr )
-
-          IF ( TRIM( initializing_actions ) == 'inifor'  .AND.                 &
-               .NOT.  check_nest )  THEN
-             message_string = 'In case of nesting, if at least in one ' //     &
-                              'domain initializing_actions = inifor, '  //     &
-                              'all domains need to be initialized that way.'
-             CALL message( 'netcdf_data_input_mod', 'PA0430', 3, 2, 0, 6, 0 )
-          ENDIF
-#endif
        ENDIF
 
Index: palm/trunk/SOURCE/parin.f90
===================================================================
--- palm/trunk/SOURCE/parin.f90	(revision 2772)
+++ palm/trunk/SOURCE/parin.f90	(revision 2773)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Nesting for chemical species implemented
+! 
+! 2766 2018-01-22 17:17:47Z kanani
 ! Removed preprocessor directive __chem
 ! 
@@ -617,35 +620,35 @@
              ENDIF
              IF ( nest_domain )  THEN
-                bc_uv_t = 'nested'
-                bc_pt_t = 'nested'
-                bc_q_t  = 'nested'
-                bc_s_t  = 'nested'
-                bc_p_t  = 'neumann'
-             ENDIF
-          ELSE
-          
+                bc_uv_t  = 'nested'
+                bc_pt_t  = 'nested'
+                bc_q_t   = 'nested'
+                bc_s_t   = 'nested'
+                bc_cs_t  = 'nested'
+                bc_p_t   = 'neumann'  
+             ENDIF        
 !
 !--       For other nesting modes only set boundary conditions for 
 !--       nested domains.
              IF ( nest_domain )  THEN
-                bc_lr   = 'nested'
-                bc_ns   = 'nested'
-                bc_uv_t = 'nested'
-                bc_pt_t = 'nested'
-                bc_q_t  = 'nested'
-                bc_s_t  = 'nested'
-                bc_p_t  = 'neumann'
+                bc_lr    = 'nested'
+                bc_ns    = 'nested'
+                bc_uv_t  = 'nested'
+                bc_pt_t  = 'nested'
+                bc_q_t   = 'nested'
+                bc_s_t   = 'nested'
+                bc_cs_t = 'nested'
+                bc_p_t   = 'neumann'
              ENDIF
           ENDIF
 
           IF ( forcing )  THEN
-             bc_lr   = 'forcing'
-             bc_ns   = 'forcing'
-             bc_uv_t = 'forcing'
-             bc_pt_t = 'forcing'
-             bc_q_t  = 'forcing'
-             bc_s_t  = 'forcing'  ! scalar boundary condition is not clear
-             bc_p_t  = 'neumann'
-
+             bc_lr    = 'forcing'
+             bc_ns    = 'forcing'
+             bc_uv_t  = 'forcing'
+             bc_pt_t  = 'forcing'
+             bc_q_t   = 'forcing'
+             bc_s_t   = 'forcing'  ! scalar boundary condition is not clear
+             bc_cs_t  = 'forcing'  ! same for chemical species
+             bc_p_t   = 'neumann'
           ENDIF
 
Index: palm/trunk/SOURCE/pmc_interface_mod.f90
===================================================================
--- palm/trunk/SOURCE/pmc_interface_mod.f90	(revision 2772)
+++ palm/trunk/SOURCE/pmc_interface_mod.f90	(revision 2773)
@@ -25,4 +25,10 @@
 ! -----------------
 ! $Id$
+! - Nesting for chemical species
+! - Bugfix in setting boundary condition at downward-facing walls for passive
+!   scalar
+! - Some formatting adjustments
+! 
+! 2718 2018-01-02 08:49:38Z maronga
 ! Corrected "Former revisions" section
 ! 
@@ -220,5 +226,5 @@
 
     USE control_parameters,                                                     &
-        ONLY:  cloud_physics, coupling_char, dt_3d, dz, humidity,               &
+        ONLY:  air_chemistry, cloud_physics, coupling_char, dt_3d, dz, humidity,&
                message_string, microphysics_morrison, microphysics_seifert,     &
                nest_bound_l, nest_bound_r, nest_bound_s, nest_bound_n,          &
@@ -226,12 +232,18 @@
                simulated_time, topography, volume_flow
 
-    USE cpulog,                                                                 &
+    USE chem_modules,                                                          &
+        ONLY:  nspec
+
+    USE chemistry_model_mod,                                                   &
+        ONLY:  chem_species, spec_conc_2
+
+    USE cpulog,                                                                &
         ONLY:  cpu_log, log_point_s
 
-    USE grid_variables,                                                         &
+    USE grid_variables,                                                        &
         ONLY:  dx, dy
 
-    USE indices,                                                                &
-        ONLY:  nbgp, nx, nxl, nxlg, nxlu, nxr, nxrg, ny, nyn, nyng, nys, nysg,  &
+    USE indices,                                                               &
+        ONLY:  nbgp, nx, nxl, nxlg, nxlu, nxr, nxrg, ny, nyn, nyng, nys, nysg, &
                nysv, nz, nzb, nzt, wall_flags_0
 
@@ -245,34 +257,34 @@
 #endif
 
-    USE pegrid,                                                                 &
-        ONLY:  collective_wait, comm1dx, comm1dy, comm2d, myid, myidx, myidy,   &
+    USE pegrid,                                                                &
+        ONLY:  collective_wait, comm1dx, comm1dy, comm2d, myid, myidx, myidy,  &
                numprocs
 
-    USE pmc_child,                                                              &
-        ONLY:  pmc_childinit, pmc_c_clear_next_array_list,                      &
-               pmc_c_getnextarray, pmc_c_get_2d_index_list, pmc_c_getbuffer,    &
-               pmc_c_putbuffer, pmc_c_setind_and_allocmem,                      &
+    USE pmc_child,                                                             &
+        ONLY:  pmc_childinit, pmc_c_clear_next_array_list,                     &
+               pmc_c_getnextarray, pmc_c_get_2d_index_list, pmc_c_getbuffer,   &
+               pmc_c_putbuffer, pmc_c_setind_and_allocmem,                     &
                pmc_c_set_dataarray, pmc_set_dataarray_name
 
-    USE pmc_general,                                                            &
+    USE pmc_general,                                                           &
         ONLY:  da_namelen
 
-    USE pmc_handle_communicator,                                                &
-        ONLY:  pmc_get_model_info, pmc_init_model, pmc_is_rootmodel,            &
+    USE pmc_handle_communicator,                                               &
+        ONLY:  pmc_get_model_info, pmc_init_model, pmc_is_rootmodel,           &
                pmc_no_namelist_found, pmc_parent_for_child
 
-    USE pmc_mpi_wrapper,                                                        &
-        ONLY:  pmc_bcast, pmc_recv_from_child, pmc_recv_from_parent,            &
+    USE pmc_mpi_wrapper,                                                       &
+        ONLY:  pmc_bcast, pmc_recv_from_child, pmc_recv_from_parent,           &
                pmc_send_to_child, pmc_send_to_parent
 
-    USE pmc_parent,                                                             &
-        ONLY:  pmc_parentinit, pmc_s_clear_next_array_list, pmc_s_fillbuffer,   &
-               pmc_s_getdata_from_buffer, pmc_s_getnextarray,                   &
-               pmc_s_setind_and_allocmem, pmc_s_set_active_data_array,          &
+    USE pmc_parent,                                                            &
+        ONLY:  pmc_parentinit, pmc_s_clear_next_array_list, pmc_s_fillbuffer,  &
+               pmc_s_getdata_from_buffer, pmc_s_getnextarray,                  &
+               pmc_s_setind_and_allocmem, pmc_s_set_active_data_array,         &
                pmc_s_set_dataarray, pmc_s_set_2d_index_list
 
 #endif
 
-    USE surface_mod,                                                            &
+    USE surface_mod,                                                           &
         ONLY:  get_topography_top_index_ji, surf_def_h, surf_lsm_h, surf_usm_h
 
@@ -338,4 +350,7 @@
     REAL(wp), SAVE, DIMENSION(:,:,:), ALLOCATABLE, TARGET ::  ncc  !:
     REAL(wp), SAVE, DIMENSION(:,:,:), ALLOCATABLE, TARGET ::  sc   !:
+
+    REAL(wp), SAVE, DIMENSION(:,:,:,:), ALLOCATABLE, TARGET ::  chem_spec_c   !< child coarse data array for chemical species 
+
 !
 !-- Child interpolation coefficients and child-array indices to be 
@@ -651,4 +666,5 @@
     INTEGER(iwp) ::  m                !:
     INTEGER(iwp) ::  mm               !:
+    INTEGER(iwp) ::  n = 1            !< running index for chemical species
     INTEGER(iwp) ::  nest_overlap     !:
     INTEGER(iwp) ::  nomatch          !:
@@ -836,6 +852,12 @@
        CALL pmc_s_clear_next_array_list
        DO  WHILE ( pmc_s_getnextarray( child_id, myname ) )
-          CALL pmci_set_array_pointer( myname, child_id = child_id,             &
-                                       nz_cl = nz_cl )
+          IF ( INDEX( TRIM( myname ), 'chem_' ) /= 0 )  THEN             
+             CALL pmci_set_array_pointer( myname, child_id = child_id,         &
+                                          nz_cl = nz_cl, n = n )
+             n = n + 1
+          ELSE
+             CALL pmci_set_array_pointer( myname, child_id = child_id,         &
+                                          nz_cl = nz_cl )
+          ENDIF
        ENDDO
        CALL pmc_s_setind_and_allocmem( child_id )
@@ -965,16 +987,18 @@
  SUBROUTINE pmci_setup_child
 
+
 #if defined( __parallel )
     IMPLICIT NONE
 
-    CHARACTER(LEN=da_namelen) ::  myname     !:
-
-    INTEGER(iwp) ::  i          !:
-    INTEGER(iwp) ::  ierr       !:
-    INTEGER(iwp) ::  icl        !:
-    INTEGER(iwp) ::  icr        !:
-    INTEGER(iwp) ::  j          !:
-    INTEGER(iwp) ::  jcn        !:
-    INTEGER(iwp) ::  jcs        !:
+    CHARACTER(LEN=da_namelen) ::  myname     !<
+
+    INTEGER(iwp) ::  i          !<
+    INTEGER(iwp) ::  ierr       !<
+    INTEGER(iwp) ::  icl        !<
+    INTEGER(iwp) ::  icr        !<
+    INTEGER(iwp) ::  j          !<
+    INTEGER(iwp) ::  jcn        !<
+    INTEGER(iwp) ::  jcs        !<
+    INTEGER(iwp) ::  n          !< running index for number of chemical species
 
     INTEGER(iwp), DIMENSION(5) ::  val        !:
@@ -1028,4 +1052,16 @@
        IF ( passive_scalar )  THEN
           CALL pmc_set_dataarray_name( 'coarse', 's'  ,'fine', 's',  ierr )
+       ENDIF
+
+       IF ( air_chemistry )  THEN
+          DO  n = 1, nspec
+             CALL pmc_set_dataarray_name( 'coarse',                            &
+                                          'chem_' //                           &
+                                          TRIM( chem_species(n)%name ),        &
+                                         'fine',                               &
+                                          'chem_' //                           &
+                                          TRIM( chem_species(n)%name ),        &
+                                          ierr )
+          ENDDO 
        ENDIF
 
@@ -1116,8 +1152,20 @@
 !--    TO_DO: Klaus: better explain the above comment (what is child content?)
        CALL  pmc_c_clear_next_array_list
+
+       n = 1
        DO  WHILE ( pmc_c_getnextarray( myname ) )
 !--       Note that cg%nz is not th eoriginal nz of parent, but the highest
-!--       parent-grid level needed for nesting.           
-          CALL pmci_create_child_arrays ( myname, icl, icr, jcs, jcn, cg%nz )
+!--       parent-grid level needed for nesting.
+!--       Please note, in case of chemical species an additional parameter
+!--       need to be passed, which is required to set the pointer correctly
+!--       to the chemical-species data structure. Hence, first check if current
+!--       variable is a chemical species. If so, pass index id of respective
+!--       species and increment this subsequently.
+          IF ( INDEX( TRIM( myname ), 'chem_' ) /= 0 )  THEN             
+             CALL pmci_create_child_arrays ( myname, icl, icr, jcs, jcn, cg%nz, n )
+             n = n + 1
+          ELSE
+             CALL pmci_create_child_arrays ( myname, icl, icr, jcs, jcn, cg%nz )
+          ENDIF
        ENDDO
        CALL pmc_c_setind_and_allocmem
@@ -2785,5 +2833,5 @@
 
 
- SUBROUTINE pmci_set_array_pointer( name, child_id, nz_cl )
+ SUBROUTINE pmci_set_array_pointer( name, child_id, nz_cl, n )
 
     IMPLICIT NONE
@@ -2791,4 +2839,6 @@
     INTEGER, INTENT(IN)          ::  child_id    !:
     INTEGER, INTENT(IN)          ::  nz_cl       !:
+    INTEGER, INTENT(IN),OPTIONAL ::  n           !< index of chemical species
+
     CHARACTER(LEN=*), INTENT(IN) ::  name        !:
 
@@ -2819,4 +2869,6 @@
     IF ( TRIM(name) == "nc" )  p_3d => nc
     IF ( TRIM(name) == "s"  )  p_3d => s
+    IF ( INDEX( TRIM(name), "chem_" ) /= 0 )  p_3d => chem_species(n)%conc
+
 !
 !-- Next line is just an example for a 2D array (not active for coupling!)
@@ -2855,4 +2907,5 @@
     IF ( TRIM(name) == "nc" )  p_3d_sec => nc_2
     IF ( TRIM(name) == "s"  )  p_3d_sec => s_2
+    IF ( INDEX( TRIM(name), "chem_" ) /= 0 )  p_3d_sec => spec_conc_2(:,:,:,n)
 
     IF ( ASSOCIATED( p_3d ) )  THEN
@@ -2883,5 +2936,5 @@
 
 
- SUBROUTINE pmci_create_child_arrays( name, is, ie, js, je, nzc  )
+ SUBROUTINE pmci_create_child_arrays( name, is, ie, js, je, nzc, n )
 
     IMPLICIT NONE
@@ -2895,4 +2948,6 @@
     INTEGER(iwp), INTENT(IN) ::  nzc     !:  Note that nzc is cg%nz
 
+    INTEGER(iwp), INTENT(IN), OPTIONAL ::  n  !< number of chemical species
+
 #if defined( __parallel )
     INTEGER(iwp) ::  ierr    !:
@@ -2908,36 +2963,40 @@
 !-- List of array names, which can be coupled
     IF ( TRIM( name ) == "u" )  THEN
-       IF ( .NOT. ALLOCATED( uc ) )  ALLOCATE( uc(0:nzc+1, js:je, is:ie) )
+       IF ( .NOT. ALLOCATED( uc ) )  ALLOCATE( uc(0:nzc+1,js:je,is:ie) )
        p_3d => uc
     ELSEIF ( TRIM( name ) == "v" )  THEN
-       IF ( .NOT. ALLOCATED( vc ) )  ALLOCATE( vc(0:nzc+1, js:je, is:ie) )
+       IF ( .NOT. ALLOCATED( vc ) )  ALLOCATE( vc(0:nzc+1,js:je,is:ie) )
        p_3d => vc
     ELSEIF ( TRIM( name ) == "w" )  THEN
-       IF ( .NOT. ALLOCATED( wc ) )  ALLOCATE( wc(0:nzc+1, js:je, is:ie) )
+       IF ( .NOT. ALLOCATED( wc ) )  ALLOCATE( wc(0:nzc+1,js:je,is:ie) )
        p_3d => wc
     ELSEIF ( TRIM( name ) == "e" )  THEN
-       IF ( .NOT. ALLOCATED( ec ) )  ALLOCATE( ec(0:nzc+1, js:je, is:ie) )
+       IF ( .NOT. ALLOCATED( ec ) )  ALLOCATE( ec(0:nzc+1,js:je,is:ie) )
        p_3d => ec
     ELSEIF ( TRIM( name ) == "pt")  THEN
-       IF ( .NOT. ALLOCATED( ptc ) ) ALLOCATE( ptc(0:nzc+1, js:je, is:ie) )
+       IF ( .NOT. ALLOCATED( ptc ) )  ALLOCATE( ptc(0:nzc+1,js:je,is:ie) )
        p_3d => ptc
     ELSEIF ( TRIM( name ) == "q")  THEN
-       IF ( .NOT. ALLOCATED( q_c ) ) ALLOCATE( q_c(0:nzc+1, js:je, is:ie) )
+       IF ( .NOT. ALLOCATED( q_c ) )  ALLOCATE( q_c(0:nzc+1,js:je,is:ie) )
        p_3d => q_c
     ELSEIF ( TRIM( name ) == "qc")  THEN
-       IF ( .NOT. ALLOCATED( qcc ) ) ALLOCATE( qcc(0:nzc+1, js:je, is:ie) )
+       IF ( .NOT. ALLOCATED( qcc ) )  ALLOCATE( qcc(0:nzc+1,js:je,is:ie) )
        p_3d => qcc
     ELSEIF ( TRIM( name ) == "qr")  THEN
-       IF ( .NOT. ALLOCATED( qrc ) ) ALLOCATE( qrc(0:nzc+1, js:je, is:ie) )
+       IF ( .NOT. ALLOCATED( qrc ) )  ALLOCATE( qrc(0:nzc+1,js:je,is:ie) )
        p_3d => qrc
     ELSEIF ( TRIM( name ) == "nr")  THEN
-       IF ( .NOT. ALLOCATED( nrc ) ) ALLOCATE( nrc(0:nzc+1, js:je, is:ie) )
+       IF ( .NOT. ALLOCATED( nrc ) )  ALLOCATE( nrc(0:nzc+1,js:je,is:ie) )
        p_3d => nrc
     ELSEIF ( TRIM( name ) == "nc")  THEN
-       IF ( .NOT. ALLOCATED( ncc ) ) ALLOCATE( ncc(0:nzc+1, js:je, is:ie) )
+       IF ( .NOT. ALLOCATED( ncc ) )  ALLOCATE( ncc(0:nzc+1,js:je,is:ie) )
        p_3d => ncc
     ELSEIF ( TRIM( name ) == "s")  THEN
-       IF ( .NOT. ALLOCATED( sc ) ) ALLOCATE( sc(0:nzc+1, js:je, is:ie) )
+       IF ( .NOT. ALLOCATED( sc ) )  ALLOCATE( sc(0:nzc+1,js:je,is:ie) )
        p_3d => sc
+    ELSEIF ( TRIM( name(1:5) ) == "chem_" )  THEN
+       IF ( .NOT. ALLOCATED( chem_spec_c ) )                                   &
+          ALLOCATE( chem_spec_c(0:nzc+1,js:je,is:ie,1:nspec) )
+       p_3d => chem_spec_c(:,:,:,n)
     !ELSEIF (trim(name) == "z0") then
        !IF (.not.allocated(z0c))  allocate(z0c(js:je, is:ie))
@@ -3001,13 +3060,14 @@
     IMPLICIT NONE
 
-    INTEGER(iwp) ::  i          !:
-    INTEGER(iwp) ::  icl        !:
-    INTEGER(iwp) ::  icr        !:
-    INTEGER(iwp) ::  j          !:
-    INTEGER(iwp) ::  jcn        !:
-    INTEGER(iwp) ::  jcs        !:
-    INTEGER(iwp) ::  k          !:
-
-    REAL(wp) ::  waittime       !:
+    INTEGER(iwp) ::  i          !<
+    INTEGER(iwp) ::  icl        !<
+    INTEGER(iwp) ::  icr        !<
+    INTEGER(iwp) ::  j          !<
+    INTEGER(iwp) ::  jcn        !<
+    INTEGER(iwp) ::  jcs        !<
+    INTEGER(iwp) ::  k          !< 
+    INTEGER(iwp) ::  n          !< running index for chemical species
+
+    REAL(wp) ::  waittime       !<
 
 !
@@ -3063,4 +3123,13 @@
           CALL pmci_interp_tril_all ( s, sc, ico, jco, kco, r1xo, r2xo, r1yo,   &
                                       r2yo, r1zo, r2zo, 's' )
+       ENDIF
+
+       IF ( air_chemistry )  THEN
+          DO  n = 1, nspec
+             CALL pmci_interp_tril_all ( chem_species(n)%conc,                 &
+                                         chem_spec_c(:,:,:,n),                 &
+                                         ico, jco, kco, r1xo, r2xo, r1yo,      &
+                                         r2yo, r1zo, r2zo, 's' )
+          ENDDO
        ENDIF
 
@@ -3707,4 +3776,6 @@
       
        IMPLICIT NONE
+
+       INTEGER(iwp) ::  n          !< running index for number of chemical species
       
 !
@@ -3787,4 +3858,15 @@
              ENDIF
 
+             IF ( air_chemistry )  THEN
+                DO  n = 1, nspec
+                   CALL pmci_interp_tril_lr( chem_species(n)%conc,              &
+                                             chem_spec_c(:,:,:,n),              &
+                                             ico, jco, kco, r1xo, r2xo,         &
+                                             r1yo, r2yo, r1zo, r2zo,            &
+                                             logc_u_l, logc_ratio_u_l,          &
+                                             nzt_topo_nestbc_l, 'l', 's' )
+                ENDDO
+             ENDIF
+
              IF ( TRIM( nesting_mode ) == 'one-way' )  THEN
                 CALL pmci_extrap_ifoutflow_lr( u, 'l', 'u' )
@@ -3818,4 +3900,11 @@
                 IF ( passive_scalar )  THEN
                    CALL pmci_extrap_ifoutflow_lr( s, 'l', 's' )
+                ENDIF
+
+                IF ( air_chemistry )  THEN
+                   DO  n = 1, nspec
+                      CALL pmci_extrap_ifoutflow_lr( chem_species(n)%conc,     &
+                                                     'l', 's' )
+                   ENDDO
                 ENDIF
 
@@ -3903,4 +3992,15 @@
                                           nzt_topo_nestbc_r, 'r', 's' )
 
+             IF ( air_chemistry )  THEN
+                DO  n = 1, nspec
+                   CALL pmci_interp_tril_lr( chem_species(n)%conc,             &
+                                             chem_spec_c(:,:,:,n),             &
+                                             ico, jco, kco, r1xo, r2xo,        &
+                                             r1yo, r2yo, r1zo, r2zo,           &
+                                             logc_u_r, logc_ratio_u_r,         &
+                                             nzt_topo_nestbc_r, 'r', 's' )
+                ENDDO
+             ENDIF
+
              ENDIF
 
@@ -3932,4 +4032,11 @@
                 IF ( passive_scalar )  THEN
                    CALL pmci_extrap_ifoutflow_lr( s, 'r', 's' )
+                ENDIF
+
+                IF ( air_chemistry )  THEN
+                   DO  n = 1, nspec
+                      CALL pmci_extrap_ifoutflow_lr( chem_species(n)%conc,     &
+                                                     'r', 's' )
+                   ENDDO
                 ENDIF
              ENDIF
@@ -4010,4 +4117,15 @@
              ENDIF
 
+             IF ( air_chemistry )  THEN
+                DO  n = 1, nspec
+                   CALL pmci_interp_tril_sn( chem_species(n)%conc,              &
+                                             chem_spec_c(:,:,:,n),              &
+                                             ico, jco, kco, r1xo, r2xo,         &
+                                             r1yo, r2yo, r1zo, r2zo,            &
+                                             logc_u_s, logc_ratio_u_s,          &
+                                             nzt_topo_nestbc_s, 's', 's' )
+                ENDDO
+             ENDIF
+
              IF ( TRIM( nesting_mode ) == 'one-way' )  THEN
                 CALL pmci_extrap_ifoutflow_sn( u, 's', 'u' )
@@ -4038,4 +4156,11 @@
                 IF ( passive_scalar )  THEN
                    CALL pmci_extrap_ifoutflow_sn( s,  's', 's' )
+                ENDIF
+
+                IF ( air_chemistry )  THEN
+                   DO  n = 1, nspec
+                      CALL pmci_extrap_ifoutflow_sn( chem_species(n)%conc,     &
+                                                     's', 's' )
+                   ENDDO
                 ENDIF
 
@@ -4120,4 +4245,15 @@
              ENDIF
 
+             IF ( air_chemistry )  THEN
+                DO  n = 1, nspec
+                   CALL pmci_interp_tril_sn( chem_species(n)%conc,              &
+                                             chem_spec_c(:,:,:,n),              &
+                                             ico, jco, kco, r1xo, r2xo,         &
+                                             r1yo, r2yo, r1zo, r2zo,            &
+                                             logc_u_n, logc_ratio_u_n,          &
+                                             nzt_topo_nestbc_n, 'n', 's' )
+                ENDDO
+             ENDIF
+
              IF ( TRIM( nesting_mode ) == 'one-way' )  THEN
                 CALL pmci_extrap_ifoutflow_sn( u, 'n', 'u' )
@@ -4147,4 +4283,11 @@
                 IF ( passive_scalar )  THEN
                    CALL pmci_extrap_ifoutflow_sn( s,  'n', 's' )
+                ENDIF
+
+                IF ( air_chemistry )  THEN
+                   DO  n = 1, nspec
+                      CALL pmci_extrap_ifoutflow_sn( chem_species(n)%conc,     &
+                                                     'n', 's' )
+                   ENDDO
                 ENDIF
 
@@ -4203,4 +4346,14 @@
        ENDIF
 
+       IF ( air_chemistry )  THEN
+          DO  n = 1, nspec
+             CALL pmci_interp_tril_t( chem_species(n)%conc,                    &
+                                      chem_spec_c(:,:,:,n),                    &
+                                      ico, jco, kco, r1xo, r2xo,               &
+                                      r1yo, r2yo, r1zo, r2zo,                  &
+                                      's' )
+          ENDDO
+       ENDIF
+
        IF ( TRIM( nesting_mode ) == 'one-way' )  THEN
 
@@ -4235,4 +4388,10 @@
           ENDIF
 
+          IF ( air_chemistry )  THEN
+             DO  n = 1, nspec
+                CALL pmci_extrap_ifoutflow_t( chem_species(n)%conc, 's' )
+             ENDDO
+          ENDIF
+
        ENDIF
 
@@ -4247,4 +4406,8 @@
 !--   Note that TKE is not anterpolated.
       IMPLICIT NONE
+
+      INTEGER(iwp) ::  n          !< running index for number of chemical species
+
+
 
       CALL pmci_anterp_tophat( u,  uc,  kctu, iflu, ifuu, jflo, jfuo, kflo,    &
@@ -4290,4 +4453,13 @@
          CALL pmci_anterp_tophat( s, sc, kctu, iflo, ifuo, jflo, jfuo, kflo,   &
                                   kfuo, ijfc_s, kfc_s, 's' )
+      ENDIF
+
+      IF ( air_chemistry )  THEN
+         DO  n = 1, nspec
+            CALL pmci_anterp_tophat( chem_species(n)%conc,                     &
+                                     chem_spec_c(:,:,:,n),                     &
+                                     kctu, iflo, ifuo, jflo, jfuo, kflo,       &
+                                     kfuo, ijfc_s, kfc_s, 's' )
+         ENDDO
       ENDIF
 
@@ -5201,4 +5373,7 @@
  SUBROUTINE pmci_boundary_conds
 
+    USE chem_modules,                                                          &
+        ONLY:  ibc_cs_b
+
     USE control_parameters,                                                    &
         ONLY:  ibc_pt_b, ibc_q_b, ibc_s_b, ibc_uv_b
@@ -5213,4 +5388,5 @@
     INTEGER(iwp) ::  k  !< Index along z-direction
     INTEGER(iwp) ::  m  !< Running index for surface type
+    INTEGER(iwp) ::  n  !< running index for number of chemical species
     
 !
@@ -5338,8 +5514,28 @@
              j = bc_h(1)%j(m)
              k = bc_h(1)%k(m)
-             s(k-1,j,i) = s(k,j,i)
+             s(k+1,j,i) = s(k,j,i)
           ENDDO  
        ENDIF
     ENDIF
+!
+!-- Set Neumann boundary conditions for chemical species
+    IF ( air_chemistry )  THEN
+       IF ( ibc_cs_b == 1 )  THEN
+          DO  n = 1, nspec
+             DO  m = 1, bc_h(0)%ns
+                i = bc_h(0)%i(m)            
+                j = bc_h(0)%j(m)
+                k = bc_h(0)%k(m)
+                chem_species(n)%conc(k-1,j,i) = chem_species(n)%conc(k,j,i)
+             ENDDO 
+             DO  m = 1, bc_h(1)%ns
+                i = bc_h(1)%i(m)            
+                j = bc_h(1)%j(m)
+                k = bc_h(1)%k(m)
+                chem_species(n)%conc(k+1,j,i) = chem_species(n)%conc(k,j,i)
+             ENDDO
+          ENDDO
+       ENDIF
+    ENDIF
 
  END SUBROUTINE pmci_boundary_conds
Index: palm/trunk/SOURCE/time_integration.f90
===================================================================
--- palm/trunk/SOURCE/time_integration.f90	(revision 2772)
+++ palm/trunk/SOURCE/time_integration.f90	(revision 2773)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! - Nesting for chemical species
+! 
+! 2766 2018-01-22 17:17:47Z kanani
 ! Removed preprocessor directive __chem
 ! 
@@ -756,4 +759,11 @@
                 IF ( passive_scalar )  CALL exchange_horiz( s, nbgp )
                 IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e, nbgp )
+
+                IF ( air_chemistry )  THEN
+                   DO  n = 1, nspec     
+                      CALL exchange_horiz( chem_species(n)%conc, nbgp ) 
+                   ENDDO
+                ENDIF
+
              ENDIF
 !
