From eb17a9938350dbb040bc5fc237511d3ddb90f1d0 Mon Sep 17 00:00:00 2001 From: Purnendu Chakraborty Date: Fri, 6 Sep 2024 10:55:47 -0400 Subject: [PATCH 1/8] Addresses #2981 - added member variable regrid_param to VariableSpec - moved reading regrid_method from field dictionary from FieldSpec to VariableSpec --- generic3g/specs/FieldSpec.F90 | 32 +++------------------------ generic3g/specs/VariableSpec.F90 | 38 ++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/generic3g/specs/FieldSpec.F90 b/generic3g/specs/FieldSpec.F90 index 84f270ae6dd5..b2d45530253a 100644 --- a/generic3g/specs/FieldSpec.F90 +++ b/generic3g/specs/FieldSpec.F90 @@ -37,7 +37,7 @@ module mapl3g_FieldSpec use mapl3g_geom_mgr, only: MAPL_SameGeom use mapl3g_FieldDictionary use mapl3g_GriddedComponentDriver - use mapl3g_VariableSpec + use mapl3g_VariableSpec, only: VariableSpec, get_regrid_method_from_field_dict use udunits2f, only: UDUNITS_are_convertible => are_convertible, udunit use gftl2_StringVector use esmf @@ -181,7 +181,7 @@ function new_FieldSpec_geom(unusable, geom, vertical_grid, vertical_dim_spec, ty ! regrid_param field_spec%regrid_param = EsmfRegridderParam() ! use default regrid method - regrid_method = get_regrid_method_(field_spec%standard_name) + regrid_method = get_regrid_method_from_field_dict(field_spec%standard_name) field_spec%regrid_param = EsmfRegridderParam(regridmethod=regrid_method) if (present(regrid_param)) field_spec%regrid_param = regrid_param @@ -199,41 +199,15 @@ function new_FieldSpec_varspec(variable_spec) result(field_spec) _SET_FIELD(field_spec, variable_spec, typekind) _SET_FIELD(field_spec, variable_spec, ungridded_dims) _SET_FIELD(field_spec, variable_spec, attributes) + _SET_FIELD(field_spec, variable_spec, regrid_param) _SET_ALLOCATED_FIELD(field_spec, variable_spec, standard_name) _SET_ALLOCATED_FIELD(field_spec, variable_spec, units) _SET_ALLOCATED_FIELD(field_spec, variable_spec, default_value) field_spec%long_name = 'unknown' - - field_spec%regrid_param = EsmfRegridderParam() ! use default regrid method - regrid_method = get_regrid_method_(field_spec%standard_name) - field_spec%regrid_param = EsmfRegridderParam(regridmethod=regrid_method) - end function new_FieldSpec_varspec - function get_regrid_method_(stdname, rc) result(regrid_method) - type(ESMF_RegridMethod_Flag) :: regrid_method - character(:), allocatable, intent(in) :: stdname - integer, optional, intent(out) :: rc - - character(len=*), parameter :: field_dictionary_file = "field_dictionary.yml" - type(FieldDictionary) :: field_dict - logical :: file_exists - integer :: status - - regrid_method = ESMF_REGRIDMETHOD_BILINEAR ! default value - if (allocated(stdname)) then - inquire(file=trim(field_dictionary_file), exist=file_exists) - if (file_exists) then - field_dict = FieldDictionary(filename=field_dictionary_file, _RC) - regrid_method = field_dict%get_regrid_method(stdname, _RC) - end if - end if - - _RETURN(_SUCCESS) - end function get_regrid_method_ - subroutine set_geometry(this, geom, vertical_grid, rc) class(FieldSpec), intent(inout) :: this type(ESMF_Geom), optional, intent(in) :: geom diff --git a/generic3g/specs/VariableSpec.F90 b/generic3g/specs/VariableSpec.F90 index 1da7ab961365..f03371930c10 100644 --- a/generic3g/specs/VariableSpec.F90 +++ b/generic3g/specs/VariableSpec.F90 @@ -14,6 +14,8 @@ module mapl3g_VariableSpec use mapl_ErrorHandling use mapl3g_StateRegistry use mapl3g_StateItem + use mapl3g_EsmfRegridder, only: EsmfRegridderParam + use mapl3g_FieldDictionary use esmf use gFTL2_StringVector use nuopc @@ -21,7 +23,7 @@ module mapl3g_VariableSpec implicit none private - public :: VariableSpec + public :: VariableSpec, get_regrid_method_from_field_dict ! This type provides components that might be needed for _any_ ! state item. This is largely to support legacy interfaces, but it @@ -32,6 +34,7 @@ module mapl3g_VariableSpec type(ESMF_StateIntent_Flag) :: state_intent character(:), allocatable :: short_name type(ESMF_TypeKind_Flag) :: typekind = ESMF_TYPEKIND_R4 + type(EsmfRegridderParam) :: regrid_param ! Metadata character(:), allocatable :: standard_name @@ -68,7 +71,7 @@ function new_VariableSpec( & units, substate, itemtype, typekind, vertical_dim_spec, ungridded_dims, default_value, & service_items, attributes, & bracket_size, & - dependencies) result(var_spec) + dependencies, regrid_param) result(var_spec) type(VariableSpec) :: var_spec type(ESMF_StateIntent_Flag), intent(in) :: state_intent @@ -88,6 +91,9 @@ function new_VariableSpec( & type(StringVector), optional, intent(in) :: attributes integer, optional, intent(in) :: bracket_size type(StringVector), optional, intent(in) :: dependencies + type(EsmfRegridderParam), optional, intent(in) :: regrid_param + + type(ESMF_RegridMethod_Flag), allocatable :: regrid_method var_spec%state_intent = state_intent var_spec%short_name = short_name @@ -111,6 +117,12 @@ function new_VariableSpec( & _SET_OPTIONAL(bracket_size) _SET_OPTIONAL(dependencies) + ! regridding parameter + var_spec%regrid_param = EsmfRegridderParam() ! use default regrid method + regrid_method = get_regrid_method_from_field_dict(var_spec%standard_name) + var_spec%regrid_param = EsmfRegridderParam(regridmethod=regrid_method) + if (present(regrid_param)) var_spec%regrid_param = regrid_param + _UNUSED_DUMMY(unusable) end function new_VariableSpec @@ -235,4 +247,26 @@ function make_dependencies(this, rc) result(dependencies) _RETURN(_SUCCESS) end function make_dependencies + function get_regrid_method_from_field_dict(stdname, rc) result(regrid_method) + type(ESMF_RegridMethod_Flag) :: regrid_method + character(:), allocatable, intent(in) :: stdname + integer, optional, intent(out) :: rc + + character(len=*), parameter :: field_dictionary_file = "field_dictionary.yml" + type(FieldDictionary) :: field_dict + logical :: file_exists + integer :: status + + regrid_method = ESMF_REGRIDMETHOD_BILINEAR ! default value + if (allocated(stdname)) then + inquire(file=trim(field_dictionary_file), exist=file_exists) + if (file_exists) then + field_dict = FieldDictionary(filename=field_dictionary_file, _RC) + regrid_method = field_dict%get_regrid_method(stdname, _RC) + end if + end if + + _RETURN(_SUCCESS) + end function get_regrid_method_from_field_dict + end module mapl3g_VariableSpec From 5deb10181e65cb599203fca1f6f60846f4aaa3ad Mon Sep 17 00:00:00 2001 From: Purnendu Chakraborty Date: Fri, 6 Sep 2024 10:55:47 -0400 Subject: [PATCH 2/8] Addresses #2981 - added member variable regrid_param to VariableSpec - moved reading regrid_method from field dictionary from FieldSpec to VariableSpec --- generic3g/specs/FieldSpec.F90 | 32 +++------------------------ generic3g/specs/VariableSpec.F90 | 38 ++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/generic3g/specs/FieldSpec.F90 b/generic3g/specs/FieldSpec.F90 index 84f270ae6dd5..b2d45530253a 100644 --- a/generic3g/specs/FieldSpec.F90 +++ b/generic3g/specs/FieldSpec.F90 @@ -37,7 +37,7 @@ module mapl3g_FieldSpec use mapl3g_geom_mgr, only: MAPL_SameGeom use mapl3g_FieldDictionary use mapl3g_GriddedComponentDriver - use mapl3g_VariableSpec + use mapl3g_VariableSpec, only: VariableSpec, get_regrid_method_from_field_dict use udunits2f, only: UDUNITS_are_convertible => are_convertible, udunit use gftl2_StringVector use esmf @@ -181,7 +181,7 @@ function new_FieldSpec_geom(unusable, geom, vertical_grid, vertical_dim_spec, ty ! regrid_param field_spec%regrid_param = EsmfRegridderParam() ! use default regrid method - regrid_method = get_regrid_method_(field_spec%standard_name) + regrid_method = get_regrid_method_from_field_dict(field_spec%standard_name) field_spec%regrid_param = EsmfRegridderParam(regridmethod=regrid_method) if (present(regrid_param)) field_spec%regrid_param = regrid_param @@ -199,41 +199,15 @@ function new_FieldSpec_varspec(variable_spec) result(field_spec) _SET_FIELD(field_spec, variable_spec, typekind) _SET_FIELD(field_spec, variable_spec, ungridded_dims) _SET_FIELD(field_spec, variable_spec, attributes) + _SET_FIELD(field_spec, variable_spec, regrid_param) _SET_ALLOCATED_FIELD(field_spec, variable_spec, standard_name) _SET_ALLOCATED_FIELD(field_spec, variable_spec, units) _SET_ALLOCATED_FIELD(field_spec, variable_spec, default_value) field_spec%long_name = 'unknown' - - field_spec%regrid_param = EsmfRegridderParam() ! use default regrid method - regrid_method = get_regrid_method_(field_spec%standard_name) - field_spec%regrid_param = EsmfRegridderParam(regridmethod=regrid_method) - end function new_FieldSpec_varspec - function get_regrid_method_(stdname, rc) result(regrid_method) - type(ESMF_RegridMethod_Flag) :: regrid_method - character(:), allocatable, intent(in) :: stdname - integer, optional, intent(out) :: rc - - character(len=*), parameter :: field_dictionary_file = "field_dictionary.yml" - type(FieldDictionary) :: field_dict - logical :: file_exists - integer :: status - - regrid_method = ESMF_REGRIDMETHOD_BILINEAR ! default value - if (allocated(stdname)) then - inquire(file=trim(field_dictionary_file), exist=file_exists) - if (file_exists) then - field_dict = FieldDictionary(filename=field_dictionary_file, _RC) - regrid_method = field_dict%get_regrid_method(stdname, _RC) - end if - end if - - _RETURN(_SUCCESS) - end function get_regrid_method_ - subroutine set_geometry(this, geom, vertical_grid, rc) class(FieldSpec), intent(inout) :: this type(ESMF_Geom), optional, intent(in) :: geom diff --git a/generic3g/specs/VariableSpec.F90 b/generic3g/specs/VariableSpec.F90 index 1da7ab961365..f03371930c10 100644 --- a/generic3g/specs/VariableSpec.F90 +++ b/generic3g/specs/VariableSpec.F90 @@ -14,6 +14,8 @@ module mapl3g_VariableSpec use mapl_ErrorHandling use mapl3g_StateRegistry use mapl3g_StateItem + use mapl3g_EsmfRegridder, only: EsmfRegridderParam + use mapl3g_FieldDictionary use esmf use gFTL2_StringVector use nuopc @@ -21,7 +23,7 @@ module mapl3g_VariableSpec implicit none private - public :: VariableSpec + public :: VariableSpec, get_regrid_method_from_field_dict ! This type provides components that might be needed for _any_ ! state item. This is largely to support legacy interfaces, but it @@ -32,6 +34,7 @@ module mapl3g_VariableSpec type(ESMF_StateIntent_Flag) :: state_intent character(:), allocatable :: short_name type(ESMF_TypeKind_Flag) :: typekind = ESMF_TYPEKIND_R4 + type(EsmfRegridderParam) :: regrid_param ! Metadata character(:), allocatable :: standard_name @@ -68,7 +71,7 @@ function new_VariableSpec( & units, substate, itemtype, typekind, vertical_dim_spec, ungridded_dims, default_value, & service_items, attributes, & bracket_size, & - dependencies) result(var_spec) + dependencies, regrid_param) result(var_spec) type(VariableSpec) :: var_spec type(ESMF_StateIntent_Flag), intent(in) :: state_intent @@ -88,6 +91,9 @@ function new_VariableSpec( & type(StringVector), optional, intent(in) :: attributes integer, optional, intent(in) :: bracket_size type(StringVector), optional, intent(in) :: dependencies + type(EsmfRegridderParam), optional, intent(in) :: regrid_param + + type(ESMF_RegridMethod_Flag), allocatable :: regrid_method var_spec%state_intent = state_intent var_spec%short_name = short_name @@ -111,6 +117,12 @@ function new_VariableSpec( & _SET_OPTIONAL(bracket_size) _SET_OPTIONAL(dependencies) + ! regridding parameter + var_spec%regrid_param = EsmfRegridderParam() ! use default regrid method + regrid_method = get_regrid_method_from_field_dict(var_spec%standard_name) + var_spec%regrid_param = EsmfRegridderParam(regridmethod=regrid_method) + if (present(regrid_param)) var_spec%regrid_param = regrid_param + _UNUSED_DUMMY(unusable) end function new_VariableSpec @@ -235,4 +247,26 @@ function make_dependencies(this, rc) result(dependencies) _RETURN(_SUCCESS) end function make_dependencies + function get_regrid_method_from_field_dict(stdname, rc) result(regrid_method) + type(ESMF_RegridMethod_Flag) :: regrid_method + character(:), allocatable, intent(in) :: stdname + integer, optional, intent(out) :: rc + + character(len=*), parameter :: field_dictionary_file = "field_dictionary.yml" + type(FieldDictionary) :: field_dict + logical :: file_exists + integer :: status + + regrid_method = ESMF_REGRIDMETHOD_BILINEAR ! default value + if (allocated(stdname)) then + inquire(file=trim(field_dictionary_file), exist=file_exists) + if (file_exists) then + field_dict = FieldDictionary(filename=field_dictionary_file, _RC) + regrid_method = field_dict%get_regrid_method(stdname, _RC) + end if + end if + + _RETURN(_SUCCESS) + end function get_regrid_method_from_field_dict + end module mapl3g_VariableSpec From 4cfe4b3bde427b0498138855f88cb30b55248c50 Mon Sep 17 00:00:00 2001 From: Purnendu Chakraborty Date: Fri, 6 Sep 2024 11:58:59 -0400 Subject: [PATCH 3/8] Removed call to get_regrid_method_from_field_dict from FieldSpec's constructor. If optional regrid_param is not present, one is generated based on the default regridding method. --- generic3g/specs/FieldSpec.F90 | 5 +---- generic3g/specs/VariableSpec.F90 | 8 ++++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/generic3g/specs/FieldSpec.F90 b/generic3g/specs/FieldSpec.F90 index b2d45530253a..4c0e17e9d44c 100644 --- a/generic3g/specs/FieldSpec.F90 +++ b/generic3g/specs/FieldSpec.F90 @@ -37,7 +37,7 @@ module mapl3g_FieldSpec use mapl3g_geom_mgr, only: MAPL_SameGeom use mapl3g_FieldDictionary use mapl3g_GriddedComponentDriver - use mapl3g_VariableSpec, only: VariableSpec, get_regrid_method_from_field_dict + use mapl3g_VariableSpec, only: VariableSpec use udunits2f, only: UDUNITS_are_convertible => are_convertible, udunit use gftl2_StringVector use esmf @@ -165,7 +165,6 @@ function new_FieldSpec_geom(unusable, geom, vertical_grid, vertical_dim_spec, ty ! optional args last real, optional, intent(in) :: default_value - type(ESMF_RegridMethod_Flag), allocatable :: regrid_method integer :: status if (present(geom)) field_spec%geom = geom @@ -181,8 +180,6 @@ function new_FieldSpec_geom(unusable, geom, vertical_grid, vertical_dim_spec, ty ! regrid_param field_spec%regrid_param = EsmfRegridderParam() ! use default regrid method - regrid_method = get_regrid_method_from_field_dict(field_spec%standard_name) - field_spec%regrid_param = EsmfRegridderParam(regridmethod=regrid_method) if (present(regrid_param)) field_spec%regrid_param = regrid_param if (present(default_value)) field_spec%default_value = default_value diff --git a/generic3g/specs/VariableSpec.F90 b/generic3g/specs/VariableSpec.F90 index f03371930c10..d1333f9eed4b 100644 --- a/generic3g/specs/VariableSpec.F90 +++ b/generic3g/specs/VariableSpec.F90 @@ -23,7 +23,7 @@ module mapl3g_VariableSpec implicit none private - public :: VariableSpec, get_regrid_method_from_field_dict + public :: VariableSpec ! This type provides components that might be needed for _any_ ! state item. This is largely to support legacy interfaces, but it @@ -119,7 +119,7 @@ function new_VariableSpec( & ! regridding parameter var_spec%regrid_param = EsmfRegridderParam() ! use default regrid method - regrid_method = get_regrid_method_from_field_dict(var_spec%standard_name) + regrid_method = get_regrid_method_from_field_dict_(var_spec%standard_name) var_spec%regrid_param = EsmfRegridderParam(regridmethod=regrid_method) if (present(regrid_param)) var_spec%regrid_param = regrid_param @@ -247,7 +247,7 @@ function make_dependencies(this, rc) result(dependencies) _RETURN(_SUCCESS) end function make_dependencies - function get_regrid_method_from_field_dict(stdname, rc) result(regrid_method) + function get_regrid_method_from_field_dict_(stdname, rc) result(regrid_method) type(ESMF_RegridMethod_Flag) :: regrid_method character(:), allocatable, intent(in) :: stdname integer, optional, intent(out) :: rc @@ -267,6 +267,6 @@ function get_regrid_method_from_field_dict(stdname, rc) result(regrid_method) end if _RETURN(_SUCCESS) - end function get_regrid_method_from_field_dict + end function get_regrid_method_from_field_dict_ end module mapl3g_VariableSpec From dac70d4c27e74d9b0f07f7c906c12a2e741e251e Mon Sep 17 00:00:00 2001 From: Purnendu Chakraborty Date: Fri, 6 Sep 2024 17:19:17 -0400 Subject: [PATCH 4/8] Created a new procedure for setting regrid_param --- generic3g/specs/VariableSpec.F90 | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/generic3g/specs/VariableSpec.F90 b/generic3g/specs/VariableSpec.F90 index 4b2fce7c5298..93b9abd3bda7 100644 --- a/generic3g/specs/VariableSpec.F90 +++ b/generic3g/specs/VariableSpec.F90 @@ -54,9 +54,9 @@ module mapl3g_VariableSpec type(StringVector) :: dependencies contains procedure :: make_virtualPt - procedure :: make_dependencies procedure :: initialize + procedure, private :: set_regrid_param_ end type VariableSpec interface VariableSpec @@ -116,11 +116,7 @@ function new_VariableSpec( & _SET_OPTIONAL(bracket_size) _SET_OPTIONAL(dependencies) - ! regridding parameter - var_spec%regrid_param = EsmfRegridderParam() ! use default regrid method - regrid_method = get_regrid_method_from_field_dict_(var_spec%standard_name) - var_spec%regrid_param = EsmfRegridderParam(regridmethod=regrid_method) - if (present(regrid_param)) var_spec%regrid_param = regrid_param + call this%set_regrid_param() _UNUSED_DUMMY(unusable) end function new_VariableSpec @@ -229,6 +225,15 @@ function make_dependencies(this, rc) result(dependencies) _RETURN(_SUCCESS) end function make_dependencies + subroutine set_regrid_param_(this) + class(VariableSpec), intent(inout) :: this + + this%regrid_param = EsmfRegridderParam() ! use default regrid method + regrid_method = get_regrid_method_from_field_dict_(var_spec%standard_name) + this%regrid_param = EsmfRegridderParam(regridmethod=regrid_method) + if (present(regrid_param)) this%regrid_param = regrid_param + end subroutine set_regrid_param_ + function get_regrid_method_from_field_dict_(stdname, rc) result(regrid_method) type(ESMF_RegridMethod_Flag) :: regrid_method character(:), allocatable, intent(in) :: stdname From 2e5c24cbd3711e8961223db0e8d85af534c9f2b9 Mon Sep 17 00:00:00 2001 From: Purnendu Chakraborty Date: Fri, 6 Sep 2024 17:28:18 -0400 Subject: [PATCH 5/8] Fixed bugs related to set_regrid_param_ --- generic3g/specs/VariableSpec.F90 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/generic3g/specs/VariableSpec.F90 b/generic3g/specs/VariableSpec.F90 index 93b9abd3bda7..e12507af83ee 100644 --- a/generic3g/specs/VariableSpec.F90 +++ b/generic3g/specs/VariableSpec.F90 @@ -116,7 +116,7 @@ function new_VariableSpec( & _SET_OPTIONAL(bracket_size) _SET_OPTIONAL(dependencies) - call this%set_regrid_param() + call var_spec%set_regrid_param_(regrid_param) _UNUSED_DUMMY(unusable) end function new_VariableSpec @@ -225,11 +225,14 @@ function make_dependencies(this, rc) result(dependencies) _RETURN(_SUCCESS) end function make_dependencies - subroutine set_regrid_param_(this) + subroutine set_regrid_param_(this, regrid_param) class(VariableSpec), intent(inout) :: this + type(EsmfRegridderParam), optional, intent(in) :: regrid_param + + type(ESMF_RegridMethod_Flag) :: regrid_method this%regrid_param = EsmfRegridderParam() ! use default regrid method - regrid_method = get_regrid_method_from_field_dict_(var_spec%standard_name) + regrid_method = get_regrid_method_from_field_dict_(this%standard_name) this%regrid_param = EsmfRegridderParam(regridmethod=regrid_method) if (present(regrid_param)) this%regrid_param = regrid_param end subroutine set_regrid_param_ From f638fbb0ffa87b1aa8ee9686a992fd42bf49191c Mon Sep 17 00:00:00 2001 From: Purnendu Chakraborty Date: Sat, 7 Sep 2024 06:57:11 -0400 Subject: [PATCH 6/8] Better error handling in get_regrid_method --- generic3g/specs/VariableSpec.F90 | 46 ++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/generic3g/specs/VariableSpec.F90 b/generic3g/specs/VariableSpec.F90 index e12507af83ee..b4534887b002 100644 --- a/generic3g/specs/VariableSpec.F90 +++ b/generic3g/specs/VariableSpec.F90 @@ -70,7 +70,7 @@ function new_VariableSpec( & units, substate, itemtype, typekind, vertical_dim_spec, ungridded_dims, default_value, & service_items, attributes, & bracket_size, & - dependencies, regrid_param) result(var_spec) + dependencies, regrid_param, rc) result(var_spec) type(VariableSpec) :: var_spec type(ESMF_StateIntent_Flag), intent(in) :: state_intent @@ -91,8 +91,10 @@ function new_VariableSpec( & integer, optional, intent(in) :: bracket_size type(StringVector), optional, intent(in) :: dependencies type(EsmfRegridderParam), optional, intent(in) :: regrid_param + integer, optional, intent(out) :: rc type(ESMF_RegridMethod_Flag), allocatable :: regrid_method + integer :: status var_spec%state_intent = state_intent var_spec%short_name = short_name @@ -116,7 +118,7 @@ function new_VariableSpec( & _SET_OPTIONAL(bracket_size) _SET_OPTIONAL(dependencies) - call var_spec%set_regrid_param_(regrid_param) + call var_spec%set_regrid_param_(regrid_param, _RC) _UNUSED_DUMMY(unusable) end function new_VariableSpec @@ -225,16 +227,28 @@ function make_dependencies(this, rc) result(dependencies) _RETURN(_SUCCESS) end function make_dependencies - subroutine set_regrid_param_(this, regrid_param) + subroutine set_regrid_param_(this, regrid_param, rc) class(VariableSpec), intent(inout) :: this type(EsmfRegridderParam), optional, intent(in) :: regrid_param + integer, optional, intent(out) :: rc type(ESMF_RegridMethod_Flag) :: regrid_method + integer :: status - this%regrid_param = EsmfRegridderParam() ! use default regrid method - regrid_method = get_regrid_method_from_field_dict_(this%standard_name) - this%regrid_param = EsmfRegridderParam(regridmethod=regrid_method) - if (present(regrid_param)) this%regrid_param = regrid_param + if (present(regrid_param)) then + this%regrid_param = regrid_param + _RETURN(_SUCCESS) + end if + + regrid_method = get_regrid_method_from_field_dict_(this%standard_name, rc=status) + if (status==ESMF_SUCCESS) then + this%regrid_param = EsmfRegridderParam(regridmethod=regrid_method) + _RETURN(_SUCCESS) + end if + + this%regrid_param = EsmfRegridderParam() ! last resort - use default regrid method + + _RETURN(_SUCCESS) end subroutine set_regrid_param_ function get_regrid_method_from_field_dict_(stdname, rc) result(regrid_method) @@ -247,14 +261,18 @@ function get_regrid_method_from_field_dict_(stdname, rc) result(regrid_method) logical :: file_exists integer :: status - regrid_method = ESMF_REGRIDMETHOD_BILINEAR ! default value - if (allocated(stdname)) then - inquire(file=trim(field_dictionary_file), exist=file_exists) - if (file_exists) then - field_dict = FieldDictionary(filename=field_dictionary_file, _RC) - regrid_method = field_dict%get_regrid_method(stdname, _RC) - end if + inquire(file=trim(field_dictionary_file), exist=file_exists) + if (.not. file_exists) then + rc = _FAILURE + return + end if + + field_dict = FieldDictionary(filename=field_dictionary_file, _RC) + if (.not. allocated(stdname)) then + rc = _FAILURE + return end if + regrid_method = field_dict%get_regrid_method(stdname, _RC) _RETURN(_SUCCESS) end function get_regrid_method_from_field_dict_ From 1c49bfaf5a0551f6ad8563ec8641e678e35ee0d0 Mon Sep 17 00:00:00 2001 From: Purnendu Chakraborty Date: Sat, 7 Sep 2024 08:15:44 -0400 Subject: [PATCH 7/8] Getting ready for NUOPC FieldDictionary --- generic3g/specs/VariableSpec.F90 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/generic3g/specs/VariableSpec.F90 b/generic3g/specs/VariableSpec.F90 index b4534887b002..c679b7f7f616 100644 --- a/generic3g/specs/VariableSpec.F90 +++ b/generic3g/specs/VariableSpec.F90 @@ -240,6 +240,13 @@ subroutine set_regrid_param_(this, regrid_param, rc) _RETURN(_SUCCESS) end if + ! if (NUOPC_FieldDictionaryHasEntry(this%standard_name, rc=status)) then + ! call NUOPC_FieldDictionaryGetEntry(this%standard_name, regrid_method, rc=status) + ! if (status==ESMF_SUCCESS) then + ! this%regrid_param = EsmfRegridderParam(regridmethod=regrid_method) + ! _RETURN(_SUCCESS) + ! end if + ! end if regrid_method = get_regrid_method_from_field_dict_(this%standard_name, rc=status) if (status==ESMF_SUCCESS) then this%regrid_param = EsmfRegridderParam(regridmethod=regrid_method) From 63d5582e264426366bf480009eee6d4ac6ad4c54 Mon Sep 17 00:00:00 2001 From: Purnendu Chakraborty Date: Sat, 7 Sep 2024 08:51:21 -0400 Subject: [PATCH 8/8] Removed trailing space --- generic3g/specs/VariableSpec.F90 | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/generic3g/specs/VariableSpec.F90 b/generic3g/specs/VariableSpec.F90 index c679b7f7f616..ac955d4319ed 100644 --- a/generic3g/specs/VariableSpec.F90 +++ b/generic3g/specs/VariableSpec.F90 @@ -1,4 +1,3 @@ - #include "MAPL_Generic.h" module mapl3g_VariableSpec @@ -136,7 +135,7 @@ subroutine initialize(this, config) this%units = ESMF_HConfigAsString(config,keyString='units') contains - + function get_itemtype(config) result(itemtype) type(ESMF_StateItem_Flag) :: itemtype type(ESMF_HConfig), intent(in) :: config @@ -146,13 +145,13 @@ function get_itemtype(config) result(itemtype) itemtype = MAPL_STATEITEM_FIELD ! default if (.not. ESMF_HConfigIsDefined(config,keyString='itemtype')) return - - itemtype_as_string = ESMF_HConfigAsString(config,keyString='itemtype',rc=status) + + itemtype_as_string = ESMF_HConfigAsString(config,keyString='itemtype',rc=status) if (status /= 0) then itemtype = MAPL_STATEITEM_UNKNOWN return end if - + select case (itemtype_as_string) case ('field') itemtype = MAPL_STATEITEM_FIELD @@ -171,9 +170,9 @@ function get_itemtype(config) result(itemtype) case default itemtype = MAPL_STATEITEM_UNKNOWN end select - + end function get_itemtype - + end subroutine initialize function make_virtualPt(this) result(v_pt) @@ -189,7 +188,7 @@ subroutine fill_units(this, units, rc) class(VariableSpec), intent(in) :: this character(:), allocatable, intent(out) :: units integer, optional, intent(out) :: rc - + character(len=ESMF_MAXSTR) :: canonical_units integer :: status @@ -205,7 +204,7 @@ subroutine fill_units(this, units, rc) call NUOPC_FieldDictionaryGetEntry(this%standard_name, canonical_units, status) _ASSERT(status == ESMF_SUCCESS,'Units not found for standard name: <'//this%standard_name//'>') units = trim(canonical_units) - + _RETURN(_SUCCESS) end subroutine fill_units