Index: palm/trunk/SOURCE/radiation_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/radiation_model_mod.f90	(revision 2894)
+++ 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
