Ignore:
Timestamp:
Oct 6, 2020 5:20:39 PM (4 years ago)
Author:
suehring
Message:

Mesoscale offline nesting: enable LOD 1 (homogeneous) input of lateral and top boundary conditions; add new generic subroutines to read time-dependent profile data from dynamic input file; minor bugfix - add missing initialization of the top boundary

File:
1 edited

Legend:

Unmodified
Added
Removed
  • palm/trunk/SOURCE/netcdf_data_input_mod.f90

    r4641 r4724  
    2525! -----------------
    2626! $Id$
     27! - New routines to read LOD=1 variables from dynamic input file
     28! - add no_abort option to all get_attribute routines
     29!
     30! 4641 2020-08-13 09:57:07Z suehring
    2731! To follow (UC)2 standard, change default of attribute data_content
    2832!
     
    741745       MODULE PROCEDURE get_variable_2d_int32
    742746       MODULE PROCEDURE get_variable_2d_real
     747       MODULE PROCEDURE get_variable_2d_real_dynamic
    743748       MODULE PROCEDURE get_variable_3d_int8
    744749       MODULE PROCEDURE get_variable_3d_real
     
    39964001!------------------------------------------------------------------------------!
    39974002     SUBROUTINE get_attribute_int32( id, attribute_name, value, global,        &
    3998                                      variable_name )
     4003                                     variable_name, no_abort )
    39994004
    40004005       USE pegrid
     
    40094014       INTEGER(iwp), INTENT(INOUT) ::  value            !< read value
    40104015
    4011        LOGICAL, INTENT(IN) ::  global                   !< flag indicating global attribute
     4016       LOGICAL                       ::  check_error    !< flag indicating if handle_error shall be checked
     4017       LOGICAL, INTENT(IN)           ::  global         !< flag indicating global attribute
     4018       LOGICAL, INTENT(IN), OPTIONAL ::  no_abort       !< flag indicating if errors should be checked
    40124019#if defined( __netcdf )
    40134020
     4021       IF ( PRESENT( no_abort ) )  THEN
     4022          check_error = no_abort
     4023       ELSE
     4024          check_error = .TRUE.
     4025       ENDIF
    40144026!
    40154027!--    Read global attribute
    40164028       IF ( global )  THEN
    40174029          nc_stat = NF90_GET_ATT( id, NF90_GLOBAL, TRIM( attribute_name ), value )
    4018           CALL handle_error( 'get_attribute_int32 global', 522, attribute_name )
     4030          IF ( check_error)  CALL handle_error( 'get_attribute_int32 global', 522, attribute_name )
    40194031!
    40204032!--    Read attributes referring to a single variable. Therefore, first inquire
     
    40224034       ELSE
    40234035          nc_stat = NF90_INQ_VARID( id, TRIM( variable_name ), id_var )
    4024           CALL handle_error( 'get_attribute_int32', 522, attribute_name )
     4036          IF ( check_error)  CALL handle_error( 'get_attribute_int32', 522, attribute_name )
    40254037          nc_stat = NF90_GET_ATT( id, id_var, TRIM( attribute_name ), value )
    4026           CALL handle_error( 'get_attribute_int32', 522, attribute_name )
     4038          IF ( check_error)  CALL handle_error( 'get_attribute_int32', 522, attribute_name )
    40274039       ENDIF
    40284040#endif
     
    40354047!------------------------------------------------------------------------------!
    40364048     SUBROUTINE get_attribute_int8( id, attribute_name, value, global,         &
    4037                                     variable_name )
     4049                                    variable_name, no_abort )
    40384050
    40394051       USE pegrid
     
    40484060       INTEGER(KIND=1), INTENT(INOUT) ::  value         !< read value
    40494061
    4050        LOGICAL, INTENT(IN) ::  global                   !< flag indicating global attribute
     4062       LOGICAL                       ::  check_error    !< flag indicating if handle_error shall be checked
     4063       LOGICAL, INTENT(IN), OPTIONAL ::  no_abort       !< flag indicating if errors should be checked
     4064       LOGICAL, INTENT(IN)           ::  global         !< flag indicating global attribute
    40514065#if defined( __netcdf )
    40524066
     4067       IF ( PRESENT( no_abort ) )  THEN
     4068          check_error = no_abort
     4069       ELSE
     4070          check_error = .TRUE.
     4071       ENDIF
    40534072!
    40544073!--    Read global attribute
    40554074       IF ( global )  THEN
    40564075          nc_stat = NF90_GET_ATT( id, NF90_GLOBAL, TRIM( attribute_name ), value )
    4057           CALL handle_error( 'get_attribute_int8 global', 523, attribute_name )
     4076          IF ( check_error)  CALL handle_error( 'get_attribute_int8 global', 523, attribute_name )
    40584077!
    40594078!--    Read attributes referring to a single variable. Therefore, first inquire
     
    40614080       ELSE
    40624081          nc_stat = NF90_INQ_VARID( id, TRIM( variable_name ), id_var )
    4063           CALL handle_error( 'get_attribute_int8', 523, attribute_name )
     4082          IF ( check_error)  CALL handle_error( 'get_attribute_int8', 523, attribute_name )
    40644083          nc_stat = NF90_GET_ATT( id, id_var, TRIM( attribute_name ), value )
    4065           CALL handle_error( 'get_attribute_int8', 523, attribute_name )
     4084          IF ( check_error)  CALL handle_error( 'get_attribute_int8', 523, attribute_name )
    40664085       ENDIF
    40674086#endif
     
    40744093!------------------------------------------------------------------------------!
    40754094     SUBROUTINE get_attribute_real( id, attribute_name, value, global,         &
    4076                                     variable_name )
     4095                                    variable_name, no_abort )
    40774096
    40784097       USE pegrid
     
    40864105       INTEGER(iwp)                ::  id_var           !< variable id
    40874106
    4088        LOGICAL, INTENT(IN) ::  global                   !< flag indicating global attribute
     4107       LOGICAL                       ::  check_error    !< flag indicating if handle_error shall be checked
     4108       LOGICAL, INTENT(IN)           ::  global         !< flag indicating global attribute
     4109       LOGICAL, INTENT(IN), OPTIONAL ::  no_abort       !< flag indicating if errors should be checked
    40894110
    40904111       REAL(wp), INTENT(INOUT)     ::  value            !< read value
    40914112#if defined( __netcdf )
    40924113
    4093 
    4094 !
    4095 !-- Read global attribute
     4114       IF ( PRESENT( no_abort ) )  THEN
     4115          check_error = no_abort
     4116       ELSE
     4117          check_error = .TRUE.
     4118       ENDIF
     4119!
     4120!--    Read global attribute
    40964121       IF ( global )  THEN
    40974122          nc_stat = NF90_GET_ATT( id, NF90_GLOBAL, TRIM( attribute_name ), value )
    4098           CALL handle_error( 'get_attribute_real global', 524, attribute_name )
    4099 !
    4100 !-- Read attributes referring to a single variable. Therefore, first inquire
    4101 !-- variable id
     4123          IF ( check_error)  CALL handle_error( 'get_attribute_real global', 524, attribute_name )
     4124!
     4125!--    Read attributes referring to a single variable. Therefore, first inquire
     4126!--    variable id
    41024127       ELSE
    41034128          nc_stat = NF90_INQ_VARID( id, TRIM( variable_name ), id_var )
    4104           CALL handle_error( 'get_attribute_real', 524, attribute_name )
     4129          IF ( check_error)  CALL handle_error( 'get_attribute_real', 524, attribute_name )
    41054130          nc_stat = NF90_GET_ATT( id, id_var, TRIM( attribute_name ), value )
    4106           CALL handle_error( 'get_attribute_real', 524, attribute_name )
     4131          IF ( check_error)  CALL handle_error( 'get_attribute_real', 524, attribute_name )
    41074132       ENDIF
    41084133#endif
     
    43324357
    43334358!------------------------------------------------------------------------------!
    4334 ! Description:
    4335 ! ------------
    4336 !> Reads a character variable in a 1D array
     4359!    Description:
     4360!    ------------
     4361!>   Reads a character variable in a 1D array
    43374362!------------------------------------------------------------------------------!
    43384363     SUBROUTINE get_variable_1d_char( id, variable_name, var )
     
    44054430       CALL handle_error( 'get_variable_1d_int', 527, variable_name )
    44064431!
    4407 !--    Inquire dimension length
     4432!--    Read variable
    44084433       nc_stat = NF90_GET_VAR( id, id_var, var )
    44094434       CALL handle_error( 'get_variable_1d_int', 527, variable_name )
     
    44174442!> Reads a 1D float variable from file.
    44184443!------------------------------------------------------------------------------!
    4419      SUBROUTINE get_variable_1d_real( id, variable_name, var )
     4444     SUBROUTINE get_variable_1d_real( id, variable_name, var, is, count_elements )
    44204445
    44214446       USE pegrid
     
    44284453       INTEGER(iwp)                ::  id_var           !< dimension id
    44294454
     4455       INTEGER(iwp), INTENT(IN), OPTIONAL ::  count_elements !< number of elements to be read
     4456       INTEGER(iwp), INTENT(IN), OPTIONAL ::  is             !< start index
     4457
    44304458       REAL(wp), DIMENSION(:), INTENT(INOUT) ::  var    !< variable to be read
    44314459#if defined( __netcdf )
    4432 
    44334460!
    44344461!--    First, inquire variable ID
     
    44364463       CALL handle_error( 'get_variable_1d_real', 528, variable_name )
    44374464!
    4438 !--    Inquire dimension length
    4439        nc_stat = NF90_GET_VAR( id, id_var, var )
    4440        CALL handle_error( 'get_variable_1d_real', 528, variable_name )
     4465!--    Read variable
     4466       IF ( PRESENT( is ) )  THEN
     4467          nc_stat = NF90_GET_VAR( id, id_var, var, start = (/ is /), count = (/ count_elements /) )
     4468          CALL handle_error( 'get_variable_1d_real', 528, variable_name )
     4469       ELSE
     4470          nc_stat = NF90_GET_VAR( id, id_var, var )
     4471          CALL handle_error( 'get_variable_1d_real', 528, variable_name )
     4472       ENDIF
    44414473
    44424474#endif
     
    44634495       INTEGER(iwp), INTENT(IN)              ::  t                !< timestep number
    44644496
    4465        REAL(wp), DIMENSION(:), INTENT(INOUT) ::  var  !< variable to be read
     4497       REAL(wp), DIMENSION(:), INTENT(INOUT) ::  var              !< variable to be read
    44664498
    44674499#if defined( __netcdf )
     
    47434775
    47444776!
    4745 !-- Allocate temporary variable according to memory access on file.
     4777!--    Allocate temporary variable according to memory access on file.
    47464778       ALLOCATE( tmp(is:ie,js:je) )
    47474779!
    4748 !-- Get variable
     4780!--    Get variable
    47494781       nc_stat = NF90_GET_VAR( id, id_var, tmp,            &
    47504782                      start = (/ is+1,      js+1 /),       &
    47514783                      count = (/ ie-is + 1, je-js+1 /) )   
    4752           CALL handle_error( 'get_variable_2d_real', 530, variable_name )
    4753 !
    4754 !-- Resort data. Please note, dimension subscripts of var all start at 1.
    4755           DO  i = is, ie
    4756              DO  j = js, je
    4757                 var(j-js+1,i-is+1) = tmp(i,j)
    4758              ENDDO
     4784       CALL handle_error( 'get_variable_2d_real', 530, variable_name )
     4785!
     4786!--    Resort data. Please note, dimension subscripts of var all start at 1.
     4787       DO  i = is, ie
     4788          DO  j = js, je
     4789             var(j-js+1,i-is+1) = tmp(i,j)
    47594790          ENDDO
     4791       ENDDO
    47604792       
    4761           DEALLOCATE( tmp )
     4793       DEALLOCATE( tmp )
    47624794
    47634795#endif
     
    51715203#endif
    51725204    END SUBROUTINE get_variable_4d_to_3d_real
     5205
     5206!------------------------------------------------------------------------------!
     5207! Description:
     5208! ------------
     5209!> Reads a 3D float variables from dynamic driver with the last dimension only
     5210!> having 1 entry (time,z). Please note,
     5211!> the passed arguments are start indices and number of elements in each
     5212!> dimension, which is in contrast to the other 3d versions where start- and
     5213!> end indices are passed. The different handling compared to get_variable_2d_real
     5214!> is due to its different start-index treatment.
     5215!------------------------------------------------------------------------------!
     5216    SUBROUTINE get_variable_2d_real_dynamic( id, variable_name, var,           &
     5217                                             i1s, i2s,                         &
     5218                                             count_1, count_2 )
     5219                               
     5220       USE indices
     5221       USE pegrid
     5222
     5223       IMPLICIT NONE
     5224
     5225       CHARACTER(LEN=*)              ::  variable_name   !< variable name
     5226
     5227       INTEGER(iwp)                  ::  count_1         !< number of elements to be read along 1st dimension (with respect to file)
     5228       INTEGER(iwp)                  ::  count_2         !< number of elements to be read along 2nd dimension (with respect to file)
     5229       INTEGER(iwp)                  ::  i1              !< running index along 1st dimension on file
     5230       INTEGER(iwp)                  ::  i1s             !< start index for subdomain input along 1st dimension (with respect to file)
     5231       INTEGER(iwp)                  ::  i2              !< running index along 2nd dimension on file       
     5232       INTEGER(iwp)                  ::  i2s             !< start index for subdomain input along 2nd dimension (with respect to file)
     5233       INTEGER(iwp), INTENT(IN)      ::  id              !< file id
     5234       INTEGER(iwp)                  ::  id_var          !< variable id
     5235       INTEGER(iwp)                  ::  lb1             !< lower bound of 1st dimension (with respect to file)
     5236       INTEGER(iwp)                  ::  lb2             !< lower bound of 2nd dimension (with respect to file)
     5237       INTEGER(iwp)                  ::  ub1             !< upper bound of 1st dimension (with respect to file)
     5238       INTEGER(iwp)                  ::  ub2             !< upper bound of 2nd dimension (with respect to file)
     5239
     5240       REAL(wp), DIMENSION(:,:), ALLOCATABLE   ::  tmp   !< temporary variable to read data from file according to its reverse memory access
     5241
     5242       REAL(wp), DIMENSION(:,:,:), INTENT(INOUT) ::  var !< input variable
     5243
     5244#if defined( __netcdf )
     5245!
     5246!--    Inquire variable id.
     5247       nc_stat = NF90_INQ_VARID( id, TRIM( variable_name ), id_var )
     5248!
     5249!--    Allocate temporary variable according to memory access on file.
     5250!--    Therefore, determine dimension bounds of input array.
     5251       lb1 = LBOUND(var,2)
     5252       ub1 = UBOUND(var,2)
     5253       lb2 = LBOUND(var,1)
     5254       ub2 = UBOUND(var,1)
     5255
     5256       ALLOCATE( tmp(lb1:ub1,lb2:ub2) )
     5257!
     5258!--    Get variable
     5259       nc_stat = NF90_GET_VAR( id, id_var, tmp,                                &
     5260                               start = (/ i1s,     i2s /),                     &
     5261                               count = (/ count_1, count_2 /) )
     5262
     5263       CALL handle_error( 'get_variable_2d_real_dynamic', 537, variable_name )
     5264!
     5265!--    Resort data. Please note, dimension subscripts of var all start at 1.
     5266       DO i2 = lb2, ub2
     5267          DO  i1 = lb1, ub1
     5268             var(i2,i1,1) = tmp(i1,i2)
     5269          ENDDO
     5270       ENDDO
     5271
     5272       DEALLOCATE( tmp )       
     5273#endif
     5274    END SUBROUTINE get_variable_2d_real_dynamic
    51735275
    51745276!------------------------------------------------------------------------------!
Note: See TracChangeset for help on using the changeset viewer.