Index: palm/trunk/UTIL/inifor/src/inifor_defs.f90
===================================================================
--- palm/trunk/UTIL/inifor/src/inifor_defs.f90	(revision 4756)
+++ palm/trunk/UTIL/inifor/src/inifor_defs.f90	(revision 4790)
@@ -214,5 +214,5 @@
     ACHAR( 10 ) // ' Copyright 2017-2020 Deutscher Wetterdienst Offenbach' !< Copyright notice
  CHARACTER(LEN=*), PARAMETER ::  LOG_FILE_NAME = 'inifor.log' !< Name of INIFOR's log file
- CHARACTER(LEN=*), PARAMETER ::  VERSION = '2.1.2'            !< INIFOR version number
+ CHARACTER(LEN=*), PARAMETER ::  VERSION = '2.1.3'            !< INIFOR version number
  
  END MODULE inifor_defs
Index: palm/trunk/UTIL/inifor/src/inifor_grid.f90
===================================================================
--- palm/trunk/UTIL/inifor/src/inifor_grid.f90	(revision 4756)
+++ palm/trunk/UTIL/inifor/src/inifor_grid.f90	(revision 4790)
@@ -26,4 +26,9 @@
 ! -----------------
 ! $Id$
+! Call dataset validation
+! Fixed error message
+!
+!
+! 4715 2020-09-30 13:14:43Z eckhard
 ! Make LODs for top boundary conditions consistent with PALM
 !
@@ -205,8 +210,9 @@
                PIDS_ORIGIN_Z
     USE inifor_io,                                                             &
-        ONLY:  file_is_present, get_cosmo_grid, get_input_file_list, get_netcdf_attribute,      &
-               get_netcdf_dim_vector, get_netcdf_variable, set_palm_origin,    &
-               netcdf_variable_present_in_file, parse_command_line_arguments, validate_config,                  &
-               has_surface_value
+        ONLY:  file_is_present, get_cosmo_grid, get_input_file_list,           &
+               get_netcdf_attribute, get_netcdf_dim_vector,                    &
+               get_netcdf_variable, set_palm_origin,                           &
+               netcdf_variable_present_in_file, parse_command_line_arguments,  &
+               validate_config, validate_dataset, has_surface_value
     USE inifor_transform,                                                      &
         ONLY:  average_2d, rotate_to_cosmo, find_horizontal_neighbours,        &
@@ -591,4 +597,5 @@
 ! Section 3: Check for consistency
 !------------------------------------------------------------------------------
+    CALL validate_dataset( flow_files, cfg%hhl_file )
 
 !
@@ -612,5 +619,5 @@
     CALL log_runtime('time', 'read')
 
