Index: palm/trunk/SOURCE/chemistry_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/chemistry_model_mod.f90	(revision 4227)
+++ palm/trunk/SOURCE/chemistry_model_mod.f90	(revision 4230)
@@ -27,4 +27,8 @@
 ! -----------------
 ! $Id$
+! Bugfix, initialize mean profiles also in restart runs. Also initialize 
+! array used for Runge-Kutta tendecies in restart runs.  
+! 
+! 4227 2019-09-10 18:04:34Z gronemeier
 ! implement new palm_date_time_mod
 ! 
@@ -1948,12 +1952,12 @@
           ENDDO
        ENDIF 
-!
-!--    Initiale old and new time levels. 
-       DO  lsp = 1, nvar
-          chem_species(lsp)%tconc_m = 0.0_wp                      
-          chem_species(lsp)%conc_p  = chem_species(lsp)%conc     
-       ENDDO
 
     ENDIF
+!
+!-- Initiale old and new time levels. Note, this has to be done also in restart runs
+    DO  lsp = 1, nvar
+       chem_species(lsp)%tconc_m = 0.0_wp                      
+       chem_species(lsp)%conc_p  = chem_species(lsp)%conc     
+    ENDDO
 
     DO  lsp = 1, nphot
@@ -1964,5 +1968,5 @@
 !--          WRITE(6,'(a,i4,3x,a)')  'Photolysis: ',lsp,TRIM( phot_names(lsp) )
 !--       ENDIF 
-          phot_frequen(lsp)%freq(nzb:nzt+1,nysg:nyng,nxlg:nxrg)  =>  freq_1(:,:,:,lsp)
+       phot_frequen(lsp)%freq(nzb:nzt+1,nysg:nyng,nxlg:nxrg)  =>  freq_1(:,:,:,lsp)
     ENDDO
 
@@ -1982,7 +1986,4 @@
 !------------------------------------------------------------------------------!
  SUBROUTINE chem_init_profiles              
-!
-!-- SUBROUTINE is called from chem_init in case of TRIM( initializing_actions ) /= 'read_restart_data'
-!< We still need to see what has to be done in case of restart run
 
     USE chem_modules
@@ -2000,57 +2001,59 @@
 !-- "cs_heights" are prescribed, their values will!override the constant profile given by
 !-- "cs_surface".
-    IF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN 
-       lsp_usr = 1
-       DO  WHILE ( TRIM( cs_name( lsp_usr ) ) /= 'novalue' )   !'novalue' is the default
-          DO  lsp = 1, nspec                                !
-!
-!--          create initial profile (conc_pr_init) for each chemical species
-             IF ( TRIM( chem_species(lsp)%name ) == TRIM( cs_name(lsp_usr) ) )  THEN   !
-                IF ( cs_profile(lsp_usr,1) == 9999999.9_wp )  THEN
-!
-!--               set a vertically constant profile based on the surface conc (cs_surface(lsp_usr)) of each species
-                   DO lpr_lev = 0, nzt+1
-                      chem_species(lsp)%conc_pr_init(lpr_lev) = cs_surface(lsp_usr)
-                   ENDDO
-                ELSE
-                   IF ( cs_heights(1,1) /= 0.0_wp )  THEN
-                      message_string = 'The surface value of cs_heights must be 0.0'
-                      CALL message( 'chem_check_parameters', 'CM0434', 1, 2, 0, 6, 0 )
+!     IF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN 
+    lsp_usr = 1
+    DO  WHILE ( TRIM( cs_name( lsp_usr ) ) /= 'novalue' )   !'novalue' is the default
+       DO  lsp = 1, nspec                                !
+!
+!--       create initial profile (conc_pr_init) for each chemical species
+          IF ( TRIM( chem_species(lsp)%name ) == TRIM( cs_name(lsp_usr) ) )  THEN   !
+             IF ( cs_profile(lsp_usr,1) == 9999999.9_wp )  THEN
+!
+!--            set a vertically constant profile based on the surface conc (cs_surface(lsp_usr)) of each species
+                DO lpr_lev = 0, nzt+1
+                   chem_species(lsp)%conc_pr_init(lpr_lev) = cs_surface(lsp_usr)
+                ENDDO
+             ELSE
+                IF ( cs_heights(1,1) /= 0.0_wp )  THEN
+                   message_string = 'The surface value of cs_heights must be 0.0'
+                   CALL message( 'chem_check_parameters', 'CM0434', 1, 2, 0, 6, 0 )
+                ENDIF
+
+                use_prescribed_profile_data = .TRUE.
+
+                npr_lev = 1
+!                chem_species(lsp)%conc_pr_init(0) = 0.0_wp
+                DO  lpr_lev = 1, nz+1
+                   IF ( npr_lev < 100 )  THEN
+                      DO  WHILE ( cs_heights(lsp_usr, npr_lev+1) <= zu(lpr_lev) )
+                         npr_lev = npr_lev + 1
+                         IF ( npr_lev == 100 )  THEN
+                            message_string = 'number of chem spcs exceeding the limit'
+                            CALL message( 'chem_check_parameters', 'CM0435', 1, 2, 0, 6, 0 )               
+                            EXIT
+                         ENDIF
+                      ENDDO
                    ENDIF
