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

Last change on this file since 4126 was 4126, checked in by gronemeier, 5 years ago

renaming in biometeorology_mod, adding of example cases for biometeorolgy

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