Index: palm/trunk/SOURCE/nesting_offl_mod.f90
===================================================================
--- palm/trunk/SOURCE/nesting_offl_mod.f90	(revision 4225)
+++ palm/trunk/SOURCE/nesting_offl_mod.f90	(revision 4226)
@@ -25,4 +25,10 @@
 ! -----------------
 ! $Id$
+! - Data input moved into nesting_offl_mod
+! - check rephrased
+! - time variable is now relative to time_utc_init
+! - Define module specific data type for offline nesting in nesting_offl_mod
+! 
+! 4182 2019-08-22 15:20:23Z scharf
 ! Corrected "Former revisions" section
 ! 
@@ -99,6 +105,27 @@
 
     USE arrays_3d,                                                             &
-        ONLY:  dzw, e, diss, pt, pt_init, q, q_init, s, u, u_init, ug, v,      &
-               v_init, vg, w, zu, zw
+        ONLY:  dzw,                                                            &
+               e,                                                              &
+               diss,                                                           &
+               pt,                                                             &
+               pt_init,                                                        &
+               q,                                                              &
+               q_init,                                                         &
+               rdf,                                                            &
+               rdf_sc,                                                         &
+               s,                                                              &
+               u,                                                              &
+               u_init,                                                         &
+               ug,                                                             &
+               v,                                                              &
+               v_init,                                                         &
+               vg,                                                             &
+               w,                                                              &
+               zu,                                                             &
+               zw
+
+    USE basic_constants_and_equations_mod,                                     &
+           ONLY:  g,                                                           &
+                  pi
                  
     USE chem_modules,                                                          &
@@ -111,4 +138,5 @@
                bc_dirichlet_r,                                                 &
                bc_dirichlet_s,                                                 &
+               coupling_char,                                                  &
                dt_3d,                                                          &
                dz,                                                             &
@@ -132,5 +160,10 @@
                
     USE cpulog,                                                                &
-        ONLY:  cpu_log, log_point
+        ONLY:  cpu_log,                                                        &
+               log_point,                                                      &
+               log_point_s
+
+    USE date_and_time_mod,                                                     &
+        ONLY:  time_utc_init
 
     USE grid_variables
@@ -145,10 +178,104 @@
 
     USE netcdf_data_input_mod,                                                 &
-        ONLY:  nest_offl
-        
+        ONLY:  check_existence,                                                &
+               close_input_file,                                               &
+               get_dimension_length,                                           &
+               get_variable,                                                   &
+               get_variable_pr,                                                &
+               input_pids_dynamic,                                             &
+               inquire_num_variables,                                          &
+               inquire_variable_names,                                         &
+               input_file_dynamic,                                             &
+               num_var_pids,                                                   &
+               open_read_file,                                                 &
+               pids_id
+
     USE pegrid
 
+    IMPLICIT NONE
+
+!
+!-- Define data type for nesting in larger-scale models like COSMO.
+!-- Data type comprises u, v, w, pt, and q at lateral and top boundaries.
+    TYPE nest_offl_type
+
+       CHARACTER(LEN=16) ::  char_l = 'ls_forcing_left_'  !< leading substring for variables at left boundary 
+       CHARACTER(LEN=17) ::  char_n = 'ls_forcing_north_' !< leading substring for variables at north boundary  
+       CHARACTER(LEN=17) ::  char_r = 'ls_forcing_right_' !< leading substring for variables at right boundary  
+       CHARACTER(LEN=17) ::  char_s = 'ls_forcing_south_' !< leading substring for variables at south boundary 
+       CHARACTER(LEN=15) ::  char_t = 'ls_forcing_top_'   !< leading substring for variables at top boundary 
+
+       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names         !< list of variable in dynamic input file
+       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names_chem_l  !< names of mesoscale nested chemistry variables at left boundary
+       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names_chem_n  !< names of mesoscale nested chemistry variables at north boundary
+       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names_chem_r  !< names of mesoscale nested chemistry variables at right boundary
+       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names_chem_s  !< names of mesoscale nested chemistry variables at south boundary
+       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names_chem_t  !< names of mesoscale nested chemistry variables at top boundary
+
+       INTEGER(iwp) ::  nt     !< number of time levels in dynamic input file
+       INTEGER(iwp) ::  nzu    !< number of vertical levels on scalar grid in dynamic input file
+       INTEGER(iwp) ::  nzw    !< number of vertical levels on w grid in dynamic input file
+       INTEGER(iwp) ::  tind   !< time index for reference time in mesoscale-offline nesting
+       INTEGER(iwp) ::  tind_p !< time index for following time in mesoscale-offline nesting
+
+       LOGICAL      ::  init         = .FALSE. !< flag indicating that offline nesting is already initialized
+
+       LOGICAL, DIMENSION(:), ALLOCATABLE ::  chem_from_file_l !< flags inidicating whether left boundary data for chemistry is in dynamic input file  
+       LOGICAL, DIMENSION(:), ALLOCATABLE ::  chem_from_file_n !< flags inidicating whether north boundary data for chemistry is in dynamic input file 
+       LOGICAL, DIMENSION(:), ALLOCATABLE ::  chem_from_file_r !< flags inidicating whether right boundary data for chemistry is in dynamic input file 
+       LOGICAL, DIMENSION(:), ALLOCATABLE ::  chem_from_file_s !< flags inidicating whether south boundary data for chemistry is in dynamic input file 
+       LOGICAL, DIMENSION(:), ALLOCATABLE ::  chem_from_file_t !< flags inidicating whether top boundary data for chemistry is in dynamic input file 
+
+       REAL(wp), DIMENSION(:), ALLOCATABLE ::  surface_pressure !< time dependent surface pressure
+       REAL(wp), DIMENSION(:), ALLOCATABLE ::  time             !< time levels in dynamic input file
+       REAL(wp), DIMENSION(:), ALLOCATABLE ::  zu_atmos         !< vertical levels at scalar grid in dynamic input file
+       REAL(wp), DIMENSION(:), ALLOCATABLE ::  zw_atmos         !< vertical levels at w grid in dynamic input file
+
+       REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  ug         !< domain-averaged geostrophic component
+       REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  vg         !< domain-averaged geostrophic component
+
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u_left   !< u-component at left boundary
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  v_left   !< v-component at left boundary
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  w_left   !< w-component at left boundary
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  q_left   !< mixing ratio at left boundary
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pt_left  !< potentital temperautre at left boundary
+
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u_north  !< u-component at north boundary
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  v_north  !< v-component at north boundary
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  w_north  !< w-component at north boundary
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  q_north  !< mixing ratio at north boundary
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pt_north !< potentital temperautre at north boundary
+
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u_right  !< u-component at right boundary
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  v_right  !< v-component at right boundary
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  w_right  !< w-component at right boundary
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  q_right  !< mixing ratio at right boundary
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pt_right !< potentital temperautre at right boundary
+
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u_south  !< u-component at south boundary
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  v_south  !< v-component at south boundary
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  w_south  !< w-component at south boundary
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  q_south  !< mixing ratio at south boundary
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pt_south !< potentital temperautre at south boundary
+
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u_top    !< u-component at top boundary
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  v_top    !< v-component at top boundary
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  w_top    !< w-component at top boundary
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  q_top    !< mixing ratio at top boundary
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pt_top   !< potentital temperautre at top boundary
+       
+       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  chem_left   !< chemical species at left boundary
+       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  chem_north  !< chemical species at left boundary
+       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  chem_right  !< chemical species at left boundary
+       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  chem_south  !< chemical species at left boundary
+       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  chem_top    !< chemical species at left boundary
+
+    END TYPE nest_offl_type
+
+    REAL(wp) ::  fac_dt              !< interpolation factor
     REAL(wp) ::  zi_ribulk = 0.0_wp  !< boundary-layer depth according to bulk Richardson criterion, i.e. the height where Ri_bulk exceeds the critical
-                                     !< bulk Richardson number of 0.25
+                                     !< bulk Richardson number of 0.2
+
+    TYPE(nest_offl_type) ::  nest_offl  !< data structure for data input at lateral and top boundaries (provided by Inifor) 
     
     SAVE
@@ -159,6 +286,9 @@
            nesting_offl_calc_zi,                                               &
            nesting_offl_check_parameters,                                      &
+           nesting_offl_geostrophic_wind,                                      &
            nesting_offl_header,                                                &
            nesting_offl_init,                                                  &
+           nesting_offl_input,                                                 &
+           nesting_offl_interpolation_factor,                                  &
            nesting_offl_mass_conservation,                                     &
            nesting_offl_parin 
@@ -178,4 +308,8 @@
        MODULE PROCEDURE nesting_offl_check_parameters
     END INTERFACE nesting_offl_check_parameters
+
+    INTERFACE nesting_offl_geostrophic_wind
+       MODULE PROCEDURE nesting_offl_geostrophic_wind
+    END INTERFACE nesting_offl_geostrophic_wind
     
     INTERFACE nesting_offl_header
@@ -186,4 +320,12 @@
        MODULE PROCEDURE nesting_offl_init
     END INTERFACE nesting_offl_init
+
+    INTERFACE nesting_offl_input
+       MODULE PROCEDURE nesting_offl_input
+    END INTERFACE nesting_offl_input
+
+    INTERFACE nesting_offl_interpolation_factor
+       MODULE PROCEDURE nesting_offl_interpolation_factor
+    END INTERFACE nesting_offl_interpolation_factor
            
     INTERFACE nesting_offl_mass_conservation
