Index: palm/trunk/SOURCE/netcdf_data_input_mod.f90
===================================================================
--- palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 4391)
+++ palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 4392)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! (resler) Decrease length of reading buffer (fix problem of ifort/icc compilers)
+! 
+! 4389 2020-01-29 08:22:42Z raasch
 ! Error messages refined for reading ASCII topo file, also reading of topo file revised so that
 ! statement labels and goto statements are not required any more
@@ -4703,5 +4706,5 @@
        IMPLICIT NONE
 
-       INTEGER, PARAMETER ::  nsurf_pars_read = 1024**2 !< read buffer size
+       INTEGER(iwp), PARAMETER                   ::  nsurf_pars_read = 2**15 !< read buffer size (value > 10^15 makes problem with ifort)
 
        CHARACTER(LEN=*)                          ::  variable_name !< variable name
Index: palm/trunk/SOURCE/plant_canopy_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/plant_canopy_model_mod.f90	(revision 4391)
+++ palm/trunk/SOURCE/plant_canopy_model_mod.f90	(revision 4392)
@@ -16,5 +16,5 @@
 !
 ! Copyright 1997-2020 Leibniz Universitaet Hannover
-! Copyright 2017-2019 Institute of Computer Science of the
+! Copyright 2017-2020 Institute of Computer Science of the
 !                     Czech Academy of Sciences, Prague
 !------------------------------------------------------------------------------!
@@ -27,4 +27,8 @@
 ! -----------------
 ! $Id$
+! (resler) Make pcm_heatrate_av, pcm_latentrate_av public to allow calculation
+! of averaged Bowen ratio in the user procedure
+!
+! 4381 2020-01-20 13:51:46Z suehring
 ! Give error message 313 only once
 ! 
@@ -286,5 +290,6 @@
     PUBLIC canopy_drag_coeff, pcm_heating_rate, pcm_transpiration_rate,       &
            pcm_latent_rate, canopy_mode, cthf, dt_plant_canopy, lad, lad_s,   &
-           pch_index, plant_canopy_transpiration
+           pch_index, plant_canopy_transpiration,                             &
+           pcm_heatrate_av, pcm_latentrate_av
 
     INTERFACE pcm_calc_transpiration_rate
Index: palm/trunk/SOURCE/radiation_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/radiation_model_mod.f90	(revision 4391)
+++ palm/trunk/SOURCE/radiation_model_mod.f90	(revision 4392)
@@ -15,5 +15,5 @@
 ! PALM. If not, see <http://www.gnu.org/licenses/>.
 !
-! Copyright 2015-2019 Institute of Computer Science of the 
+! Copyright 2015-2020 Institute of Computer Science of the
 !                     Czech Academy of Sciences, Prague
 ! Copyright 2015-2019 Czech Technical University in Prague
@@ -28,4 +28,9 @@
 ! -----------------
 ! $Id$
+! - Add debug tracing of large radiative fluxes (option trace_fluxes_above)
+! - Print exact counts of SVF and CSF if debut_output is enabled
+! - Update descriptions of RTM 3.0 and related comments
+! 
+! 4360 2020-01-07 11:25:50Z suehring
 ! Renamed pc_heating_rate, pc_transpiration_rate, pc_transpiration_rate to
 ! pcm_heating_rate, pcm_latent_rate, pcm_transpiration_rate
@@ -214,15 +219,16 @@
 ! Description:
 ! ------------
-!> Radiation models and interfaces
-!> @todo Replace dz(1) appropriatly to account for grid stretching
+!> Radiation models and interfaces:
+!> constant, simple and RRTMG models, interface to external radiation model
+!> Radiative Transfer Model (RTM) version 3.0 for modelling of radiation
+!> interactions within urban canopy or other surface layer in complex terrain
+!> Integrations of RTM with other PALM-4U modules:
+!> integration with RRTMG, USM, LSM, PCM, BIO modules
+!>
 !> @todo move variable definitions used in radiation_init only to the subroutine
 !>       as they are no longer required after initialization.
 !> @todo Output of full column vertical profiles used in RRTMG
 !> @todo Output of other rrtm arrays (such as volume mixing ratios)
