Index: palm/trunk/SOURCE/chemistry_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/chemistry_model_mod.f90	(revision 3878)
+++ palm/trunk/SOURCE/chemistry_model_mod.f90	(revision 3879)
@@ -289,5 +289,5 @@
 
     USE indices,                                                                                   &
-         ONLY:  nz, nzb, nzt, nysg, nyng, nxlg, nxrg, nys, nyn, nx, nxl, nxr, ny, wall_flags_0
+         ONLY:  nbgp, nz, nzb, nzt, nysg, nyng, nxlg, nxrg, nys, nyn, nx, nxl, nxr, ny, wall_flags_0
 
     USE pegrid,                                                                                    &
@@ -429,6 +429,9 @@
     INTERFACE chem_boundary_conds
        MODULE PROCEDURE chem_boundary_conds
+    END INTERFACE chem_boundary_conds
+
+    INTERFACE chem_boundary_conds_decycle
        MODULE PROCEDURE chem_boundary_conds_decycle
-    END INTERFACE chem_boundary_conds
+    END INTERFACE chem_boundary_conds_decycle
 
     INTERFACE chem_check_data_output
@@ -585,5 +588,6 @@
 
 
-    PUBLIC chem_3d_data_averaging, chem_boundary_conds, chem_check_data_output, &
+    PUBLIC chem_3d_data_averaging, chem_boundary_conds,                       &
+            chem_boundary_conds_decycle, chem_check_data_output,              &
          chem_check_data_output_pr, chem_check_parameters,                    &
          chem_data_output_2d, chem_data_output_3d, chem_data_output_mask,     &
@@ -871,5 +875,5 @@
 !> x-direction
 !------------------------------------------------------------------------------!
- SUBROUTINE chem_boundary_conds_decycle( cs_3d, cs_pr_init )
+ SUBROUTINE chem_boundary_conds_decycle()
 !
 !-- Decycling of chemistry variables: Dirichlet BCs with cyclic is frequently not
@@ -887,138 +891,163 @@
     INTEGER(iwp) ::  k         !< 
     INTEGER(iwp) ::  ss        !< 
+    INTEGER(iwp) ::  lsp       !<
+    INTEGER(iwp) ::  lsp_usr   !<
     REAL(wp), DIMENSION(nzb:nzt+1) ::  cs_pr_init
     REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  cs_3d
     REAL(wp) ::  flag !< flag to mask topography grid points
 
-    flag = 0.0_wp
-!
-!-- Left and right boundaries
-    IF ( decycle_chem_lr  .AND.  bc_lr_cyc )  THEN
-
-       DO  boundary = 1, 2
-
-          IF ( decycle_method(boundary) == 'dirichlet' )  THEN
-!    
-!--          Initial profile is copied to ghost and first three layers          
-             ss = 1
-             ee = 0
-             IF ( boundary == 1  .AND.  nxl == 0 )  THEN
-                ss = nxlg
-                ee = nxl+2
-             ELSEIF ( boundary == 2  .AND.  nxr == nx )  THEN
-                ss = nxr-2
-                ee = nxrg
+    CALL cpu_log( log_point_s(84), 'chem.exch-horiz', 'start' )
+
+    DO  lsp = 1, nspec
+
+       CALL exchange_horiz( chem_species(lsp)%conc_p, nbgp )
+       lsp_usr = 1
+       DO WHILE ( TRIM( cs_name( lsp_usr ) ) /= 'novalue' )
+          IF ( TRIM(chem_species(lsp)%name) == TRIM(cs_name(lsp_usr)) )  THEN
+
+             cs_3d = chem_species(lsp)%conc_p
+             cs_pr_init = chem_species(lsp)%conc_pr_init
+
+             flag = 0.0_wp
+         !
+         !-- Left and right boundaries
+             IF ( decycle_chem_lr  .AND.  bc_lr_cyc )  THEN
+
+                DO  boundary = 1, 2
+
+                   IF ( decycle_method(boundary) == 'dirichlet' )  THEN
+         !
+         !--          Initial profile is copied to ghost and first three layers
+                      ss = 1
+                      ee = 0
+                      IF ( boundary == 1  .AND.  nxl == 0 )  THEN
+                         ss = nxlg
+                         ee = nxl+2
+                      ELSEIF ( boundary == 2  .AND.  nxr == nx )  THEN
+                         ss = nxr-2
+                         ee = nxrg
+                      ENDIF
+
+                      DO  i = ss, ee
+                         DO  j = nysg, nyng
+                            DO  k = nzb+1, nzt
+                               flag = MERGE( 1.0_wp, 0.0_wp,                            &
+                                             BTEST( wall_flags_0(k,j,i), 0 ) )
+                               cs_3d(k,j,i) = cs_pr_init(k) * flag
+                            ENDDO
+                         ENDDO
+                      ENDDO
+
+                 ELSEIF ( decycle_method(boundary) == 'neumann' )  THEN
+         !
+         !--          The value at the boundary is copied to the ghost layers to simulate
+         !--          an outlet with zero gradient
+                      ss = 1
+                      ee = 0
+                      IF ( boundary == 1  .AND.  nxl == 0 )  THEN
+                         ss = nxlg
+                         ee = nxl-1
+                         copied = nxl
+                      ELSEIF ( boundary == 2  .AND.  nxr == nx )  THEN
+                         ss = nxr+1
+                         ee = nxrg
+                         copied = nxr
+                      ENDIF
+
+                       DO  i = ss, ee
+                         DO  j = nysg, nyng
+                            DO  k = nzb+1, nzt
+                               flag = MERGE( 1.0_wp, 0.0_wp,                            &
+                                             BTEST( wall_flags_0(k,j,i), 0 ) )
+                              cs_3d(k,j,i) = cs_3d(k,j,copied) * flag
+                            ENDDO
+                         ENDDO
+                      ENDDO
+
+                   ELSE
+                      WRITE(message_string,*)                                           &
+                                          'unknown decycling method: decycle_method (', &
+                              boundary, ') ="' // TRIM( decycle_method(boundary) ) // '"'
+                      CALL message( 'chem_boundary_conds_decycle', 'CM0431',           &
+                                    1, 2, 0, 6, 0 )
+                   ENDIF
+                ENDDO
              ENDIF
