Index: palm/trunk/SOURCE/netcdf_data_input_mod.f90
===================================================================
--- palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 3257)
+++ palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 3298)
@@ -25,4 +25,10 @@
 ! -----------------
 ! $Id$
+! Modified EXPERT mode to PRE-PROCESSED mode (Russo)
+! Introduced Chemistry static netcdf file (Russo)
+! Added the routine for reading-in netcdf data for chemistry (Russo)
+! Added routines to get_variable interface specific for chemistry files (Russo)
+!
+! 3257 2018-09-17 17:11:46Z suehring
 ! Adjust checks for building_type and building_id, which is necessary after 
 ! topography filtering (building_type and id can be modified by the filtering).
@@ -189,5 +195,5 @@
 !> Modulue contains routines to input data according to Palm input data
 !> standart using dynamic and static input files.
-!>
+!> @todo - Review Reading of netcdf files for chemistry
 !> @todo - Order input alphabetically
 !> @todo - Revise error messages and error numbers
@@ -341,4 +347,62 @@
 
     END TYPE init_type
+
+!-- Data type for the general information of chemistry emissions, do not dependent on the particular chemical species
+    TYPE chem_emis_att_type 
+
+       !-DIMENSIONS
+       INTEGER(iwp)                                 :: nspec                     !< number of chem species for which emission values are provided
+       INTEGER(iwp)                                 :: ncat                      !< number of emission categories
+       INTEGER(iwp)                                 :: nvoc                      !< number of VOCs components
+       INTEGER(iwp)                                 :: npm                       !< number of PMs components
+       INTEGER(iwp)                                 :: nnox=2                    !< number of NOx components: NO and NO2
+       INTEGER(iwp)                                 :: nsox=2                    !< number of SOx components: SO and SO4
+       INTEGER(iwp)                                 :: nhoursyear                !< number of hours of a specific year in the HOURLY mode
+                                                                                 !  of the default mode
+       INTEGER(iwp)                                 :: nmonthdayhour             !< number of month days and hours in the MDH mode 
+                                                                                 !  of the default mode
+       INTEGER(iwp)                                 :: dt_emission               !< Number of emissions timesteps for one year 
+                                                                                 !  in the pre-processed emissions case
+       !-- 1d emission input variables
+       CHARACTER (LEN=25),ALLOCATABLE, DIMENSION(:) :: pm_name                   !< Names of PMs components
+       CHARACTER (LEN=25),ALLOCATABLE, DIMENSION(:) :: cat_name                  !< Emission categories names
+       CHARACTER (LEN=25),ALLOCATABLE, DIMENSION(:) :: species_name              !< Names of emission chemical species
+       CHARACTER (LEN=25),ALLOCATABLE, DIMENSION(:) :: voc_name                  !< Names of VOCs components
+       CHARACTER (LEN=25)                           :: units                     !< Units
+
+       INTEGER(iwp)                                 :: i_hour                    !< indices for assigning the emission values at different timesteps
+       INTEGER(iwp),ALLOCATABLE, DIMENSION(:)       :: cat_index                 !< Index of emission categories
+       INTEGER(iwp),ALLOCATABLE, DIMENSION(:)       :: species_index             !< Index of emission chem species
+
+       REAL(wp), DIMENSION(24)                      :: par_emis_time_factor      !< time factors 
+                                                                                 !  for the parameterized mode: these are fixed for each hour
+                                                                                 !  of a single day.
+       REAL(wp),ALLOCATABLE, DIMENSION(:)           :: xm                        !< Molecular masses of emission chem species
+
+       !-- 2d emission input variables 
+       REAL(wp),ALLOCATABLE, DIMENSION(:,:)         :: hourly_emis_time_factor   !< Time factors for HOURLY emissions (DEFAULT mode)
+       REAL(wp),ALLOCATABLE, DIMENSION(:,:)         :: mdh_emis_time_factor      !< Time factors for MDH emissions (DEFAULT mode)
+       REAL(wp),ALLOCATABLE, DIMENSION(:,:)         :: nox_comp                  !< Composition of NO and NO2 
+       REAL(wp),ALLOCATABLE, DIMENSION(:,:)         :: sox_comp                  !< Composition of SO2 and SO4
+       REAL(wp),ALLOCATABLE, DIMENSION(:,:)         :: voc_comp                  !< Composition of different VOC components (number not fixed)
+
+       !-- 3d emission input variables
+       REAL(wp),ALLOCATABLE, DIMENSION(:,:,:)       :: pm_comp                   !< Composition of different PMs components (number not fixed) 
+  
+    END TYPE chem_emis_att_type
+
+
+!-- Data type for the values of chemistry emissions ERUSSO
+    TYPE chem_emis_val_type 
+
+       !REAL(wp),ALLOCATABLE, DIMENSION(:,:)         :: stack_height              !< stack height
+
+       !-- 3d emission input variables
+       REAL(wp),ALLOCATABLE, DIMENSION(:,:,:)     :: default_emission_data     !< Input Values emissions DEFAULT mode
+
+       !-- 4d emission input variables 
+       REAL(wp),ALLOCATABLE, DIMENSION(:,:,:,:)   :: preproc_emission_data      !< Input Values emissions PRE-PROCESSED mode
+
+    END TYPE chem_emis_val_type
 
 !
@@ -546,4 +610,6 @@
     TYPE(pars)  ::  water_pars_f               !< input variable for water parameters
 