-!> @todo Check for mis-used NINT() calls in raytrace_2d
-!>       RESULT: Original was correct (carefully verified formula), the change
-!>               to INT broke raytracing      -- P. Krc
 !> @todo Optimize radiation_tendency routines
-!> @todo Consider rotated model domains (rotation_angle/=0.0)
 !>
 !> @note Many variables have a leading dummy dimension (0:0) in order to
@@ -430,5 +436,6 @@
                 skip_time_do_radiation = 0.0_wp, & !< Radiation model is not called before this time
                 sky_trans,                       & !< sky transmissivity
-                time_radiation = 0.0_wp            !< time since last call of radiation code
+                time_radiation = 0.0_wp,         & !< time since last call of radiation code
+                trace_fluxes_above = -1.0_wp       !< NAMELIST option for debug tracing of large radiative fluxes (W/m2;W/m3)
 
     INTEGER(iwp) ::  day_of_year   !< day of the current year
@@ -1532,5 +1539,5 @@
 ! Description:
 ! ------------
-!> Initialization of the radiation model
+!> Initialization of the radiation model and Radiative Transfer Model
 !------------------------------------------------------------------------------!
     SUBROUTINE radiation_init
@@ -3848,5 +3855,5 @@
 ! Description:
 ! ------------
-!> Parin for &radiation_parameters for radiation model
+!> Parin for &radiation_parameters for radiation model and RTM
 !------------------------------------------------------------------------------!
     SUBROUTINE radiation_parin
@@ -3868,4 +3875,5 @@
                                   raytrace_discrete_azims,                      &
                                   raytrace_discrete_elevs, raytrace_mpi_rma,    &
+                                  trace_fluxes_above,                           &
                                   skip_time_do_radiation, surface_reflections,  &
                                   svfnorm_report_thresh, sw_radiation,          &
@@ -3884,4 +3892,5 @@
                                   raytrace_discrete_azims,                      &
                                   raytrace_discrete_elevs, raytrace_mpi_rma,    &
+                                  trace_fluxes_above,                           &
                                   skip_time_do_radiation, surface_reflections,  &
                                   svfnorm_report_thresh, sw_radiation,          &
@@ -5698,13 +5707,31 @@
 ! Description:
 ! ------------
-!> This subroutine calculates interaction of the solar radiation
+!> Radiative Transfer Model (RTM) version 3.0 for modelling of radiation
+!> interactions within urban canopy or inside of surface layer in complex terrain.
+!> This subroutine calculates interaction of the solar SW and LW radiation
 !> with urban and land surfaces and updates all surface heatfluxes.
-!> It calculates also the required parameters for RRTMG lower BC.
+!> It also calculates interactions of SW and LW radiation with resolved
+!> plant canopy and calculates the corresponding plant canopy heat fluxes.
+!> The subroutine also models spatial and temporal distribution of Mean
+!> Radiant Temperature (MRT). The resulting values are provided to other
+!> PALM-4U modules (RRTMG, USM, LSM, PCM and BIO).
 !>
-!> For more info. see Resler et al. 2017
+!> The new version 3.0 was radically rewriten from version 1.0.
+!> The most significant changes include new angular discretization scheme,
+!> redesigned and significantly optimized raytracing scheme, new processes
+!> included in modelling (e.g. intetrations of LW radiation with PC),
+!> integrated calculation of Mean Radiant Temperature (MRT), and improved
+!> and enhanced output and debug capabilities. This new version significantly
+!> improves effectivity of the paralelization and the scalability of the model
+!> and allows simulation of extensive domain with appropriate HPC resources.
 !>
-!> The new version 2.0 was radically rewriten, the discretization scheme
-!> has been changed. This new version significantly improves effectivity
-!> of the paralelization and the scalability of the model.
+!> More info about RTM v.1.0. see:
+!> Resler et al., GMD. 2017, https://doi.org/10.5194/gmd-10-3635-2017
+!> Info about RTM v. 3.0 see:
+!> Krc et al. 2020 (to appear in GMD),
+!> Maronga et al., GMDD 2019,  https://doi.org/10.5194/gmd-2019-103
+!>
+
+
 !------------------------------------------------------------------------------!
 
@@ -5900,4 +5927,11 @@
      ENDDO
 
+     IF ( trace_fluxes_above >= 0._wp )  THEN
+        CALL radiation_print_debug_surf( 'surfoutll before initial pass', surfoutll )
+        CALL radiation_print_debug_horz( 'rad_lw_in_diff before initial pass', rad_lw_in_diff )
+        CALL radiation_print_debug_horz( 'rad_sw_in_diff before initial pass', rad_sw_in_diff )
+        CALL radiation_print_debug_horz( 'rad_sw_in_dir before initial pass', rad_sw_in_dir )
+     ENDIF
+
 #if defined( __parallel )
 !--     might be optimized and gather only values relevant for current processor
@@ -6039,4 +6073,16 @@
      ENDIF
 
+     IF ( trace_fluxes_above >= 0._wp )  THEN
+        CALL radiation_print_debug_surf( 'surfinl after initial pass', surfinl )
+        CALL radiation_print_debug_surf( 'surfinlwdif after initial pass', surfinlwdif )
+        CALL radiation_print_debug_surf( 'surfinswdif after initial pass', surfinswdif )
+        CALL radiation_print_debug_surf( 'surfinswdir after initial pass', surfinswdir )
+        IF ( npcbl > 0 )  THEN
+           CALL radiation_print_debug_pcb( 'pcbinlw after initial pass', pcbinlw )
+           CALL radiation_print_debug_pcb( 'pcbinswdif after initial pass', pcbinswdif )
+           CALL radiation_print_debug_pcb( 'pcbinswdir after initial pass', pcbinswdir )
+        ENDIF
+     ENDIF
+
      IF ( plant_lw_interact )  THEN
 !
@@ -6054,4 +6100,8 @@
      ENDIF
 
+     IF ( trace_fluxes_above >= 0._wp )  THEN
+        CALL radiation_print_debug_surf( 'surfinl after PC emiss', surfinl )
+     ENDIF
+
      surfins = surfinswdir + surfinswdif
      surfinl = surfinl + surfinlwdif
@@ -6081,4 +6131,9 @@
 !--      for non-transparent surfaces, longwave albedo is 1 - emissivity
          surfoutll = (1._wp - emiss_surf) * surfinl
+
+         IF ( trace_fluxes_above >= 0._wp )  THEN
+            CALL radiation_print_debug_surf( 'surfoutll before reflective pass', surfoutll, refstep )
+            CALL radiation_print_debug_surf( 'surfoutsl before reflective pass', surfoutsl, refstep )
+         ENDIF
 
 #if defined( __parallel )
@@ -6148,4 +6203,11 @@
             mrtinlw(imrt) = mrtinlw(imrt) + mrtf(imrtf) * surfoutl(isurfsrc)
          ENDDO
+
+         IF ( trace_fluxes_above >= 0._wp )  THEN
+            CALL radiation_print_debug_surf( 'surfinl after reflected pass', surfinl, refstep )
+            CALL radiation_print_debug_surf( 'surfins after reflected pass', surfins, refstep )
+            CALL radiation_print_debug_pcb( 'pcbinlw after reflected pass', pcbinlw, refstep )
+            CALL radiation_print_debug_pcb( 'pcbinsw after reflected pass', pcbinsw, refstep )
+         ENDIF
 
          surfinsw = surfinsw  + surfins
@@ -6582,5 +6644,5 @@
 ! Description:
 ! ------------
-!> This subroutine splits direct and diffusion dw radiation
+!> This subroutine splits direct and diffusion dw radiation for RTM processing.
 !> It sould not be called in case the radiation model already does it
 !> It follows Boland, Ridley & Brown (2008)
@@ -6642,4 +6704,98 @@
     END SUBROUTINE calc_diffusion_radiation
 
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Print consecutive radiative extremes if requested to trace early radiation
+!> interaction instabilities.
+!------------------------------------------------------------------------------!
+    SUBROUTINE radiation_print_debug_surf( description, values, step )
+
+       CHARACTER (LEN=*), INTENT(in)      ::  description
+       REAL(wp), DIMENSION(:), INTENT(in) ::  values
+       INTEGER(iwp), INTENT(in), OPTIONAL ::  step
+
+       CHARACTER (LEN=50)                 ::  location
+       CHARACTER (LEN=1024)               ::  debug_string
+       INTEGER                            ::  isurf
+       REAL(wp)                           ::  x
+
+       isurf = MAXLOC( values, DIM=1 )
+       x = values(isurf)
+       IF ( x < trace_fluxes_above )  RETURN
+
+       IF ( PRESENT( step ) )  THEN
+          WRITE( location, '(A," #",I0)' ) description, step
+       ELSE
+          location = description
+       ENDIF
+
+       WRITE( debug_string, '("Maximum of ",A50," = ",F12.1," at coords ' //  &
+                            'i=",I4,", j=",I4,", k=",I4,", d=",I1,". '    //  &
+                            'Alb=",F7.3,", emis=",F7.3)'                    ) &
+              location, x, surfl(ix,isurf), surfl(iy,isurf),                  &
+              surfl(iz,isurf), surfl(id,isurf), albedo_surf(isurf),           &
+              emiss_surf(isurf)
+       CALL debug_message( debug_string, 'info' )
+
+    END SUBROUTINE
+
+    SUBROUTINE radiation_print_debug_pcb( description, values, step )
+
+       CHARACTER (LEN=*), INTENT(in)      ::  description
+       REAL(wp), DIMENSION(:), INTENT(in) ::  values
+       INTEGER(iwp), INTENT(in), OPTIONAL ::  step
+
+       CHARACTER (LEN=50)                 ::  location
+       CHARACTER (LEN=1024)               ::  debug_string
+       INTEGER                            ::  ipcb
+       REAL(wp)                           ::  x
+
+       IF ( npcbl <= 0 )  RETURN
+       ipcb = MAXLOC( values, DIM=1 )
+       x = values(ipcb) / (dx*dy*dz(1))
+       IF ( x < trace_fluxes_above )  RETURN
+
+       IF ( PRESENT( step ) )  THEN
+          WRITE( location, '(A," #",I0)' ) description, step
+       ELSE
+          location = description
+       ENDIF
+
+       WRITE( debug_string, '("Maximum of ",A50," = ",F12.1," at coords ' //  &
+                            'i=",I4,", j=",I4,", k=",I4)'                   ) &
+              location, x, pcbl(ix,ipcb), pcbl(iy,ipcb), pcbl(iz,ipcb)
+       CALL debug_message( debug_string, 'info' )
+
+    END SUBROUTINE
+
+    SUBROUTINE radiation_print_debug_horz( description, values, step )
+
+       CHARACTER (LEN=*), INTENT(in)        ::  description
+       REAL(wp), DIMENSION(:,:), INTENT(in) ::  values
+       INTEGER(iwp), INTENT(in), OPTIONAL   ::  step
+
+       CHARACTER (LEN=50)                   ::  location
+       CHARACTER (LEN=1024)                 ::  debug_string
+       INTEGER, DIMENSION(2)                ::  ji
+       REAL(wp)                             ::  x
+
+       ji = MAXLOC( values )
+       x = values(ji(1),ji(2))
+       IF ( x < trace_fluxes_above )  RETURN
+
+       IF ( PRESENT( step ) )  THEN
+          WRITE( location, '(A," #",I0)' ) description, step
+       ELSE
+          location = description
+       ENDIF
+
+       WRITE( debug_string, '("Maximum of ",A50," = ",F12.1," at coords ' //  &
+                            'i=",I4,", j=",I4)'                             ) &
+              location, x, ji(2), ji(1)
+       CALL debug_message( debug_string, 'info' )
+
+    END SUBROUTINE
+
  END SUBROUTINE radiation_interaction
     
@@ -6647,14 +6803,8 @@
 ! Description:
 ! ------------
-!> This subroutine initializes structures needed for radiative transfer
-!> model. This model calculates transformation processes of the
+!> This subroutine initializes structures needed for Radiative Transfer
+!> Model (RTM). This model calculates transformation processes of the
 !> radiation inside urban and land canopy layer. The module includes also
 !> the interaction of the radiation with the resolved plant canopy.
-!>
-!> For more info. see Resler et al. 2017
-!>
-!> The new version 2.0 was radically rewriten, the discretization scheme
-!> has been changed. This new version significantly improves effectivity
-!> of the paralelization and the scalability of the model.
 !>
 !------------------------------------------------------------------------------!
@@ -7182,5 +7332,8 @@
 !> Calculates shape view factors (SVF), plant sink canopy factors (PCSF),
 !> sky-view factors, discretized path for direct solar radiation, MRT factors
-!> and other preprocessed data needed for radiation_interaction.
+!> and other preprocessed data needed for radiation_interaction inside RTM.
+!> This subroutine is called only one at the beginning of the simulation.
+!> The resulting factors can be stored to files and reused with other
+!> simulations utilizing the same surface and plant canopy structure.
 !------------------------------------------------------------------------------!
     SUBROUTINE radiation_calc_svf
@@ -7944,5 +8097,8 @@
 
         IF ( rad_angular_discretization )  THEN
-           IF ( debug_output )  CALL debug_message( 'Load svf from the structure array to plain arrays', 'info' )
+           IF ( debug_output )  THEN
+              WRITE( debug_string, '("Load ",I0," SVFs from the structure array to plain arrays")' ) nsvfl
+              CALL debug_message( debug_string, 'info' )
+           ENDIF
            ALLOCATE( svf(ndsvf,nsvfl) )
            ALLOCATE( svfsurf(idsvf,nsvfl) )
@@ -7958,5 +8114,8 @@
 
            !< load svf from the structure array to plain arrays
-           IF ( debug_output )  CALL debug_message( 'Load svf from the structure array to plain arrays', 'info' )
+           IF ( debug_output )  THEN
+              WRITE( debug_string, '("Load ",I0," SVFs from the structure array to plain arrays")' ) nsvfl
+              CALL debug_message( debug_string, 'info' )
+           ENDIF
            ALLOCATE( svf(ndsvf,nsvfl) )
            ALLOCATE( svfsurf(idsvf,nsvfl) )
@@ -8189,5 +8348,8 @@
             DEALLOCATE( pcsflt_l )
             DEALLOCATE( kpcsflt_l )
-            IF ( debug_output )  CALL debug_message( 'End of aggregate csf', 'info' )
+            IF ( debug_output )  THEN
+               WRITE( debug_string, '("Finished aggregating ",I0," CSFs.")') ncsfl
+               CALL debug_message( debug_string, 'info' )
+            ENDIF
             
         ENDIF
@@ -8212,6 +8374,6 @@
 ! ------------
 !> Raytracing for detecting obstacles and calculating compound canopy sink
-!> factors. (A simple obstacle detection would only need to process faces in
-!> 3 dimensions without any ordering.)
+!> factors for RTM. (A simple obstacle detection would only need to process
+!> faces in 3 dimensions without any ordering.)
 !> Assumtions:
 !> -----------
