Index: palm/trunk/SOURCE/read_3d_binary.f90
===================================================================
--- palm/trunk/SOURCE/read_3d_binary.f90	(revision 1469)
+++ palm/trunk/SOURCE/read_3d_binary.f90	(revision 1551)
@@ -20,5 +20,7 @@
 ! Current revisions:
 ! -----------------
-! 
+! Added support for binary input of land surface and radiation model data. In the
+! course of this work, new temporary arrays tmp_3d_soil1, tmp_3d_soil2 were
+! required.
 ! 
 ! Former revisions:
@@ -94,8 +96,17 @@
     USE kinds
 
+    USE land_surface_model_mod,                                                &
+        ONLY:  c_liq_av, c_soil_av, c_veg, c_veg_av, ghf_eb_av, lai_av,        &
+               qsws_eb_av, qsws_liq_eb_av, qsws_soil_eb_av, qsws_veg_eb_av,    & 
+               land_surface, m_liq_eb, m_liq_eb_av, m_soil, m_soil_av,         &
+               nzb_soil, nzt_soil, shf_eb_av, t_soil, t_soil_av
+
     USE particle_attributes,                                                   &
         ONLY:  iran_part
 
     USE pegrid
+
+    USE radiation_model_mod,                                                   &
+        ONLY: rad_net_av, rad_sw_in_av
 
     USE random_function_mod,                                                   &
@@ -157,18 +168,20 @@
     REAL(wp) ::  rdummy
 
-    REAL(wp), DIMENSION(:,:), ALLOCATABLE     ::  tmp_2d     !:
-    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3d     !:
-    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwul  !:
-    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwun  !:
-    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwur  !:
-    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwus  !:
-    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwvl  !:
-    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwvn  !:
-    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwvr  !:
-    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwvs  !:
-    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwwl  !:
-    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwwn  !:
-    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwwr  !:
-    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwws  !:
+    REAL(wp), DIMENSION(:,:), ALLOCATABLE     ::  tmp_2d      !: temporary array for storing 2D data
+    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3d      !: temporary array for storing 3D data
+    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3d_soil1!: temporary array for storing 3D soil model data
+    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3d_soil2!: temporary array for storing 3D soil model data
+    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwul   !:
+    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwun   !:
+    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwur   !:
+    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwus   !:
+    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwvl   !:
+    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwvn   !:
+    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwvr   !:
+    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwvs   !:
+    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwwl   !:
+    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwwn   !:
+    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwwr   !:
+    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp_3dwws   !:
 
     REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  tmp_4d     !:
@@ -317,5 +330,5 @@
 !--    First compare the version numbers
        READ ( 13 )  version_on_file
-       binary_version = '3.4'
+       binary_version = '4.0'
        IF ( TRIM( version_on_file ) /= TRIM( binary_version ) )  THEN
           WRITE( message_string, * ) 'version mismatch concerning data ',      &
@@ -387,9 +400,20 @@
 !
 !--    Allocate temporary arrays sized as the arrays on the restart file
