Index: palm/trunk/SOURCE/check_open.f90
===================================================================
--- palm/trunk/SOURCE/check_open.f90	(revision 2903)
+++ palm/trunk/SOURCE/check_open.f90	(revision 2906)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! CASE 88 and 89 has been added for the input/output of sky view factors
+! 
+! 2718 2018-01-02 08:49:38Z maronga
 ! Corrected "Former revisions" section
 ! 
@@ -512,6 +515,6 @@
                            FORM='UNFORMATTED', POSITION='APPEND', IOSTAT=ioerr )
                 IF ( ioerr /= 0 )  THEN
-                   WRITE( 9, * )  '*** could not open "PARTICLE_DATA'//    &
-                                  TRIM( coupling_char )//'/'//myid_char//  &
+                   WRITE( 9, * )  '*** could not open "PARTICLE_DATA'//        &
+                                  TRIM( coupling_char )//'/'//myid_char//      &
                                   '"! Trying again in 1 sec.'
                    CALL fortran_sleep( 1 )
@@ -533,4 +536,58 @@
              WRITE ( 85 )  particle_groups
              WRITE ( 85 )  nxl, nxr, nys, nyn, nzb, nzt, nbgp
+          ENDIF
+
+!
+!--    File where sky-view factors and further required data is stored will be 
+!--    read
+       CASE ( 88 )
+
+          IF (numprocs_previous_run /= numprocs) THEN
+             WRITE( message_string, * ) 'A different number of processors',    &
+                                        ' between the run that has written',   &
+                                        ' the svf data and the one that will ',&
+                                        ' read it is not allowed' 
+             CALL message( 'check_open', 'PA0484', 1, 2, 0, 6, 0 )
+          ENDIF
+
+          IF ( myid_char == '' )  THEN
+             OPEN ( 88, FILE='SVFIN'//TRIM( coupling_char )//myid_char,        &
+                        FORM='UNFORMATTED', STATUS='OLD', IOSTAT=ioerr )
+          ELSE
+
+             OPEN ( 88, FILE='SVFIN'//TRIM( coupling_char )//'/'//myid_char,   &
+                        FORM='UNFORMATTED', STATUS='OLD', IOSTAT=ioerr )
+          ENDIF
+
+!
+!--    File where sky-view factors and further required data is stored will be
+!--    created
+       CASE ( 89 )
+
+          IF ( myid_char == '' )  THEN
+             OPEN ( 89, FILE='SVFOUT'//TRIM( coupling_char )//myid_char,       &
+                        FORM='UNFORMATTED', STATUS='NEW' )
+          ELSE
+             IF ( myid == 0  .AND. .NOT. openfile(file_id)%opened_before )  THEN
+                CALL local_system( 'mkdir  SVFOUT' // TRIM( coupling_char ) )
+             ENDIF
+#if defined( __parallel )
+!
+!--          Set a barrier in order to allow that all other processors in the 
+!--          directory created by PE0 can open their file
+             CALL MPI_BARRIER( comm2d, ierr )
+#endif
+             ioerr = 1
+             DO WHILE ( ioerr /= 0 )
+                OPEN ( 89, FILE='SVFOUT'//TRIM(coupling_char)//'/'//myid_char, &
+                           FORM='UNFORMATTED', STATUS='NEW', IOSTAT=ioerr )
+                IF ( ioerr /= 0 )  THEN
+                   WRITE( 9, * )  '*** could not open "BINOUT'//         &
+                                  TRIM(coupling_char)//'/'//myid_char//  &
+                                  '"! Trying again in 1 sec.'
+                   CALL fortran_sleep( 1 )
+                ENDIF
+             ENDDO
+
           ENDIF
 
Index: palm/trunk/SOURCE/init_3d_model.f90
===================================================================
--- palm/trunk/SOURCE/init_3d_model.f90	(revision 2903)
+++ palm/trunk/SOURCE/init_3d_model.f90	(revision 2906)
@@ -25,4 +25,9 @@
 ! -----------------
 ! $Id$
+! The variables read/write_svf_on_init have been removed. Instead ENVIRONMENT
+! variables read/write_svf have been introduced. Location_message has been 
+! added.
+! 
+! 2894 2018-03-15 09:17:58Z Giersch
 ! Renamed routines with respect to reading restart data, file 13 is closed in
 ! rrd_read_parts_of_global now
@@ -474,5 +479,5 @@
         ONLY:  dots_max, dots_num, dots_unit, dots_label
 
-    USE netcdf_data_input_mod,                                                  &
+    USE netcdf_data_input_mod,                                                 &
         ONLY:  init_3d, netcdf_data_input_interpolate, netcdf_data_input_init_3d
     
@@ -487,6 +492,5 @@
     USE radiation_model_mod,                                                   &
         ONLY:  radiation_init, radiation, radiation_control, radiation_scheme, &
-               read_svf_on_init,                                               &
-               write_svf_on_init, radiation_calc_svf, radiation_write_svf,     &
+               radiation_calc_svf, radiation_write_svf,                        &
                radiation_interaction, radiation_interactions,                  &
                radiation_interaction_init, radiation_read_svf
@@ -2356,5 +2360,5 @@
 !
 !--    If required, read or calculate and write out the SVF 
-       IF ( radiation_interactions  .AND.  read_svf_on_init )  THEN
+       IF ( radiation_interactions .AND. read_svf)  THEN
 !
 !--       Read sky-view factors and further required data from file
@@ -2363,5 +2367,5 @@
           CALL location_message( '    Reading SVF from file has finished', .TRUE. )
 
-       ELSEIF ( radiation_interactions )  THEN
+       ELSEIF ( radiation_interactions .AND. .NOT. read_svf)  THEN
 !
 !--       calculate SFV and CSF
@@ -2371,8 +2375,10 @@
        ENDIF
 
-       IF ( radiation_interactions  .AND.  write_svf_on_init )  THEN
+       IF ( radiation_interactions .AND. write_svf)  THEN
 !
 !--       Write svf, csf svfsurf and csfsurf data to file
+          CALL location_message( '    Start writing SVF in file', .FALSE. )
           CALL radiation_write_svf()
+          CALL location_message( '    Writing SVF in file has finished', .TRUE. )
        ENDIF
 
Index: palm/trunk/SOURCE/modules.f90
===================================================================
--- palm/trunk/SOURCE/modules.f90	(revision 2903)
+++ palm/trunk/SOURCE/modules.f90	(revision 2906)
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! Module control_parameters has been extended with ENVIRONMENT variables 
+! read/write_svf 
+! 
+! 2894 2018-03-15 09:17:58Z Giersch
 ! _prerun flags were removed, Control paramters restart_string and length have
 ! been added
@@ -1298,4 +1302,5 @@
     LOGICAL ::  rans_tke_e = .FALSE.                             !< use TKE-e turbulence closure for RANS mode
     LOGICAL ::  rans_tke_l = .FALSE.                             !< use TKE-l turbulence closure for RANS mode
+    LOGICAL ::  read_svf = .FALSE.                               !< ENVPAR namelist parameter to steer input of svf (ENVPAR is created by palmrun)
     LOGICAL ::  recycling_yshift = .FALSE.                       !< namelist parameter
     LOGICAL ::  run_control_header = .FALSE.                     !< onetime output of RUN_CONTROL header
@@ -1327,5 +1332,6 @@
     LOGICAL ::  wall_adjustment = .TRUE.                         !< namelist parameter
     LOGICAL ::  wind_turbine = .FALSE.                           !< flag for use of wind turbine model
-    LOGICAL ::  write_binary = .FALSE.                           !< ENVPAR namelist parameter to steer restart I/O (ENVPAR is created by mrun)
+    LOGICAL ::  write_binary = .FALSE.                           !< ENVPAR namelist parameter to steer restart I/O (ENVPAR is created by palmrun)
+    LOGICAL ::  write_svf = .FALSE.                              !< ENVPAR namelist parameter to steer output of svf (ENVPAR is created by palmrun)
     LOGICAL ::  ws_scheme_sca = .FALSE.                          !< use Wicker-Skamarock scheme (scalar advection)?
     LOGICAL ::  ws_scheme_mom = .FALSE.                          !< use Wicker-Skamarock scheme (momentum advection)?
Index: palm/trunk/SOURCE/parin.f90
===================================================================
--- palm/trunk/SOURCE/parin.f90	(revision 2903)
+++ palm/trunk/SOURCE/parin.f90	(revision 2906)
@@ -25,4 +25,7 @@
 ! -----------------
 ! $Id$
+! ENVIRONMENT variables read/write_svf has been added 
+! 
+! 2894 2018-03-15 09:17:58Z Giersch
 ! read_var_list has been renamed to rrd_global, all module related _parin 
 ! routines are called before reading the global restart data to overwrite them
@@ -542,5 +545,6 @@
     NAMELIST /envpar/  batch_job, host, local_dvrserver_running,               &
                        maximum_cpu_time_allowed, maximum_parallel_io_streams,  &
-                       revision, run_identifier, tasks_per_node, write_binary
+                       read_svf, revision, run_identifier, tasks_per_node,     &
+                       write_binary, write_svf
 
 !
Index: palm/trunk/SOURCE/radiation_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/radiation_model_mod.f90	(revision 2903)
+++ palm/trunk/SOURCE/radiation_model_mod.f90	(revision 2906)
@@ -25,4 +25,9 @@
 ! -----------------
 ! $Id$
+! NAMELIST paramter read/write_svf_on_init have been removed, functions 
+! check_open and close_file are used now for opening/closing files related to
+! svf data, adjusted unit number and error numbers 
+! 
+! 2894 2018-03-15 09:17:58Z Giersch
 ! Calculations of the index range of the subdomain on file which overlaps with
 ! the current subdomain are already done in read_restart_data_mod
@@ -650,6 +655,4 @@
     LOGICAL                                        ::  energy_balance_surf_h = .TRUE.     !< flag parameter indicating wheather the energy balance is calculated for horizontal surfaces
     LOGICAL                                        ::  energy_balance_surf_v = .TRUE.     !< flag parameter indicating wheather the energy balance is calculated for vertical surfaces
-    LOGICAL                                        ::  read_svf_on_init = .FALSE.         !< flag parameter indicating wheather SVFs will be read from a file at initialization
-    LOGICAL                                        ::  write_svf_on_init = .FALSE.        !< flag parameter indicating wheather SVFs will be written out to a file
     LOGICAL                                        ::  mrt_factors = .FALSE.              !< whether to generate MRT factor files during init
     INTEGER(iwp)                                   ::  nrefsteps = 0                      !< number of reflection steps to perform
@@ -885,6 +888,6 @@
            zenith, calc_zenith, sun_direction, sun_dir_lat, sun_dir_lon,       &
            split_diffusion_radiation,                                          &
-           energy_balance_surf_h, energy_balance_surf_v, write_svf_on_init,    &
-           read_svf_on_init, nrefsteps, mrt_factors, dist_max_svf, nsvfl, svf, &
+           energy_balance_surf_h, energy_balance_surf_v,                       &
+           nrefsteps, mrt_factors, dist_max_svf, nsvfl, svf,                   &
            svfsurf, surfinsw, surfinlw, surfins, surfinl, surfinswdir,         &
            surfinswdif, surfoutsw, surfoutlw, surfinlwdif, rad_sw_in_dir,      &
@@ -2801,7 +2804,5 @@
                                   energy_balance_surf_h,                       &
                                   energy_balance_surf_v,                       &
-                                  read_svf_on_init,                            &
                                   nrefsteps,                                   &
-                                  write_svf_on_init,                           &
                                   mrt_factors,                                 &
                                   dist_max_svf,                                &
@@ -6612,58 +6613,65 @@
     SUBROUTINE radiation_read_svf
 
-        IMPLICIT NONE
-        INTEGER(iwp)                 :: fsvf = 89
-        INTEGER(iwp)                 :: i
-        CHARACTER(usm_version_len)   :: usm_version_field
-        CHARACTER(svf_code_len)      :: svf_code_field
-
-        DO  i = 0, io_blocks-1
-            IF ( i == io_group )  THEN
-                OPEN ( fsvf, FILE='SVFIN'//TRIM(coupling_char)//'/'//myid_char,&
-                    form='unformatted', status='old' )
-
-!--             read and check version
-                READ ( fsvf ) usm_version_field
-                IF ( TRIM(usm_version_field) /= TRIM(usm_version) )  THEN
-                    WRITE( message_string, * ) 'Version of binary SVF file "',           &
-                                            TRIM(usm_version_field), '" does not match ',            &
-                                            'the version of model "', TRIM(usm_version), '"'
-                    CALL message( 'radiation_read_svf', 'UI0012', 1, 2, 0, 6, 0 )
-                ENDIF
+       IMPLICIT NONE
+       INTEGER(iwp)                 :: fsvf = 88
+       INTEGER(iwp)                 :: i
+       CHARACTER(usm_version_len)   :: usm_version_field
+       CHARACTER(svf_code_len)      :: svf_code_field
+
+       DO  i = 0, io_blocks-1
+          IF ( i == io_group )  THEN
+
+!
+!--          Open binary file 
+             CALL check_open( fsvf )
+
+
+!--          read and check version
+             READ ( fsvf ) usm_version_field
+             IF ( TRIM(usm_version_field) /= TRIM(usm_version) )  THEN
+                 WRITE( message_string, * ) 'Version of binary SVF file "',           &
+                                         TRIM(usm_version_field), '" does not match ',            &
+                                         'the version of model "', TRIM(usm_version), '"'
+                 CALL message( 'radiation_read_svf', 'PA0482', 1, 2, 0, 6, 0 )
+             ENDIF
                 
-!--             read nsvfl, ncsfl
-                READ ( fsvf ) nsvfl, ncsfl
-                IF ( nsvfl <= 0  .OR.  ncsfl < 0 )  THEN
-                    WRITE( message_string, * ) 'Wrong number of SVF or CSF'
-                    CALL message( 'radiation_read_svf', 'UI0012', 1, 2, 0, 6, 0 )
-                ELSE
-                    WRITE(message_string,*) '    Number of SVF and CSF to read', nsvfl, ncsfl
-                    CALL location_message( message_string, .TRUE. )
-                ENDIF
+!--          read nsvfl, ncsfl
+             READ ( fsvf ) nsvfl, ncsfl
+             IF ( nsvfl <= 0  .OR.  ncsfl < 0 )  THEN
+                WRITE( message_string, * ) 'Wrong number of SVF or CSF'
+                CALL message( 'radiation_read_svf', 'PA0483', 1, 2, 0, 6, 0 )
+             ELSE
+                WRITE(message_string,*) '    Number of SVF and CSF to read', nsvfl, ncsfl
+                CALL location_message( message_string, .TRUE. )
+             ENDIF
                 
-                ALLOCATE(svf(ndsvf,nsvfl))
-                ALLOCATE(svfsurf(idsvf,nsvfl))
-                READ(fsvf) svf
-                READ(fsvf) svfsurf
-                IF ( plant_canopy )  THEN
-                    ALLOCATE(csf(ndcsf,ncsfl))
-                    ALLOCATE(csfsurf(idcsf,ncsfl))
-                    READ(fsvf) csf
-                    READ(fsvf) csfsurf
-                ENDIF
-                READ ( fsvf ) svf_code_field
+             ALLOCATE(svf(ndsvf,nsvfl))
+             ALLOCATE(svfsurf(idsvf,nsvfl))
+
+             READ(fsvf) svf
+             READ(fsvf) svfsurf
+
+             IF ( plant_canopy )  THEN
+                 ALLOCATE(csf(ndcsf,ncsfl))
+                 ALLOCATE(csfsurf(idcsf,ncsfl))
+                 READ(fsvf) csf
+                 READ(fsvf) csfsurf
+             ENDIF
+
+             READ ( fsvf ) svf_code_field
+             IF ( TRIM(svf_code_field) /= TRIM(svf_code) )  THEN
+                WRITE( message_string, * ) 'Wrong structure of binary svf file'
+                CALL message( 'radiation_read_svf', 'PA0484', 1, 2, 0, 6, 0 )
+             ENDIF
                 
-                IF ( TRIM(svf_code_field) /= TRIM(svf_code) )  THEN
-                    WRITE( message_string, * ) 'Wrong structure of binary svf file'
-                    CALL message( 'radiation_read_svf', 'UI0012', 1, 2, 0, 6, 0 )
-                ENDIF
+!
+!--          Close binary file                 
+             CALL close_file( fsvf )
                 
-                CLOSE (fsvf)
-                
-            ENDIF
+          ENDIF
 #if defined( __parallel )
-            CALL MPI_BARRIER( comm2d, ierr )
+          CALL MPI_BARRIER( comm2d, ierr )
 #endif
-        ENDDO
+       ENDDO
 
     END SUBROUTINE radiation_read_svf
@@ -6678,29 +6686,37 @@
     SUBROUTINE radiation_write_svf
 
-        IMPLICIT NONE
-        INTEGER(iwp)        :: fsvf = 89
-        INTEGER(iwp)        :: i
-
-        DO  i = 0, io_blocks-1
-            IF ( i == io_group )  THEN
-                OPEN ( fsvf, FILE='SVFOUT'//TRIM( coupling_char )//'/'//myid_char,   &
-                    form='unformatted', status='new' )
-
-                WRITE ( fsvf )  usm_version
-                WRITE ( fsvf )  nsvfl, ncsfl
-                WRITE ( fsvf )  svf
-                WRITE ( fsvf )  svfsurf
-                IF ( plant_canopy )  THEN
-                    WRITE ( fsvf )  csf
-                    WRITE ( fsvf )  csfsurf
-                ENDIF
-                WRITE ( fsvf )  TRIM(svf_code)
-                
-                CLOSE (fsvf)
+
+       IMPLICIT NONE
+
+       INTEGER(iwp)        :: fsvf = 89
+       INTEGER(iwp)        :: i
+
+
+       DO  i = 0, io_blocks-1
+          IF ( i == io_group )  THEN
+            
+!
+!--          Open binary file 
+             CALL check_open( fsvf )
+
+             WRITE ( fsvf )  usm_version
+             WRITE ( fsvf )  nsvfl, ncsfl
+             WRITE ( fsvf )  svf
+             WRITE ( fsvf )  svfsurf
+             IF ( plant_canopy )  THEN
+                WRITE ( fsvf )  csf
+                WRITE ( fsvf )  csfsurf
+             ENDIF
+             WRITE ( fsvf )  TRIM(svf_code)
+
+!
+!--          Close binary file                 
+             CALL close_file( fsvf )
+
+          ENDIF
 #if defined( __parallel )
-                CALL MPI_BARRIER( comm2d, ierr )
+          CALL MPI_BARRIER( comm2d, ierr )
 #endif
-            ENDIF
-        ENDDO
+       ENDDO
 
     END SUBROUTINE radiation_write_svf
Index: palm/trunk/SOURCE/urban_surface_mod.f90
===================================================================
--- palm/trunk/SOURCE/urban_surface_mod.f90	(revision 2903)
+++ palm/trunk/SOURCE/urban_surface_mod.f90	(revision 2906)
@@ -26,4 +26,8 @@
 ! -----------------
 ! $Id$
+! Local variable ids has to be initialized with a value of -1 in 
+! usm_average_3d_data
+! 
+! 2894 2018-03-15 09:17:58Z Giersch
 ! Calculations of the index range of the subdomain on file which overlaps with
 ! the current subdomain are already done in read_restart_data_mod,
@@ -1177,4 +1181,5 @@
 
 !--     find the real name of the variable
+        ids = -1
         var = TRIM(variable)
         DO i = 0, nd-1
