Index: /palm/trunk/SOURCE/land_surface_model_mod.f90
===================================================================
--- /palm/trunk/SOURCE/land_surface_model_mod.f90	(revision 3940)
+++ /palm/trunk/SOURCE/land_surface_model_mod.f90	(revision 3941)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Check that at least one surface type is set at surface element.
+! 
+! 3933 2019-04-25 12:33:20Z kanani
 ! Remove unused subroutine and allocation of pt_2m, this is done in surface_mod
 ! now (surfaces%pt_2m)
@@ -2277,6 +2280,4 @@
        ENDIF
 
-
-!        pt(k+k_off,j+j_off,i+i_off) = surf_t_surface_p%var_1d(m) / exner(nzb)  !is actually no air temperature
        surf%pt_surface(m)          = surf_t_surface_p%var_1d(m) / exner(nzb)
 
@@ -2881,4 +2882,17 @@
                 IF ( water_type_f%var(j,i)      /= water_type_f%fill )         &
                    surf_lsm_h%water_surface(m) = .TRUE.
+!
+!--             Check if at least one type is set.
+                IF ( .NOT. surf_lsm_h%vegetation_surface(m)  .AND.             &
+                     .NOT. surf_lsm_h%pavement_surface(m)    .AND.             &
+                     .NOT. surf_lsm_h%water_surface(m) )  THEN
+                   WRITE( message_string, * ) 'Horizontal surface element ' // &
+                                       ' at i, j = ',  i, j,                   &
+                                       ' is neither a vegetation, ' //         &
+                                       'pavement, nor a water surface.'
+                   CALL message( 'land_surface_model_mod', 'PA0619',          &
+                                  2, 2, myid, 6, 0 )
+                ENDIF
+                
              ENDDO
 !
@@ -2959,6 +2973,15 @@
                       surf_lsm_v(l)%water_surface(m) = .TRUE.
 !
-!--                Check if surface element has the flag %building_covered_all,
-!--                this case, set vegetation_type appropriate
+!--                Check if at least one type is set.
+                   IF ( .NOT. surf_lsm_v(l)%vegetation_surface(m)  .AND.       &
+                        .NOT. surf_lsm_v(l)%pavement_surface(m)    .AND.       &
+                        .NOT. surf_lsm_v(l)%water_surface(m) )  THEN
+                      WRITE( message_string, * ) 'Vertical surface element ' //&
+                                       ' at i, j = ',  i, j,                   &
+                                       ' is neither a vegetation, ' //         &
+                                       'pavement, nor a water surface.'
+                      CALL message( 'land_surface_model_mod', 'PA0619',        &
+                                     2, 2, myid, 6, 0 )
+                   ENDIF
                 ENDDO
              ENDDO
Index: /palm/trunk/SOURCE/netcdf_data_input_mod.f90
===================================================================
--- /palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 3940)
+++ /palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 3941)
@@ -25,4 +25,9 @@
 ! -----------------
 ! $Id$
+! Move check for grid dimension to an earlier point in time when first array
+! is read.
+! Improve checks for building types / IDs with respect to 2D/3D buildings.
+! 
+! 3885 2019-04-11 11:29:34Z kanani
 ! Changes related to global restructuring of location messages and introduction 
 ! of additional debug messages
@@ -2498,6 +2503,9 @@
            ONLY:  message_string, topography
 
+       USE grid_variables,                                                     &
+           ONLY:  dx, dy    
+           
        USE indices,                                                            &
-           ONLY:  nbgp, nxl, nxr, ny, nyn, nys, nzb
+           ONLY:  nbgp, nx, nxl, nxr, ny, nyn, nys, nzb
 
 
@@ -2544,4 +2552,22 @@
           CALL get_variable( id_topo, 'x', dim_static%x )
           CALL get_variable( id_topo, 'y', dim_static%y )
+!
+!--       Check whether dimension size in input file matches the model dimensions
+          IF ( dim_static%nx-1 /= nx  .OR.  dim_static%ny-1 /= ny )  THEN
+             message_string = 'Static input file: horizontal dimension in ' // &
+                              'x- and/or y-direction ' //                      &
+                              'do not match the respective model dimension'
+             CALL message( 'netcdf_data_input_mod', 'PA0548', 1, 2, 0, 6, 0 )
+          ENDIF
+!
+!--       Check if grid spacing of provided input data matches the respective
+!--       grid spacing in the model. 
+          IF ( ABS( dim_static%x(1) - dim_static%x(0) - dx ) > 10E-6_wp  .OR.  &
+               ABS( dim_static%y(1) - dim_static%y(0) - dy ) > 10E-6_wp )  THEN
+             message_string = 'Static input file: horizontal grid spacing ' // &
+                              'in x- and/or y-direction ' //                   &
+                              'do not match the respective model grid spacing.'
+             CALL message( 'netcdf_data_input_mod', 'PA0549', 1, 2, 0, 6, 0 )
+          ENDIF
 !
 !--       Terrain height. First, get variable-related _FillValue attribute
@@ -3810,9 +3836,6 @@
            ONLY:  land_surface, message_string, urban_surface
 
-       USE grid_variables,                                                     &
-           ONLY:  dx, dy
-
        USE indices,                                                            &
-           ONLY:  nx, nxl, nxr, ny, nyn, nys
+           ONLY:  nxl, nxr, nyn, nys
 
        IMPLICIT NONE
