Index: palm/trunk/SOURCE/Makefile
===================================================================
--- palm/trunk/SOURCE/Makefile	(revision 3473)
+++ palm/trunk/SOURCE/Makefile	(revision 3474)
@@ -1960,4 +1960,5 @@
 	mod_kinds.o \
 	modules.o \
+	netcdf_data_input_mod.o \
 	radiation_model_mod.o
 vertical_nesting_mod.o: \
Index: palm/trunk/SOURCE/netcdf_data_input_mod.f90
===================================================================
--- palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 3473)
+++ palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 3474)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! Add UV exposure model input (Schrempf)
+! 
+! 3472 2018-10-30 20:43:50Z suehring
 ! Salsa implemented
 ! 
@@ -446,4 +449,12 @@
     END TYPE int_2d_8bit
 !
+!-- 8-bit Integer 3D
+    TYPE int_3d_8bit
+       INTEGER(KIND=1) ::  fill = -127                           !< fill value
+       INTEGER(KIND=1), DIMENSION(:,:,:), ALLOCATABLE ::  var_3d !< respective variable
+
+       LOGICAL ::  from_file = .FALSE.  !< flag indicating whether an input variable is available and read from file or default values are used
+    END TYPE int_3d_8bit
+!
 !-- 32-bit Integer 2D
     TYPE int_2d_32bit
@@ -464,5 +475,5 @@
 
 !
-!-- Define data type to read 2D real variables
+!-- Define data type to read 3D real variables
     TYPE real_3d
        LOGICAL ::  from_file = .FALSE.  !< flag indicating whether an input variable is available and read from file or default values are used
@@ -629,5 +640,8 @@
     TYPE(int_2d_8bit)  ::  vegetation_type_f !< input variable for vegetation type
     TYPE(int_2d_8bit)  ::  water_type_f      !< input variable for water type
-
+!
+!-- Define 3D variables of type NC_BYTE
+    TYPE(int_3d_8bit)  ::  building_obstruction_f    !< input variable for building obstruction
+    TYPE(int_3d_8bit)  ::  building_obstruction_full !< input variable for building obstruction
 !
 !-- Define 2D variables of type NC_INT
@@ -636,4 +650,6 @@
 !-- Define 2D variables of type NC_FLOAT
     TYPE(real_2d) ::  terrain_height_f       !< input variable for terrain height
+    TYPE(real_2d) ::  uvem_irradiance_f      !< input variable for uvem irradiance lookup table
+    TYPE(real_2d) ::  uvem_integration_f     !< input variable for uvem integration
 !
 !-- Define 3D variables of type NC_FLOAT
@@ -642,5 +658,6 @@
     TYPE(real_3d) ::  root_area_density_lad_f !< input variable for root area density - resolved vegetation
     TYPE(real_3d) ::  root_area_density_lsm_f !< input variable for root area density - parametrized vegetation
-
+    TYPE(real_3d) ::  uvem_radiance_f         !< input variable for uvem radiance lookup table
+    TYPE(real_3d) ::  uvem_projarea_f         !< input variable for uvem projection area lookup table
 !
 !-- Define input variable for buildings
@@ -670,8 +687,9 @@
     CHARACTER(LEN=100) ::  input_file_dynamic = 'PIDS_DYNAMIC' !< Name of file which comprises dynamic input data
     CHARACTER(LEN=100) ::  input_file_chem    = 'PIDS_CHEM'    !< Name of file which comprises chemistry input data
+    CHARACTER(LEN=100) ::  input_file_uvem    = 'PIDS_UVEM'    !< Name of file which comprises static uv_exposure model input data
     CHARACTER(LEN=100) ::  input_file_vm      = 'PIDS_VM'      !< Name of file which comprises virtual measurement data
 
     CHARACTER (LEN=25), ALLOCATABLE, DIMENSION(:)    ::  string_values  !< output of string variables read from netcdf input files
- 
+
     INTEGER(iwp)                                     ::  id_emis        !< NetCDF id of input file for chemistry emissions: TBD: It has to be removed
 
@@ -681,6 +699,7 @@
     LOGICAL ::  input_pids_dynamic = .FALSE.   !< Flag indicating whether Palm-input-data-standard file containing dynamic information exists
     LOGICAL ::  input_pids_chem    = .FALSE.   !< Flag indicating whether Palm-input-data-standard file containing chemistry information exists
+    LOGICAL ::  input_pids_uvem    = .FALSE.   !< Flag indicating whether uv-expoure-model input file containing static information exists
     LOGICAL ::  input_pids_vm      = .FALSE.   !< Flag indicating whether input file for virtual measurements exist
-    
+
     LOGICAL ::  collective_read = .FALSE.      !< Enable NetCDF collective read
 
@@ -749,4 +768,8 @@
        MODULE PROCEDURE netcdf_data_input_var_real_2d
     END INTERFACE netcdf_data_input_var
+
+    INTERFACE netcdf_data_input_uvem
+       MODULE PROCEDURE netcdf_data_input_uvem
+    END INTERFACE netcdf_data_input_uvem
 
     INTERFACE get_variable
@@ -791,4 +814,10 @@
            terrain_height_f, vegetation_pars_f, vegetation_type_f,             &
            water_pars_f, water_type_f
+!
+!-- Public uv exposure variables
+    PUBLIC building_obstruction_f, input_file_uvem, input_pids_uvem,           &
+           netcdf_data_input_uvem,                                             &
+           uvem_integration_f, uvem_irradiance_f,                              &
+           uvem_projarea_f, uvem_radiance_f
 
 !
@@ -804,4 +833,5 @@
            netcdf_data_input_var, get_attribute, get_variable, open_read_file
 
+
  CONTAINS
 
@@ -826,4 +856,6 @@
        INQUIRE( FILE = TRIM( input_file_chem )    // TRIM( coupling_char ),    &
                 EXIST = input_pids_chem )
+       INQUIRE( FILE = TRIM( input_file_uvem ) // TRIM( coupling_char ),       &
+                EXIST = input_pids_uvem  )
        INQUIRE( FILE = TRIM( input_file_vm )      // TRIM( coupling_char ),    &
                 EXIST = input_pids_vm )
@@ -2497,4 +2529,132 @@
 ! Description:
 ! ------------
+!> Reads uvem lookup table information.
+!------------------------------------------------------------------------------!
+    SUBROUTINE netcdf_data_input_uvem
+       
+       USE indices,                                                            &
+           ONLY:  nxl, nxr, nyn, nys
+
+       IMPLICIT NONE
+
+       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE ::  var_names  !< variable names in static input file
+
+
+       INTEGER(iwp) ::  id_uvem       !< NetCDF id of uvem lookup table input file
+       INTEGER(iwp) ::  nli = 35      !< dimension length of lookup table in x
+       INTEGER(iwp) ::  nlj =  9      !< dimension length of lookup table in y
+       INTEGER(iwp) ::  nlk = 90      !< dimension length of lookup table in z
+       INTEGER(iwp) ::  num_vars      !< number of variables in netcdf input file
+!
+!--    Input via uv exposure model lookup table input
+       IF ( input_pids_uvem )  THEN
+
+#if defined ( __netcdf )
+!
+!--       Open file in read-only mode
+          CALL open_read_file( TRIM( input_file_uvem ) //                    &
+                               TRIM( coupling_char ), id_uvem )
+!
+!--       At first, inquire all variable names.
+!--       This will be used to check whether an input variable exist or not.
+          CALL inquire_num_variables( id_uvem, num_vars )
+!
+!--       Allocate memory to store variable names and inquire them.
+          ALLOCATE( var_names(1:num_vars) )
+          CALL inquire_variable_names( id_uvem, var_names )
+!
+!
+!--       uvem integration
+          IF ( check_existence( var_names, 'int_factors' ) )  THEN
+             uvem_integration_f%from_file = .TRUE.
+!
+!--          Input 2D uvem integration.
+             ALLOCATE ( uvem_integration_f%var(0:nlj,0:nli)  )
+             
+             CALL get_variable( id_uvem, 'int_factors', uvem_integration_f%var, 0, nli, 0, nlj )
+          ELSE
+             uvem_integration_f%from_file = .FALSE.
+          ENDIF
+!
+!
+!
+!--       uvem irradiance
+          IF ( check_existence( var_names, 'irradiance' ) )  THEN
+             uvem_irradiance_f%from_file = .TRUE.
+!
+!--          Input 2D uvem irradiance.
+             ALLOCATE ( uvem_irradiance_f%var(0:nlk, 0:2)  )
+             
+             CALL get_variable( id_uvem, 'irradiance', uvem_irradiance_f%var, 0, 2, 0, nlk )
+          ELSE
+             uvem_irradiance_f%from_file = .FALSE.
+          ENDIF
+!
+!
+!
+!--       uvem porjection areas
+          IF ( check_existence( var_names, 'projarea' ) )  THEN
+             uvem_projarea_f%from_file = .TRUE.
+!
+!--          Input 3D uvem projection area (human geometgry)
+             ALLOCATE ( uvem_projarea_f%var(0:2,0:nlj,0:nli)  )
+           
+             CALL get_variable( id_uvem, 'projarea', uvem_projarea_f%var, 0, nli, 0, nlj, 0, 2 )
+          ELSE
+             uvem_projarea_f%from_file = .FALSE.
+          ENDIF
+!
+!
+!
+!--       uvem radiance
+          IF ( check_existence( var_names, 'radiance' ) )  THEN
+             uvem_radiance_f%from_file = .TRUE.
+!
+!--          Input 3D uvem radiance
+             ALLOCATE ( uvem_radiance_f%var(0:nlk,0:nlj,0:nli)  )
+             
+             CALL get_variable( id_uvem, 'radiance', uvem_radiance_f%var, 0, nli, 0, nlj, 0, nlk )
+          ELSE
+             uvem_radiance_f%from_file = .FALSE.
+          ENDIF
+!
+!
+!
+!--       Read building obstruction
+          IF ( check_existence( var_names, 'obstruction' ) )  THEN
+             building_obstruction_full%from_file = .TRUE.
+!--          Input 3D uvem building obstruction
+              ALLOCATE ( building_obstruction_full%var_3d(0:44,0:2,0:2) )
+              CALL get_variable( id_uvem, 'obstruction', building_obstruction_full%var_3d,0, 2, 0, 2, 0, 44 )        
+          ELSE
+             building_obstruction_full%from_file = .FALSE.
+          ENDIF
+!
+          IF ( check_existence( var_names, 'obstruction' ) )  THEN
+             building_obstruction_f%from_file = .TRUE.
+!
+!--          Input 3D uvem building obstruction
+             ALLOCATE ( building_obstruction_f%var_3d(0:44,nys:nyn,nxl:nxr) )
+!
+             CALL get_variable( id_uvem, 'obstruction', building_obstruction_f%var_3d,      &
+                                nxl, nxr, nys, nyn, 0, 44 )        
+          ELSE
+             building_obstruction_f%from_file = .FALSE.
+          ENDIF
+!
+!
+!
+!
+!--       Close uvem lookup table input file
+          CALL close_input_file( id_uvem )
+#else
+          CONTINUE
+#endif
+       ENDIF
+    END SUBROUTINE netcdf_data_input_uvem
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
 !> Reads orography and building information.
 !------------------------------------------------------------------------------!
Index: palm/trunk/SOURCE/uv_exposure_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/uv_exposure_model_mod.f90	(revision 3473)
+++ palm/trunk/SOURCE/uv_exposure_model_mod.f90	(revision 3474)
@@ -19,5 +19,5 @@
 !
 ! Current revisions:
-! -----------------
+! ------------------
 ! 
 ! 
@@ -25,4 +25,10 @@
 ! -----------------
 ! $Id$
+! Schrempf:
+! Bugfix in rotate 3D-Model human to desired direction
+! Bugfix in interpolate to accurate Solar Azimuth Angle
+! Further changes in variables
+! 
+! 3448 2018-10-29 18:14:31Z kanani
 ! Temporary rename of namelist until uv model moves to biometeorology module
 ! 
@@ -90,8 +96,11 @@
     USE kinds
 
-!
-!-- Load required variables from existing modules
-!-- USE modulename,                                                            &
-!--     ONLY: ...
+    USE date_and_time_mod,                                                     &
+       ONLY:  calc_date_and_time, day_of_year, time_utc
+
+    USE netcdf_data_input_mod,                                                 &
+       ONLY:  netcdf_data_input_uvem, uvem_projarea_f, uvem_radiance_f,        &
+               uvem_irradiance_f, uvem_integration_f, building_obstruction_f 
+
 
 
@@ -102,44 +111,41 @@
 !-- Declare all global variables within the module (alphabetical order)
     INTEGER(iwp) ::  ai                      = 0 !< running index
-    INTEGER(iwp) ::  clothing                = 3 !< clothing (0=unclothed, 1=Arms,Hands Face free, 3=Hand, Face free)
-    INTEGER(iwp) ::  consider_obstructions   = 1 !< 0 = unobstructed scenario, 
-                                                 !< 1 = scenario where obstrcutions are considered
-    INTEGER(iwp) ::  orientation_angle       = 0 !< orientation of front/face of the human model
-    INTEGER(iwp) ::  saa_in_south            = 1 !< 0 = sun always in south direction, 1 = actual sun position  
-    INTEGER(iwp) ::  obstruction_direct_beam = 0 !< Obstruction information for direct beam
-    INTEGER(iwp) ::  turn_to_sun             = 1 !< 0 = orientation of human as in orientation_angle,
-                                                 !< 1 = human is always orientated towards the sun
+    INTEGER(iwp) ::  clothing                = 1 !< clothing (0=unclothed, 1=Arms,Hands Face free, 3=Hand, Face free)
+    INTEGER(iwp) ::  obstruction_direct_beam = 0 !< Obstruction information for direct beam    
     INTEGER(iwp) ::  zi                      = 0 !< running index
 
-    INTEGER(iwp), DIMENSION(0:44)  ::  obstruction_temp1 = 0 !< temporary obstruction information
+    INTEGER(KIND=1), DIMENSION(0:44)  ::  obstruction_temp1 = 0 !< temporary obstruction information
                                                              !< stored with ibset as logical information 
     INTEGER(iwp), DIMENSION(0:359) ::  obstruction_temp2 = 0 !< temporary obstruction information restored values
                                                              !< from logical information, which where stored by ibset  
     
-    INTEGER(iwp), DIMENSION(0:35,0:9) ::  obstruction = 0 !< final obstruction information array for all
+    INTEGER(iwp), DIMENSION(0:35,0:9) ::  obstruction = 1 !< final obstruction information array for all
                                                           !< hemispherical directions
     
-    INTEGER(KIND=1), DIMENSION(:,:,:), ALLOCATABLE ::  obstruction_lookup_table !< lookup table of obstruction
-                                                                                !< information of entire domain
-
-    REAL(wp) ::  diffuse_exposure            = 0.0_wp !< calculated exposure by diffuse radiation
-    REAL(wp) ::  direct_exposure             = 0.0_wp !< calculated exposure by direct beam   
-    REAL(wp) ::  projection_area_direct_beam = 0.0_wp !< projection area for  by direct beam
+    LOGICAL ::  consider_obstructions = .TRUE.   !< namelist parameter (see documentation)
+    LOGICAL ::  sun_in_south          = .FALSE.  !< namelist parameter (see documentation)
+    LOGICAL ::  turn_to_sun           = .TRUE.   !< namelist parameter (see documentation)
+
+    REAL(wp) ::  diffuse_exposure            =   0.0_wp !< calculated exposure by diffuse radiation
+    REAL(wp) ::  direct_exposure             =   0.0_wp !< calculated exposure by direct beam   
+    REAL(wp) ::  orientation_angle           =   0.0_wp !< orientation of front/face of the human model    
+    REAL(wp) ::  projection_area_direct_beam =   0.0_wp !< projection area for  by direct beam
     REAL(wp) ::  saa                         = 180.0_wp !< solar azimuth angle
-    REAL(wp) ::  startpos_human              = 0.0_wp !< start position in azimuth direction for the
-                                                      !< interpolation of the projection area              
-    REAL(wp) ::  startpos_saa_float          = 0.0_wp !< start position in azimuth direction for the
-                                                      !< interpolation of the radiance field             
-    REAL(wp) ::  sza                         = 20.0_wp !< solar zenith angle
-    REAL(wp) ::  xfactor                     = 0.0_wp !< relative x-position used for interpolation
-    REAL(wp) ::  yfactor                     = 0.0_wp !< relative y-position used for interpolation
-    
-    REAL(wp), DIMENSION(0:2)  ::  irradiance  = 0.0_wp !< iradiance values extracted from irradiance lookup table
-    
+    REAL(wp) ::  startpos_human              =   0.0_wp !< start position in azimuth direction for the
+                                                        !< interpolation of the projection area              
+    REAL(wp) ::  startpos_saa_float          =   0.0_wp !< start position in azimuth direction for the
+                                                        !< interpolation of the radiance field             
+    REAL(wp) ::  sza                         =  20.0_wp !< solar zenith angle
+    REAL(wp) ::  xfactor                     =   0.0_wp !< relative x-position used for interpolation
+    REAL(wp) ::  yfactor                     =   0.0_wp !< relative y-position used for interpolation
+    
+    REAL(wp), DIMENSION(0:2)  ::  irradiance =   0.0_wp !< iradiance values extracted from irradiance lookup table    
     REAL(wp), DIMENSION(0:2,0:90) ::  irradiance_lookup_table = 0.0_wp !< irradiance lookup table contains values
                                                                        !< for direct, diffuse and global component
+
     REAL(wp), DIMENSION(0:35,0:9) ::  integration_array            = 0.0_wp
     REAL(wp), DIMENSION(0:35,0:9) ::  projection_area              = 0.0_wp
     REAL(wp), DIMENSION(0:35,0:9) ::  projection_area_lookup_table = 0.0_wp
+    REAL(wp), DIMENSION(0:71,0:9) ::  projection_area_direct_temp  = 0.0_wp
     REAL(wp), DIMENSION(0:71,0:9) ::  projection_area_temp         = 0.0_wp
     REAL(wp), DIMENSION(0:35,0:9) ::  radiance_array               = 0.0_wp
@@ -181,16 +187,4 @@
        MODULE PROCEDURE uvem_check_data_output
     END INTERFACE uvem_check_data_output
-    
-! !
-! !-- Data output checks for profile data to be done in check_parameters
-!     INTERFACE uvem_check_data_output_pr
-!        MODULE PROCEDURE uvem_check_data_output_pr
-!     END INTERFACE uvem_check_data_output_pr
-!     
-! !
-! !-- Input parameter checks to be done in check_parameters
-!     INTERFACE uvem_check_parameters
-!        MODULE PROCEDURE uvem_check_parameters
-!     END INTERFACE uvem_check_parameters
 ! 
 !
@@ -200,5 +194,5 @@
     END INTERFACE uvem_3d_data_averaging
 ! 
-! !
+!
 !-- Data output of 2D quantities
     INTERFACE uvem_data_output_2d
@@ -206,22 +200,10 @@
     END INTERFACE uvem_data_output_2d
 ! 
-! !
-! !-- Data output of 3D data
-!     INTERFACE uvem_data_output_3d
-!        MODULE PROCEDURE uvem_data_output_3d
-!     END INTERFACE uvem_data_output_3d
-! 
-! !
+!
 ! !-- Definition of data output quantities
     INTERFACE uvem_define_netcdf_grid
        MODULE PROCEDURE uvem_define_netcdf_grid
     END INTERFACE uvem_define_netcdf_grid
-! 
-! !
-! !-- Output of information to the header file
-!     INTERFACE uvem_header
-!        MODULE PROCEDURE uvem_header
-!     END INTERFACE uvem_header
-  
+!  
 !
 !-- Initialization actions  
@@ -229,40 +211,16 @@
        MODULE PROCEDURE uvem_init
     END INTERFACE uvem_init
- 
-!
-!-- Initialization of arrays
+! 
+!
+! !-- Initialization of arrays
     INTERFACE uvem_init_arrays
        MODULE PROCEDURE uvem_init_arrays
     END INTERFACE uvem_init_arrays
-! 
-! !
-! !-- Writing of binary output for restart runs  !!! renaming?!
-!     INTERFACE uvem_wrd_global
-!        MODULE PROCEDURE uvem_wrd_global
-!     END INTERFACE uvem_wrd_global
 !     
 !
-!-- Reading of NAMELIST parameters
+! !-- Reading of NAMELIST parameters
     INTERFACE uvem_parin
        MODULE PROCEDURE uvem_parin
     END INTERFACE uvem_parin
-! 
-! !
-! !-- Reading of parameters for restart runs
-!     INTERFACE uvem_rrd_global
-!        MODULE PROCEDURE uvem_rrd_global
-!     END INTERFACE uvem_rrd_global
-! 
-! !
-! !-- Swapping of time levels (required for prognostic variables)
-!     INTERFACE uvem_swap_timelevel
-!        MODULE PROCEDURE uvem_swap_timelevel
-!     END INTERFACE uvem_swap_timelevel
-! 
-! !
-! !-- New module-specific procedure(s) (alphabetical order):
-!     INTERFACE uvem_newprocedure
-!        MODULE PROCEDURE uvem_newprocedure
-!     END INTERFACE uvem_newprocedure
 
  CONTAINS
@@ -457,8 +415,11 @@
     CHARACTER (LEN=80) ::  line  !< dummy string for current line in parameter file 
     
-    NAMELIST /biometeorology_parameters_uv/  clothing
-    
-    line = ' '
-    
+    NAMELIST /biometeorology_parameters_uv/  clothing,                            &
+                                             consider_obstructions,               &
+                                             orientation_angle,                   &
+                                             sun_in_south,                        &
+                                             turn_to_sun
+    
+!    line = ' '  
 !
 !-- Try to find uv exposure model namelist
@@ -477,4 +438,5 @@
 !-- Set flag that indicates that the uv exposure model is switched on
     uv_exposure = .TRUE.
+    GOTO 20
 
  10 BACKSPACE( 11 )
@@ -570,46 +532,11 @@
         ONLY:  initializing_actions
 
-    IMPLICIT NONE
-
-!
-!-- Actions for initial runs
-    IF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
-       OPEN(90, STATUS='old',FILE=&
-       'RADIANCE', FORM='UNFORMATTED')
-       READ(90) radiance_lookup_table
-       CLOSE(90)
-       OPEN(90, STATUS='old',FILE=&
-       'IRRADIANCE', FORM='UNFORMATTED')
-       READ(90) irradiance_lookup_table
-       CLOSE(90)
-      
-      !________________________LOAD Obstruction information _______________________________
-       IF ( consider_obstructions == 1 )  THEN
-          OPEN(90, STATUS='old',FILE=&
-          'OBSTRUCTION', FORM='UNFORMATTED')
-          READ(90) obstruction_lookup_table
-          CLOSE(90)  
-      ELSEIF( consider_obstructions == 0 ) THEN
-          obstruction(:,:) = 1
-      ENDIF
-
-      !________________________LOAD integration_array ________________________________________________________________________
-      OPEN(90, STATUS='old',FILE=&
-      'SOLIDANGLE', FORM='UNFORMATTED')
-      READ(90) integration_array
-      CLOSE(90)
-
-      IF (clothing==1) THEN
-          OPEN(90, STATUS='old',FILE='HUMAN', FORM='UNFORMATTED')
-      ENDIF
-      READ(90) projection_area_lookup_table
-      CLOSE(90)
-
-!
-!-- Actions for restart runs
-    ELSE
-! ....
-
-    ENDIF
+    USE netcdf_data_input_mod,                                                &
+        ONLY:  netcdf_data_input_uvem, uvem_projarea_f, uvem_radiance_f,      &
+               uvem_irradiance_f, uvem_integration_f, building_obstruction_f 
+
+    IMPLICIT NONE
+
+    CALL netcdf_data_input_uvem
 
  END SUBROUTINE uvem_init
@@ -627,4 +554,5 @@
 
 
+
     IMPLICIT NONE
 
@@ -633,5 +561,4 @@
     ALLOCATE ( vitd3_exposure(nysg:nyng,nxlg:nxrg) )
     ALLOCATE ( vitd3_exposure_av(nysg:nyng,nxlg:nxrg) )
-    ALLOCATE ( obstruction_lookup_table(nxlg:nxrg,nysg:nyng,0:44) )
 
 !
@@ -639,5 +566,4 @@
     vitd3_exposure = 0.0_wp
     vitd3_exposure_av = 0.0_wp
-    obstruction_lookup_table = 0
 
 
@@ -660,5 +586,6 @@
     
    
-    REAL(wp) ::  alpha       = 0.0_wp   !< solar azimuth angle in radiant       
+    REAL(wp) ::  alpha       = 0.0_wp   !< solar azimuth angle in radiant    
+    REAL(wp) ::  doy_r       = 0.0_wp   !< real format of day_of_year           
     REAL(wp) ::  declination = 0.0_wp   !< declination
     REAL(wp) ::  dtor        = 0.0_wp   !< factor to convert degree to radiant
@@ -674,5 +601,5 @@
 
     CALL calc_date_and_time
-       
+    doy_r = real(day_of_year)   
     dtor = pi / 180.0_wp
     lat = latitude
@@ -680,5 +607,5 @@
 !
 !-- calculation of js :
-    js=  72.0_wp * ( day_of_year + ( time_utc / 86400.0_wp ) ) / 73.0_wp 
+    js=  72.0_wp * ( doy_r + ( time_utc / 86400.0_wp ) ) / 73.0_wp 
 !
 !-- calculation of equation of time (zgl):
@@ -704,8 +631,8 @@
 !
 !-- calculation of solar azimuth angle
-    IF (woz .LE. 12.0_wp) alpha = pi - acos( sin(thetasr) * sin(lat * dtor) -                           & 
-    sin( declination * dtor ) / ( cos(thetasr) * cos( lat * dtor ) ) )    
-    IF (woz .GT. 12.0_wp) alpha = pi + acos( sin(thetasr) * sin(lat * dtor) -                           &
-    sin( declination * dtor ) / ( cos(thetasr) * cos( lat * dtor ) ) )    
+    IF (woz .LE. 12.0_wp) alpha = pi - acos( (sin(thetasr) * sin(lat * dtor) -                     & 
+    sin( declination * dtor )) / ( cos(thetasr) * cos( lat * dtor ) ) )    
+    IF (woz .GT. 12.0_wp) alpha = pi + acos( (sin(thetasr) * sin(lat * dtor) -                     &
+    sin( declination * dtor )) / ( cos(thetasr) * cos( lat * dtor ) ) )    
     saa = alpha / dtor
 
@@ -721,5 +648,5 @@
 
     USE indices,                                                               &
-        ONLY:  nxlg, nxrg, nyng, nysg
+        ONLY:  nxlg, nxrg, nyng, nysg, nys, nyn, nxl, nxr 
     
     
@@ -728,5 +655,5 @@
     INTEGER(iwp) ::  i   !< running index
     INTEGER(iwp) ::  j   !< running index
-
+    INTEGER(iwp) ::  k   !< running index
 
     CALL uvem_solar_position
@@ -736,35 +663,44 @@
     ELSE
        
-!       
+       DO  i = 0, 35
+          DO  j = 0, 9
+                projection_area_lookup_table(i,j) = uvem_projarea_f%var(clothing,j,i)
+          ENDDO
+       ENDDO
+       DO  i = 0, 35
+          DO  j = 0, 9
+                integration_array(i,j) = uvem_integration_f%var(j,i)
+          ENDDO
+       ENDDO
+       DO  i = 0, 2
+          DO  j = 0, 90
+                irradiance_lookup_table(i,j) = uvem_irradiance_f%var(j,i)
+          ENDDO
+       ENDDO
+       DO  i = 0, 35
+          DO  j = 0, 9
+             DO  k = 0, 90
+                radiance_lookup_table(i,j,k) = uvem_radiance_f%var(k,j,i)
+             ENDDO
+          ENDDO
+       ENDDO
+        
+        
+        
 !--    rotate 3D-Model human to desired direction  ----------------------------- 
        projection_area_temp( 0:35,:) = projection_area_lookup_table
        projection_area_temp(36:71,:) = projection_area_lookup_table               