@@ -197,4 +339,464 @@
  CONTAINS
 
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Reads data at lateral and top boundaries derived from larger-scale model.
+!------------------------------------------------------------------------------!
+    SUBROUTINE nesting_offl_input
+
+       INTEGER(iwp) ::  n   !< running index for chemistry variables
+       INTEGER(iwp) ::  t   !< running index time dimension
+
+!
+!--    Initialize INIFOR forcing in first call. 
+       IF ( .NOT. nest_offl%init )  THEN
+#if defined ( __netcdf )
+!
+!--       Open file in read-only mode
+          CALL open_read_file( TRIM( input_file_dynamic ) //                   &
+                               TRIM( coupling_char ), pids_id )
+!
+!--       At first, inquire all variable names.
+          CALL inquire_num_variables( pids_id, num_var_pids )
+!
+!--       Allocate memory to store variable names.
+          ALLOCATE( nest_offl%var_names(1:num_var_pids) )
+          CALL inquire_variable_names( pids_id, nest_offl%var_names )
+!
+!--       Read time dimension, allocate memory and finally read time array
+          CALL get_dimension_length( pids_id, nest_offl%nt, 'time' )
+
+          IF ( check_existence( nest_offl%var_names, 'time' ) )  THEN
+             ALLOCATE( nest_offl%time(0:nest_offl%nt-1) )
+             CALL get_variable( pids_id, 'time', nest_offl%time )
+          ENDIF
+!
+!--       Read vertical dimension of scalar und w grid
+          CALL get_dimension_length( pids_id, nest_offl%nzu, 'z' )
+          CALL get_dimension_length( pids_id, nest_offl%nzw, 'zw' )
+
+          IF ( check_existence( nest_offl%var_names, 'z' ) )  THEN
+             ALLOCATE( nest_offl%zu_atmos(1:nest_offl%nzu) )
+             CALL get_variable( pids_id, 'z', nest_offl%zu_atmos )
+          ENDIF
+          IF ( check_existence( nest_offl%var_names, 'zw' ) )  THEN
+             ALLOCATE( nest_offl%zw_atmos(1:nest_offl%nzw) )
+             CALL get_variable( pids_id, 'zw', nest_offl%zw_atmos )
+          ENDIF
+!
+!--       Read surface pressure
+          IF ( check_existence( nest_offl%var_names,                           &
+                                'surface_forcing_surface_pressure' ) )  THEN
+             ALLOCATE( nest_offl%surface_pressure(0:nest_offl%nt-1) )
+             CALL get_variable( pids_id,                                       &
+                                'surface_forcing_surface_pressure',            &
+                                nest_offl%surface_pressure )
+          ENDIF
+!
+!--       Close input file
+          CALL close_input_file( pids_id )
+#endif
+       ENDIF
+!
+!--    Check if dynamic driver data input is required.
+       IF ( nest_offl%time(nest_offl%tind_p) <=                                &
+            MAX( time_since_reference_point, 0.0_wp) + time_utc_init  .OR.                   &
+            .NOT.  nest_offl%init )  THEN
+          CONTINUE
+!
+!--    Return otherwise
+       ELSE
+          RETURN
+       ENDIF
+!
+!--    CPU measurement
+       CALL cpu_log( log_point_s(86), 'NetCDF input forcing', 'start' )
+
+!
+!--    Obtain time index for current point in time. Note, the time coordinate
+!--    in the input file is relative to time_utc_init. Since time_since_...
+!--    is negativ when spinup is used, use MAX function to obtain correct 
+!--    time at the beginning. 
+       nest_offl%tind = MINLOC( ABS( nest_offl%time - (                        &
+                                     time_utc_init +                           &
+                                     MAX( time_since_reference_point, 0.0_wp) )&
+                                   ), DIM = 1 ) - 1
+       nest_offl%tind_p = nest_offl%tind + 1
+!
+!--    Open file in read-only mode
+#if defined ( __netcdf )
+       CALL open_read_file( TRIM( input_file_dynamic ) //                      &
+                            TRIM( coupling_char ), pids_id )
+!
+!--    Read geostrophic wind components
+       DO  t = nest_offl%tind, nest_offl%tind_p
+          CALL get_variable_pr( pids_id, 'ls_forcing_ug', t+1,                 &
+                                nest_offl%ug(t-nest_offl%tind,nzb+1:nzt) )
+          CALL get_variable_pr( pids_id, 'ls_forcing_vg', t+1,                 &
+                                nest_offl%vg(t-nest_offl%tind,nzb+1:nzt) )
+       ENDDO
+!
+!--    Read data at lateral and top boundaries. Please note, at left and
+!--    right domain boundary, yz-layers are read for u, v, w, pt and q.
+!--    For the v-component, the data starts at nysv, while for the other
+!--    quantities the data starts at nys. This is equivalent at the north
+!--    and south domain boundary for the u-component. 
+!--    Note, lateral data is also accessed by parallel IO, which is the reason
+!--    why different arguments are passed depending on the boundary control
+!--    flags. Cores that do not belong to the respective boundary just make
+!--    a dummy read with count = 0, just in order to participate the collective
+!--    operation. 
+!--    Read data for western boundary    
+       CALL get_variable( pids_id, 'ls_forcing_left_u',                        &
+                          nest_offl%u_left,                                    & ! array to be read
+                          MERGE( nys+1, 1, bc_dirichlet_l),                    & ! start index y direction
+                          MERGE( nzb+1, 1, bc_dirichlet_l),                    & ! start index z direction
+                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_l),         & ! start index time dimension
+                          MERGE( nyn-nys+1, 0, bc_dirichlet_l),                & ! number of elements along y
+                          MERGE( nest_offl%nzu, 0, bc_dirichlet_l),            & ! number of elements alogn z
+                          MERGE( 2, 0, bc_dirichlet_l),                        & ! number of time steps (2 or 0)
+                          .TRUE. )                                               ! parallel IO when compiled accordingly
+      
+       CALL get_variable( pids_id, 'ls_forcing_left_v',                        &
+                          nest_offl%v_left,                                    &
+                          MERGE( nysv, 1, bc_dirichlet_l),                     &
+                          MERGE( nzb+1, 1, bc_dirichlet_l),                    &
+                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_l),         &
+                          MERGE( nyn-nysv+1, 0, bc_dirichlet_l),               &
+                          MERGE( nest_offl%nzu, 0, bc_dirichlet_l),            &
+                          MERGE( 2, 0, bc_dirichlet_l),                        &
+                          .TRUE. )                                        
+
+       CALL get_variable( pids_id, 'ls_forcing_left_w',                        &
+                          nest_offl%w_left,                                    &
+                          MERGE( nys+1, 1, bc_dirichlet_l),                    &
+                          MERGE( nzb+1, 1, bc_dirichlet_l),                    &
+                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_l),         &
+                          MERGE( nyn-nys+1, 0, bc_dirichlet_l),                &
+                          MERGE( nest_offl%nzw, 0, bc_dirichlet_l),            &
+                          MERGE( 2, 0, bc_dirichlet_l),                        &
+                          .TRUE. )   
+
+       IF ( .NOT. neutral )  THEN
+          CALL get_variable( pids_id, 'ls_forcing_left_pt',                    &
+                             nest_offl%pt_left,                                &
+                             MERGE( nys+1, 1, bc_dirichlet_l),                 &
+                             MERGE( nzb+1, 1, bc_dirichlet_l),                 &
+                             MERGE( nest_offl%tind+1, 1, bc_dirichlet_l),      &
+                             MERGE( nyn-nys+1, 0, bc_dirichlet_l),             &
+                             MERGE( nest_offl%nzu, 0, bc_dirichlet_l),         &
+                             MERGE( 2, 0, bc_dirichlet_l),                     &
+                             .TRUE. )
+       ENDIF
+
+       IF ( humidity )  THEN
+          CALL get_variable( pids_id, 'ls_forcing_left_qv',                    &
+                             nest_offl%q_left,                                 &
+                             MERGE( nys+1, 1, bc_dirichlet_l),                 &
+                             MERGE( nzb+1, 1, bc_dirichlet_l),                 &
+                             MERGE( nest_offl%tind+1, 1, bc_dirichlet_l),      &
+                             MERGE( nyn-nys+1, 0, bc_dirichlet_l),             &
+                             MERGE( nest_offl%nzu, 0, bc_dirichlet_l),         &
+                             MERGE( 2, 0, bc_dirichlet_l),                     &
+                             .TRUE. )
+       ENDIF
+       
+       IF ( air_chemistry )  THEN
+          DO  n = 1, UBOUND(nest_offl%var_names_chem_l, 1)
+             IF ( check_existence( nest_offl%var_names,                        &
+                                   nest_offl%var_names_chem_l(n) ) )  THEN  
+                CALL get_variable( pids_id,                                    &
+                           TRIM( nest_offl%var_names_chem_l(n) ),              &
+                           nest_offl%chem_left(:,:,:,n),                       &
+                           MERGE( nys+1, 1, bc_dirichlet_l),                   &
+                           MERGE( nzb+1, 1, bc_dirichlet_l),                   &
+                           MERGE( nest_offl%tind+1, 1, bc_dirichlet_l),        &
+                           MERGE( nyn-nys+1, 0, bc_dirichlet_l),               &
+                           MERGE( nest_offl%nzu, 0, bc_dirichlet_l),           &
+                           MERGE( 2, 0, bc_dirichlet_l),                       &
+                           .TRUE. )
+                nest_offl%chem_from_file_l(n) = .TRUE.
+             ENDIF
+          ENDDO
+       ENDIF
+!
+!--    Read data for eastern boundary    
+       CALL get_variable( pids_id, 'ls_forcing_right_u',                       &
+                          nest_offl%u_right,                                   &
+                          MERGE( nys+1, 1, bc_dirichlet_r),                    &
+                          MERGE( nzb+1, 1, bc_dirichlet_r),                    &
+                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_r),         &
+                          MERGE( nyn-nys+1, 0, bc_dirichlet_r),                &
+                          MERGE( nest_offl%nzu, 0, bc_dirichlet_r),            &
+                          MERGE( 2, 0, bc_dirichlet_r),                        &
+                          .TRUE. )                                             
+      
+       CALL get_variable( pids_id, 'ls_forcing_right_v',                       &
+                          nest_offl%v_right,                                   &
+                          MERGE( nysv, 1, bc_dirichlet_r),                     &
+                          MERGE( nzb+1, 1, bc_dirichlet_r),                    &
+                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_r),         &
+                          MERGE( nyn-nysv+1, 0, bc_dirichlet_r),               &
+                          MERGE( nest_offl%nzu, 0, bc_dirichlet_r),            &
+                          MERGE( 2, 0, bc_dirichlet_r),                        &
+                          .TRUE. )                                             
+
+       CALL get_variable( pids_id, 'ls_forcing_right_w',                       &
+                          nest_offl%w_right,                                   &
+                          MERGE( nys+1, 1, bc_dirichlet_r),                    &
+                          MERGE( nzb+1, 1, bc_dirichlet_r),                    &
+                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_r),         &
+                          MERGE( nyn-nys+1, 0, bc_dirichlet_r),                &
+                          MERGE( nest_offl%nzw, 0, bc_dirichlet_r),            &
+                          MERGE( 2, 0, bc_dirichlet_r),                        &
+                          .TRUE. )   
+
+       IF ( .NOT. neutral )  THEN
+          CALL get_variable( pids_id, 'ls_forcing_right_pt',                   &
+                             nest_offl%pt_right,                               &
+                             MERGE( nys+1, 1, bc_dirichlet_r),                 &
+                             MERGE( nzb+1, 1, bc_dirichlet_r),                 &
+                             MERGE( nest_offl%tind+1, 1, bc_dirichlet_r),      &
+                             MERGE( nyn-nys+1, 0, bc_dirichlet_r),             &
+                             MERGE( nest_offl%nzu, 0, bc_dirichlet_r),         &
+                             MERGE( 2, 0, bc_dirichlet_r),                     &
+                             .TRUE. )
+       ENDIF
+
+       IF ( humidity )  THEN
+          CALL get_variable( pids_id, 'ls_forcing_right_qv',                   &
+                             nest_offl%q_right,                                &
+                             MERGE( nys+1, 1, bc_dirichlet_r),                 &
+                             MERGE( nzb+1, 1, bc_dirichlet_r),                 &
+                             MERGE( nest_offl%tind+1, 1, bc_dirichlet_r),      &
+                             MERGE( nyn-nys+1, 0, bc_dirichlet_r),             &
+                             MERGE( nest_offl%nzu, 0, bc_dirichlet_r),         &
+                             MERGE( 2, 0, bc_dirichlet_r),                     &
+                             .TRUE. )
+       ENDIF
+       
+       IF ( air_chemistry )  THEN
+          DO  n = 1, UBOUND(nest_offl%var_names_chem_r, 1)
+             IF ( check_existence( nest_offl%var_names,                        &
+                                   nest_offl%var_names_chem_r(n) ) )  THEN     
+                CALL get_variable( pids_id,                                    &
+                           TRIM( nest_offl%var_names_chem_r(n) ),              &
+                           nest_offl%chem_right(:,:,:,n),                      &
+                           MERGE( nys+1, 1, bc_dirichlet_r),                   &
+                           MERGE( nzb+1, 1, bc_dirichlet_r),                   &
+                           MERGE( nest_offl%tind+1, 1, bc_dirichlet_r),        &
+                           MERGE( nyn-nys+1, 0, bc_dirichlet_r),               &
+                           MERGE( nest_offl%nzu, 0, bc_dirichlet_r),           &
+                           MERGE( 2, 0, bc_dirichlet_r),                       &
+                           .TRUE. )
+                nest_offl%chem_from_file_r(n) = .TRUE.
+             ENDIF
+          ENDDO
+       ENDIF
+!
+!--    Read data for northern boundary
+       CALL get_variable( pids_id, 'ls_forcing_north_u',                       & ! array to be read
+                          nest_offl%u_north,                                   & ! start index x direction
+                          MERGE( nxlu, 1, bc_dirichlet_n ),                    & ! start index z direction
+                          MERGE( nzb+1, 1, bc_dirichlet_n ),                   & ! start index time dimension
+                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_n ),        & ! number of elements along x
+                          MERGE( nxr-nxlu+1, 0, bc_dirichlet_n ),              & ! number of elements alogn z 
+                          MERGE( nest_offl%nzu, 0, bc_dirichlet_n ),           & ! number of time steps (2 or 0)
+                          MERGE( 2, 0, bc_dirichlet_n ),                       & ! parallel IO when compiled accordingly
+                          .TRUE. )                                             
+                                                                               
+       CALL get_variable( pids_id, 'ls_forcing_north_v',                       & ! array to be read
+                          nest_offl%v_north,                                   & ! start index x direction
+                          MERGE( nxl+1, 1, bc_dirichlet_n ),                   & ! start index z direction
+                          MERGE( nzb+1, 1, bc_dirichlet_n ),                   & ! start index time dimension
+                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_n ),        & ! number of elements along x
+                          MERGE( nxr-nxl+1, 0, bc_dirichlet_n ),               & ! number of elements alogn z 
+                          MERGE( nest_offl%nzu, 0, bc_dirichlet_n ),           & ! number of time steps (2 or 0)
+                          MERGE( 2, 0, bc_dirichlet_n ),                       & ! parallel IO when compiled accordingly
+                          .TRUE. )                                             
+                                                                               
+       CALL get_variable( pids_id, 'ls_forcing_north_w',                       & ! array to be read
+                          nest_offl%w_north,                                   & ! start index x direction
+                          MERGE( nxl+1, 1, bc_dirichlet_n ),                   & ! start index z direction
+                          MERGE( nzb+1, 1, bc_dirichlet_n ),                   & ! start index time dimension
+                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_n ),        & ! number of elements along x
+                          MERGE( nxr-nxl+1, 0, bc_dirichlet_n ),               & ! number of elements alogn z 
+                          MERGE( nest_offl%nzw, 0, bc_dirichlet_n ),           & ! number of time steps (2 or 0)
+                          MERGE( 2, 0, bc_dirichlet_n ),                       & ! parallel IO when compiled accordingly
+                          .TRUE. )                                             
+                                                                               
+       IF ( .NOT. neutral )  THEN                                              
+          CALL get_variable( pids_id, 'ls_forcing_north_pt',                   & ! array to be read
+                             nest_offl%pt_north,                               & ! start index x direction
+                             MERGE( nxl+1, 1, bc_dirichlet_n ),                & ! start index z direction
+                             MERGE( nzb+1, 1, bc_dirichlet_n ),                & ! start index time dimension
+                             MERGE( nest_offl%tind+1, 1, bc_dirichlet_n ),     & ! number of elements along x
+                             MERGE( nxr-nxl+1, 0, bc_dirichlet_n ),            & ! number of elements alogn z 
+                             MERGE( nest_offl%nzu, 0, bc_dirichlet_n ),        & ! number of time steps (2 or 0)
+                             MERGE( 2, 0, bc_dirichlet_n ),                    & ! parallel IO when compiled accordingly
+                             .TRUE. )                                             
+       ENDIF                                                                   
+       IF ( humidity )  THEN                                                   
+          CALL get_variable( pids_id, 'ls_forcing_north_qv',                   & ! array to be read
+                             nest_offl%q_north,                                & ! start index x direction
+                             MERGE( nxl+1, 1, bc_dirichlet_n ),                & ! start index z direction
+                             MERGE( nzb+1, 1, bc_dirichlet_n ),                & ! start index time dimension
+                             MERGE( nest_offl%tind+1, 1, bc_dirichlet_n ),     & ! number of elements along x
+                             MERGE( nxr-nxl+1, 0, bc_dirichlet_n ),            & ! number of elements alogn z 
+                             MERGE( nest_offl%nzu, 0, bc_dirichlet_n ),        & ! number of time steps (2 or 0)
+                             MERGE( 2, 0, bc_dirichlet_n ),                    & ! parallel IO when compiled accordingly
+                             .TRUE. )                                             
+       ENDIF                                                                   
+                                                                               
+       IF ( air_chemistry )  THEN                                              
+          DO  n = 1, UBOUND(nest_offl%var_names_chem_n, 1)                     
+             IF ( check_existence( nest_offl%var_names,                        &
+                                   nest_offl%var_names_chem_n(n) ) )  THEN     
+                CALL get_variable( pids_id,                                    &
+                           TRIM( nest_offl%var_names_chem_n(n) ),              &
+                           nest_offl%chem_north(:,:,:,n),                      &
+                           MERGE( nxl+1, 1, bc_dirichlet_n ),                  &
+                           MERGE( nzb+1, 1, bc_dirichlet_n ),                  &
+                           MERGE( nest_offl%tind+1, 1, bc_dirichlet_n ),       &
+                           MERGE( nxr-nxl+1, 0, bc_dirichlet_n ),              &
+                           MERGE( nest_offl%nzu, 0, bc_dirichlet_n ),          &
+                           MERGE( 2, 0, bc_dirichlet_n ),                      &
+                           .TRUE. )
+                nest_offl%chem_from_file_n(n) = .TRUE.
+             ENDIF
+          ENDDO
+       ENDIF
+!
+!--    Read data for southern boundary
+       CALL get_variable( pids_id, 'ls_forcing_south_u',                       & ! array to be read
+                          nest_offl%u_south,                                   & ! start index x direction
+                          MERGE( nxlu, 1, bc_dirichlet_s ),                    & ! start index z direction
+                          MERGE( nzb+1, 1, bc_dirichlet_s ),                   & ! start index time dimension
+                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_s ),        & ! number of elements along x
+                          MERGE( nxr-nxlu+1, 0, bc_dirichlet_s ),              & ! number of elements alogn z 
+                          MERGE( nest_offl%nzu, 0, bc_dirichlet_s ),           & ! number of time steps (2 or 0)
+                          MERGE( 2, 0, bc_dirichlet_s ),                       & ! parallel IO when compiled accordingly
+                          .TRUE. )                                             
+                                                                               
+       CALL get_variable( pids_id, 'ls_forcing_south_v',                       & ! array to be read
+                          nest_offl%v_south,                                   & ! start index x direction
+                          MERGE( nxl+1, 1, bc_dirichlet_s ),                   & ! start index z direction
+                          MERGE( nzb+1, 1, bc_dirichlet_s ),                   & ! start index time dimension
+                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_s ),        & ! number of elements along x
+                          MERGE( nxr-nxl+1, 0, bc_dirichlet_s ),               & ! number of elements alogn z 
+                          MERGE( nest_offl%nzu, 0, bc_dirichlet_s ),           & ! number of time steps (2 or 0)
+                          MERGE( 2, 0, bc_dirichlet_s ),                       & ! parallel IO when compiled accordingly
+                          .TRUE. )                                             
+                                                                               
+       CALL get_variable( pids_id, 'ls_forcing_south_w',                       & ! array to be read
+                          nest_offl%w_south,                                   & ! start index x direction
+                          MERGE( nxl+1, 1, bc_dirichlet_s ),                   & ! start index z direction
+                          MERGE( nzb+1, 1, bc_dirichlet_s ),                   & ! start index time dimension
+                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_s ),        & ! number of elements along x
+                          MERGE( nxr-nxl+1, 0, bc_dirichlet_s ),               & ! number of elements alogn z 
+                          MERGE( nest_offl%nzw, 0, bc_dirichlet_s ),           & ! number of time steps (2 or 0)
+                          MERGE( 2, 0, bc_dirichlet_s ),                       & ! parallel IO when compiled accordingly
+                          .TRUE. )                                             
+                                                                               
+       IF ( .NOT. neutral )  THEN                                              
+          CALL get_variable( pids_id, 'ls_forcing_south_pt',                   & ! array to be read
+                             nest_offl%pt_south,                               & ! start index x direction
+                             MERGE( nxl+1, 1, bc_dirichlet_s ),                & ! start index z direction
+                             MERGE( nzb+1, 1, bc_dirichlet_s ),                & ! start index time dimension
+                             MERGE( nest_offl%tind+1, 1, bc_dirichlet_s ),     & ! number of elements along x
+                             MERGE( nxr-nxl+1, 0, bc_dirichlet_s ),            & ! number of elements alogn z 
+                             MERGE( nest_offl%nzu, 0, bc_dirichlet_s ),        & ! number of time steps (2 or 0)
+                             MERGE( 2, 0, bc_dirichlet_s ),                    & ! parallel IO when compiled accordingly
+                             .TRUE. )                                             
+       ENDIF                                                                   
+       IF ( humidity )  THEN                                                   
+          CALL get_variable( pids_id, 'ls_forcing_south_qv',                   & ! array to be read
+                             nest_offl%q_south,                                & ! start index x direction
+                             MERGE( nxl+1, 1, bc_dirichlet_s ),                & ! start index z direction
+                             MERGE( nzb+1, 1, bc_dirichlet_s ),                & ! start index time dimension
+                             MERGE( nest_offl%tind+1, 1, bc_dirichlet_s ),     & ! number of elements along x
+                             MERGE( nxr-nxl+1, 0, bc_dirichlet_s ),            & ! number of elements alogn z 
+                             MERGE( nest_offl%nzu, 0, bc_dirichlet_s ),        & ! number of time steps (2 or 0)
+                             MERGE( 2, 0, bc_dirichlet_s ),                    & ! parallel IO when compiled accordingly
+                             .TRUE. )                                             
+       ENDIF                                                                   
+                                                                               
+       IF ( air_chemistry )  THEN                                              
+          DO  n = 1, UBOUND(nest_offl%var_names_chem_s, 1)                     
+             IF ( check_existence( nest_offl%var_names,                        &
+                                   nest_offl%var_names_chem_s(n) ) )  THEN     
+                CALL get_variable( pids_id,                                    &
+                           TRIM( nest_offl%var_names_chem_s(n) ),              &
+                           nest_offl%chem_south(:,:,:,n),                      &
+                           MERGE( nxl+1, 1, bc_dirichlet_s ),                  &
+                           MERGE( nzb+1, 1, bc_dirichlet_s ),                  &
+                           MERGE( nest_offl%tind+1, 1, bc_dirichlet_s ),       &
+                           MERGE( nxr-nxl+1, 0, bc_dirichlet_s ),              &
+                           MERGE( nest_offl%nzu, 0, bc_dirichlet_s ),          &
+                           MERGE( 2, 0, bc_dirichlet_s ),                      &
+                           .TRUE. )
+                nest_offl%chem_from_file_s(n) = .TRUE.
+             ENDIF
+          ENDDO
+       ENDIF
+!
+!--    Top boundary
+       CALL get_variable( pids_id, 'ls_forcing_top_u',                         &
+                             nest_offl%u_top(0:1,nys:nyn,nxlu:nxr),            &
+                             nxlu, nys+1, nest_offl%tind+1,                    &
+                             nxr-nxlu+1, nyn-nys+1, 2, .TRUE. )
+
+       CALL get_variable( pids_id, 'ls_forcing_top_v',                         &
+                             nest_offl%v_top(0:1,nysv:nyn,nxl:nxr),            &
+                             nxl+1, nysv, nest_offl%tind+1,                    &
+                             nxr-nxl+1, nyn-nysv+1, 2, .TRUE. )
+                             
+       CALL get_variable( pids_id, 'ls_forcing_top_w',                         &
+                             nest_offl%w_top(0:1,nys:nyn,nxl:nxr),             &
+                             nxl+1, nys+1, nest_offl%tind+1,                   &
+                             nxr-nxl+1, nyn-nys+1, 2, .TRUE. )
+                             
+       IF ( .NOT. neutral )  THEN
+          CALL get_variable( pids_id, 'ls_forcing_top_pt',                     &
+                                nest_offl%pt_top(0:1,nys:nyn,nxl:nxr),         &
+                                nxl+1, nys+1, nest_offl%tind+1,                &
+                                nxr-nxl+1, nyn-nys+1, 2, .TRUE. )
+       ENDIF
+       IF ( humidity )  THEN
+          CALL get_variable( pids_id, 'ls_forcing_top_qv',                     &
+                                nest_offl%q_top(0:1,nys:nyn,nxl:nxr),          &
+                                nxl+1, nys+1, nest_offl%tind+1,                &
+                                nxr-nxl+1, nyn-nys+1, 2, .TRUE. )
+       ENDIF
+       
+       IF ( air_chemistry )  THEN
+          DO  n = 1, UBOUND(nest_offl%var_names_chem_t, 1)
+             IF ( check_existence( nest_offl%var_names,                        &
+                                   nest_offl%var_names_chem_t(n) ) )  THEN      
+                CALL get_variable( pids_id,                                    &
+                              TRIM( nest_offl%var_names_chem_t(n) ),           &
+                              nest_offl%chem_top(0:1,nys:nyn,nxl:nxr,n),       &
+                              nxl+1, nys+1, nest_offl%tind+1,                  &
+                              nxr-nxl+1, nyn-nys+1, 2, .TRUE. )
+                nest_offl%chem_from_file_t(n) = .TRUE.
+             ENDIF
+          ENDDO
+       ENDIF
+
+!
+!--    Close input file
+       CALL close_input_file( pids_id )
+#endif
+!
+!--    Set control flag to indicate that boundary data has been initially
+!--    input.
+       nest_offl%init = .TRUE.
+!
+!--    End of CPU measurement
+       CALL cpu_log( log_point_s(86), 'NetCDF input forcing', 'stop' )
+
+    END SUBROUTINE nesting_offl_input
+
 
 !------------------------------------------------------------------------------!
@@ -210,6 +812,4 @@
     SUBROUTINE nesting_offl_mass_conservation
 
-       IMPLICIT NONE
-
        INTEGER(iwp) ::  i !< grid index in x-direction
        INTEGER(iwp) ::  j !< grid index in y-direction
@@ -281,5 +881,5 @@
 #if defined( __parallel )
        IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
-       CALL MPI_ALLREDUCE( volume_flow_l, volume_flow, 3, MPI_REAL, MPI_SUM,      &
+       CALL MPI_ALLREDUCE( volume_flow_l, volume_flow, 3, MPI_REAL, MPI_SUM,   &
                            comm2d, ierr )
 #else
@@ -314,12 +914,8 @@
     SUBROUTINE nesting_offl_bc                     
 
-       IMPLICIT NONE
-
        INTEGER(iwp) ::  i !< running index x-direction
        INTEGER(iwp) ::  j !< running index y-direction
        INTEGER(iwp) ::  k !< running index z-direction
        INTEGER(iwp) ::  n !< running index for chemical species
-
-       REAL(wp) ::  fac_dt   !< interpolation factor
        
        REAL(wp), DIMENSION(nzb:nzt+1) ::  pt_ref   !< reference profile for potential temperature
@@ -347,12 +943,4 @@
        u_ref_l  = 0.0_wp
        v_ref_l  = 0.0_wp
-!
-!--    Determine interpolation factor and limit it to 1. This is because
-!--    t+dt can slightly exceed time(tind_p) before boundary data is updated 
-!--    again. 
-       fac_dt = ( time_since_reference_point - nest_offl%time(nest_offl%tind)  &
-                + dt_3d ) /                                                    &
-           ( nest_offl%time(nest_offl%tind_p) - nest_offl%time(nest_offl%tind) )
-       fac_dt = MIN( 1.0_wp, fac_dt )
 !
 !--    Set boundary conditions of u-, v-, w-component, as well as q, and pt.
@@ -863,5 +1451,22 @@
        CALL nesting_offl_calc_zi
        CALL adjust_sponge_layer 
-    
+       
+       CALL  cpu_log( log_point(58), 'offline nesting', 'stop' )
+
+       IF ( debug_output_timestep )  CALL debug_message( 'nesting_offl_bc', 'end' )
+
+
+    END SUBROUTINE nesting_offl_bc
+
+!------------------------------------------------------------------------------!
+! Description:
+!------------------------------------------------------------------------------!
+!>  Update of the geostrophic wind components.
+!>  @todo: update geostrophic wind also in the child domains (should be done
+!>         in the nesting.
+!------------------------------------------------------------------------------!
+    SUBROUTINE nesting_offl_geostrophic_wind
+
+       INTEGER(iwp) ::  k
 !
 !--    Update geostrophic wind components from dynamic input file. 
@@ -874,11 +1479,27 @@
        ug(nzt+1) = ug(nzt)
        vg(nzt+1) = vg(nzt)
-    
-       CALL  cpu_log( log_point(58), 'offline nesting', 'stop' )
-
-       IF ( debug_output_timestep )  CALL debug_message( 'nesting_offl_bc', 'end' )
-
-
-    END SUBROUTINE nesting_offl_bc
+
+    END SUBROUTINE nesting_offl_geostrophic_wind
+
+!------------------------------------------------------------------------------!
+! Description:
+!------------------------------------------------------------------------------!
+!>  Determine the interpolation constant for time interpolation. The 
+!>  calculation is separated from the nesting_offl_bc and 
+!>  nesting_offl_geostrophic_wind in order to be independent on the order 
+!>  of calls. 
+!------------------------------------------------------------------------------!
+    SUBROUTINE nesting_offl_interpolation_factor
+!
+!--    Determine interpolation factor and limit it to 1. This is because
+!--    t+dt can slightly exceed time(tind_p) before boundary data is updated 
+!--    again. 
+       fac_dt = ( time_utc_init + time_since_reference_point                   &
+                - nest_offl%time(nest_offl%tind) + dt_3d ) /                   &
+           ( nest_offl%time(nest_offl%tind_p) - nest_offl%time(nest_offl%tind) )
+
+       fac_dt = MIN( 1.0_wp, fac_dt )
+
+    END SUBROUTINE nesting_offl_interpolation_factor
 
 !------------------------------------------------------------------------------!
@@ -889,11 +1510,4 @@
 !------------------------------------------------------------------------------!
     SUBROUTINE nesting_offl_calc_zi
-       
-       USE basic_constants_and_equations_mod,                                  &
-           ONLY:  g
-       
-       USE kinds
-
-       IMPLICIT NONE 
 
        INTEGER(iwp) :: i                            !< loop index in x-direction
@@ -1070,14 +1684,4 @@
 !------------------------------------------------------------------------------!
     SUBROUTINE adjust_sponge_layer
-       
-       USE arrays_3d,                                                          &
-           ONLY:  rdf, rdf_sc, zu
-       
-       USE basic_constants_and_equations_mod,                                  &
-           ONLY:  pi
-       
-       USE kinds
-
-       IMPLICIT NONE 
 
        INTEGER(iwp) :: k   !< loop index in z-direction
@@ -1116,6 +1720,4 @@
 !------------------------------------------------------------------------------!
     SUBROUTINE nesting_offl_check_parameters 
-
-       IMPLICIT NONE
 !
 !--    Check if offline nesting is applied in nested child domain.
@@ -1123,5 +1725,5 @@
           message_string = 'Offline nesting is only applicable in root model.'
           CALL message( 'offline_nesting_check_parameters', 'PA0622', 1, 2, 0, 6, 0 )       
-       ENDIF     
+       ENDIF
 
     END SUBROUTINE nesting_offl_check_parameters
@@ -1133,6 +1735,4 @@
 !------------------------------------------------------------------------------!
     SUBROUTINE nesting_offl_parin 
-
-       IMPLICIT NONE
        
        CHARACTER (LEN=80) ::  line   !< dummy string that contains the current line of the parameter file
@@ -1174,6 +1774,4 @@
     SUBROUTINE nesting_offl_header ( io )
 
-       IMPLICIT NONE
-
        INTEGER(iwp), INTENT(IN) ::  io !< Unit of the output file
 
@@ -1199,10 +1797,5 @@
 !------------------------------------------------------------------------------!
     SUBROUTINE nesting_offl_init
-    
-       USE netcdf_data_input_mod,                                              &
-           ONLY:  netcdf_data_input_offline_nesting  
-
-       IMPLICIT NONE
-       
+           
        INTEGER(iwp) ::  n !< running index for chemical species
 
@@ -1340,6 +1933,15 @@
        ENDIF
 !
+!--    Before initial data input is initiated, check if dynamic input file is 
+!--    present.
+       IF ( .NOT. input_pids_dynamic )  THEN
+          message_string = 'nesting_offline = .TRUE. requires dynamic '  //    &
+                            'input file ' //                                   &
+                            TRIM( input_file_dynamic ) // TRIM( coupling_char )
+          CALL message( 'nesting_offl_init', 'PA0546', 1, 2, 0, 6, 0 )
+       ENDIF
+!
 !--    Read COSMO data at lateral and top boundaries
-       CALL netcdf_data_input_offline_nesting
+       CALL nesting_offl_input
 !
 !--    Check if sufficient time steps are provided to cover the entire 
@@ -1347,8 +1949,15 @@
 !--    not for the soil/wall spinup. However, as the spinup time is added
 !--    to the end_time, this must be considered here. 
-       IF ( end_time - spinup_time > nest_offl%time(nest_offl%nt-1) )  THEN
-          message_string = 'end_time > provided time in offline nesting.'
-          CALL message( 'offline_nesting_check_parameters', 'PA0183',          &
-                        1, 2, 0, 6, 0 ) 
+       IF ( end_time - spinup_time >                                           &
+            nest_offl%time(nest_offl%nt-1) - time_utc_init )  THEN
+          message_string = 'end_time of the simulation exceeds the ' //        &
+                           'time dimension in the dynamic input file.'
+          CALL message( 'nesting_offl_init', 'PA0183', 1, 2, 0, 6, 0 ) 
+       ENDIF
+
+       IF ( nest_offl%time(0) /= time_utc_init )  THEN
+          message_string = 'Offline nesting: time dimension must start at ' // &
+                           ' time_utc_init.'
+          CALL message( 'nesting_offl_init', 'PA0676', 1, 2, 0, 6, 0 )
        ENDIF
 !
@@ -1466,8 +2075,4 @@
 !------------------------------------------------------------------------------!
     FUNCTION interpolate_in_time( var_t1, var_t2, fac  ) 
-       
-       USE kinds
-
-       IMPLICIT NONE 
 
        REAL(wp)            :: interpolate_in_time !< time-interpolated boundary value
Index: palm/trunk/SOURCE/netcdf_data_input_mod.f90
===================================================================
--- palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 4225)
+++ palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 4226)
@@ -25,4 +25,11 @@
 ! -----------------
 ! $Id$
+! - Netcdf input routine for dimension length renamed
+! - Move offline-nesting-specific checks to nesting_offl_mod
+! - Module-specific input of boundary data for offline nesting moved to 
+!   nesting_offl_mod
+! - Define module specific data type for offline nesting in nesting_offl_mod
+! 
+! 4190 2019-08-27 15:42:37Z suehring
 ! type real_1d changed to real_1d_3d
 ! 
@@ -169,82 +176,4 @@
        REAL(wp), DIMENSION(:), ALLOCATABLE :: z       !< dimension array in z
     END TYPE dims_xy
-!
-!-- Define data type for nesting in larger-scale models like COSMO.
-!-- Data type comprises u, v, w, pt, and q at lateral and top boundaries.
-    TYPE nest_offl_type
-
-       CHARACTER(LEN=16) ::  char_l = 'ls_forcing_left_'  !< leading substring for variables at left boundary 
-       CHARACTER(LEN=17) ::  char_n = 'ls_forcing_north_' !< leading substring for variables at north boundary  
-       CHARACTER(LEN=17) ::  char_r = 'ls_forcing_right_' !< leading substring for variables at right boundary  
-       CHARACTER(LEN=17) ::  char_s = 'ls_forcing_south_' !< leading substring for variables at south boundary 
-       CHARACTER(LEN=15) ::  char_t = 'ls_forcing_top_'   !< leading substring for variables at top boundary 
-
-       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names         !< list of variable in dynamic input file
-       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names_chem_l  !< names of mesoscale nested chemistry variables at left boundary
-       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names_chem_n  !< names of mesoscale nested chemistry variables at north boundary
-       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names_chem_r  !< names of mesoscale nested chemistry variables at right boundary
-       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names_chem_s  !< names of mesoscale nested chemistry variables at south boundary
-       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names_chem_t  !< names of mesoscale nested chemistry variables at top boundary
-
-       INTEGER(iwp) ::  nt     !< number of time levels in dynamic input file
-       INTEGER(iwp) ::  nzu    !< number of vertical levels on scalar grid in dynamic input file
-       INTEGER(iwp) ::  nzw    !< number of vertical levels on w grid in dynamic input file
-       INTEGER(iwp) ::  tind   !< time index for reference time in mesoscale-offline nesting
-       INTEGER(iwp) ::  tind_p !< time index for following time in mesoscale-offline nesting
-
-       LOGICAL      ::  init         = .FALSE. !< flag indicating that offline nesting is already initialized
-
-       LOGICAL, DIMENSION(:), ALLOCATABLE ::  chem_from_file_l !< flags inidicating whether left boundary data for chemistry is in dynamic input file  
-       LOGICAL, DIMENSION(:), ALLOCATABLE ::  chem_from_file_n !< flags inidicating whether north boundary data for chemistry is in dynamic input file 
-       LOGICAL, DIMENSION(:), ALLOCATABLE ::  chem_from_file_r !< flags inidicating whether right boundary data for chemistry is in dynamic input file 
-       LOGICAL, DIMENSION(:), ALLOCATABLE ::  chem_from_file_s !< flags inidicating whether south boundary data for chemistry is in dynamic input file 
-       LOGICAL, DIMENSION(:), ALLOCATABLE ::  chem_from_file_t !< flags inidicating whether top boundary data for chemistry is in dynamic input file 
-
-       REAL(wp), DIMENSION(:), ALLOCATABLE ::  surface_pressure !< time dependent surface pressure
-       REAL(wp), DIMENSION(:), ALLOCATABLE ::  time             !< time levels in dynamic input file
-       REAL(wp), DIMENSION(:), ALLOCATABLE ::  zu_atmos         !< vertical levels at scalar grid in dynamic input file
-       REAL(wp), DIMENSION(:), ALLOCATABLE ::  zw_atmos         !< vertical levels at w grid in dynamic input file
-
-       REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  ug         !< domain-averaged geostrophic component
-       REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  vg         !< domain-averaged geostrophic component
-
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u_left   !< u-component at left boundary
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  v_left   !< v-component at left boundary
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  w_left   !< w-component at left boundary
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  q_left   !< mixing ratio at left boundary
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pt_left  !< potentital temperautre at left boundary
-
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u_north  !< u-component at north boundary
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  v_north  !< v-component at north boundary
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  w_north  !< w-component at north boundary
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  q_north  !< mixing ratio at north boundary
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pt_north !< potentital temperautre at north boundary
-
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u_right  !< u-component at right boundary
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  v_right  !< v-component at right boundary
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  w_right  !< w-component at right boundary
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  q_right  !< mixing ratio at right boundary
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pt_right !< potentital temperautre at right boundary
-
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u_south  !< u-component at south boundary
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  v_south  !< v-component at south boundary
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  w_south  !< w-component at south boundary
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  q_south  !< mixing ratio at south boundary
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pt_south !< potentital temperautre at south boundary
-
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  u_top    !< u-component at top boundary
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  v_top    !< v-component at top boundary
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  w_top    !< w-component at top boundary
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  q_top    !< mixing ratio at top boundary
-       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  pt_top   !< potentital temperautre at top boundary
-       
-       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  chem_left   !< chemical species at left boundary
-       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  chem_north  !< chemical species at left boundary
-       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  chem_right  !< chemical species at left boundary
-       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  chem_south  !< chemical species at left boundary
-       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  chem_top    !< chemical species at left boundary
-
-    END TYPE nest_offl_type
-
     TYPE init_type
 
@@ -571,7 +500,5 @@
     TYPE(crs_type)   ::  coord_ref_sys  !< coordinate reference system
 
-    TYPE(dims_xy)    ::  dim_static     !< data structure for x, y-dimension in static input file
-
-    TYPE(nest_offl_type) ::  nest_offl  !< data structure for data input at lateral and top boundaries (provided by Inifor)  
+    TYPE(dims_xy)    ::  dim_static     !< data structure for x, y-dimension in static input file 
 
     TYPE(init_type) ::  init_3d    !< data structure for the initialization of the 3D flow and soil fields
@@ -679,7 +606,7 @@
     END INTERFACE netcdf_data_input_chemistry_data
     
-    INTERFACE netcdf_data_input_get_dimension_length                        
-       MODULE PROCEDURE netcdf_data_input_get_dimension_length
-    END INTERFACE netcdf_data_input_get_dimension_length
+    INTERFACE get_dimension_length                        
+       MODULE PROCEDURE get_dimension_length
+    END INTERFACE get_dimension_length
 
     INTERFACE netcdf_data_input_inquire_file
@@ -705,8 +632,4 @@
        MODULE PROCEDURE netcdf_data_input_init_lsm
     END INTERFACE netcdf_data_input_init_lsm
-
-    INTERFACE netcdf_data_input_offline_nesting
-       MODULE PROCEDURE netcdf_data_input_offline_nesting
-    END INTERFACE netcdf_data_input_offline_nesting
 
     INTERFACE netcdf_data_input_surface_data
@@ -770,5 +693,5 @@
            input_pids_static,                                                  &
            input_pids_dynamic, input_pids_vm, input_file_vm,                   &
-           leaf_area_density_f, nest_offl,                                     &
+           leaf_area_density_f,                                                &
            num_var_pids,                                                       &
            pavement_pars_f, pavement_subsurface_pars_f, pavement_type_f,       &
@@ -790,12 +713,18 @@
     PUBLIC netcdf_data_input_check_dynamic, netcdf_data_input_check_static,    &
            netcdf_data_input_chemistry_data,                                   &
-           netcdf_data_input_get_dimension_length,                             &
+           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_offline_nesting,   &
+           netcdf_data_input_interpolate,                                      &
            netcdf_data_input_surface_data, netcdf_data_input_topo,             &
-           netcdf_data_input_var, get_attribute, get_variable, open_read_file, &
-           check_existence, inquire_num_variables, inquire_variable_names,     &
+           netcdf_data_input_var,                                              &
+           get_attribute,                                                      &
+           get_variable,                                                       &
+           get_variable_pr,                                                    &
+           open_read_file,                                                     &
+           check_existence,                                                    &
+           inquire_num_variables,                                              &
+           inquire_variable_names,                                             &
            close_input_file
 
@@ -1347,6 +1276,5 @@
 !-- Tther dimensions depend on the emission mode or specific components
 
-          CALL netcdf_data_input_get_dimension_length (    &
-                                 id_emis, emt_att%n_emiss_species, 'nspecies' )
+          CALL get_dimension_length ( id_emis, emt_att%n_emiss_species, 'nspecies' )
 
 !
@@ -1408,6 +1336,5 @@
 !-- get number of emission categories
 
-             CALL netcdf_data_input_get_dimension_length (           &
-                                    id_emis, emt_att%ncat, 'ncat' )
+             CALL get_dimension_length ( id_emis, emt_att%ncat, 'ncat' )
 
 !-- READING IN EMISSION CATEGORIES INDICES
@@ -1445,6 +1372,5 @@
 !
 !-- VOC name
-                   CALL netcdf_data_input_get_dimension_length (     &
-                                          id_emis, emt_att%nvoc, 'nvoc' )
+                   CALL get_dimension_length ( id_emis, emt_att%nvoc, 'nvoc' )
                    ALLOCATE ( emt_att%voc_name(emt_att%nvoc) )
                    CALL get_variable ( id_emis,"emission_voc_name",  &
@@ -1471,6 +1397,5 @@
 !-- PM name
 
-                   CALL netcdf_data_input_get_dimension_length (     &
-                                          id_emis, emt_att%npm, 'npm' )
+                   CALL get_dimension_length ( id_emis, emt_att%npm, 'npm' )
                    ALLOCATE ( emt_att%pm_name(emt_att%npm) )
                    CALL get_variable ( id_emis, "pm_name", string_values, emt_att%npm )
@@ -1522,6 +1447,5 @@
                    TRIM(time_fac_type) == "hour" )  THEN
 
-                CALL netcdf_data_input_get_dimension_length (                  &
-                                       id_emis, emt_att%nhoursyear, 'nhoursyear' )
+                CALL get_dimension_length ( id_emis, emt_att%nhoursyear, 'nhoursyear' )
                 ALLOCATE ( emt_att%hourly_emis_time_factor(emt_att%ncat,emt_att%nhoursyear) )
                 CALL get_variable ( id_emis, "emission_time_factors",          &
@@ -1535,6 +1459,5 @@
                         TRIM(time_fac_type)  ==  "mdh" )  THEN
 
-                CALL netcdf_data_input_get_dimension_length (                  &
-                                       id_emis, emt_att%nmonthdayhour, 'nmonthdayhour' )
+                CALL get_dimension_length ( id_emis, emt_att%nmonthdayhour, 'nmonthdayhour' )
                 ALLOCATE ( emt_att%mdh_emis_time_factor(emt_att%ncat,emt_att%nmonthdayhour) )
                 CALL get_variable ( id_emis, "emission_time_factors",          &
@@ -1652,6 +1575,5 @@
 !
 !-- VOC name
-                   CALL netcdf_data_input_get_dimension_length (                         &
-                                          id_emis, emt_att%nvoc, 'nvoc' )
+                   CALL get_dimension_length ( id_emis, emt_att%nvoc, 'nvoc' )
                    ALLOCATE ( emt_att%voc_name(emt_att%nvoc) )
                    CALL get_variable ( id_emis, "emission_voc_name",                     &
@@ -1673,6 +1595,5 @@
 !-- EMISSION DATA
 
-             CALL netcdf_data_input_get_dimension_length (                               &
-                                    id_emis, emt_att%dt_emission, 'time' )   
+             CALL get_dimension_length ( id_emis, emt_att%dt_emission, 'time' )   
  
 !
@@ -1805,7 +1726,7 @@
 !
 !--          Inquire number of vertical vegetation layer
-             CALL netcdf_data_input_get_dimension_length( id_surf,             &
-                                                 leaf_area_density_f%nz,       &
-                                                 'zlad' )
+             CALL get_dimension_length( id_surf,                               &
+                                        leaf_area_density_f%nz,                &
+                                        'zlad' )
 !
 !--          Allocate variable for leaf-area density
@@ -1830,7 +1751,7 @@
 !
 !--          Inquire number of vertical vegetation layer
-             CALL netcdf_data_input_get_dimension_length( id_surf,             &
-                                                 basal_area_density_f%nz,      &
-                                                 'zlad' )
+             CALL get_dimension_length( id_surf,                               &
+                                        basal_area_density_f%nz,               & 
+                                        'zlad' )
 !
 !--          Allocate variable
@@ -1854,5 +1775,5 @@
 !
 !--          Inquire number of vertical soil layers
-             CALL netcdf_data_input_get_dimension_length( id_surf,             &
+             CALL get_dimension_length( id_surf,             &
                                                    root_area_density_lad_f%nz, &
                                                   'zsoil' )
@@ -1936,6 +1857,5 @@
 !
 !--          Obtain number of soil layers from file.
-             CALL netcdf_data_input_get_dimension_length( id_surf, nz_soil,    &
-                                                          'zsoil' )
+             CALL get_dimension_length( id_surf, nz_soil, 'zsoil' )
 
              ALLOCATE ( soil_type_f%var_3d(0:nz_soil,nys:nyn,nxl:nxr) )
@@ -1989,7 +1909,7 @@
 !
 !--       Inquire number of surface fractions
-          CALL netcdf_data_input_get_dimension_length( id_surf,                &
-                                                       surface_fraction_f%nf,  &
-                                                       'nsurface_fraction' )
+          CALL get_dimension_length( id_surf,                                  &
+                                     surface_fraction_f%nf,                    &
+                                     'nsurface_fraction' )
 !
 !--       Allocate dimension array and input array for surface fractions
@@ -2018,7 +1938,7 @@
 !
 !--       Inquire number of building parameters
-          CALL netcdf_data_input_get_dimension_length( id_surf,                &
-                                                       building_pars_f%np,     &
-                                                       'nbuilding_pars' )
+          CALL get_dimension_length( id_surf,                                  &
+                                      building_pars_f%np,                      &
+                                      'nbuilding_pars' )
 !
 !--       Allocate dimension array and input array for building parameters
@@ -2061,7 +1981,7 @@
 !
 !--       Inquire number of albedo parameters
-          CALL netcdf_data_input_get_dimension_length( id_surf,                &
-                                                       albedo_pars_f%np,       &
-                                                       'nalbedo_pars' )
+          CALL get_dimension_length( id_surf,                                  &
+                                     albedo_pars_f%np,                         &
+                                     'nalbedo_pars' )
 !
 !--       Allocate dimension array and input array for albedo parameters
@@ -2089,7 +2009,7 @@
 !
 !--       Inquire number of pavement parameters
-          CALL netcdf_data_input_get_dimension_length( id_surf,                &
-                                                       pavement_pars_f%np,     &
-                                                       'npavement_pars' )
+          CALL get_dimension_length( id_surf,                                  &
+                                     pavement_pars_f%np,                       &
+                                     'npavement_pars' )
 !
 !--       Allocate dimension array and input array for pavement parameters
@@ -2118,12 +2038,12 @@
 !
 !--       Inquire number of parameters
-          CALL netcdf_data_input_get_dimension_length( id_surf,                &
-                                                pavement_subsurface_pars_f%np, &
-                                               'npavement_subsurface_pars' )
+          CALL get_dimension_length( id_surf,                                  &
+                                     pavement_subsurface_pars_f%np,            &
+                                     'npavement_subsurface_pars' )
 !
 !--       Inquire number of soil layers
-          CALL netcdf_data_input_get_dimension_length( id_surf,                &
-                                                pavement_subsurface_pars_f%nz, &
-                                                'zsoil' )
+          CALL get_dimension_length( id_surf,                                  &
+                                     pavement_subsurface_pars_f%nz,            &
+                                     'zsoil' )
 !
 !--       Allocate dimension array and input array for pavement parameters
@@ -2158,7 +2078,7 @@
 !
 !--       Inquire number of vegetation parameters
-          CALL netcdf_data_input_get_dimension_length( id_surf,                &
-                                                       vegetation_pars_f%np,   &
-                                                       'nvegetation_pars' )
+          CALL get_dimension_length( id_surf,                                  &
+                                     vegetation_pars_f%np,                     &
+                                     'nvegetation_pars' )
 !
 !--       Allocate dimension array and input array for surface fractions
@@ -2192,7 +2112,7 @@
 !
 !--       Inquire number of soil parameters
-          CALL netcdf_data_input_get_dimension_length( id_surf,                &
-                                                       soil_pars_f%np,         &
-                                                       'nsoil_pars' )
+          CALL get_dimension_length( id_surf,                                  &
+                                     soil_pars_f%np,                           &
+                                     'nsoil_pars' )
 !
 !--       Read parameters array
@@ -2204,7 +2124,7 @@
 !--       soil layers, allocate memory and read the respective dimension
           IF ( soil_pars_f%lod == 2 )  THEN
-             CALL netcdf_data_input_get_dimension_length( id_surf,             &
-                                                          soil_pars_f%nz,      &
-                                                          'zsoil' )
+             CALL get_dimension_length( id_surf,                               &
+                                        soil_pars_f%nz,                        &
+                                        'zsoil' )
 
              ALLOCATE( soil_pars_f%layers(0:soil_pars_f%nz-1) )
@@ -2245,7 +2165,7 @@
 !
 !--       Inquire number of water parameters
-          CALL netcdf_data_input_get_dimension_length( id_surf,                &
-                                                       water_pars_f%np,        &
-                                                       'nwater_pars' )
+          CALL get_dimension_length( id_surf,                                  &
+                                     water_pars_f%np,                          &
+                                     'nwater_pars' )
 !
 !--       Allocate dimension array and input array for water parameters
@@ -2271,7 +2191,7 @@
 !
 !--       Obtain number of soil layers from file and allocate variable
-          CALL netcdf_data_input_get_dimension_length( id_surf,                &
-                                                   root_area_density_lsm_f%nz, &
-                                                   'zsoil' )
+          CALL get_dimension_length( id_surf,                                  &
+                                     root_area_density_lsm_f%nz,               &
+                                     'zsoil' )
           ALLOCATE( root_area_density_lsm_f%var                                &
                                         (0:root_area_density_lsm_f%nz-1,       &
@@ -2645,6 +2565,6 @@
 !
 !--       Read x, y - dimensions. Only required for consistency checks.
-          CALL netcdf_data_input_get_dimension_length( id_topo, dim_static%nx, 'x' )
-          CALL netcdf_data_input_get_dimension_length( id_topo, dim_static%ny, 'y' )
+          CALL get_dimension_length( id_topo, dim_static%nx, 'x' )
+          CALL get_dimension_length( id_topo, dim_static%ny, 'y' )
           ALLOCATE( dim_static%x(0:dim_static%nx-1) )
           ALLOCATE( dim_static%y(0:dim_static%ny-1) )
@@ -2725,6 +2645,5 @@
                                  .FALSE., 'buildings_3d' )
 
-             CALL netcdf_data_input_get_dimension_length( id_topo,             &
-                                                          buildings_f%nz, 'z' )
+             CALL get_dimension_length( id_topo, buildings_f%nz, 'z' )
 !
 !--          Read 3D buildings
@@ -2941,13 +2860,13 @@
 !
 !--    Read vertical dimension of scalar und w grid. 
-       CALL netcdf_data_input_get_dimension_length( id_dynamic, init_3d%nzu, 'z'     )
-       CALL netcdf_data_input_get_dimension_length( id_dynamic, init_3d%nzw, 'zw'    )
+       CALL get_dimension_length( id_dynamic, init_3d%nzu, 'z'     )
+       CALL get_dimension_length( id_dynamic, init_3d%nzw, 'zw'    )
 !
 !--    Read also the horizontal dimensions. These are used just used fo
 !--    checking the compatibility with the PALM grid before reading.
-       CALL netcdf_data_input_get_dimension_length( id_dynamic, init_3d%nx,  'x'  )
-       CALL netcdf_data_input_get_dimension_length( id_dynamic, init_3d%nxu, 'xu' )
-       CALL netcdf_data_input_get_dimension_length( id_dynamic, init_3d%ny,  'y'  )
-       CALL netcdf_data_input_get_dimension_length( id_dynamic, init_3d%nyv, 'yv' )
+       CALL get_dimension_length( id_dynamic, init_3d%nx,  'x'  )
+       CALL get_dimension_length( id_dynamic, init_3d%nxu, 'xu' )
+       CALL get_dimension_length( id_dynamic, init_3d%ny,  'y'  )
+       CALL get_dimension_length( id_dynamic, init_3d%nyv, 'yv' )
 
 !
@@ -3444,6 +3363,5 @@
 !--    Read vertical dimension for soil depth. 
        IF ( check_existence( var_names, 'zsoil' ) )                            &
-          CALL netcdf_data_input_get_dimension_length( id_dynamic, init_3d%nzs,&
-                                                       'zsoil' )
+          CALL get_dimension_length( id_dynamic, init_3d%nzs, 'zsoil' )
 !
 !--    Read also the horizontal dimensions required for soil initialization.
@@ -3451,8 +3369,6 @@
 !--    these data is already available, but will be read again for the sake
 !--    of clearness. 
-       CALL netcdf_data_input_get_dimension_length( id_dynamic, init_3d%nx,    &
-                                                    'x'  )
-       CALL netcdf_data_input_get_dimension_length( id_dynamic, init_3d%ny,    &
-                                                    'y'  )
+       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,
@@ -3544,481 +3460,12 @@
 ! Description:
 ! ------------
-!> Reads data at lateral and top boundaries derived from larger-scale model
-!> (COSMO) by Inifor.
-!------------------------------------------------------------------------------!
-    SUBROUTINE netcdf_data_input_offline_nesting
+!> Checks input file for consistency and minimum requirements.
+!------------------------------------------------------------------------------!
+    SUBROUTINE netcdf_data_input_check_dynamic
 
        USE control_parameters,                                                 &
-           ONLY:  air_chemistry, bc_dirichlet_l, bc_dirichlet_n,               &
-                  bc_dirichlet_r, bc_dirichlet_s, humidity, neutral,           &
-                  nesting_offline, time_since_reference_point
-
-       USE indices,                                                            &
-           ONLY:  nxl, nxlu, nxr, nyn, nys, nysv, nzb, nzt
+           ONLY:  initializing_actions, message_string
 
        IMPLICIT NONE
-       
-       INTEGER(iwp) ::  id_dynamic !< NetCDF id of dynamic input file
-       INTEGER(iwp) ::  n          !< running index for chemistry variables
-       INTEGER(iwp) ::  num_vars   !< number of variables in netcdf input file
-       INTEGER(iwp) ::  t          !< running index time dimension
-!
-!--    Skip input if no forcing from larger-scale models is applied.
-       IF ( .NOT. nesting_offline )  RETURN
-
-!
-!--    CPU measurement
-       CALL cpu_log( log_point_s(86), 'NetCDF input forcing', 'start' )
-
-#if defined ( __netcdf )
-!
-!--    Open file in read-only mode
-       CALL open_read_file( TRIM( input_file_dynamic ) //                      &
-                            TRIM( coupling_char ), id_dynamic )
-!
-!--    Initialize INIFOR forcing. 
-       IF ( .NOT. nest_offl%init )  THEN
-!
-!--       At first, inquire all variable names.
-          CALL inquire_num_variables( id_dynamic, num_vars )
-!
-!--       Allocate memory to store variable names.
-          ALLOCATE( nest_offl%var_names(1:num_vars) )
-          CALL inquire_variable_names( id_dynamic, nest_offl%var_names )
-!
-!--       Read time dimension, allocate memory and finally read time array
-          CALL netcdf_data_input_get_dimension_length( id_dynamic,             &
-                                                       nest_offl%nt, 'time' )
-
-          IF ( check_existence( nest_offl%var_names, 'time' ) )  THEN
-             ALLOCATE( nest_offl%time(0:nest_offl%nt-1) )
-             CALL get_variable( id_dynamic, 'time', nest_offl%time )
-          ENDIF
-!
-!--       Read vertical dimension of scalar und w grid
-          CALL netcdf_data_input_get_dimension_length( id_dynamic,             &
-                                                       nest_offl%nzu, 'z' )
-          CALL netcdf_data_input_get_dimension_length( id_dynamic,             &
-                                                       nest_offl%nzw, 'zw' )
-
-          IF ( check_existence( nest_offl%var_names, 'z' ) )  THEN
-             ALLOCATE( nest_offl%zu_atmos(1:nest_offl%nzu) )
-             CALL get_variable( id_dynamic, 'z', nest_offl%zu_atmos )
-          ENDIF
-          IF ( check_existence( nest_offl%var_names, 'zw' ) )  THEN
-             ALLOCATE( nest_offl%zw_atmos(1:nest_offl%nzw) )
-             CALL get_variable( id_dynamic, 'zw', nest_offl%zw_atmos )
-          ENDIF
-
-!
-!--       Read surface pressure
-          IF ( check_existence( nest_offl%var_names,                           &
-                                'surface_forcing_surface_pressure' ) )  THEN
-             ALLOCATE( nest_offl%surface_pressure(0:nest_offl%nt-1) )
-             CALL get_variable( id_dynamic,                                    &
-                                'surface_forcing_surface_pressure',            &
-                                nest_offl%surface_pressure )
-          ENDIF
-!
-!--       Set control flag to indicate that initialization is already done
-          nest_offl%init = .TRUE.
-
-       ENDIF
-
-!
-!--    Obtain time index for current input starting at 0.
-!--    @todo: At the moment INIFOR and simulated time correspond
-!--           to each other. If required, adjust to daytime.
-       nest_offl%tind = MINLOC( ABS( nest_offl%time -                          &
-                                     time_since_reference_point ), DIM = 1 )   &
-                        - 1
-       nest_offl%tind_p = nest_offl%tind + 1       
-!
-!--    Read geostrophic wind components
-       DO  t = nest_offl%tind, nest_offl%tind_p
-          CALL get_variable_pr( id_dynamic, 'ls_forcing_ug', t+1,              &
-                                nest_offl%ug(t-nest_offl%tind,nzb+1:nzt) )
-          CALL get_variable_pr( id_dynamic, 'ls_forcing_vg', t+1,              &
-                                nest_offl%vg(t-nest_offl%tind,nzb+1:nzt) )
-       ENDDO
-!
-!--    Read data at lateral and top boundaries. Please note, at left and
-!--    right domain boundary, yz-layers are read for u, v, w, pt and q.
-!--    For the v-component, the data starts at nysv, while for the other
-!--    quantities the data starts at nys. This is equivalent at the north
-!--    and south domain boundary for the u-component. 
-!--    Note, lateral data is also accessed by parallel IO, which is the reason
-!--    why different arguments are passed depending on the boundary control
-!--    flags. Cores that do not belong to the respective boundary just make
-!--    a dummy read with count = 0, just in order to participate the collective
-!--    operation. 
-!--    Read data for western boundary    
-       CALL get_variable( id_dynamic, 'ls_forcing_left_u',                     &
-                          nest_offl%u_left,                                    & ! array to be read
-                          MERGE( nys+1, 1, bc_dirichlet_l),                    & ! start index y direction
-                          MERGE( nzb+1, 1, bc_dirichlet_l),                    & ! start index z direction
-                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_l),         & ! start index time dimension
-                          MERGE( nyn-nys+1, 0, bc_dirichlet_l),                & ! number of elements along y
-                          MERGE( nest_offl%nzu, 0, bc_dirichlet_l),            & ! number of elements alogn z
-                          MERGE( 2, 0, bc_dirichlet_l),                        & ! number of time steps (2 or 0)
-                          .TRUE. )                                               ! parallel IO when compiled accordingly
-      
-       CALL get_variable( id_dynamic, 'ls_forcing_left_v',                     &
-                          nest_offl%v_left,                                    &
-                          MERGE( nysv, 1, bc_dirichlet_l),                     &
-                          MERGE( nzb+1, 1, bc_dirichlet_l),                    &
-                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_l),         &
-                          MERGE( nyn-nysv+1, 0, bc_dirichlet_l),               &
-                          MERGE( nest_offl%nzu, 0, bc_dirichlet_l),            &
-                          MERGE( 2, 0, bc_dirichlet_l),                        &
-                          .TRUE. )                                        
-
-       CALL get_variable( id_dynamic, 'ls_forcing_left_w',                     &
-                          nest_offl%w_left,                                    &
-                          MERGE( nys+1, 1, bc_dirichlet_l),                    &
-                          MERGE( nzb+1, 1, bc_dirichlet_l),                    &
-                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_l),         &
-                          MERGE( nyn-nys+1, 0, bc_dirichlet_l),                &
-                          MERGE( nest_offl%nzw, 0, bc_dirichlet_l),            &
-                          MERGE( 2, 0, bc_dirichlet_l),                        &
-                          .TRUE. )   
-
-       IF ( .NOT. neutral )  THEN
-          CALL get_variable( id_dynamic, 'ls_forcing_left_pt',                 &
-                             nest_offl%pt_left,                                &
-                             MERGE( nys+1, 1, bc_dirichlet_l),                 &
-                             MERGE( nzb+1, 1, bc_dirichlet_l),                 &
-                             MERGE( nest_offl%tind+1, 1, bc_dirichlet_l),      &
-                             MERGE( nyn-nys+1, 0, bc_dirichlet_l),             &
-                             MERGE( nest_offl%nzu, 0, bc_dirichlet_l),         &
-                             MERGE( 2, 0, bc_dirichlet_l),                     &
-                             .TRUE. )
-       ENDIF
-
-       IF ( humidity )  THEN
-          CALL get_variable( id_dynamic, 'ls_forcing_left_qv',                 &
-                             nest_offl%q_left,                                 &
-                             MERGE( nys+1, 1, bc_dirichlet_l),                 &
-                             MERGE( nzb+1, 1, bc_dirichlet_l),                 &
-                             MERGE( nest_offl%tind+1, 1, bc_dirichlet_l),      &
-                             MERGE( nyn-nys+1, 0, bc_dirichlet_l),             &
-                             MERGE( nest_offl%nzu, 0, bc_dirichlet_l),         &
-                             MERGE( 2, 0, bc_dirichlet_l),                     &
-                             .TRUE. )
-       ENDIF
-       
-       IF ( air_chemistry )  THEN
-          DO  n = 1, UBOUND(nest_offl%var_names_chem_l, 1)
-             IF ( check_existence( nest_offl%var_names,                        &
-                                   nest_offl%var_names_chem_l(n) ) )  THEN  
-                CALL get_variable( id_dynamic,                                 &
-                           TRIM( nest_offl%var_names_chem_l(n) ),              &
-                           nest_offl%chem_left(:,:,:,n),                       &
-                           MERGE( nys+1, 1, bc_dirichlet_l),                   &
-                           MERGE( nzb+1, 1, bc_dirichlet_l),                   &
-                           MERGE( nest_offl%tind+1, 1, bc_dirichlet_l),        &
-                           MERGE( nyn-nys+1, 0, bc_dirichlet_l),               &
-                           MERGE( nest_offl%nzu, 0, bc_dirichlet_l),           &
-                           MERGE( 2, 0, bc_dirichlet_l),                       &
-                           .TRUE. )
-                nest_offl%chem_from_file_l(n) = .TRUE.
-             ENDIF
-          ENDDO
-       ENDIF
-!
-!--    Read data for eastern boundary    
-       CALL get_variable( id_dynamic, 'ls_forcing_right_u',                    &
-                          nest_offl%u_right,                                   &
-                          MERGE( nys+1, 1, bc_dirichlet_r),                    &
-                          MERGE( nzb+1, 1, bc_dirichlet_r),                    &
-                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_r),         &
-                          MERGE( nyn-nys+1, 0, bc_dirichlet_r),                &
-                          MERGE( nest_offl%nzu, 0, bc_dirichlet_r),            &
-                          MERGE( 2, 0, bc_dirichlet_r),                        &
-                          .TRUE. )                                             
-      
-       CALL get_variable( id_dynamic, 'ls_forcing_right_v',                    &
-                          nest_offl%v_right,                                   &
-                          MERGE( nysv, 1, bc_dirichlet_r),                     &
-                          MERGE( nzb+1, 1, bc_dirichlet_r),                    &
-                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_r),         &
-                          MERGE( nyn-nysv+1, 0, bc_dirichlet_r),               &
-                          MERGE( nest_offl%nzu, 0, bc_dirichlet_r),            &
-                          MERGE( 2, 0, bc_dirichlet_r),                        &
-                          .TRUE. )                                             
-
-       CALL get_variable( id_dynamic, 'ls_forcing_right_w',                    &
-                          nest_offl%w_right,                                   &
-                          MERGE( nys+1, 1, bc_dirichlet_r),                    &
-                          MERGE( nzb+1, 1, bc_dirichlet_r),                    &
-                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_r),         &
-                          MERGE( nyn-nys+1, 0, bc_dirichlet_r),                &
-                          MERGE( nest_offl%nzw, 0, bc_dirichlet_r),            &
-                          MERGE( 2, 0, bc_dirichlet_r),                        &
-                          .TRUE. )   
-
-       IF ( .NOT. neutral )  THEN
-          CALL get_variable( id_dynamic, 'ls_forcing_right_pt',                &
-                             nest_offl%pt_right,                               &
-                             MERGE( nys+1, 1, bc_dirichlet_r),                 &
-                             MERGE( nzb+1, 1, bc_dirichlet_r),                 &
-                             MERGE( nest_offl%tind+1, 1, bc_dirichlet_r),      &
-                             MERGE( nyn-nys+1, 0, bc_dirichlet_r),             &
-                             MERGE( nest_offl%nzu, 0, bc_dirichlet_r),         &
-                             MERGE( 2, 0, bc_dirichlet_r),                     &
-                             .TRUE. )
-       ENDIF
-
-       IF ( humidity )  THEN
-          CALL get_variable( id_dynamic, 'ls_forcing_right_qv',                &
-                             nest_offl%q_right,                                &
-                             MERGE( nys+1, 1, bc_dirichlet_r),                 &
-                             MERGE( nzb+1, 1, bc_dirichlet_r),                 &
-                             MERGE( nest_offl%tind+1, 1, bc_dirichlet_r),      &
-                             MERGE( nyn-nys+1, 0, bc_dirichlet_r),             &
-                             MERGE( nest_offl%nzu, 0, bc_dirichlet_r),         &
-                             MERGE( 2, 0, bc_dirichlet_r),                     &
-                             .TRUE. )
-       ENDIF
-       
-       IF ( air_chemistry )  THEN
-          DO  n = 1, UBOUND(nest_offl%var_names_chem_r, 1)
-             IF ( check_existence( nest_offl%var_names,                        &
-                                   nest_offl%var_names_chem_r(n) ) )  THEN     
-                CALL get_variable( id_dynamic,                                 &
-                           TRIM( nest_offl%var_names_chem_r(n) ),              &
-                           nest_offl%chem_right(:,:,:,n),                      &
-                           MERGE( nys+1, 1, bc_dirichlet_r),                   &
-                           MERGE( nzb+1, 1, bc_dirichlet_r),                   &
-                           MERGE( nest_offl%tind+1, 1, bc_dirichlet_r),        &
-                           MERGE( nyn-nys+1, 0, bc_dirichlet_r),               &
-                           MERGE( nest_offl%nzu, 0, bc_dirichlet_r),           &
-                           MERGE( 2, 0, bc_dirichlet_r),                       &
-                           .TRUE. )
-                nest_offl%chem_from_file_r(n) = .TRUE.
-             ENDIF
-          ENDDO
-       ENDIF
-!
-!--    Read data for northern boundary
-       CALL get_variable( id_dynamic, 'ls_forcing_north_u',                    & ! array to be read
-                          nest_offl%u_north,                                   & ! start index x direction
-                          MERGE( nxlu, 1, bc_dirichlet_n ),                    & ! start index z direction
-                          MERGE( nzb+1, 1, bc_dirichlet_n ),                   & ! start index time dimension
-                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_n ),        & ! number of elements along x
-                          MERGE( nxr-nxlu+1, 0, bc_dirichlet_n ),              & ! number of elements alogn z 
-                          MERGE( nest_offl%nzu, 0, bc_dirichlet_n ),           & ! number of time steps (2 or 0)
-                          MERGE( 2, 0, bc_dirichlet_n ),                       & ! parallel IO when compiled accordingly
-                          .TRUE. )                                             
-                                                                               
-       CALL get_variable( id_dynamic, 'ls_forcing_north_v',                    & ! array to be read
-                          nest_offl%v_north,                                   & ! start index x direction
-                          MERGE( nxl+1, 1, bc_dirichlet_n ),                   & ! start index z direction
-                          MERGE( nzb+1, 1, bc_dirichlet_n ),                   & ! start index time dimension
-                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_n ),        & ! number of elements along x
-                          MERGE( nxr-nxl+1, 0, bc_dirichlet_n ),               & ! number of elements alogn z 
-                          MERGE( nest_offl%nzu, 0, bc_dirichlet_n ),           & ! number of time steps (2 or 0)
-                          MERGE( 2, 0, bc_dirichlet_n ),                       & ! parallel IO when compiled accordingly
-                          .TRUE. )                                             
-                                                                               
-       CALL get_variable( id_dynamic, 'ls_forcing_north_w',                    & ! array to be read
-                          nest_offl%w_north,                                   & ! start index x direction
-                          MERGE( nxl+1, 1, bc_dirichlet_n ),                   & ! start index z direction
-                          MERGE( nzb+1, 1, bc_dirichlet_n ),                   & ! start index time dimension
-                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_n ),        & ! number of elements along x
-                          MERGE( nxr-nxl+1, 0, bc_dirichlet_n ),               & ! number of elements alogn z 
-                          MERGE( nest_offl%nzw, 0, bc_dirichlet_n ),           & ! number of time steps (2 or 0)
-                          MERGE( 2, 0, bc_dirichlet_n ),                       & ! parallel IO when compiled accordingly
-                          .TRUE. )                                             
-                                                                               
-       IF ( .NOT. neutral )  THEN                                              
-          CALL get_variable( id_dynamic, 'ls_forcing_north_pt',                & ! array to be read
-                             nest_offl%pt_north,                               & ! start index x direction
-                             MERGE( nxl+1, 1, bc_dirichlet_n ),                & ! start index z direction
-                             MERGE( nzb+1, 1, bc_dirichlet_n ),                & ! start index time dimension
-                             MERGE( nest_offl%tind+1, 1, bc_dirichlet_n ),     & ! number of elements along x
-                             MERGE( nxr-nxl+1, 0, bc_dirichlet_n ),            & ! number of elements alogn z 
-                             MERGE( nest_offl%nzu, 0, bc_dirichlet_n ),        & ! number of time steps (2 or 0)
-                             MERGE( 2, 0, bc_dirichlet_n ),                    & ! parallel IO when compiled accordingly
-                             .TRUE. )                                             
-       ENDIF                                                                   
-       IF ( humidity )  THEN                                                   
-          CALL get_variable( id_dynamic, 'ls_forcing_north_qv',                & ! array to be read
-                             nest_offl%q_north,                                & ! start index x direction
-                             MERGE( nxl+1, 1, bc_dirichlet_n ),                & ! start index z direction
-                             MERGE( nzb+1, 1, bc_dirichlet_n ),                & ! start index time dimension
-                             MERGE( nest_offl%tind+1, 1, bc_dirichlet_n ),     & ! number of elements along x
-                             MERGE( nxr-nxl+1, 0, bc_dirichlet_n ),            & ! number of elements alogn z 
-                             MERGE( nest_offl%nzu, 0, bc_dirichlet_n ),        & ! number of time steps (2 or 0)
-                             MERGE( 2, 0, bc_dirichlet_n ),                    & ! parallel IO when compiled accordingly
-                             .TRUE. )                                             
-       ENDIF                                                                   
-                                                                               
-       IF ( air_chemistry )  THEN                                              
-          DO  n = 1, UBOUND(nest_offl%var_names_chem_n, 1)                     
-             IF ( check_existence( nest_offl%var_names,                        &
-                                   nest_offl%var_names_chem_n(n) ) )  THEN     
-                CALL get_variable( id_dynamic,                                 &
-                           TRIM( nest_offl%var_names_chem_n(n) ),              &
-                           nest_offl%chem_north(:,:,:,n),                      &
-                           MERGE( nxl+1, 1, bc_dirichlet_n ),                  &
-                           MERGE( nzb+1, 1, bc_dirichlet_n ),                  &
-                           MERGE( nest_offl%tind+1, 1, bc_dirichlet_n ),       &
-                           MERGE( nxr-nxl+1, 0, bc_dirichlet_n ),              &
-                           MERGE( nest_offl%nzu, 0, bc_dirichlet_n ),          &
-                           MERGE( 2, 0, bc_dirichlet_n ),                      &
-                           .TRUE. )
-                nest_offl%chem_from_file_n(n) = .TRUE.
-             ENDIF
-          ENDDO
-       ENDIF
-!
-!--    Read data for southern boundary
-       CALL get_variable( id_dynamic, 'ls_forcing_south_u',                    & ! array to be read
-                          nest_offl%u_south,                                   & ! start index x direction
-                          MERGE( nxlu, 1, bc_dirichlet_s ),                    & ! start index z direction
-                          MERGE( nzb+1, 1, bc_dirichlet_s ),                   & ! start index time dimension
-                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_s ),        & ! number of elements along x
-                          MERGE( nxr-nxlu+1, 0, bc_dirichlet_s ),              & ! number of elements alogn z 
-                          MERGE( nest_offl%nzu, 0, bc_dirichlet_s ),           & ! number of time steps (2 or 0)
-                          MERGE( 2, 0, bc_dirichlet_s ),                       & ! parallel IO when compiled accordingly
-                          .TRUE. )                                             
-                                                                               
-       CALL get_variable( id_dynamic, 'ls_forcing_south_v',                    & ! array to be read
-                          nest_offl%v_south,                                   & ! start index x direction
-                          MERGE( nxl+1, 1, bc_dirichlet_s ),                   & ! start index z direction
-                          MERGE( nzb+1, 1, bc_dirichlet_s ),                   & ! start index time dimension
-                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_s ),        & ! number of elements along x
-                          MERGE( nxr-nxl+1, 0, bc_dirichlet_s ),               & ! number of elements alogn z 
-                          MERGE( nest_offl%nzu, 0, bc_dirichlet_s ),           & ! number of time steps (2 or 0)
-                          MERGE( 2, 0, bc_dirichlet_s ),                       & ! parallel IO when compiled accordingly
-                          .TRUE. )                                             
-                                                                               
-       CALL get_variable( id_dynamic, 'ls_forcing_south_w',                    & ! array to be read
-                          nest_offl%w_south,                                   & ! start index x direction
-                          MERGE( nxl+1, 1, bc_dirichlet_s ),                   & ! start index z direction
-                          MERGE( nzb+1, 1, bc_dirichlet_s ),                   & ! start index time dimension
-                          MERGE( nest_offl%tind+1, 1, bc_dirichlet_s ),        & ! number of elements along x
-                          MERGE( nxr-nxl+1, 0, bc_dirichlet_s ),               & ! number of elements alogn z 
-                          MERGE( nest_offl%nzw, 0, bc_dirichlet_s ),           & ! number of time steps (2 or 0)
-                          MERGE( 2, 0, bc_dirichlet_s ),                       & ! parallel IO when compiled accordingly
-                          .TRUE. )                                             
-                                                                               
-       IF ( .NOT. neutral )  THEN                                              
-          CALL get_variable( id_dynamic, 'ls_forcing_south_pt',                & ! array to be read
-                             nest_offl%pt_south,                               & ! start index x direction
-                             MERGE( nxl+1, 1, bc_dirichlet_s ),                & ! start index z direction
-                             MERGE( nzb+1, 1, bc_dirichlet_s ),                & ! start index time dimension
-                             MERGE( nest_offl%tind+1, 1, bc_dirichlet_s ),     & ! number of elements along x
-                             MERGE( nxr-nxl+1, 0, bc_dirichlet_s ),            & ! number of elements alogn z 
-                             MERGE( nest_offl%nzu, 0, bc_dirichlet_s ),        & ! number of time steps (2 or 0)
-                             MERGE( 2, 0, bc_dirichlet_s ),                    & ! parallel IO when compiled accordingly
-                             .TRUE. )                                             
-       ENDIF                                                                   
-       IF ( humidity )  THEN                                                   
-          CALL get_variable( id_dynamic, 'ls_forcing_south_qv',                & ! array to be read
-                             nest_offl%q_south,                                & ! start index x direction
-                             MERGE( nxl+1, 1, bc_dirichlet_s ),                & ! start index z direction
-                             MERGE( nzb+1, 1, bc_dirichlet_s ),                & ! start index time dimension
-                             MERGE( nest_offl%tind+1, 1, bc_dirichlet_s ),     & ! number of elements along x
-                             MERGE( nxr-nxl+1, 0, bc_dirichlet_s ),            & ! number of elements alogn z 
-                             MERGE( nest_offl%nzu, 0, bc_dirichlet_s ),        & ! number of time steps (2 or 0)
-                             MERGE( 2, 0, bc_dirichlet_s ),                    & ! parallel IO when compiled accordingly
-                             .TRUE. )                                             
-       ENDIF                                                                   
-                                                                               
-       IF ( air_chemistry )  THEN                                              
-          DO  n = 1, UBOUND(nest_offl%var_names_chem_s, 1)                     
-             IF ( check_existence( nest_offl%var_names,                        &
-                                   nest_offl%var_names_chem_s(n) ) )  THEN     
-                CALL get_variable( id_dynamic,                                 &
-                           TRIM( nest_offl%var_names_chem_s(n) ),              &
-                           nest_offl%chem_south(:,:,:,n),                      &
-                           MERGE( nxl+1, 1, bc_dirichlet_s ),                  &
-                           MERGE( nzb+1, 1, bc_dirichlet_s ),                  &
-                           MERGE( nest_offl%tind+1, 1, bc_dirichlet_s ),       &
-                           MERGE( nxr-nxl+1, 0, bc_dirichlet_s ),              &
-                           MERGE( nest_offl%nzu, 0, bc_dirichlet_s ),          &
-                           MERGE( 2, 0, bc_dirichlet_s ),                      &
-                           .TRUE. )
-                nest_offl%chem_from_file_s(n) = .TRUE.
-             ENDIF
-          ENDDO
-       ENDIF
-!
-!--    Top boundary
-       CALL get_variable( id_dynamic, 'ls_forcing_top_u',                      &
-                             nest_offl%u_top(0:1,nys:nyn,nxlu:nxr),            &
-                             nxlu, nys+1, nest_offl%tind+1,                    &
-                             nxr-nxlu+1, nyn-nys+1, 2, .TRUE. )
-
-       CALL get_variable( id_dynamic, 'ls_forcing_top_v',                      &
-                             nest_offl%v_top(0:1,nysv:nyn,nxl:nxr),            &
-                             nxl+1, nysv, nest_offl%tind+1,                    &
-                             nxr-nxl+1, nyn-nysv+1, 2, .TRUE. )
-                             
-       CALL get_variable( id_dynamic, 'ls_forcing_top_w',                      &
-                             nest_offl%w_top(0:1,nys:nyn,nxl:nxr),             &
-                             nxl+1, nys+1, nest_offl%tind+1,                   &
-                             nxr-nxl+1, nyn-nys+1, 2, .TRUE. )
-                             
-       IF ( .NOT. neutral )  THEN
-          CALL get_variable( id_dynamic, 'ls_forcing_top_pt',                  &
-                                nest_offl%pt_top(0:1,nys:nyn,nxl:nxr),         &
-                                nxl+1, nys+1, nest_offl%tind+1,                &
-                                nxr-nxl+1, nyn-nys+1, 2, .TRUE. )
-       ENDIF
-       IF ( humidity )  THEN
-          CALL get_variable( id_dynamic, 'ls_forcing_top_qv',                  &
-                                nest_offl%q_top(0:1,nys:nyn,nxl:nxr),          &
-                                nxl+1, nys+1, nest_offl%tind+1,                &
-                                nxr-nxl+1, nyn-nys+1, 2, .TRUE. )
-       ENDIF
-       
-       IF ( air_chemistry )  THEN
-          DO  n = 1, UBOUND(nest_offl%var_names_chem_t, 1)
-             IF ( check_existence( nest_offl%var_names,                     &
-                                   nest_offl%var_names_chem_t(n) ) )  THEN      
-                CALL get_variable( id_dynamic,                                 &
-                              TRIM( nest_offl%var_names_chem_t(n) ),           &
-                              nest_offl%chem_top(0:1,nys:nyn,nxl:nxr,n),       &
-                              nxl+1, nys+1, nest_offl%tind+1,                  &
-                              nxr-nxl+1, nyn-nys+1, 2, .TRUE. )
-                nest_offl%chem_from_file_t(n) = .TRUE.
-             ENDIF
-          ENDDO
-       ENDIF
-
-!
-!--    Close input file
-       CALL close_input_file( id_dynamic )
-#endif
-!
-!--    End of CPU measurement
-       CALL cpu_log( log_point_s(86), 'NetCDF input forcing', 'stop' )
-
-    END SUBROUTINE netcdf_data_input_offline_nesting
-
-
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Checks input file for consistency and minimum requirements.
-!------------------------------------------------------------------------------!
-    SUBROUTINE netcdf_data_input_check_dynamic
-
-       USE control_parameters,                                                 &
-           ONLY:  initializing_actions, message_string, nesting_offline 
-
-       IMPLICIT NONE
-
-!
-!--    In case of forcing, check whether dynamic input file is present
-       IF ( .NOT. input_pids_dynamic  .AND.  nesting_offline  )  THEN
-          message_string = 'nesting_offline = .TRUE. requires dynamic '  //    &
-                            'input file ' //                                   &
-                            TRIM( input_file_dynamic ) // TRIM( coupling_char )
-          CALL message( 'netcdf_data_input_mod', 'PA0546', 1, 2, 0, 6, 0 )
-       ENDIF
 !
 !--    Dynamic input file must also be present if initialization via inifor is
