Index: palm/trunk/SOURCE/netcdf_data_input_mod.f90
===================================================================
--- palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 4392)
+++ palm/trunk/SOURCE/netcdf_data_input_mod.f90	(revision 4400)
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! - Routine to inquire default fill values added
+! - netcdf_data_input_att and netcdf_data_input_var routines removed
+! 
+! 4392 2020-01-31 16:14:57Z pavelkrc
 ! (resler) Decrease length of reading buffer (fix problem of ifort/icc compilers)
 ! 
@@ -542,4 +546,5 @@
        INTEGER(iwp) ::  version              !< version of data set
 
+       REAL(wp) ::  fillvalue = -9999.0      !< default fill value
        REAL(wp) ::  origin_lat               !< latitude of lower left corner
        REAL(wp) ::  origin_lon               !< longitude of lower left corner
@@ -652,4 +657,6 @@
     LOGICAL ::  collective_read = .FALSE.      !< Enable NetCDF collective read
 
+    REAL(wp), DIMENSION(8) ::  crs_list        !< list of coord_ref_sys values
+
     TYPE(global_atts_type) ::  input_file_atts !< global attributes of input file
 
@@ -666,11 +673,16 @@
     END INTERFACE netcdf_data_input_check_static
 
-    INTERFACE netcdf_data_input_chemistry_data                        
+    INTERFACE netcdf_data_input_chemistry_data
        MODULE PROCEDURE netcdf_data_input_chemistry_data
     END INTERFACE netcdf_data_input_chemistry_data
-    
-    INTERFACE get_dimension_length                        
+
+    INTERFACE get_dimension_length
        MODULE PROCEDURE get_dimension_length
     END INTERFACE get_dimension_length
+
+    INTERFACE inquire_fill_value
+       MODULE PROCEDURE inquire_fill_value_int
+       MODULE PROCEDURE inquire_fill_value_real
+    END INTERFACE inquire_fill_value
 
     INTERFACE netcdf_data_input_inquire_file
@@ -681,11 +693,4 @@
        MODULE PROCEDURE netcdf_data_input_init
     END INTERFACE netcdf_data_input_init
-    
-    INTERFACE netcdf_data_input_att
-       MODULE PROCEDURE netcdf_data_input_att_int8
-       MODULE PROCEDURE netcdf_data_input_att_int32
-       MODULE PROCEDURE netcdf_data_input_att_real
-       MODULE PROCEDURE netcdf_data_input_att_string
-    END INTERFACE netcdf_data_input_att
 
     INTERFACE netcdf_data_input_init_3d
@@ -696,10 +701,4 @@
        MODULE PROCEDURE netcdf_data_input_surface_data
     END INTERFACE netcdf_data_input_surface_data
-
-    INTERFACE netcdf_data_input_var
-       MODULE PROCEDURE netcdf_data_input_var_char
-       MODULE PROCEDURE netcdf_data_input_var_real_1d
-       MODULE PROCEDURE netcdf_data_input_var_real_2d
-    END INTERFACE netcdf_data_input_var
 
     INTERFACE netcdf_data_input_uvem
@@ -752,4 +751,5 @@
            chem_emis, chem_emis_att, chem_emis_att_type, chem_emis_val_type,   &
            coord_ref_sys,                                                      &
+           crs_list,                                                           &
            init_3d, init_model, input_file_atts,                               &
            input_file_dynamic,                                                 &
@@ -781,8 +781,6 @@
            netcdf_data_input_init,                                             &
            netcdf_data_input_init_3d,                                          &
-           netcdf_data_input_att,                                              &
            netcdf_data_input_surface_data,                                     &
            netcdf_data_input_topo,                                             &
-           netcdf_data_input_var,                                              &
            get_attribute,                                                      &
            get_variable,                                                       &
@@ -790,4 +788,5 @@
            open_read_file,                                                     &
            check_existence,                                                    &
+           inquire_fill_value,                                                 &
            inquire_num_variables,                                              &
            inquire_variable_names,                                             &
@@ -817,5 +816,5 @@
        INQUIRE( FILE = TRIM( input_file_chem )    // TRIM( coupling_char ),    &
                 EXIST = input_pids_chem )