-
-                   use_prescribed_profile_data = .TRUE.
-
-                   npr_lev = 1
-!                   chem_species(lsp)%conc_pr_init(0) = 0.0_wp
-                   DO  lpr_lev = 1, nz+1
-                      IF ( npr_lev < 100 )  THEN
-                         DO  WHILE ( cs_heights(lsp_usr, npr_lev+1) <= zu(lpr_lev) )
-                            npr_lev = npr_lev + 1
-                            IF ( npr_lev == 100 )  THEN
-                               message_string = 'number of chem spcs exceeding the limit'
-                               CALL message( 'chem_check_parameters', 'CM0435', 1, 2, 0, 6, 0 )               
-                               EXIT
-                            ENDIF
-                         ENDDO
-                      ENDIF
-                      IF ( npr_lev < 100  .AND.  cs_heights(lsp_usr,npr_lev+1) /= 9999999.9_wp )  THEN
-                         chem_species(lsp)%conc_pr_init(lpr_lev) = cs_profile(lsp_usr, npr_lev) +       &
-                              ( zu(lpr_lev) - cs_heights(lsp_usr, npr_lev) ) /                          &
-                              ( cs_heights(lsp_usr, (npr_lev + 1)) - cs_heights(lsp_usr, npr_lev ) ) *  &
-                              ( cs_profile(lsp_usr, (npr_lev + 1)) - cs_profile(lsp_usr, npr_lev ) )
-                      ELSE
-                         chem_species(lsp)%conc_pr_init(lpr_lev) = cs_profile(lsp_usr, npr_lev)
-                      ENDIF
-                   ENDDO
-                ENDIF
-!
-!--          If a profile is prescribed explicity using cs_profiles and cs_heights, then  
-!--          chem_species(lsp)%conc_pr_init is populated with the specific "lsp" based
-!--          on the cs_profiles(lsp_usr,:)  and cs_heights(lsp_usr,:). 
+                   IF ( npr_lev < 100  .AND.  cs_heights(lsp_usr,npr_lev+1) /= 9999999.9_wp )  THEN
+                      chem_species(lsp)%conc_pr_init(lpr_lev) = cs_profile(lsp_usr, npr_lev) +       &
+                           ( zu(lpr_lev) - cs_heights(lsp_usr, npr_lev) ) /                          &
+                           ( cs_heights(lsp_usr, (npr_lev + 1)) - cs_heights(lsp_usr, npr_lev ) ) *  &
+                           ( cs_profile(lsp_usr, (npr_lev + 1)) - cs_profile(lsp_usr, npr_lev ) )
+                   ELSE
+                      chem_species(lsp)%conc_pr_init(lpr_lev) = cs_profile(lsp_usr, npr_lev)
+                   ENDIF
+                ENDDO
              ENDIF
-          ENDDO
-          lsp_usr = lsp_usr + 1
+!
+!--       If a profile is prescribed explicity using cs_profiles and cs_heights, then  
+!--       chem_species(lsp)%conc_pr_init is populated with the specific "lsp" based
+!--       on the cs_profiles(lsp_usr,:)  and cs_heights(lsp_usr,:). 
+          ENDIF
+
        ENDDO
-    ENDIF
+
+       lsp_usr = lsp_usr + 1
+    ENDDO
+!     ENDIF
 
  END SUBROUTINE chem_init_profiles