@@ -5269,6 +4716,5 @@
 !> Get dimension array for a given dimension
 !------------------------------------------------------------------------------!
-     SUBROUTINE netcdf_data_input_get_dimension_length( id, dim_len,           &
-                                                        variable_name )
+     SUBROUTINE get_dimension_length( id, dim_len, variable_name )
        USE pegrid
 
@@ -5286,14 +4732,12 @@
 !--    First, inquire dimension ID
        nc_stat = NF90_INQ_DIMID( id, TRIM( variable_name ), id_dim )
-       CALL handle_error( 'netcdf_data_input_get_dimension_length', 526,       &
-                          variable_name )
+       CALL handle_error( 'get_dimension_length', 526, variable_name )
 !
 !--    Inquire dimension length
        nc_stat = NF90_INQUIRE_DIMENSION( id, id_dim, dum, LEN = dim_len )
-       CALL handle_error( 'netcdf_data_input_get_dimension_length', 526,       &
-                          variable_name )
+       CALL handle_error( 'get_dimension_length', 526, variable_name )
 
 #endif
-    END SUBROUTINE netcdf_data_input_get_dimension_length
+    END SUBROUTINE get_dimension_length
 
 !------------------------------------------------------------------------------!
Index: palm/trunk/SOURCE/plant_canopy_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/plant_canopy_model_mod.f90	(revision 4225)
+++ palm/trunk/SOURCE/plant_canopy_model_mod.f90	(revision 4226)
@@ -22,9 +22,12 @@
 ! Current revisions:
 ! ------------------
