Index: palm/trunk/SOURCE/chemistry_model_mod.f90
===================================================================
--- palm/trunk/SOURCE/chemistry_model_mod.f90	(revision 3719)
+++ palm/trunk/SOURCE/chemistry_model_mod.f90	(revision 3737)
@@ -27,4 +27,8 @@
 ! -----------------
 ! $Id$
+! Enable mesoscale offline nesting for chemistry variables as well as 
+! initialization of chemistry via dynamic input file.
+! 
+! 3719 2019-02-06 13:10:18Z kanani
 ! Resolved cpu logpoint overlap with all progn.equations, moved cpu_log call
 ! to prognostic_equations for better overview
@@ -1408,7 +1412,15 @@
 !                                                           TRIM(chem_species(lsp)%name)       
             IF (av == 0) THEN
+            write(9,*) "before", TRIM(chem_species(lsp)%name), fill_value
+            flush(9)
                DO  i = nxl, nxr
                   DO  j = nys, nyn
                      DO  k = nzb_do, nzt_do
+!                      write(9,*) k, j, i
+!                      flush(9)
+!                      write(9) chem_species(lsp)%conc(k,j,i)
+!                      flush(9)
+!                      write(9) "fill", fill_value
+!                      flush(9)
                          local_pf(i,j,k) = MERGE(                             &
                                              chem_species(lsp)%conc(k,j,i),   &
@@ -1745,9 +1757,30 @@
     USE chem_emissions_mod,                                                    &
         ONLY:  chem_emissions_init
+        
+    USE netcdf_data_input_mod,                                                 &
+        ONLY:  init_3d
 
     IMPLICIT NONE
 
+    INTEGER(iwp) ::  i !< running index x dimension
+    INTEGER(iwp) ::  j !< running index y dimension
+    INTEGER(iwp) ::  n !< running index for chemical species
 
     IF ( do_emis )  CALL chem_emissions_init
+!
+!-- Chemistry variables will be initialized if availabe from dynamic 
+!-- input file. Note, it is possible to initialize only part of the chemistry
+!-- variables from dynamic input. 
+    IF ( INDEX( initializing_actions, 'inifor' ) /= 0 )  THEN
+       DO  n = 1, nspec
+          IF ( init_3d%from_file_chem(n) )  THEN
+             DO  i = nxlg, nxrg
+                DO  j = nysg, nyng
+                   chem_species(n)%conc(:,j,i) = init_3d%chem_init(:,n)
+                ENDDO
+             ENDDO
+          ENDIF
+       ENDDO
+    ENDIF
 
 
@@ -1764,12 +1797,13 @@
  SUBROUTINE chem_init_internal
 
-    USE control_parameters,                                                  &
+    USE control_parameters,                                                    &
         ONLY:  message_string, io_blocks, io_group, turbulent_inflow
-    USE arrays_3d,                                                           &
+    USE arrays_3d,                                                             &
         ONLY:  mean_inflow_profiles
     USE pegrid
 
     USE netcdf_data_input_mod,                                                 &
-        ONLY:  chem_emis, chem_emis_att, netcdf_data_input_chemistry_data
+        ONLY:  chem_emis, chem_emis_att, input_pids_dynamic, init_3d,          &
+               netcdf_data_input_chemistry_data
 
     IMPLICIT NONE
@@ -1839,11 +1873,23 @@
 !-- Initial concentration of profiles is prescribed by parameters cs_profile
 !-- and cs_heights in the namelist &chemistry_parameters
-    CALL chem_init_profiles      
+    CALL chem_init_profiles
+!    
+!-- In case there is dynamic input file, create a list of names for chemistry
+!-- initial input files. Also, initialize array that indicates whether the
+!-- respective variable is on file or not. 
+    IF ( input_pids_dynamic )  THEN    
+       ALLOCATE( init_3d%var_names_chem(1:nspec) )
+       ALLOCATE( init_3d%from_file_chem(1:nspec) )
+       init_3d%from_file_chem(:) = .FALSE.
+       
+       DO  lsp = 1, nspec
+          init_3d%var_names_chem(lsp) = init_3d%init_char // TRIM( chem_species(lsp)%name )
+       ENDDO
+    ENDIF
+
 
 
 !
 !-- Initialize model variables
-
-
     IF ( TRIM( initializing_actions ) /= 'read_restart_data'  .AND.            &
          TRIM( initializing_actions ) /= 'cyclic_fill' )  THEN