-
-             DO  i = ss, ee
-                DO  j = nysg, nyng
-                   DO  k = nzb+1, nzt
-                      flag = MERGE( 1.0_wp, 0.0_wp,                            &
-                                    BTEST( wall_flags_0(k,j,i), 0 ) )
-                      cs_3d(k,j,i) = cs_pr_init(k) * flag
-                   ENDDO
+         !
+         !-- South and north boundaries
+             IF ( decycle_chem_ns  .AND.  bc_ns_cyc )  THEN
+
+                DO  boundary = 3, 4
+
+                   IF ( decycle_method(boundary) == 'dirichlet' )  THEN
+         !
+         !--          Initial profile is copied to ghost and first three layers
+                      ss = 1
+                      ee = 0
+                      IF ( boundary == 3  .AND.  nys == 0 )  THEN
+                         ss = nysg
+                         ee = nys+2
+                      ELSEIF ( boundary == 4  .AND.  nyn == ny )  THEN
+                         ss = nyn-2
+                         ee = nyng
+                      ENDIF
+
+                      DO  i = nxlg, nxrg
+                         DO  j = ss, ee
+                            DO  k = nzb+1, nzt
+                               flag = MERGE( 1.0_wp, 0.0_wp,                            &
+                                             BTEST( wall_flags_0(k,j,i), 0 ) )
+                               cs_3d(k,j,i) = cs_pr_init(k) * flag
+                            ENDDO
+                         ENDDO
+                      ENDDO
+
+
+                 ELSEIF ( decycle_method(boundary) == 'neumann' )  THEN
+         !
+         !--          The value at the boundary is copied to the ghost layers to simulate
+         !--          an outlet with zero gradient
+                      ss = 1
+                      ee = 0
+                      IF ( boundary == 3  .AND.  nys == 0 )  THEN
+                         ss = nysg
+                         ee = nys-1
+                         copied = nys
+                      ELSEIF ( boundary == 4  .AND.  nyn == ny )  THEN
+                         ss = nyn+1
+                         ee = nyng
+                         copied = nyn
+                      ENDIF
+
+                       DO  i = nxlg, nxrg
+                         DO  j = ss, ee
+                            DO  k = nzb+1, nzt
+                               flag = MERGE( 1.0_wp, 0.0_wp,                            &
+                                             BTEST( wall_flags_0(k,j,i), 0 ) )
+                               cs_3d(k,j,i) = cs_3d(k,copied,i) * flag
+                            ENDDO
+                         ENDDO
+                      ENDDO
+
+                   ELSE
+                      WRITE(message_string,*)                                           &
+                                          'unknown decycling method: decycle_method (', &
+                              boundary, ') ="' // TRIM( decycle_method(boundary) ) // '"'
+                      CALL message( 'chem_boundary_conds_decycle', 'CM0432',           &
+                                    1, 2, 0, 6, 0 )
+                   ENDIF
                 ENDDO