@@ -3827,22 +3850,4 @@
 !--    Return if no static input file is available
        IF ( .NOT. input_pids_static )  RETURN
-!
-!--    Check whether dimension size in input file matches the model dimensions
-       IF ( dim_static%nx-1 /= nx  .OR.  dim_static%ny-1 /= ny )  THEN
-          message_string = 'Static input file: horizontal dimension in ' //    &
-                           'x- and/or y-direction ' //                         &
-                           'do not match the respective model dimension'
-          CALL message( 'netcdf_data_input_mod', 'PA0548', 1, 2, 0, 6, 0 )
-       ENDIF
-!
-!--    Check if grid spacing of provided input data matches the respective
-!--    grid spacing in the model. 
-       IF ( ABS( dim_static%x(1) - dim_static%x(0) - dx ) > 10E-6_wp  .OR.     &
-            ABS( dim_static%y(1) - dim_static%y(0) - dy ) > 10E-6_wp )  THEN
-          message_string = 'Static input file: horizontal grid spacing ' //    &
-                           'in x- and/or y-direction ' //                      &
-                           'do not match the respective model grid spacing.'
-          CALL message( 'netcdf_data_input_mod', 'PA0549', 1, 2, 0, 6, 0 )
-       ENDIF
 !
 !--    Check for correct dimension of surface_fractions, should run from 0-2.
@@ -4250,10 +4255,12 @@
                 IF ( buildings_f%lod == 1 )  THEN
                    IF ( buildings_f%var_2d(j,i)  /= buildings_f%fill1  .AND.   &
-                        building_type_f%var(j,i) == building_type_f%fill )  THEN
+                        building_type_f%var(j,i) == building_type_f%fill  .OR. &
+                        buildings_f%var_2d(j,i)  == buildings_f%fill1  .AND.   &
+                        building_type_f%var(j,i) /= building_type_f%fill )  THEN
                       WRITE( message_string, * ) 'Each location where a ' //   &
-                                         'building is set requires a type ' // &
-                                         '( and vice versa ) in case the ' //  &
-                                         'urban-surface model is applied. ' // &
-                                         'i, j = ', i, j
+                                      '2D building is set requires a type ' // &
+                                      '( and vice versa ) in case the ' //     &
+                                      'urban-surface model is applied. ' //    &
+                                      'i, j = ', i, j
                       CALL message( 'netcdf_data_input_mod', 'PA0573',         &
                                      2, 2, myid, 6, 0 )
@@ -4262,10 +4269,12 @@
                 IF ( buildings_f%lod == 2 )  THEN
                    IF ( ANY( buildings_f%var_3d(:,j,i) == 1 )  .AND.           &
-                        building_type_f%var(j,i) == building_type_f%fill )  THEN
+                        building_type_f%var(j,i) == building_type_f%fill  .OR. &
+                  .NOT. ANY( buildings_f%var_3d(:,j,i) == 1 )  .AND.           &
+                        building_type_f%var(j,i) /= building_type_f%fill )  THEN
                       WRITE( message_string, * ) 'Each location where a ' //   &
-                                         'building is set requires a type ' // &
-                                         '( and vice versa ) in case the ' //  &
-                                         'urban-surface model is applied. ' // &
-                                         'i, j = ', i, j
+                                      '3D building is set requires a type ' // &
+                                      '( and vice versa ) in case the ' //     &
+                                      'urban-surface model is applied. ' //    &
+                                      'i, j = ', i, j
                       CALL message( 'netcdf_data_input_mod', 'PA0573',         &
                                      2, 2, myid, 6, 0 )
@@ -4279,8 +4288,10 @@
                 IF ( buildings_f%lod == 1 )  THEN
                    IF ( buildings_f%var_2d(j,i) /= buildings_f%fill1  .AND.    &
-                        building_id_f%var(j,i)  == building_id_f%fill )  THEN
+                        building_id_f%var(j,i)  == building_id_f%fill  .OR.    &
+                        buildings_f%var_2d(j,i) == buildings_f%fill1  .AND.    &
+                        building_id_f%var(j,i)  /= building_id_f%fill )  THEN
                       WRITE( message_string, * ) 'Each location where a ' //   &
-                                         'building is set requires an ID ' //  &
-                                         '( and vice versa ). i, j = ', i, j
+                                      '2D building is set requires an ID ' //  &
+                                      '( and vice versa ). i, j = ', i, j
                       CALL message( 'netcdf_data_input_mod', 'PA0574',         &
                                      2, 2, myid, 6, 0 )
@@ -4288,8 +4299,10 @@
                 ELSEIF ( buildings_f%lod == 2 )  THEN
                    IF ( ANY( buildings_f%var_3d(:,j,i) == 1 )  .AND.           &
-                        building_id_f%var(j,i) == building_id_f%fill )  THEN
+                        building_id_f%var(j,i) == building_id_f%fill  .OR.     &
+                  .NOT. ANY( buildings_f%var_3d(:,j,i) == 1 )  .AND.           &
+                        building_id_f%var(j,i) /= building_id_f%fill )  THEN
                       WRITE( message_string, * ) 'Each location where a ' //   &
-                                         'building is set requires an ID ' //  &
-                                         '( and vice versa ). i, j = ', i, j
+                                      '3D building is set requires an ID ' //  &
+                                      '( and vice versa ). i, j = ', i, j
                       CALL message( 'netcdf_data_input_mod', 'PA0574',         &
                                      2, 2, myid, 6, 0 )