-    CALL get_cosmo_grid( cfg % hhl_file, soil_files(1), rlon, rlat, hhl, hfl,  &
+    CALL get_cosmo_grid( cfg%hhl_file, soil_files(1), rlon, rlat, hhl, hfl,    &
                          depths, d_depth, d_depth_rho_inv, phi_n, lambda_n,    &
                          phi_equat,                                            &
@@ -2384,5 +2391,5 @@
              ELSE
                 message = "Set up input file name '" // TRIM(filename) // "'"
-                CALL report('verify_file', message)
+                CALL report('validate_io_groups', message)
              ENDIF
 
Index: palm/trunk/UTIL/inifor/src/inifor_io.f90
===================================================================
--- palm/trunk/UTIL/inifor/src/inifor_io.f90	(revision 4756)
+++ palm/trunk/UTIL/inifor/src/inifor_io.f90	(revision 4790)
@@ -26,4 +26,8 @@
 ! -----------------
 ! $Id$
+! Validate mesoscale input data by the number of dimensions and their lengths
+!
+!
+! 4675 2020-09-11 10:00:26Z eckhard
 ! New command-line options for soil profile initialization and homogeneous
 !    boundary conditions
@@ -409,15 +413,15 @@
  SUBROUTINE netcdf_define_variable(var, ncid)
 
-     TYPE(nc_var), INTENT(INOUT) ::  var
-     INTEGER, INTENT(IN)         ::  ncid
-
-     CALL check(nf90_def_var(ncid, var%name, NF90_FLOAT,       var%dimids(1:var%ndim), var%varid))
-     CALL check(nf90_put_att(ncid, var%varid, "long_name",     var%long_name))
-     CALL check(nf90_put_att(ncid, var%varid, "units",         var%units))
-     IF ( var%lod .GE. 0 )  THEN
-        CALL check(nf90_put_att(ncid, var%varid, "lod",           var%lod))
-     ENDIF 
-     CALL check(nf90_put_att(ncid, var%varid, "source",        var%source))
-     CALL check(nf90_put_att(ncid, var%varid, "_FillValue",    NF90_FILL_REAL))
+    TYPE(nc_var), INTENT(INOUT) ::  var
+    INTEGER, INTENT(IN)         ::  ncid
+
+    CALL check(nf90_def_var(ncid, var%name, NF90_FLOAT,       var%dimids(1:var%ndim), var%varid))
+    CALL check(nf90_put_att(ncid, var%varid, "long_name",     var%long_name))
+    CALL check(nf90_put_att(ncid, var%varid, "units",         var%units))
+    IF ( var%lod .GE. 0 )  THEN
+       CALL check(nf90_put_att(ncid, var%varid, "lod",           var%lod))
+    ENDIF 
+    CALL check(nf90_put_att(ncid, var%varid, "source",        var%source))
+    CALL check(nf90_put_att(ncid, var%varid, "_FillValue",    NF90_FILL_REAL))
 
  END SUBROUTINE netcdf_define_variable
@@ -433,14 +437,14 @@
  SUBROUTINE netcdf_get_dimensions(var, ncid)
 
-     TYPE(nc_var), INTENT(INOUT) ::  var
-     INTEGER, INTENT(IN)         ::  ncid
-     INTEGER                     ::  i
-     CHARACTER(SNAME)            ::  null
-
-     DO  i = 1, var%ndim
-        CALL check(nf90_inquire_dimension(ncid, var%dimids(i), &
-                                          name = null, &
-                                          len  = var%dimlen(i)  ) )
-     ENDDO
+    TYPE(nc_var), INTENT(INOUT) ::  var
+    INTEGER, INTENT(IN)         ::  ncid
+    INTEGER                     ::  i
+    CHARACTER(SNAME)            ::  null
+
+    DO  i = 1, var%ndim
+       CALL check(nf90_inquire_dimension(ncid, var%dimids(i), &
+                                         name = null, &
+                                         len  = var%dimlen(i)  ) )
+    ENDDO
 
  END SUBROUTINE netcdf_get_dimensions
@@ -819,9 +823,101 @@
 
 
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Checks wheather the COSMO grid matches the shape of the meteorological input
+!> data by comparing the number of netCDF dimensions and their lengths in the
+!> hhl.nc and the first of the *-flow files.
+!------------------------------------------------------------------------------!
+ SUBROUTINE validate_dataset(flow_files, hhl_file)
+    CHARACTER(LEN=PATH), INTENT(IN) ::  flow_files(:) !< paths to files containing atmospheric variables
+    CHARACTER(LEN=PATH), INTENT(IN) ::  hhl_file      !< path to file containing the HHL variable (height of half layers)
+
+    CHARACTER(SNAME), PARAMETER ::  NC_W_NAME = 'W'
+    TYPE(nc_var)                ::  hhl_var, flow_var
+    INTEGER                     ::  dim_idx, ncid, ndims_flow, ndims_hhl, varid
+    REAL(wp), ALLOCATABLE       ::  hhl_dim_vector(:), flow_dim_vector(:)
+    LOGICAL                     ::  dims_have_same_length
+
+    IF ( nf90_open( TRIM( flow_files(1) ), NF90_NOWRITE, ncid ) .EQ. NF90_NOERR )  THEN
+
+       CALL check( nf90_inq_varid( ncid, NC_W_NAME, varid=varid ) )
+       CALL check( nf90_inquire_variable( ncid, varid, ndims=ndims_flow ) )
+       CALL netcdf_get_dimensions( flow_var, ncid )
+       CALL check( nf90_close( ncid ) )
+
+    ELSE
+
+       message = "Failed to read netCDF dimensions'" //                        &
+                 "' from file '" // TRIM( flow_files(1) ) // "'."
+       CALL inifor_abort( 'validate_dataset', message )
+
+    ENDIF
+
+    IF ( nf90_open( TRIM( hhl_file ), NF90_NOWRITE, ncid ) .EQ. NF90_NOERR )  THEN
+
+       CALL check( nf90_inq_varid( ncid, NC_HHL_NAME, varid=varid ) )
+       CALL check( nf90_inquire_variable( ncid, varid, ndims=ndims_hhl ) )
+       CALL netcdf_get_dimensions( hhl_var, ncid )
+       CALL check( nf90_close( ncid ) )
+
+    ELSE
+
+       message = "Failed to read netCDF dimensions'" //                        &
+                 "' from file '" // TRIM(hhl_file) // "'."
+       CALL inifor_abort( 'validate_dataset', message )
+
+    ENDIF
+
+!
+!-- Compare number dimensions of 'HHL' in hhl file and 'W' in first flow file
+    IF  ( .NOT. ndims_flow .EQ. ndims_hhl )  THEN
+       message = "Mesoscale data inconsistent. Number of dimensions in the " //&
+                 "hhl file does not match with the meteorologial fields " //   &
+                 "in the *-flow files (" //                                    &
+                 "HHL: ndims = " // TRIM( str( ndims_hhl ) )  // ", " //       &
+                 "W: ndims = "   // TRIM( str( ndims_flow ) ) // ")."
+       CALL inifor_abort( 'validate_dataset', message )
+    ENDIF
+
+
+!
+!-- Compare lengths of each dimension, ignoring time (dim_idx = 1)
+    DO dim_idx = 2, ndims_hhl
+
+       CALL get_dimension_vector_of_variable(                                  &
+          NC_HHL_NAME,                                                         &
+          dim_idx = dim_idx,                                                   &
+          filename = hhl_file,                                                 &
+          dim_vector = hhl_dim_vector                                          &
+       )
+
+       CALL get_dimension_vector_of_variable(                                  &
+          NC_W_NAME,                                                           &
+          dim_idx = dim_idx,                                                   &
+          filename = flow_files(1),                                            &
+          dim_vector = flow_dim_vector                                         &
+       )
+
+       dims_have_same_length = SIZE( flow_dim_vector ) .EQ. SIZE( hhl_dim_vector )
+       IF  ( .NOT. dims_have_same_length )  THEN
+          message = &
+             "Mesoscale data inconsistent. Number of grid points " //          &
+             "in dimension #" // TRIM( str( dim_idx ) ) //                     &
+             " do not match in the hhl and *-flow files (" //                  &
+             "HHL: len = " // TRIM( str( SIZE( hhl_dim_vector ) ) ) // ", " // &
+             "W: len = "   // TRIM( str( SIZE( flow_dim_vector ) ) )// ")."
+          CALL inifor_abort( 'validate_dataset', message )
+       ENDIF
+
+    ENDDO
+
+ END SUBROUTINE validate_dataset
+
  SUBROUTINE get_cosmo_grid( hhl_file, soil_file, rlon, rlat, hhl, hfl, depths, &
-                            d_depth, d_depth_rho_inv, phi_n, lambda_n,       &
-                            phi_equat,                                       &
-                            lonmin_cosmo, lonmax_cosmo,                      &
-                            latmin_cosmo, latmax_cosmo,                      &
+                            d_depth, d_depth_rho_inv, phi_n, lambda_n,         &
+                            phi_equat,                                         &
+                            lonmin_cosmo, lonmax_cosmo,                        &
+                            latmin_cosmo, latmax_cosmo,                        &
                             nlon, nlat, nlev, ndepths )
 
Index: palm/trunk/UTIL/inifor/src/inifor_util.f90
===================================================================
--- palm/trunk/UTIL/inifor/src/inifor_util.f90	(revision 4756)
+++ palm/trunk/UTIL/inifor/src/inifor_util.f90	(revision 4790)
@@ -21,9 +21,13 @@
 ! Current revisions:
 ! -----------------
-! 
-! 
+!
+!
 ! Former revisions:
 ! -----------------
 ! $Id$
+! Support integer-string conversion for 8 and 4 bit types
+! 
+! 
+! 4568 2020-06-19 11:56:30Z eckhard
 ! Added function for checking floating point equality
 ! 
@@ -166,4 +170,11 @@
  END INTERFACE
 
+ 
+ INTERFACE str
+    MODULE PROCEDURE str_iwp
+    MODULE PROCEDURE str_4
+ END INTERFACE
+
+
  CONTAINS
 
@@ -438,14 +449,22 @@
 !> Converts the given integer value to a string
 !------------------------------------------------------------------------------!
- CHARACTER(LEN=10) FUNCTION str(val)
+ CHARACTER(LEN=10) FUNCTION str_iwp(val)
 
      INTEGER(iwp), INTENT(IN) ::  val
 
-     WRITE(str, '(i10)') val
-     str = ADJUSTL(str)
-
- END FUNCTION str
-
-
+     WRITE(str_iwp, '(i10)') val
+     str_iwp= ADJUSTL(str_iwp)
+
+ END FUNCTION str_iwp
+
+
+ CHARACTER(LEN=10) FUNCTION str_4(val)
+
+     INTEGER(4), INTENT(IN) ::  val
+
+     WRITE(str_4, '(i10)') val
+     str_4 = ADJUSTL(str_4)
+
+ END FUNCTION str_4
 !------------------------------------------------------------------------------!
 ! Description:
