source: palm/trunk/SOURCE/biometeorology_mod.f90 @ 4598

Last change on this file since 4598 was 4590, checked in by suehring, 4 years ago

Biomet: Enable restart via mpi-IO; Restart: Bugfix in allocation of hom and hom_sum in case of mpi-io restart when chemistry or salsa are employed

  • Property svn:keywords set to Id
  • Property svn:mergeinfo set to (toggle deleted branches)
    /palm/branches/chemistry/SOURCE/biometeorology_mod.f902047-3190,​3218-3297
    /palm/branches/resler/SOURCE/biometeorology_mod.f902023-4492
    /palm/branches/salsa/SOURCE/biometeorology_mod.f902503-3581
    /palm/trunk/SOURCE/biometeorology_mod.f90mergedeligible
    /palm/branches/forwind/SOURCE/biometeorology_mod.f901564-1913
    /palm/branches/fricke/SOURCE/biometeorology_mod.f90942-977
    /palm/branches/hoffmann/SOURCE/biometeorology_mod.f90989-1052
    /palm/branches/letzel/masked_output/SOURCE/biometeorology_mod.f90296-409
    /palm/branches/palm4u/SOURCE/biometeorology_mod.f902540-2692
    /palm/branches/rans/SOURCE/biometeorology_mod.f902078-3128
    /palm/branches/suehring/biometeorology_mod.f90423-666
File size: 193.5 KB
Line 
1!> @file biometeorology_mod.f90
2!--------------------------------------------------------------------------------------------------!
3! This file is part of PALM-4U.
4!
5! PALM-4U is free software: You can redistribute it and/or modify it under the terms of the GNU
6! General Public License as published by the Free Software Foundation, either version 3 of the
7! License, or (at your option) any later version.
8!
9! PALM-4U is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10! the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11! Public License for more details.
12!
13! You should have received a copy of the GNU General Public License along with PALM. If not, see
14! <http://www.gnu.org/licenses/>.
15!
16! Copyright 2018-2020 Deutscher Wetterdienst (DWD)
17! Copyright 2018-2020 Institute of Computer Science, Academy of Sciences, Prague
18! Copyright 2018-2020 Leibniz Universitaet Hannover
19!--------------------------------------------------------------------------------------------------!
20!
21! Current revisions:
22! ------------------
23!
24!
25! Former revisions:
26! -----------------
27! $Id: biometeorology_mod.f90 4590 2020-07-06 14:34:59Z suehring $
28! Enable restart via mpi-IO. Therefore, allocated array mrt_av_grid as 3D array instead of an
29! 1D array.
30!
31! 4577 2020-06-25 09:53:58Z raasch
32! further re-formatting concerning Fortran parameter variables
33!
34! 4540 2020-05-18 15:23:29Z raasch
35! file re-formatted to follow the PALM coding standard
36!
37! 4535 2020-05-15 12:07:23Z raasch
38! bugfix for restart data format query
39!
40! 4517 2020-05-03 14:29:30Z raasch
41! added restart with MPI-IO for reading local arrays
42!
43! 4495 2020-04-13 20:11:20Z raasch
44! restart data handling with MPI-IO added
45!
46! 4493 2020-04-10 09:49:43Z pavelkrc
47! Revise bad formatting
48!
49! 4286 2019-10-30 16:01:14Z resler
50! implement new palm_date_time_mod
51!
52! 4223 2019-09-10 09:20:47Z gronemeier
53! Corrected "Former revisions" section
54!
55! 4168 2019-08-16 13:50:17Z suehring
56! Replace function get_topography_top_index by topo_top_ind
57!
58! 4144 2019-08-06 09:11:47Z raasch
59! relational operators .EQ., .NE., etc. replaced by ==, /=, etc.
60!
61! 4127 2019-07-30 14:47:10Z suehring
62! Output for bio_mrt added (merge from branch resler)
63!
64! 4126 2019-07-30 11:09:11Z gronemeier
65! renamed vitd3_exposure_av into vitd3_dose,
66! renamed uvem_calc_exposure into bio_calculate_uv_exposure
67!
68! 3885 2019-04-11 11:29:34Z kanani
69! Changes related to global restructuring of location messages and introduction of additional debug
70! messages
71!
72! 3753 2019-02-19 14:48:54Z dom_dwd_user
73! - Added automatic setting of mrt_nlevels in case it was not part of radiation_parameters namelist
74!   (or set to 0 accidentially).
75! - Minor speed improvoemnts in perceived temperature calculations.
76! - Perceived temperature regression arrays now declared as PARAMETERs.
77!
78! 3750 2019-02-19 07:29:39Z dom_dwd_user
79! - Added addittional safety meassures to bio_calculate_thermal_index_maps.
80! - Replaced several REAL (un-)equality comparisons.
81!
82! 3742 2019-02-14 11:25:22Z dom_dwd_user
83! - Allocation of the input _av grids was moved to the "sum" section of bio_3d_data_averaging to
84!   make sure averaging is only done once!
85! - Moved call of bio_calculate_thermal_index_maps from biometeorology module to time_integration to
86!   make sure averaged input is updated before calculating.
87!
88! 3740 2019-02-13 12:35:12Z dom_dwd_user
89! - Added safety-meassure to catch the case that 'bio_mrt_av' is stated after 'bio_<index>' in the
90!   output section of the p3d file.
91!
92! 3739 2019-02-13 08:05:17Z dom_dwd_user
93! - Auto-adjusting thermal_comfort flag if not set by user, but thermal_indices set as output
94!   quantities.
95! - Renamed flags "bio_<index>" to "do_calculate_<index>" for better readability
96! - Removed everything related to "time_bio_results" as this is never used.
97! - Moved humidity warning to check_data_output.
98! - Fixed bug in mrt calculation introduced with my commit yesterday.
99!
100! 3735 2019-02-12 09:52:40Z dom_dwd_user
101! - Fixed auto-setting of thermal index calculation flags by output as originally proposed by
102!   resler.
103! - removed bio_pet and outher configuration variables.
104! - Updated namelist.
105!
106! 3711 2019-01-31 13:44:26Z knoop
107! Introduced interface routine bio_init_checks + small error message changes
108!
109! 3693 2019-01-23 15:20:53Z dom_dwd_user
110! Added usage of time_averaged mean radiant temperature, together with calculation, grid and restart
111! routines. General cleanup and commenting.
112!
113! 3685 2019-01-21 01:02:11Z knoop
114! Some interface calls moved to module_interface + cleanup
115!
116! 3650 2019-01-04 13:01:33Z kanani
117! Bugfixes and additions for enabling restarts with biometeorology
118!
119! 3448 2018-10-29 18:14:31Z kanani
120! Initial revision
121!
122!
123!
124! Authors:
125! --------
126! @author Dominik Froehlich <dominik.froehlich@dwd.de>, thermal indices
127! @author Jaroslav Resler <resler@cs.cas.cz>, mean radiant temperature
128! @author Michael Schrempf <schrempf@muk.uni-hannover.de>, uv exposure
129!
130!
131! Description:
132! ------------
133!> Biometeorology module consisting of two parts:
134!> 1.: Human thermal comfort module calculating thermal perception of a sample human being under the
135!> current meteorological conditions.
136!> 2.: Calculation of vitamin-D weighted UV exposure
137!>
138!> @todo Alphabetical sorting of "USE ..." lists, "ONLY" list, variable declarations
139!>       (per subroutine: first all CHARACTERs, then INTEGERs, LOGICALs, REALs, )
140!> @todo Comments start with capital letter --> "!-- Include..."
141!> @todo uv_vitd3dose-->new output type necessary (cumulative)
142!> @todo consider upwelling radiation in UV
143!>
144!> @note nothing now
145!>
146!> @bug  no known bugs by now
147!--------------------------------------------------------------------------------------------------!
148 MODULE biometeorology_mod
149
150    USE arrays_3d,                                                                                 &
151        ONLY:  pt, p, u, v, w, q
152
153    USE averaging,                                                                                 &
154        ONLY:  pt_av, q_av, u_av, v_av, w_av
155
156    USE basic_constants_and_equations_mod,                                                         &
157        ONLY: degc_to_k, c_p, l_v, magnus, pi, sigma_sb
158
159    USE control_parameters,                                                                        &
160        ONLY:  average_count_3d, biometeorology,                                                   &
161               debug_output,                                                                       &
162               dz, dz_stretch_factor,                                                              &
163               dz_stretch_level, humidity, initializing_actions, nz_do3d,                          &
164               restart_data_format_output, surface_pressure
165
166    USE grid_variables,                                                                            &
167        ONLY:  ddx, dx, ddy, dy
168
169    USE indices,                                                                                   &
170        ONLY:  nxl, nxr, nys, nyn, nzb, nzt, nys, nyn, nxl, nxr, nxlg, nxrg, nysg, nyng,           &
171               topo_top_ind
172
173    USE kinds  !< Set precision of INTEGER and REAL arrays according to PALM
174
175    USE netcdf_data_input_mod,                                                                     &
176        ONLY: building_obstruction_f, netcdf_data_input_uvem, uvem_integration_f,                  &
177              uvem_irradiance_f, uvem_projarea_f, uvem_radiance_f
178
179    USE palm_date_time_mod,                                                                        &
180        ONLY:  get_date_time
181!
182!-- Import radiation model to obtain input for mean radiant temperature
183    USE radiation_model_mod,                                                                       &
184        ONLY:  id, ix, iy, iz, mrt_include_sw, mrt_nlevels,                                        &
185               mrtbl, mrtinlw, mrtinsw, nmrtbl, radiation,                                         &
186               rad_lw_in, rad_lw_out, rad_sw_in, rad_sw_out, radiation_interactions
187
188    USE restart_data_mpi_io_mod,                                                                   &
189        ONLY:  rrd_mpi_io,                                                                         &
190               rd_mpi_io_check_array,                                                              &
191               wrd_mpi_io
192
193
194    IMPLICIT NONE
195
196!
197!-- Declare all global variables within the module (alphabetical order)
198    REAL(wp), PARAMETER ::  bio_fill_value = -9999.0_wp  !< set module fill value, replace by global fill value as soon as available
199    REAL(wp), PARAMETER ::  human_absorb = 0.7_wp  !< SW absorbtivity of a human body (Fanger 1972)
200    REAL(wp), PARAMETER ::  human_emiss = 0.97_wp  !< LW emissivity of a human body after (Fanger 1972)
201
202    INTEGER(iwp) ::  bio_cell_level     !< cell level biom calculates for
203
204    LOGICAL ::  thermal_comfort        = .FALSE.  !< Enables or disables the entire thermal comfort part
205    LOGICAL ::  do_average_theta       = .FALSE.  !< switch: do theta averaging in this module? (if .FALSE. this is done globally)
206    LOGICAL ::  do_average_q           = .FALSE.  !< switch: do e averaging in this module?
207    LOGICAL ::  do_average_u           = .FALSE.  !< switch: do u averaging in this module?
208    LOGICAL ::  do_average_v           = .FALSE.  !< switch: do v averaging in this module?
209    LOGICAL ::  do_average_w           = .FALSE.  !< switch: do w averaging in this module?
210    LOGICAL ::  do_average_mrt         = .FALSE.  !< switch: do mrt averaging in this module?
211    LOGICAL ::  average_trigger_perct  = .FALSE.  !< update averaged input on call to bio_perct?
212    LOGICAL ::  average_trigger_utci   = .FALSE.  !< update averaged input on call to bio_utci?
213    LOGICAL ::  average_trigger_pet    = .FALSE.  !< update averaged input on call to bio_pet?
214    LOGICAL ::  average_trigger_mrt    = .FALSE.  !< update averaged input on call to bio_pet?
215    LOGICAL ::  do_calculate_perct     = .FALSE.  !< Turn index PT (instant. input) on or off
216    LOGICAL ::  do_calculate_perct_av  = .FALSE.  !< Turn index PT (averaged input) on or off
217    LOGICAL ::  do_calculate_pet       = .FALSE.  !< Turn index PET (instant. input) on or off
218    LOGICAL ::  do_calculate_pet_av    = .FALSE.  !< Turn index PET (averaged input) on or off
219    LOGICAL ::  do_calculate_utci      = .FALSE.  !< Turn index UTCI (instant. input) on or off
220    LOGICAL ::  do_calculate_utci_av   = .FALSE.  !< Turn index UTCI (averaged input) on or off
221    LOGICAL ::  do_calculate_mrt2d     = .FALSE.  !< Turn index MRT 2D (averaged or inst) on or off
222
223    REAL(wp)    ::  bio_output_height  !< height output is calculated in m
224
225    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  perct      !< PT results   (degree_C)
226    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  pet        !< PET results  (degree_C)
227    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  tmrt_grid  !< tmrt results (degree_C)
228    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  utci       !< UTCI results (degree_C)
229!
230!-- Grids for averaged thermal indices
231    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  perct_av      !< PT results (aver. input)   (degree_C)
232    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  pet_av        !< PET results (aver. input)  (degree_C)
233    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  tmrt_av_grid  !< tmrt results (degree_C)
234    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  utci_av       !< UTCI results (aver. input) (degree_C)
235
236    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  mrt_av_grid   !< time average mean radiant temperature
237
238!
239!-- UVEM parameters from here
240    INTEGER(iwp) ::  ai                      = 0  !< loop index in azimuth direction
241    INTEGER(iwp) ::  bi                      = 0  !< loop index of bit location within an 8bit-integer (one Byte)
242    INTEGER(iwp) ::  bio_nmrtbl
243    INTEGER(iwp) ::  clothing                = 1  !< clothing (0=unclothed, 1=Arms,Hands,Face free, 3=Hand,Face free)
244    INTEGER(iwp) ::  iq                      = 0  !< loop index of irradiance quantity
245    INTEGER(iwp) ::  pobi                    = 0  !< loop index of the position of corresponding byte within ibset byte vektor
246    INTEGER(iwp) ::  obstruction_direct_beam = 0  !< Obstruction information for direct beam
247    INTEGER(iwp) ::  zi                      = 0  !< loop index in zenith direction
248
249    INTEGER(KIND=1), DIMENSION(0:44)  ::  obstruction_temp1 = 0  !< temporary obstruction information stored with ibset
250    INTEGER(iwp),    DIMENSION(0:359) ::  obstruction_temp2 = 0  !< restored temporary obstruction information from ibset file
251
252    INTEGER(iwp), DIMENSION(0:35,0:9) ::  obstruction       = 1  !< final 2D obstruction information array
253
254    LOGICAL ::  consider_obstructions = .TRUE.   !< namelist parameter (see documentation)
255    LOGICAL ::  sun_in_south          = .FALSE.  !< namelist parameter (see documentation)
256    LOGICAL ::  turn_to_sun           = .TRUE.   !< namelist parameter (see documentation)
257    LOGICAL ::  uv_exposure           = .FALSE.  !< namelist parameter (see documentation)
258
259    REAL(wp) ::  diffuse_exposure            =   0.0_wp  !< calculated exposure by diffuse radiation
260    REAL(wp) ::  direct_exposure             =   0.0_wp  !< calculated exposure by direct solar beam
261    REAL(wp) ::  orientation_angle           =   0.0_wp  !< orientation of front/face of the human model
262    REAL(wp) ::  projection_area_direct_beam =   0.0_wp  !< projection area for direct solar beam
263    REAL(wp) ::  saa                         = 180.0_wp  !< solar azimuth angle
264    REAL(wp) ::  startpos_human              =   0.0_wp  !< start value for azimuth interpolation of human geometry array
265    REAL(wp) ::  startpos_saa_float          =   0.0_wp  !< start value for azimuth interpolation of radiance array
266    REAL(wp) ::  sza                         =  20.0_wp  !< solar zenith angle
267    REAL(wp) ::  xfactor                     =   0.0_wp  !< relative x-position used for interpolation
268    REAL(wp) ::  yfactor                     =   0.0_wp  !< relative y-position used for interpolation
269
270    REAL(wp), DIMENSION(0:2)  ::  irradiance =   0.0_wp  !< iradiance values extracted from irradiance lookup table
271
272    REAL(wp), DIMENSION(0:2,0:90) ::  irradiance_lookup_table      = 0.0_wp  !< irradiance lookup table
273    REAL(wp), DIMENSION(0:35,0:9) ::  integration_array            = 0.0_wp  !< solid angle factors for hemispherical integration
274    REAL(wp), DIMENSION(0:35,0:9) ::  projection_area              = 0.0_wp  !< projection areas of a human (all directions)
275    REAL(wp), DIMENSION(0:35,0:9) ::  projection_area_lookup_table = 0.0_wp  !< human geometry lookup table (projection areas)
276    REAL(wp), DIMENSION(0:71,0:9) ::  projection_area_direct_temp  = 0.0_wp  !< temporary projection area for direct solar beam
277    REAL(wp), DIMENSION(0:71,0:9) ::  projection_area_temp         = 0.0_wp  !< temporary projection area for all directions
278    REAL(wp), DIMENSION(0:35,0:9) ::  radiance_array               = 0.0_wp  !< radiance extracted from radiance_lookup_table
279    REAL(wp), DIMENSION(0:71,0:9) ::  radiance_array_temp          = 0.0_wp  !< temporary radiance data
280
281    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  vitd3_exposure  !< result variable for instantaneous vitamin-D weighted exposures
282    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  vitd3_dose      !< result variable for summation of vitamin-D weighted exposures
283
284    REAL(wp), DIMENSION(0:35,0:9,0:90) ::  radiance_lookup_table   = 0.0_wp  !< radiance lookup table
285
286
287    PRIVATE
288
289!
290!-- INTERFACES that must be available to other modules (alphabetical order)
291    PUBLIC bio_3d_data_averaging,  bio_calculate_mrt_grid, bio_calculate_thermal_index_maps,       &
292           bio_calc_ipt, bio_check_data_output, bio_check_parameters,                              &
293           bio_data_output_2d, bio_data_output_3d,  bio_define_netcdf_grid,                        &
294           bio_get_thermal_index_input_ij, bio_header, bio_init, bio_init_checks, bio_nmrtbl,      &
295           bio_parin, bio_rrd_global, bio_rrd_local, bio_wrd_global, bio_wrd_local, thermal_comfort
296!
297!-- UVEM PUBLIC variables and methods
298    PUBLIC bio_calculate_uv_exposure, uv_exposure
299
300!
301!-- PALM interfaces:
302!
303!-- 3D averaging for HTCM _INPUT_ variables
304    INTERFACE bio_3d_data_averaging
305       MODULE PROCEDURE bio_3d_data_averaging
306    END INTERFACE bio_3d_data_averaging
307!
308!-- Calculate mtr from rtm fluxes and assign into 2D grid
309    INTERFACE bio_calculate_mrt_grid
310       MODULE PROCEDURE bio_calculate_mrt_grid
311    END INTERFACE bio_calculate_mrt_grid
312!
313!-- Calculate static thermal indices PT, UTCI and/or PET
314    INTERFACE bio_calculate_thermal_index_maps
315       MODULE PROCEDURE bio_calculate_thermal_index_maps
316    END INTERFACE bio_calculate_thermal_index_maps
317!
318!-- Calculate the dynamic index iPT (to be caled by the agent model)
319    INTERFACE bio_calc_ipt
320       MODULE PROCEDURE bio_calc_ipt
321    END INTERFACE bio_calc_ipt
322!
323!-- Data output checks for 2D/3D data to be done in check_parameters
324    INTERFACE bio_check_data_output
325       MODULE PROCEDURE bio_check_data_output
326    END INTERFACE bio_check_data_output
327!
328!-- Input parameter checks to be done in check_parameters
329    INTERFACE bio_check_parameters
330       MODULE PROCEDURE bio_check_parameters
331    END INTERFACE bio_check_parameters
332!
333!-- Data output of 2D quantities
334    INTERFACE bio_data_output_2d
335       MODULE PROCEDURE bio_data_output_2d
336    END INTERFACE bio_data_output_2d
337!
338!-- no 3D data, thus, no averaging of 3D data, removed
339    INTERFACE bio_data_output_3d
340       MODULE PROCEDURE bio_data_output_3d
341    END INTERFACE bio_data_output_3d
342!
343!-- Definition of data output quantities
344    INTERFACE bio_define_netcdf_grid
345       MODULE PROCEDURE bio_define_netcdf_grid
346    END INTERFACE bio_define_netcdf_grid
347!
348!-- Obtains all relevant input values to estimate local thermal comfort/stress
349    INTERFACE bio_get_thermal_index_input_ij
350       MODULE PROCEDURE bio_get_thermal_index_input_ij
351    END INTERFACE bio_get_thermal_index_input_ij
352!
353!-- Output of information to the header file
354    INTERFACE bio_header
355       MODULE PROCEDURE bio_header
356    END INTERFACE bio_header
357!
358!-- Initialization actions
359    INTERFACE bio_init
360       MODULE PROCEDURE bio_init
361    END INTERFACE bio_init
362!
363!-- Initialization checks
364    INTERFACE bio_init_checks
365       MODULE PROCEDURE bio_init_checks
366    END INTERFACE bio_init_checks
367!
368!-- Reading of NAMELIST parameters
369    INTERFACE bio_parin
370       MODULE PROCEDURE bio_parin
371    END INTERFACE bio_parin
372!
373!-- Read global restart parameters
374    INTERFACE bio_rrd_global
375       MODULE PROCEDURE bio_rrd_global_ftn
376       MODULE PROCEDURE bio_rrd_global_mpi
377    END INTERFACE bio_rrd_global
378!
379!-- Read local restart parameters
380    INTERFACE bio_rrd_local
381       MODULE PROCEDURE bio_rrd_local_ftn
382       MODULE PROCEDURE bio_rrd_local_mpi
383    END INTERFACE bio_rrd_local
384!
385!-- Write global restart parameters
386    INTERFACE bio_wrd_global
387       MODULE PROCEDURE bio_wrd_global
388    END INTERFACE bio_wrd_global
389!
390!-- Write local restart parameters
391    INTERFACE bio_wrd_local
392       MODULE PROCEDURE bio_wrd_local
393    END INTERFACE bio_wrd_local
394!
395!-- Calculate UV exposure grid
396    INTERFACE bio_calculate_uv_exposure
397       MODULE PROCEDURE bio_calculate_uv_exposure
398    END INTERFACE bio_calculate_uv_exposure
399
400 CONTAINS
401
402
403!--------------------------------------------------------------------------------------------------!
404! Description:
405! ------------
406!> Sum up and time-average biom input quantities as well as allocate the array necessary for storing
407!> the average.
408!> There is a considerable difference to the 3d_data_averaging subroutines used by other modules:
409!> For the thermal indices, the module needs to average the input conditions, not the result!
410!--------------------------------------------------------------------------------------------------!
411 SUBROUTINE bio_3d_data_averaging( mode, variable )
412
413    IMPLICIT NONE
414
415    CHARACTER (LEN=*) ::  mode     !< Averaging mode: allocate, sum, or average
416    CHARACTER (LEN=*) ::  variable !< The variable in question
417
418    INTEGER(iwp) ::  i        !< Running index, x-direction
419    INTEGER(iwp) ::  j        !< Running index, y-direction
420    INTEGER(iwp) ::  k        !< Running index, z-direction
421    INTEGER(iwp) ::  l        !< index used to link radiation arrays to 3d grid arrays
422
423
424    IF ( mode == 'allocate' )  THEN
425
426       SELECT CASE ( TRIM( variable ) )
427
428          CASE ( 'bio_mrt' )
429
430                IF ( .NOT. ALLOCATED( mrt_av_grid ) )  THEN
431                   ALLOCATE( mrt_av_grid(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
432                ENDIF
433                mrt_av_grid = 0.0_wp
434                do_average_mrt = .FALSE.  !< Overwrite if that was enabled somehow
435
436
437          CASE ( 'bio_perct*', 'bio_utci*', 'bio_pet*', 'bio_mrt*' )
438
439!
440!--          Averaging, as well as the allocation of the required grids must be done only once,
441!--          independent of for how many thermal indices averaged output is desired.
442!--          Therefore we need to memorize which index is the one that controls the averaging
443!--          (what must be the first thermal index called).
444!--          Indices are in unknown order as depending on the input file, determine first index to
445!--          average und update only once.
446!
447!--          Only proceed here if this was not done for any index before. This is done only once
448!--          during the whole model run.
449             IF ( .NOT. average_trigger_perct  .AND.                                               &
450                  .NOT. average_trigger_utci   .AND.                                               &
451                  .NOT. average_trigger_pet    .AND.                                               &
452                  .NOT. average_trigger_mrt )  THEN
453!
454!--             Memorize the first index called to control averaging
455                IF ( TRIM( variable ) == 'bio_perct*' )  THEN
456                    average_trigger_perct = .TRUE.
457                ENDIF
458                IF ( TRIM( variable ) == 'bio_utci*' )  THEN
459                    average_trigger_utci = .TRUE.
460                ENDIF
461                IF ( TRIM( variable ) == 'bio_pet*' )  THEN
462                    average_trigger_pet = .TRUE.
463                ENDIF
464                IF ( TRIM( variable ) == 'bio_mrt*' )  THEN
465                    average_trigger_mrt = .TRUE.
466                ENDIF
467             ENDIF
468!
469!--          Allocation of the input _av grids was moved to the "sum" section to make sure averaging
470!--          is only done once!
471
472          CASE ( 'uvem_vitd3dose*' )
473
474             IF ( .NOT. ALLOCATED( vitd3_dose ) )  THEN
475                ALLOCATE( vitd3_dose(nysg:nyng,nxlg:nxrg) )
476             ENDIF
477             vitd3_dose = 0.0_wp
478
479          CASE DEFAULT
480             CONTINUE
481
482       END SELECT
483
484    ELSEIF ( mode == 'sum' )  THEN
485
486       SELECT CASE ( TRIM( variable ) )
487
488          CASE ( 'bio_mrt' )
489!
490!--          Consider the case 'bio_mrt' is called after some thermal index. In that case
491!            do_average_mrt will be .TRUE. leading to a double-averaging.
492             IF ( .NOT. do_average_mrt  .AND.  ALLOCATED( mrt_av_grid ) )  THEN
493
494                IF ( mrt_include_sw )  THEN
495                   DO  l = 1, nmrtbl
496                      i = mrtbl(ix,l)
497                      j = mrtbl(iy,l)
498                      k = mrtbl(iz,l)
499                      mrt_av_grid(k,j,i) = mrt_av_grid(k,j,i)  +                                   &
500                                    ( ( human_absorb * mrtinsw(l) +                                &
501                                    mrtinlw(l) ) / ( human_emiss * sigma_sb ) )**0.25_wp - degc_to_k
502                   ENDDO
503                ELSE
504                   DO  l = 1, nmrtbl
505                      i = mrtbl(ix,l)
506                      j = mrtbl(iy,l)
507                      k = mrtbl(iz,l)
508                      mrt_av_grid(k,j,i) = mrt_av_grid(k,j,i)  +                                   &
509                                    ( mrtinlw(l) / ( human_emiss * sigma_sb ) )**0.25_wp - degc_to_k
510                   ENDDO
511                ENDIF
512             ENDIF
513
514          CASE ( 'bio_perct*', 'bio_utci*', 'bio_pet*', 'bio_mrt*' )
515!
516!--          Only continue if the current index is the one to trigger the input averaging, see
517!--          above.
518             IF ( average_trigger_perct  .AND.  TRIM( variable ) /= 'bio_perct*')    RETURN
519             IF ( average_trigger_utci   .AND.  TRIM( variable ) /= 'bio_utci*' )    RETURN
520             IF ( average_trigger_pet    .AND.  TRIM( variable ) /= 'bio_pet*'  )    RETURN
521             IF ( average_trigger_mrt    .AND.  TRIM( variable ) /= 'bio_mrt*'  )    RETURN
522!
523!--          Now memorize which of the input grids are not averaged by other modules. Set averaging
524!--          switch to .TRUE. and allocate the respective grid in that case.
525             IF ( .NOT. ALLOCATED( pt_av ) )  THEN  !< if not averaged by other module
526                ALLOCATE( pt_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
527                do_average_theta = .TRUE.  !< memorize, that bio is responsible
528                pt_av = 0.0_wp
529             ENDIF
530             IF ( ALLOCATED( pt_av )  .AND.  do_average_theta )  THEN
531                DO  i = nxl, nxr
532                   DO  j = nys, nyn
533                      DO  k = nzb, nzt+1
534                         pt_av(k,j,i) = pt_av(k,j,i) + pt(k,j,i)
535                      ENDDO
536                   ENDDO
537                ENDDO
538             ENDIF
539
540             IF ( .NOT. ALLOCATED( q_av ) )  THEN
541                ALLOCATE( q_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
542                do_average_q = .TRUE.
543                q_av = 0.0_wp
544             ENDIF
545             IF ( ALLOCATED( q_av )  .AND.  do_average_q )  THEN
546                DO  i = nxl, nxr
547                   DO  j = nys, nyn
548                      DO  k = nzb, nzt+1
549                         q_av(k,j,i) = q_av(k,j,i) + q(k,j,i)
550                      ENDDO
551                   ENDDO
552                ENDDO
553             ENDIF
554
555!
556!--          u_av, v_av and w_av are always allocated
557             IF ( .NOT. ALLOCATED( u_av ) )  THEN
558                ALLOCATE( u_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
559                do_average_u = .TRUE.
560                u_av = 0.0_wp
561             ENDIF
562             IF ( ALLOCATED( u_av )  .AND.  do_average_u )  THEN
563                DO  i = nxlg, nxrg       !< yes, ghost points are required here!
564                   DO  j = nysg, nyng
565                      DO  k = nzb, nzt+1
566                         u_av(k,j,i) = u_av(k,j,i) + u(k,j,i)
567                      ENDDO
568                   ENDDO
569                ENDDO
570             ENDIF
571
572             IF ( .NOT. ALLOCATED( v_av ) )  THEN
573                ALLOCATE( v_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
574                do_average_v = .TRUE.
575                v_av = 0.0_wp
576             ENDIF
577             IF ( ALLOCATED( v_av )  .AND.  do_average_v )  THEN
578                DO  i = nxlg, nxrg       !< yes, ghost points are required here!
579                   DO  j = nysg, nyng
580                      DO  k = nzb, nzt+1
581                         v_av(k,j,i) = v_av(k,j,i) + v(k,j,i)
582                      ENDDO
583                   ENDDO
584                ENDDO
585             ENDIF
586
587             IF ( .NOT. ALLOCATED( w_av ) )  THEN
588                ALLOCATE( w_av(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
589                do_average_w = .TRUE.
590                w_av = 0.0_wp
591             ENDIF
592             IF ( ALLOCATED( w_av )  .AND.  do_average_w )  THEN
593                DO  i = nxlg, nxrg       !< yes, ghost points are required here!
594                   DO  j = nysg, nyng
595                      DO  k = nzb, nzt+1
596                         w_av(k,j,i) = w_av(k,j,i) + w(k,j,i)
597                      ENDDO
598                   ENDDO
599                ENDDO
600             ENDIF
601
602             IF ( .NOT. ALLOCATED( mrt_av_grid ) )  THEN
603                ALLOCATE( mrt_av_grid(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
604                do_average_mrt = .TRUE.
605                mrt_av_grid = 0.0_wp
606             ENDIF
607             IF ( ALLOCATED( mrt_av_grid )  .AND.  do_average_mrt )  THEN
608
609                IF ( mrt_include_sw )  THEN
610                   DO  l = 1, nmrtbl
611                      i = mrtbl(ix,l)
612                      j = mrtbl(iy,l)
613                      k = mrtbl(iz,l)
614                      mrt_av_grid(k,j,i) = mrt_av_grid(k,j,i)  +                                   &
615                                    ( ( human_absorb * mrtinsw(l) +                                &
616                                    mrtinlw(l) ) /                                                 &
617                                      ( human_emiss  * sigma_sb ) )**0.25_wp - degc_to_k
618                   ENDDO
619                ELSE
620                   DO  l = 1, nmrtbl
621                      i = mrtbl(ix,l)
622                      j = mrtbl(iy,l)
623                      k = mrtbl(iz,l)
624                      mrt_av_grid(k,j,i) = mrt_av_grid(k,j,i) +                                    &
625                                    ( mrtinlw(l) /                                                 &
626                                    ( human_emiss * sigma_sb ) )**0.25_wp - degc_to_k
627                   ENDDO
628                ENDIF
629             ENDIF
630!
631!--       This is a cumulated dose. No mode == 'average' for this quantity.
632          CASE ( 'uvem_vitd3dose*' )
633             IF ( ALLOCATED( vitd3_dose ) )  THEN
634                DO  i = nxlg, nxrg
635                   DO  j = nysg, nyng
636                      vitd3_dose(j,i) = vitd3_dose(j,i) + vitd3_exposure(j,i)
637                   ENDDO
638                ENDDO
639             ENDIF
640
641          CASE DEFAULT
642             CONTINUE
643
644       END SELECT
645
646    ELSEIF ( mode == 'average' )  THEN
647
648       SELECT CASE ( TRIM( variable ) )
649
650          CASE ( 'bio_mrt' )
651!
652!--          Consider the case 'bio_mrt' is called after some thermal index. In that case
653!--          do_average_mrt will be .TRUE. leading to a double-averaging.
654             IF ( .NOT. do_average_mrt  .AND.  ALLOCATED( mrt_av_grid ) )  THEN
655                DO  i = nxl, nxr
656                   DO  j = nys, nyn
657                      DO  k = nzb, nzt+1
658                         mrt_av_grid(k,j,i) = mrt_av_grid(k,j,i) / REAL( average_count_3d, KIND=wp )
659                      ENDDO
660                   ENDDO
661                ENDDO
662             ENDIF
663
664          CASE ( 'bio_perct*', 'bio_utci*', 'bio_pet*', 'bio_mrt*' )
665!
666!--          Only continue if update index, see above
667             IF ( average_trigger_perct  .AND.                                                     &
668                TRIM( variable ) /= 'bio_perct*' )  RETURN
669             IF ( average_trigger_utci  .AND.                                                      &
670                TRIM( variable ) /= 'bio_utci*' )  RETURN
671             IF ( average_trigger_pet   .AND.                                                      &
672                TRIM( variable ) /= 'bio_pet*' )  RETURN
673             IF ( average_trigger_mrt   .AND.                                                      &
674                TRIM( variable ) /= 'bio_mrt*' )  RETURN
675
676             IF ( ALLOCATED( pt_av )  .AND.  do_average_theta )  THEN
677                DO  i = nxl, nxr
678                   DO  j = nys, nyn
679                      DO  k = nzb, nzt+1
680                         pt_av(k,j,i) = pt_av(k,j,i) /  REAL( average_count_3d, KIND = wp )
681                      ENDDO
682                   ENDDO
683                ENDDO
684             ENDIF
685
686             IF ( ALLOCATED( q_av )  .AND.  do_average_q )  THEN
687                DO  i = nxl, nxr
688                   DO  j = nys, nyn
689                      DO  k = nzb, nzt+1
690                         q_av(k,j,i) = q_av(k,j,i) / REAL( average_count_3d, KIND = wp )
691                      ENDDO
692                   ENDDO
693                ENDDO
694             ENDIF
695
696             IF ( ALLOCATED( u_av )  .AND.  do_average_u )  THEN
697                DO  i = nxlg, nxrg       !< yes, ghost points are required here!
698                   DO  j = nysg, nyng
699                      DO  k = nzb, nzt+1
700                         u_av(k,j,i) = u_av(k,j,i) / REAL( average_count_3d, KIND = wp )
701                      ENDDO
702                   ENDDO
703                ENDDO
704             ENDIF
705
706             IF ( ALLOCATED( v_av )  .AND.  do_average_v )  THEN
707                DO  i = nxlg, nxrg
708                   DO  j = nysg, nyng
709                      DO  k = nzb, nzt+1
710                         v_av(k,j,i) = v_av(k,j,i) / REAL( average_count_3d, KIND = wp )
711                      ENDDO
712                   ENDDO
713                ENDDO
714             ENDIF
715
716             IF ( ALLOCATED( w_av )  .AND.  do_average_w )  THEN
717                DO  i = nxlg, nxrg
718                   DO  j = nysg, nyng
719                      DO  k = nzb, nzt+1
720                         w_av(k,j,i) = w_av(k,j,i) / REAL( average_count_3d, KIND = wp )
721                      ENDDO
722                   ENDDO
723                ENDDO
724             ENDIF
725
726             IF ( ALLOCATED( mrt_av_grid )  .AND.  do_average_mrt )  THEN
727                DO  i = nxl, nxr
728                   DO  j = nys, nyn
729                      DO  k = nzb, nzt+1
730                         mrt_av_grid(k,j,i) = mrt_av_grid(k,j,i) / REAL( average_count_3d, KIND=wp )
731                      ENDDO
732                   ENDDO
733                ENDDO
734             ENDIF
735
736!
737!--     No averaging for UVEM SINce we are calculating a dose (only sum is calculated and saved to
738!--     av.nc file)
739        END SELECT
740
741    ENDIF
742
743
744 END SUBROUTINE bio_3d_data_averaging
745
746
747
748!--------------------------------------------------------------------------------------------------!
749! Description:
750! ------------
751!> Check data output for biometeorology model
752!--------------------------------------------------------------------------------------------------!
753 SUBROUTINE bio_check_data_output( var, unit, i, j, ilen, k )
754
755    USE control_parameters,                                                                        &
756        ONLY: data_output, message_string
757
758    IMPLICIT NONE
759
760    CHARACTER (LEN=*) ::  unit     !< The unit for the variable var
761    CHARACTER (LEN=*) ::  var      !< The variable in question
762
763    INTEGER(iwp), INTENT(IN) ::  i     !< Current element of data_output
764    INTEGER(iwp), INTENT(IN) ::  j     !< Average quantity? 0 = no, 1 = yes
765    INTEGER(iwp), INTENT(IN) ::  ilen  !< Length of current entry in data_output
766    INTEGER(iwp), INTENT(IN) ::  k     !< Output is xy mode? 0 = no, 1 = yes
767
768    SELECT CASE ( TRIM( var ) )
769!
770!--    Allocate a temporary array with the desired output dimensions.
771!--    Arrays for time-averaged thermal indices are also allocated here because they are not running
772!--    through the standard averaging procedure in bio_3d_data_averaging as the values of the
773!--    averaged thermal indices are derived in a SINgle step based on priorly averaged arrays (see
774!--    bio_calculate_thermal_index_maps).
775       CASE ( 'bio_mrt', 'bio_mrt*' )
776          unit = 'degree_C'
777          thermal_comfort = .TRUE.  !< enable thermal_comfort if user forgot to do so
778          IF ( .NOT. ALLOCATED( tmrt_grid ) )  THEN
779             ALLOCATE( tmrt_grid (nys:nyn,nxl:nxr) )
780             tmrt_grid = REAL( bio_fill_value, KIND = wp )
781          ENDIF
782          IF ( TRIM( var ) == 'bio_mrt*' )  THEN
783             do_calculate_mrt2d = .TRUE.
784          END IF
785
786       CASE ( 'bio_perct*' )
787          unit = 'degree_C'
788          thermal_comfort = .TRUE.
789          IF ( j == 0 )  THEN                !< if instantaneous input
790             do_calculate_perct = .TRUE.
791             IF ( .NOT. ALLOCATED( perct ) )  THEN
792                ALLOCATE( perct (nys:nyn,nxl:nxr) )
793                perct = REAL( bio_fill_value, KIND = wp )
794             ENDIF
795          ELSE                               !< if averaged input
796             do_calculate_perct_av = .TRUE.
797             IF ( .NOT. ALLOCATED( perct_av ) )  THEN
798                ALLOCATE( perct_av (nys:nyn,nxl:nxr) )
799                perct_av = REAL( bio_fill_value, KIND = wp )
800             ENDIF
801          ENDIF
802
803       CASE ( 'bio_utci*' )
804          unit = 'degree_C'
805          thermal_comfort = .TRUE.
806          IF ( j == 0 )  THEN
807             do_calculate_utci = .TRUE.
808             IF ( .NOT. ALLOCATED( utci ) )  THEN
809                ALLOCATE( utci (nys:nyn,nxl:nxr) )
810                utci = REAL( bio_fill_value, KIND = wp )
811             ENDIF
812          ELSE
813             do_calculate_utci_av = .TRUE.
814             IF ( .NOT. ALLOCATED( utci_av ) )  THEN
815                ALLOCATE( utci_av (nys:nyn,nxl:nxr) )
816                utci_av = REAL( bio_fill_value, KIND = wp )
817             ENDIF
818          ENDIF
819
820       CASE ( 'bio_pet*' )
821          unit = 'degree_C'
822          thermal_comfort = .TRUE.
823          IF ( j == 0 )  THEN
824             do_calculate_pet = .TRUE.
825             IF ( .NOT. ALLOCATED( pet ) )  THEN
826                ALLOCATE( pet (nys:nyn,nxl:nxr) )
827                pet = REAL( bio_fill_value, KIND = wp )
828             ENDIF
829          ELSE
830             do_calculate_pet_av = .TRUE.
831             IF ( .NOT. ALLOCATED( pet_av ) )  THEN
832                ALLOCATE( pet_av (nys:nyn,nxl:nxr) )
833                pet_av = REAL( bio_fill_value, KIND = wp )
834             ENDIF
835          ENDIF
836
837
838       CASE ( 'uvem_vitd3*' )
839!           IF ( .NOT. uv_exposure )  THEN
840!              message_string = 'output of "' // TRIM( var ) // '" requi' //                       &
841!                       'res a namelist &uvexposure_par'
842!              CALL message( 'uvem_check_data_output', 'UV0001', 1, 2, 0, 6, 0 )
843!           ENDIF
844          IF ( k == 0  .OR.  data_output(i)(ilen-2:ilen) /= '_xy' )  THEN
845             message_string = 'illegal value for data_output: "' //                                &
846                              TRIM( var ) // '" & only 2d-horizontal ' //                          &
847                              'cross sections are allowed for this value'
848             CALL message( 'check_parameters', 'PA0111', 1, 2, 0, 6, 0 )
849          ENDIF
850          unit = 'IU/s'
851          IF ( .NOT. ALLOCATED( vitd3_exposure ) )  THEN
852             ALLOCATE( vitd3_exposure(nysg:nyng,nxlg:nxrg) )
853          ENDIF
854          vitd3_exposure = 0.0_wp
855
856       CASE ( 'uvem_vitd3dose*' )
857!           IF (  .NOT.  uv_exposure )  THEN
858!              message_string = 'output of "' // TRIM( var ) // '" requi' //     &
859!                       'res  a namelist &uvexposure_par'
860!              CALL message( 'uvem_check_data_output', 'UV0001', 1, 2, 0, 6, 0 )
861!           ENDIF
862          IF ( k == 0  .OR.  data_output(i)(ilen-2:ilen) /= '_xy' )  THEN
863             message_string = 'illegal value for data_output: "' //                                &
864                              TRIM( var ) // '" & only 2d-horizontal ' //                          &
865                              'cross sections are allowed for this value'
866             CALL message( 'check_parameters', 'PA0111', 1, 2, 0, 6, 0 )
867          ENDIF
868          unit = 'IU/av-h'
869          IF ( .NOT. ALLOCATED( vitd3_dose ) )  THEN
870             ALLOCATE( vitd3_dose(nysg:nyng,nxlg:nxrg) )
871          ENDIF
872          vitd3_dose = 0.0_wp
873
874       CASE DEFAULT
875          unit = 'illegal'
876
877    END SELECT
878
879!
880!-- Further checks if thermal comfort output is desired.
881    IF ( thermal_comfort  .AND.  unit == 'degree_C' )  THEN
882!
883!--    Break if required modules "radiation" is not available.
884       IF ( .NOT.  radiation )  THEN
885          message_string = 'output of "' // TRIM( var ) // '" require' // 's radiation = .TRUE.'
886          CALL message( 'check_parameters', 'PA0509', 1, 2, 0, 6, 0 )
887          unit = 'illegal'
888       ENDIF
889!
890!--    All "thermal_comfort" outputs except from 'bio_mrt' will also need  humidity input. Check
891!--    also for that.
892       IF ( TRIM( var ) /= 'bio_mrt' )  THEN
893          IF ( .NOT.  humidity )  THEN
894             message_string = 'The estimation of thermal comfort '    //                           &
895                              'requires air humidity information, but ' //                         &
896                              'humidity module is disabled!'
897             CALL message( 'check_parameters', 'PA0561', 1, 2, 0, 6, 0 )
898             unit = 'illegal'
899          ENDIF
900       ENDIF
901
902
903    ENDIF
904
905 END SUBROUTINE bio_check_data_output
906
907!--------------------------------------------------------------------------------------------------!
908! Description:
909! ------------
910!> Check parameters routine for biom module
911!> Currently unused but might come in handy for future checks?
912!--------------------------------------------------------------------------------------------------!
913 SUBROUTINE bio_check_parameters
914
915
916    IMPLICIT NONE
917
918
919 END SUBROUTINE bio_check_parameters
920
921
922!--------------------------------------------------------------------------------------------------!
923! Description:
924! ------------
925!> Subroutine defining 2D output variables
926!> data_output_2d 1188ff
927!--------------------------------------------------------------------------------------------------!
928 SUBROUTINE bio_data_output_2d( av, variable, found, grid, local_pf, two_d, nzb_do, nzt_do)
929
930
931    USE kinds
932
933
934    IMPLICIT NONE
935!
936!-- Input variables
937    CHARACTER (LEN=*), INTENT(IN) ::  variable    !< Char identifier to select var for output
938    INTEGER(iwp), INTENT(IN)      ::  av          !< Use averaged data? 0 = no, 1 = yes?
939    INTEGER(iwp), INTENT(IN)      ::  nzb_do      !< Unused. 2D. nz bottom to nz top
940    INTEGER(iwp), INTENT(IN)      ::  nzt_do      !< Unused.
941!
942!-- Output variables
943    CHARACTER (LEN=*), INTENT(OUT) ::  grid   !< Grid type (always "zu1" for biom)
944
945    LOGICAL, INTENT(OUT)           ::  found  !< Output found?
946    LOGICAL, INTENT(OUT)           ::  two_d  !< Flag parameter that indicates 2D variables,
947                                              !< horizontal cross sections, must be .TRUE. for thermal indices and uv
948    REAL(wp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do) ::  local_pf  !< Temp. result grid to return
949!
950!-- Internal variables
951    INTEGER(iwp) ::  i        !< Running index, x-dir
952    INTEGER(iwp) ::  j        !< Running index, y-dir
953    INTEGER(iwp) ::  k        !< Running index, z-dir
954    INTEGER(iwp) ::  l        !< Running index, radiation grid
955
956
957    found = .TRUE.
958    local_pf = bio_fill_value
959
960    SELECT CASE ( TRIM( variable ) )
961
962
963        CASE ( 'bio_mrt_xy' )
964           grid = 'zu1'
965           two_d = .FALSE.  !< can be calculated for several levels
966           local_pf = REAL( bio_fill_value, KIND = wp )
967           DO  l = 1, nmrtbl
968              i = mrtbl(ix,l)
969              j = mrtbl(iy,l)
970              k = mrtbl(iz,l)
971              IF ( k < nzb_do  .OR.  k > nzt_do  .OR.  j < nys  .OR.                               &
972                 j > nyn  .OR.  i < nxl  .OR.  i > nxr )  CYCLE
973              IF ( av == 0 )  THEN
974                 IF ( mrt_include_sw )  THEN
975                    local_pf(i,j,k) = ( ( human_absorb * mrtinsw(l) +                              &
976                                      mrtinlw(l) ) /                                               &
977                                      ( human_emiss * sigma_sb ) )**0.25_wp - degc_to_k
978                 ELSE
979                    local_pf(i,j,k) = ( mrtinlw(l) /                                               &
980                                      ( human_emiss * sigma_sb ) )**0.25_wp - degc_to_k
981                 ENDIF
982              ELSE
983                 local_pf(i,j,k) = mrt_av_grid(k,j,i)
984              ENDIF
985           ENDDO
986
987        CASE ( 'bio_mrt*_xy' )        ! 2d-array
988           grid = 'zu1'
989           two_d = .TRUE.
990           IF ( av == 0 )  THEN
991              DO  i = nxl, nxr
992                 DO  j = nys, nyn
993                    local_pf(i,j,nzb+1) = tmrt_grid(j,i)
994                 ENDDO
995              ENDDO
996           ELSE
997              DO  i = nxl, nxr
998                 DO  j = nys, nyn
999                    local_pf(i,j,nzb+1) = tmrt_av_grid(j,i)
1000                 ENDDO
1001              ENDDO
1002           ENDIF
1003
1004
1005        CASE ( 'bio_perct*_xy' )        ! 2d-array
1006           grid = 'zu1'
1007           two_d = .TRUE.
1008           IF ( av == 0 )  THEN
1009              DO  i = nxl, nxr
1010                 DO  j = nys, nyn
1011                    local_pf(i,j,nzb+1) = perct(j,i)
1012                 ENDDO
1013              ENDDO
1014           ELSE
1015              DO  i = nxl, nxr
1016                 DO  j = nys, nyn
1017                    local_pf(i,j,nzb+1) = perct_av(j,i)
1018                 ENDDO
1019              ENDDO
1020           ENDIF
1021
1022
1023        CASE ( 'bio_utci*_xy' )        ! 2d-array
1024           grid = 'zu1'
1025           two_d = .TRUE.
1026           IF ( av == 0 )  THEN
1027              DO  i = nxl, nxr
1028                 DO  j = nys, nyn
1029                    local_pf(i,j,nzb+1) = utci(j,i)
1030                 ENDDO
1031              ENDDO
1032           ELSE
1033              DO  i = nxl, nxr
1034                 DO  j = nys, nyn
1035                    local_pf(i,j,nzb+1) = utci_av(j,i)
1036                 ENDDO
1037              ENDDO
1038           ENDIF
1039
1040
1041        CASE ( 'bio_pet*_xy' )        ! 2d-array
1042           grid = 'zu1'
1043           two_d = .TRUE.
1044           IF ( av == 0 )  THEN
1045              DO  i = nxl, nxr
1046                 DO  j = nys, nyn
1047                    local_pf(i,j,nzb+1) = pet(j,i)
1048                 ENDDO
1049              ENDDO
1050           ELSE
1051              DO  i = nxl, nxr
1052                 DO  j = nys, nyn
1053                    local_pf(i,j,nzb+1) = pet_av(j,i)
1054                 ENDDO
1055              ENDDO
1056           ENDIF
1057
1058!
1059!--    Before data is transfered to local_pf, transfer is in 2D dummy variable and exchange ghost
1060!--    points therein. However, at this point this is only required for instantaneous arrays,
1061!--    time-averaged quantities are already exchanged.
1062       CASE ( 'uvem_vitd3*_xy' )        ! 2d-array
1063          IF ( av == 0 )  THEN
1064             DO  i = nxl, nxr
1065                DO  j = nys, nyn
1066                   local_pf(i,j,nzb+1) = vitd3_exposure(j,i)
1067                ENDDO
1068             ENDDO
1069          ENDIF
1070
1071          two_d = .TRUE.
1072          grid = 'zu1'
1073
1074       CASE ( 'uvem_vitd3dose*_xy' )        ! 2d-array
1075          IF ( av == 1 )  THEN
1076             DO  i = nxl, nxr
1077                DO  j = nys, nyn
1078                   local_pf(i,j,nzb+1) = vitd3_dose(j,i)
1079                ENDDO
1080             ENDDO
1081          ENDIF
1082
1083          two_d = .TRUE.
1084          grid = 'zu1'
1085
1086
1087       CASE DEFAULT
1088          found = .FALSE.
1089          grid  = 'none'
1090
1091    END SELECT
1092
1093
1094 END SUBROUTINE bio_data_output_2d
1095
1096
1097!--------------------------------------------------------------------------------------------------!
1098! Description:
1099! ------------
1100!> Subroutine defining 3D output variables (dummy, always 2d!)
1101!> data_output_3d 709ff
1102!--------------------------------------------------------------------------------------------------!
1103 SUBROUTINE bio_data_output_3d( av, variable, found, local_pf, nzb_do, nzt_do )
1104
1105    USE indices
1106
1107    USE kinds
1108
1109
1110    IMPLICIT NONE
1111!
1112!-- Input variables
1113    CHARACTER (LEN=*), INTENT(IN) ::  variable   !< Char identifier to select var for output
1114
1115    INTEGER(iwp), INTENT(IN) ::  av       !< Use averaged data? 0 = no, 1 = yes?
1116    INTEGER(iwp), INTENT(IN) ::  nzb_do   !< Unused. 2D. nz bottom to nz top
1117    INTEGER(iwp), INTENT(IN) ::  nzt_do   !< Unused.
1118!
1119!-- Output variables
1120    LOGICAL, INTENT(OUT) ::  found   !< Output found?
1121
1122    REAL(sp), DIMENSION(nxl:nxr,nys:nyn,nzb_do:nzt_do) ::  local_pf   !< Temp. result grid to return
1123!
1124!-- Internal variables
1125    INTEGER(iwp) ::  l    !< Running index, radiation grid
1126    INTEGER(iwp) ::  i    !< Running index, x-dir
1127    INTEGER(iwp) ::  j    !< Running index, y-dir
1128    INTEGER(iwp) ::  k    !< Running index, z-dir
1129
1130!    REAL(wp) ::  mrt  !< Buffer for mean radiant temperature
1131
1132    found = .TRUE.
1133
1134    SELECT CASE ( TRIM( variable ) )
1135
1136        CASE ( 'bio_mrt' )
1137            local_pf = REAL( bio_fill_value, KIND = sp )
1138            DO  l = 1, nmrtbl
1139               i = mrtbl(ix,l)
1140               j = mrtbl(iy,l)
1141               k = mrtbl(iz,l)
1142               IF ( k < nzb_do  .OR.  k > nzt_do  .OR.  j < nys  .OR.                              &
1143                  j > nyn  .OR.  i < nxl  .OR.  i > nxr )  CYCLE
1144               IF ( av == 0 )  THEN
1145                  IF ( mrt_include_sw )  THEN
1146                     local_pf(i,j,k) = REAL( ( ( human_absorb * mrtinsw(l) +                       &
1147                                       mrtinlw(l) ) /                                              &
1148                                       ( human_emiss * sigma_sb ) )**0.25_wp - degc_to_k,          &
1149                                         KIND = sp )
1150                  ELSE
1151                     local_pf(i,j,k) = REAL( ( mrtinlw(l) /                                        &
1152                                       ( human_emiss * sigma_sb ) )**0.25_wp - degc_to_k,          &
1153                                         KIND = sp )
1154                  ENDIF
1155               ELSE
1156                  local_pf(i,j,k) = REAL( mrt_av_grid(k,j,i), KIND = sp )
1157               ENDIF
1158            ENDDO
1159
1160       CASE DEFAULT
1161          found = .FALSE.
1162
1163    END SELECT
1164
1165 END SUBROUTINE bio_data_output_3d
1166
1167!--------------------------------------------------------------------------------------------------!
1168! Description:
1169! ------------
1170!> Subroutine defining appropriate grid for netcdf variables.
1171!> It is called out from subroutine netcdf_interface_mod.
1172!> netcdf_interface_mod 918ff
1173!--------------------------------------------------------------------------------------------------!
1174 SUBROUTINE bio_define_netcdf_grid( var, found, grid_x, grid_y, grid_z )
1175
1176    IMPLICIT NONE
1177!
1178!-- Input variables
1179    CHARACTER (LEN=*), INTENT(IN)  ::  var      !< Name of output variable
1180!
1181!-- Output variables
1182    CHARACTER (LEN=*), INTENT(OUT) ::  grid_x   !< x grid of output variable
1183    CHARACTER (LEN=*), INTENT(OUT) ::  grid_y   !< y grid of output variable
1184    CHARACTER (LEN=*), INTENT(OUT) ::  grid_z   !< z grid of output variable
1185
1186    LOGICAL, INTENT(OUT)           ::  found    !< Flag if output var is found
1187!
1188!-- Local variables
1189    INTEGER(iwp) :: l     !< Length of the var array
1190
1191    LOGICAL      :: is2d  !< Var is 2d?
1192
1193    found  = .FALSE.
1194    grid_x = 'none'
1195    grid_y = 'none'
1196    grid_z = 'none'
1197
1198    l = MAX( 2, LEN_TRIM( var ) )
1199    is2d = ( var(l-1:l) == 'xy' )
1200
1201    IF ( var(1:4) == 'bio_' )  THEN
1202       found  = .TRUE.
1203       grid_x = 'x'
1204       grid_y = 'y'
1205       grid_z = 'zu'
1206       IF ( is2d  .AND.  var(1:7) /= 'bio_mrt' )  grid_z = 'zu1'
1207    ENDIF
1208
1209    IF ( is2d  .AND.  var(1:4) == 'uvem' )  THEN
1210       grid_x = 'x'
1211       grid_y = 'y'
1212       grid_z = 'zu1'
1213    ENDIF
1214
1215 END SUBROUTINE bio_define_netcdf_grid
1216
1217!--------------------------------------------------------------------------------------------------!
1218! Description:
1219! ------------
1220!> Header output for biom module
1221!> header 982
1222!--------------------------------------------------------------------------------------------------!
1223 SUBROUTINE bio_header( io )
1224
1225    IMPLICIT NONE
1226!
1227!-- Input variables
1228    INTEGER(iwp), INTENT(IN) ::  io           !< Unit of the output file
1229!
1230!-- Internal variables
1231    CHARACTER (LEN=86) ::  output_height_chr  !< String for output height
1232
1233    WRITE( output_height_chr, '(F8.1,7X)' )  bio_output_height
1234!
1235!-- Write biom header
1236    WRITE( io, 1 )
1237    WRITE( io, 2 )  TRIM( output_height_chr )
1238    WRITE( io, 3 )  TRIM( ACHAR( bio_cell_level ) )
1239
12401   FORMAT (//' Human thermal comfort module information:'/                                        &
1241              ' ------------------------------'/)
12422   FORMAT ('    --> All indices calculated for a height of (m): ', A )
12433   FORMAT ('    --> This corresponds to cell level : ', A )
1244
1245 END SUBROUTINE bio_header
1246
1247
1248!--------------------------------------------------------------------------------------------------!
1249! Description:
1250! ------------
1251!> Initialization of the HTCM
1252!> init_3d_model 1987ff
1253!--------------------------------------------------------------------------------------------------!
1254 SUBROUTINE bio_init
1255
1256    USE netcdf_data_input_mod,                                                                     &
1257        ONLY:  netcdf_data_input_uvem
1258
1259    IMPLICIT NONE
1260!
1261!-- Internal vriables
1262    REAL ( wp )  :: height  !< current height in meters
1263
1264    IF ( debug_output )  CALL debug_message( 'bio_init', 'start' )
1265!
1266!-- Determine cell level corresponding to 1.1 m above ground level (gravimetric center of sample
1267!-- human)
1268
1269    bio_cell_level = 0_iwp
1270    bio_output_height = 0.5_wp * dz(1)
1271    height = 0.0_wp
1272
1273    bio_cell_level = INT( 1.099_wp / dz(1) )
1274    bio_output_height = bio_output_height + bio_cell_level * dz(1)
1275!
1276!-- Set radiation level if not done by user
1277    IF ( mrt_nlevels == 0 )  THEN
1278       mrt_nlevels = bio_cell_level + 1_iwp
1279    ENDIF
1280!
1281!-- Init UVEM and load lookup tables
1282    IF ( uv_exposure )  CALL netcdf_data_input_uvem
1283
1284    IF ( debug_output )  CALL debug_message( 'bio_init', 'end' )
1285
1286 END SUBROUTINE bio_init
1287
1288
1289!--------------------------------------------------------------------------------------------------!
1290! Description:
1291! ------------
1292!> Checks done after the Initialization
1293!--------------------------------------------------------------------------------------------------!
1294 SUBROUTINE bio_init_checks
1295
1296    USE control_parameters,                                                                        &
1297        ONLY: message_string
1298
1299    IF ( (.NOT. radiation_interactions) .AND. ( thermal_comfort ) )  THEN
1300       message_string = 'The mrt calculation requires ' //                                         &
1301                        'enabled radiation_interactions but it ' //                                &
1302                        'is disabled!'
1303       CALL message( 'bio_init_checks', 'PAHU03', 1, 2, 0, 6, 0 )
1304    ENDIF
1305
1306
1307 END SUBROUTINE bio_init_checks
1308
1309
1310!--------------------------------------------------------------------------------------------------!
1311! Description:
1312! ------------
1313!> Parin for &biometeorology_parameters for reading biomet parameters
1314!--------------------------------------------------------------------------------------------------!
1315 SUBROUTINE bio_parin
1316
1317    IMPLICIT NONE
1318
1319!
1320!-- Internal variables
1321    CHARACTER (LEN=80) ::  line  !< Dummy string for current line in parameter file
1322
1323    NAMELIST /biometeorology_parameters/  clothing,                                                &
1324                                          consider_obstructions,                                   &
1325                                          orientation_angle,                                       &
1326                                          sun_in_south,                                            &
1327                                          thermal_comfort,                                         &
1328                                          turn_to_sun,                                             &
1329                                          uv_exposure
1330
1331
1332!-- Try to find biometeorology_parameters namelist
1333    REWIND ( 11 )
1334    line = ' '
1335    DO WHILE ( INDEX( line, '&biometeorology_parameters' ) == 0 )
1336       READ ( 11, '(A)', END = 20 )  line
1337    ENDDO
1338    BACKSPACE ( 11 )
1339
1340!
1341!-- Read biometeorology_parameters namelist
1342    READ ( 11, biometeorology_parameters, ERR = 10, END = 20 )
1343
1344!
1345!-- Set flag that indicates that the biomet_module is switched on
1346    biometeorology = .TRUE.
1347
1348    GOTO 20
1349
1350!
1351!-- In case of error
1352 10 BACKSPACE( 11 )
1353    READ( 11 , '(A)') line
1354    CALL parin_fail_message( 'biometeorology_parameters', line )
1355
1356!
1357!-- Complete
1358 20 CONTINUE
1359
1360
1361 END SUBROUTINE bio_parin
1362
1363!--------------------------------------------------------------------------------------------------!
1364! Description:
1365! ------------
1366!> Read module-specific global restart data (Fortran binary format).
1367!--------------------------------------------------------------------------------------------------!
1368 SUBROUTINE bio_rrd_global_ftn( found )
1369
1370    USE control_parameters,                                                                        &
1371        ONLY:  length, restart_string
1372
1373
1374    IMPLICIT NONE
1375
1376    LOGICAL, INTENT(OUT) ::  found      !< variable found? yes = .T., no = .F.
1377
1378    found = .TRUE.
1379
1380
1381    SELECT CASE ( restart_string(1:length) )
1382
1383!
1384!--    Read control flags to determine if input grids need to be averaged.
1385       CASE ( 'do_average_theta' )
1386          READ ( 13 )  do_average_theta
1387
1388       CASE ( 'do_average_q' )
1389          READ ( 13 )  do_average_q
1390
1391       CASE ( 'do_average_u' )
1392          READ ( 13 )  do_average_u
1393
1394       CASE ( 'do_average_v' )
1395          READ ( 13 )  do_average_v
1396
1397       CASE ( 'do_average_w' )
1398          READ ( 13 )  do_average_w
1399
1400       CASE ( 'do_average_mrt' )
1401          READ ( 13 )  do_average_mrt
1402
1403!
1404!--    Read control flags to determine which thermal index needs to trigger averaging.
1405       CASE ( 'average_trigger_perct' )
1406          READ ( 13 )  average_trigger_perct
1407
1408       CASE ( 'average_trigger_utci' )
1409          READ ( 13 )  average_trigger_utci
1410
1411       CASE ( 'average_trigger_pet' )
1412          READ ( 13 )  average_trigger_pet
1413
1414       CASE ( 'average_trigger_mrt' )
1415          READ ( 13 )  average_trigger_mrt
1416
1417
1418       CASE DEFAULT
1419
1420          found = .FALSE.
1421
1422    END SELECT
1423
1424
1425 END SUBROUTINE bio_rrd_global_ftn
1426
1427
1428!--------------------------------------------------------------------------------------------------!
1429! Description:
1430! ------------
1431!> Read module-specific global restart data (MPI-IO).
1432!--------------------------------------------------------------------------------------------------!
1433 SUBROUTINE bio_rrd_global_mpi
1434
1435
1436!
1437!--  Read control flags to determine if input grids need to be averaged
1438     CALL rrd_mpi_io( 'do_average_theta', do_average_theta )
1439     CALL rrd_mpi_io( 'do_average_q', do_average_q )
1440     CALL rrd_mpi_io( 'do_average_u', do_average_u )
1441     CALL rrd_mpi_io( 'do_average_v', do_average_v )
1442     CALL rrd_mpi_io( 'do_average_w', do_average_w )
1443     CALL rrd_mpi_io( 'do_average_mrt', do_average_mrt )
1444!
1445!--  Rad control flags to determine which thermal index needs to trigger averaging
1446     CALL rrd_mpi_io( 'average_trigger_perct', average_trigger_perct )
1447     CALL rrd_mpi_io( 'average_trigger_utci', average_trigger_utci )
1448     CALL rrd_mpi_io( 'average_trigger_pet', average_trigger_pet )
1449     CALL rrd_mpi_io( 'average_trigger_mrt', average_trigger_mrt )
1450
1451 END SUBROUTINE bio_rrd_global_mpi
1452
1453
1454!--------------------------------------------------------------------------------------------------!
1455! Description:
1456! ------------
1457!> Read module-specific local restart data arrays (Fortran binary format).
1458!--------------------------------------------------------------------------------------------------!
1459 SUBROUTINE bio_rrd_local_ftn( found )
1460
1461
1462    USE control_parameters,                                                                        &
1463        ONLY:  length, restart_string
1464
1465
1466    IMPLICIT NONE
1467
1468
1469    LOGICAL, INTENT(OUT) ::  found      !< variable found? yes = .TRUE., no = .FALSE.
1470
1471    found = .TRUE.
1472
1473
1474    SELECT CASE ( restart_string(1:length) )
1475
1476       CASE ( 'mrt_av_grid' )
1477          IF ( .NOT. ALLOCATED( mrt_av_grid ) )  THEN
1478             ALLOCATE( mrt_av_grid(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
1479             mrt_av_grid = 0.0_wp
1480          ENDIF
1481          READ ( 13 )  mrt_av_grid
1482
1483       CASE DEFAULT
1484
1485          found = .FALSE.
1486
1487    END SELECT
1488
1489
1490 END SUBROUTINE bio_rrd_local_ftn
1491
1492
1493!------------------------------------------------------------------------------!
1494! Description:
1495! ------------
1496!> Read module-specific local restart data arrays (Fortran binary format).
1497!------------------------------------------------------------------------------!
1498 SUBROUTINE bio_rrd_local_mpi
1499
1500    USE control_parameters
1501
1502    USE indices
1503
1504    USE kinds
1505
1506
1507    IMPLICIT NONE
1508
1509    LOGICAL      ::  array_found  !<
1510
1511    CALL rd_mpi_io_check_array( 'mrt_av_grid' , found = array_found )
1512    IF ( array_found )  THEN
1513       IF ( .NOT. ALLOCATED( mrt_av_grid ) )  ALLOCATE( mrt_av_grid(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
1514       CALL rrd_mpi_io( 'mrt_av_grid', mrt_av_grid )
1515    ENDIF
1516
1517 END SUBROUTINE bio_rrd_local_mpi
1518
1519
1520!--------------------------------------------------------------------------------------------------!
1521! Description:
1522! ------------
1523!> Write global restart data for the biometeorology module.
1524!--------------------------------------------------------------------------------------------------!
1525 SUBROUTINE bio_wrd_global
1526
1527    IF ( TRIM( restart_data_format_output ) == 'fortran_binary' )  THEN
1528
1529       CALL wrd_write_string( 'do_average_theta' )
1530       WRITE ( 14 )  do_average_theta
1531       CALL wrd_write_string( 'do_average_q' )
1532       WRITE ( 14 )  do_average_q
1533       CALL wrd_write_string( 'do_average_u' )
1534       WRITE ( 14 )  do_average_u
1535       CALL wrd_write_string( 'do_average_v' )
1536       WRITE ( 14 )  do_average_v
1537       CALL wrd_write_string( 'do_average_w' )
1538       WRITE ( 14 )  do_average_w
1539       CALL wrd_write_string( 'do_average_mrt' )
1540       WRITE ( 14 )  do_average_mrt
1541       CALL wrd_write_string( 'average_trigger_perct' )
1542       WRITE ( 14 )  average_trigger_perct
1543       CALL wrd_write_string( 'average_trigger_utci' )
1544       WRITE ( 14 )  average_trigger_utci
1545       CALL wrd_write_string( 'average_trigger_pet' )
1546       WRITE ( 14 )  average_trigger_pet
1547       CALL wrd_write_string( 'average_trigger_mrt' )
1548       WRITE ( 14 )  average_trigger_mrt
1549
1550    ELSEIF ( TRIM( restart_data_format_output(1:3) ) == 'mpi' )  THEN
1551
1552       CALL wrd_mpi_io( 'do_average_theta', do_average_theta )
1553       CALL wrd_mpi_io( 'do_average_q', do_average_q )
1554       CALL wrd_mpi_io( 'do_average_u', do_average_u )
1555       CALL wrd_mpi_io( 'do_average_v', do_average_v )
1556       CALL wrd_mpi_io( 'do_average_w', do_average_w )
1557       CALL wrd_mpi_io( 'do_average_mrt', do_average_mrt )
1558       CALL wrd_mpi_io( 'average_trigger_perct', average_trigger_perct )
1559       CALL wrd_mpi_io( 'average_trigger_utci', average_trigger_utci )
1560       CALL wrd_mpi_io( 'average_trigger_pet', average_trigger_pet )
1561       CALL wrd_mpi_io( 'average_trigger_mrt', average_trigger_mrt )
1562
1563    ENDIF
1564
1565 END SUBROUTINE bio_wrd_global
1566
1567
1568!--------------------------------------------------------------------------------------------------!
1569! Description:
1570! ------------
1571!> Write local restart data for the biometeorology module.
1572!--------------------------------------------------------------------------------------------------!
1573 SUBROUTINE bio_wrd_local
1574
1575    IF ( TRIM( restart_data_format_output ) == 'fortran_binary' )  THEN
1576
1577       IF ( ALLOCATED( mrt_av_grid ) )  THEN
1578          CALL wrd_write_string( 'mrt_av_grid' )
1579          WRITE ( 14 )  mrt_av_grid
1580       ENDIF
1581
1582    ELSEIF ( TRIM( restart_data_format_output(1:3) ) == 'mpi' )  THEN
1583
1584       IF ( ALLOCATED( mrt_av_grid ) )  CALL wrd_mpi_io( 'mrt_av_grid', mrt_av_grid )
1585
1586    ENDIF
1587
1588 END SUBROUTINE bio_wrd_local
1589
1590!--------------------------------------------------------------------------------------------------!
1591! Description:
1592! ------------
1593!> Calculate biometeorology MRT for all 2D grid
1594!--------------------------------------------------------------------------------------------------!
1595 SUBROUTINE bio_calculate_mrt_grid ( av )
1596
1597    IMPLICIT NONE
1598
1599    LOGICAL, INTENT(IN)         ::  av    !< use averaged input?
1600!
1601!-- Internal variables
1602    INTEGER(iwp)                ::  i     !< Running index, x-dir, radiation coordinates
1603    INTEGER(iwp)                ::  j     !< Running index, y-dir, radiation coordinates
1604    INTEGER(iwp)                ::  k     !< Running index, y-dir, radiation coordinates
1605    INTEGER(iwp)                ::  l     !< Running index, radiation coordinates
1606
1607
1608!
1609!-- We need to differentiate if averaged input is desired (av == .TRUE.) or not.
1610    IF ( av )  THEN
1611!
1612!--    Make sure tmrt_av_grid is present and initialize with the fill value
1613       IF ( .NOT. ALLOCATED( tmrt_av_grid ) )  THEN
1614          ALLOCATE( tmrt_av_grid(nys:nyn,nxl:nxr) )
1615       ENDIF
1616       tmrt_av_grid = REAL( bio_fill_value, KIND = wp )
1617
1618!
1619!--    mrt_av_grid should always be allcoated here, but better make sure ist actually is.
1620       IF ( ALLOCATED( mrt_av_grid ) )  THEN
1621!
1622!--       Iterate over the radiation grid (radiation coordinates) and fill the tmrt_av_grid
1623!--       (x, y coordinates) where appropriate: tmrt_av_grid is written for all i / j if level (k)
1624!--       matches output height.
1625          DO  l = 1, nmrtbl
1626             i = mrtbl(ix,l)
1627             j = mrtbl(iy,l)
1628             k = mrtbl(iz,l)
1629             IF ( k - topo_top_ind(j,i,0) == bio_cell_level + 1_iwp)  THEN
1630!
1631!--             Averaging was done before, so we can just copy the result here.
1632                tmrt_av_grid(j,i) = mrt_av_grid(k,j,i)
1633
1634             ENDIF
1635          ENDDO
1636       ENDIF
1637
1638!
1639!-- In case instantaneous input is desired, mrt values will be re-calculated.
1640    ELSE
1641!
1642!--    Calculate biometeorology MRT from local radiation fluxes calculated by RTM and assign into 2D
1643!--    grid. Depending on selected output quantities, tmrt_grid might not have been allocated in
1644!--    bio_check_data_output yet.
1645       IF ( .NOT. ALLOCATED( tmrt_grid ) )  THEN
1646          ALLOCATE( tmrt_grid (nys:nyn,nxl:nxr) )
1647       ENDIF
1648       tmrt_grid = REAL( bio_fill_value, KIND = wp )
1649
1650       DO  l = 1, nmrtbl
1651          i = mrtbl(ix,l)
1652          j = mrtbl(iy,l)
1653          k = mrtbl(iz,l)
1654          IF ( k - topo_top_ind(j,i,0) == bio_cell_level + 1_iwp)  THEN
1655             IF ( mrt_include_sw )  THEN
1656                tmrt_grid(j,i) = ( ( human_absorb * mrtinsw(l) +                                   &
1657                                 mrtinlw(l) )  /                                                   &
1658                                 ( human_emiss * sigma_sb ) )**0.25_wp -                           &
1659                                 degc_to_k
1660             ELSE
1661                tmrt_grid(j,i) = ( mrtinlw(l)  /                                                   &
1662                                 ( human_emiss * sigma_sb ) )**0.25_wp -                           &
1663                                 degc_to_k
1664             ENDIF
1665          ENDIF
1666       ENDDO
1667    ENDIF
1668
1669 END SUBROUTINE bio_calculate_mrt_grid
1670
1671
1672!--------------------------------------------------------------------------------------------------!
1673! Description:
1674! ------------
1675!> Calculate static thermal indices for 2D grid point i, j
1676!--------------------------------------------------------------------------------------------------!
1677 SUBROUTINE bio_get_thermal_index_input_ij( average_input, i, j, ta, vp, ws, pair, tmrt )
1678
1679    IMPLICIT NONE
1680!
1681!-- Input variables
1682    LOGICAL,      INTENT ( IN ) ::  average_input  !< Determine averaged input conditions?
1683    INTEGER(iwp), INTENT ( IN ) ::  i     !< Running index, x-dir
1684    INTEGER(iwp), INTENT ( IN ) ::  j     !< Running index, y-dir
1685!
1686!-- Output parameters
1687    REAL(wp), INTENT ( OUT )    ::  pair  !< Air pressure                    (hPa)
1688    REAL(wp), INTENT ( OUT )    ::  ta    !< Air temperature                 (degree_C)
1689    REAL(wp), INTENT ( OUT )    ::  tmrt  !< Mean radiant temperature        (degree_C)
1690    REAL(wp), INTENT ( OUT )    ::  vp    !< Vapour pressure                 (hPa)
1691    REAL(wp), INTENT ( OUT )    ::  ws    !< Wind speed    (local level)     (m/s)
1692!
1693!-- Internal variables
1694    INTEGER(iwp)                ::  k     !< Running index, z-dir
1695    INTEGER(iwp)                ::  k_wind  !< Running index, z-dir, wind speed only
1696
1697    REAL(wp)                    ::  vp_sat  !< Saturation vapor pressure     (hPa)
1698
1699!
1700!-- Determine cell level closest to 1.1m above ground by making use of truncation due to int cast.
1701    k = INT( topo_top_ind(j,i,0) + bio_cell_level )  !< Vertical cell center closest to 1.1m
1702
1703!
1704!-- Avoid non-representative horizontal u and v of 0.0 m/s too close to ground
1705    k_wind = k
1706    IF ( bio_cell_level < 1_iwp )  THEN
1707       k_wind = k + 1_iwp
1708    ENDIF
1709!
1710!-- Determine local values:
1711    IF ( average_input )  THEN
1712!
1713!--    Calculate ta from Tp assuming dry adiabatic laps rate
1714       ta = bio_fill_value
1715       IF ( ALLOCATED( pt_av ) )  THEN
1716          ta = pt_av(k,j,i) - ( 0.0098_wp * dz(1) * ( k + 0.5_wp ) ) - degc_to_k
1717       ENDIF
1718
1719       vp = bio_fill_value
1720       IF ( humidity  .AND.  ALLOCATED( q_av ) )  THEN
1721          vp = q_av(k,j,i)
1722       ENDIF
1723
1724       ws = bio_fill_value
1725       IF ( ALLOCATED( u_av )  .AND.  ALLOCATED( v_av )  .AND.                                     &
1726          ALLOCATED( w_av ) )  THEN
1727             ws = ( 0.5_wp * ABS( u_av(k_wind,j,i) + u_av(k_wind,j,i+1) ) +                        &
1728                    0.5_wp * ABS( v_av(k_wind,j,i) + v_av(k_wind,j+1,i) ) +                        &
1729                    0.5_wp * ABS( w_av(k_wind,j,i) + w_av(k_wind+1,j,i) ) )
1730       ENDIF
1731    ELSE
1732!
1733!--    Calculate ta from Tp assuming dry adiabatic laps rate
1734       ta = pt(k,j,i) - ( 0.0098_wp * dz(1) * (  k + 0.5_wp ) ) - degc_to_k
1735
1736       vp = bio_fill_value
1737       IF ( humidity )  THEN
1738          vp = q(k,j,i)
1739       ENDIF
1740
1741       ws = ( 0.5_wp * ABS( u(k_wind,j,i) + u(k_wind,j,i+1) )  +                                   &
1742              0.5_wp * ABS( v(k_wind,j,i) + v(k_wind,j+1,i) )  +                                   &
1743              0.5_wp * ABS( w(k_wind,j,i) + w(k_wind+1,j,i) ) )
1744
1745    ENDIF
1746!
1747!-- Local air pressure
1748    pair = surface_pressure
1749!
1750!-- Calculate water vapour pressure at saturation and convert to hPa.
1751!-- The magnus formula is limited to temperatures up to 333.15 K to avoid negative values of vp_sat.
1752    IF ( vp > -998.0_wp )  THEN
1753       vp_sat = 0.01_wp * magnus( MIN( ta + degc_to_k, 333.15_wp ) )
1754       vp  = vp * pair / ( vp + 0.622_wp )
1755       IF ( vp > vp_sat )  vp = vp_sat
1756    ENDIF
1757!
1758!-- Local mtr value at [i,j]
1759    tmrt = bio_fill_value  !< this can be a valid result (e.g. for inside some ostacle)
1760    IF ( .NOT. average_input )  THEN
1761!
1762!--    Use MRT from RTM precalculated in tmrt_grid
1763       tmrt = tmrt_grid(j,i)
1764    ELSE
1765       tmrt = tmrt_av_grid(j,i)
1766    ENDIF
1767
1768 END SUBROUTINE bio_get_thermal_index_input_ij
1769
1770
1771!--------------------------------------------------------------------------------------------------!
1772! Description:
1773! ------------
1774!> Calculate static thermal indices for any point within a 2D grid time_integration.f90: 1065ff
1775!--------------------------------------------------------------------------------------------------!
1776 SUBROUTINE bio_calculate_thermal_index_maps( av )
1777
1778    IMPLICIT NONE
1779!
1780!-- Input attributes
1781    LOGICAL, INTENT ( IN ) ::  av  !< Calculate based on averaged input conditions?
1782!
1783!-- Internal variables
1784    INTEGER(iwp) ::  i, j     !< Running index
1785
1786    REAL(wp) ::  clo          !< Clothing index                (no dimension)
1787    REAL(wp) ::  pair         !< Air pressure                     (hPa)
1788    REAL(wp) ::  perct_ij     !< Perceived temperature            (degree_C)
1789    REAL(wp) ::  pet_ij       !< Physiologically equivalent temperature  (degree_C)
1790    REAL(wp) ::  ta           !< Air temperature                  (degree_C)
1791    REAL(wp) ::  tmrt_ij      !< Mean radiant temperature         (degree_C)
1792    REAL(wp) ::  utci_ij      !< Universal thermal climate index  (degree_C)
1793    REAL(wp) ::  vp           !< Vapour pressure                  (hPa)
1794    REAL(wp) ::  ws           !< Wind speed    (local level)      (m/s)
1795
1796!
1797!-- Check if some thermal index is desired. Don't do anything if, e.g. only bio_mrt is desired.
1798    IF ( do_calculate_perct    .OR.  do_calculate_perct_av  .OR.  do_calculate_utci    .OR.        &
1799         do_calculate_utci_av  .OR.  do_calculate_pet       .OR.  do_calculate_pet_av  .OR.        &
1800         do_calculate_mrt2d )  THEN
1801
1802!
1803!--    fill out the MRT 2D grid from appropriate source (RTM, RRTMG,...)
1804       CALL bio_calculate_mrt_grid ( av )
1805
1806       DO  i = nxl, nxr
1807          DO  j = nys, nyn
1808!
1809!--          Determine local input conditions
1810             tmrt_ij = bio_fill_value
1811             vp      = bio_fill_value
1812!
1813!--          Determine local meteorological conditions
1814             CALL bio_get_thermal_index_input_ij ( av, i, j, ta, vp, ws, pair, tmrt_ij )
1815!
1816!--          Only proceed if input is available
1817             pet_ij   = bio_fill_value   !< set fail value, e.g. valid for
1818             perct_ij = bio_fill_value   !< within some obstacle
1819             utci_ij  = bio_fill_value
1820             IF ( .NOT. ( tmrt_ij <= -998.0_wp  .OR.  vp <= -998.0_wp  .OR.   ws <= -998.0_wp  .OR.&
1821                  ta <= -998.0_wp ) )  THEN
1822!
1823!--             Calculate static thermal indices based on local tmrt
1824                clo = bio_fill_value
1825
1826                IF ( do_calculate_perct  .OR.  do_calculate_perct_av )  THEN
1827!
1828!--                Estimate local perceived temperature
1829                   CALL calculate_perct_static( ta, vp, ws, tmrt_ij, pair, clo, perct_ij )
1830                ENDIF
1831
1832                IF ( do_calculate_utci  .OR.  do_calculate_utci_av )  THEN
1833!
1834!--                Estimate local universal thermal climate index
1835                   CALL calculate_utci_static( ta, vp, ws, tmrt_ij, bio_output_height, utci_ij )
1836                ENDIF
1837
1838                IF ( do_calculate_pet  .OR.  do_calculate_pet_av )  THEN
1839!
1840!--                Estimate local physiologically equivalent temperature
1841                   CALL calculate_pet_static( ta, vp, ws, tmrt_ij, pair, pet_ij )
1842                ENDIF
1843             ENDIF
1844
1845
1846             IF ( av )  THEN
1847!
1848!--             Write results for selected averaged indices
1849                IF ( do_calculate_perct_av )  THEN
1850                   perct_av(j, i) = perct_ij
1851                ENDIF
1852                IF ( do_calculate_utci_av )  THEN
1853                   utci_av(j, i) = utci_ij
1854                ENDIF
1855                IF ( do_calculate_pet_av )  THEN
1856                   pet_av(j, i)  = pet_ij
1857                ENDIF
1858             ELSE
1859!
1860!--             Write result for selected indices
1861                IF ( do_calculate_perct )  THEN
1862                   perct(j, i) = perct_ij
1863                ENDIF
1864                IF ( do_calculate_utci )  THEN
1865                   utci(j, i) = utci_ij
1866                ENDIF
1867                IF ( do_calculate_pet )  THEN
1868                   pet(j, i)  = pet_ij
1869                ENDIF
1870             ENDIF
1871
1872          ENDDO
1873       ENDDO
1874    ENDIF
1875
1876 END SUBROUTINE bio_calculate_thermal_index_maps
1877
1878!--------------------------------------------------------------------------------------------------!
1879! Description:
1880! ------------
1881!> Calculate dynamic thermal indices (currently only iPT, but expandable)
1882!--------------------------------------------------------------------------------------------------!
1883 SUBROUTINE bio_calc_ipt( ta, vp, ws, pair, tmrt, dt, energy_storage, t_clo, clo, actlev, age,     &
1884                          weight, height, work, sex, ipt )
1885
1886    IMPLICIT NONE
1887!
1888!-- Input parameters
1889    INTEGER(iwp), INTENT ( IN ) ::  sex  !< Sex of agent (1 = male, 2 = female)
1890
1891    REAL(wp), INTENT ( IN )  ::  age     !< Age of agent                     (y)
1892    REAL(wp), INTENT ( IN )  ::  dt      !< Time past SINce last calculation (s)
1893    REAL(wp), INTENT ( IN )  ::  height  !< Height of agent                  (m)
1894    REAL(wp), INTENT ( IN )  ::  pair    !< Air pressure                     (hPa)
1895    REAL(wp), INTENT ( IN )  ::  ta      !< Air temperature                  (degree_C)
1896    REAL(wp), INTENT ( IN )  ::  tmrt    !< Mean radiant temperature         (degree_C)
1897    REAL(wp), INTENT ( IN )  ::  vp      !< Vapour pressure                  (hPa)
1898    REAL(wp), INTENT ( IN )  ::  weight  !< Weight of agent                  (Kg)
1899    REAL(wp), INTENT ( IN )  ::  work    !< Mechanical workload of agent  (without metabolism!) (W)
1900    REAL(wp), INTENT ( IN )  ::  ws      !< Wind speed  (local level)        (m/s)
1901
1902!
1903!-- Both, input and output parameters
1904    Real(wp), INTENT ( INOUT )  ::  actlev            !< Individuals activity level
1905                                                      !< per unit surface area      (W/m²)
1906    Real(wp), INTENT ( INOUT )  ::  clo               !< Current clothing in sulation
1907    Real(wp), INTENT ( INOUT )  ::  energy_storage    !< Energy storage   (W/m²)
1908    Real(wp), INTENT ( INOUT )  ::  t_clo             !< Clothing temperature       (degree_C)
1909!
1910!-- Output parameters
1911    REAL(wp), INTENT ( OUT ) ::  ipt    !< Instationary perceived temp.   (degree_C)
1912!
1913!-- Return immediatelly if nothing to do!
1914    IF ( .NOT. thermal_comfort )  THEN
1915        RETURN
1916    ENDIF
1917!
1918!-- If clo equals the initial value, this is the initial call
1919    IF ( clo <= -998.0_wp )  THEN
1920!
1921!--    Initialize instationary perceived temperature with personalized PT as an initial guess, set
1922!--    actlev and clo
1923       CALL ipt_init( age, weight, height, sex, work, actlev, clo, ta, vp, ws, tmrt, pair, dt,     &
1924                      energy_storage, t_clo, ipt )
1925    ELSE
1926!
1927!--    Estimate local instatinoary perceived temperature
1928       CALL ipt_cycle ( ta, vp, ws, tmrt, pair, dt, energy_storage, t_clo, clo, actlev, work, ipt )
1929    ENDIF
1930
1931 END SUBROUTINE bio_calc_ipt
1932
1933
1934
1935!--------------------------------------------------------------------------------------------------!
1936! Description:
1937! ------------
1938!> SUBROUTINE for calculating UTCI Temperature (UTCI)
1939!> computed by a 6th order approximation
1940!>
1941!> UTCI regression equation according to
1942!> Bröde P, Fiala D, Blazejczyk K, Holmér I, Jendritzky G, Kampmann B, Tinz B, Havenith G (2012)
1943!> Deriving the operational procedure for the Universal Thermal Climate Index (UTCI). International
1944!> Journal of Biometeorology 56 (3):481-494. doi:10.1007/s00484-011-0454-1
1945!>
1946!> original source available at:
1947!> www.utci.org
1948!--------------------------------------------------------------------------------------------------!
1949 SUBROUTINE calculate_utci_static( ta_in, vp, ws_hag, tmrt, hag, utci_ij )
1950
1951    IMPLICIT NONE
1952!
1953!-- Type of input of the argument list
1954    REAL(WP), INTENT ( IN )  ::  hag      !< Height of wind speed input (m)
1955    REAL(WP), INTENT ( IN )  ::  ta_in    !< Local air temperature (degree_C)
1956    REAL(WP), INTENT ( IN )  ::  tmrt     !< Local mean radiant temperature (degree_C)
1957    REAL(WP), INTENT ( IN )  ::  vp       !< Loacl vapour pressure (hPa)
1958    REAL(WP), INTENT ( IN )  ::  ws_hag   !< Incident wind speed (m/s)
1959!
1960!-- Type of output of the argument list
1961    REAL(WP) ::  d_tmrt       !< delta-tmrt               (degree_C)
1962    REAL(WP) ::  d_tmrt2      !< 2 times d_tmrt
1963    REAL(WP) ::  d_tmrt3      !< 3 times d_tmrt
1964    REAL(WP) ::  d_tmrt4      !< 4 times d_tmrt
1965    REAL(WP) ::  d_tmrt5      !< 5 times d_tmrt
1966    REAL(WP) ::  d_tmrt6      !< 6 times d_tmrt
1967    REAL(WP) ::  offset       !< utci deviation by ta cond. exceeded      (degree_C)
1968    REAL(WP) ::  pa           !< air pressure in kPa      (kPa)
1969    REAL(WP) ::  pa2          !< 2 times pa
1970    REAL(WP) ::  pa3          !< 3 times pa
1971    REAL(WP) ::  pa4          !< 4 times pa
1972    REAL(WP) ::  pa5          !< 5 times pa
1973    REAL(WP) ::  pa6          !< 6 times pa
1974    REAL(WP) ::  part_d_tmrt  !< Mean radiant temp. related part of the reg.
1975    REAL(WP) ::  part_pa      !< Air pressure related part of the regression
1976    REAL(WP) ::  part_pa2     !< Air pressure^2 related part of the regression
1977    REAL(WP) ::  part_pa3     !< Air pressure^3 related part of the regression
1978    REAL(WP) ::  part_pa46    !< Air pressure^4-6 related part of the regression
1979    REAL(WP) ::  part_ta      !< Air temperature related part of the regression
1980    REAL(WP) ::  part_va      !< Vapour pressure related part of the regression
1981    REAL(WP) ::  ta           !< air temperature modified by offset (degree_C)
1982    REAL(WP) ::  ta2          !< 2 times ta
1983    REAL(WP) ::  ta3          !< 3 times ta
1984    REAL(WP) ::  ta4          !< 4 times ta
1985    REAL(WP) ::  ta5          !< 5 times ta
1986    REAL(WP) ::  ta6          !< 6 times ta
1987    REAL(WP) ::  va           !< wind speed at 10 m above ground level    (m/s)
1988    REAL(WP) ::  va2          !< 2 times va
1989    REAL(WP) ::  va3          !< 3 times va
1990    REAL(WP) ::  va4          !< 4 times va
1991    REAL(WP) ::  va5          !< 5 times va
1992    REAL(WP) ::  va6          !< 6 times va
1993
1994
1995    REAL(wp), INTENT ( OUT ) ::  utci_ij  !< Universal Thermal Climate Index (degree_C)
1996
1997!
1998!-- Initialize
1999    offset = 0.0_wp
2000    ta = ta_in
2001    d_tmrt = tmrt - ta_in
2002!
2003!-- Use vapour pressure in kpa
2004    pa = vp / 10.0_wp
2005!
2006!-- Wind altitude correction from hag to 10m after Broede et al. (2012), eq.3
2007!-- z(0) is set to 0.01 according to UTCI profile definition
2008    va = ws_hag *  log ( 10.0_wp / 0.01_wp ) / log ( hag / 0.01_wp )
2009!
2010!-- Check if input values in range after Broede et al. (2012)
2011    IF ( ( d_tmrt > 70.0_wp )  .OR.  ( d_tmrt < -30.0_wp )  .OR.  ( vp >= 50.0_wp ) )  THEN
2012       utci_ij = bio_fill_value
2013       RETURN
2014    ENDIF
2015!
2016!-- Apply eq. 2 in Broede et al. (2012) for ta out of bounds
2017    IF ( ta > 50.0_wp )  THEN
2018       offset = ta - 50.0_wp
2019       ta = 50.0_wp
2020    ENDIF
2021    IF ( ta < -50.0_wp )  THEN
2022       offset = ta + 50.0_wp
2023       ta = -50.0_wp
2024    ENDIF
2025!
2026!-- For routine application. For wind speeds and relative humidity values below 0.5 m/s or 5%,
2027!-- respectively, the user is advised to use the lower bounds for the calculations.
2028    IF ( va < 0.5_wp )  va = 0.5_wp
2029    IF ( va > 17.0_wp )  va = 17.0_wp
2030
2031!
2032!-- Pre-calculate multiples of input parameters to save time later
2033    ta2 = ta  * ta
2034    ta3 = ta2 * ta
2035    ta4 = ta3 * ta
2036    ta5 = ta4 * ta
2037    ta6 = ta5 * ta
2038
2039    va2 = va  * va
2040    va3 = va2 * va
2041    va4 = va3 * va
2042    va5 = va4 * va
2043    va6 = va5 * va
2044
2045    d_tmrt2 = d_tmrt  * d_tmrt
2046    d_tmrt3 = d_tmrt2 * d_tmrt
2047    d_tmrt4 = d_tmrt3 * d_tmrt
2048    d_tmrt5 = d_tmrt4 * d_tmrt
2049    d_tmrt6 = d_tmrt5 * d_tmrt
2050
2051    pa2 = pa  * pa
2052    pa3 = pa2 * pa
2053    pa4 = pa3 * pa
2054    pa5 = pa4 * pa
2055    pa6 = pa5 * pa
2056
2057!
2058!-- Pre-calculate parts of the regression equation
2059    part_ta = (  6.07562052e-01_wp )       +                                                       &
2060              ( -2.27712343e-02_wp ) * ta  +                                                       &
2061              (  8.06470249e-04_wp ) * ta2 +                                                       &
2062              ( -1.54271372e-04_wp ) * ta3 +                                                       &
2063              ( -3.24651735e-06_wp ) * ta4 +                                                       &
2064              (  7.32602852e-08_wp ) * ta5 +                                                       &
2065              (  1.35959073e-09_wp ) * ta6
2066
2067    part_va = ( -2.25836520e+00_wp ) *       va  +                                                 &
2068              (  8.80326035e-02_wp ) * ta  * va  +                                                 &
2069              (  2.16844454e-03_wp ) * ta2 * va  +                                                 &
2070              ( -1.53347087e-05_wp ) * ta3 * va  +                                                 &
2071              ( -5.72983704e-07_wp ) * ta4 * va  +                                                 &
2072              ( -2.55090145e-09_wp ) * ta5 * va  +                                                 &
2073              ( -7.51269505e-01_wp ) *       va2 +                                                 &
2074              ( -4.08350271e-03_wp ) * ta  * va2 +                                                 &
2075              ( -5.21670675e-05_wp ) * ta2 * va2 +                                                 &
2076              (  1.94544667e-06_wp ) * ta3 * va2 +                                                 &
2077              (  1.14099531e-08_wp ) * ta4 * va2 +                                                 &
2078              (  1.58137256e-01_wp ) *       va3 +                                                 &
2079              ( -6.57263143e-05_wp ) * ta  * va3 +                                                 &
2080              (  2.22697524e-07_wp ) * ta2 * va3 +                                                 &
2081              ( -4.16117031e-08_wp ) * ta3 * va3 +                                                 &
2082              ( -1.27762753e-02_wp ) *       va4 +                                                 &
2083              (  9.66891875e-06_wp ) * ta  * va4 +                                                 &
2084              (  2.52785852e-09_wp ) * ta2 * va4 +                                                 &
2085              (  4.56306672e-04_wp ) *       va5 +                                                 &
2086              ( -1.74202546e-07_wp ) * ta  * va5 +                                                 &
2087              ( -5.91491269e-06_wp ) * va6
2088
2089    part_d_tmrt = (  3.98374029e-01_wp ) *             d_tmrt  +                                   &
2090                  (  1.83945314e-04_wp ) * ta  *       d_tmrt  +                                   &
2091                  ( -1.73754510e-04_wp ) * ta2 *       d_tmrt  +                                   &
2092                  ( -7.60781159e-07_wp ) * ta3 *       d_tmrt  +                                   &
2093                  (  3.77830287e-08_wp ) * ta4 *       d_tmrt  +                                   &
2094                  (  5.43079673e-10_wp ) * ta5 *       d_tmrt  +                                   &
2095                  ( -2.00518269e-02_wp ) *       va  * d_tmrt  +                                   &
2096                  (  8.92859837e-04_wp ) * ta  * va  * d_tmrt  +                                   &
2097                  (  3.45433048e-06_wp ) * ta2 * va  * d_tmrt  +                                   &
2098                  ( -3.77925774e-07_wp ) * ta3 * va  * d_tmrt  +                                   &
2099                  ( -1.69699377e-09_wp ) * ta4 * va  * d_tmrt  +                                   &
2100                  (  1.69992415e-04_wp ) *       va2 * d_tmrt  +                                   &
2101                  ( -4.99204314e-05_wp ) * ta  * va2 * d_tmrt  +                                   &
2102                  (  2.47417178e-07_wp ) * ta2 * va2 * d_tmrt  +                                   &
2103                  (  1.07596466e-08_wp ) * ta3 * va2 * d_tmrt  +                                   &
2104                  (  8.49242932e-05_wp ) *       va3 * d_tmrt  +                                   &
2105                  (  1.35191328e-06_wp ) * ta  * va3 * d_tmrt  +                                   &
2106                  ( -6.21531254e-09_wp ) * ta2 * va3 * d_tmrt  +                                   &
2107                  ( -4.99410301e-06_wp ) * va4 *       d_tmrt  +                                   &
2108                  ( -1.89489258e-08_wp ) * ta  * va4 * d_tmrt  +                                   &
2109                  (  8.15300114e-08_wp ) *       va5 * d_tmrt  +                                   &
2110                  (  7.55043090e-04_wp ) *             d_tmrt2 +                                   &
2111                  ( -5.65095215e-05_wp ) * ta  *       d_tmrt2 +                                   &
2112                  ( -4.52166564e-07_wp ) * ta2 *       d_tmrt2 +                                   &
2113                  (  2.46688878e-08_wp ) * ta3 *       d_tmrt2 +                                   &
2114                  (  2.42674348e-10_wp ) * ta4 *       d_tmrt2 +                                   &
2115                  (  1.54547250e-04_wp ) *       va  * d_tmrt2 +                                   &
2116                  (  5.24110970e-06_wp ) * ta  * va  * d_tmrt2 +                                   &
2117                  ( -8.75874982e-08_wp ) * ta2 * va  * d_tmrt2 +                                   &
2118                  ( -1.50743064e-09_wp ) * ta3 * va  * d_tmrt2 +                                   &
2119                  ( -1.56236307e-05_wp ) *       va2 * d_tmrt2 +                                   &
2120                  ( -1.33895614e-07_wp ) * ta  * va2 * d_tmrt2 +                                   &
2121                  (  2.49709824e-09_wp ) * ta2 * va2 * d_tmrt2 +                                   &
2122                  (  6.51711721e-07_wp ) *       va3 * d_tmrt2 +                                   &
2123                  (  1.94960053e-09_wp ) * ta  * va3 * d_tmrt2 +                                   &
2124                  ( -1.00361113e-08_wp ) *       va4 * d_tmrt2 +                                   &
2125                  ( -1.21206673e-05_wp ) *             d_tmrt3 +                                   &
2126                  ( -2.18203660e-07_wp ) * ta  *       d_tmrt3 +                                   &
2127                  (  7.51269482e-09_wp ) * ta2 *       d_tmrt3 +                                   &
2128                  (  9.79063848e-11_wp ) * ta3 *       d_tmrt3 +                                   &
2129                  (  1.25006734e-06_wp ) *       va  * d_tmrt3 +                                   &
2130                  ( -1.81584736e-09_wp ) * ta  * va  * d_tmrt3 +                                   &
2131                  ( -3.52197671e-10_wp ) * ta2 * va  * d_tmrt3 +                                   &
2132                  ( -3.36514630e-08_wp ) *       va2 * d_tmrt3 +                                   &
2133                  (  1.35908359e-10_wp ) * ta  * va2 * d_tmrt3 +                                   &
2134                  (  4.17032620e-10_wp ) *       va3 * d_tmrt3 +                                   &
2135                  ( -1.30369025e-09_wp ) *             d_tmrt4 +                                   &
2136                  (  4.13908461e-10_wp ) * ta  *       d_tmrt4 +                                   &
2137                  (  9.22652254e-12_wp ) * ta2 *       d_tmrt4 +                                   &
2138                  ( -5.08220384e-09_wp ) *       va  * d_tmrt4 +                                   &
2139                  ( -2.24730961e-11_wp ) * ta  * va  * d_tmrt4 +                                   &
2140                  (  1.17139133e-10_wp ) *       va2 * d_tmrt4 +                                   &
2141                  (  6.62154879e-10_wp ) *             d_tmrt5 +                                   &
2142                  (  4.03863260e-13_wp ) * ta  *       d_tmrt5 +                                   &
2143                  (  1.95087203e-12_wp ) *       va  * d_tmrt5 +                                   &
2144                  ( -4.73602469e-12_wp ) *             d_tmrt6
2145
2146    part_pa = (  5.12733497e+00_wp ) *                       pa +                                  &
2147              ( -3.12788561e-01_wp ) * ta  *                 pa +                                  &
2148              ( -1.96701861e-02_wp ) * ta2 *                 pa +                                  &
2149              (  9.99690870e-04_wp ) * ta3 *                 pa +                                  &
2150              (  9.51738512e-06_wp ) * ta4 *                 pa +                                  &
2151              ( -4.66426341e-07_wp ) * ta5 *                 pa +                                  &
2152              (  5.48050612e-01_wp ) *       va  *           pa +                                  &
2153              ( -3.30552823e-03_wp ) * ta  * va  *           pa +                                  &
2154              ( -1.64119440e-03_wp ) * ta2 * va  *           pa +                                  &
2155              ( -5.16670694e-06_wp ) * ta3 * va  *           pa +                                  &
2156              (  9.52692432e-07_wp ) * ta4 * va  *           pa +                                  &
2157              ( -4.29223622e-02_wp ) *       va2 *           pa +                                  &
2158              (  5.00845667e-03_wp ) * ta  * va2 *           pa +                                  &
2159              (  1.00601257e-06_wp ) * ta2 * va2 *           pa +                                  &
2160              ( -1.81748644e-06_wp ) * ta3 * va2 *           pa +                                  &
2161              ( -1.25813502e-03_wp ) *       va3 *           pa +                                  &
2162              ( -1.79330391e-04_wp ) * ta  * va3 *           pa +                                  &
2163              (  2.34994441e-06_wp ) * ta2 * va3 *           pa +                                  &
2164              (  1.29735808e-04_wp ) *       va4 *           pa +                                  &
2165              (  1.29064870e-06_wp ) * ta  * va4 *           pa +                                  &
2166              ( -2.28558686e-06_wp ) *       va5 *           pa +                                  &
2167              ( -3.69476348e-02_wp ) *             d_tmrt  * pa +                                  &
2168              (  1.62325322e-03_wp ) * ta  *       d_tmrt  * pa +                                  &
2169              ( -3.14279680e-05_wp ) * ta2 *       d_tmrt  * pa +                                  &
2170              (  2.59835559e-06_wp ) * ta3 *       d_tmrt  * pa +                                  &
2171              ( -4.77136523e-08_wp ) * ta4 *       d_tmrt  * pa +                                  &
2172              (  8.64203390e-03_wp ) *       va  * d_tmrt  * pa +                                  &
2173              ( -6.87405181e-04_wp ) * ta  * va  * d_tmrt  * pa +                                  &
2174              ( -9.13863872e-06_wp ) * ta2 * va  * d_tmrt  * pa +                                  &
2175              (  5.15916806e-07_wp ) * ta3 * va  * d_tmrt  * pa +                                  &
2176              ( -3.59217476e-05_wp ) *       va2 * d_tmrt  * pa +                                  &
2177              (  3.28696511e-05_wp ) * ta  * va2 * d_tmrt  * pa +                                  &
2178              ( -7.10542454e-07_wp ) * ta2 * va2 * d_tmrt  * pa +                                  &
2179              ( -1.24382300e-05_wp ) *       va3 * d_tmrt  * pa +                                  &
2180              ( -7.38584400e-09_wp ) * ta  * va3 * d_tmrt  * pa +                                  &
2181              (  2.20609296e-07_wp ) *       va4 * d_tmrt  * pa +                                  &
2182              ( -7.32469180e-04_wp ) *             d_tmrt2 * pa +                                  &
2183              ( -1.87381964e-05_wp ) * ta  *       d_tmrt2 * pa +                                  &
2184              (  4.80925239e-06_wp ) * ta2 *       d_tmrt2 * pa +                                  &
2185              ( -8.75492040e-08_wp ) * ta3 *       d_tmrt2 * pa +                                  &
2186              (  2.77862930e-05_wp ) *       va  * d_tmrt2 * pa +                                  &
2187              ( -5.06004592e-06_wp ) * ta  * va  * d_tmrt2 * pa +                                  &
2188              (  1.14325367e-07_wp ) * ta2 * va  * d_tmrt2 * pa +                                  &
2189              (  2.53016723e-06_wp ) *       va2 * d_tmrt2 * pa +                                  &
2190              ( -1.72857035e-08_wp ) * ta  * va2 * d_tmrt2 * pa +                                  &
2191              ( -3.95079398e-08_wp ) *       va3 * d_tmrt2 * pa +                                  &
2192              ( -3.59413173e-07_wp ) *             d_tmrt3 * pa +                                  &
2193              (  7.04388046e-07_wp ) * ta  *       d_tmrt3 * pa +                                  &
2194              ( -1.89309167e-08_wp ) * ta2 *       d_tmrt3 * pa +                                  &
2195              ( -4.79768731e-07_wp ) *       va  * d_tmrt3 * pa +                                  &
2196              (  7.96079978e-09_wp ) * ta  * va  * d_tmrt3 * pa +                                  &
2197              (  1.62897058e-09_wp ) *       va2 * d_tmrt3 * pa +                                  &
2198              (  3.94367674e-08_wp ) *             d_tmrt4 * pa +                                  &
2199              ( -1.18566247e-09_wp ) * ta *        d_tmrt4 * pa +                                  &
2200              (  3.34678041e-10_wp ) *       va  * d_tmrt4 * pa +                                  &
2201              ( -1.15606447e-10_wp ) *             d_tmrt5 * pa
2202
2203    part_pa2 = ( -2.80626406e+00_wp ) *                       pa2 +                                &
2204               (  5.48712484e-01_wp ) * ta  *                 pa2 +                                &
2205               ( -3.99428410e-03_wp ) * ta2 *                 pa2 +                                &
2206               ( -9.54009191e-04_wp ) * ta3 *                 pa2 +                                &
2207               (  1.93090978e-05_wp ) * ta4 *                 pa2 +                                &
2208               ( -3.08806365e-01_wp ) *       va *            pa2 +                                &
2209               (  1.16952364e-02_wp ) * ta  * va *            pa2 +                                &
2210               (  4.95271903e-04_wp ) * ta2 * va *            pa2 +                                &
2211               ( -1.90710882e-05_wp ) * ta3 * va *            pa2 +                                &
2212               (  2.10787756e-03_wp ) *       va2 *           pa2 +                                &
2213               ( -6.98445738e-04_wp ) * ta  * va2 *           pa2 +                                &
2214               (  2.30109073e-05_wp ) * ta2 * va2 *           pa2 +                                &
2215               (  4.17856590e-04_wp ) *       va3 *           pa2 +                                &
2216               ( -1.27043871e-05_wp ) * ta  * va3 *           pa2 +                                &
2217               ( -3.04620472e-06_wp ) *       va4 *           pa2 +                                &
2218               (  5.14507424e-02_wp ) *             d_tmrt  * pa2 +                                &
2219               ( -4.32510997e-03_wp ) * ta  *       d_tmrt  * pa2 +                                &
2220               (  8.99281156e-05_wp ) * ta2 *       d_tmrt  * pa2 +                                &
2221               ( -7.14663943e-07_wp ) * ta3 *       d_tmrt  * pa2 +                                &
2222               ( -2.66016305e-04_wp ) *       va  * d_tmrt  * pa2 +                                &
2223               (  2.63789586e-04_wp ) * ta  * va  * d_tmrt  * pa2 +                                &
2224               ( -7.01199003e-06_wp ) * ta2 * va  * d_tmrt  * pa2 +                                &
2225               ( -1.06823306e-04_wp ) *       va2 * d_tmrt  * pa2 +                                &
2226               (  3.61341136e-06_wp ) * ta  * va2 * d_tmrt  * pa2 +                                &
2227               (  2.29748967e-07_wp ) *       va3 * d_tmrt  * pa2 +                                &
2228               (  3.04788893e-04_wp ) *             d_tmrt2 * pa2 +                                &
2229               ( -6.42070836e-05_wp ) * ta  *       d_tmrt2 * pa2 +                                &
2230               (  1.16257971e-06_wp ) * ta2 *       d_tmrt2 * pa2 +                                &
2231               (  7.68023384e-06_wp ) *       va  * d_tmrt2 * pa2 +                                &
2232               ( -5.47446896e-07_wp ) * ta  * va  * d_tmrt2 * pa2 +                                &
2233               ( -3.59937910e-08_wp ) *       va2 * d_tmrt2 * pa2 +                                &
2234               ( -4.36497725e-06_wp ) *             d_tmrt3 * pa2 +                                &
2235               (  1.68737969e-07_wp ) * ta  *       d_tmrt3 * pa2 +                                &
2236               (  2.67489271e-08_wp ) *       va  * d_tmrt3 * pa2 +                                &
2237               (  3.23926897e-09_wp ) *             d_tmrt4 * pa2
2238
2239    part_pa3 = ( -3.53874123e-02_wp ) *                       pa3 +                                &
2240               ( -2.21201190e-01_wp ) * ta  *                 pa3 +                                &
2241               (  1.55126038e-02_wp ) * ta2 *                 pa3 +                                &
2242               ( -2.63917279e-04_wp ) * ta3 *                 pa3 +                                &
2243               (  4.53433455e-02_wp ) *       va  *           pa3 +                                &
2244               ( -4.32943862e-03_wp ) * ta  * va  *           pa3 +                                &
2245               (  1.45389826e-04_wp ) * ta2 * va  *           pa3 +                                &
2246               (  2.17508610e-04_wp ) *       va2 *           pa3 +                                &
2247               ( -6.66724702e-05_wp ) * ta  * va2 *           pa3 +                                &
2248               (  3.33217140e-05_wp ) *       va3 *           pa3 +                                &
2249               ( -2.26921615e-03_wp ) *             d_tmrt  * pa3 +                                &
2250               (  3.80261982e-04_wp ) * ta  *       d_tmrt  * pa3 +                                &
2251               ( -5.45314314e-09_wp ) * ta2 *       d_tmrt  * pa3 +                                &
2252               ( -7.96355448e-04_wp ) *       va  * d_tmrt  * pa3 +                                &
2253               (  2.53458034e-05_wp ) * ta  * va  * d_tmrt  * pa3 +                                &
2254               ( -6.31223658e-06_wp ) *       va2 * d_tmrt  * pa3 +                                &
2255               (  3.02122035e-04_wp ) *             d_tmrt2 * pa3 +                                &
2256               ( -4.77403547e-06_wp ) * ta  *       d_tmrt2 * pa3 +                                &
2257               (  1.73825715e-06_wp ) *       va  * d_tmrt2 * pa3 +                                &
2258               ( -4.09087898e-07_wp ) *             d_tmrt3 * pa3
2259
2260    part_pa46 = (  6.14155345e-01_wp ) *                       pa4 +                               &
2261                ( -6.16755931e-02_wp ) * ta  *                 pa4 +                               &
2262                (  1.33374846e-03_wp ) * ta2 *                 pa4 +                               &
2263                (  3.55375387e-03_wp ) *       va  *           pa4 +                               &
2264                ( -5.13027851e-04_wp ) * ta  * va  *           pa4 +                               &
2265                (  1.02449757e-04_wp ) *       va2 *           pa4 +                               &
2266                ( -1.48526421e-03_wp ) *             d_tmrt  * pa4 +                               &
2267                ( -4.11469183e-05_wp ) * ta  *       d_tmrt  * pa4 +                               &
2268                ( -6.80434415e-06_wp ) *       va  * d_tmrt  * pa4 +                               &
2269                ( -9.77675906e-06_wp ) *             d_tmrt2 * pa4 +                               &
2270                (  8.82773108e-02_wp ) *                       pa5 +                               &
2271                ( -3.01859306e-03_wp ) * ta  *                 pa5 +                               &
2272                (  1.04452989e-03_wp ) *       va  *           pa5 +                               &
2273                (  2.47090539e-04_wp ) *             d_tmrt  * pa5 +                               &
2274                (  1.48348065e-03_wp ) *                       pa6
2275!
2276!-- Calculate 6th order polynomial as approximation
2277    utci_ij = ta + part_ta + part_va + part_d_tmrt + part_pa + part_pa2 + part_pa3 + part_pa46
2278!
2279!-- Consider offset in result
2280    utci_ij = utci_ij + offset
2281
2282 END SUBROUTINE calculate_utci_static
2283
2284
2285
2286
2287!--------------------------------------------------------------------------------------------------!
2288! Description:
2289! ------------
2290!> Calculate_perct_static: Estimation of perceived temperature (PT, degree_C)
2291!> Value of perct is the Perceived Temperature, degree centigrade
2292!--------------------------------------------------------------------------------------------------!
2293 SUBROUTINE calculate_perct_static( ta, vp, ws, tmrt, pair, clo, perct_ij )
2294
2295    IMPLICIT NONE
2296!
2297!-- Type of input of the argument list
2298    REAL(wp), INTENT ( IN )  :: pair !< Local barometric air pressure (hPa)
2299    REAL(wp), INTENT ( IN )  :: ta   !< Local air temperature (degC)
2300    REAL(wp), INTENT ( IN )  :: tmrt !< Local mean radiant temperature (degC)
2301    REAL(wp), INTENT ( IN )  :: vp   !< Local vapour pressure (hPa)
2302    REAL(wp), INTENT ( IN )  :: ws   !< Local wind velocitry (m/s)
2303!
2304!-- Type of output of the argument list
2305    REAL(wp), INTENT ( OUT ) :: clo       !< Clothing index (dimensionless)
2306    REAL(wp), INTENT ( OUT ) :: perct_ij  !< Perceived temperature (degC)
2307!
2308!-- Parameters for standard "Klima-Michel"
2309    REAL(wp), PARAMETER :: actlev = 134.6862_wp  !< Workload by activity per standardized surface (A_Du)
2310    REAL(wp), PARAMETER :: eta = 0.0_wp          !< Mechanical work efficiency for walking on flat
2311                                                 !< ground (compare to Fanger (1972) pp 24f)
2312!
2313!-- Type of program variables
2314    REAL(wp), PARAMETER :: eps = 0.0005  !< Accuracy in clothing insulation (clo) for evaluation the root of Fanger's PMV (pmva=0)
2315
2316    INTEGER(iwp) :: ncount      !< running index
2317    INTEGER(iwp) :: nerr_cold   !< error number (cold conditions)
2318    INTEGER(iwp) :: nerr        !< error number
2319
2320    LOGICAL :: sultrieness
2321
2322    REAL(wp) ::  clon           !< clo for neutral conditions   (clo)
2323    REAL(wp) ::  d_pmv          !< PMV deviation (dimensionless --> PMV)
2324    REAL(wp) ::  dgtcm          !< Mean deviation dependent on perct
2325    REAL(wp) ::  dgtcstd        !< Mean deviation plus its standard deviation
2326    REAL(wp) ::  d_std          !< factor to threshold for sultriness
2327    REAL(wp) ::  ireq_minimal   !< Minimal required clothing insulation (clo)
2328    REAL(wp) ::  pmv_s          !< Fangers predicted mean vote for summer clothing
2329    REAL(wp) ::  pmv_w          !< Fangers predicted mean vote for winter clothing
2330    REAL(wp) ::  pmva           !< adjusted predicted mean vote
2331    REAL(wp) ::  pmvs           !< pred. mean vote considering sultrieness
2332    REAL(wp) ::  ptc            !< perceived temp. for cold conditions (degree_C)
2333    REAL(wp) ::  sclo           !< summer clothing insulation
2334    REAL(wp) ::  svp_ta         !< saturation vapor pressure    (hPa)
2335    REAL(wp) ::  sult_lim       !< threshold for sultrieness    (hPa)
2336    REAL(wp) ::  wclo           !< winter clothing insulation
2337
2338!
2339!-- Initialise
2340    perct_ij = bio_fill_value
2341
2342    nerr     = 0_iwp
2343    ncount   = 0_iwp
2344    sultrieness  = .FALSE.
2345!
2346!-- Tresholds: clothing insulation (account for model inaccuracies)
2347!-- Summer clothing
2348    sclo     = 0.44453_wp
2349!
2350!-- Winter clothing
2351    wclo     = 1.76267_wp
2352!
2353!-- Eecision: first calculate for winter or summer clothing
2354    IF ( ta <= 10.0_wp )  THEN
2355!
2356!--    First guess: winter clothing insulation: cold stress
2357       clo = wclo
2358       CALL fanger ( ta, tmrt, vp, ws, pair, clo, actlev, eta, pmva )
2359       pmv_w = pmva
2360
2361       IF ( pmva > 0.0_wp )  THEN
2362!
2363!--       Case summer clothing insulation: heat load ?
2364          clo = sclo
2365          CALL fanger ( ta, tmrt, vp, ws, pair, clo, actlev, eta, pmva )
2366          pmv_s = pmva
2367          IF ( pmva <= 0.0_wp )  THEN
2368!
2369!--          Case: comfort achievable by varying clothing insulation between winter and summer set
2370!--                values
2371             CALL iso_ridder ( ta, tmrt, vp, ws, pair, actlev, eta, sclo, pmv_s, wclo, pmv_w, eps, &
2372                               pmva, ncount, clo )
2373             IF ( ncount < 0_iwp )  THEN
2374                nerr = -1_iwp
2375                RETURN
2376             ENDIF
2377          ELSE IF ( pmva > 0.06_wp )  THEN
2378             clo = 0.5_wp
2379             CALL fanger ( ta, tmrt, vp, ws, pair, clo, actlev, eta,  pmva )
2380          ENDIF
2381       ELSE IF ( pmva < - 0.11_wp )  THEN
2382          clo = 1.75_wp
2383          CALL fanger ( ta, tmrt, vp, ws, pair, clo, actlev, eta, pmva )
2384       ENDIF
2385    ELSE
2386!
2387!--    First guess: summer clothing insulation: heat load
2388       clo = sclo
2389       CALL fanger ( ta, tmrt, vp, ws, pair, clo, actlev, eta, pmva )
2390       pmv_s = pmva
2391
2392       IF ( pmva < 0.0_wp )  THEN
2393!
2394!--       Case winter clothing insulation: cold stress ?
2395          clo = wclo
2396          CALL fanger ( ta, tmrt, vp, ws, pair, clo, actlev, eta, pmva )
2397          pmv_w = pmva
2398
2399          IF ( pmva >= 0.0_wp )  THEN
2400!
2401!--          Case: comfort achievable by varying clothing insulation between winter and summer set
2402!--                values
2403             CALL iso_ridder ( ta, tmrt, vp, ws, pair, actlev, eta, sclo, pmv_s, wclo, pmv_w, eps, &
2404                               pmva, ncount, clo )
2405             IF ( ncount < 0_iwp )  THEN
2406                nerr = -1_iwp
2407                RETURN
2408             ENDIF
2409          ELSE IF ( pmva < - 0.11_wp )  THEN
2410             clo = 1.75_wp
2411             CALL fanger ( ta, tmrt, vp, ws, pair, clo, actlev, eta, pmva )
2412          ENDIF
2413       ELSE IF ( pmva > 0.06_wp )  THEN
2414          clo = 0.5_wp
2415          CALL fanger ( ta, tmrt, vp, ws, pair, clo, actlev, eta, pmva )
2416       ENDIF
2417
2418    ENDIF
2419!
2420!-- Determine perceived temperature by regression equation + adjustments
2421    pmvs = pmva
2422    CALL perct_regression( pmva, clo, perct_ij )
2423    ptc = perct_ij
2424    IF ( clo >= 1.75_wp  .AND.  pmva <= - 0.11_wp )  THEN
2425!
2426!--    Adjust for cold conditions according to Gagge 1986
2427       CALL dpmv_cold ( pmva, ta, ws, tmrt, nerr_cold, d_pmv )
2428       IF ( nerr_cold > 0_iwp )  nerr = -5_iwp
2429       pmvs = pmva - d_pmv
2430       IF ( pmvs > - 0.11_wp )  THEN
2431          d_pmv  = 0.0_wp
2432          pmvs   = - 0.11_wp
2433       ENDIF
2434       CALL perct_regression( pmvs, clo, perct_ij )
2435    ENDIF
2436!     clo_fanger = clo
2437    clon = clo
2438    IF ( clo > 0.5_wp  .AND.  perct_ij <= 8.73_wp )  THEN
2439!
2440!--    Required clothing insulation (ireq) is exclusively defined for perceived temperatures (perct)
2441!--    less 10 (C) for a reference wind of 0.2 m/s according to 8.73 (C) for 0.1 m/s.
2442       clon = ireq_neutral ( perct_ij, ireq_minimal, nerr )
2443       clo = clon
2444    ENDIF
2445    CALL calc_sultr( ptc, dgtcm, dgtcstd, sult_lim )
2446    sultrieness    = .FALSE.
2447    d_std = -99.0_wp
2448    IF ( pmva > 0.06_wp  .AND.  clo <= 0.5_wp )  THEN
2449!
2450!--    Adjust for warm/humid conditions according to Gagge 1986
2451       CALL saturation_vapor_pressure ( ta, svp_ta )
2452       d_pmv  = deltapmv ( pmva, ta, vp, svp_ta, tmrt, ws, nerr )
2453       pmvs   = pmva + d_pmv
2454       CALL perct_regression( pmvs, clo, perct_ij )
2455       IF ( sult_lim < 99.0_wp )  THEN
2456          IF ( (perct_ij - ptc) > sult_lim )  sultrieness = .TRUE.
2457!
2458!--       Set factor to threshold for sultriness
2459          IF ( ABS( dgtcstd ) > 0.00001_wp )  THEN
2460             d_std = ( ( perct_ij - ptc ) - dgtcm ) / dgtcstd
2461          ENDIF
2462       ENDIF
2463    ENDIF
2464
2465 END SUBROUTINE calculate_perct_static
2466
2467!--------------------------------------------------------------------------------------------------!
2468! Description:
2469! ------------
2470!> The SUBROUTINE calculates the (saturation) water vapour pressure (hPa = hecto Pascal) for a given
2471!> temperature ta (degC).
2472!>'ta' can be the air temperature or the dew point temperature. The first will result in the current
2473!> vapor pressure (hPa), the latter will calulate the saturation vapor pressure (hPa).
2474!--------------------------------------------------------------------------------------------------!
2475 SUBROUTINE saturation_vapor_pressure( ta, svp_ta )
2476
2477    IMPLICIT NONE
2478
2479    REAL(wp), INTENT ( IN )  ::  ta     !< ambient air temperature (degC)
2480    REAL(wp), INTENT ( OUT ) ::  svp_ta !< water vapour pressure (hPa)
2481
2482    REAL(wp)      ::  b
2483    REAL(wp)      ::  c
2484
2485
2486    IF ( ta < 0.0_wp )  THEN
2487!
2488!--    ta  < 0 (degC): water vapour pressure over ice
2489       b = 17.84362_wp
2490       c = 245.425_wp
2491    ELSE
2492!
2493!--    ta >= 0 (degC): water vapour pressure over water
2494       b = 17.08085_wp
2495       c = 234.175_wp
2496    ENDIF
2497!
2498!-- Saturation water vapour pressure
2499    svp_ta = 6.1078_wp * EXP( b * ta / ( c + ta ) )
2500
2501 END SUBROUTINE saturation_vapor_pressure
2502
2503!--------------------------------------------------------------------------------------------------!
2504! Description:
2505! ------------
2506!> Find the clothing insulation value clo_res (clo) to make Fanger's Predicted Mean Vote (PMV) equal
2507!> comfort (pmva=0) for actual meteorological conditions (ta,tmrt, vp, ws, pair) and values of
2508!> individual's activity level.
2509!--------------------------------------------------------------------------------------------------!
2510 SUBROUTINE iso_ridder( ta, tmrt, vp, ws, pair, actlev, eta, sclo, pmv_s, wclo, pmv_w, eps, pmva,  &
2511                        nerr, clo_res )
2512
2513    IMPLICIT NONE
2514!
2515!-- Input variables of argument list:
2516    REAL(wp), INTENT ( IN )  :: actlev   !< Individuals activity level per unit surface area (W/m2)
2517    REAL(wp), INTENT ( IN )  :: eps      !< (0.05) accuracy in clothing insulation (clo) for evaluation the root of Fanger's PMV (pmva=0)
2518    REAL(wp), INTENT ( IN )  :: eta      !< Individuals work efficiency (dimensionless)
2519    REAL(wp), INTENT ( IN )  :: pair     !< Barometric air pressure (hPa)
2520    REAL(wp), INTENT ( IN )  :: pmv_s    !< Fanger's PMV corresponding to sclo
2521    REAL(wp), INTENT ( IN )  :: pmv_w    !< Fanger's PMV corresponding to wclo
2522    REAL(wp), INTENT ( IN )  :: sclo     !< Lower threshold of bracketing clothing insulation (clo)
2523    REAL(wp), INTENT ( IN )  :: ta       !< Ambient temperature (degC)
2524    REAL(wp), INTENT ( IN )  :: tmrt     !< Mean radiant temperature (degC)
2525    REAL(wp), INTENT ( IN )  :: vp       !< Water vapour pressure (hPa)
2526    REAL(wp), INTENT ( IN )  :: wclo     !< Upper threshold of bracketing clothing insulation (clo)
2527    REAL(wp), INTENT ( IN )  :: ws       !< Wind speed (m/s) 1 m above ground
2528!
2529!-- Output variables of argument list:
2530    INTEGER(iwp), INTENT ( OUT ) :: nerr !< Error status / quality flag
2531                                         !< nerr >= 0, o.k., and nerr is the number of iterations for convergence
2532                                         !< nerr = -1: error = malfunction of Ridder's convergence method
2533                                         !< nerr = -2: error = maximum iterations (max_iteration) exceeded
2534                                         !< nerr = -3: error = root not bracketed between sclo and wclo
2535
2536    REAL(wp), INTENT ( OUT ) :: clo_res  !< Resulting clothing insulation value (clo)
2537    REAL(wp), INTENT ( OUT ) :: pmva     !< 0 (set to zero, because clo is evaluated for comfort)
2538!
2539!-- Type of program variables
2540    INTEGER(iwp), PARAMETER  ::  max_iteration = 15_iwp       !< max number of iterations
2541
2542    REAL(wp),     PARAMETER  ::  guess_0       = -1.11e30_wp  !< initial guess
2543
2544    INTEGER(iwp) ::  j       !< running index
2545
2546    REAL(wp) ::  clo_lower   !< lower limit of clothing insulation      (clo)
2547    REAL(wp) ::  clo_upper   !< upper limit of clothing insulation      (clo)
2548    REAL(wp) ::  sroot       !< sqrt of PMV-guess
2549    REAL(wp) ::  x_average   !< average of x_lower and x_upper          (clo)
2550    REAL(wp) ::  x_lower     !< lower guess for clothing insulation     (clo)
2551    REAL(wp) ::  x_new       !< preliminary result for clothing insulation (clo)
2552    REAL(wp) ::  x_ridder    !< current guess for clothing insulation   (clo)
2553    REAL(wp) ::  x_upper     !< upper guess for clothing insulation     (clo)
2554    REAL(wp) ::  y_average   !< average of y_lower and y_upper
2555    REAL(wp) ::  y_new       !< preliminary result for pred. mean vote
2556    REAL(wp) ::  y_lower     !< predicted mean vote for summer clothing
2557    REAL(wp) ::  y_upper     !< predicted mean vote for winter clothing
2558!
2559!-- Initialise
2560    nerr    = 0_iwp
2561!
2562!-- Set pmva = 0 (comfort): Root of PMV depending on clothing insulation
2563    x_ridder    = bio_fill_value
2564    pmva        = 0.0_wp
2565    clo_lower   = sclo
2566    y_lower     = pmv_s
2567    clo_upper   = wclo
2568    y_upper     = pmv_w
2569    IF ( ( y_lower > 0.0_wp .AND. y_upper < 0.0_wp )  .OR.                                         &
2570         ( y_lower < 0.0_wp .AND. y_upper > 0.0_wp ) )  THEN
2571       x_lower  = clo_lower
2572       x_upper  = clo_upper
2573       x_ridder = guess_0
2574
2575       DO  j = 1_iwp, max_iteration
2576          x_average = 0.5_wp * ( x_lower + x_upper )
2577          CALL fanger ( ta, tmrt, vp, ws, pair, x_average, actlev, eta, y_average )
2578          sroot = SQRT( y_average**2 - y_lower * y_upper )
2579          IF ( ABS( sroot ) < 0.00001_wp )  THEN
2580             clo_res = x_average
2581             nerr = j
2582             RETURN
2583          ENDIF
2584          x_new = x_average + ( x_average - x_lower ) *                                            &
2585                  ( SIGN ( 1.0_wp, y_lower - y_upper ) * y_average / sroot )
2586          IF ( ABS( x_new - x_ridder ) <= eps )  THEN
2587             clo_res = x_ridder
2588             nerr       = j
2589             RETURN
2590          ENDIF
2591          x_ridder = x_new
2592          CALL fanger ( ta, tmrt, vp, ws, pair, x_ridder, actlev, eta, y_new )
2593          IF ( ABS( y_new ) < 0.00001_wp )  THEN
2594             clo_res = x_ridder
2595             nerr       = j
2596             RETURN
2597          ENDIF
2598          IF ( ABS( SIGN( y_average, y_new ) - y_average ) > 0.00001_wp )  THEN
2599             x_lower = x_average
2600             y_lower = y_average
2601             x_upper  = x_ridder
2602             y_upper  = y_new
2603          ELSE IF ( ABS( SIGN( y_lower, y_new ) - y_lower ) > 0.00001_wp )  THEN
2604             x_upper  = x_ridder
2605             y_upper  = y_new
2606          ELSE IF ( ABS( SIGN( y_upper, y_new ) - y_upper ) > 0.00001_wp )  THEN
2607             x_lower = x_ridder
2608             y_lower = y_new
2609          ELSE
2610!
2611!--          Never get here in x_ridder: SINgularity in y
2612             nerr    = -1_iwp
2613             clo_res = x_ridder
2614             RETURN
2615          ENDIF
2616          IF ( ABS( x_upper - x_lower ) <= eps )  THEN
2617             clo_res = x_ridder
2618             nerr    = j
2619             RETURN
2620          ENDIF
2621       ENDDO
2622!
2623!--    x_ridder exceed maximum iterations
2624       nerr       = -2_iwp
2625       clo_res = y_new
2626       RETURN
2627    ELSE IF ( ABS( y_lower ) < 0.00001_wp )  THEN
2628       x_ridder = clo_lower
2629    ELSE IF ( ABS( y_upper ) < 0.00001_wp )  THEN
2630       x_ridder = clo_upper
2631    ELSE
2632!
2633!--    x_ridder not bracketed by u_clo and o_clo
2634       nerr = -3_iwp
2635       clo_res = x_ridder
2636       RETURN
2637    ENDIF
2638
2639 END SUBROUTINE iso_ridder
2640
2641!--------------------------------------------------------------------------------------------------!
2642! Description:
2643! ------------
2644!> Regression relations between perceived temperature (perct) and (adjusted) PMV. The regression
2645!> presumes the Klima-Michel settings for reference individual and reference environment.
2646!--------------------------------------------------------------------------------------------------!
2647 SUBROUTINE perct_regression( pmv, clo, perct_ij )
2648
2649    IMPLICIT NONE
2650
2651    REAL(wp), INTENT ( IN ) ::  clo   !< clothing insulation index (clo)
2652    REAL(wp), INTENT ( IN ) ::  pmv   !< Fangers predicted mean vote (dimensionless)
2653
2654    REAL(wp), INTENT ( OUT ) ::  perct_ij   !< perct (degC) corresponding to given PMV / clo
2655
2656    IF ( pmv <= - 0.11_wp )  THEN
2657       perct_ij = 5.805_wp + 12.6784_wp * pmv
2658    ELSE
2659       IF ( pmv >= + 0.01_wp )  THEN
2660          perct_ij = 16.826_wp + 6.163_wp * pmv
2661       ELSE
2662          perct_ij = 21.258_wp - 9.558_wp * clo
2663       ENDIF
2664    ENDIF
2665
2666 END SUBROUTINE perct_regression
2667
2668!--------------------------------------------------------------------------------------------------!
2669! Description:
2670! ------------
2671!> FANGER.F90
2672!>
2673!> SI-VERSION: ACTLEV W m-2, VAPOUR PRESSURE hPa
2674!> Calculates the current Predicted Mean Vote according to Fanger.
2675!> The case of free convection (ws < 0.1 m/s) is dealt with ws = 0.1 m/s
2676!--------------------------------------------------------------------------------------------------!
2677 SUBROUTINE fanger( ta, tmrt, pa, in_ws, pair, in_clo, actlev, eta, pmva )
2678
2679    IMPLICIT NONE
2680!
2681!-- Input variables of argument list:
2682    REAL(wp), INTENT ( IN ) ::  actlev   !< Individuals activity level per unit surface area (W/m2)
2683    REAL(wp), INTENT ( IN ) ::  eta      !< Individuals mechanical work efficiency (dimensionless)
2684    REAL(wp), INTENT ( IN ) ::  in_clo   !< Clothing insulation (clo)
2685    REAL(wp), INTENT ( IN ) ::  in_ws    !< Wind speed (m/s) 1 m above ground
2686    REAL(wp), INTENT ( IN ) ::  pa       !< Water vapour pressure (hPa)
2687    REAL(wp), INTENT ( IN ) ::  pair     !< Barometric pressure (hPa) at site
2688    REAL(wp), INTENT ( IN ) ::  ta       !< Ambient air temperature (degC)
2689    REAL(wp), INTENT ( IN ) ::  tmrt     !< Mean radiant temperature (degC)
2690
2691!
2692!-- Output variables of argument list:
2693    REAL(wp), INTENT ( OUT ) ::  pmva    !< Actual Predicted Mean Vote (PMV,
2694                                         !< dimensionless) according to Fanger corresponding to meteorological
2695                                         !< (ta,tmrt,pa,ws,pair) and individual variables (clo, actlev, eta)
2696!
2697!-- Internal variables
2698    INTEGER(iwp) :: i         !< running index
2699
2700    REAL(wp) ::  activity     !< persons activity  (must stay == actlev, W)
2701    REAL(wp) ::  bc           !< preliminary result storage
2702    REAL(wp) ::  cc           !< preliminary result storage
2703    REAL(wp) ::  clo          !< clothing insulation index              (clo)
2704    REAL(wp) ::  dc           !< preliminary result storage
2705    REAL(wp) ::  ec           !< preliminary result storage
2706    REAL(wp) ::  f_cl         !< Increase in surface due to clothing    (factor)
2707    REAL(wp) ::  gc           !< preliminary result storage
2708    REAL(wp) ::  heat_convection  !< energy loss by autocnvection       (W)
2709    REAL(wp) ::  hr           !< radiational heat resistence
2710    REAL(wp) ::  t_clothing   !< clothing temperature                   (degree_C)
2711    REAL(wp) ::  t_skin_aver  !< average skin temperature               (degree_C)
2712    REAL(wp) ::  ws           !< wind speed                             (m/s)
2713    REAL(wp) ::  z1           !< Empiric factor for the adaption of the heat
2714                              !< ballance equation to the psycho-physical scale (Equ. 40 in FANGER)
2715    REAL(wp) ::  z2           !< Water vapour diffution through the skin
2716    REAL(wp) ::  z3           !< Sweat evaporation from the skin surface
2717    REAL(wp) ::  z4           !< Loss of latent heat through respiration
2718    REAL(wp) ::  z5           !< Loss of radiational heat
2719    REAL(wp) ::  z6           !< Heat loss through forced convection
2720
2721!
2722!-- Clo must be > 0. to avoid div. by 0!
2723    clo = in_clo
2724    IF ( clo <= 0.0_wp )  clo = .001_wp
2725!
2726!-- f_cl = increase in surface due to clothing
2727    f_cl = 1.0_wp + 0.15_wp * clo
2728!
2729!-- Case of free convection (ws < 0.1 m/s ) not considered
2730    ws = in_ws
2731    IF ( ws < 0.1_wp )  THEN
2732       ws = 0.1_wp
2733    ENDIF
2734!
2735!-- Heat_convection = forced convection
2736    heat_convection = 12.1_wp * SQRT( ws * pair / 1013.25_wp )
2737!
2738!-- Activity = inner heat production per standardized surface
2739    activity = actlev * ( 1.0_wp - eta )
2740!
2741!-- t_skin_aver = average skin temperature
2742    t_skin_aver = 35.7_wp - 0.0275_wp * activity
2743!
2744!-- Calculation of constants for evaluation below
2745    bc = 0.155_wp * clo * 3.96_wp * 10.0_wp**( -8 ) * f_cl
2746    cc = f_cl * heat_convection
2747    ec = 0.155_wp * clo
2748    dc = ( 1.0_wp + ec * cc ) / bc
2749    gc = ( t_skin_aver + bc * ( tmrt + degc_to_k )**4 + ec * cc * ta ) / bc
2750!
2751!-- Calculation of clothing surface temperature (t_clothing) based on Newton-approximation with air
2752!-- temperature as initial guess.
2753    t_clothing = ta
2754    DO  i = 1, 3
2755       t_clothing = t_clothing - ( ( t_clothing + degc_to_k )**4 + t_clothing * dc - gc ) /        &
2756                    ( 4.0_wp * ( t_clothing + degc_to_k )**3 + dc )
2757    ENDDO
2758!
2759!-- Empiric factor for the adaption of the heat ballance equation to the psycho-physical scale (Equ.
2760!-- 40 in FANGER)
2761    z1 = ( 0.303_wp * EXP( - 0.036_wp * actlev ) + 0.0275_wp )
2762!
2763!-- Water vapour diffution through the skin
2764    z2 = 0.31_wp * ( 57.3_wp - 0.07_wp * activity-pa )
2765!
2766!-- Sweat evaporation from the skin surface
2767    z3 = 0.42_wp * ( activity - 58.0_wp )
2768!
2769!-- Loss of latent heat through respiration
2770    z4 = 0.0017_wp * actlev * ( 58.7_wp - pa ) + 0.0014_wp * actlev *                              &
2771         ( 34.0_wp - ta )
2772!
2773!-- Loss of radiational heat
2774    z5 = 3.96e-8_wp * f_cl * ( ( t_clothing + degc_to_k )**4 - ( tmrt + degc_to_k )**4 )
2775    IF ( ABS( t_clothing - tmrt ) > 0.0_wp )  THEN
2776       hr = z5 / f_cl / ( t_clothing - tmrt )
2777    ELSE
2778       hr = 0.0_wp
2779    ENDIF
2780!
2781!-- Heat loss through forced convection cc*(t_clothing-TT)
2782    z6 = cc * ( t_clothing - ta )
2783!
2784!-- Predicted Mean Vote
2785    pmva = z1 * ( activity - z2 - z3 - z4 - z5 - z6 )
2786
2787 END SUBROUTINE fanger
2788
2789!--------------------------------------------------------------------------------------------------!
2790! Description:
2791! ------------
2792!> For pmva > 0 and clo =0.5 the increment (deltapmv) is calculated that converts pmva into Gagge's
2793!> et al. (1986) PMV*.
2794!--------------------------------------------------------------------------------------------------!
2795 REAL(wp) FUNCTION deltapmv( pmva, ta, vp, svp_ta, tmrt, ws, nerr )
2796
2797    IMPLICIT NONE
2798
2799!
2800!-- Input variables of argument list:
2801    REAL(wp),     INTENT ( IN )  :: pmva     !< Actual Predicted Mean Vote (PMV) according to Fanger
2802    REAL(wp),     INTENT ( IN )  :: svp_ta   !< Saturation water vapour pressure (hPa) at ta
2803    REAL(wp),     INTENT ( IN )  :: ta       !< Ambient temperature (degC) at screen level
2804    REAL(wp),     INTENT ( IN )  :: tmrt     !< Mean radiant temperature (degC) at screen level
2805    REAL(wp),     INTENT ( IN )  :: vp       !< Water vapour pressure (hPa) at screen level
2806    REAL(wp),     INTENT ( IN )  :: ws       !< Wind speed (m/s) 1 m above ground
2807
2808!
2809!-- Output variables of argument list:
2810    INTEGER(iwp), INTENT ( OUT ) :: nerr     !< Error status / quality flag
2811                                             !<  0 = o.k.
2812                                             !< -2 = pmva outside valid regression range
2813                                             !< -3 = rel. humidity set to 5 % or 95 %, respectively
2814                                             !< -4 = deltapmv set to avoid pmvs < 0
2815
2816!
2817!-- Internal variables:
2818    INTEGER(iwp) :: nreg      !<
2819
2820    REAL(wp) ::  apa          !< natural logarithm of pa (with hard lower border)
2821    REAL(wp) ::  dapa         !< difference of apa and pa_p50
2822    REAL(wp) ::  dpmv_1       !<
2823    REAL(wp) ::  dpmv_2       !<
2824    REAL(wp) ::  dtmrt        !< difference mean radiation to air temperature
2825    REAL(wp) ::  pa           !< vapor pressure (hPa) with hard bounds
2826    REAL(wp) ::  pa_p50       !< ratio actual water vapour pressure to that of relative humidity of
2827                              !< 50 %
2828    REAL(wp) ::  pmv          !< temp storage og predicted mean vote
2829    REAL(wp) ::  pmvs         !<
2830    REAL(wp) ::  p10          !< lower bound for pa
2831    REAL(wp) ::  p95          !< upper bound for pa
2832    REAL(wp) ::  sqvel        !< square root of local wind velocity
2833    REAL(wp) ::  weight       !<
2834    REAL(wp) ::  weight2      !<
2835
2836!
2837!-- Regression coefficients:
2838    REAL(wp), DIMENSION(0:7), PARAMETER ::  bpmv = (/                                              &
2839     - 0.0556602_wp, - 0.1528680_wp, - 0.2336104_wp, - 0.2789387_wp,                               &
2840     - 0.3551048_wp, - 0.4304076_wp, - 0.4884961_wp, - 0.4897495_wp /)
2841
2842    REAL(wp), DIMENSION(0:7), PARAMETER ::  bpa_p50 = (/                                           &
2843     - 0.1607154_wp, - 0.4177296_wp, - 0.4120541_wp, - 0.0886564_wp,                               &
2844       0.4285938_wp,   0.6281256_wp,   0.5067361_wp,   0.3965169_wp /)
2845
2846    REAL(wp), DIMENSION(0:7), PARAMETER ::  bpa = (/                                               &
2847       0.0580284_wp,   0.0836264_wp,   0.1009919_wp,   0.1020777_wp,                               &
2848       0.0898681_wp,   0.0839116_wp,   0.0853258_wp,   0.0866589_wp /)
2849
2850    REAL(wp), DIMENSION(0:7), PARAMETER ::  bapa = (/                                              &
2851     - 1.7838788_wp, - 2.9306231_wp, - 1.6350334_wp,    0.6211547_wp,                              &
2852       3.3918083_wp,   5.5521025_wp,   8.4897418_wp,   16.6265851_wp /)
2853
2854    REAL(wp), DIMENSION(0:7), PARAMETER ::  bdapa = (/                                             &
2855       1.6752720_wp,   2.7379504_wp,   1.2940526_wp, -  1.0985759_wp,                              &
2856     - 3.9054732_wp, - 6.0403012_wp, - 8.9437119_wp, - 17.0671201_wp /)
2857
2858    REAL(wp), DIMENSION(0:7), PARAMETER ::  bsqvel = (/                                            &
2859     - 0.0315598_wp, - 0.0286272_wp, - 0.0009228_wp,   0.0483344_wp,                               &
2860       0.0992366_wp,   0.1491379_wp,   0.1951452_wp,   0.2133949_wp /)
2861
2862    REAL(wp), DIMENSION(0:7), PARAMETER ::  bta = (/                                               &
2863       0.0953986_wp,   0.1524760_wp,   0.0564241_wp, - 0.0893253_wp,                               &
2864     - 0.2398868_wp, - 0.3515237_wp, - 0.5095144_wp, - 0.9469258_wp /)
2865
2866    REAL(wp), DIMENSION(0:7), PARAMETER ::  bdtmrt = (/                                            &
2867     - 0.0004672_wp, - 0.0000514_wp, - 0.0018037_wp, - 0.0049440_wp,                               &
2868     - 0.0069036_wp, - 0.0075844_wp, - 0.0079602_wp, - 0.0089439_wp /)
2869
2870    REAL(wp), DIMENSION(0:7), PARAMETER ::  aconst = (/                                            &
2871       1.8686215_wp,   3.4260713_wp,    2.0116185_wp, -  0.7777552_wp,                             &
2872     - 4.6715853_wp, - 7.7314281_wp, - 11.7602578_wp, - 23.5934198_wp /)
2873
2874
2875!
2876!-- Test for compliance with regression range
2877    IF ( pmva < -1.0_wp  .OR.  pmva > 7.0_wp )  THEN
2878       nerr = -2_iwp
2879    ELSE
2880       nerr = 0_iwp
2881    ENDIF
2882!
2883!-- Initialise classic PMV
2884    pmv  = pmva
2885!
2886!-- Water vapour pressure of air
2887    p10  = 0.05_wp * svp_ta
2888    p95  = 1.00_wp * svp_ta
2889    IF ( vp >= p10  .AND.  vp <= p95 )  THEN
2890       pa = vp
2891    ELSE
2892       nerr = -3_iwp
2893       IF ( vp < p10 )  THEN
2894!
2895!--       Due to conditions of regression: r.H. >= 5 %
2896          pa = p10
2897       ELSE
2898!
2899!--       Due to conditions of regression: r.H. <= 95 %
2900          pa = p95
2901       ENDIF
2902    ENDIF
2903    IF ( pa > 0.0_wp )  THEN
2904!
2905!--    Natural logarithm of pa
2906       apa = LOG( pa )
2907    ELSE
2908       apa = -5.0_wp
2909    ENDIF
2910!
2911!-- Ratio actual water vapour pressure to that of a r.H. of 50 %
2912    pa_p50   = 0.5_wp * svp_ta
2913    IF ( pa_p50 > 0.0_wp  .AND.  pa > 0.0_wp )  THEN
2914       dapa   = apa - LOG( pa_p50 )
2915       pa_p50 = pa / pa_p50
2916    ELSE
2917       dapa   = -5.0_wp
2918       pa_p50 = 0.0_wp
2919    ENDIF
2920!
2921!-- Square root of wind velocity
2922    IF ( ws >= 0.0_wp )  THEN
2923       sqvel = SQRT( ws )
2924    ELSE
2925       sqvel = 0.0_wp
2926    ENDIF
2927!
2928!-- Difference mean radiation to air temperature
2929    dtmrt = tmrt - ta
2930!
2931!-- Select the valid regression coefficients
2932    nreg = INT( pmv )
2933    IF ( nreg < 0_iwp )  THEN
2934!
2935!--    Value of the FUNCTION in the case pmv <= -1
2936       deltapmv = 0.0_wp
2937       RETURN
2938    ENDIF
2939    weight = MOD ( pmv, 1.0_wp )
2940    IF ( weight < 0.0_wp )  weight = 0.0_wp
2941    IF ( nreg > 5_iwp )  THEN
2942       nreg  = 5_iwp
2943       weight   = pmv - 5.0_wp
2944       weight2  = pmv - 6.0_wp
2945       IF ( weight2 > 0_iwp )  THEN
2946          weight = ( weight - weight2 ) / weight
2947       ENDIF
2948    ENDIF
2949!
2950!-- Regression valid for 0. <= pmv <= 6., bounds are checked above
2951    dpmv_1 =                                                                                       &
2952             + bpa(nreg)     * pa                                                                  &
2953             + bpmv(nreg)    * pmv                                                                 &
2954             + bapa(nreg)    * apa                                                                 &
2955             + bta(nreg)     * ta                                                                  &
2956             + bdtmrt(nreg)  * dtmrt                                                               &
2957             + bdapa(nreg)   * dapa                                                                &
2958             + bsqvel(nreg)  * sqvel                                                               &
2959             + bpa_p50(nreg) * pa_p50                                                              &
2960             + aconst(nreg)
2961
2962!    dpmv_2 = 0.0_wp
2963!    IF ( nreg < 6_iwp )  THEN  !< nreg is always <= 5, see above
2964    dpmv_2 =                                                                                       &
2965             + bpa(nreg+1_iwp)     * pa                                                            &
2966             + bpmv(nreg+1_iwp)    * pmv                                                           &
2967             + bapa(nreg+1_iwp)    * apa                                                           &
2968             + bta(nreg+1_iwp)     * ta                                                            &
2969             + bdtmrt(nreg+1_iwp)  * dtmrt                                                         &
2970             + bdapa(nreg+1_iwp)   * dapa                                                          &
2971             + bsqvel(nreg+1_iwp)  * sqvel                                                         &
2972             + bpa_p50(nreg+1_iwp) * pa_p50                                                        &
2973             + aconst(nreg+1_iwp)
2974!    ENDIF
2975!
2976!-- Calculate pmv modification
2977    deltapmv = ( 1.0_wp - weight ) * dpmv_1 + weight * dpmv_2
2978    pmvs = pmva + deltapmv
2979    IF ( ( pmvs ) < 0.0_wp )  THEN
2980!
2981!--    Prevent negative pmv* due to problems with clothing insulation
2982       nerr = -4_iwp
2983       IF ( pmvs > -0.11_wp )  THEN
2984!
2985!--       Threshold from perct_regression for winter clothing insulation
2986          deltapmv = deltapmv + 0.11_wp
2987       ELSE
2988!
2989!--       Set pmvs to "0" for compliance with summer clothing insulation
2990          deltapmv = -1.0_wp * pmva
2991       ENDIF
2992    ENDIF
2993
2994 END FUNCTION deltapmv
2995
2996!--------------------------------------------------------------------------------------------------!
2997! Description:
2998! ------------
2999!> The subroutine "calc_sultr" returns a threshold value to perceived temperature allowing to decide
3000!> whether the actual perceived temperature is linked to perecption of sultriness. The threshold
3001!> values depends on the Fanger's classical PMV, expressed here as perceived temperature perct.
3002!--------------------------------------------------------------------------------------------------!
3003 SUBROUTINE calc_sultr( perct_ij, dperctm, dperctstd, sultr_res )
3004
3005    IMPLICIT NONE
3006!
3007!-- Input of the argument list:
3008    REAL(wp), INTENT ( IN )  ::  perct_ij   !< Classical perceived temperature: Base is Fanger's PMV
3009!
3010!-- Additional output variables of argument list:
3011    REAL(wp), INTENT ( OUT ) ::  dperctm    !< Mean deviation perct (classical gt) to gt* (rational
3012                                            !< gt calculated based on Gagge's rational PMV*)
3013    REAL(wp), INTENT ( OUT ) ::  dperctstd  !< dperctm plus its standard deviation times a factor
3014                                            !< determining the significance to perceive sultriness
3015    REAL(wp), INTENT ( OUT ) ::  sultr_res
3016!
3017!-- Types of coefficients mean deviation: third order polynomial
3018    REAL(wp), PARAMETER ::  dperctka =   7.5776086_wp
3019    REAL(wp), PARAMETER ::  dperctkb = - 0.740603_wp
3020    REAL(wp), PARAMETER ::  dperctkc =   0.0213324_wp
3021    REAL(wp), PARAMETER ::  dperctkd = - 0.00027797237_wp
3022!
3023!-- Types of coefficients mean deviation plus standard deviation
3024!-- regression coefficients: third order polynomial
3025    REAL(wp), PARAMETER ::  dperctsa =   0.0268918_wp
3026    REAL(wp), PARAMETER ::  dperctsb =   0.0465957_wp
3027    REAL(wp), PARAMETER ::  dperctsc = - 0.00054709752_wp
3028    REAL(wp), PARAMETER ::  dperctsd =   0.0000063714823_wp
3029!
3030!-- Factor to mean standard deviation defining SIGNificance for
3031!-- sultriness
3032    REAL(wp), PARAMETER :: faktor = 1.0_wp
3033!
3034!-- Initialise
3035    sultr_res = 99.0_wp
3036    dperctm   = 0.0_wp
3037    dperctstd = 999999.0_wp
3038
3039    IF ( perct_ij < 16.826_wp  .OR.  perct_ij > 56.0_wp )  THEN
3040!
3041!--    Unallowed value of classical perct!
3042       RETURN
3043    ENDIF
3044!
3045!-- Mean deviation dependent on perct
3046    dperctm = dperctka + dperctkb * perct_ij + dperctkc * perct_ij**2.0_wp + dperctkd *            &
3047              perct_ij**3.0_wp
3048!
3049!-- Mean deviation plus its standard deviation
3050    dperctstd = dperctsa + dperctsb * perct_ij + dperctsc * perct_ij**2.0_wp + dperctsd *          &
3051                perct_ij**3.0_wp
3052!
3053!-- Value of the FUNCTION
3054    sultr_res = dperctm + faktor * dperctstd
3055    IF ( ABS( sultr_res ) > 99.0_wp )  sultr_res = +99.0_wp
3056
3057 END SUBROUTINE calc_sultr
3058
3059!--------------------------------------------------------------------------------------------------!
3060! Description:
3061! ------------
3062!> Multiple linear regression to calculate an increment delta_cold, to adjust Fanger's classical PMV
3063!> (pmva) by Gagge's 2 node model, applying Fanger's convective heat transfer coefficient, hcf.
3064!> Wind velocitiy of the reference environment is 0.10 m/s
3065!--------------------------------------------------------------------------------------------------!
3066 SUBROUTINE dpmv_cold( pmva, ta, ws, tmrt, nerr, dpmv_cold_res )
3067
3068    IMPLICIT NONE
3069!
3070!-- Type of input arguments
3071    REAL(wp), INTENT ( IN ) ::  pmva   !< Fanger's classical predicted mean vote
3072    REAL(wp), INTENT ( IN ) ::  ta     !< Air temperature 2 m above ground (degC)
3073    REAL(wp), INTENT ( IN ) ::  tmrt   !< Mean radiant temperature (degC)
3074    REAL(wp), INTENT ( IN ) ::  ws     !< Relative wind velocity 1 m above ground (m/s)
3075!
3076!-- Type of output argument
3077    INTEGER(iwp), INTENT ( OUT ) ::  nerr !< Error indicator: 0 = o.k., +1 = denominator for
3078                                          !< intersection = 0
3079
3080    REAL(wp),     INTENT ( OUT ) ::  dpmv_cold_res    !< Increment to adjust pmva according to the
3081                                                      !< results of Gagge's 2 node model depending on the input
3082!
3083!-- Type of program variables
3084    INTEGER(iwp) ::  i          !< running index
3085    INTEGER(iwp) ::  i_bin      !< result row number
3086
3087    REAL(wp) ::  delta_cold(3)
3088    REAL(wp) ::  dtmrt          !< delta mean radiant temperature
3089    REAL(wp) ::  pmv_cross(2)
3090    REAL(wp) ::  reg_a(3)
3091    REAL(wp) ::  r_denominator  !< the regression equations denominator
3092    REAL(wp) ::  sqrt_ws        !< sqare root of wind speed
3093
3094!    REAL(wp) ::  coeff(3,5)  !< unsafe! array is (re-)writable!
3095!    coeff(1,1:5) =                                                             &
3096!       (/ +0.161_wp,   +0.130_wp, -1.125E-03_wp, +1.106E-03_wp, -4.570E-04_wp /)
3097!    coeff(2,1:5) =                                                             &
3098!       (/  0.795_wp,    0.713_wp, -8.880E-03_wp, -1.803E-03_wp, -2.816E-03_wp /)
3099!    coeff(3,1:5) =                                                             &
3100!       (/ +0.05761_wp, +0.458_wp, -1.829E-02_wp, -5.577E-03_wp, -1.970E-03_wp /)
3101
3102!
3103!-- Coefficient of the 3 regression lines:
3104!      1:const      2:*pmva    3:*ta          4:*sqrt_ws     5:*dtmrt
3105    REAL(wp), DIMENSION(1:3,1:5), PARAMETER ::  coeff = RESHAPE( (/                                &
3106        0.161_wp,   0.130_wp, -1.125E-03_wp,  1.106E-03_wp, -4.570E-04_wp,                         &
3107        0.795_wp,   0.713_wp, -8.880E-03_wp, -1.803E-03_wp, -2.816E-03_wp,                         &
3108        0.05761_wp, 0.458_wp, -1.829E-02_wp, -5.577E-03_wp, -1.970E-03_wp                          &
3109       /), SHAPE( coeff ), order=(/ 2, 1 /)                    )
3110!
3111!-- Initialise
3112    nerr           = 0_iwp
3113    dpmv_cold_res  = 0.0_wp
3114    dtmrt          = tmrt - ta
3115    sqrt_ws        = ws
3116    IF ( sqrt_ws < 0.1_wp )  THEN
3117       sqrt_ws = 0.1_wp
3118    ELSE
3119       sqrt_ws = SQRT( sqrt_ws )
3120    ENDIF
3121
3122    delta_cold = 0.0_wp
3123    pmv_cross = pmva
3124
3125!
3126!-- Determine regression constant for given meteorological conditions
3127    DO  i = 1, 3
3128       reg_a(i) = coeff(i,1) + coeff(i,3) * ta + coeff(i,4) * sqrt_ws + coeff(i,5)*dtmrt
3129       delta_cold(i) = reg_a(i) + coeff(i,2) * pmva
3130    ENDDO
3131!
3132!-- Intersection points of regression lines in terms of Fanger's PMV
3133    DO  i = 1, 2
3134       r_denominator = coeff(i,2) - coeff(i+1,2)
3135       IF ( ABS( r_denominator ) > 0.00001_wp )  THEN
3136          pmv_cross(i) = ( reg_a(i+1) - reg_a(i) ) / r_denominator
3137       ELSE
3138          nerr = 1_iwp
3139          RETURN
3140       ENDIF
3141    ENDDO
3142!
3143!-- Select result row number
3144    i_bin = 3
3145    DO  i = 1, 2
3146       IF ( pmva > pmv_cross(i) )  THEN
3147          i_bin = i
3148          EXIT
3149       ENDIF
3150    ENDDO
3151!
3152!-- Adjust to operative temperature scaled according to classical PMV (Fanger)
3153    dpmv_cold_res = delta_cold(i_bin) - dpmv_cold_adj(pmva)
3154
3155 END SUBROUTINE dpmv_cold
3156
3157!--------------------------------------------------------------------------------------------------!
3158! Description:
3159! ------------
3160!> Calculates the summand dpmv_cold_adj adjusting to the operative temperature scaled according to
3161!> classical PMV (Fanger) for cold conditions. Valid for reference environment: v (1m) = 0.10 m/s,
3162!> dTMRT = 0 K, r.h. = 50 %
3163!--------------------------------------------------------------------------------------------------!
3164 REAL(wp) FUNCTION dpmv_cold_adj( pmva )
3165
3166    IMPLICIT NONE
3167
3168    INTEGER(iwp)  ::  i       !< running index
3169    INTEGER(iwp)  ::  thr     !< thermal range
3170
3171    REAL(wp), INTENT ( IN ) ::  pmva        !< (adjusted) Predicted Mean Vote
3172
3173    REAL(wp)  ::  pmv     !< pmv-part of the regression
3174
3175!
3176!-- Provide regression coefficients for three thermal ranges:
3177!--                                                    slightly cold  cold           very cold
3178    REAL(wp), DIMENSION(1:3,0:3), PARAMETER ::  coef = RESHAPE( (/                                 &
3179                                                       0.0941540_wp, -0.1506620_wp, -0.0871439_wp, &
3180                                                       0.0783162_wp, -1.0612651_wp,  0.1695040_wp, &
3181                                                       0.1350144_wp, -1.0049144_wp, -0.0167627_wp, &
3182                                                       0.1104037_wp, -0.2005277_wp, -0.0003230_wp  &
3183                                                                 /), SHAPE(coef), order=(/ 1, 2 /) )
3184!
3185!-- Select thermal range
3186    IF ( pmva <= -2.1226_wp )  THEN     !< very cold
3187       thr = 3_iwp
3188    ELSE IF ( pmva <= -1.28_wp )  THEN  !< cold
3189       thr = 2_iwp
3190    ELSE                                !< slightly cold
3191       thr = 1_iwp
3192    ENDIF
3193!
3194!-- Initialize
3195    dpmv_cold_adj = coef(thr,0)
3196    pmv           = 1.0_wp
3197!
3198!-- Calculate pmv adjustment (dpmv_cold_adj)
3199    DO  i = 1, 3
3200       pmv           = pmv * pmva
3201       dpmv_cold_adj = dpmv_cold_adj + coef(thr,i) * pmv
3202    ENDDO
3203
3204    RETURN
3205 END FUNCTION dpmv_cold_adj
3206
3207!--------------------------------------------------------------------------------------------------!
3208! Description:
3209! ------------
3210!> Based on perceived temperature (perct) as input, ireq_neutral determines the required clothing
3211!> insulation (clo) for thermally neutral conditions (neither body cooling nor body heating). It is
3212!> related to the Klima-Michel activity level (134.682 W/m2). IREQ_neutral is only defined for perct
3213!> < 10 (degC)
3214!--------------------------------------------------------------------------------------------------!
3215 REAL(wp) FUNCTION ireq_neutral( perct_ij, ireq_minimal, nerr )
3216
3217    IMPLICIT NONE
3218!
3219!-- Type declaration of arguments
3220    INTEGER(iwp), INTENT ( OUT ) ::  nerr
3221
3222    REAL(wp),     INTENT ( IN )  ::  perct_ij
3223    REAL(wp),     INTENT ( OUT ) ::  ireq_minimal
3224!
3225!-- Type declaration for internal varables
3226    REAL(wp)                     ::  perct02
3227!
3228!-- Initialise
3229    nerr = 0_iwp
3230!
3231!-- Convert perceived temperature from basis 0.1 m/s to basis 0.2 m/s
3232    perct02 = 1.8788_wp + 0.9296_wp * perct_ij
3233!
3234!-- IREQ neutral conditions (thermal comfort)
3235    ireq_neutral = 1.62_wp - 0.0564_wp * perct02
3236!
3237!-- Regression only defined for perct <= 10 (degC)
3238    IF ( ireq_neutral < 0.5_wp )  THEN
3239       IF ( ireq_neutral < 0.48_wp )  THEN
3240          nerr = 1_iwp
3241       ENDIF
3242       ireq_neutral = 0.5_wp
3243    ENDIF
3244!
3245!-- Minimal required clothing insulation: maximal acceptable body cooling
3246    ireq_minimal = 1.26_wp - 0.0588_wp * perct02
3247    IF ( nerr > 0_iwp )  THEN
3248       ireq_minimal = ireq_neutral
3249    ENDIF
3250
3251    RETURN
3252 END FUNCTION ireq_neutral
3253
3254
3255!--------------------------------------------------------------------------------------------------!
3256! Description:
3257! ------------
3258!> The SUBROUTINE surface area calculates the surface area of the individual according to its height
3259!> (m), weight (kg), and age (y)
3260!--------------------------------------------------------------------------------------------------!
3261 SUBROUTINE surface_area( height_cm, weight, age, surf )
3262
3263    IMPLICIT NONE
3264
3265    INTEGER(iwp), INTENT(in)  ::  age
3266
3267    REAL(wp)    , INTENT(in)  ::  height_cm
3268    REAL(wp)    , INTENT(in)  ::  weight
3269
3270    REAL(wp)    , INTENT(out) ::  surf
3271
3272    REAL(wp)                  ::  height
3273
3274    height = height_cm * 100.0_wp
3275!
3276!-- According to Gehan-George, for children
3277    IF ( age < 19_iwp )  THEN
3278       IF ( age < 5_iwp )  THEN
3279          surf = 0.02667_wp * height**0.42246_wp * weight**0.51456_wp
3280          RETURN
3281       ENDIF
3282       surf = 0.03050_wp * height**0.35129_wp * weight**0.54375_wp
3283       RETURN
3284    ENDIF
3285!
3286!-- DuBois D, DuBois EF: A formula to estimate the approximate surface area if height and weight be
3287!>  known. In: Arch. Int. Med.. 17, 1916, pp. 863:871.
3288    surf = 0.007184_wp * height**0.725_wp * weight**0.425_wp
3289    RETURN
3290
3291 END SUBROUTINE surface_area
3292
3293!--------------------------------------------------------------------------------------------------!
3294! Description:
3295! ------------
3296!> The SUBROUTINE persdat calculates
3297!>  - the total internal energy production = metabolic + workload,
3298!>  - the total internal energy production for a standardized surface (actlev)
3299!>  - the DuBois - area (a_surf [m2])
3300!> from
3301!>  - the persons age (years),
3302!>  - weight (kg),
3303!>  - height (m),
3304!>  - sex (1 = male, 2 = female),
3305!>  - work load (W)
3306!> for a sample human.
3307!--------------------------------------------------------------------------------------------------!
3308 SUBROUTINE persdat( age, weight, height, sex, work, a_surf, actlev )
3309
3310    IMPLICIT NONE
3311
3312    INTEGER(iwp), INTENT(in) ::  sex
3313
3314
3315    REAL(wp), INTENT(in) ::  age
3316    REAL(wp), INTENT(in) ::  height
3317    REAL(wp), INTENT(in) ::  weight
3318    REAL(wp), INTENT(in) ::  work
3319
3320    REAL(wp), INTENT(out) ::  actlev
3321
3322    REAL(wp) ::  a_surf
3323    REAL(wp) ::  basic_heat_prod
3324    REAL(wp) ::  energy_prod
3325    REAL(wp) ::  factor
3326    REAL(wp) ::  s
3327
3328
3329    CALL surface_area( height, weight, INT( age ), a_surf )
3330    s = height * 100.0_wp / ( weight**( 1.0_wp / 3.0_wp ) )
3331    factor = 1.0_wp + .004_wp  * ( 30.0_wp - age )
3332    basic_heat_prod = 0.0_wp
3333    IF ( sex == 1_iwp )  THEN
3334       basic_heat_prod = 3.45_wp * weight**( 3.0_wp / 4.0_wp ) * ( factor + 0.01_wp                &
3335                         * ( s - 43.4_wp ) )
3336    ELSE IF ( sex == 2_iwp )  THEN
3337       basic_heat_prod = 3.19_wp * weight**( 3.0_wp / 4.0_wp ) * ( factor + 0.018_wp               &
3338                         * ( s - 42.1_wp ) )
3339    ENDIF
3340
3341    energy_prod = work + basic_heat_prod
3342    actlev = energy_prod / a_surf
3343
3344 END SUBROUTINE persdat
3345
3346
3347!--------------------------------------------------------------------------------------------------!
3348! Description:
3349! ------------
3350!> SUBROUTINE ipt_init
3351!> initializes the instationary perceived temperature
3352!--------------------------------------------------------------------------------------------------!
3353
3354 SUBROUTINE ipt_init( age, weight, height, sex, work, actlev, clo, ta, vp, ws, tmrt, pair, dt,     &
3355                      storage, t_clothing, ipt )
3356
3357    IMPLICIT NONE
3358!
3359!-- Input parameters
3360
3361    INTEGER(iwp), INTENT(in)  :: sex    !< Persons sex (1 = male, 2 = female)
3362
3363    REAL(wp), INTENT(in) ::  age        !< Persons age          (years)
3364    REAL(wp), INTENT(in) ::  dt         !< Timestep             (s)
3365    REAL(wp), INTENT(in) ::  height     !< Persons height       (m)7
3366    REAL(wp), INTENT(in) ::  pair       !< Air pressure         (hPa)
3367    REAL(wp), INTENT(in) ::  ta         !< Air Temperature      (degree_C)
3368    REAL(wp), INTENT(in) ::  tmrt       !< Mean radiant temperature   (degree_C)
3369    REAL(wp), INTENT(in) ::  vp         !< Vapor pressure       (hPa)
3370    REAL(wp), INTENT(in) ::  weight     !< Persons weight       (kg)
3371    REAL(wp), INTENT(in) ::  work       !< Current workload     (W)
3372    REAL(wp), INTENT(in) ::  ws         !< Wind speed in approx. 1.1m (m/s)
3373!
3374!-- Output parameters
3375    REAL(wp), INTENT(out) ::  actlev
3376    REAL(wp), INTENT(out) ::  clo
3377    REAL(wp), INTENT(out) ::  ipt
3378    REAL(wp), INTENT(out) ::  storage
3379    REAL(wp), INTENT(out) ::  t_clothing
3380!
3381!-- Internal variables
3382    REAL(wp), PARAMETER :: eps = 0.0005_wp
3383    REAL(wp), PARAMETER :: eta = 0.0_wp
3384
3385    INTEGER(iwp) ::  ncount
3386    INTEGER(iwp) ::  nerr_cold
3387    INTEGER(iwp) ::  nerr
3388
3389    LOGICAL ::  sultrieness
3390
3391!    REAL(wp) ::  acti
3392    REAL(wp) ::  a_surf
3393!    REAL(wp) ::  clo_fanger
3394    REAL(wp) ::  clon
3395    REAL(wp) ::  d_pmv
3396    REAL(wp) ::  d_std
3397    REAL(wp) ::  dgtcm
3398    REAL(wp) ::  dgtcstd
3399    REAL(wp) ::  ireq_minimal
3400    REAL(wp) ::  pmv_s
3401    REAL(wp) ::  pmv_w
3402    REAL(wp) ::  pmva
3403    REAL(wp) ::  pmvs
3404    REAL(wp) ::  ptc
3405    REAL(wp) ::  sclo
3406    REAL(wp) ::  sult_lim
3407    REAL(wp) ::  svp_ta
3408    REAL(wp) ::  wclo
3409
3410
3411    storage = 0.0_wp
3412    CALL persdat( age, weight, height, sex, work, a_surf, actlev )
3413!
3414!-- Initialise
3415    t_clothing = bio_fill_value
3416    ipt        = bio_fill_value
3417    nerr       = 0_wp
3418    ncount     = 0_wp
3419    sultrieness    = .FALSE.
3420!
3421!-- Tresholds: clothing insulation (account for model inaccuracies)
3422!-- Summer clothing
3423    sclo     = 0.44453_wp
3424!-- Winter clothing
3425    wclo     = 1.76267_wp
3426!
3427!-- Decision: firstly calculate for winter or summer clothing
3428    IF ( ta <= 10.0_wp )  THEN
3429!
3430!--    First guess: winter clothing insulation: cold stress
3431       clo = wclo
3432       t_clothing = bio_fill_value  ! force initial run
3433       CALL fanger_s_acti ( ta, tmrt, vp, ws, pair, clo, actlev, work, t_clothing, storage, dt,    &
3434                            pmva )
3435       pmv_w = pmva
3436
3437       IF ( pmva > 0.0_wp )  THEN
3438!
3439!--       Case summer clothing insulation: heat load ?
3440          clo = sclo
3441          t_clothing = bio_fill_value  ! force initial run
3442          CALL fanger_s_acti ( ta, tmrt, vp, ws, pair, clo, actlev, work, t_clothing, storage, dt, &
3443                               pmva )
3444          pmv_s = pmva
3445          IF ( pmva <= 0.0_wp )  THEN
3446!
3447!--          Case: comfort achievable by varying clothing insulation between winter and summer set
3448!--                values
3449             CALL iso_ridder ( ta, tmrt, vp, ws, pair, actlev, eta , sclo, pmv_s, wclo, pmv_w, eps,&
3450                               pmva, ncount, clo )
3451             IF ( ncount < 0_iwp )  THEN
3452                nerr = -1_iwp
3453                RETURN
3454             ENDIF
3455          ELSE IF ( pmva > 0.06_wp )  THEN
3456             clo = 0.5_wp
3457             t_clothing = bio_fill_value
3458             CALL fanger_s_acti ( ta, tmrt, vp, ws, pair, clo, actlev, work, t_clothing, storage,  &
3459                                  dt, pmva )
3460          ENDIF
3461       ELSE IF ( pmva < - 0.11_wp )  THEN
3462          clo = 1.75_wp
3463          t_clothing = bio_fill_value
3464          CALL fanger_s_acti ( ta, tmrt, vp, ws, pair, clo, actlev, work, t_clothing, storage, dt, &
3465                               pmva )
3466       ENDIF
3467
3468    ELSE
3469!
3470!--    First guess: summer clothing insulation: heat load
3471       clo = sclo
3472       t_clothing = bio_fill_value
3473       CALL fanger_s_acti ( ta, tmrt, vp, ws, pair, clo, actlev, work, t_clothing, storage, dt,    &
3474                            pmva )
3475       pmv_s = pmva
3476
3477       IF ( pmva < 0.0_wp )  THEN
3478!
3479!--       Case winter clothing insulation: cold stress ?
3480          clo = wclo
3481          t_clothing = bio_fill_value
3482          CALL fanger_s_acti ( ta, tmrt, vp, ws, pair, clo, actlev, work, t_clothing, storage, dt, &
3483                               pmva )
3484          pmv_w = pmva
3485
3486          IF ( pmva >= 0.0_wp )  THEN
3487!
3488!--          Case: comfort achievable by varying clothing insulation between winter and summer set
3489!--                values
3490             CALL iso_ridder ( ta, tmrt, vp, ws, pair, actlev, eta, sclo, pmv_s, wclo, pmv_w, eps, &
3491                               pmva, ncount, clo )
3492             IF ( ncount < 0_wp )  THEN
3493                nerr = -1_iwp
3494                RETURN
3495             ENDIF
3496          ELSE IF ( pmva < - 0.11_wp )  THEN
3497             clo = 1.75_wp
3498             t_clothing = bio_fill_value
3499             CALL fanger_s_acti ( ta, tmrt, vp, ws, pair, clo, actlev, work, t_clothing, storage,  &
3500                                  dt, pmva )
3501          ENDIF
3502       ELSE IF ( pmva > 0.06_wp )  THEN
3503          clo = 0.5_wp
3504          t_clothing = bio_fill_value
3505          CALL fanger_s_acti ( ta, tmrt, vp, ws, pair, clo, actlev, work, t_clothing, storage, dt, &
3506                               pmva )
3507       ENDIF
3508
3509    ENDIF
3510!
3511!-- Determine perceived temperature by regression equation + adjustments
3512    pmvs = pmva
3513    CALL perct_regression( pmva, clo, ipt )
3514    ptc = ipt
3515    IF ( clo >= 1.75_wp  .AND.  pmva <= - 0.11_wp )  THEN
3516!
3517!--    Adjust for cold conditions according to Gagge 1986
3518       CALL dpmv_cold ( pmva, ta, ws, tmrt, nerr_cold, d_pmv )
3519       IF ( nerr_cold > 0_iwp )  nerr = -5_iwp
3520       pmvs = pmva - d_pmv
3521       IF ( pmvs > - 0.11_wp )  THEN
3522          d_pmv  = 0.0_wp
3523          pmvs   = - 0.11_wp
3524       ENDIF
3525       CALL perct_regression( pmvs, clo, ipt )
3526    ENDIF
3527!     clo_fanger = clo
3528    clon = clo
3529    IF ( clo > 0.5_wp  .AND.  ipt <= 8.73_wp )  THEN
3530!
3531!--    Required clothing insulation (ireq) is exclusively defined for perceived temperatures (ipt)
3532!--    less 10 (C) for a reference wind of 0.2 m/s according to 8.73 (C) for 0.1 m/s
3533       clon = ireq_neutral ( ipt, ireq_minimal, nerr )
3534       clo = clon
3535    ENDIF
3536    CALL calc_sultr( ptc, dgtcm, dgtcstd, sult_lim )
3537    sultrieness    = .FALSE.
3538    d_std      = - 99.0_wp
3539    IF ( pmva > 0.06_wp  .AND.  clo <= 0.5_wp )  THEN
3540!
3541!--    Adjust for warm/humid conditions according to Gagge 1986
3542       CALL saturation_vapor_pressure ( ta, svp_ta )
3543       d_pmv  = deltapmv ( pmva, ta, vp, svp_ta, tmrt, ws, nerr )
3544       pmvs   = pmva + d_pmv
3545       CALL perct_regression( pmvs, clo, ipt )
3546       IF ( sult_lim < 99.0_wp )  THEN
3547          IF ( (ipt - ptc) > sult_lim )  sultrieness = .TRUE.
3548       ENDIF
3549    ENDIF
3550
3551
3552 END SUBROUTINE ipt_init
3553
3554!--------------------------------------------------------------------------------------------------!
3555! Description:
3556! ------------
3557!> SUBROUTINE ipt_cycle
3558!> Calculates one timestep for the instationary version of perceived temperature (iPT, degree_C) for
3559!>  - standard measured/predicted meteorological values and TMRT as input;
3560!>  - regressions for determination of PT;
3561!>  - adjustment to Gagge's PMV* (2-node-model, 1986) as base of PT under warm/humid conditions
3562!>    (Icl= 0.50 clo) and under cold conditions (Icl= 1.75 clo)
3563!--------------------------------------------------------------------------------------------------!
3564 SUBROUTINE ipt_cycle( ta, vp, ws, tmrt, pair, dt, storage, t_clothing, clo, actlev, work, ipt )
3565
3566    IMPLICIT NONE
3567!
3568!-- Type of input of the argument list
3569    REAL(wp), INTENT ( IN )  ::  actlev  !< Internal heat production    (W)
3570    REAL(wp), INTENT ( IN )  ::  clo     !< Clothing index              (no dim)
3571    REAL(wp), INTENT ( IN )  ::  dt      !< Timestep                    (s)
3572    REAL(wp), INTENT ( IN )  ::  pair    !< Air pressure                (hPa)
3573    REAL(wp), INTENT ( IN )  ::  ta      !< Air temperature             (degree_C)
3574    REAL(wp), INTENT ( IN )  ::  tmrt    !< Mean radiant temperature    (degree_C)
3575    REAL(wp), INTENT ( IN )  ::  vp      !< Vapor pressure              (hPa)
3576    REAL(wp), INTENT ( IN )  ::  work    !< Mechanical work load        (W)
3577    REAL(wp), INTENT ( IN )  ::  ws      !< Wind speed                  (m/s)
3578!
3579!-- In and output parameters
3580    REAL(wp), INTENT (INOUT) ::  storage     !< Heat storage            (W)
3581    REAL(wp), INTENT (INOUT) ::  t_clothing  !< Clothig temperature     (degree_C)
3582!
3583!-- Type of output of the argument list
3584    REAL(wp), INTENT ( OUT ) ::  ipt  !< Instationary perceived temperature (degree_C)
3585!
3586!-- Type of internal variables
3587    INTEGER(iwp) ::  nerr
3588    INTEGER(iwp) ::  nerr_cold
3589
3590    LOGICAL ::  sultrieness
3591
3592    REAL(wp) ::  d_pmv
3593    REAL(wp) ::  d_std
3594    REAL(wp) ::  dgtcm
3595    REAL(wp) ::  dgtcstd
3596    REAL(wp) ::  pmva
3597    REAL(wp) ::  pmvs
3598    REAL(wp) ::  ptc
3599    REAL(wp) ::  sult_lim
3600    REAL(wp) ::  svp_ta
3601!
3602!-- Initialise
3603    ipt = bio_fill_value
3604
3605    nerr     = 0_iwp
3606    sultrieness  = .FALSE.
3607!
3608!-- Determine pmv_adjusted for current conditions
3609    CALL fanger_s_acti ( ta, tmrt, vp, ws, pair, clo, actlev, work, t_clothing, storage, dt, pmva )
3610!
3611!-- Determine perceived temperature by regression equation + adjustments
3612    CALL perct_regression( pmva, clo, ipt )
3613!
3614!-- Consider cold conditions
3615    IF ( clo >= 1.75_wp  .AND.  pmva <= -0.11_wp )  THEN
3616!
3617!--    Adjust for cold conditions according to Gagge 1986
3618       CALL dpmv_cold ( pmva, ta, ws, tmrt, nerr_cold, d_pmv )
3619       IF ( nerr_cold > 0_iwp )  nerr = -5_iwp
3620       pmvs = pmva - d_pmv
3621       IF ( pmvs > - 0.11_wp )  THEN
3622          d_pmv  = 0.0_wp
3623          pmvs   = - 0.11_wp
3624       ENDIF
3625       CALL perct_regression( pmvs, clo, ipt )
3626    ENDIF
3627!
3628!-- Consider sultriness if appropriate
3629    ptc = ipt
3630    CALL calc_sultr( ptc, dgtcm, dgtcstd, sult_lim )
3631    sultrieness = .FALSE.
3632    d_std       = - 99.0_wp
3633    IF ( pmva > 0.06_wp  .AND.  clo <= 0.5_wp )  THEN
3634!
3635!--    Adjust for warm/humid conditions according to Gagge 1986
3636       CALL saturation_vapor_pressure ( ta, svp_ta )
3637       d_pmv = deltapmv ( pmva, ta, vp, svp_ta, tmrt, ws, nerr )
3638       pmvs  = pmva + d_pmv
3639       CALL perct_regression( pmvs, clo, ipt )
3640       IF ( sult_lim < 99.0_wp )  THEN
3641          IF ( (ipt - ptc) > sult_lim )  sultrieness = .TRUE.
3642       ENDIF
3643    ENDIF
3644
3645 END SUBROUTINE ipt_cycle
3646
3647!--------------------------------------------------------------------------------------------------!
3648! Description:
3649! ------------
3650!> SUBROUTINE fanger_s calculates the actual Predicted Mean Vote (dimensionless) according to Fanger
3651!> corresponding to meteorological (ta,tmrt,pa,ws,pair) and individual variables (clo, actlev, eta)
3652!> considering a storage and clothing temperature for a given timestep.
3653!--------------------------------------------------------------------------------------------------!
3654 SUBROUTINE fanger_s_acti( ta, tmrt, pa, in_ws, pair, in_clo, actlev, activity, t_cloth, s, dt,    &
3655                           pmva )
3656
3657    IMPLICIT NONE
3658!
3659!--  Input argument types
3660    REAL(wp), INTENT ( IN )  ::  activity !< Work load                (W/m²)
3661    REAL(wp), INTENT ( IN )  ::  actlev   !< Metabolic + work energy  (W/m²)
3662    REAL(wp), INTENT ( IN )  ::  dt       !< Timestep                 (s)
3663    REAL(wp), INTENT ( IN )  ::  in_clo   !< Clothing index (clo)     (no dim)
3664    REAL(wp), INTENT ( IN )  ::  in_ws    !< Wind speed               (m/s)
3665    REAL(wp), INTENT ( IN )  ::  pa       !< Vapour pressure          (hPa)
3666    REAL(wp), INTENT ( IN )  ::  pair     !< Air pressure             (hPa)
3667    REAL(wp), INTENT ( IN )  ::  ta       !< Air temperature          (degree_C)
3668    REAL(wp), INTENT ( IN )  ::  tmrt     !< Mean radiant temperature (degree_C)
3669!
3670!-- Output argument types
3671    REAL(wp), INTENT ( OUT ) ::  pmva  !< actual Predicted Mean Vote (no dim)
3672
3673    REAL(wp), INTENT (INOUT) ::  s  !< storage var. of energy balance (W/m2)
3674    REAL(wp), INTENT (INOUT) ::  t_cloth  !< clothing temperature (degree_C)
3675!
3676!-- Internal variables
3677    REAL(wp), PARAMETER  ::  time_equil = 7200.0_wp
3678
3679    INTEGER(iwp) :: i         !< running index
3680    INTEGER(iwp) ::  niter    !< Running index
3681
3682    REAL(wp) ::  adjustrate        !< Max storage adjustment rate
3683    REAL(wp) ::  adjustrate_cloth  !< max clothing temp. adjustment rate
3684    REAL(wp) ::  bc                !< preliminary result storage
3685    REAL(wp) ::  cc                !< preliminary result storage
3686    REAL(wp) ::  clo               !< clothing insulation index              (clo)
3687    REAL(wp) ::  d_s               !< Storage delta                          (W)
3688    REAL(wp) ::  dc                !< preliminary result storage
3689    REAL(wp) ::  en                !< Energy ballance                        (W)
3690    REAL(wp) ::  ec                !< preliminary result storage
3691    REAL(wp) ::  f_cl              !< Increase in surface due to clothing    (factor)
3692    REAL(wp) ::  gc                !< preliminary result storage
3693    REAL(wp) ::  heat_convection   !< energy loss by autocnvection       (W)
3694!    REAL(wp) ::  hr                !< radiational heat resistence
3695    REAL(wp) ::  t_clothing        !< clothing temperature                   (degree_C)
3696    REAL(wp) ::  t_skin_aver       !< average skin temperature               (degree_C)
3697    REAL(wp) ::  ws                !< wind speed                             (m/s)
3698    REAL(wp) ::  z1                !< Empiric factor for the adaption of the heat
3699                                   !< ballance equation to the psycho-physical scale
3700                                   !< (Equ. 40 in FANGER)
3701    REAL(wp) ::  z2                !< Water vapour diffution through the skin
3702    REAL(wp) ::  z3                !< Sweat evaporation from the skin surface
3703    REAL(wp) ::  z4                !< Loss of latent heat through respiration
3704    REAL(wp) ::  z5                !< Loss of radiational heat
3705    REAL(wp) ::  z6                !< Heat loss through forced convection
3706
3707
3708
3709
3710!
3711!-- Clo must be > 0. to avoid div. by 0!
3712    clo = in_clo
3713    IF ( clo < 001.0_wp )  clo = 0.001_wp
3714!
3715!-- Increase in surface due to clothing
3716    f_cl = 1.0_wp + 0.15_wp * clo
3717!
3718!-- Case of free convection (ws < 0.1 m/s ) not considered
3719    ws = in_ws
3720    IF ( ws < 0.1_wp )  THEN
3721       ws = 0.1_wp
3722    ENDIF
3723!
3724!-- Heat_convection = forced convection
3725    heat_convection = 12.1_wp * SQRT( ws * pair / 1013.25_wp )
3726!
3727!-- Average skin temperature
3728    t_skin_aver = 35.7_wp - 0.0275_wp * activity
3729!
3730!-- Calculation of constants for evaluation below
3731    bc = 0.155_wp * clo * 3.96_wp * 10.0_wp**( -8.0_wp ) * f_cl
3732    cc = f_cl * heat_convection
3733    ec = 0.155_wp * clo
3734    dc = ( 1.0_wp + ec * cc ) / bc
3735    gc = ( t_skin_aver + bc * ( tmrt + 273.2_wp )**4.0_wp + ec * cc * ta ) / bc
3736!
3737!-- Calculation of clothing surface temperature (t_clothing) based on Newton-approximation with air
3738!-- temperature as initial guess
3739    niter = INT( dt * 10.0_wp, KIND=iwp )
3740    IF ( niter < 1 )  niter = 1_iwp
3741    adjustrate = 1.0_wp - EXP( -1.0_wp * ( 10.0_wp / time_equil ) * dt )
3742    IF ( adjustrate >= 1.0_wp )  adjustrate = 1.0_wp
3743    adjustrate_cloth = adjustrate * 30.0_wp
3744    t_clothing = t_cloth
3745!
3746!-- Set initial values for niter, adjustrates and t_clothing if this is the first call
3747    IF ( t_cloth <= -998.0_wp )  THEN  ! If initial run
3748       niter = 3_iwp
3749       adjustrate = 1.0_wp
3750       adjustrate_cloth = 1.0_wp
3751       t_clothing = ta
3752    ENDIF
3753!
3754!-- Update clothing temperature
3755    DO  i = 1, niter
3756       t_clothing = t_clothing - adjustrate_cloth * ( ( t_clothing + 273.2_wp )**4.0_wp  +         &
3757                    t_clothing * dc - gc ) / ( 4.0_wp * ( t_clothing + 273.2_wp )**3.0_wp + dc )
3758    ENDDO
3759!
3760!-- Empiric factor for the adaption of the heat ballance equation to the psycho-physical scale
3761!-- (Equ. 40 in FANGER)
3762    z1 = ( 0.303_wp * EXP( - 0.036_wp * actlev ) + 0.0275_wp )
3763!
3764!-- Water vapour diffution through the skin
3765    z2 = 0.31_wp * ( 57.3_wp - 0.07_wp * activity-pa )
3766!
3767!-- Sweat evaporation from the skin surface
3768    z3 = 0.42_wp * ( activity - 58.0_wp )
3769!
3770!-- Loss of latent heat through respiration
3771    z4 = 0.0017_wp * actlev * ( 58.7_wp - pa ) + 0.0014_wp * actlev * ( 34.0_wp - ta )
3772!
3773!-- Loss of radiational heat
3774    z5 = 3.96e-8_wp * f_cl * ( ( t_clothing + 273.2_wp )**4 - ( tmrt + 273.2_wp )**4 )
3775!
3776!-- Heat loss through forced convection
3777    z6 = cc * ( t_clothing - ta )
3778!
3779!-- Write together as energy ballance
3780    en = activity - z2 - z3 - z4 - z5 - z6
3781!
3782!-- Manage storage
3783    d_s = adjustrate * en + ( 1.0_wp - adjustrate ) * s
3784!
3785!-- Predicted Mean Vote
3786    pmva = z1 * d_s
3787!
3788!-- Update storage
3789    s = d_s
3790    t_cloth = t_clothing
3791
3792 END SUBROUTINE fanger_s_acti
3793
3794
3795
3796!--------------------------------------------------------------------------------------------------!
3797!
3798! Description:
3799! ------------
3800!> Physiologically Equivalent Temperature (PET),
3801!> stationary (calculated based on MEMI),
3802!> Subroutine based on PETBER vers. 1.5.1996 by P. Hoeppe
3803!--------------------------------------------------------------------------------------------------!
3804
3805 SUBROUTINE calculate_pet_static( ta, vpa, v, tmrt, pair, pet_ij )
3806
3807    IMPLICIT NONE
3808!
3809!-- Input arguments:
3810    REAL(wp), INTENT( IN ) ::  pair  !< Air pressure                (hPa)
3811    REAL(wp), INTENT( IN ) ::  ta    !< Air temperature             (degree_C)
3812    REAL(wp), INTENT( IN ) ::  tmrt  !< Mean radiant temperature    (degree_C)
3813    REAL(wp), INTENT( IN ) ::  v     !< Wind speed                  (m/s)
3814    REAL(wp), INTENT( IN ) ::  vpa   !< Vapor pressure              (hPa)
3815!
3816!-- Output arguments:
3817    REAL(wp), INTENT ( OUT ) ::  pet_ij  !< PET                     (degree_C)
3818!
3819!-- Internal variables:
3820    REAL(wp) ::  acl        !< clothing area                        (m²)
3821    REAL(wp) ::  adu        !< Du Bois area                         (m²)
3822    REAL(wp) ::  aeff       !< effective area                       (m²)
3823    REAL(wp) ::  ere        !< energy ballance                      (W)
3824    REAL(wp) ::  erel       !< latent energy ballance               (W)
3825    REAL(wp) ::  esw        !< Energy-loss through sweat evap.      (W)
3826    REAL(wp) ::  facl       !< Surface area extension through clothing (factor)
3827    REAL(wp) ::  feff       !< Surface modification by posture      (factor)
3828    REAL(wp) ::  rdcl       !< Diffusion resistence of clothing     (factor)
3829    REAL(wp) ::  rdsk       !< Diffusion resistence of skin         (factor)
3830    REAL(wp) ::  rtv
3831    REAL(wp) ::  vpts       !< Sat. vapor pressure over skin        (hPa)
3832    REAL(wp) ::  tcl        !< Clothing temperature                 (degree_C)
3833    REAL(wp) ::  tsk        !< Skin temperature                     (degree_C)
3834    REAL(wp) ::  wetsk      !< Fraction of wet skin                 (factor)
3835!
3836!-- Variables:
3837    REAL(wp) :: int_heat    !< Internal heat        (W)
3838!
3839!-- MEMI configuration
3840    REAL(wp) :: age         !< Persons age          (a)
3841    REAL(wp) :: clo         !< Clothing insulation index (clo)
3842    REAL(wp) :: eta         !< Work efficiency      (dimensionless)
3843    REAL(wp) :: fcl         !< Surface area modification by clothing (factor)
3844    REAL(wp) :: ht          !< Persons height       (m)
3845    REAL(wp) :: mbody       !< Persons body mass    (kg)
3846    REAL(wp) :: work        !< Work load            (W)
3847!    INTEGER(iwp) :: pos     !< Posture: 1 = standing, 2 = sitting
3848!    INTEGER(iwp) :: sex     !< Sex: 1 = male, 2 = female
3849!
3850!-- Configuration, keep standard parameters!
3851    age   = 35.0_wp
3852    mbody = 75.0_wp
3853    ht    =  1.75_wp
3854    work  = 80.0_wp
3855    eta   =  0.0_wp
3856    clo   =  0.9_wp
3857    fcl   =  1.15_wp
3858!
3859!-- Call subfunctions
3860    CALL in_body( age, eta, ere, erel, ht, int_heat, mbody, pair, rtv, ta, vpa, work )
3861
3862    CALL heat_exch( acl, adu, aeff, clo, ere, erel, esw, facl, fcl, feff, ht, int_heat, mbody,     &
3863                    pair, rdcl, rdsk, ta, tcl, tmrt, tsk, v, vpa, vpts, wetsk )
3864
3865    CALL pet_iteration( acl, adu, aeff, esw, facl, feff, int_heat, pair, rdcl, rdsk, rtv, ta, tcl, &
3866                        tsk, pet_ij, vpts, wetsk )
3867
3868
3869 END SUBROUTINE calculate_pet_static
3870
3871
3872!--------------------------------------------------------------------------------------------------!
3873! Description:
3874! ------------
3875!> Calculate internal energy ballance
3876!--------------------------------------------------------------------------------------------------!
3877 SUBROUTINE in_body( age, eta, ere, erel, ht, int_heat, mbody, pair, rtv, ta, vpa, work )
3878!
3879!-- Input arguments:
3880    REAL(wp), INTENT( IN )  ::  age       !< Persons age              (a)
3881    REAL(wp), INTENT( IN )  ::  eta       !< Work efficiency     (dimensionless)
3882    REAL(wp), INTENT( IN )  ::  ht        !< Persons height           (m)
3883    REAL(wp), INTENT( IN )  ::  mbody     !< Persons body mass        (kg)
3884    REAL(wp), INTENT( IN )  ::  pair      !< air pressure             (hPa)
3885    REAL(wp), INTENT( IN )  ::  ta        !< air temperature          (degree_C)
3886    REAL(wp), INTENT( IN )  ::  vpa       !< vapor pressure           (hPa)
3887    REAL(wp), INTENT( IN )  ::  work      !< Work load                (W)
3888!
3889!-- Output arguments:
3890    REAL(wp), INTENT( OUT ) ::  ere       !< energy ballance          (W)
3891    REAL(wp), INTENT( OUT ) ::  erel      !< latent energy ballance   (W)
3892    REAL(wp), INTENT( OUT ) ::  int_heat  !< internal heat production (W)
3893    REAL(wp), INTENT( OUT ) ::  rtv       !< respiratory volume
3894!
3895!-- Internal variables:
3896    REAL(wp) ::  eres                     !< Sensible respiratory heat flux (W)
3897    REAL(wp) ::  met
3898    REAL(wp) ::  tex
3899    REAL(wp) ::  vpex
3900
3901!
3902!-- Metabolic heat production
3903    met = 3.45_wp * mbody**( 3.0_wp / 4.0_wp ) * (1.0_wp + 0.004_wp *                              &
3904          ( 30.0_wp - age) + 0.010_wp * ( ( ht * 100.0_wp /                                        &
3905          ( mbody**( 1.0_wp / 3.0_wp ) ) ) - 43.4_wp ) )
3906    met = work + met
3907    int_heat = met * (1.0_wp - eta)
3908!
3909!-- Sensible respiration energy
3910    tex  = 0.47_wp * ta + 21.0_wp
3911    rtv  = 1.44_wp * 10.0_wp**(-6.0_wp) * met
3912    eres = c_p * (ta - tex) * rtv
3913!
3914!-- Latent respiration energy
3915    vpex = 6.11_wp * 10.0_wp**( 7.45_wp * tex / ( 235.0_wp + tex ) )
3916    erel = 0.623_wp * l_v / pair * ( vpa - vpex ) * rtv
3917!
3918!-- Sum of the results
3919    ere = eres + erel
3920
3921 END SUBROUTINE in_body
3922
3923
3924!--------------------------------------------------------------------------------------------------!
3925! Description:
3926! ------------
3927!> Calculate heat gain or loss
3928!--------------------------------------------------------------------------------------------------!
3929 SUBROUTINE heat_exch( acl, adu, aeff, clo, ere, erel, esw, facl, fcl, feff, ht, int_heat, mbody,  &
3930                       pair, rdcl, rdsk, ta, tcl, tmrt, tsk, v, vpa, vpts, wetsk )
3931
3932!
3933!-- Input arguments:
3934    REAL(wp), INTENT( IN )  ::  clo    !< clothing insulation      (clo)
3935    REAL(wp), INTENT( IN )  ::  fcl    !< factor for surface area increase by clothing
3936    REAL(wp), INTENT( IN )  ::  ere    !< Energy ballance          (W)
3937    REAL(wp), INTENT( IN )  ::  erel   !< Latent energy ballance   (W)
3938    REAL(wp), INTENT( IN )  ::  ht     !< height                   (m)
3939    REAL(wp), INTENT( IN )  ::  int_heat  !< internal heat production (W)
3940    REAL(wp), INTENT( IN )  ::  mbody  !< body mass                (kg)
3941    REAL(wp), INTENT( IN )  ::  pair   !< Air pressure             (hPa)
3942    REAL(wp), INTENT( IN )  ::  ta     !< Air temperature          (degree_C)
3943    REAL(wp), INTENT( IN )  ::  tmrt   !< Mean radiant temperature (degree_C)
3944    REAL(wp), INTENT( IN )  ::  v      !< Wind speed               (m/s)
3945    REAL(wp), INTENT( IN )  ::  vpa    !< Vapor pressure           (hPa)
3946!
3947!-- Output arguments:
3948    REAL(wp), INTENT( OUT ) ::  acl    !< Clothing surface area        (m²)
3949    REAL(wp), INTENT( OUT ) ::  adu    !< Du-Bois area                 (m²)
3950    REAL(wp), INTENT( OUT ) ::  aeff   !< Effective surface area       (m²)
3951    REAL(wp), INTENT( OUT ) ::  esw    !< Energy-loss through sweat evap. (W)
3952    REAL(wp), INTENT( OUT ) ::  facl   !< Surface area extension through clothing (factor)
3953    REAL(wp), INTENT( OUT ) ::  feff   !< Surface modification by posture (factor)
3954    REAL(wp), INTENT( OUT ) ::  rdcl   !< Diffusion resistence of clothing (factor)
3955    REAL(wp), INTENT( OUT ) ::  rdsk   !< Diffusion resistence of skin (factor)
3956    REAL(wp), INTENT( OUT ) ::  tcl    !< Clothing temperature         (degree_C)
3957    REAL(wp), INTENT( OUT ) ::  tsk    !< Skin temperature             (degree_C)
3958    REAL(wp), INTENT( OUT ) ::  vpts   !< Sat. vapor pressure over skin (hPa)
3959    REAL(wp), INTENT( OUT ) ::  wetsk  !< Fraction of wet skin (dimensionless)
3960!
3961!-- Cconstants:
3962!     REAL(wp), PARAMETER :: cair = 1010.0_wp      !< replaced by c_p
3963    REAL(wp), PARAMETER :: cb   = 3640.0_wp        !<
3964    REAL(wp), PARAMETER :: emcl =    0.95_wp      !< Longwave emission coef. of cloth
3965    REAL(wp), PARAMETER :: emsk =    0.99_wp      !< Longwave emission coef. of skin
3966!    REAL(wp), PARAMETER :: evap = 2.42_wp * 10.0_wp **6.0_wp  !< replaced by l_v
3967    REAL(wp), PARAMETER :: food =    0.0_wp        !< Heat gain by food        (W)
3968    REAL(wp), PARAMETER :: po   = 1013.25_wp      !< Air pressure at sea level (hPa)
3969    REAL(wp), PARAMETER :: rob  =    1.06_wp      !<
3970!
3971!-- Internal variables
3972    INTEGER(iwp) ::  count1     !< running index
3973    INTEGER(iwp) ::  count3     !< running index
3974    INTEGER(iwp) ::  j          !< running index
3975    INTEGER(iwp) ::  i          !< running index
3976
3977    LOGICAL ::  skipincreasecount   !< iteration control flag
3978
3979    REAL(wp) ::  cbare          !< Convection through bare skin
3980    REAL(wp) ::  cclo           !< Convection through clothing
3981    REAL(wp) ::  csum           !< Convection in total
3982    REAL(wp) ::  di             !< difference between r1 and r2
3983    REAL(wp) ::  ed             !< energy transfer by diffusion     (W)
3984    REAL(wp) ::  enbal          !< energy ballance                  (W)
3985    REAL(wp) ::  enbal2         !< energy ballance (storage, last cycle)
3986    REAL(wp) ::  eswdif         !< difference between sweat production and evaporation potential
3987    REAL(wp) ::  eswphy         !< sweat created by physiology
3988    REAL(wp) ::  eswpot         !< potential sweat evaporation
3989    REAL(wp) ::  fec            !<
3990    REAL(wp) ::  hc             !<
3991    REAL(wp) ::  he             !<
3992    REAL(wp) ::  htcl           !<
3993    REAL(wp) ::  r1             !<
3994    REAL(wp) ::  r2             !<
3995    REAL(wp) ::  rbare          !< Radiational loss of bare skin    (W/m²)
3996    REAL(wp) ::  rcl            !<
3997    REAL(wp) ::  rclo           !< Radiational loss of clothing     (W/m²)
3998    REAL(wp) ::  rclo2          !< Longwave radiation gain or loss  (W/m²)
3999    REAL(wp) ::  rsum           !< Radiational loss or gain         (W/m²)
4000    REAL(wp) ::  sw             !<
4001!    REAL(wp) ::  swf            !< female factor, currently unused
4002    REAL(wp) ::  swm            !<
4003    REAL(wp) ::  tbody          !<
4004    REAL(wp) ::  vb             !<
4005    REAL(wp) ::  vb1            !<
4006    REAL(wp) ::  vb2            !<
4007    REAL(wp) ::  wd             !<
4008    REAL(wp) ::  wr             !<
4009    REAL(wp) ::  ws             !<
4010    REAL(wp) ::  wsum           !<
4011    REAL(wp) ::  xx             !< modification step                (K)
4012    REAL(wp) ::  y              !< fraction of bare skin
4013
4014    REAL(wp) ::  c(0:10)        !< Core temperature array           (degree_C)
4015    REAL(wp) ::  tcore(1:7)     !<
4016
4017!
4018!-- Initialize
4019    wetsk = 0.0_wp  !< skin is dry everywhere on init (no non-evaporated sweat)
4020!
4021!-- Set Du Bois Area for the sample person
4022    adu = 0.203_wp * mbody**0.425_wp * ht**0.725_wp
4023!
4024!-- Initialize convective heat considering local air preassure
4025    hc = 2.67_wp + ( 6.5_wp * v**0.67_wp )
4026    hc = hc * ( pair / po )**0.55_wp
4027!
4028!-- Set surface modification by posture (the person will always stand)
4029    feff = 0.725_wp                     !< Posture: 0.725 for stading
4030!
4031!-- Set surface modification by clothing
4032    facl = ( - 2.36_wp + 173.51_wp * clo - 100.76_wp * clo * clo + 19.28_wp * ( clo**3.0_wp ) )    &
4033           / 100.0_wp
4034    IF ( facl > 1.0_wp )  facl = 1.0_wp
4035!
4036!-- Initialize heat resistences
4037    rcl = ( clo / 6.45_wp ) / facl
4038    IF ( clo >= 2.0_wp )  y  = 1.0_wp
4039    IF ( ( clo > 0.6_wp )   .AND.  ( clo < 2.0_wp ) )   y = ( ht - 0.2_wp ) / ht
4040    IF ( ( clo <= 0.6_wp )  .AND.  ( clo > 0.3_wp ) )  y = 0.5_wp
4041    IF ( ( clo <= 0.3_wp )  .AND.  ( clo > 0.0_wp ) )   y = 0.1_wp
4042    r2   = adu * ( fcl - 1.0_wp + facl ) / ( 2.0_wp * 3.14_wp * ht * y )
4043    r1   = facl * adu / ( 2.0_wp * 3.14_wp * ht * y )
4044    di   = r2 - r1
4045
4046!
4047!-- Estimate skin temperatur
4048    DO  j = 1, 7
4049
4050       tsk    = 34.0_wp
4051       count1 = 0_iwp
4052       tcl    = ( ta + tmrt + tsk ) / 3.0_wp
4053       count3 = 1_iwp
4054       enbal2 = 0.0_wp
4055
4056       DO  i = 1, 100  ! allow for 100 iterations max
4057          acl   = adu * facl + adu * ( fcl - 1.0_wp )
4058          rclo2 = emcl * sigma_sb * ( ( tcl + degc_to_k )**4.0_wp -                                &
4059                  ( tmrt + degc_to_k )**4.0_wp ) * feff
4060          htcl  = 6.28_wp * ht * y * di / ( rcl * LOG( r2 / r1 ) * acl )
4061          tsk   = 1.0_wp / htcl * ( hc * ( tcl - ta ) + rclo2 ) + tcl
4062!
4063!--       Radiation saldo
4064          aeff  = adu * feff
4065          rbare = aeff * ( 1.0_wp - facl ) * emsk * sigma_sb *                                     &
4066                  ( ( tmrt + degc_to_k )**4.0_wp - ( tsk + degc_to_k )**4.0_wp )
4067          rclo  = feff * acl * emcl * sigma_sb *                                                   &
4068                  ( ( tmrt + degc_to_k )**4.0_wp - ( tcl + degc_to_k )**4.0_wp )
4069          rsum  = rbare + rclo
4070!
4071!--       Convection
4072          cbare = hc * ( ta - tsk ) * adu * ( 1.0_wp - facl )
4073          cclo  = hc * ( ta - tcl ) * acl
4074          csum  = cbare + cclo
4075!
4076!--       Core temperature
4077          c(0)  = int_heat + ere
4078          c(1)  = adu * rob * cb
4079          c(2)  = 18.0_wp - 0.5_wp * tsk
4080          c(3)  = 5.28_wp * adu * c(2)
4081          c(4)  = 0.0208_wp * c(1)
4082          c(5)  = 0.76075_wp * c(1)
4083          c(6)  = c(3) - c(5) - tsk * c(4)
4084          c(7)  = - c(0) * c(2) - tsk * c(3) + tsk * c(5)
4085          c(8)  = c(6) * c(6) - 4.0_wp * c(4) * c(7)
4086          c(9)  = 5.28_wp * adu - c(5) - c(4) * tsk
4087          c(10) = c(9) * c(9) - 4.0_wp * c(4) * ( c(5) * tsk - c(0) - 5.28_wp * adu * tsk )
4088
4089          IF ( ABS( tsk - 36.0_wp ) < 0.00001_wp )  tsk = 36.01_wp
4090          tcore(7) = c(0) / ( 5.28_wp * adu + c(1) * 6.3_wp / 3600.0_wp ) + tsk
4091          tcore(3) = c(0) / ( 5.28_wp * adu + ( c(1) * 6.3_wp / 3600.0_wp ) /   &
4092                     ( 1.0_wp + 0.5_wp * ( 34.0_wp - tsk ) ) ) + tsk
4093          IF ( c(10) >= 0.0_wp )  THEN
4094             tcore(6) = ( - c(9) - c(10)**0.5_wp ) / ( 2.0_wp * c(4) )
4095             tcore(1) = ( - c(9) + c(10)**0.5_wp ) / ( 2.0_wp * c(4) )
4096          ENDIF
4097
4098          IF ( c(8) >= 0.0_wp )  THEN
4099             tcore(2) = ( - c(6) + ABS( c(8) )**0.5_wp ) / ( 2.0_wp * c(4) )
4100             tcore(5) = ( - c(6) - ABS( c(8) )**0.5_wp ) / ( 2.0_wp * c(4) )
4101             tcore(4) = c(0) / ( 5.28_wp * adu + c(1) * 1.0_wp / 40.0_wp ) + tsk
4102          ENDIF
4103!
4104!--       Transpiration
4105          tbody = 0.1_wp * tsk + 0.9_wp * tcore(j)
4106          swm   = 304.94_wp * ( tbody - 36.6_wp ) * adu / 3600000.0_wp
4107          vpts  = 6.11_wp * 10.0_wp**( 7.45_wp * tsk / ( 235.0_wp + tsk ) )
4108
4109          IF ( tbody <= 36.6_wp )  swm = 0.0_wp  !< no need for sweating
4110
4111          sw = swm
4112          eswphy = - sw * l_v
4113          he     = 0.633_wp * hc / ( pair * c_p )
4114          fec    = 1.0_wp / ( 1.0_wp + 0.92_wp * hc * rcl )
4115          eswpot = he * ( vpa - vpts ) * adu * l_v * fec
4116          wetsk  = eswphy / eswpot
4117
4118          IF ( wetsk > 1.0_wp )  wetsk = 1.0_wp
4119!
4120!--       Sweat production > evaporation?
4121          eswdif = eswphy - eswpot
4122
4123          IF ( eswdif <= 0.0_wp )  esw = eswpot     !< Limit is evaporation
4124          IF ( eswdif > 0.0_wp )   esw = eswphy     !< Limit is sweat production
4125          IF ( esw  > 0.0_wp )     esw = 0.0_wp     !< Sweat can't be evaporated, no more cooling
4126                                                    !< effect
4127!
4128!--       Diffusion
4129          rdsk = 0.79_wp * 10.0_wp**7.0_wp
4130          rdcl = 0.0_wp
4131          ed   = l_v / ( rdsk + rdcl ) * adu * ( 1.0_wp - wetsk ) * ( vpa - vpts )
4132!
4133!--       Max vb
4134          vb1 = 34.0_wp - tsk
4135          vb2 = tcore(j) - 36.6_wp
4136
4137          IF ( vb2 < 0.0_wp )  vb2 = 0.0_wp
4138          IF ( vb1 < 0.0_wp )  vb1 = 0.0_wp
4139          vb = ( 6.3_wp + 75.0_wp * vb2 ) / ( 1.0_wp + 0.5_wp * vb1 )
4140!
4141!--       Energy ballence
4142          enbal = int_heat + ed + ere + esw + csum + rsum + food
4143!
4144!--       Clothing temperature
4145          xx = 0.001_wp
4146          IF ( count1 == 0_iwp )  xx = 1.0_wp
4147          IF ( count1 == 1_iwp )  xx = 0.1_wp
4148          IF ( count1 == 2_iwp )  xx = 0.01_wp
4149          IF ( count1 == 3_iwp )  xx = 0.001_wp
4150
4151          IF ( enbal > 0.0_wp )  tcl = tcl + xx
4152          IF ( enbal < 0.0_wp )  tcl = tcl - xx
4153
4154          skipincreasecount = .FALSE.
4155          IF ( ( (enbal <= 0.0_wp )  .AND.  (enbal2 > 0.0_wp ) )  .OR.                             &
4156             ( ( enbal >= 0.0_wp )   .AND.  ( enbal2 < 0.0_wp ) ) )  THEN
4157             skipincreasecount = .TRUE.
4158          ELSE
4159             enbal2 = enbal
4160             count3 = count3 + 1_iwp
4161          ENDIF
4162
4163          IF ( ( count3 > 200_iwp )  .OR.  skipincreasecount )  THEN
4164             IF ( count1 < 3_iwp )  THEN
4165                count1 = count1 + 1_iwp
4166                enbal2 = 0.0_wp
4167             ELSE
4168                EXIT
4169             ENDIF
4170          ENDIF
4171       ENDDO
4172
4173       IF ( count1 == 3_iwp )  THEN
4174          SELECT CASE ( j )
4175             CASE ( 2, 5)
4176                IF ( .NOT. ( ( tcore(j) >= 36.6_wp )  .AND.  ( tsk <= 34.050_wp ) ) )  CYCLE
4177             CASE ( 6, 1 )
4178                IF ( c(10) < 0.0_wp ) CYCLE
4179                IF ( .NOT. ( ( tcore(j) >= 36.6_wp )  .AND.  ( tsk > 33.850_wp ) ) )  CYCLE
4180             CASE ( 3 )
4181                IF ( .NOT. ( ( tcore(j) < 36.6_wp )  .AND.  ( tsk <= 34.000_wp ) ) )  CYCLE
4182             CASE ( 7 )
4183                IF ( .NOT. ( ( tcore(j) < 36.6_wp )  .AND.  ( tsk > 34.000_wp ) ) )  CYCLE
4184             CASE default
4185          END SELECT
4186       ENDIF
4187
4188       IF ( ( j /= 4_iwp )  .AND.  ( vb >= 91.0_wp ) )  CYCLE
4189       IF ( ( j == 4_iwp )  .AND.  ( vb < 89.0_wp ) )  CYCLE
4190       IF ( vb > 90.0_wp ) vb = 90.0_wp
4191!
4192!--    Loses by water
4193       ws = sw * 3600.0_wp * 1000.0_wp
4194       IF ( ws > 2000.0_wp )  ws = 2000.0_wp
4195       wd = ed / l_v * 3600.0_wp * ( -1000.0_wp )
4196       wr = erel / l_v * 3600.0_wp * ( -1000.0_wp )
4197
4198       wsum = ws + wr + wd
4199
4200       RETURN
4201    ENDDO
4202 END SUBROUTINE heat_exch
4203
4204!--------------------------------------------------------------------------------------------------!
4205! Description:
4206! ------------
4207!> Calculate PET
4208!--------------------------------------------------------------------------------------------------!
4209 SUBROUTINE pet_iteration( acl, adu, aeff, esw, facl, feff, int_heat, pair, rdcl, rdsk, rtv, ta,   &
4210                           tcl, tsk, pet_ij, vpts, wetsk )
4211!
4212!-- Input arguments:
4213    REAL(wp), INTENT( IN ) ::  acl       !< clothing surface area        (m²)
4214    REAL(wp), INTENT( IN ) ::  adu       !< Du-Bois area                 (m²)
4215    REAL(wp), INTENT( IN ) ::  esw       !< energy-loss through sweat evap. (W)
4216    REAL(wp), INTENT( IN ) ::  facl      !< surface area extension through clothing (factor)
4217    REAL(wp), INTENT( IN ) ::  feff      !< surface modification by posture (factor)
4218    REAL(wp), INTENT( IN ) ::  int_heat  !< internal heat production (W)
4219    REAL(wp), INTENT( IN ) ::  pair      !< air pressure                 (hPa)
4220    REAL(wp), INTENT( IN ) ::  rdcl      !< diffusion resistence of clothing (factor)
4221    REAL(wp), INTENT( IN ) ::  rdsk      !< diffusion resistence of skin (factor)
4222    REAL(wp), INTENT( IN ) ::  rtv       !< respiratory volume
4223    REAL(wp), INTENT( IN ) ::  ta        !< air temperature              (degree_C)
4224    REAL(wp), INTENT( IN ) ::  tcl       !< clothing temperature         (degree_C)
4225    REAL(wp), INTENT( IN ) ::  tsk       !< skin temperature             (degree_C)
4226    REAL(wp), INTENT( IN ) ::  vpts      !< sat. vapor pressure over skin (hPa)
4227    REAL(wp), INTENT( IN ) ::  wetsk     !< fraction of wet skin (dimensionless)
4228!
4229!-- Output arguments:
4230    REAL(wp), INTENT( OUT ) ::  aeff     !< effective surface area       (m²)
4231    REAL(wp), INTENT( OUT ) ::  pet_ij   !< PET                          (degree_C)
4232!
4233!-- Cconstants:
4234    REAL(wp), PARAMETER :: emcl =    0.95_wp      !< Longwave emission coef. of cloth
4235    REAL(wp), PARAMETER :: emsk =    0.99_wp      !< Longwave emission coef. of skin
4236    REAL(wp), PARAMETER :: po   = 1013.25_wp      !< Air pressure at sea level (hPa)
4237!
4238!-- Internal variables
4239    INTEGER ( iwp ) ::  count1        !< running index
4240    INTEGER ( iwp ) ::  i             !< running index
4241
4242    REAL ( wp ) ::  cbare             !< Convection through bare skin
4243    REAL ( wp ) ::  cclo              !< Convection through clothing
4244    REAL ( wp ) ::  csum              !< Convection in total
4245    REAL ( wp ) ::  ed                !< Diffusion                      (W)
4246    REAL ( wp ) ::  enbal             !< Energy ballance                (W)
4247    REAL ( wp ) ::  enbal2            !< Energy ballance (last iteration cycle)
4248    REAL ( wp ) ::  ere               !< Energy ballance result         (W)
4249    REAL ( wp ) ::  erel              !< Latent energy ballance         (W)
4250    REAL ( wp ) ::  eres              !< Sensible respiratory heat flux (W)
4251    REAL ( wp ) ::  hc                !<
4252    REAL ( wp ) ::  rbare             !< Radiational loss of bare skin  (W/m²)
4253    REAL ( wp ) ::  rclo              !< Radiational loss of clothing   (W/m²)
4254    REAL ( wp ) ::  rsum              !< Radiational loss or gain       (W/m²)
4255    REAL ( wp ) ::  tex               !< Temperat. of exhaled air       (degree_C)
4256    REAL ( wp ) ::  vpex              !< Vapor pressure of exhaled air  (hPa)
4257    REAL ( wp ) ::  xx                !< Delta PET per iteration        (K)
4258
4259
4260    pet_ij = ta
4261    enbal2 = 0.0_wp
4262
4263    DO  count1 = 0, 3
4264       DO  i = 1, 125  ! 500 / 4
4265          hc = 2.67_wp + 6.5_wp * 0.1_wp**0.67_wp
4266          hc = hc * ( pair / po )**0.55_wp
4267!
4268!--       Radiation
4269          aeff  = adu * feff
4270          rbare = aeff * ( 1.0_wp - facl ) * emsk * sigma_sb *                  &
4271                  ( ( pet_ij + degc_to_k )**4.0_wp - ( tsk + degc_to_k )**4.0_wp )
4272          rclo  = feff * acl * emcl * sigma_sb *                               &
4273                  ( ( pet_ij + degc_to_k )**4.0_wp - ( tcl + degc_to_k )**4.0_wp )
4274          rsum  = rbare + rclo
4275!
4276!--       Covection
4277          cbare = hc * ( pet_ij - tsk ) * adu * ( 1.0_wp - facl )
4278          cclo  = hc * ( pet_ij - tcl ) * acl
4279          csum  = cbare + cclo
4280!
4281!--       Diffusion
4282          ed = l_v / ( rdsk + rdcl ) * adu * ( 1.0_wp - wetsk ) * ( 12.0_wp - vpts )
4283!
4284!--       Respiration
4285          tex  = 0.47_wp * pet_ij + 21.0_wp
4286          eres = c_p * ( pet_ij - tex ) * rtv
4287          vpex = 6.11_wp * 10.0_wp**( 7.45_wp * tex / ( 235.0_wp + tex ) )
4288          erel = 0.623_wp * l_v / pair * ( 12.0_wp - vpex ) * rtv
4289          ere  = eres + erel
4290!
4291!--       Energy ballance
4292          enbal = int_heat + ed + ere + esw + csum + rsum
4293!
4294!--       Iteration concerning ta
4295          xx = 0.001_wp
4296          IF ( count1 == 0_iwp )  xx = 1.0_wp
4297          IF ( count1 == 1_iwp )  xx = 0.1_wp
4298          IF ( count1 == 2_iwp )  xx = 0.01_wp
4299!           IF ( count1 == 3_iwp )  xx = 0.001_wp
4300          IF ( enbal > 0.0_wp )  pet_ij = pet_ij - xx
4301          IF ( enbal < 0.0_wp )  pet_ij = pet_ij + xx
4302          IF ( ( enbal <= 0.0_wp )  .AND.  ( enbal2 > 0.0_wp ) )  EXIT
4303          IF ( ( enbal >= 0.0_wp )  .AND.  ( enbal2 < 0.0_wp ) )  EXIT
4304
4305          enbal2 = enbal
4306       ENDDO
4307    ENDDO
4308 END SUBROUTINE pet_iteration
4309
4310!
4311!-- UVEM specific subroutines
4312
4313!--------------------------------------------------------------------------------------------------!
4314! Description:
4315! ------------
4316!> Module-specific routine for new module
4317!--------------------------------------------------------------------------------------------------!
4318 SUBROUTINE uvem_solar_position
4319
4320    USE control_parameters,                                                                        &
4321       ONLY:  latitude, longitude, time_SINce_reference_point
4322
4323    IMPLICIT NONE
4324
4325    INTEGER(iwp) ::  day_of_year = 0       !< day of year
4326
4327    REAL(wp) ::  alpha         = 0.0_wp    !< solar azimuth angle in radiant
4328    REAL(wp) ::  declination   = 0.0_wp    !< declination
4329    REAL(wp) ::  dtor          = 0.0_wp    !< factor to convert degree to radiant
4330    REAL(wp) ::  js            = 0.0_wp    !< parameter for solar position calculation
4331    REAL(wp) ::  lat           = 52.39_wp  !< latitude
4332    REAL(wp) ::  lon           = 9.7_wp    !< longitude
4333    REAL(wp) ::  second_of_day = 0.0_wp    !< current second of the day
4334    REAL(wp) ::  thetar        = 0.0_wp    !< angle for solar zenith angle calculation
4335    REAL(wp) ::  thetasr       = 0.0_wp    !< angle for solar azimuth angle calculation
4336    REAL(wp) ::  zgl           = 0.0_wp    !< calculated exposure by direct beam
4337    REAL(wp) ::  woz           = 0.0_wp    !< calculated exposure by diffuse radiation
4338    REAL(wp) ::  wsp           = 0.0_wp    !< calculated exposure by direct beam
4339
4340
4341    CALL get_date_time( time_SINce_reference_point, day_of_year = day_of_year,                     &
4342                        second_of_day = second_of_day )
4343    dtor = pi / 180.0_wp
4344    lat = latitude
4345    lon = longitude
4346!
4347!-- Calculation of js, necessary for calculation of equation of time (zgl) :
4348    js=  72.0_wp * ( REAL( day_of_year, KIND = wp ) + ( second_of_day / 86400.0_wp ) ) / 73.0_wp
4349!
4350!-- Calculation of equation of time (zgl):
4351    zgl = 0.0066_wp + 7.3525_wp * COS( ( js + 85.9_wp ) * dtor ) + 9.9359_wp *                     &
4352    COS( ( 2.0_wp * js + 108.9_wp ) * dtor ) + 0.3387_wp * COS( ( 3 * js + 105.2_wp ) * dtor )
4353!
4354!-- Calculation of apparent solar time woz:
4355    woz = ( ( second_of_day / 3600.0_wp ) - ( 4.0_wp * ( 15.0_wp - lon ) ) / 60.0_wp ) +           &
4356          ( zgl / 60.0_wp )
4357!
4358!-- Calculation of hour angle (wsp):
4359    wsp = ( woz - 12.0_wp ) * 15.0_wp
4360!
4361!-- Calculation of declination:
4362    declination = 0.3948_wp - 23.2559_wp * COS( ( js + 9.1_wp ) * dtor ) -                         &
4363                  0.3915_wp * COS( ( 2.0_wp * js + 5.4_wp ) * dtor ) - 0.1764_wp *                 &
4364                  COS( ( 3.0_wp * js + 26.0_wp ) * dtor )
4365!
4366!-- Calculation of solar zenith angle
4367    thetar  = ACOS( SIN( lat * dtor) * SIN( declination * dtor ) + COS( wsp * dtor ) *             &
4368              COS( lat * dtor ) * COS( declination * dtor ) )
4369    thetasr = ASIN( SIN( lat * dtor) * SIN( declination * dtor ) + COS( wsp * dtor ) *             &
4370              COS( lat * dtor ) * COS( declination * dtor ) )
4371    sza = thetar / dtor
4372!
4373!-- calculation of solar azimuth angle
4374    IF (woz <= 12.0_wp) alpha = pi - ACOS( ( SIN(thetasr) * SIN( lat * dtor ) -                    &
4375                                SIN( declination * dtor ) ) / ( COS(thetasr) * COS( lat * dtor ) ) )
4376    IF (woz > 12.0_wp)  alpha = pi + ACOS( ( SIN(thetasr) * SIN( lat * dtor ) -                    &
4377                                SIN( declination * dtor ) ) / ( COS(thetasr) * COS( lat * dtor ) ) )
4378    saa = alpha / dtor
4379
4380 END SUBROUTINE uvem_solar_position
4381
4382
4383!--------------------------------------------------------------------------------------------------!
4384! Description:
4385! ------------
4386!> Module-specific routine for new module
4387!--------------------------------------------------------------------------------------------------!
4388 SUBROUTINE bio_calculate_uv_exposure
4389
4390    USE indices,                                                                                   &
4391        ONLY:  nxl, nxr, nyn, nys
4392
4393
4394    IMPLICIT NONE
4395
4396    INTEGER(iwp) ::  i     !< loop index in x direction
4397    INTEGER(iwp) ::  j     !< loop index in y direction
4398    INTEGER(iwp) ::  szai  !< loop index for different sza values
4399
4400    CALL uvem_solar_position
4401
4402    IF (sza  >=  90)  THEN
4403       vitd3_exposure(:,:) = 0.0_wp
4404    ELSE
4405
4406       DO  ai = 0, 35
4407          DO  zi = 0, 9
4408             projection_area_lookup_table(ai,zi) = uvem_projarea_f%var(clothing,zi,ai)
4409          ENDDO
4410       ENDDO
4411       DO  ai = 0, 35
4412          DO  zi = 0, 9
4413             integration_array(ai,zi) = uvem_integration_f%var(zi,ai)
4414          ENDDO
4415       ENDDO
4416       DO  ai = 0, 2
4417          DO  zi = 0, 90
4418             irradiance_lookup_table(ai,zi) = uvem_irradiance_f%var(zi,ai)
4419          ENDDO
4420       ENDDO
4421       DO  ai = 0, 35
4422          DO  zi = 0, 9
4423             DO  szai = 0, 90
4424                radiance_lookup_table(ai,zi,szai) = uvem_radiance_f%var(szai,zi,ai)
4425             ENDDO
4426          ENDDO
4427       ENDDO
4428
4429
4430!--    Rotate 3D-Model human to desired direction
4431       projection_area_temp( 0:35,:) = projection_area_lookup_table
4432       projection_area_temp(36:71,:) = projection_area_lookup_table
4433       IF (  .NOT.  turn_to_sun ) startpos_human = orientation_angle / 10.0_wp
4434       IF (       turn_to_sun ) startpos_human = saa / 10.0_wp
4435       DO  ai = 0, 35
4436          xfactor = ( startpos_human ) - INT( startpos_human )
4437          DO  zi = 0, 9
4438             projection_area(ai,zi) = ( projection_area_temp( 36 -                                 &
4439                                                               INT( startpos_human ) - 1 + ai , zi)&
4440                                        * ( xfactor ) )                                            &
4441                                      + ( projection_area_temp( 36 -                               &
4442                                                                INT( startpos_human ) + ai , zi)   &
4443                                        * ( 1.0_wp - xfactor ) )
4444          ENDDO
4445       ENDDO
4446!
4447!
4448!--    Interpolate to accurate Solar Zenith Angle
4449       DO  ai = 0, 35
4450          xfactor = ( sza )-INT( sza )
4451          DO  zi = 0, 9
4452             radiance_array(ai,zi) = ( radiance_lookup_table(ai, zi, INT( sza ) ) *                &
4453                                     ( 1.0_wp - xfactor) ) +                                       &
4454                                     ( radiance_lookup_table(ai,zi,INT( sza ) + 1) * xfactor )
4455          ENDDO
4456       ENDDO
4457       DO  iq = 0, 2
4458          irradiance(iq) = ( irradiance_lookup_table(iq, INT( sza ) ) * ( 1.0_wp - xfactor)) +     &
4459                           ( irradiance_lookup_table(iq, INT( sza ) + 1) * xfactor )
4460       ENDDO
4461!
4462!--    Interpolate to accurate Solar Azimuth Angle
4463       IF ( sun_in_south )  THEN
4464          startpos_saa_float = 180.0_wp / 10.0_wp
4465       ELSE
4466          startpos_saa_float = saa / 10.0_wp
4467       ENDIF
4468       radiance_array_temp( 0:35,:) = radiance_array
4469       radiance_array_temp(36:71,:) = radiance_array
4470       xfactor = (startpos_saa_float) - INT( startpos_saa_float )
4471       DO  ai = 0, 35
4472          DO  zi = 0, 9
4473             radiance_array(ai,zi) = ( radiance_array_temp(36 -                                    &
4474                                                           INT( startpos_saa_float ) - 1 + ai, zi) &
4475                                       * ( xfactor ) )                                             &
4476                                     + ( radiance_array_temp(36 -                                  &
4477                                                             INT( startpos_saa_float ) + ai, zi)   &
4478                                       * ( 1.0_wp - xfactor ) )
4479          ENDDO
4480       ENDDO
4481
4482!
4483!--    Calculate Projectionarea for direct beam
4484       projection_area_direct_temp( 0:35,:) = projection_area
4485       projection_area_direct_temp(36:71,:) = projection_area
4486       yfactor = ( sza / 10.0_wp ) - INT( sza / 10.0_wp )
4487       xfactor = ( startpos_saa_float ) - INT( startpos_saa_float )
4488       projection_area_direct_beam = ( projection_area_direct_temp( INT(startpos_saa_float)    ,INT(sza/10.0_wp)  ) * &
4489                                     ( 1.0_wp - xfactor ) * ( 1.0_wp - yfactor ) ) +                                  &
4490                                     ( projection_area_direct_temp( INT(startpos_saa_float) + 1,INT(sza/10.0_wp)  ) * &
4491                                     (          xfactor ) * ( 1.0_wp - yfactor ) ) +                                  &
4492                                     ( projection_area_direct_temp( INT(startpos_saa_float)    ,INT(sza/10.0_wp)+1) * &
4493                                     ( 1.0_wp - xfactor ) * (          yfactor ) ) +                                  &
4494                                     ( projection_area_direct_temp( INT(startpos_saa_float) + 1,INT(sza/10.0_wp)+1) * &
4495                                     (          xfactor ) * (          yfactor ) )
4496
4497
4498       DO  i = nxl, nxr
4499          DO  j = nys, nyn
4500!
4501!--          Extract obstruction from IBSET-Integer_Array
4502             IF (consider_obstructions )  THEN
4503                obstruction_temp1 = building_obstruction_f%var_3d(:,j,i)
4504                IF ( obstruction_temp1(0)  /=  9 )  THEN
4505                   DO  pobi = 0, 44
4506                      DO  bi = 0, 7
4507                         IF ( BTEST( obstruction_temp1(pobi), bi )  .EQV.  .TRUE.)  THEN
4508                            obstruction_temp2( ( pobi * 8 ) + bi ) = 1
4509                         ELSE
4510                            obstruction_temp2( ( pobi * 8 ) + bi ) = 0
4511                         ENDIF
4512                      ENDDO
4513                   ENDDO
4514                   DO  zi = 0, 9
4515                      obstruction(:,zi) = obstruction_temp2( zi * 36 :( zi * 36) + 35 )
4516                   ENDDO
4517                ELSE
4518                   obstruction(:,:) = 0
4519                ENDIF
4520             ENDIF
4521!
4522!--          Calculated human exposure
4523             diffuse_exposure = SUM( radiance_array * projection_area * integration_array *        &
4524                                     obstruction )
4525
4526             obstruction_direct_beam = obstruction( NINT( startpos_saa_float),                     &
4527                                                    NINT( sza / 10.0_wp ) )
4528             IF (sza  >=  89.99_wp)  THEN
4529                sza = 89.99999_wp
4530             ENDIF
4531!
4532!--          Calculate direct normal irradiance (direct beam)
4533             direct_exposure = ( irradiance(1) / COS( pi * sza / 180.0_wp ) ) *                    &
4534                               projection_area_direct_beam * obstruction_direct_beam
4535
4536             vitd3_exposure(j,i) = ( diffuse_exposure + direct_exposure ) / 1000.0_wp * 70.97_wp
4537!            unit = international units vitamin D per second
4538          ENDDO
4539       ENDDO
4540    ENDIF
4541
4542 END SUBROUTINE bio_calculate_uv_exposure
4543
4544 END MODULE biometeorology_mod
Note: See TracBrowser for help on using the repository browser.