keys() function for dictionary as in Python.
Does not work for gfortran which fails with an ICE.
This commit is contained in:
parent
48f38e74d7
commit
c2a822d8fd
|
@ -62,6 +62,8 @@ module YAML_types
|
|||
tNode_get_byKey_as1dString => tNode_get_byKey_as1dString
|
||||
procedure :: &
|
||||
getKey => tNode_get_byIndex_asKey
|
||||
procedure :: &
|
||||
Keys => tNode_getKeys
|
||||
procedure :: &
|
||||
getIndex => tNode_get_byKey_asIndex
|
||||
procedure :: &
|
||||
|
@ -625,6 +627,32 @@ function tNode_get_byIndex_asKey(self,i) result(key)
|
|||
end function tNode_get_byIndex_asKey
|
||||
|
||||
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief Get all keys from a dictionary
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
function tNode_getKeys(self) result(keys)
|
||||
|
||||
class(tNode), intent(in) :: self
|
||||
character(len=:), dimension(:), allocatable :: keys
|
||||
|
||||
character(len=pStringLen), dimension(:), allocatable :: temp
|
||||
integer :: j, l
|
||||
|
||||
allocate(temp(self%length))
|
||||
l = 0
|
||||
do j = 1, self%length
|
||||
temp(j) = self%getKey(j)
|
||||
l = max(len_trim(temp(j)),l)
|
||||
end do
|
||||
|
||||
allocate(character(l)::keys(self%length))
|
||||
do j = 1, self%length
|
||||
keys(j) = trim(temp(j))
|
||||
end do
|
||||
|
||||
end function tNode_getKeys
|
||||
|
||||
|
||||
!-------------------------------------------------------------------------------------------------
|
||||
!> @brief Checks if a given key/item is present in the dict/list
|
||||
!-------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -108,8 +108,14 @@ subroutine parse()
|
|||
homogenizations => config_material%get('homogenization')
|
||||
|
||||
call sanityCheck(materials, homogenizations)
|
||||
|
||||
#if defined (__GFORTRAN__)
|
||||
material_name_phase = getKeys(phases)
|
||||
material_name_homogenization = getKeys(homogenizations)
|
||||
#else
|
||||
material_name_phase = phases%Keys()
|
||||
material_name_homogenization = homogenizations%Keys()
|
||||
#endif
|
||||
|
||||
allocate(homogenization_Nconstituents(homogenizations%length))
|
||||
do h=1, homogenizations%length
|
||||
|
@ -203,9 +209,9 @@ subroutine sanityCheck(materials,homogenizations)
|
|||
|
||||
end subroutine sanityCheck
|
||||
|
||||
|
||||
#if defined (__GFORTRAN__)
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
!> @brief Get all keys from a dictionary
|
||||
!> @brief %keys() is broken on gfortran
|
||||
!--------------------------------------------------------------------------------------------------
|
||||
function getKeys(dict)
|
||||
|
||||
|
@ -228,5 +234,6 @@ function getKeys(dict)
|
|||
end do
|
||||
|
||||
end function getKeys
|
||||
#endif
|
||||
|
||||
end module material
|
||||
|
|
Loading…
Reference in New Issue