Index: palm/trunk/SOURCE/pres.f90
===================================================================
--- palm/trunk/SOURCE/pres.f90	(revision 3015)
+++ palm/trunk/SOURCE/pres.f90	(revision 3016)
@@ -24,5 +24,8 @@
 ! Former revisions:
 ! -----------------
-! Id: pres.f90 2696 2017-12-14 17:12:51Z kanani $
+! $Id$
+! Dollar sign added before Id
+! 
+! 2696 2017-12-14 17:12:51Z kanani
 ! To avoid jumps while plotting w-profiles w level nzt+1 is set to w level nzt 
 ! after velocity modifications through the pressure solver were carried out
Index: palm/trunk/SOURCE/radiation_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/radiation_model_mod.f90	(revision 3015)
+++ palm/trunk/SOURCE/radiation_model_mod.f90	(revision 3016)
@@ -28,4 +28,9 @@
 ! -----------------
 ! $Id$
+! Revised structure of reading svf data according to PALM coding standard: 
+! svf_code_field/len and fsvf removed, error messages PA0493 and PA0494 added,
+! allocation status of output arrays checked. 
+! 
+! 3014 2018-05-09 08:42:38Z maronga
 ! Introduced plant canopy height similar to urban canopy height to limit
 ! the memory requirement to allocate lad.
@@ -728,8 +733,6 @@
     INTEGER(iwp)                                   ::  nrefsteps = 0                      !< number of reflection steps to perform
     REAL(wp), PARAMETER                            ::  ext_coef = 0.6_wp                  !< extinction coefficient (a.k.a. alpha)
-    INTEGER(iwp), PARAMETER                        ::  svf_code_len = 15                  !< length of code for verification of the end of svf file
-    CHARACTER(svf_code_len), PARAMETER             ::  svf_code = '*** end svf ***'       !< code for verification of the end of svf file
     INTEGER(iwp), PARAMETER                        ::  rad_version_len = 10               !< length of identification string of rad version
-    CHARACTER(rad_version_len), PARAMETER          ::  rad_version = 'RAD v. 1.0'         !< identification of version of binary svf and restart files
+    CHARACTER(rad_version_len), PARAMETER          ::  rad_version = 'RAD v. 1.1'         !< identification of version of binary svf and restart files
     INTEGER(iwp)                                   ::  raytrace_discrete_elevs = 40       !< number of discretization steps for elevation (nadir to zenith)
     INTEGER(iwp)                                   ::  raytrace_discrete_azims = 80       !< number of discretization steps for azimuth (out of 360 degrees)
@@ -6753,94 +6756,125 @@
     SUBROUTINE radiation_read_svf
 
-        IMPLICIT NONE
-        INTEGER(iwp)                 :: fsvf = 88
-        INTEGER(iwp)                 :: i
-        INTEGER(iwp)                 :: nsurfl_from_file = 0
-        CHARACTER(rad_version_len)   :: rad_version_field
-        CHARACTER(svf_code_len)      :: svf_code_field
-
-        DO  i = 0, io_blocks-1
-           IF ( i == io_group )  THEN
-
-              IF ( initializing_actions == 'read_restart_data' ) THEN
-
-                 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', 'PA0491', 1, 2, 0, 6, 0 )
-                 ENDIF
-
-              ENDIF
-!
-!--           Open binary file 
-              CALL check_open( fsvf )
-
- !--          read and check version
-              READ ( fsvf ) rad_version_field
-              IF ( TRIM(rad_version_field) /= TRIM(rad_version) )  THEN
-                  WRITE( message_string, * ) 'Version of binary SVF file "',           &
-                              TRIM(rad_version_field), '" does not match ',            &
-                              'the version of model "', TRIM(rad_version), '"'
-                  CALL message( 'radiation_read_svf', 'PA0482', 1, 2, 0, 6, 0 )
-              ENDIF
+       IMPLICIT NONE
+       
+       CHARACTER(rad_version_len)   :: rad_version_field
+       
+       INTEGER(iwp)                 :: i
+       INTEGER(iwp)                 :: ndsidir_from_file = 0
+       INTEGER(iwp)                 :: npcbl_from_file = 0
+       INTEGER(iwp)                 :: nsurfl_from_file = 0
+       
+       DO  i = 0, io_blocks-1
+          IF ( i == io_group )  THEN
+
+!
+!--          numprocs_previous_run is only known in case of reading restart
+!--          data. If a new initial run which reads svf data is started the
+!--          following query will be skipped
+             IF ( initializing_actions == 'read_restart_data' ) THEN
+
+                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', 'PA0491', 1, 2, 0, 6, 0 )
+                ENDIF
+
+             ENDIF
               
