Index: palm/trunk/SOURCE/palm.f90
===================================================================
--- palm/trunk/SOURCE/palm.f90	(revision 2512)
+++ palm/trunk/SOURCE/palm.f90	(revision 2696)
@@ -1,5 +1,5 @@
 !> @file palm.f90
 !------------------------------------------------------------------------------!
-! This file is part of PALM.
+! This file is part of the PALM model system.
 !
 ! PALM is free software: you can redistribute it and/or modify it under the
@@ -25,4 +25,10 @@
 ! -----------------
 ! $Id$
+! Implementation of chemistry module (FK)
+! Introduce input-data standard
+! Rename lsm_last_actions into lsm_write_restart_data
+! Move usm_write_restart_data into io_blocks loop (MS)
+! 
+! 2512 2017-10-04 08:26:59Z raasch
 ! user interface required revision updated
 ! 
@@ -185,4 +191,5 @@
 !> @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
 !------------------------------------------------------------------------------!
  PROGRAM palm
@@ -191,6 +198,14 @@
     USE arrays_3d
 
+#if defined( __chem )
+    USE chemistry_model_mod,                                                   &
+        ONLY:  chem_init, chem_last_actions
+    USE chem_photolysis_mod,                                                   &
+        ONLY:  photolysis_init
+#endif
+
     USE control_parameters,                                                    &
-        ONLY:  cloud_physics, constant_diffusion, coupling_char, coupling_mode,&
+        ONLY:  air_chemistry,                                                  &
+               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,         &
@@ -208,8 +223,12 @@
         ONLY:  nbgp
 
+    USE netcdf_data_input_mod,                                                 &
+        ONLY:  netcdf_data_input_inquire_file, netcdf_data_input_init,         &
+               netcdf_data_input_surface_data, netcdf_data_input_topo
+
     USE kinds
 
     USE land_surface_model_mod,                                                &
-        ONLY:  lsm_last_actions
+        ONLY:  lsm_write_restart_data
 
     USE particle_attributes,                                                   &
@@ -326,9 +345,34 @@
 !-- Determine processor topology and local array indices
     CALL init_pegrid
-
-!
-!-- Generate grid parameters
+!
+!-- Check if input file according to input-data standard exists
+    CALL netcdf_data_input_inquire_file
+!
+!-- Read topography input data if required. This is required before the 
+!-- numerical grid is finally created in init_grid
+    CALL netcdf_data_input_topo  
+!
+!-- Generate grid parameters, initialize generic topography and further process
+!-- topography information if required
     CALL init_grid
-
+!
+!-- Read global attributes if available.  
+    CALL netcdf_data_input_init 
+!
+!-- Read surface classification data, e.g. vegetation and soil types, water 
+!-- surfaces, etc., if available. Some of these data is required before 
+!-- check parameters is invoked.     
+    CALL netcdf_data_input_surface_data
+!
+!-- Initialize chemistry (called before check_parameters due to dependencies)
+!-- --> Needs to be moved!! What is the dependency about?
+#if defined( __chem )
+! IF (  TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
+    IF ( air_chemistry )  THEN
+       CALL chem_init
+       CALL photolysis_init   ! probably also required for restart
+    ENDIF
+! END IF
+#endif
 !
 !-- Check control parameters and deduce further quantities
@@ -443,7 +487,4 @@
 !--    If required, write particle data
        IF ( particle_advection )  CALL lpm_write_restart_file
-!
-!--    If required, write urban surface data
-       IF (urban_surface)  CALL usm_write_restart_data
        
     ENDIF
@@ -460,10 +501,20 @@
     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_last_actions
+             CALL lsm_write_restart_data
           ENDIF
           IF ( radiation )  THEN
              CALL radiation_last_actions
           ENDIF
+#if defined( __chem )
+          IF ( air_chemistry )  THEN
+             CALL chem_last_actions
+          ENDIF
+#endif
+          
           CALL user_last_actions
           IF ( write_binary )  CALL close_file( 14 )
