Index: palm/trunk/SOURCE/palm.f90
===================================================================
--- palm/trunk/SOURCE/palm.f90	(revision 2801)
+++ palm/trunk/SOURCE/palm.f90	(revision 2894)
@@ -25,4 +25,11 @@
 ! -----------------
 ! $Id$
+! Modified todo list, _write_restart_data/_last_actions has been renamed to 
+! _wrd_local, unit 14 will be opened now for each io_group
+! write_3d_binary is called wrd_local now, wrd_global moved from wrd_local to 
+! palm.f90, unit 14 is closed directly after the wrd_local call, Module related
+! routines for writing restart data have been moved to wrd_local
+! 
+! 2801 2018-02-14 16:01:55Z suehring
 ! Changed lpm from subroutine to module.
 ! Introduce particle transfer in nested models.
@@ -204,5 +211,4 @@
 !>
 !> @todo create routine last_actions instead of calling lsm_last_actions etc.
-!> @todo eventually move CALL usm_write_restart_data to suitable location
 !> @todo move chem_init call to init_3d_model or to check_parameters
 !------------------------------------------------------------------------------!
@@ -213,5 +219,5 @@
 
     USE chemistry_model_mod,                                                   &
-        ONLY:  chem_init, chem_last_actions
+        ONLY:  chem_init
 
     USE chem_photolysis_mod,                                                   &
@@ -222,8 +228,8 @@
                cloud_physics, constant_diffusion, coupling_char, coupling_mode,&
                do2d_at_begin, do3d_at_begin, humidity, initializing_actions,   &
-               io_blocks, io_group, land_surface, large_scale_forcing,         &
+               io_blocks, io_group, large_scale_forcing,                       &
                message_string, microphysics_morrison, microphysics_seifert,    &
                nest_domain, neutral, nudging, passive_scalar, runnr,           &
-               simulated_time, simulated_time_chr, spinup, urban_surface,      &
+               simulated_time, simulated_time_chr, spinup,                     &
                user_interface_current_revision,                                &
                user_interface_required_revision, version, wall_heatflux,       &
@@ -242,11 +248,11 @@
     USE kinds
 
-    USE land_surface_model_mod,                                                &
-        ONLY:  lsm_write_restart_data
-
     USE particle_attributes,                                                   &
         ONLY:  particle_advection
 
     USE pegrid
+
+    USE pmc_particle_interface,                                                &
+        ONLY: pmcp_g_alloc_win
 
     USE pmc_interface,                                                         &
@@ -255,12 +261,7 @@
                pmci_ensure_nest_mass_conservation
 
-    USE pmc_particle_interface,                                                 &
-        ONLY: pmcp_g_alloc_win
-
-    USE radiation_model_mod,                                                   &
-        ONLY:  radiation, radiation_last_actions
-       
-    USE urban_surface_mod,                                                     &
-        ONLY:  usm_write_restart_data        
+    USE write_restart_data_mod,                                                &
+        ONLY:  wrd_global, wrd_local
+
 
     IMPLICIT NONE
@@ -478,15 +479,24 @@
     IF ( write_binary )  THEN
 
-       CALL cpu_log( log_point(22), 'write_3d_binary', 'start' )
+       CALL cpu_log( log_point(22), 'wrd_local', 'start' )
 
        CALL location_message( 'writing restart data', .FALSE. )
-
-       CALL check_open( 14 )
 
        DO  i = 0, io_blocks-1
           IF ( i == io_group )  THEN
-!
-!--          Write flow field data
-             CALL write_3d_binary
+
+!
+!--          Open binary file 
+             CALL check_open( 14 )
+!
+!--          Write control parameters and other global variables for restart.
+             IF ( myid == 0 )  CALL wrd_global
+!
+!--          Write processor specific flow field data for restart runs
+             CALL wrd_local
+!
+!--          Close binary file 
+             CALL close_file( 14 )
+
           ENDIF
 #if defined( __parallel )
@@ -497,8 +507,8 @@
        CALL location_message( 'finished', .TRUE. )
 
-       CALL cpu_log( log_point(22), 'write_3d_binary', 'stop' )
-
-!
-!--    If required, write particle data
+       CALL cpu_log( log_point(22), 'wrd_local', 'stop' )
+
+!
+!--    If required, write particle data in own restart files
        IF ( particle_advection )  CALL lpm_write_restart_file
        
@@ -509,34 +519,14 @@
     IF ( myid == 0 )  CALL header
 !
-!-- If required, final land surface and user-defined actions, and
+!-- If required, final  user-defined actions, and
 !-- last actions on the open files and close files. Unit 14 was opened
-!-- in write_3d_binary but it is closed here, to allow writing on this
+!-- in wrd_local but it is closed here, to allow writing on this
 !-- unit in routine user_last_actions.
     CALL cpu_log( log_point(4), 'last actions', 'start' )
-    DO  i = 0, io_blocks-1
-       IF ( i == io_group )  THEN
-
-          IF ( urban_surface )  THEN
-             CALL usm_write_restart_data
-          ENDIF
-          IF ( land_surface )  THEN
-             CALL lsm_write_restart_data
-          ENDIF
-          IF ( radiation )  THEN
-             CALL radiation_last_actions
-          ENDIF
-          IF ( air_chemistry )  THEN
-             CALL chem_last_actions
-          ENDIF
           
-          CALL user_last_actions
-          IF ( write_binary )  CALL close_file( 14 )
-       ENDIF
-#if defined( __parallel )
-       CALL MPI_BARRIER( comm2d, ierr )
-#endif
-    ENDDO
+    CALL user_last_actions
     CALL close_file( 0 )
     CALL close_dvrp
+
     CALL cpu_log( log_point(4), 'last actions', 'stop' )
 