+    TYPE(chem_emis_att_type)                             ::  chem_emis_att    !< Input Information of Chemistry Emission Data from netcdf  
+    TYPE(chem_emis_val_type), ALLOCATABLE, DIMENSION(:)  ::  chem_emis        !< Input Chemistry Emission Data from netcdf  
 
     CHARACTER(LEN=3)  ::  char_lod  = 'lod'         !< name of level-of-detail attribute in NetCDF file
@@ -553,4 +619,9 @@
     CHARACTER(LEN=100) ::  input_file_static  = 'PIDS_STATIC'  !< Name of file which comprises static input data
     CHARACTER(LEN=100) ::  input_file_dynamic = 'PIDS_DYNAMIC' !< Name of file which comprises dynamic input data
+    CHARACTER(LEN=100) ::  input_file_chem    = 'PIDS_CHEM'    !< Name of file which comprises chemistry input data
+
+    CHARACTER (LEN=25), ALLOCATABLE, DIMENSION(:)    :: string_values  !< output of string variables read from netcdf input files
+ 
+    INTEGER(iwp)                                     :: id_emis        !< NetCDF id of input file for chemistry emissions: TBD: It has to be removed
 
     INTEGER(iwp) ::  nc_stat         !< return value of nf90 function call
@@ -558,4 +629,5 @@
     LOGICAL ::  input_pids_static  = .FALSE.   !< Flag indicating whether Palm-input-data-standard file containing static information exists
     LOGICAL ::  input_pids_dynamic = .FALSE.   !< Flag indicating whether Palm-input-data-standard file containing dynamic information exists
+    LOGICAL ::  input_pids_chem = .FALSE.      !< Flag indicating whether Palm-input-data-standard file containing chemistry information exists
 
     LOGICAL ::  collective_read = .FALSE.      !< Enable NetCDF collective read
@@ -581,4 +653,8 @@
        MODULE PROCEDURE netcdf_data_input_check_static
     END INTERFACE netcdf_data_input_check_static
+
+    INTERFACE netcdf_data_input_chemistry_data                        
+       MODULE PROCEDURE netcdf_data_input_chemistry_data
+    END INTERFACE netcdf_data_input_chemistry_data
 
     INTERFACE netcdf_data_input_inquire_file
@@ -611,4 +687,5 @@
 
     INTERFACE get_variable
+       MODULE PROCEDURE get_variable_string
        MODULE PROCEDURE get_variable_1d_int
        MODULE PROCEDURE get_variable_1d_real
@@ -619,5 +696,7 @@
        MODULE PROCEDURE get_variable_3d_real
        MODULE PROCEDURE get_variable_3d_real_dynamic
+       MODULE PROCEDURE get_variable_4d_to_3d_real
        MODULE PROCEDURE get_variable_4d_real
+       MODULE PROCEDURE get_variable_5d_to_4d_real
     END INTERFACE get_variable
 
@@ -636,6 +715,7 @@
 !-- Public variables
     PUBLIC albedo_pars_f, albedo_type_f, basal_area_density_f, buildings_f,    &
-           building_id_f, building_pars_f, building_type_f, init_3d,           &
-           init_model, input_file_static, input_pids_static,                   &
+           building_id_f, building_pars_f, building_type_f,                    &
+           chem_emis, chem_emis_att, chem_emis_att_type, chem_emis_val_type,   &
+           init_3d, init_model, input_file_static, input_pids_static,          &
            input_pids_dynamic, leaf_area_density_f, nest_offl,                 &
            pavement_pars_f, pavement_subsurface_pars_f, pavement_type_f,       &
@@ -648,5 +728,5 @@
 !-- Public subroutines
     PUBLIC netcdf_data_input_check_dynamic, netcdf_data_input_check_static,    &
-           netcdf_data_input_inquire_file,                                     &
+           netcdf_data_input_chemistry_data, netcdf_data_input_inquire_file,                                     &
            netcdf_data_input_init, netcdf_data_input_init_lsm,                 &
            netcdf_data_input_init_3d,                                          &
@@ -674,4 +754,7 @@
        INQUIRE( FILE = TRIM( input_file_dynamic ) // TRIM( coupling_char ),    &
                 EXIST = input_pids_dynamic )
+       INQUIRE( FILE = TRIM( input_file_chem ) // TRIM( coupling_char ),    &
+                EXIST = input_pids_chem )
+
 #endif
 