-! Bugfix, missing initialization of heating rate
+! 
 ! 
 ! Former revisions:
 ! -----------------
 ! $Id$
+! Bugfix, missing initialization of heating rate
+! 
+! 4221 2019-09-09 08:50:35Z suehring
 ! Further bugfix in 3d data output for plant canopy
 ! 
Index: palm/trunk/SOURCE/radiation_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/radiation_model_mod.f90	(revision 4225)
+++ palm/trunk/SOURCE/radiation_model_mod.f90	(revision 4226)
@@ -28,4 +28,8 @@
 ! -----------------
 ! $Id$
+! - Netcdf input routine for dimension length renamed
+! - Define time variable for external radiation input relative to time_utc_init 
+! 
+! 4210 2019-09-02 13:07:09Z suehring
 ! - Revise steering of splitting diffuse and direct radiation
 ! - Bugfixes in checks
@@ -34,5 +38,6 @@
 ! 
 ! 4208 2019-09-02 09:01:07Z suehring
-! Bugfix in accessing albedo_pars in the clear-sky branch (merge from branch) 
+! Bugfix in accessing albedo_pars in the clear-sky branch
+! (merge from branch resler) 
 ! 
 ! 4198 2019-08-29 15:17:48Z gronemeier
@@ -259,4 +264,5 @@
                close_input_file,                                               &
                get_attribute,                                                  &
+               get_dimension_length,                                           &
                get_variable,                                                   &
                inquire_num_variables,                                          &
@@ -264,5 +270,4 @@
                input_file_dynamic,                                             &
                input_pids_dynamic,                                             &
-               netcdf_data_input_get_dimension_length,                         &
                num_var_pids,                                                   &
                pids_id,                                                        &
@@ -2510,7 +2515,5 @@
 !--       Input time dimension.
           IF ( check_existence( vars_pids, 'time_rad' ) )  THEN
-             CALL netcdf_data_input_get_dimension_length( pids_id,             &
-                                                          ntime,               &
-                                                          'time_rad' )
+             CALL get_dimension_length( pids_id, ntime, 'time_rad' )
           
              ALLOCATE( time_rad_f%var1d(0:ntime-1) )
@@ -2637,11 +2640,12 @@
           ENDIF
           
-          IF ( time_rad_f%var1d(0) /= 0.0_wp )  THEN
+          IF ( time_rad_f%var1d(0) /= time_utc_init )  THEN
              message_string = 'External radiation forcing: first point in ' // &
-                              'time is /= 0.0.'
+                              'time is /= time_utc_init.'
              CALL message( 'radiation_init', 'PA0313', 1, 2, 0, 6, 0 )
           ENDIF
           
