Index: palm/trunk/SOURCE/biometeorology_mod.f90
===================================================================
--- palm/trunk/SOURCE/biometeorology_mod.f90	(revision 3649)
+++ palm/trunk/SOURCE/biometeorology_mod.f90	(revision 3650)
@@ -15,7 +15,7 @@
 ! PALM. If not, see <http://www.gnu.org/licenses/>.
 !
-! Copyright 2018-2018 Deutscher Wetterdienst (DWD)
-! Copyright 2018-2018 Institute of Computer Science, Academy of Sciences, Prague
-! Copyright 2018-2018 Leibniz Universitaet Hannover
+! Copyright 2018-2019 Deutscher Wetterdienst (DWD)
+! Copyright 2018-2019 Institute of Computer Science, Academy of Sciences, Prague
+! Copyright 2018-2019 Leibniz Universitaet Hannover
 !--------------------------------------------------------------------------------!
 !
@@ -27,4 +27,7 @@
 ! -----------------
 ! $Id$
+! Bugfixes and additions for enabling restarts with biometeorology 
+! 
+! 3646 2018-12-28 17:58:49Z kanani
 ! Remove check for simulated_time > 0, it is not required since biometeorology
 ! is only called from time_integration and not during time_integration_spinup
@@ -180,4 +183,5 @@
 !
 !-- Declare all global variables within the module (alphabetical order)
+    INTEGER(iwp) ::  bio_nmrtbl
     INTEGER(iwp) ::  ai                      = 0  !< loop index in azimuth direction
     INTEGER(iwp) ::  bi                      = 0  !< loop index of bit location within an 8bit-integer (one Byte)
@@ -234,7 +238,8 @@
     bio_init, bio_parin, bio_perct, bio_perct_av, bio_pet,                     &
     bio_pet_av, bio_utci, bio_utci_av, thermal_comfort, time_bio_results,      &
+    bio_nmrtbl, bio_wrd_local, bio_rrd_local, bio_wrd_global, bio_rrd_global
 !
 !-- UVEM PUBLIC variables and methods
-    uvem_calc_exposure, uv_exposure
+    PUBLIC uvem_calc_exposure, uv_exposure
 
 !
@@ -305,5 +310,24 @@
        MODULE PROCEDURE bio_parin
     END INTERFACE bio_parin
-
+!
+!-- Read global restart parameters
+    INTERFACE bio_rrd_global
+       MODULE PROCEDURE bio_rrd_global
+    END INTERFACE bio_rrd_global
+!
+!-- Read local restart parameters
+    INTERFACE bio_rrd_local
+       MODULE PROCEDURE bio_rrd_local
+    END INTERFACE bio_rrd_local
+!
+!-- Write global restart parameters
+    INTERFACE bio_wrd_global
+       MODULE PROCEDURE bio_wrd_global
+    END INTERFACE bio_wrd_global
+!
+!-- Write local restart parameters
+    INTERFACE bio_wrd_local
+       MODULE PROCEDURE bio_wrd_local
+    END INTERFACE bio_wrd_local
 !
 !-- Calculate UV exposure grid
@@ -363,20 +387,4 @@
                   .NOT. average_trigger_utci  .AND.                            &
                   .NOT. average_trigger_pet ) THEN
-!
-!--             Allocate the required grids
-                IF ( .NOT. ALLOCATED( perct_av ) ) THEN
-                   ALLOCATE( perct_av (nys:nyn,nxl:nxr) )
-                ENDIF
-                perct_av = REAL( bio_fill_value, KIND = wp )
-
-                IF ( .NOT. ALLOCATED( utci_av ) ) THEN
-                   ALLOCATE( utci_av (nys:nyn,nxl:nxr) )
-                ENDIF
-                utci_av = REAL( bio_fill_value, KIND = wp )
-
-                IF ( .NOT. ALLOCATED( pet_av ) ) THEN
-                   ALLOCATE( pet_av (nys:nyn,nxl:nxr) )
-                ENDIF
-                pet_av = REAL( bio_fill_value, KIND = wp )
 !
 !--             Memorize the first index called to control averaging
@@ -401,5 +409,5 @@
 !            modules. Set averaging switch to .TRUE. in that case.
              IF ( .NOT. ALLOCATED( pt_av ) )  THEN