@@ -8410,5 +8572,5 @@
 ! ------------
 !> A new, more efficient version of ray tracing algorithm that processes a whole
-!> arc instead of a single ray.
+!> arc instead of a single ray (new in RTM version 2.5).
 !>
 !> In all comments, horizon means tangent of horizon angle, i.e.
@@ -8925,5 +9087,5 @@
 ! ------------
 !> Calculates apparent solar positions for all timesteps and stores discretized
-!> positions.
+!> positions for RTM.
 !------------------------------------------------------------------------------!
    SUBROUTINE radiation_presimulate_solar_pos
@@ -9013,5 +9175,5 @@
 ! Description:
 ! ------------
-!> Determines whether two faces are oriented towards each other. Since the
+!> Determines whether two faces are oriented towards each other in RTM. Since the
 !> surfaces follow the gird box surfaces, it checks first whether the two surfaces
 !> are directed in the same direction, then it checks if the two surfaces are
@@ -9074,6 +9236,7 @@
 ! Description:
 ! ------------
-!> Reads svf, svfsurf, csf, csfsurf and mrt factors data from saved file
-!> SVF means sky view factors and CSF means canopy sink factors
+!> Reads svf, svfsurf, csf, csfsurf and mrt factors data from saved file.
+!> This allows to skip their calculation during of RTM init phase.
+!> SVF means sky view factors and CSF means canopy sink factors.
 !------------------------------------------------------------------------------!
     SUBROUTINE radiation_read_svf
@@ -9240,4 +9403,6 @@
 ! ------------
 !> Subroutine stores svf, svfsurf, csf, csfsurf and mrt data to a file.
+!> The stored factors can be reused in future simulation with the same
+!> geometry structure of the surfaces and resolved plant canopy.
 !------------------------------------------------------------------------------!
     SUBROUTINE radiation_write_svf
@@ -9304,5 +9469,5 @@
 ! Description:
 ! ------------
-!> Block of auxiliary subroutines:
+!> Block of auxiliary subroutines for RTM:
 !> 1. quicksort and corresponding comparison
 !> 2. merge_and_grow_csf for implementation of "dynamical growing"
@@ -9440,7 +9605,7 @@
 ! Description:
 ! ------------
-!> Grows the CSF array exponentially after it is full. During that, the ray
-!> canopy sink factors with common source face and target plant canopy grid
-!> cell are merged together so that the size doesn't grow out of control.
+!> Grows the CSF array in RTM exponentially when it is full. During that,
+!> the ray canopy sink factors with common source face and target plant canopy
+!> grid cell are merged together so that the size doesn't grow out of control.
 !------------------------------------------------------------------------------!
     SUBROUTINE merge_and_grow_csf(newsize)
Index: palm/trunk/SOURCE/urban_surface_mod.f90
===================================================================
--- palm/trunk/SOURCE/urban_surface_mod.f90	(revision 4391)
+++ palm/trunk/SOURCE/urban_surface_mod.f90	(revision 4392)
@@ -16,5 +16,5 @@
 !
 ! Copyright 2015-2019 Czech Technical University in Prague
-! Copyright 2015-2019 Institute of Computer Science of the 
+! Copyright 2015-2020 Institute of Computer Science of the
 !                     Czech Academy of Sciences, Prague
 ! Copyright 1997-2020 Leibniz Universitaet Hannover
@@ -281,6 +281,4 @@
                force_radiation_call, iup_u, inorth_u, isouth_u, ieast_u,       &
                iwest_u, iup_l, inorth_l, isouth_l, ieast_l, iwest_l, id,       &
-               iz, iy, ix,  nsurf, idsvf, ndsvf,                               &
-               idcsf, ndcsf, kdcsf, pct,                                       &
                nz_urban_b, nz_urban_t, unscheduled_radiation_calls
 