- !--             read nsvfl, ncsfl
-              READ ( fsvf ) nsvfl, ncsfl, nsurfl_from_file, npcbl, ndsidir
-              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, CSF, and nsurfl to read '&
-                       , nsvfl, ncsfl, nsurfl
-                  CALL location_message( message_string, .TRUE. )
-              ENDIF
-              IF ( nsurfl_from_file /= nsurfl )  THEN
-                  WRITE( message_string, * ) 'nsurfl from SVF file does not ', &
-                                             'match calculated nsurfl from ',  &
-                                             'radiation_interaction_init'
-                  CALL message( 'radiation_read_svf', 'PA0490', 1, 2, 0, 6, 0 )
-              ENDIF
-              IF ( nsurfl > 0 )  THEN
-                 IF ( .NOT. ALLOCATED( skyvf ) )    ALLOCATE( skyvf(nsurfl) )
-                 IF ( .NOT. ALLOCATED( skyvft ) )   ALLOCATE( skyvft(nsurfl) )
-                 READ(fsvf) skyvf
-                 READ(fsvf) skyvft
-                 READ(fsvf) dsitrans  
-              ENDIF
+!
+!--          Open binary file 
+             CALL check_open( 88 )
+
+!
+!--          read and check version
+             READ ( 88 ) rad_version_field
+             IF ( TRIM(rad_version_field) /= TRIM(rad_version) )  THEN
+                 WRITE( message_string, * ) 'Version of binary SVF file "',    &
+                             TRIM(rad_version_field), '" does not match ',     &
+                             'the version of model "', TRIM(rad_version), '"'
+                 CALL message( 'radiation_read_svf', 'PA0482', 1, 2, 0, 6, 0 )
+             ENDIF
               
-              IF ( plant_canopy  .AND.  npcbl > 0 ) THEN
-                 READ ( fsvf )  dsitransc
-              ENDIF
-   
-              IF ( nsvfl > 0 )  THEN
-                 IF ( .NOT. ALLOCATED( svf ) )      ALLOCATE( svf(ndsvf,nsvfl) )
-                 IF ( .NOT. ALLOCATED( svfsurf ) )  ALLOCATE( svfsurf(idsvf,nsvfl) )
-                 READ(fsvf) svf
-                 READ(fsvf) svfsurf
-              ENDIF
-
-              IF ( plant_canopy  .AND.  ncsfl > 0 )  THEN
-                 IF ( .NOT. ALLOCATED( csf ) )      ALLOCATE( csf(ndcsf,ncsfl) )
-                 IF ( .NOT. ALLOCATED( csfsurf ) )  ALLOCATE( csfsurf(idcsf,ncsfl) )
-                 READ(fsvf) csf
-                 READ(fsvf) csfsurf
-              ENDIF
-              READ ( fsvf ) svf_code_field
+!
+!--          read nsvfl, ncsfl, nsurfl
+             READ ( 88 ) nsvfl, ncsfl, nsurfl_from_file, npcbl_from_file,      &
+                         ndsidir_from_file
+             
+             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, CSF, and nsurfl ',&
+                                         'to read', nsvfl, ncsfl,              &
+                                         nsurfl_from_file
+                 CALL location_message( message_string, .TRUE. )
+             ENDIF
+             
+             IF ( nsurfl_from_file /= nsurfl )  THEN
+                 WRITE( message_string, * ) 'nsurfl from SVF file does not ',  &
+                                            'match calculated nsurfl from ',   &
+                                            'radiation_interaction_init'
+                 CALL message( 'radiation_read_svf', 'PA0490', 1, 2, 0, 6, 0 )
+             ENDIF
+             
+             IF ( npcbl_from_file /= npcbl )  THEN
+                 WRITE( message_string, * ) 'npcbl from SVF file does not ',   &
+                                            'match calculated npcbl from ',    &
+                                            'radiation_interaction_init'
+                 CALL message( 'radiation_read_svf', 'PA0493', 1, 2, 0, 6, 0 )
+             ENDIF
+             
+             IF ( ndsidir_from_file /= ndsidir )  THEN
+                 WRITE( message_string, * ) 'ndsidir from SVF file does not ', &
+                                            'match calculated ndsidir from ',  &
+                                            'radiation_presimulate_solar_pos'
+                 CALL message( 'radiation_read_svf', 'PA0494', 1, 2, 0, 6, 0 )
+             ENDIF
+              
+!
+!--          Arrays skyvf, skyvft, dsitrans and dsitransc are allready 
+!--          allocated in radiation_interaction_init and 
+!--          radiation_presimulate_solar_pos
+             IF ( nsurfl > 0 )  THEN
+                READ(88) skyvf
+                READ(88) skyvft
+                READ(88) dsitrans  
+             ENDIF
+              
+             IF ( plant_canopy  .AND.  npcbl > 0 ) THEN
+                READ ( 88 )  dsitransc
+             ENDIF
+             
+!
+!--          The allocation of svf, svfsurf, csf and csfsurf happens in routine 
+!--          radiation_calc_svf which is not called if the program enters 
+!--          radiation_read_svf. Therefore these arrays has to allocate in the 
+!--          following
+             IF ( nsvfl > 0 )  THEN
+                ALLOCATE( svf(ndsvf,nsvfl) )
+                ALLOCATE( svfsurf(idsvf,nsvfl) )
+                READ(88) svf
+                READ(88) svfsurf
+             ENDIF
+
+             IF ( plant_canopy  .AND.  ncsfl > 0 )  THEN
+                ALLOCATE( csf(ndcsf,ncsfl) )
+                ALLOCATE( csfsurf(idcsf,ncsfl) )
+                READ(88) csf
+                READ(88) csfsurf
+             ENDIF
+              
+!
+!--          Close binary file                 
+             CALL close_file( 88 )
                 