-          IF ( end_time - spinup_time > time_rad_f%var1d(ntime-1) )  THEN
+          IF ( end_time - spinup_time > time_rad_f%var1d(ntime-1)              &
+                                      - time_utc_init )  THEN
              message_string = 'External radiation forcing does not cover ' //  &
                               'the entire simulation time.'
@@ -2832,5 +2836,6 @@
        ELSE
           t = 0
-          DO WHILE ( time_rad_f%var1d(t) <= time_since_reference_point )
+          DO WHILE ( time_rad_f%var1d(t) <=                                    &
+                     time_since_reference_point + time_utc_init )
              t = t + 1
           ENDDO
@@ -2838,5 +2843,6 @@
           tm = MAX( t-1, 0 )
           
-          fac_dt = ( time_since_reference_point - time_rad_f%var1d(tm) + dt_3d ) &
+          fac_dt = ( time_since_reference_point + time_utc_init                &
+                   - time_rad_f%var1d(tm) + dt_3d )                            &
                  / ( time_rad_f%var1d(t)  - time_rad_f%var1d(tm) )
           fac_dt = MIN( 1.0_wp, fac_dt )
Index: palm/trunk/SOURCE/salsa_mod.f90
===================================================================
--- palm/trunk/SOURCE/salsa_mod.f90	(revision 4225)
+++ palm/trunk/SOURCE/salsa_mod.f90	(revision 4226)
@@ -26,4 +26,7 @@
 ! -----------------
 ! $Id$
+! Netcdf input routine for dimension length renamed
+! 
+! 4182 2019-08-22 15:20:23Z scharf
 ! Corrected "Former revisions" section
 ! 
@@ -1757,7 +1760,8 @@
 
     USE netcdf_data_input_mod,                                                                     &
-        ONLY:  check_existence, close_input_file, get_attribute, get_variable,                     &
+        ONLY:  check_existence, close_input_file, get_dimension_length,                            &
+               get_attribute, get_variable,                                                        &
                inquire_num_variables, inquire_variable_names,                                      &
-               netcdf_data_input_get_dimension_length, open_read_file
+               open_read_file
 
     IMPLICIT NONE
@@ -1836,5 +1840,5 @@
 !
 !--       Inquire vertical dimension and number of aerosol chemical components
-          CALL netcdf_data_input_get_dimension_length( id_dyn, pr_nz, 'z' )
+          CALL get_dimension_length( id_dyn, pr_nz, 'z' )
           IF ( pr_nz /= nz )  THEN
              WRITE( message_string, * ) 'Number of inifor horizontal grid points does not match '//&
@@ -1842,5 +1846,5 @@
              CALL message( 'aerosol_init', 'PA0601', 1, 2, 0, 6, 0 )
           ENDIF
-          CALL netcdf_data_input_get_dimension_length( id_dyn, pr_ncc, 'composition_index' )
+          CALL get_dimension_length( id_dyn, pr_ncc, 'composition_index' )
 !
 !--       Allocate memory
@@ -1915,5 +1919,5 @@
 !
 !--          Bin mean diameters in the input file
-             CALL netcdf_data_input_get_dimension_length( id_dyn, pr_nbins, 'Dmid')
+             CALL get_dimension_length( id_dyn, pr_nbins, 'Dmid')
              IF ( pr_nbins /= nbins_aerosol )  THEN
                 message_string = 'Number of size bins in init_atmosphere_aerosol does not match '  &
@@ -2067,5 +2071,5 @@
 !
 !--       Inquire dimensions:
-          CALL netcdf_data_input_get_dimension_length( id_dyn, pr_nz, 'z' )
+          CALL get_dimension_length( id_dyn, pr_nz, 'z' )
           IF ( pr_nz /= nz )  THEN
              WRITE( message_string, * ) 'Number of inifor horizontal grid points does not match '//&
@@ -8388,5 +8392,5 @@
         ONLY:  check_existence, close_input_file, get_attribute, get_variable,                     &
                inquire_num_variables, inquire_variable_names,                                      &
-               netcdf_data_input_get_dimension_length, open_read_file, street_type_f
+               get_dimension_length, open_read_file, street_type_f
 
     USE surface_mod,                                                                               &
@@ -8525,5 +8529,5 @@
 !
 !--          Read the index and name of chemical components
-             CALL netcdf_data_input_get_dimension_length( id_salsa, aero_emission_att%ncc,         &
+             CALL get_dimension_length( id_salsa, aero_emission_att%ncc,         &
                                                           'composition_index' )
              ALLOCATE( aero_emission_att%cc_index(1:aero_emission_att%ncc) )
@@ -8598,6 +8602,5 @@
 !
 !--             Get number of emission categories and allocate emission arrays
-                CALL netcdf_data_input_get_dimension_length( id_salsa, aero_emission_att%ncat,     &
-                                                             'ncat' )
+                CALL get_dimension_length( id_salsa, aero_emission_att%ncat, 'ncat' )
                 ALLOCATE( aero_emission_att%cat_index(1:aero_emission_att%ncat),                   &
                           aero_emission_att%rho(1:aero_emission_att%ncat),                         &
@@ -8636,6 +8639,6 @@
 !--             For each hour of year:
                 IF ( check_existence( aero_emission_att%var_names, 'nhoursyear' ) )  THEN
-                   CALL netcdf_data_input_get_dimension_length( id_salsa,                          &
-                                                        aero_emission_att%nhoursyear, 'nhoursyear' )
+                   CALL get_dimension_length( id_salsa,                                            &
+                                              aero_emission_att%nhoursyear, 'nhoursyear' )
                    ALLOCATE( aero_emission_att%etf(1:aero_emission_att%ncat,                       &
                                                    1:aero_emission_att%nhoursyear) )
@@ -8645,7 +8648,7 @@
 !--             Based on the month, day and hour:
                 ELSEIF ( check_existence( aero_emission_att%var_names, 'nmonthdayhour' ) )  THEN
-                   CALL netcdf_data_input_get_dimension_length( id_salsa,                          &
-                                                                aero_emission_att%nmonthdayhour,   &
-                                                                'nmonthdayhour' )
+                   CALL get_dimension_length( id_salsa,                                            &
+                                              aero_emission_att%nmonthdayhour,                     &
+                                              'nmonthdayhour' )
                    ALLOCATE( aero_emission_att%etf(1:aero_emission_att%ncat,                       &
                                                    1:aero_emission_att%nmonthdayhour) )
@@ -8734,6 +8737,5 @@
 !
 !--             Number of aerosol size bins in the emission data
-                CALL netcdf_data_input_get_dimension_length( id_salsa, aero_emission_att%nbins,    &
-                                                             'Dmid' )
+                CALL get_dimension_length( id_salsa, aero_emission_att%nbins, 'Dmid' )
                 IF ( aero_emission_att%nbins /= nbins_aerosol )  THEN
                    message_string = 'The number of size bins in aerosol input data does not ' //   &
@@ -8743,5 +8745,5 @@
 !
 !--             Number of time steps in the emission data
-                CALL netcdf_data_input_get_dimension_length( id_salsa, aero_emission_att%nt, 'time')
+                CALL get_dimension_length( id_salsa, aero_emission_att%nt, 'time')
 !
 !--             Allocate bin diameters, time and mass fraction array
@@ -9124,5 +9126,5 @@
         ONLY:  check_existence, close_input_file, get_attribute, get_variable,                     &
                inquire_num_variables, inquire_variable_names,                                      &
-               netcdf_data_input_get_dimension_length, open_read_file
+               get_dimension_length, open_read_file
 
     USE surface_mod,                                                                               &
@@ -9174,6 +9176,5 @@
 !
 !--    Read the index and name of chemical components
-       CALL netcdf_data_input_get_dimension_length( id_chem, chem_emission_att%n_emiss_species,    &
-                                                    'nspecies' )
+       CALL get_dimension_length( id_chem, chem_emission_att%n_emiss_species, 'nspecies' )
        ALLOCATE( chem_emission_att%species_index(1:chem_emission_att%n_emiss_species) )
        CALL get_variable( id_chem, 'emission_index', chem_emission_att%species_index )
@@ -9221,5 +9222,5 @@
 !
 !--       Get number of emission categories and allocate emission arrays
-          CALL netcdf_data_input_get_dimension_length( id_chem, chem_emission_att%ncat, 'ncat' )
+          CALL get_dimension_length( id_chem, chem_emission_att%ncat, 'ncat' )
           ALLOCATE( chem_emission_att%cat_index(1:chem_emission_att%ncat),                         &
                     time_factor(1:chem_emission_att%ncat) )
@@ -9235,6 +9236,5 @@
 !--       For each hour of year:
           IF ( check_existence( var_names, 'nhoursyear' ) )  THEN
-             CALL netcdf_data_input_get_dimension_length( id_chem, chem_emission_att%nhoursyear,   &
-                                                          'nhoursyear' )
+             CALL get_dimension_length( id_chem, chem_emission_att%nhoursyear, 'nhoursyear' )
              ALLOCATE( chem_emission_att%hourly_emis_time_factor(1:chem_emission_att%ncat,         &
                                                                  1:chem_emission_att%nhoursyear) )
@@ -9245,6 +9245,5 @@
 !--       Based on the month, day and hour:
           ELSEIF ( check_existence( var_names, 'nmonthdayhour' ) )  THEN
-             CALL netcdf_data_input_get_dimension_length( id_chem, chem_emission_att%nmonthdayhour,&
-                                                          'nmonthdayhour' )
+             CALL get_dimension_length( id_chem, chem_emission_att%nmonthdayhour, 'nmonthdayhour' )
              ALLOCATE( chem_emission_att%mdh_emis_time_factor(1:chem_emission_att%ncat,            &
                                                               1:chem_emission_att%nmonthdayhour) )
@@ -9284,6 +9283,5 @@
 !
 !--       Number of time steps in the emission data
-          CALL netcdf_data_input_get_dimension_length( id_chem, chem_emission_att%dt_emission,     &
-                                                       'time' )
+          CALL get_dimension_length( id_chem, chem_emission_att%dt_emission, 'time' )
 !
 !--       Allocate and read time
Index: palm/trunk/SOURCE/time_integration.f90
===================================================================
--- palm/trunk/SOURCE/time_integration.f90	(revision 4225)
+++ palm/trunk/SOURCE/time_integration.f90	(revision 4226)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Changes in interface for the offline nesting
+! 
+! 4182 2019-08-22 15:20:23Z scharf
 ! Corrected "Former revisions" section
 ! 
@@ -257,8 +260,12 @@
 
     USE nesting_offl_mod,                                                                          &
-        ONLY:  nesting_offl_bc, nesting_offl_mass_conservation
+        ONLY:  nesting_offl_bc,                                                                    &
+               nesting_offl_geostrophic_wind,                                                      &
+               nesting_offl_input,                                                                 &
+               nesting_offl_interpolation_factor,                                                  &
+               nesting_offl_mass_conservation
 
     USE netcdf_data_input_mod,                                                                     &
-        ONLY:  chem_emis, chem_emis_att, nest_offl, netcdf_data_input_offline_nesting
+        ONLY:  chem_emis, chem_emis_att
 
     USE ocean_mod,                                                                                 &
@@ -566,11 +573,6 @@
        ENDIF
 !
-!--    If forcing by larger-scale models is applied, check if new data
-!--    at domain boundaries need to be read.
-       IF ( nesting_offline ) THEN
-          IF ( nest_offl%time(nest_offl%tind_p) <= time_since_reference_point ) &
-               CALL netcdf_data_input_offline_nesting
-       ENDIF
-
+!--    Input of boundary data. 
+       IF ( nesting_offline )  CALL nesting_offl_input
 !
 !--    Execute all other module actions routunes
@@ -955,8 +957,13 @@
 !
 !--       Map forcing data derived from larger scale model onto domain 
-!--       boundaries. 
+!--       boundaries. Further, update geostrophic wind components.
           IF ( nesting_offline  .AND.  intermediate_timestep_count ==                              &
-                                       intermediate_timestep_count_max  )                          &
+                                       intermediate_timestep_count_max  )  THEN
+!--          Determine interpolation factor before boundary conditions and geostrophic wind 
+!--          is updated.
+             CALL nesting_offl_interpolation_factor
              CALL nesting_offl_bc
+             CALL nesting_offl_geostrophic_wind
+          ENDIF
 !
 !--       Impose a turbulent inflow using synthetic generated turbulence.
Index: palm/trunk/SOURCE/virtual_measurement_mod.f90
===================================================================
--- palm/trunk/SOURCE/virtual_measurement_mod.f90	(revision 4225)
+++ palm/trunk/SOURCE/virtual_measurement_mod.f90	(revision 4226)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Netcdf input routine for dimension length renamed
+! 
+! 4182 2019-08-22 15:20:23Z scharf
 ! Corrected "Former revisions" section
 ! 
@@ -435,7 +438,9 @@
  
     USE netcdf_data_input_mod,                                                 &
-        ONLY:  init_model, input_file_vm,                                      &
-               netcdf_data_input_get_dimension_length,                         &
-               netcdf_data_input_att, netcdf_data_input_var
+        ONLY:  get_dimension_length,                                           &
+               init_model,                                                     &
+               input_file_vm,                                                  &
+               netcdf_data_input_att,                                          &
+               netcdf_data_input_var
         
     IMPLICIT NONE
@@ -648,12 +653,12 @@
 !--          For non-stationary measurements read the number of trajectories
 !--          and the number of time coordinates.
-             CALL netcdf_data_input_get_dimension_length( vmea_general%id_vm, &
-                                                          vmea(l)%ntraj,      &
-                                                          "traj" //           &
-                                                          TRIM( dum ) )
-             CALL netcdf_data_input_get_dimension_length( vmea_general%id_vm, &
-                                                          dim_ntime,          &
-                                                          "ntime" //          &
-                                                          TRIM( dum ) )
+             CALL get_dimension_length( vmea_general%id_vm,                    &
+                                        vmea(l)%ntraj,                         &
+                                        "traj" //                              &
+                                        TRIM( dum ) )
+             CALL get_dimension_length( vmea_general%id_vm,                    &
+                                        dim_ntime,                             &
+                                        "ntime" //                             &
+                                        TRIM( dum ) )
 !
 !--       For stationary measurements the dimension for UTM and time 
