Index: palm/trunk/SOURCE/netcdf_data_input_mod.f90
===================================================================
--- palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 4247)
+++ palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 4258)
@@ -25,4 +25,9 @@
 ! -----------------
 ! $Id$
+! - Migrate input of soil temperature and moisture to land-surface model.
+! - Remove interpolate routines and move the only required subroutine to 
+!   land-surface model.
+! 
+! 4247 2019-09-30 10:18:24Z pavelkrc
 ! Add reading and processing of building_surface_pars
 ! 
@@ -608,11 +613,4 @@
     PRIVATE
 
-    INTERFACE netcdf_data_input_interpolate
-       MODULE PROCEDURE netcdf_data_input_interpolate_1d
-       MODULE PROCEDURE netcdf_data_input_interpolate_1d_soil
-       MODULE PROCEDURE netcdf_data_input_interpolate_2d
-       MODULE PROCEDURE netcdf_data_input_interpolate_3d
-    END INTERFACE netcdf_data_input_interpolate
-
     INTERFACE netcdf_data_input_check_dynamic
        MODULE PROCEDURE netcdf_data_input_check_dynamic
@@ -650,8 +648,4 @@
     END INTERFACE netcdf_data_input_init_3d
     
-    INTERFACE netcdf_data_input_init_lsm
-       MODULE PROCEDURE netcdf_data_input_init_lsm
-    END INTERFACE netcdf_data_input_init_lsm
-
     INTERFACE netcdf_data_input_surface_data
        MODULE PROCEDURE netcdf_data_input_surface_data
@@ -733,12 +727,14 @@
 !
 !-- Public subroutines
-    PUBLIC netcdf_data_input_check_dynamic, netcdf_data_input_check_static,    &
+    PUBLIC netcdf_data_input_check_dynamic,                                    &
+           netcdf_data_input_check_static,                                     &
            netcdf_data_input_chemistry_data,                                   &
            get_dimension_length,                                               &
            netcdf_data_input_inquire_file,                                     &
-           netcdf_data_input_init, netcdf_data_input_init_lsm,                 &
-           netcdf_data_input_init_3d, netcdf_data_input_att,                   &
-           netcdf_data_input_interpolate,                                      &
-           netcdf_data_input_surface_data, netcdf_data_input_topo,             &
+           netcdf_data_input_init,                                             &
+           netcdf_data_input_init_3d,                                          &
+           netcdf_data_input_att,                                              &
+           netcdf_data_input_surface_data,                                     &
+           netcdf_data_input_topo,                                             &
            netcdf_data_input_var,                                              &
            get_attribute,                                                      &
@@ -2914,14 +2910,14 @@
        IF ( init_3d%nx-1 /= nx  .OR.  init_3d%nxu-1 /= nx - 1  .OR.            &
             init_3d%ny-1 /= ny  .OR.  init_3d%nyv-1 /= ny - 1 )  THEN
-          message_string = 'Number of inifor horizontal grid points  '//       &
-                           'does not match the number of numeric grid '//      &
-                           'points.'
+          message_string = 'Number of horizontal grid points in '//            &
+                           'dynamic input file does not match ' //             &
+                           'the number of numeric grid points.'
           CALL message( 'netcdf_data_input_mod', 'PA0543', 1, 2, 0, 6, 0 )
        ENDIF
 
        IF ( init_3d%nzu /= nz )  THEN
-          message_string = 'Number of inifor vertical grid points ' //         &
-                           'does not match the number of numeric grid '//      &
-                           'points.'
+          message_string = 'Number of vertical grid points in '//              &
+                           'dynamic input file does not match ' //             &
+                           'the number of numeric grid points.'
           CALL message( 'netcdf_data_input_mod', 'PA0543', 1, 2, 0, 6, 0 )
        ENDIF
@@ -3353,143 +3349,4 @@
 
     END SUBROUTINE netcdf_data_input_init_3d