@@ -756,4 +839,296 @@
 
     END SUBROUTINE netcdf_data_input_init
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Reads Chemistry NETCDF Input data, such as emission values, emission species, etc. .
+!------------------------------------------------------------------------------!
+    SUBROUTINE netcdf_data_input_chemistry_data(emt_att,emt)
+
+       USE chem_modules,                                       &
+           ONLY:  do_emis, mode_emis, time_fac_type,           & 
+                  surface_csflux_name 
+
+       USE control_parameters,                                 &
+           ONLY:  message_string
+
+       USE indices,                                            &
+           ONLY:  nz, nx, ny, nxl, nxr, nys, nyn, nzb, nzt
+
+       IMPLICIT NONE
+
+       TYPE(chem_emis_att_type), INTENT(INOUT)                                        :: emt_att
+       TYPE(chem_emis_val_type), ALLOCATABLE, DIMENSION(:), INTENT(INOUT)             :: emt
+    
+       CHARACTER (LEN=80)                               :: units=''              !< units of chemistry inputs
+ 
+       INTEGER(iwp)                                     :: ispec                 !< index for number of emission species in input
+
+       INTEGER(iwp), ALLOCATABLE, DIMENSION(:)          :: dum_var               !< value of variable read from netcdf input
+       INTEGER(iwp)                                     :: errno                 !< error number NF90_???? function
+       INTEGER(iwp)                                     :: id_var                !< variable id
+!       INTEGER(iwp)                                     :: id_emis               !< NetCDF id of input file
+       INTEGER(iwp)                                     :: num_vars              !< number of variables in netcdf input file
+       INTEGER(iwp)                                     :: len_dims,len_dims_2   !< Length of dimensions
+
+       INTEGER(iwp)                                     :: max_string_length=25  !< Variable for the maximum length of a string
+ 
+       CHARACTER(LEN=100), DIMENSION(:), ALLOCATABLE    :: var_names             !< Name of Variables
+
+       REAL(wp), ALLOCATABLE, DIMENSION(:,:,:)          :: dum_var_3d            !< variable for storing temporary data of 3-dimensional 
+                                                                                 !  variables read from netcdf for chemistry emissions
+
+       REAL(wp), ALLOCATABLE, DIMENSION(:,:,:,:)        :: dum_var_4d            !< variable for storing temporary data of 5-dimensional
+                                                                                 !< variables read from netcdf for chemistry emissions
+!--
+       !> Start the processing of the data
+       CALL location_message( 'starting allocation of chemistry emissions arrays', .FALSE. )
+
+       !> Parameterized mode of the emissions
+       IF (TRIM(mode_emis)=="PARAMETERIZED" .OR. TRIM(mode_emis)=="parameterized") THEN 
+
+           ispec=1
+           emt_att%nspec=0
+
+          !number of species
+           DO  WHILE (TRIM( surface_csflux_name( ispec ) ) /= 'novalue' )
+
+             emt_att%nspec=emt_att%nspec+1
+             ispec=ispec+1
+
+           ENDDO
+
+          !-- allocate emission values data type arrays
+          ALLOCATE(emt(emt_att%nspec))
+
+          !-- Read EMISSION SPECIES NAMES
+
+          !Assign values
+          ALLOCATE(emt_att%species_name(emt_att%nspec))
+ 
+         DO ispec=1,emt_att%nspec
+            emt_att%species_name(ispec) = TRIM(surface_csflux_name(ispec))
+         ENDDO
+
+          !Assign Constant Values of time factors:
+          emt_att%par_emis_time_factor( : ) = (/ 0.01, 0.01, 0.01, 0.02, 0.03, 0.07, 0.09, 0.09, 0.05, 0.03, 0.03, 0.03, &
+                                                 0.03, 0.03, 0.03, 0.04, 0.05, 0.09, 0.09, 0.09, 0.04, 0.02, 0.01, 0.01 /)
+
+       !> DEFAULT AND PRE-PROCESSED MODE
+       ELSE
+
+#if defined ( __netcdf )        
+          IF ( .NOT. input_pids_chem )  RETURN
+
+          !-- Open file in read-only mode
+          CALL open_read_file( TRIM( input_file_chem ) //                       &
+                               TRIM( coupling_char ), id_emis )
+          !-- inquire number of variables
+          CALL inquire_num_variables( id_emis, num_vars )
+
+          !-- Get General Dimension Lengths: only number of species and number of categories.
+          !                                  the other dimensions depend on the mode of the emissions or on the presence of specific components
+          !nspecies
+          CALL get_dimension_length( id_emis, emt_att%nspec, 'nspecies' )
+
+ 
+          !-- Allocate emission values data type arrays
+          ALLOCATE(emt(1:emt_att%nspec))
+
+
+          !-- Read EMISSION SPECIES NAMES
+          !Allocate Arrays 
+          ALLOCATE(emt_att%species_name(emt_att%nspec)) 
+
+          !Call get Variable
+          CALL get_variable( id_emis, 'emission_name', string_values, emt_att%nspec )
+          emt_att%species_name=string_values
+          ! If allocated, Deallocate var_string, an array only used for reading-in strings
+          IF (ALLOCATED(string_values)) DEALLOCATE(string_values) 
+
+          !-- Read EMISSION SPECIES INDEX
+          !Allocate Arrays 
+          ALLOCATE(emt_att%species_index(emt_att%nspec))
+          !Call get Variable
+          CALL get_variable( id_emis, 'emission_index', emt_att%species_index )
+
+
+          !-- Now the routine has to distinguish between DEFAULT and PRE-PROCESSED chemistry emission modes
+
+          IF (TRIM(mode_emis)=="DEFAULT" .OR. TRIM(mode_emis)=="default") THEN
+ 
+             !number of categories
+             CALL get_dimension_length( id_emis, emt_att%ncat, 'ncat' )
+
+             !-- Read EMISSION CATEGORIES INDEX
+             !Allocate Arrays 
+             ALLOCATE(emt_att%cat_index(emt_att%ncat))
+             !Call get Variable
+             CALL get_variable( id_emis, 'emission_cat_index', emt_att%cat_index )
+
+ 
+             DO ispec=1,emt_att%nspec
+                !-- EMISSION_VOC_NAME (1-DIMENSIONAL)
+                IF (TRIM(emt_att%species_name(ispec))=="VOC" .OR. TRIM(emt_att%species_name(ispec))=="voc") THEN
+                   !Allocate Array
+                   CALL get_dimension_length( id_emis, emt_att%nvoc, 'nvoc' )
+                   ALLOCATE(emt_att%voc_name(1:emt_att%nvoc))
+                   !Read-in Variable
+                   CALL get_variable( id_emis,"emission_voc_name",string_values, emt_att%nvoc)
+                   emt_att%voc_name=string_values
+                   IF (ALLOCATED(string_values)) DEALLOCATE(string_values)
+ 
+                !-- COMPOSITION VOC (2-DIMENSIONAL)
+                   !Allocate Array 
+                   ALLOCATE(emt_att%voc_comp(1:emt_att%ncat,1:emt_att%nvoc))
+                   !Read-in Variable
+!               CALL get_variable(id_emis,"composition_voc",emt%voc_comp,1,1,emt%ncat,emt%nvoc)
+                   CALL get_variable(id_emis,"composition_voc",emt_att%voc_comp,1,emt_att%ncat,1,emt_att%nvoc)
+                ENDIF
+
+                !-- EMISSION_PM_NAME (1-DIMENSIONAL)
+                IF (TRIM(emt_att%species_name(ispec))=="PM" .OR. TRIM(emt_att%species_name(ispec))=="pm") THEN
+                   CALL get_dimension_length( id_emis, emt_att%npm, 'npm' )
+                   ALLOCATE(emt_att%pm_name(1:emt_att%npm))
+                   !Read-in Variable
+                   CALL get_variable( id_emis,"pm_name",string_values, emt_att%npm)
+                   emt_att%pm_name=string_values
+                   IF (ALLOCATED(string_values)) DEALLOCATE(string_values)      
+
+                !-- COMPOSITION PM (3-DIMENSIONAL)
+                   !Allocate
+                   len_dims=3  !> number of PMs: PM1, PM2.5 and PM10
+                   ALLOCATE(emt_att%pm_comp(1:emt_att%ncat,1:emt_att%npm,1:len_dims))
+                   !Read-in Variable
+                   CALL get_variable(id_emis,"composition_pm",emt_att%pm_comp,1,emt_att%ncat,1,emt_att%npm,1,len_dims)                    
+                ENDIF
+
+                !-- COMPOSITION_NOX (2-DIMENSIONAL)
+                IF (TRIM(emt_att%species_name(ispec))=="NOx" .OR. TRIM(emt_att%species_name(ispec))=="nox") THEN
+                   !Allocate array
+                   ALLOCATE(emt_att%nox_comp(1:emt_att%ncat,1:emt_att%nnox))
+                   !Read-in Variable
+                   CALL get_variable(id_emis,"composition_nox",emt_att%nox_comp,1,emt_att%ncat,1,emt_att%nnox)
+                ENDIF
+
+                !-- COMPOSITION-SOX (2-DIMENSIONAL)
+                IF (TRIM(emt_att%species_name(ispec))=="SOx" .OR. TRIM(emt_att%species_name(ispec))=="sox") THEN
+                   ALLOCATE(emt_att%sox_comp(1:emt_att%ncat,1:emt_att%nsox))
+                   !Read-in Variable
+                   CALL get_variable(id_emis,"composition_sox",emt_att%sox_comp,1,emt_att%ncat,1,emt_att%nsox)
+                ENDIF
+             ENDDO !>ispec
+
+!-- For reading the emission time factors, the distinction between HOUR and MDH data is necessary
+      
+             !-- EMISSION_TIME_SCALING_FACTORS
+                !-- HOUR   
+             IF (TRIM(time_fac_type)=="HOUR" .OR. TRIM(time_fac_type)=="hour") THEN
+                !-- Allocate Array
+                CALL get_dimension_length( id_emis, emt_att%nhoursyear, 'nhoursyear' )
+                ALLOCATE(emt_att%hourly_emis_time_factor(1:emt_att%ncat,1:emt_att%nhoursyear))
+                !Read-in Variable
+                CALL get_variable(id_emis,"emission_time_factors",emt_att%hourly_emis_time_factor,1,emt_att%ncat,1,emt_att%nhoursyear)
+
+                !-- MDH
+             ELSE IF (TRIM(time_fac_type) == "MDH" .OR. TRIM(time_fac_type) == "mdh") THEN
+                !-- Allocate Array
+                CALL get_dimension_length( id_emis, emt_att%nmonthdayhour, 'nmonthdayhour' )
+                ALLOCATE(emt_att%mdh_emis_time_factor(1:emt_att%ncat,1:emt_att%nmonthdayhour))
+                !-- Read-in Variable
+                CALL get_variable(id_emis,"emission_time_factors",emt_att%mdh_emis_time_factor,1,emt_att%ncat,1,emt_att%nmonthdayhour)
+
+             ELSE
+
+             message_string = 'We are in the DEFAULT chemistry emissions mode: '            //          &
+                              '     !no time-factor type specified!'                        //          &
+                              'Please, specify the value of time_fac_type:'                 //          &
+                              '         either "MDH" or "HOUR"'                  
+             CALL message( 'netcdf_data_input_chemistry_data', 'CM0200', 2, 2, 0, 6, 0 ) 
+ 
+
+             ENDIF
+
+             !-- Finally read-in the emission values and their units (DEFAULT mode)
+
+             DO ispec=1,emt_att%nspec
+
+                IF ( .NOT. ALLOCATED( emt(ispec)%default_emission_data ) ) ALLOCATE(emt(ispec)%default_emission_data(1:emt_att%ncat,1:ny+1,1:nx+1))
+
+                ALLOCATE(dum_var_3d(1:emt_att%ncat,nys+1:nyn+1,nxl+1:nxr+1))
+
+                CALL get_variable(id_emis,"emission_values",dum_var_3d,ispec,1,emt_att%ncat,nys,nyn,nxl,nxr)          
+
+                emt(ispec)%default_emission_data(:,nys+1:nyn+1,nxl+1:nxr+1)=dum_var_3d(1:emt_att%ncat,nys+1:nyn+1,nxl+1:nxr+1)
+
+                DEALLOCATE (dum_var_3d)
+
+             ENDDO
+
+             !-- UNITS
+             CALL get_attribute(id_emis,"units",emt_att%units,.FALSE.,"emission_values")
+
+
+          !-- PRE-PROCESSED MODE --
+
+          ELSE IF (TRIM(mode_emis)=="PRE-PROCESSED" .OR. TRIM(mode_emis)=="pre-processed") THEN
+          !-- In the PRE-PROCESSED mode, only the VOC names, the VOC_composition, the emission values and their units remain to be read at this point
+
+             DO ispec=1,emt_att%nspec
+
+             !-- EMISSION_VOC_NAME (1-DIMENSIONAL)
+                IF (TRIM(emt_att%species_name(ispec))=="VOC" .OR. TRIM(emt_att%species_name(ispec))=="voc") THEN
+                   !Allocate Array
+                   CALL get_dimension_length( id_emis, emt_att%nvoc, 'nvoc' )
+                   ALLOCATE(emt_att%voc_name(1:emt_att%nvoc))
+                   !Read-in Variable
+                   CALL get_variable( id_emis,"emission_voc_name",string_values, emt_att%nvoc)
+                   emt_att%voc_name=string_values
+                   IF (ALLOCATED(string_values)) DEALLOCATE(string_values)
+ 
+             !-- COMPOSITION VOC (2-DIMENSIONAL)
+                   !Allocate Array 
+                   ALLOCATE(emt_att%voc_comp(1:emt_att%ncat,1:emt_att%nvoc))
+                   !Read-in Variable
+                   CALL get_variable(id_emis,"composition_voc",emt_att%voc_comp,1,emt_att%ncat,1,emt_att%nvoc)
+                ENDIF
+  
+             ENDDO !> ispec
+
+             !-- EMISSION_VALUES (4-DIMENSIONAL)
+             !Calculate temporal dimension length
+             CALL get_dimension_length( id_emis, emt_att%dt_emission, 'time' )   
+         
+
+             DO ispec=1,emt_att%nspec
+
+                !Allocation for the entire domain has to be done only for the first processor between all the subdomains     
+                IF ( .NOT. ALLOCATED( emt(ispec)%preproc_emission_data ) ) ALLOCATE(emt(ispec)%preproc_emission_data(emt_att%dt_emission,1,1:ny+1,1:nx+1)) 
+
+                !> allocate variable where to pass emission values read from netcdf
+                ALLOCATE(dum_var_4d(1:emt_att%dt_emission,1,nys+1:nyn+1,nxl+1:nxr+1))
+
+                !Read-in Variable 
+                CALL get_variable(id_emis,"emission_values",dum_var_4d,ispec,1,emt_att%dt_emission,1,1,nys,nyn,nxl,nxr)          
+
+      
+                emt(ispec)%preproc_emission_data(:,1,nys+1:nyn+1,nxl+1:nxr+1)=dum_var_4d(1:emt_att%dt_emission,1,nys+1:nyn+1,nxl+1:nxr+1)
+
+                DEALLOCATE ( dum_var_4d )
+
+             ENDDO
+
+             !-- UNITS
+             CALL get_attribute(id_emis,"units",emt_att%units,.FALSE.,"emission_values")
+       
+          ENDIF
+
+       CALL close_input_file( id_emis )
+
+#endif
+       ENDIF
+
+    END SUBROUTINE netcdf_data_input_chemistry_data
 
 !------------------------------------------------------------------------------!
