Index: palm/trunk/SOURCE/data_output_2d.f90
===================================================================
--- palm/trunk/SOURCE/data_output_2d.f90	(revision 2512)
+++ palm/trunk/SOURCE/data_output_2d.f90	(revision 2696)
@@ -1,5 +1,5 @@
 !> @file data_output_2d.f90
 !------------------------------------------------------------------------------!
-! This file is part of PALM.
+! This file is part of the PALM model system.
 !
 ! PALM is free software: you can redistribute it and/or modify it under the
@@ -25,4 +25,10 @@
 ! -----------------
 ! $Id$
+! Implementation of uv exposure model (FK)
+! Implementation of turbulence_closure_mod (TG)
+! Set fill values at topography grid points or e.g. non-natural-type surface
+! in case of LSM output (MS)
+! 
+! 2512 2017-10-04 08:26:59Z raasch
 ! upper bounds of cross section output changed from nx+1,ny+1 to nx,ny
 ! no output of ghost layer data
@@ -196,5 +202,5 @@
                ntdim_2d_xy, ntdim_2d_xz, ntdim_2d_yz,                          &
                psolver, section, simulated_time, simulated_time_chr,           &
-               time_since_reference_point
+               time_since_reference_point, uv_exposure
         
     USE cpulog,                                                                &
@@ -205,5 +211,5 @@
         
     USE indices,                                                               &
-        ONLY:  nbgp, nx, nxl, nxr, ny, nyn, nys, nz, nzb, nzt
+        ONLY:  nbgp, nx, nxl, nxr, ny, nyn, nys, nz, nzb, nzt, wall_flags_0
                
     USE kinds
@@ -217,7 +223,7 @@
 
     USE netcdf_interface,                                                      &
-        ONLY:  id_set_xy, id_set_xz, id_set_yz, id_var_do2d, id_var_time_xy,   &
-               id_var_time_xz, id_var_time_yz, nc_stat, netcdf_data_format,    &
-               netcdf_handle_error
+        ONLY:  fill_value, id_set_xy, id_set_xz, id_set_yz, id_var_do2d,       &
+               id_var_time_xy, id_var_time_xz, id_var_time_yz, nc_stat,        &
+               netcdf_data_format, netcdf_handle_error
 
     USE particle_attributes,                                                   &
@@ -232,4 +238,11 @@
     USE surface_mod,                                                           &
         ONLY:  surf_def_h, surf_lsm_h, surf_usm_h
+
+    USE turbulence_closure_mod,                                                &
+        ONLY:  tcm_data_output_2d
+
+    USE uv_exposure_model_mod,                                                 &
+        ONLY:  uvem_data_output_2d
+
 
     IMPLICIT NONE
@@ -244,4 +257,5 @@
     INTEGER(iwp) ::  ngp       !< 
     INTEGER(iwp) ::  file_id   !< 
+    INTEGER(iwp) ::  flag_nr   !< number of masking flag
     INTEGER(iwp) ::  i         !< 
     INTEGER(iwp) ::  if        !< 
@@ -457,8 +471,14 @@
           nzt_do = nzt+1
 !
+!--       Before each output, set array local_pf to fill value
+          local_pf = fill_value
+!
+!--       Set masking flag for topography for not resorted arrays
+          flag_nr = 0
+          
+!
 !--       Store the array chosen on the temporary array.
           resorted = .FALSE.
           SELECT CASE ( TRIM( do2d(av,if) ) )
-
              CASE ( 'e_xy', 'e_xz', 'e_yz' )
                 IF ( av == 0 )  THEN
@@ -928,4 +948,5 @@
 
              CASE ( 'u_xy', 'u_xz', 'u_yz' )
+                flag_nr = 1
                 IF ( av == 0 )  THEN
                    to_be_resorted => u
@@ -970,4 +991,5 @@
 
              CASE ( 'v_xy', 'v_xz', 'v_yz' )
+                flag_nr = 2
                 IF ( av == 0 )  THEN
                    to_be_resorted => v
@@ -992,4 +1014,5 @@
 
              CASE ( 'w_xy', 'w_xz', 'w_yz' )
+                flag_nr = 3
                 IF ( av == 0 )  THEN
                    to_be_resorted => w
@@ -1093,8 +1116,22 @@
 
 !
+!--             Turbulence closure variables
+                IF ( .NOT. found )  THEN
+                   CALL tcm_data_output_2d( av, do2d(av,if), found, grid, mode,&
+                                             local_pf, two_d, nzb_do, nzt_do )
+                ENDIF
+
+!
 !--             Radiation quantity
                 IF ( .NOT. found  .AND.  radiation )  THEN
                    CALL radiation_data_output_2d( av, do2d(av,if), found, grid,&
                                                   mode, local_pf, two_d  )
+                ENDIF
+
+!
+!--             UV exposure model quantity
+                IF ( uv_exposure )  THEN
+                   CALL uvem_data_output_2d( av, do2d(av,if), found, grid, mode,&
+                                             local_pf, two_d, nzb_do, nzt_do )
                 ENDIF
 
@@ -1127,10 +1164,14 @@
 
 !
-!--       Resort the array to be output, if not done above
+!--       Resort the array to be output, if not done above. Flag topography 
+!--       grid points with fill values, using the corresponding maksing flag.
           IF ( .NOT. resorted )  THEN
              DO  i = nxl, nxr
                 DO  j = nys, nyn
                    DO  k = nzb_do, nzt_do
-                      local_pf(i,j,k) = to_be_resorted(k,j,i)
+                      local_pf(i,j,k) = MERGE( to_be_resorted(k,j,i),          &
+                                               REAL( fill_value, KIND = wp ),  &
+                                               BTEST( wall_flags_0(k,j,i),     &
+                                                      flag_nr ) ) 
                    ENDDO
                 ENDDO