-    
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Reads initialization data of u, v, w, pt, q, geostrophic wind components,
-!> as well as soil moisture and soil temperature, derived from larger-scale
-!> model (COSMO) by Inifor.
-!------------------------------------------------------------------------------!
-    SUBROUTINE netcdf_data_input_init_lsm
-
-       USE control_parameters,                                                 &
-           ONLY:  message_string
-
-       USE indices,                                                            &
-           ONLY:  nx, nxl, nxr, ny, nyn, nys
-
-       IMPLICIT NONE
-
-       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names !< string containing all variables on file
-      
-       INTEGER(iwp) ::  id_dynamic !< NetCDF id of dynamic input file
-       INTEGER(iwp) ::  num_vars   !< number of variables in netcdf input file
-
-!
-!--    Skip routine if no input file with dynamic input data is available.
-       IF ( .NOT. input_pids_dynamic )  RETURN
-!
-!--    CPU measurement
-       CALL cpu_log( log_point_s(85), 'NetCDF input init', 'start' )
-
-#if defined ( __netcdf )
-!
-!--    Open file in read-only mode
-       CALL open_read_file( TRIM( input_file_dynamic ) //                      &
-                            TRIM( coupling_char ), id_dynamic )
-
-!
-!--    At first, inquire all variable names.
-       CALL inquire_num_variables( id_dynamic, num_vars )
-!
-!--    Allocate memory to store variable names.
-       ALLOCATE( var_names(1:num_vars) )
-       CALL inquire_variable_names( id_dynamic, var_names )
-!
-!--    Read vertical dimension for soil depth. 
-       IF ( check_existence( var_names, 'zsoil' ) )                            &
-          CALL get_dimension_length( id_dynamic, init_3d%nzs, 'zsoil' )
-!
-!--    Read also the horizontal dimensions required for soil initialization.
-!--    Please note, in case of non-nested runs or in case of root domain, 
-!--    these data is already available, but will be read again for the sake
-!--    of clearness. 
-       CALL get_dimension_length( id_dynamic, init_3d%nx, 'x'  )
-       CALL get_dimension_length( id_dynamic, init_3d%ny, 'y'  )
-!
-!--    Check for correct horizontal and vertical dimension. Please note,
-!--    in case of non-nested runs or in case of root domain, these checks 
-!--    are already performed
-       IF ( init_3d%nx-1 /= nx  .OR.  init_3d%ny-1 /= ny )  THEN
-          message_string = 'Number of inifor horizontal grid points  '//       &
-                           'does not match the number of numeric grid points.'
-          CALL message( 'netcdf_data_input_mod', 'PA0543', 1, 2, 0, 6, 0 )
-       ENDIF
-!
-!--    Read vertical dimensions. Later, these are required for eventual
-!--    inter- and extrapolations of the initialization data.
-       IF ( check_existence( var_names, 'zsoil' ) )  THEN
-          ALLOCATE( init_3d%z_soil(1:init_3d%nzs) )
-          CALL get_variable( id_dynamic, 'zsoil', init_3d%z_soil )
-       ENDIF
-!
-!--    Read initial data for soil moisture
-       IF ( check_existence( var_names, 'init_soil_m' ) )  THEN
-!
-!--       Read attributes for the fill value and level-of-detail
-          CALL get_attribute( id_dynamic, char_fill,                           &
-                              init_3d%fill_msoil,                              &
-                              .FALSE., 'init_soil_m' )
-          CALL get_attribute( id_dynamic, char_lod,                            &
-                              init_3d%lod_msoil,                               &
-                              .FALSE., 'init_soil_m' )
-!
-!--       level-of-detail 1 - read initialization profile
-          IF ( init_3d%lod_msoil == 1 )  THEN
-             ALLOCATE( init_3d%msoil_1d(0:init_3d%nzs-1) )
-
-             CALL get_variable( id_dynamic, 'init_soil_m',                     &
-                                init_3d%msoil_1d(0:init_3d%nzs-1) )
-!
-!--       level-of-detail 2 - read 3D initialization data
-          ELSEIF ( init_3d%lod_msoil == 2 )  THEN
-             ALLOCATE ( init_3d%msoil_3d(0:init_3d%nzs-1,nys:nyn,nxl:nxr) )
-
-            CALL get_variable( id_dynamic, 'init_soil_m',                      &   
-                             init_3d%msoil_3d(0:init_3d%nzs-1,nys:nyn,nxl:nxr),&
-                             nxl, nxr, nys, nyn, 0, init_3d%nzs-1 )
-
-          ENDIF
-          init_3d%from_file_msoil = .TRUE.
-       ENDIF
-!
-!--    Read soil temperature
-       IF ( check_existence( var_names, 'init_soil_t' ) )  THEN
-!
-!--       Read attributes for the fill value and level-of-detail
-          CALL get_attribute( id_dynamic, char_fill,                           &
-                              init_3d%fill_tsoil,                              &
-                              .FALSE., 'init_soil_t' )
-          CALL get_attribute( id_dynamic, char_lod,                            &
-                              init_3d%lod_tsoil,                               &
-                              .FALSE., 'init_soil_t' )
-!
-!--       level-of-detail 1 - read initialization profile
-          IF ( init_3d%lod_tsoil == 1 )  THEN
-             ALLOCATE( init_3d%tsoil_1d(0:init_3d%nzs-1) )
-
-             CALL get_variable( id_dynamic, 'init_soil_t',                     &
-                                init_3d%tsoil_1d(0:init_3d%nzs-1) )
-
-!
-!--       level-of-detail 2 - read 3D initialization data
-          ELSEIF ( init_3d%lod_tsoil == 2 )  THEN
-             ALLOCATE ( init_3d%tsoil_3d(0:init_3d%nzs-1,nys:nyn,nxl:nxr) )
-             
-             CALL get_variable( id_dynamic, 'init_soil_t',                     &   
-                             init_3d%tsoil_3d(0:init_3d%nzs-1,nys:nyn,nxl:nxr),&
-                             nxl, nxr, nys, nyn, 0, init_3d%nzs-1 )
-          ENDIF
-          init_3d%from_file_tsoil = .TRUE.
-       ENDIF
-!
-!--    Close input file
-       CALL close_input_file( id_dynamic )
-#endif
-!
-!--    End of CPU measurement
-       CALL cpu_log( log_point_s(85), 'NetCDF input init', 'stop' )
-
-    END SUBROUTINE netcdf_data_input_init_lsm    
 
 !------------------------------------------------------------------------------!