-                ALLOCATE( pt_av(nzb:nzt+1,nys:nyn,nxl:nxr) )
+                ALLOCATE( pt_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
                 aver_perct = .TRUE.
                 pt_av = 0.0_wp
@@ -407,5 +415,5 @@
 
              IF ( .NOT. ALLOCATED( q_av ) )  THEN
-                ALLOCATE( q_av(nzb:nzt+1,nys:nyn,nxl:nxr) )
+                ALLOCATE( q_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
                 aver_q = .TRUE.
                 q_av = 0.0_wp
@@ -646,10 +654,14 @@
 !
 !-- Allocate a temporary array with the desired output dimensions.
+!-- Arrays for time-averaged thermal indices are also allocated here because they are not running
+!-- through the standard averaging procedure in bio_3d_data_averaging as the values of the
+!-- averaged thermal indices are derived in a single step based on priorly averaged arrays
+!-- (see bio_calculate_thermal_index_maps).
        CASE ( 'bio_mrt' )
           unit = 'degree_C'
           IF ( .NOT. ALLOCATED( tmrt_grid ) )  THEN
              ALLOCATE( tmrt_grid (nys:nyn,nxl:nxr) )
+             tmrt_grid = REAL( bio_fill_value, KIND = wp )
           ENDIF
-          tmrt_grid = REAL( bio_fill_value, KIND = wp )
 
        CASE ( 'bio_perct*' )
@@ -657,6 +669,10 @@
           IF ( .NOT. ALLOCATED( perct ) )  THEN
              ALLOCATE( perct (nys:nyn,nxl:nxr) )
+             perct = REAL( bio_fill_value, KIND = wp )
           ENDIF
-          perct = REAL( bio_fill_value, KIND = wp )
+          IF ( .NOT. ALLOCATED( perct_av ) )  THEN
+             ALLOCATE( perct_av (nys:nyn,nxl:nxr) )
+             perct_av = REAL( bio_fill_value, KIND = wp )
+          ENDIF
 
        CASE ( 'bio_utci*' )
@@ -664,6 +680,10 @@
           IF ( .NOT. ALLOCATED( utci ) )  THEN
              ALLOCATE( utci (nys:nyn,nxl:nxr) )
+             utci = REAL( bio_fill_value, KIND = wp )
           ENDIF
-          utci = REAL( bio_fill_value, KIND = wp )
+          IF ( .NOT. ALLOCATED( utci_av ) )  THEN
+             ALLOCATE( utci_av (nys:nyn,nxl:nxr) )
+             utci_av = REAL( bio_fill_value, KIND = wp )
+          ENDIF
 
        CASE ( 'bio_pet*' )
@@ -671,6 +691,11 @@
           IF ( .NOT. ALLOCATED( pet ) )  THEN
              ALLOCATE( pet (nys:nyn,nxl:nxr) )
+             pet = REAL( bio_fill_value, KIND = wp )
           ENDIF
-          pet = REAL( bio_fill_value, KIND = wp )
+          IF ( .NOT. ALLOCATED( pet_av ) )  THEN
+             ALLOCATE( pet_av (nys:nyn,nxl:nxr) )
+             pet_av = REAL( bio_fill_value, KIND = wp )
+          ENDIF
+
 
        CASE ( 'uvem_vitd3*' )
@@ -1110,5 +1135,5 @@
 !
 !-- Init UVEM and load lookup tables
-    CALL netcdf_data_input_uvem
+    IF ( uv_exposure )  CALL netcdf_data_input_uvem
 
  END SUBROUTINE bio_init
@@ -1472,4 +1497,154 @@
 
  END SUBROUTINE bio_calc_ipt
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Soubroutine reads global biometeorology configuration from restart file(s)
+!------------------------------------------------------------------------------!
+ SUBROUTINE bio_rrd_global( found )
+
+    USE control_parameters,                                                    &
+        ONLY:  length, restart_string
+
+
+    IMPLICIT NONE
+
+    LOGICAL, INTENT(OUT) ::  found      !< variable found? yes = .T., no = .F.
+
+    found = .TRUE.
+
+
+    SELECT CASE ( restart_string(1:length) )
+
+!
+!--    read control flags to determine if input grids need to be averaged
+       CASE ( 'aver_perct' )
+          READ ( 13 )  aver_perct
+
+       CASE ( 'aver_q' )
+          READ ( 13 )  aver_q
+
+       CASE ( 'aver_u' )
+          READ ( 13 )  aver_u
+
+       CASE ( 'aver_v' )
+          READ ( 13 )  aver_v
+
+       CASE ( 'aver_w' )
+          READ ( 13 )  aver_w
+!
+!--    read control flags to determine which thermal index needs to trigger averaging
+       CASE ( 'average_trigger_perct' )
+          READ ( 13 )  average_trigger_perct
+
+       CASE ( 'average_trigger_utci' )
+          READ ( 13 )  average_trigger_utci
+
+       CASE ( 'average_trigger_pet' )
+          READ ( 13 )  average_trigger_pet
+
+
+       CASE DEFAULT
+
+          found = .FALSE.
+
+    END SELECT
+
+
+ END SUBROUTINE bio_rrd_global
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Soubroutine reads local biometeorology configuration from restart file(s)
+!------------------------------------------------------------------------------!
+ SUBROUTINE bio_rrd_local( found )
+
+
+    USE control_parameters,                                                    &
+        ONLY:  length, restart_string
+
+
+    IMPLICIT NONE
+
+
+    LOGICAL, INTENT(OUT) ::  found      !< variable found? yes = .T., no = .F.
+
+    found = .TRUE.
+
+
+    SELECT CASE ( restart_string(1:length) )
+
+       CASE ( 'nmrtbl' )
+          READ ( 13 )  bio_nmrtbl
+
+       CASE ( 'mrt_av_grid' )
+          IF ( .NOT. ALLOCATED( mrt_av_grid ) )  THEN
+             ALLOCATE( mrt_av_grid(bio_nmrtbl) )
+          ENDIF
+          READ ( 13 )  mrt_av_grid
+
+
+       CASE DEFAULT
+
+          found = .FALSE.
+
+    END SELECT
+
+
+ END SUBROUTINE bio_rrd_local
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Write global restart data for the biometeorology module.
+!------------------------------------------------------------------------------!
+ SUBROUTINE bio_wrd_global
+
+    IMPLICIT NONE
+
+    CALL wrd_write_string( 'aver_perct' )
+    WRITE ( 14 )  aver_perct
+    CALL wrd_write_string( 'aver_q' )
+    WRITE ( 14 )  aver_q
+    CALL wrd_write_string( 'aver_u' )
+    WRITE ( 14 )  aver_u
+    CALL wrd_write_string( 'aver_v' )
+    WRITE ( 14 )  aver_v
+    CALL wrd_write_string( 'aver_w' )
+    WRITE ( 14 )  aver_w
+    CALL wrd_write_string( 'average_trigger_perct' )
+    WRITE ( 14 )  average_trigger_perct
+    CALL wrd_write_string( 'average_trigger_utci' )
+    WRITE ( 14 )  average_trigger_utci
+    CALL wrd_write_string( 'average_trigger_pet' )
+    WRITE ( 14 )  average_trigger_pet
+
+ END SUBROUTINE bio_wrd_global
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Write local restart data for the biometeorology module.
+!------------------------------------------------------------------------------!
+ SUBROUTINE bio_wrd_local
+
+    IMPLICIT NONE
+
+!
+!-- First nmrtbl has to be written/read, because it is the dimension of mrt_av_grid
+    CALL wrd_write_string( 'nmrtbl' )
+    WRITE ( 14 )  nmrtbl
+
+    IF ( ALLOCATED( mrt_av_grid ) )  THEN
+       CALL wrd_write_string( 'mrt_av_grid' )
+       WRITE ( 14 )  mrt_av_grid
+    ENDIF
+
+
+ END SUBROUTINE bio_wrd_local
 
 
Index: palm/trunk/SOURCE/module_interface.f90
===================================================================
--- palm/trunk/SOURCE/module_interface.f90	(revision 3649)
+++ palm/trunk/SOURCE/module_interface.f90	(revision 3650)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Add restart routines for biometeorology
+! 
+! 3649 2019-01-02 16:52:21Z suehring
 ! Initialize strings, in order to avoid compiler warnings for non-initialized
 ! characters with intent(out) attribute
@@ -75,5 +78,9 @@
               bio_3d_data_averaging,                                           &
               bio_data_output_2d,                                              &
-              bio_data_output_3d
+              bio_data_output_3d,                                              &
+              bio_rrd_global,                                                  &
+              bio_rrd_local,                                                   &
+              bio_wrd_global,                                                  &
+              bio_wrd_local
 
    USE bulk_cloud_model_mod,                                                   &
@@ -552,5 +559,5 @@
    CHARACTER (LEN=*), INTENT(OUT) ::  grid_z !< netcdf dimension in z-direction
 !
-!--As long as no action is done in this subroutine, initial strings with   
+!--As long as no action is done in this subroutine, initialize strings with   
 !--intent(out) attribute, in order to avoid compiler warnings.
    found  = .FALSE.
@@ -878,4 +885,5 @@
    LOGICAL,           INTENT(OUT) ::  found    !< flag if variable was found
 
+   IF ( .NOT. found )  CALL bio_rrd_global( found ) ! ToDo: change interface to pass variable
    IF ( .NOT. found )  CALL bcm_rrd_global( found ) ! ToDo: change interface to pass variable
    IF ( .NOT. found )  CALL flight_rrd_global( found ) ! ToDo: change interface to pass variable
@@ -899,4 +907,5 @@
 
 
+   IF ( biometeorology )       CALL bio_wrd_global
    IF ( bulk_cloud_model )     CALL bcm_wrd_global
    IF ( virtual_flight )       CALL flight_wrd_global
@@ -946,4 +955,8 @@
 
 
+   IF ( .NOT. found ) CALL bio_rrd_local(                                      &
+                              found                                            &
+                           )
+
    IF ( .NOT. found ) CALL bcm_rrd_local(                                      &
                               file_index, map_index,                           &
@@ -1039,4 +1052,5 @@
 
 
+   IF ( biometeorology )       CALL bio_wrd_local
    IF ( bulk_cloud_model )     CALL bcm_wrd_local
    IF ( air_chemistry )        CALL chem_wrd_local