-       INQUIRE( FILE = TRIM( input_file_uvem ) // TRIM( coupling_char ),       &
+       INQUIRE( FILE = TRIM( input_file_uvem )    // TRIM( coupling_char ),    &
                 EXIST = input_pids_uvem  )
        INQUIRE( FILE = TRIM( input_file_vm )      // TRIM( coupling_char ),    &
@@ -962,5 +961,16 @@
        init_model%origin_z        = input_file_atts%origin_z  
        init_model%rotation_angle  = input_file_atts%rotation_angle  
-            
+
+!
+!--    Define list of crs attributes. This is required for coordinate 
+!--    transformation. 
+       crs_list = (/ coord_ref_sys%semi_major_axis,                            &
+                     coord_ref_sys%inverse_flattening,                         &
+                     coord_ref_sys%longitude_of_prime_meridian,                &
+                     coord_ref_sys%longitude_of_central_meridian,              &
+                     coord_ref_sys%scale_factor_at_central_meridian,           &
+                     coord_ref_sys%latitude_of_projection_origin,              &
+                     coord_ref_sys%false_easting,                              &
+                     coord_ref_sys%false_northing /)
 !
 !--    In case of nested runs, each model domain might have different longitude
@@ -977,258 +987,5 @@
 
     END SUBROUTINE netcdf_data_input_init
-    
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Read an array of characters.
-!------------------------------------------------------------------------------!
-    SUBROUTINE netcdf_data_input_var_char( val, search_string, id_mod )
-
-       IMPLICIT NONE
-
-       CHARACTER(LEN=*) ::  search_string     !< name of the variable
-       CHARACTER(LEN=*), DIMENSION(:) ::  val !< variable which should be read
-       
-       INTEGER(iwp) ::  id_mod   !< NetCDF id of input file
-
-#if defined ( __netcdf )
-!
-!--    Read variable
-       CALL get_variable( id_mod, search_string, val )
-#endif            
-
-    END SUBROUTINE netcdf_data_input_var_char
-    
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Read an 1D array of REAL values.
-!------------------------------------------------------------------------------!
-    SUBROUTINE netcdf_data_input_var_real_1d( val, search_string, id_mod )
-
-       IMPLICIT NONE
-
-       CHARACTER(LEN=*) ::  search_string     !< name of the variable      
-       
-       INTEGER(iwp) ::  id_mod        !< NetCDF id of input file
-       
-       REAL(wp), DIMENSION(:) ::  val !< variable which should be read
-
-#if defined ( __netcdf )
-!
-!--    Read variable
-       CALL get_variable( id_mod, search_string, val )
-#endif            
-
-    END SUBROUTINE netcdf_data_input_var_real_1d
-    
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Read an 1D array of REAL values.
-!------------------------------------------------------------------------------!
-    SUBROUTINE netcdf_data_input_var_real_2d( val, search_string,              &
-                                              id_mod, d1s, d1e, d2s, d2e )
-
-       IMPLICIT NONE
-
-       CHARACTER(LEN=*) ::  search_string     !< name of the variable     
-       
-       INTEGER(iwp) ::  id_mod  !< NetCDF id of input file
-       INTEGER(iwp) ::  d1e     !< end index of first dimension to be read
-       INTEGER(iwp) ::  d2e     !< end index of second dimension to be read
-       INTEGER(iwp) ::  d1s     !< start index of first dimension to be read
-       INTEGER(iwp) ::  d2s     !< start index of second dimension to be read
-       
-       REAL(wp), DIMENSION(:,:) ::  val !< variable which should be read
-
-#if defined ( __netcdf )
-!
-!--    Read character variable
-       CALL get_variable( id_mod, search_string, val, d1s, d1e, d2s, d2e )
-#endif            
-
-    END SUBROUTINE netcdf_data_input_var_real_2d
-    
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Read a global string attribute 
-!------------------------------------------------------------------------------!
-    SUBROUTINE netcdf_data_input_att_string( val, search_string, id_mod,       &
-                                             input_file, global, openclose,    &
-                                             variable_name )
-
-       IMPLICIT NONE
-
-       CHARACTER(LEN=*) ::  search_string !< name of the attribue
-       CHARACTER(LEN=*) ::  val           !< attribute
-       
-       CHARACTER(LEN=*) ::  input_file    !< name of input file
-       CHARACTER(LEN=*) ::  openclose     !< string indicating whether NetCDF needs to be opend or closed
-       CHARACTER(LEN=*) ::  variable_name !< string indicating whether NetCDF needs to be opend or closed  
-       
-       INTEGER(iwp) ::  id_mod   !< NetCDF id of input file
-       
-       LOGICAL ::  global                 !< flag indicating a global or a variable's attribute
-
-#if defined ( __netcdf )
-!
-!--    Open file in read-only mode if necessary
-       IF ( openclose == 'open' )  THEN
-          CALL open_read_file( TRIM( input_file ) // TRIM( coupling_char ), &
-                                  id_mod )
-       ENDIF
-!
-!--    Read global attribute
-       IF ( global )  THEN
-          CALL get_attribute( id_mod, search_string, val, global )
-!
-!--    Read variable attribute
-       ELSE
-          CALL get_attribute( id_mod, search_string, val, global, variable_name )
-       ENDIF
-!
-!--    Close input file 
-       IF ( openclose == 'close' )  CALL close_input_file( id_mod )
-#endif            
-
-    END SUBROUTINE netcdf_data_input_att_string
-    
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Read a global 8-bit integer attribute 
-!------------------------------------------------------------------------------!
-    SUBROUTINE netcdf_data_input_att_int8( val, search_string, id_mod,         &
-                                           input_file, global, openclose,      &
-                                           variable_name )
-
-       IMPLICIT NONE
-
-       CHARACTER(LEN=*) ::  search_string !< name of the attribue
-       
-       CHARACTER(LEN=*) ::  input_file    !< name of input file
-       CHARACTER(LEN=*) ::  openclose     !< string indicating whether NetCDF needs to be opend or closed
-       CHARACTER(LEN=*) ::  variable_name !< string indicating whether NetCDF needs to be opend or closed 
-       
-       INTEGER(iwp) ::  id_mod   !< NetCDF id of input file
-       INTEGER(KIND=1) ::  val      !< value of the attribute
-       
-       LOGICAL ::  global        !< flag indicating a global or a variable's attribute
-
-#if defined ( __netcdf )
-!
-!--    Open file in read-only mode
-       IF ( openclose == 'open' )  THEN
-          CALL open_read_file( TRIM( input_file ) // TRIM( coupling_char ), &
-                                  id_mod )
-       ENDIF
-!
-!--    Read global attribute
-       IF ( global )  THEN
-          CALL get_attribute( id_mod, search_string, val, global )
-!
-!--    Read variable attribute
-       ELSE
-          CALL get_attribute( id_mod, search_string, val, global, variable_name )
-       ENDIF
-!
-!--    Finally, close input file
-       IF ( openclose == 'close' )  CALL close_input_file( id_mod )
-#endif            
-
-    END SUBROUTINE netcdf_data_input_att_int8
-    
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Read a global 32-bit integer attribute 
-!------------------------------------------------------------------------------!
-    SUBROUTINE netcdf_data_input_att_int32( val, search_string, id_mod,        &
-                                            input_file, global, openclose,     &
-                                            variable_name )
-
-       IMPLICIT NONE
-
-       CHARACTER(LEN=*) ::  search_string !< name of the attribue
-       
-       CHARACTER(LEN=*) ::  input_file    !< name of input file
-       CHARACTER(LEN=*) ::  openclose     !< string indicating whether NetCDF needs to be opend or closed
-       CHARACTER(LEN=*) ::  variable_name !< string indicating whether NetCDF needs to be opend or closed 
-       
-       INTEGER(iwp) ::  id_mod   !< NetCDF id of input file
-       INTEGER(iwp) ::  val      !< value of the attribute
-       
-       LOGICAL ::  global        !< flag indicating a global or a variable's attribute
-
-#if defined ( __netcdf )
-!
-!--    Open file in read-only mode
-       IF ( openclose == 'open' )  THEN
-          CALL open_read_file( TRIM( input_file ) // TRIM( coupling_char ), &
-                                  id_mod )
-       ENDIF
-!
-!--    Read global attribute
-       IF ( global )  THEN
-          CALL get_attribute( id_mod, search_string, val, global )
-!
-!--    Read variable attribute
-       ELSE
-          CALL get_attribute( id_mod, search_string, val, global, variable_name )
-       ENDIF
-!
-!--    Finally, close input file
-       IF ( openclose == 'close' )  CALL close_input_file( id_mod )
-#endif            
-
-    END SUBROUTINE netcdf_data_input_att_int32
-    
-!------------------------------------------------------------------------------!
-! Description:
-! ------------
-!> Read a global real attribute 
-!------------------------------------------------------------------------------!
-    SUBROUTINE netcdf_data_input_att_real( val, search_string, id_mod,         &
-                                           input_file, global, openclose,      &
-                                           variable_name )
-
-       IMPLICIT NONE
-
-       CHARACTER(LEN=*) ::  search_string !< name of the attribue
-       
-       CHARACTER(LEN=*) ::  input_file    !< name of input file
-       CHARACTER(LEN=*) ::  openclose     !< string indicating whether NetCDF needs to be opend or closed
-       CHARACTER(LEN=*) ::  variable_name !< string indicating whether NetCDF needs to be opend or closed 
-       
-       INTEGER(iwp) ::  id_mod            !< NetCDF id of input file
-       
-       LOGICAL ::  global                 !< flag indicating a global or a variable's attribute
-       
-       REAL(wp) ::  val                   !< value of the attribute
-
-#if defined ( __netcdf )
-!
-!--    Open file in read-only mode
-       IF ( openclose == 'open' )  THEN
-          CALL open_read_file( TRIM( input_file ) // TRIM( coupling_char ), &
-                                  id_mod )
-       ENDIF
-!
-!--    Read global attribute
-       IF ( global )  THEN
-          CALL get_attribute( id_mod, search_string, val, global )
-!
-!--    Read variable attribute
-       ELSE
-          CALL get_attribute( id_mod, search_string, val, global, variable_name )
-       ENDIF
-!
-!--    Finally, close input file
-       IF ( openclose == 'close' )  CALL close_input_file( id_mod )
-#endif            
-
-    END SUBROUTINE netcdf_data_input_att_real
+
 
 !------------------------------------------------------------------------------!
@@ -5823,4 +5580,53 @@
 ! Description:
 ! ------------
+!> Inquires the _FillValue settings of an integer variable.
+!------------------------------------------------------------------------------!
+    SUBROUTINE inquire_fill_value_int( id, var_name, nofill, fill_value )
+#if defined( __netcdf )
+       CHARACTER(LEN=*), INTENT(IN) ::  var_name    !< variable name
+
+       INTEGER(iwp), INTENT(IN)  ::  id          !< file id
+       INTEGER(iwp)              ::  nofill      !< flag indicating whether fill values are set or not
+       INTEGER(iwp)              ::  fill_value  !< fill value
+       INTEGER(iwp)              ::  id_var      !< netCDF variable id (varid)
+
+       nc_stat = NF90_INQ_VARID( id, TRIM( var_name ), id_var )
+       nc_stat = NF90_INQ_VAR_FILL(id, id_var, no_fill, fill_value )
+#endif
+!
+!--    Further line is just to avoid compiler warnings. nofill might be used
+!--    in future.
+       IF ( nofill == 0  .OR.  nofill /= 0 )  CONTINUE
+
+    END SUBROUTINE inquire_fill_value_int
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Inquires the _FillValue settings of a real variable.
+!------------------------------------------------------------------------------!
+    SUBROUTINE inquire_fill_value_real( id, var_name, nofill, fill_value )
+#if defined( __netcdf )
+       CHARACTER(LEN=*), INTENT(IN) ::  var_name    !< variable name
+
+       INTEGER(iwp), INTENT(IN)  ::  id          !< file id
+       INTEGER(iwp)              ::  nofill      !< flag indicating whether fill values are set or not
+       INTEGER(iwp)              ::  id_var      !< netCDF variable id (varid)
+
+       REAL(wp), INTENT(OUT)     ::  fill_value  !< fill value
+
+       nc_stat = NF90_INQ_VARID( id, TRIM( var_name ), id_var )
+       nc_stat = NF90_INQ_VAR_FILL(id, id_var, no_fill, fill_value )
+#endif
+!
+!--    Further line is just to avoid compiler warnings. nofill might be used
+!--    in future.
+       IF ( nofill == 0  .OR.  nofill /= 0 )  CONTINUE
+
+    END SUBROUTINE inquire_fill_value_real
+
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
 !> Prints out a text message corresponding to the current status.
 !------------------------------------------------------------------------------!
