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

Last change on this file since 4180 was 4180, checked in by scharf, 5 years ago

removed comments in 'Former revisions' section that are older than 01.01.2019

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