-       IF ( Turn_to_Sun .EQ. 0 )  startpos_human = orientation_angle / 10.0_wp
-       IF ( Turn_to_Sun .EQ. 1 )  startpos_human = startpos_saa_float        
+       IF ( .NOT. turn_to_sun )  startpos_human = orientation_angle / 10.0_wp
+       IF (       turn_to_sun )  startpos_human = saa / 10.0_wp        
        DO  ai = 0, 35
            xfactor = ( startpos_human ) - INT( startpos_human )
           DO  zi = 0, 9
-              projection_area(ai,zi) = ( projection_area_temp( ai +     INT( startpos_human ), zi) * &
-                                       (1.0_wp - xfactor ) ) &
-                                      +( projection_area_temp( ai + 1 + INT( startpos_human ), zi) * &
-                                        xfactor)
+              projection_area(ai,zi) = ( projection_area_temp( 36 - INT( startpos_human ) - 1 + ai , zi) * &
+                                       ( xfactor ) ) &
+                                      +( projection_area_temp( 36 - INT( startpos_human ) + ai , zi) * &
+                                        ( 1.0_wp - xfactor ) )
           ENDDO
-       ENDDO
-!      
-!--    calculate Projectionarea for direct beam -----------------------------'
-       projection_area_temp( 0:35,:) = projection_area
-       projection_area_temp(36:71,:) = projection_area
-       yfactor = ( sza / 10.0_wp ) - INT( sza / 10.0_wp )
-       xfactor = ( startpos_saa_float ) - INT( startpos_saa_float )
-       projection_area_direct_beam = ( projection_area_temp( INT(startpos_saa_float)    ,INT( sza / 10.0_wp ) ) * &
-                                     ( 1.0_wp - xfactor ) * ( 1.0_wp - yfactor ) ) + &
-                                     ( projection_area_temp( INT(startpos_saa_float) + 1,INT(sza/10.0_wp))  *&
-                                     (    xfactor ) * ( 1.0_wp - yfactor ) ) + &
-                                     ( projection_area_temp( INT(startpos_saa_float)    ,INT(sza/10.0_wp)+1)*&
-                                     ( 1.0_wp - xfactor ) * (   yfactor ) ) + &
-                                     ( projection_area_temp( INT(startpos_saa_float) + 1,INT(sza/10.0_wp)+1)*&
-                                     (    xfactor ) * (   yfactor ) )
-                 
-             
+       ENDDO           
+!             
 !           
 !--    interpolate to accurate Solar Zenith Angle  ------------------          
@@ -776,5 +712,5 @@
           ENDDO
        ENDDO
-       Do  ai = 0, 2            
+       Do  ai = 0, 2
            irradiance(ai) = ( irradiance_lookup_table(ai, INT(sza) ) * ( 1.0_wp - xfactor)) + &
            (irradiance_lookup_table(ai, INT(sza) + 1) * xfactor )
@@ -782,5 +718,5 @@
 !         
 !--    interpolate to accurate Solar Azimuth Angle ------------------
-       IF ( saa_in_south .EQ. 0 )  THEN
+       IF ( sun_in_south )  THEN
           startpos_saa_float = 180.0_wp / 10.0_wp
        ELSE 
@@ -790,22 +726,36 @@
        radiance_array_temp(36:71,:) = radiance_array
        xfactor = (startpos_saa_float) - INT(startpos_saa_float)
-       DO  ai = 0, 35
+              DO  ai = 0, 35
           DO  zi = 0, 9
-             radiance_array(ai,zi) = ( radiance_array_temp( ai + INT( startpos_saa_float ), zi ) * &
-                                     (1.0_wp - xfactor)) &
-                                     + ( radiance_array_temp( ai + 1 + INT( startpos_saa_float ), zi ) &
-                                     * xfactor)
+             radiance_array(ai,zi) = ( radiance_array_temp( 36 - INT( startpos_saa_float ) - 1 + ai , zi ) * &
+                                     ( xfactor ) ) &
+                                     + ( radiance_array_temp( 36 - INT( startpos_saa_float ) + ai , zi ) &
+                                     * ( 1.0_wp - xfactor ) )
           ENDDO
        ENDDO 
