From d6ce721a2516d1bbb8aa7f3253ae49bc0d061aff Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 24 Jul 2021 12:10:59 +0200 Subject: [PATCH 1/2] need to check type of leaf otherwise, using a [list] where a scalar is expected results in a crash, not in a meaningful error message --- src/YAML_types.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/YAML_types.f90 b/src/YAML_types.f90 index 45907fbae..e11be1275 100644 --- a/src/YAML_types.f90 +++ b/src/YAML_types.f90 @@ -849,7 +849,7 @@ function tNode_get_byKey_as1dFloat(self,k,defaultVal,requiredSize) result(nodeAs if (self%contains(k)) then node => self%get(k) - select type(self) + select type(node) class is(tList) list => node%asList() nodeAs1dFloat = list%as1dFloat() From f22f30e05da9008998a6c9316c470c8ac621c93e Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 24 Jul 2021 14:27:00 +0200 Subject: [PATCH 2/2] same functionality as for 1D --- src/YAML_types.f90 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/YAML_types.f90 b/src/YAML_types.f90 index e11be1275..8f81923a8 100644 --- a/src/YAML_types.f90 +++ b/src/YAML_types.f90 @@ -872,11 +872,12 @@ end function tNode_get_byKey_as1dFloat !-------------------------------------------------------------------------------------------------- !> @brief Access by key and convert to float array (2D) !-------------------------------------------------------------------------------------------------- -function tNode_get_byKey_as2dFloat(self,k,defaultVal) result(nodeAs2dFloat) +function tNode_get_byKey_as2dFloat(self,k,defaultVal,requiredShape) result(nodeAs2dFloat) class(tNode), intent(in), target :: self character(len=*), intent(in) :: k real(pReal), intent(in), dimension(:,:), optional :: defaultVal + integer, intent(in), dimension(2), optional :: requiredShape real(pReal), dimension(:,:), allocatable :: nodeAs2dFloat @@ -898,6 +899,10 @@ function tNode_get_byKey_as2dFloat(self,k,defaultVal) result(nodeAs2dFloat) call IO_error(143,ext_msg=k) endif + if (present(requiredShape)) then + if (any(requiredShape /= shape(nodeAs2dFloat))) call IO_error(146,ext_msg=k) + endif + end function tNode_get_byKey_as2dFloat