-       ALLOCATE( tmp_2d(nys_on_file-nbgp:nyn_on_file+nbgp,           &
-                        nxl_on_file-nbgp:nxr_on_file+nbgp),          &
-                 tmp_3d(nzb:nzt+1,nys_on_file-nbgp:nyn_on_file+nbgp, &
+       ALLOCATE( tmp_2d(nys_on_file-nbgp:nyn_on_file+nbgp,                     &
+                        nxl_on_file-nbgp:nxr_on_file+nbgp),                    &
+                 tmp_3d(nzb:nzt+1,nys_on_file-nbgp:nyn_on_file+nbgp,           &
                         nxl_on_file-nbgp:nxr_on_file+nbgp) )
 
+!
+!--    If the land surface model is used, allocate array for storing soil model
+!--    data
+       IF ( land_surface )  THEN
+          ALLOCATE( tmp_3d_soil1(nzb_soil:nzt_soil+1,                          &
+                                nys_on_file-nbgp:nyn_on_file+nbgp,             &
+                                nxl_on_file-nbgp:nxr_on_file+nbgp) )
+          ALLOCATE( tmp_3d_soil2(nzb_soil:nzt_soil,                            &
+                                nys_on_file-nbgp:nyn_on_file+nbgp,             &
+                                nxl_on_file-nbgp:nxr_on_file+nbgp) )
+       ENDIF
 !
 !--    Read arrays
@@ -423,4 +447,28 @@
              SELECT CASE ( TRIM( field_chr ) )
 
+                CASE ( 'c_liq_av' )
+                   IF ( .NOT. ALLOCATED( c_liq_av ) )  THEN
+                      ALLOCATE( c_liq_av(nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_2d
+                   c_liq_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                  tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+                CASE ( 'c_soil_av' )
+                   IF ( .NOT. ALLOCATED( c_soil_av ) )  THEN
+                      ALLOCATE( c_soil_av(nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_2d
+                   c_soil_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                  tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+                CASE ( 'c_veg_av' )
+                   IF ( .NOT. ALLOCATED( c_veg_av ) )  THEN
+                      ALLOCATE( c_veg_av(nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_2d
+                   c_veg_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                  tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
                 CASE ( 'e' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
@@ -436,8 +484,24 @@
                             tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
+                CASE ( 'ghf_eb_av' )
+                   IF ( .NOT. ALLOCATED( ghf_eb_av ) )  THEN
+                      ALLOCATE( ghf_eb_av(nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_2d
+                   ghf_eb_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                  tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
                 CASE ( 'iran' ) ! matching random numbers is still unresolved
                                 ! issue
                    IF ( k == 1 )  READ ( 13 )  iran, iran_part
 
+                CASE ( 'lai_av' )
+                   IF ( .NOT. ALLOCATED( lai_av ) )  THEN
+                      ALLOCATE( lai_av(nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_2d
+                   lai_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
+                                  tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
                 CASE ( 'kh' )
                    IF ( k == 1 )  READ ( 13 )  tmp_3d
@@ -465,4 +529,31 @@
                    lwp_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
                                   tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+                CASE ( 'm_liq_eb' )
+                   IF ( k == 1 )  READ ( 13 )  tmp_2d
+                   m_liq_eb(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  =        &
+                                 tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+                CASE ( 'm_liq_eb_av' )
+                   IF ( .NOT. ALLOCATED( m_liq_eb_av ) )  THEN
+                      ALLOCATE( m_liq_eb_av(nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_2d
+                   m_liq_eb_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =      &
+                                  tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+                CASE ( 'm_soil' )
+                   IF ( k == 1 )  READ ( 13 )  tmp_3d_soil2(:,:,:)
+                   m_soil(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =         &
+                          tmp_3d_soil2(nzb_soil:nzt_soil,nysf-nbgp:nynf        &
+                          +nbgp,nxlf-nbgp:nxrf+nbgp)
+
+                CASE ( 'm_soil_av' )
+                   IF ( .NOT. ALLOCATED( m_soil_av ) )  THEN
+                      ALLOCATE( m_soil_av(nzb_soil:nzt_soil,nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_3d_soil2(:,:,:)
+                   m_soil_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =      &
+                                    tmp_3d_soil2(nzb_soil:nzt_soil,nysf        &
+                                    -nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'nr' )
@@ -679,4 +770,35 @@
                                           tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
+                CASE ( 'qsws_eb_av' )
+                   IF ( .NOT. ALLOCATED( qsws_eb_av ) )  THEN
+                      ALLOCATE( qsws_eb_av(nysg:nyng,nxlg:nxrg) )
+                   ENDIF  
+                   IF ( k == 1 )  READ ( 13 )  tmp_2d
+                   qsws_eb_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                                          tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+                CASE ( 'qsws_liq_eb_av' )
+                   IF ( .NOT. ALLOCATED( qsws_liq_eb_av ) )  THEN
+                      ALLOCATE( qsws_liq_eb_av(nysg:nyng,nxlg:nxrg) )
+                   ENDIF  
+                   IF ( k == 1 )  READ ( 13 )  tmp_2d
+                   qsws_liq_eb_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                                          tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+                CASE ( 'qsws_soil_eb_av' )
+                   IF ( .NOT. ALLOCATED( qsws_soil_eb_av ) )  THEN
+                      ALLOCATE( qsws_soil_eb_av(nysg:nyng,nxlg:nxrg) )
+                   ENDIF  
+                   IF ( k == 1 )  READ ( 13 )  tmp_2d
+                   qsws_soil_eb_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                                          tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+                CASE ( 'qsws_veg_eb_av' )
+                   IF ( .NOT. ALLOCATED( qsws_veg_eb_av ) )  THEN
+                      ALLOCATE( qsws_veg_eb_av(nysg:nyng,nxlg:nxrg) )
+                   ENDIF  
+                   IF ( k == 1 )  READ ( 13 )  tmp_2d
+                   qsws_veg_eb_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                                          tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
                 CASE ( 'qv_av' )
                    IF ( .NOT. ALLOCATED( qv_av ) )  THEN
@@ -686,4 +808,20 @@
                    qv_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) = &
                              tmp_3d(:,nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+                CASE ( 'rad_net_av' )
+                   IF ( .NOT. ALLOCATED( rad_net_av ) )  THEN
+                      ALLOCATE( rad_net_av(nysg:nyng,nxlg:nxrg) )
+                   ENDIF  
+                   IF ( k == 1 )  READ ( 13 )  tmp_2d
+                   rad_net_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                                          tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+                CASE ( 'rad_sw_in_av' )
+                   IF ( .NOT. ALLOCATED( rad_sw_in_av ) )  THEN
+                      ALLOCATE( rad_sw_in_av(nysg:nyng,nxlg:nxrg) )
+                   ENDIF  
+                   IF ( k == 1 )  READ ( 13 )  tmp_2d
+                   rad_sw_in_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                                          tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'random_iv' )  ! still unresolved issue
@@ -759,4 +897,12 @@
                    IF ( k == 1 )  READ ( 13 )  tmp_2d
                    shf_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
+                         tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+                CASE ( 'shf_eb_av' )
+                   IF ( .NOT. ALLOCATED( shf_eb_av ) )  THEN
+                      ALLOCATE( shf_eb_av(nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_2d
+                   shf_eb_av(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
                          tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
 
@@ -808,4 +954,19 @@
                    tswst(nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp)  = &
                          tmp_2d(nysf-nbgp:nynf+nbgp,nxlf-nbgp:nxrf+nbgp)
+
+                CASE ( 't_soil' )
+                   IF ( k == 1 )  READ ( 13 )  tmp_3d_soil1
+                   t_soil(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =         &
+                                   tmp_3d_soil1(:,nysf-nbgp:nynf+nbgp,         &
+                                                nxlf-nbgp:nxrf+nbgp)
+
+                CASE ( 't_soil_av' )
+                   IF ( .NOT. ALLOCATED( t_soil_av ) )  THEN
+                      ALLOCATE( t_soil_av(nzb_soil:nzt_soil,nysg:nyng,nxlg:nxrg) )
+                   ENDIF
+                   IF ( k == 1 )  READ ( 13 )  tmp_3d_soil2(:,:,:)
+                   t_soil_av(:,nysc-nbgp:nync+nbgp,nxlc-nbgp:nxrc+nbgp) =      &
+                                    tmp_3d_soil2(:,nysf-nbgp:nynf+nbgp,        &
+                                    nxlf-nbgp:nxrf+nbgp)
 
                 CASE ( 'u' )
@@ -1085,4 +1246,6 @@
 
        DEALLOCATE( tmp_2d, tmp_3d )
+       IF ( ALLOCATED( tmp_3d_soil1 ) )  DEALLOCATE( tmp_3d_soil1 )
+       IF ( ALLOCATED( tmp_3d_soil2 ) )  DEALLOCATE( tmp_3d_soil2 )
 
     ENDDO  ! loop over restart files