-             ENDDO
-
-        ELSEIF ( decycle_method(boundary) == 'neumann' )  THEN
-!
-!--          The value at the boundary is copied to the ghost layers to simulate
-!--          an outlet with zero gradient
-             ss = 1
-             ee = 0
-             IF ( boundary == 1  .AND.  nxl == 0 )  THEN
-                ss = nxlg
-                ee = nxl-1
-                copied = nxl
-             ELSEIF ( boundary == 2  .AND.  nxr == nx )  THEN
-                ss = nxr+1
-                ee = nxrg
-                copied = nxr
              ENDIF
 
-              DO  i = ss, ee
-                DO  j = nysg, nyng
-                   DO  k = nzb+1, nzt
-                      flag = MERGE( 1.0_wp, 0.0_wp,                            &
-                                    BTEST( wall_flags_0(k,j,i), 0 ) )
-                     cs_3d(k,j,i) = cs_3d(k,j,copied) * flag
-                   ENDDO
-                ENDDO
-             ENDDO
-
-          ELSE
-             WRITE(message_string,*)                                           &
-                                 'unknown decycling method: decycle_method (', &
-                     boundary, ') ="' // TRIM( decycle_method(boundary) ) // '"'
-             CALL message( 'chem_boundary_conds_decycle', 'CM0431',           &
-                           1, 2, 0, 6, 0 )
           ENDIF
+
+          lsp_usr = lsp_usr + 1
+
        ENDDO
-    ENDIF
-!
-!-- South and north boundaries
-    IF ( decycle_chem_ns  .AND.  bc_ns_cyc )  THEN
-
-       DO  boundary = 3, 4
-
-          IF ( decycle_method(boundary) == 'dirichlet' )  THEN
-!    
-!--          Initial profile is copied to ghost and first three layers          
-             ss = 1
-             ee = 0
-             IF ( boundary == 3  .AND.  nys == 0 )  THEN
-                ss = nysg
-                ee = nys+2
-             ELSEIF ( boundary == 4  .AND.  nyn == ny )  THEN
-                ss = nyn-2
-                ee = nyng
-             ENDIF
-
-             DO  i = nxlg, nxrg
-                DO  j = ss, ee
-                   DO  k = nzb+1, nzt
-                      flag = MERGE( 1.0_wp, 0.0_wp,                            &
-                                    BTEST( wall_flags_0(k,j,i), 0 ) )
-                      cs_3d(k,j,i) = cs_pr_init(k) * flag
-                   ENDDO
-                ENDDO
-             ENDDO
-
-
-        ELSEIF ( decycle_method(boundary) == 'neumann' )  THEN
-!
-!--          The value at the boundary is copied to the ghost layers to simulate
-!--          an outlet with zero gradient
-             ss = 1
-             ee = 0
-             IF ( boundary == 3  .AND.  nys == 0 )  THEN
-                ss = nysg
-                ee = nys-1
-                copied = nys
-             ELSEIF ( boundary == 4  .AND.  nyn == ny )  THEN
-                ss = nyn+1
-                ee = nyng
-                copied = nyn
-             ENDIF
-
-              DO  i = nxlg, nxrg
-                DO  j = ss, ee
-                   DO  k = nzb+1, nzt
-                      flag = MERGE( 1.0_wp, 0.0_wp,                            &
-                                    BTEST( wall_flags_0(k,j,i), 0 ) )
-                      cs_3d(k,j,i) = cs_3d(k,copied,i) * flag
-                   ENDDO
-                ENDDO
-             ENDDO
-
-          ELSE
-             WRITE(message_string,*)                                           &
-                                 'unknown decycling method: decycle_method (', &
-                     boundary, ') ="' // TRIM( decycle_method(boundary) ) // '"'
-             CALL message( 'chem_boundary_conds_decycle', 'CM0432',           &
-                           1, 2, 0, 6, 0 )
-          ENDIF
-       ENDDO
-    ENDIF
+
+    ENDDO
+
+    CALL cpu_log( log_point_s(84), 'chem.exch-horiz', 'stop' )
+
  END SUBROUTINE chem_boundary_conds_decycle
 
