Index: palm/trunk/SOURCE/data_output_mask.f90
===================================================================
--- palm/trunk/SOURCE/data_output_mask.f90	(revision 4376)
+++ palm/trunk/SOURCE/data_output_mask.f90	(revision 4377)
@@ -20,41 +20,45 @@
 ! Current revisions:
 ! -----------------
-! 
-! 
+!
+!
 ! Former revisions:
 ! -----------------
 ! $Id$
+! bugfix: set fill value for output according to wall_flags_total_0 for
+!         non-terrain following output
+!
+! 4360 2020-01-07 11:25:50Z suehring
 ! Introduction of wall_flags_total_0, which currently sets bits based on static
 ! topography information used in wall_flags_static_0
-! 
+!
 ! 4331 2019-12-10 18:25:02Z suehring
 ! Formatting adjustment
-! 
+!
 ! 4329 2019-12-10 15:46:36Z motisi
 ! Renamed wall_flags_0 to wall_flags_static_0
-! 
+!
 ! 4246 2019-09-30 09:27:52Z pavelkrc
 ! Corrected "Former revisions" section
-! 
+!
 ! 4168 2019-08-16 13:50:17Z suehring
 ! Remove variable grid
-! 
+!
 ! 4167 2019-08-16 11:01:48Z suehring
-! Changed behaviour of masked output over surface to follow terrain and ignore 
+! Changed behaviour of masked output over surface to follow terrain and ignore
 ! buildings (J.Resler, T.Gronemeier)
-! 
+!
 ! 4069 2019-07-01 14:05:51Z Giersch
-! Masked output running index mid has been introduced as a local variable to 
-! avoid runtime error (Loop variable has been modified) in time_integration 
-! 
+! Masked output running index mid has been introduced as a local variable to
+! avoid runtime error (Loop variable has been modified) in time_integration
+!
 ! 4039 2019-06-18 10:32:41Z suehring
 ! Modularize diagnostic output
-! 
+!
 ! 3994 2019-05-22 18:08:09Z suehring
 ! output of turbulence intensity added
-! 
+!
 ! 3665 2019-01-10 08:28:24Z raasch
 ! unused variables removed
-! 
+!
 ! 3655 2019-01-07 16:51:22Z knoop
 ! Fix output time levels (use time_since_reference_point)
@@ -69,5 +73,5 @@
  SUBROUTINE data_output_mask( av, mid )
 
- 
+
 
 #if defined( __netcdf )
@@ -79,5 +83,5 @@
         ONLY:  e_av, lpt_av, nc_av, nr_av, p_av, pc_av, pr_av, pt_av, q_av,    &
                qc_av, ql_av, ql_c_av, ql_v_av, ql_vp_av, qv_av, qr_av,         &
-               rho_ocean_av, s_av, sa_av, u_av, v_av, vpt_av, w_av 
+               rho_ocean_av, s_av, sa_av, u_av, v_av, vpt_av, w_av
 
     USE basic_constants_and_equations_mod,                                     &
@@ -94,7 +98,7 @@
                time_since_reference_point
 
-    USE diagnostic_output_quantities_mod,                                      & 
+    USE diagnostic_output_quantities_mod,                                      &
         ONLY:  doq_output_mask
-               
+
     USE cpulog,                                                                &
         ONLY:  cpu_log, log_point
@@ -107,15 +111,15 @@
     USE bulk_cloud_model_mod,                                                  &
         ONLY:  bulk_cloud_model
-    
+
     USE NETCDF
-    
+
     USE netcdf_interface,                                                      &
         ONLY:  fill_value, id_set_mask, id_var_domask, id_var_time_mask,       &
                nc_stat, netcdf_data_format, netcdf_handle_error
-    
+
     USE particle_attributes,                                                   &
         ONLY:  grid_particles, number_of_particles, particles,                 &
                particle_advection_start, prt_count
-    
+
     USE pegrid
 
@@ -124,5 +128,5 @@
 
     USE salsa_mod,                                                             &
-        ONLY:  salsa_data_output_mask     
+        ONLY:  salsa_data_output_mask
 
 
@@ -131,4 +135,5 @@
     INTEGER(iwp) ::  av                      !< flag for (non-)average output
     INTEGER(iwp) ::  ngp                     !< number of grid points of an output slice
+    INTEGER(iwp) ::  flag_nr                 !< number of masking flag
     INTEGER(iwp) ::  i                       !< loop index
     INTEGER(iwp) ::  ivar                    !< variable index
@@ -151,5 +156,5 @@
     REAL(wp) ::  s_r2      !< sum( particle-radius**2 )
     REAL(wp) ::  s_r3      !< sum( particle-radius**3 )
-    
+
     REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  local_pf    !< output array
 #if defined( __parallel )
@@ -175,5 +180,5 @@
     IF ( myid == 0  .OR.  netcdf_data_format > 4 )  THEN
        CALL check_open( 200+mid+av*max_masks )
-    ENDIF 
+    ENDIF
 
 !
@@ -210,4 +215,7 @@
                              mask_size_l(mid,3)) )
        ENDIF
+!
+!--    Set masking flag for topography for not resorted arrays
+       flag_nr = 0
 !
 !--    Store the variable chosen.
@@ -397,5 +405,5 @@
                          ENDDO
                       ENDDO
-                   ENDIF                   
+                   ENDIF
                    resorted = .TRUE.
                 ENDIF
@@ -567,4 +575,5 @@
 
           CASE ( 'u' )
+             flag_nr = 1
              IF ( av == 0 )  THEN
                 to_be_resorted => u
@@ -574,4 +583,5 @@
 
           CASE ( 'v' )
+             flag_nr = 2
              IF ( av == 0 )  THEN
                 to_be_resorted => v
@@ -588,4 +598,5 @@
 
           CASE ( 'w' )
+             flag_nr = 3
              IF ( av == 0 )  THEN
                 to_be_resorted => w
@@ -621,5 +632,5 @@
                 CALL salsa_data_output_mask( av, domask(mid,av,ivar), found,   &
                                              local_pf, mid )
-             ENDIF         
+             ENDIF
 !
 !--          User defined quantity
@@ -648,6 +659,13 @@
                 DO  j = 1, mask_size_l(mid,2)
                    DO  k = 1, mask_size_l(mid,3)
-                      local_pf(i,j,k) =  to_be_resorted(mask_k(mid,k), &
-                                         mask_j(mid,j),mask_i(mid,i))
+                      local_pf(i,j,k) = MERGE( to_be_resorted(mask_k(mid,k),  &
+                                                              mask_j(mid,j),  &
+                                                              mask_i(mid,i)), &
+                                               REAL( fill_value, KIND = wp ), &
+                                               BTEST( wall_flags_total_0(     &
+                                                              mask_k(mid,k),  &
+                                                              mask_j(mid,j),  &
+                                                              mask_i(mid,i)), &
+                                                      flag_nr ) )
                    ENDDO
                 ENDDO
@@ -705,5 +723,5 @@
 !--       (1) b. Conventional I/O only through PE0
 !--       PE0 receives partial arrays from all processors of the respective mask
-!--       and outputs them. Here a barrier has to be set, because otherwise 
+!--       and outputs them. Here a barrier has to be set, because otherwise
 !--       "-MPI- FATAL: Remote protocol queue full" may occur.
           CALL MPI_BARRIER( comm2d, ierr )