-
-
-
-                                    
-       DO  i = nxlg, nxrg    
-          DO  j = nysg, nyng
-!            
-!--          extract obstrcution from IBSET-Integer_Array ------------------'
-             IF (consider_obstructions == 1) THEN
-                obstruction_temp1 = obstruction_lookup_table(i,j,:)
+!        
+!      
+!--    calculate Projectionarea for direct beam -----------------------------'
+       projection_area_direct_temp( 0:35,:) = projection_area
+       projection_area_direct_temp(36:71,:) = projection_area
+       yfactor = ( sza / 10.0_wp ) - INT( sza / 10.0_wp )
+       xfactor = ( startpos_saa_float ) - INT( startpos_saa_float )
+       projection_area_direct_beam = ( projection_area_direct_temp( INT(startpos_saa_float)    ,INT(sza/10.0_wp)  ) *&
+                                     ( 1.0_wp - xfactor ) * ( 1.0_wp - yfactor ) ) + &
+                                     ( projection_area_direct_temp( INT(startpos_saa_float) + 1,INT(sza/10.0_wp)  ) *&
+                                     (          xfactor ) * ( 1.0_wp - yfactor ) ) + &
+                                     ( projection_area_direct_temp( INT(startpos_saa_float)    ,INT(sza/10.0_wp)+1) *&
+                                     ( 1.0_wp - xfactor ) * (          yfactor ) ) + &
+                                     ( projection_area_direct_temp( INT(startpos_saa_float) + 1,INT(sza/10.0_wp)+1) *&
+                                     (          xfactor ) * (          yfactor ) )
+!                                                
+!                                                
+!                                                
+       DO  i = nxl, nxr    !nxlg, nxrg
+          DO  j = nys, nyn    !nysg, nyng 
+!                   
+! !--        extract obstruction from IBSET-Integer_Array ------------------'
+             IF (consider_obstructions ) THEN
+                obstruction_temp1 = building_obstruction_f%var_3d(:,j,i)
                 IF (obstruction_temp1(0) .NE. 9) THEN 
                    DO  zi = 0, 44 
@@ -826,5 +776,5 @@
              ENDIF
 !              
-!--          calculated human exposure ------------------'  
+! !--        calculated human exposure ------------------'  
              diffuse_exposure = SUM( radiance_array * projection_area * integration_array * obstruction )      
          
@@ -834,5 +784,5 @@
              ENDIF
 !             
-!--          calculate direct normal irradiance (direct beam) ------------------'
+! !--        calculate direct normal irradiance (direct beam) ------------------'
              direct_exposure = ( irradiance(1) / cos( pi * sza / 180.0_wp ) ) * &
              projection_area_direct_beam * obstruction_direct_beam  
@@ -846,101 +796,3 @@
  END SUBROUTINE uvem_calc_exposure
 
-
-
-
- 
-! ------------------------------------------------------------------------------!
-! Description:
-! ------------
-! > Check parameters routine
-! ------------------------------------------------------------------------------!
-!  SUBROUTINE uvem_check_parameters
-! 
-!     USE control_parameters,                                                    &
-!         ONLY:  message_string
-! 
-!        
-!     IMPLICIT NONE
-! 
-! 
-! --    Checks go here (cf. check_parameters.f90). 
-!            
-!  END SUBROUTINE uvem_check_parameters
-
-
- 
-! !------------------------------------------------------------------------------!
-! ! Description:
-! ! ------------
-! !> Header output
-! !------------------------------------------------------------------------------!
-!  SUBROUTINE uvem_header ( io )
-! 
-! 
-!     IMPLICIT NONE
-! 
-!  
-!     INTEGER(iwp), INTENT(IN) ::  io   !< Unit of the output file
-!  
-! !
-! !-- Header output goes here
-! !-- ...
-! 
-!  END SUBROUTINE uvem_header
-
-
-
-! !------------------------------------------------------------------------------!
-! ! Description:
-! ! ------------
-! !> This routine reads the global restart data.
-! !------------------------------------------------------------------------------!
-!  SUBROUTINE uvem_rrd_global
-!
-!
-!     USE control_parameters,                                                    &
-!         ONLY: length, restart_string
-!
-!
-!     IMPLICIT NONE
-!
-!     LOGICAL, INTENT(OUT)  ::  found 
-!
-!
-!     found = .TRUE. 
-!        
-!        
-!     SELECT CASE ( restart_string(1:length) )
-!
-!       CASE ( 'param1' )
-!          READ ( 13 )  param1
-!
-!        CASE DEFAULT
-!
-!          found = .FALSE.   
-!
-!     END SELECT
-! 
-!  END SUBROUTINE uvem_rrd_global  
-    
-
-! !------------------------------------------------------------------------------!
-! ! Description:
-! ! ------------
-! !> This routine writes the global restart data.
-! !------------------------------------------------------------------------------!
-!  SUBROUTINE uvem_wrd_global
-! 
-!
-!     IMPLICIT NONE
-!
-!
-!     CALL wrd_write_string( 'param1' )
-!     WRITE ( 14 )  param1         
-! 
-!        
-!        
-!  END SUBROUTINE uvem_wrd_global   
-
-
  END MODULE uv_exposure_model_mod