@@ -4094,4 +4469,78 @@
 ! Description:
 ! ------------
+!> Routine for reading-in a character string from the chem emissions netcdf input file.  
+!------------------------------------------------------------------------------!
+ 
+ SUBROUTINE get_variable_string( id, variable_name, var_string, names_number)
+#if defined( __netcdf )
+
+    USE indices
+    USE pegrid
+
+    IMPLICIT NONE
+
+    CHARACTER (LEN=25), ALLOCATABLE, DIMENSION(:), INTENT(INOUT)  :: var_string
+
+    CHARACTER(LEN=*)                                              :: variable_name          !> variable name 
+
+    CHARACTER (LEN=1), ALLOCATABLE, DIMENSION(:,:)                :: tmp_var_string         !> variable to be read
+
+
+    INTEGER(iwp), INTENT(IN)                                      :: id                     !> file id
+
+    INTEGER(iwp), INTENT(IN)                                      :: names_number           !> number of names
+
+    INTEGER(iwp)                                                  :: id_var                 !> variable id
+
+    INTEGER(iwp)                                                  :: i,j                    !> index to go through the length of the dimensions
+
+    INTEGER(iwp)                                                  :: max_string_length=25   !> this is both the maximum length of a name, but also  
+                                                                                            ! the number of the components of the first dimensions
+                                                                                            ! (rows)
+
+
+    ALLOCATE(tmp_var_string(max_string_length,names_number))
+
+    ALLOCATE(var_string(names_number))
+
+    !-- Inquire variable id
+    nc_stat = NF90_INQ_VARID( id, TRIM( variable_name ), id_var )
+
+
+    !-- Get variable
+    !-- Start cycle over the emission species
+    DO i = 1, names_number 
+       !-- read the first letter of each component
+       nc_stat = NF90_GET_VAR( id, id_var, var_string(i), start = (/ 1,i /), &
+                                 count = (/ 1,1 /) )
+       CALL handle_error( 'get_variable_string', 701 )
+
+       !-- Start cycle over charachters
+       DO j = 1, max_string_length
+                       
+          !-- read the rest of the components of the name
+          nc_stat = NF90_GET_VAR( id, id_var, tmp_var_string(j,i), start = (/ j,i /),&
+                                     count = (/ 1,1 /) )
+          CALL handle_error( 'get_variable_string', 702 )
+
+          IF ( iachar(tmp_var_string(j,i) ) == 0 ) THEN
+               tmp_var_string(j,i)=''
+          ENDIF
+
+          IF ( j>1 ) THEN
+          !-- Concatenate first letter of the name and the others
+             var_string(i)=TRIM(var_string(i)) // TRIM(tmp_var_string(j,i))
+
+          ENDIF 
+       ENDDO 
+    ENDDO
+
+#endif
+ END SUBROUTINE get_variable_string
+
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
 !> Reads a 1D integer variable from file.
 !------------------------------------------------------------------------------!