-              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       
-!
-!--           Close binary file               
-              CALL close_file( fsvf )
-                
-           ENDIF
+          ENDIF
 #if defined( __parallel )
-           CALL MPI_BARRIER( comm2d, ierr )
+          CALL MPI_BARRIER( comm2d, ierr )
 #endif
-        ENDDO
+       ENDDO
 
     END SUBROUTINE radiation_read_svf
@@ -6855,42 +6889,42 @@
     SUBROUTINE radiation_write_svf
 
-        IMPLICIT NONE
-        INTEGER(iwp)        :: fsvf = 89
-        INTEGER(iwp)        :: i
-
-        DO  i = 0, io_blocks-1
-            IF ( i == io_group )  THEN
+       IMPLICIT NONE
+       
+       INTEGER(iwp)        :: i
+
+       DO  i = 0, io_blocks-1
+          IF ( i == io_group )  THEN
 !
 !--          Open binary file 
-             CALL check_open( fsvf )
-
-                WRITE ( fsvf )  rad_version
-                WRITE ( fsvf )  nsvfl, ncsfl, nsurfl, npcbl, ndsidir
-                IF ( nsurfl > 0 ) THEN
-                   WRITE ( fsvf )  skyvf
-                   WRITE ( fsvf )  skyvft
-                   WRITE ( fsvf )  dsitrans
-                ENDIF
-                IF ( npcbl > 0 ) THEN
-                   WRITE ( fsvf )  dsitransc
-                ENDIF
-                IF ( nsvfl > 0 ) THEN
-                   WRITE ( fsvf )  svf
-                   WRITE ( fsvf )  svfsurf
-                ENDIF
-                IF ( plant_canopy  .AND.  ncsfl > 0 )  THEN
-                    WRITE ( fsvf )  csf
-                    WRITE ( fsvf )  csfsurf
-                ENDIF
-                WRITE ( fsvf )  TRIM(svf_code)
+             CALL check_open( 89 )
+
+             WRITE ( 89 )  rad_version
+             WRITE ( 89 )  nsvfl, ncsfl, nsurfl, npcbl, ndsidir
+             IF ( nsurfl > 0 ) THEN
+                WRITE ( 89 )  skyvf
+                WRITE ( 89 )  skyvft
+                WRITE ( 89 )  dsitrans
+             ENDIF
+             IF ( npcbl > 0 ) THEN
+                WRITE ( 89 )  dsitransc
+             ENDIF
+             IF ( nsvfl > 0 ) THEN
+                WRITE ( 89 )  svf
+                WRITE ( 89 )  svfsurf
+             ENDIF
+             IF ( plant_canopy  .AND.  ncsfl > 0 )  THEN
+                 WRITE ( 89 )  csf
+                 WRITE ( 89 )  csfsurf
+             ENDIF
+
 !
 !--          Close binary file                 
-             CALL close_file( fsvf )
+             CALL close_file( 89 )
 
           ENDIF
 #if defined( __parallel )
-                CALL MPI_BARRIER( comm2d, ierr )
+          CALL MPI_BARRIER( comm2d, ierr )
 #endif
-        ENDDO
+       ENDDO
     END SUBROUTINE radiation_write_svf
 