@@ -3584,5 +3441,5 @@
                 message_string = 'Reading 3D building data - vertical ' //     &
                                  'coordinate do not match numeric grid.'
-                CALL message( 'netcdf_data_input_mod', 'PA0553', 2, 2, myid, 6, 0 )
+                CALL message( 'netcdf_data_input_mod', 'PA0553', 2, 2, 0, 6, 0 )
              ENDIF
           ENDIF
@@ -4227,262 +4084,4 @@
 
     END SUBROUTINE resize_array_4d_real
-    
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Vertical interpolation and extrapolation of 1D variables.
-!------------------------------------------------------------------------------!
-    SUBROUTINE netcdf_data_input_interpolate_1d( var, z_grid, z_file)
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  k       !< running index z-direction file
-       INTEGER(iwp) ::  kk      !< running index z-direction stretched model grid
-       INTEGER(iwp) ::  kl      !< lower index bound along z-direction
-       INTEGER(iwp) ::  ku      !< upper index bound along z-direction
-
-       REAL(wp), DIMENSION(:) ::  z_grid                  !< grid levels on numeric grid
-       REAL(wp), DIMENSION(:) ::  z_file                  !< grid levels on file grid
-       REAL(wp), DIMENSION(:), INTENT(INOUT) ::  var      !< treated variable
-       REAL(wp), DIMENSION(:), ALLOCATABLE   ::  var_tmp  !< temporary variable
-
-
-       kl = LBOUND(var,1)
-       ku = UBOUND(var,1)
-       ALLOCATE( var_tmp(kl:ku) )
-
-       DO  k = kl, ku
-
-          kk = MINLOC( ABS( z_file - z_grid(k) ), DIM = 1 )
-
-          IF ( kk < ku )  THEN
-             IF ( z_file(kk) - z_grid(k) <= 0.0_wp )  THEN
-                var_tmp(k) = var(kk) +                                         &
-                                       ( var(kk+1)        - var(kk)    ) /     &
-                                       ( z_file(kk+1)     - z_file(kk) ) *     &
-                                       ( z_grid(k)        - z_file(kk) )
-
-             ELSEIF ( z_file(kk) - z_grid(k) > 0.0_wp )  THEN
-                var_tmp(k) = var(kk-1) +                                       &
-                                         ( var(kk)     - var(kk-1)    ) /      &
-                                         ( z_file(kk)  - z_file(kk-1) ) *      &
-                                         ( z_grid(k)   - z_file(kk-1) )
-             ENDIF
-!
-!--       Extrapolate
-          ELSE
-
-             var_tmp(k) = var(ku) +   ( var(ku)    - var(ku-1)      ) /        &
-                                      ( z_file(ku) - z_file(ku-1)   ) *        &
-                                      ( z_grid(k)  - z_file(ku)     )
-
-          ENDIF
-
-       ENDDO
-       var(:) = var_tmp(:)
-
-       DEALLOCATE( var_tmp )
-
-
-    END SUBROUTINE netcdf_data_input_interpolate_1d
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Vertical interpolation and extrapolation of 1D variables from Inifor grid
-!> onto Palm grid, where both have same dimension. Please note, the passed
-!> paramter list in 1D version is different compared to 2D version.
-!------------------------------------------------------------------------------!
-    SUBROUTINE netcdf_data_input_interpolate_1d_soil( var, var_file,           &
-                                                      z_grid, z_file,          &
-                                                      nzb_var, nzt_var,        &
-                                                      nzb_file, nzt_file )
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  k        !< running index z-direction file
-       INTEGER(iwp) ::  kk       !< running index z-direction stretched model grid
-       INTEGER(iwp) ::  ku       !< upper index bound along z-direction for varialbe from file
-       INTEGER(iwp) ::  nzb_var  !< lower bound of final array
-       INTEGER(iwp) ::  nzt_var  !< upper bound of final array
-       INTEGER(iwp) ::  nzb_file !< lower bound of file array
-       INTEGER(iwp) ::  nzt_file !< upper bound of file array
-
-!        LOGICAL, OPTIONAL ::  zsoil !< flag indicating reverse z-axis, i.e. zsoil instead of height, e.g. in case of ocean or soil
-
-       REAL(wp), DIMENSION(nzb_var:nzt_var)   ::  z_grid   !< grid levels on numeric grid
-       REAL(wp), DIMENSION(nzb_file:nzt_file) ::  z_file   !< grid levels on file grid
-       REAL(wp), DIMENSION(nzb_var:nzt_var)   ::  var      !< treated variable
-       REAL(wp), DIMENSION(nzb_file:nzt_file) ::  var_file !< temporary variable
-
-       ku = nzt_file
-
-       DO  k = nzb_var, nzt_var
-!
-!--       Determine index on Inifor grid which is closest to the actual height
-          kk = MINLOC( ABS( z_file - z_grid(k) ), DIM = 1 )
-!
-!--       If closest index on Inifor grid is smaller than top index,
-!--       interpolate the data
-          IF ( kk < nzt_file )  THEN
-             IF ( z_file(kk) - z_grid(k) <= 0.0_wp )  THEN
-                var(k) = var_file(kk) + ( var_file(kk+1) - var_file(kk) ) /    &
-                                        ( z_file(kk+1)   - z_file(kk)   ) *    &
-                                        ( z_grid(k)      - z_file(kk)   )
-
-             ELSEIF ( z_file(kk) - z_grid(k) > 0.0_wp )  THEN
-                var(k) = var_file(kk-1) + ( var_file(kk) - var_file(kk-1) ) /  &
-                                          ( z_file(kk)   - z_file(kk-1)   ) *  &
-                                          ( z_grid(k)    - z_file(kk-1)   )
-             ENDIF
-!
-!--       Extrapolate if actual height is above the highest Inifor level by the last value
-          ELSE
-             var(k) = var_file(ku)
-          ENDIF
-
-       ENDDO
-
-    END SUBROUTINE netcdf_data_input_interpolate_1d_soil
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Vertical interpolation and extrapolation of 2D variables at lateral boundaries.
-!------------------------------------------------------------------------------!
-    SUBROUTINE netcdf_data_input_interpolate_2d( var, z_grid, z_file)
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i       !< running index x- or y -direction
-       INTEGER(iwp) ::  il      !< lower index bound along x- or y-direction
-       INTEGER(iwp) ::  iu      !< upper index bound along x- or y-direction
-       INTEGER(iwp) ::  k       !< running index z-direction file
-       INTEGER(iwp) ::  kk      !< running index z-direction stretched model grid
-       INTEGER(iwp) ::  kl      !< lower index bound along z-direction
-       INTEGER(iwp) ::  ku      !< upper index bound along z-direction
-
-       REAL(wp), DIMENSION(:) ::  z_grid                  !< grid levels on numeric grid
-       REAL(wp), DIMENSION(:) ::  z_file                  !< grid levels on file grid
-       REAL(wp), DIMENSION(:,:), INTENT(INOUT) ::  var    !< treated variable
-       REAL(wp), DIMENSION(:), ALLOCATABLE   ::  var_tmp  !< temporary variable
-
-
-       il = LBOUND(var,2)
-       iu = UBOUND(var,2)
-       kl = LBOUND(var,1)
-       ku = UBOUND(var,1)
-       ALLOCATE( var_tmp(kl:ku) )
-
-       DO  i = il, iu
-          DO  k = kl, ku
-
-             kk = MINLOC( ABS( z_file - z_grid(k) ), DIM = 1 )
-
-             IF ( kk < ku )  THEN
-                IF ( z_file(kk) - z_grid(k) <= 0.0_wp )  THEN
-                   var_tmp(k) = var(kk,i) +                                    &
-                                          ( var(kk+1,i)      - var(kk,i)  ) /  &
-                                          ( z_file(kk+1)     - z_file(kk) ) *  &
-                                          ( z_grid(k)        - z_file(kk) )
-
-                ELSEIF ( z_file(kk) - z_grid(k) > 0.0_wp )  THEN
-                   var_tmp(k) = var(kk-1,i) +                                  &
-                                            ( var(kk,i)   - var(kk-1,i)  ) /   &
-                                            ( z_file(kk)  - z_file(kk-1) ) *   &
-                                            ( z_grid(k)   - z_file(kk-1) )
-                ENDIF
-!
-!--          Extrapolate
-             ELSE
-
-                var_tmp(k) = var(ku,i) + ( var(ku,i)  - var(ku-1,i)    ) /     &
-                                         ( z_file(ku) - z_file(ku-1)   ) *     &
-                                         ( z_grid(k)  - z_file(ku)     )
-
-             ENDIF
-
-          ENDDO
-          var(:,i) = var_tmp(:)
-
-       ENDDO
-
-       DEALLOCATE( var_tmp )
-
-
-    END SUBROUTINE netcdf_data_input_interpolate_2d
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Vertical interpolation and extrapolation of 3D variables.
-!------------------------------------------------------------------------------!
-    SUBROUTINE netcdf_data_input_interpolate_3d( var, z_grid, z_file )
-
-       IMPLICIT NONE
-
-       INTEGER(iwp) ::  i       !< running index x-direction
-       INTEGER(iwp) ::  il      !< lower index bound along x-direction
-       INTEGER(iwp) ::  iu      !< upper index bound along x-direction
-       INTEGER(iwp) ::  j       !< running index y-direction
-       INTEGER(iwp) ::  jl      !< lower index bound along x-direction
-       INTEGER(iwp) ::  ju      !< upper index bound along x-direction
-       INTEGER(iwp) ::  k       !< running index z-direction file
-       INTEGER(iwp) ::  kk      !< running index z-direction stretched model grid
-       INTEGER(iwp) ::  kl      !< lower index bound along z-direction
-       INTEGER(iwp) ::  ku      !< upper index bound along z-direction
-
-       REAL(wp), DIMENSION(:) ::  z_grid                      !< grid levels on numeric grid
-       REAL(wp), DIMENSION(:) ::  z_file                      !< grid levels on file grid
-       REAL(wp), DIMENSION(:,:,:), INTENT(INOUT) ::  var      !< treated variable
-       REAL(wp), DIMENSION(:), ALLOCATABLE       ::  var_tmp  !< temporary variable
-
-       il = LBOUND(var,3)
-       iu = UBOUND(var,3)
-       jl = LBOUND(var,2)
-       ju = UBOUND(var,2)
-       kl = LBOUND(var,1)
-       ku = UBOUND(var,1)
-
-       ALLOCATE( var_tmp(kl:ku) )
-
-       DO  i = il, iu
-          DO  j = jl, ju
-             DO  k = kl, ku
-
-                kk = MINLOC( ABS( z_file - z_grid(k) ), DIM = 1 )
-
-                IF ( kk < ku )  THEN
-                   IF ( z_file(kk) - z_grid(k) <= 0.0_wp )  THEN
-                      var_tmp(k) = var(kk,j,i) +                               &
-                                             ( var(kk+1,j,i) - var(kk,j,i) ) / &
-                                             ( z_file(kk+1)  - z_file(kk)  ) * &
-                                             ( z_grid(k)     - z_file(kk)  )
-
-                   ELSEIF ( z_file(kk) - z_grid(k) > 0.0_wp )  THEN
-                      var_tmp(k) = var(kk-1,j,i) +                             &
-                                             ( var(kk,j,i) - var(kk-1,j,i) ) / &
-                                             ( z_file(kk)  - z_file(kk-1)  ) * &
-                                             ( z_grid(k)   - z_file(kk-1)  )
-                   ENDIF
-!
-!--             Extrapolate
-                ELSE
-                   var_tmp(k) = var(ku,j,i) +                                  &
-                                       ( var(ku,j,i)  - var(ku-1,j,i)   ) /    &
-                                       ( z_file(ku)   - z_file(ku-1)    ) *    &
-                                       ( z_grid(k)    - z_file(ku)      )
-
-                ENDIF
-             ENDDO
-             var(:,j,i) = var_tmp(:)
-          ENDDO
-       ENDDO
-
-       DEALLOCATE( var_tmp )
-
-
-    END SUBROUTINE netcdf_data_input_interpolate_3d
 
 !------------------------------------------------------------------------------!