@@ -4233,4 +4682,26 @@
 #endif
        ENDIF
+
+
+       !Temporary solution for reading emission chemistry files: TBD: we should discuss whether remove it or not
+       IF ( id==id_emis ) THEN
+
+          !--    Allocate temporary variable according to memory access on file. 
+          ALLOCATE( tmp(is:ie,js:je) )
+
+          !--    Get variable
+          nc_stat = NF90_GET_VAR( id, id_var, tmp,                                &
+                                  start = (/ is,      js /),                  &
+                                  count = (/ ie-is+1 , je-js+1 /) ) 
+
+          var=tmp
+
+          CALL handle_error( 'get_variable_2d_real', 530, variable_name ) !TBD: the error number shuld be changed, but since the solution is 
+                                                                          ! provisory, we give the same as below
+ 
+          DEALLOCATE( tmp )
+       
+       !>  Original Subroutine part
+       ELSE
 !
 !--    Allocate temporary variable according to memory access on file. 
@@ -4238,19 +4709,20 @@
 !
 !--    Get variable
-       nc_stat = NF90_GET_VAR( id, id_var, tmp,                                &
+          nc_stat = NF90_GET_VAR( id, id_var, tmp,                                &
                                start = (/ is+1,      js+1 /),                  &
                                count = (/ ie-is + 1, je-js+1 /) )   
                                
-       CALL handle_error( 'get_variable_2d_real', 530, variable_name )
+          CALL handle_error( 'get_variable_2d_real', 530, variable_name )
 !
 !--    Resort data. Please note, dimension subscripts of var all start at 1. 
-       DO  i = is, ie 
-          DO  j = js, je 
-             var(j-js+1,i-is+1) = tmp(i,j)
+          DO  i = is, ie 
+             DO  j = js, je 
+                var(j-js+1,i-is+1) = tmp(i,j)
+             ENDDO
           ENDDO
-       ENDDO
        
-       DEALLOCATE( tmp )
-
+          DEALLOCATE( tmp )
+
+       ENDIF
 #endif
     END SUBROUTINE get_variable_2d_real
@@ -4647,4 +5119,24 @@
 #endif
        ENDIF
+
+      !Temporary solution for reading emission chemistry files: 
+       IF ( id==id_emis ) THEN
+
+          !--    Allocate temporary variable according to memory access on file. 
+          ALLOCATE( tmp(is:ie,js:je,k1s:k1e,k2s:k2e) )
+
+          !--    Get variable
+          nc_stat = NF90_GET_VAR( id, id_var, tmp,                                &
+                                  start = (/ is,   js,   k1s+1,   k2s+1 /),                  &
+                                  count = (/ ie-is+1 , je-js+1, k1e-k1s+1, k2e-k2s+1 /) ) 
+
+          var=tmp
+
+          CALL handle_error( 'get_variable_4d_real', 535, variable_name )
+ 
+          DEALLOCATE( tmp )
+
+       !> Original subroutine part
+       ELSE
 !
 !--    Allocate temporary variable according to memory access on file. 
@@ -4652,27 +5144,115 @@
 !
 !--    Get variable
-       nc_stat = NF90_GET_VAR( id, id_var, tmp,                                &
+          nc_stat = NF90_GET_VAR( id, id_var, tmp,                                &
                                start = (/ is+1,    js+1,   k1s+1, k2s+1 /),    &
                                count = (/ ie-is+1, je-js+1,                    &
                                           k1e-k1s+1, k2e-k2s+1 /) )
 
-       CALL handle_error( 'get_variable_4d_real', 535, variable_name )
+          CALL handle_error( 'get_variable_4d_real', 535, variable_name )
 !
 !--    Resort data. Please note, dimension subscripts of var all start at 1. 
-       DO  i = is, ie 
-          DO  j = js, je
-             DO  k1 = k1s, k1e
-                DO  k2 = k2s, k2e
-                   var(k2-k2s+1,k1-k1s+1,j-js+1,i-is+1) = tmp(i,j,k1,k2)
+          DO  i = is, ie 
+             DO  j = js, je
+                DO  k1 = k1s, k1e
+                   DO  k2 = k2s, k2e
+                      var(k2-k2s+1,k1-k1s+1,j-js+1,i-is+1) = tmp(i,j,k1,k2)
+                   ENDDO
                 ENDDO
              ENDDO
           ENDDO
-       ENDDO
        
-       DEALLOCATE( tmp )
+          DEALLOCATE( tmp )
+       ENDIF
 #endif
     END SUBROUTINE get_variable_4d_real
 
-
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Reads a 4D float variable from file and store it to a 3-d variable.
+!------------------------------------------------------------------------------!
+    SUBROUTINE get_variable_4d_to_3d_real( id, variable_name, var, ns, is, ie, js, je,   &
+                                           ks, ke )
+
+       USE indices
+       USE pegrid
+
+       IMPLICIT NONE
+
+       CHARACTER(LEN=*)              ::  variable_name   !< variable name
+
+       INTEGER(iwp)                  ::  ns              !< start index for subdomain input along n dimension: ns coincides here with ne, since, we select only one value along the 1st dimension n
+
+       INTEGER(iwp)                  ::  i               !< index along x direction
+       INTEGER(iwp)                  ::  ie              !< end index for subdomain input along x direction
+       INTEGER(iwp)                  ::  is              !< start index for subdomain input along x direction
+       INTEGER(iwp), INTENT(IN)      ::  id              !< file id
+       INTEGER(iwp)                  ::  id_var          !< variable id
+       INTEGER(iwp)                  ::  j               !< index along y direction
+       INTEGER(iwp)                  ::  je              !< end index for subdomain input along y direction
+       INTEGER(iwp)                  ::  js              !< start index for subdomain input along y direction
+       INTEGER(iwp)                  ::  k               !< index along any 4th dimension
+       INTEGER(iwp)                  ::  ke              !< end index of 4th dimension
+       INTEGER(iwp)                  ::  ks              !< start index of 4th dimension
+       
+       REAL(wp), DIMENSION(:,:,:), ALLOCATABLE   ::  tmp !< temporary variable to read data from file according 
+                                                         !< to its reverse memory access
+
+       REAL(wp), DIMENSION(:,:,:), INTENT(INOUT) ::  var  !< variable where the read data have to be stored: one dimension is reduced in the process
+#if defined( __netcdf )
+
+!
+!--    Inquire variable id
+       nc_stat = NF90_INQ_VARID( id, TRIM( variable_name ), id_var )  
+!
+!--    Check for collective read-operation and set respective NetCDF flags if
+!--    required. 
+       IF ( collective_read )  THEN
+          nc_stat = NF90_VAR_PAR_ACCESS (id, id_var, NF90_COLLECTIVE)
+       ENDIF
+
+      !Temporary solution for reading emission chemistry files: 
+       IF ( id==id_emis ) THEN
+
+          !--    Allocate temporary variable according to memory access on file. 
+          ALLOCATE( tmp(is:ie,js:je,ks:ke) )
+
+          !--    Get variable
+          nc_stat = NF90_GET_VAR( id, id_var, tmp(is:ie,js:je,ks:ke),                                &
+                                  start = (/ ns, is,   js+1,   ks+1 /),                  &
+                                  count = (/ 1, ie-is+1 , je-js+1, ke-ks+1 /) ) 
+
+          var=tmp(:,:,:)
+
+          CALL handle_error( 'get_variable_4d_to_3d_real', 536, variable_name )
+ 
+          DEALLOCATE( tmp )
+
+       ELSE
+!
+!--    Allocate temporary variable according to memory access on file. 
+          ALLOCATE( tmp(is:ie,js:je,ks:ke) )
+!
+!--    Get variable
+          nc_stat = NF90_GET_VAR( id, id_var, tmp,                                &
+                                  start = (/ ns+1, is+1,    js+1,    ks+1 /),           &
+                                  count = (/ 1, ie-is+1, je-js+1, ke-ks+1 /) )   
+                               
+          CALL handle_error( 'get_variable_4d_to_3d_real', 536, variable_name )
+!
+!--    Resort data. Please note, dimension subscripts of var all start at 1. 
+          DO  i = is, ie 
+             DO  j = js, je
+                DO  k = ks, ke
+                   var(k-ks+1,j-js+1,i-is+1) = tmp(i,j,k)
+                ENDDO
+             ENDDO
+          ENDDO
+       
+         DEALLOCATE( tmp )
+
+       ENDIF
+#endif
+    END SUBROUTINE get_variable_4d_to_3d_real
 
 !------------------------------------------------------------------------------!
@@ -4755,5 +5335,5 @@
                                count = (/ count_1, count_2, count_3 /) )
 
-       CALL handle_error( 'get_variable_3d_real_dynamic', 536, variable_name )
+       CALL handle_error( 'get_variable_3d_real_dynamic', 537, variable_name )
 !
 !--    Resort data. Please note, dimension subscripts of var all start at 1. 
@@ -4770,4 +5350,98 @@
     END SUBROUTINE get_variable_3d_real_dynamic
 
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Reads a 5D float variable from file and store it to a 4-d variable.
+!------------------------------------------------------------------------------!
+    SUBROUTINE get_variable_5d_to_4d_real( id, variable_name, var,              &
+                                           ns, ts, te, is, ie, js, je, ks, ke )
+
+       USE indices
+       USE pegrid
+
+       IMPLICIT NONE
+
+       CHARACTER(LEN=*)              ::  variable_name   !< variable name
+
+       INTEGER(iwp)                  ::  ns              !< start index for subdomain input along n dimension: ns coincides here with ne, since, we select only one value along the 1st dimension n
+
+       INTEGER(iwp)                  ::  t               !< index along t direction
+       INTEGER(iwp)                  ::  te              !< end index for subdomain input along t direction
+       INTEGER(iwp)                  ::  ts              !< start index for subdomain input along t direction
+
+       INTEGER(iwp)                  ::  i               !< index along x direction
+       INTEGER(iwp)                  ::  ie              !< end index for subdomain input along x direction
+       INTEGER(iwp)                  ::  is              !< start index for subdomain input along x direction
+       INTEGER(iwp), INTENT(IN)      ::  id              !< file id
+       INTEGER(iwp)                  ::  id_var          !< variable id
+       INTEGER(iwp)                  ::  j               !< index along y direction
+       INTEGER(iwp)                  ::  je              !< end index for subdomain input along y direction
+       INTEGER(iwp)                  ::  js              !< start index for subdomain input along y direction
+       INTEGER(iwp)                  ::  k               !< index along any 5th dimension
+       INTEGER(iwp)                  ::  ke              !< end index of 5th dimension
+       INTEGER(iwp)                  ::  ks              !< start index of 5th dimension
+       
+       REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE   ::  tmp !< temporary variable to read data from file according 
+                                                           ! to its reverse memory access
+       REAL(wp), DIMENSION(:,:,:,:), INTENT(INOUT) ::  var !< variable to be read
+#if defined( __netcdf )
+!
+!--    Inquire variable id
+       nc_stat = NF90_INQ_VARID( id, TRIM( variable_name ), id_var )  
+!
+!--    Check for collective read-operation and set respective NetCDF flags if
+!--    required. 
+       IF ( collective_read )  THEN
+          nc_stat = NF90_VAR_PAR_ACCESS (id, id_var, NF90_COLLECTIVE)
+       ENDIF
+
+      !Temporary solution for reading emission chemistry files: 
+       IF ( id==id_emis ) THEN
+
+          !--    Allocate temporary variable according to memory access on file. 
+          ALLOCATE( tmp(ts:te,1,js+1:je+1,ks+1:ke+1) )
+
+          !--    Get variable
+          nc_stat = NF90_GET_VAR( id, id_var, tmp(ts:te,1,js+1:je+1,ks+1:ke+1),               &
+                                  start = (/ ns, ts,  1,   js+1,   ks+1 /),                  &
+                                  count = (/ 1, te-ts+1, 1, je-js+1, ke-ks+1 /) ) 
+
+          var=tmp
+
+          CALL handle_error( 'get_variable_5d_to_4d_real', 538, variable_name )
+ 
+          DEALLOCATE( tmp )
+
+       !>  Original Subroutine part
+       ELSE
+!
+!--    Allocate temporary variable according to memory access on file. 
+          ALLOCATE( tmp(ks:ke,js:je,is:is,ts:te) )
+!
+!--    Get variable
+          nc_stat = NF90_GET_VAR( id, id_var, tmp,                                &
+                                  start = (/ ks+1, js+1, is+1, ts+1, ns /),           &
+                                  count = (/ ke-ks+1, je-js+1, ie-is+1, te-ts+1, 1 /) )   
+                               
+          CALL handle_error( 'get_variable_5d_to_4d_real', 538, variable_name )
+!
+!--    Resort data. Please note, dimension subscripts of var all start at 1. 
+
+          DO  t = ts, te 
+             DO  i = is, ie 
+                DO  j = js, je
+                   DO  k = ks, ke
+                      var(t-ts+1,i-is+1,j-js+1,k-ks+1) = tmp(k,j,i,t)
+                   ENDDO
+                ENDDO
+             ENDDO
+          ENDDO 
+
+         DEALLOCATE( tmp )
+
+       ENDIF
+#endif
+    END SUBROUTINE get_variable_5d_to_4d_real
 
 
@@ -4789,5 +5463,5 @@
 
        nc_stat = NF90_INQUIRE( id, NVARIABLES = num_vars )
-       CALL handle_error( 'inquire_num_variables', 537 )
+       CALL handle_error( 'inquire_num_variables', 539 )
 
 #endif
@@ -4816,9 +5490,9 @@
        ALLOCATE( varids(1:SIZE(var_names)) )
        nc_stat = NF90_INQ_VARIDS( id, NVARS = num_vars, VARIDS = varids )
-       CALL handle_error( 'inquire_variable_names', 538 )
+       CALL handle_error( 'inquire_variable_names', 540 )
 
        DO  i = 1, SIZE(var_names)
           nc_stat = NF90_INQUIRE_VARIABLE( id, varids(i), NAME = var_names(i) )
-          CALL handle_error( 'inquire_variable_names', 538 )
+          CALL handle_error( 'inquire_variable_names', 540 )
        ENDDO
 
