2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2020-05-08 02:40:27 +05:30
|
|
|
!> @author Sharan Roongta, Max-Planck-Institut für Eisenforschung GmbH
|
|
|
|
!> @author Martin Diehl, Max-Planck-Institut für Eisenforschung GmbH
|
|
|
|
!> @brief Data types to create a scalar, a list, and a dictionary/hash
|
2020-04-22 16:22:47 +05:30
|
|
|
!> @details module describes the various functions to store and get the yaml data.
|
2020-05-08 02:40:27 +05:30
|
|
|
!! A node is the base class for scalar, list and dictionary, list items and dictionary entries point
|
|
|
|
!! to a node.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
|
2020-04-28 13:59:13 +05:30
|
|
|
module YAML_types
|
2020-04-22 16:22:47 +05:30
|
|
|
use IO
|
|
|
|
use prec
|
|
|
|
|
2022-06-22 02:16:54 +05:30
|
|
|
implicit none(type,external)
|
2020-04-22 16:22:47 +05:30
|
|
|
private
|
|
|
|
|
2020-05-22 00:22:15 +05:30
|
|
|
type, abstract, public :: tNode
|
2022-10-25 21:39:36 +05:30
|
|
|
integer :: &
|
|
|
|
length = 0
|
2020-04-22 16:22:47 +05:30
|
|
|
contains
|
2023-06-04 10:47:38 +05:30
|
|
|
procedure(asFormattedStr), deferred :: &
|
|
|
|
asFormattedStr
|
2020-04-22 16:22:47 +05:30
|
|
|
procedure :: &
|
2022-10-25 21:39:36 +05:30
|
|
|
asScalar => tNode_asScalar, &
|
|
|
|
asList => tNode_asList, &
|
|
|
|
asDict => tNode_asDict
|
2020-04-22 16:22:47 +05:30
|
|
|
end type tNode
|
|
|
|
|
2020-05-22 00:22:15 +05:30
|
|
|
type, extends(tNode), public :: tScalar
|
2022-10-25 21:39:36 +05:30
|
|
|
character(len=:), allocatable, private :: &
|
|
|
|
value
|
2020-04-22 16:22:47 +05:30
|
|
|
contains
|
|
|
|
procedure :: &
|
2023-06-04 10:47:38 +05:30
|
|
|
asFormattedStr => tScalar_asFormattedStr, &
|
|
|
|
asReal => tScalar_asReal, &
|
|
|
|
asInt => tScalar_asInt, &
|
|
|
|
asBool => tScalar_asBool, &
|
|
|
|
asStr => tScalar_asStr
|
2020-04-22 16:22:47 +05:30
|
|
|
end type tScalar
|
|
|
|
|
2020-05-22 00:22:15 +05:30
|
|
|
type, extends(tNode), public :: tList
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tItem), pointer :: &
|
|
|
|
first => NULL(), &
|
|
|
|
last => NULL()
|
2020-04-22 16:22:47 +05:30
|
|
|
contains
|
|
|
|
procedure :: &
|
2023-06-04 10:47:38 +05:30
|
|
|
asFormattedStr => tList_asFormattedStr, &
|
2022-10-25 21:39:36 +05:30
|
|
|
append => tList_append, &
|
2023-06-03 20:36:32 +05:30
|
|
|
as1dReal => tList_as1dReal, &
|
|
|
|
as2dReal => tList_as2dReal, &
|
2022-10-25 21:39:36 +05:30
|
|
|
as1dInt => tList_as1dInt, &
|
|
|
|
as1dBool => tList_as1dBool, &
|
2023-06-04 10:47:38 +05:30
|
|
|
as1dStr => tList_as1dStr, &
|
2022-10-25 21:39:36 +05:30
|
|
|
contains => tList_contains, &
|
|
|
|
tList_get, &
|
|
|
|
tList_get_scalar, &
|
|
|
|
tList_get_list, &
|
|
|
|
tList_get_dict, &
|
2023-06-03 20:36:32 +05:30
|
|
|
tList_get_asReal, &
|
|
|
|
tList_get_as1dReal, &
|
2022-10-25 21:39:36 +05:30
|
|
|
tList_get_asInt, &
|
|
|
|
tList_get_as1dInt, &
|
|
|
|
tList_get_asBool, &
|
|
|
|
tList_get_as1dBool, &
|
2023-06-04 10:47:38 +05:30
|
|
|
tList_get_asStr, &
|
|
|
|
tList_get_as1dStr
|
|
|
|
generic :: get => tList_get
|
|
|
|
generic :: get_scalar => tList_get_scalar
|
|
|
|
generic :: get_list => tList_get_list
|
|
|
|
generic :: get_dict => tList_get_dict
|
|
|
|
generic :: get_asReal => tList_get_asReal
|
|
|
|
generic :: get_as1dReal => tList_get_as1dReal
|
|
|
|
generic :: get_asInt => tList_get_asInt
|
|
|
|
generic :: get_as1dInt => tList_get_as1dInt
|
|
|
|
generic :: get_asBool => tList_get_asBool
|
|
|
|
generic :: get_as1dBool => tList_get_as1dBool
|
|
|
|
generic :: get_asStr => tList_get_asStr
|
|
|
|
generic :: get_as1dStr => tList_get_as1dStr
|
2020-04-22 16:22:47 +05:30
|
|
|
final :: tList_finalize
|
|
|
|
end type tList
|
|
|
|
|
2020-05-22 00:22:15 +05:30
|
|
|
type, extends(tList), public :: tDict
|
2020-04-22 16:22:47 +05:30
|
|
|
contains
|
2022-10-25 21:39:36 +05:30
|
|
|
procedure :: &
|
2023-06-04 10:47:38 +05:30
|
|
|
asFormattedStr => tDict_asFormattedStr, &
|
|
|
|
set => tDict_set, &
|
|
|
|
index => tDict_index, &
|
|
|
|
key => tDict_key, &
|
|
|
|
keys => tDict_keys, &
|
|
|
|
contains => tDict_contains, &
|
2022-10-25 21:39:36 +05:30
|
|
|
tDict_get, &
|
|
|
|
tDict_get_scalar, &
|
|
|
|
tDict_get_list, &
|
|
|
|
tDict_get_dict, &
|
2023-06-03 20:36:32 +05:30
|
|
|
tDict_get_asReal, &
|
|
|
|
tDict_get_as1dReal, &
|
|
|
|
tDict_get_as2dReal, &
|
2022-10-25 21:39:36 +05:30
|
|
|
tDict_get_asInt, &
|
|
|
|
tDict_get_as1dInt, &
|
|
|
|
tDict_get_asBool, &
|
|
|
|
tDict_get_as1dBool, &
|
2023-06-04 10:47:38 +05:30
|
|
|
tDict_get_asStr, &
|
|
|
|
tDict_get_as1dStr
|
|
|
|
generic :: get => tDict_get
|
|
|
|
generic :: get_scalar => tDict_get_scalar
|
|
|
|
generic :: get_list => tDict_get_list
|
|
|
|
generic :: get_dict => tDict_get_dict
|
|
|
|
generic :: get_asReal => tDict_get_asReal
|
|
|
|
generic :: get_as1dReal => tDict_get_as1dReal
|
|
|
|
generic :: get_as2dReal => tDict_get_as2dReal
|
|
|
|
generic :: get_asInt => tDict_get_asInt
|
|
|
|
generic :: get_as1dInt => tDict_get_as1dInt
|
|
|
|
generic :: get_asBool => tDict_get_asBool
|
|
|
|
generic :: get_as1dBool => tDict_get_as1dBool
|
|
|
|
generic :: get_asStr => tDict_get_asStr
|
|
|
|
generic :: get_as1dStr => tDict_get_as1dStr
|
2022-10-25 21:39:36 +05:30
|
|
|
end type tDict
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
2022-04-14 04:36:47 +05:30
|
|
|
type, public :: tItem
|
2020-04-22 16:22:47 +05:30
|
|
|
character(len=:), allocatable :: key
|
2022-01-22 05:04:42 +05:30
|
|
|
class(tNode), pointer :: node => NULL()
|
|
|
|
class(tItem), pointer :: next => NULL()
|
2020-05-01 00:59:59 +05:30
|
|
|
contains
|
|
|
|
final :: tItem_finalize
|
2020-04-22 16:22:47 +05:30
|
|
|
end type tItem
|
|
|
|
|
2020-06-23 14:36:41 +05:30
|
|
|
type(tDict), target, public :: &
|
2020-06-16 19:27:16 +05:30
|
|
|
emptyDict
|
2020-06-23 14:36:41 +05:30
|
|
|
type(tList), target, public :: &
|
2020-06-16 19:27:16 +05:30
|
|
|
emptyList
|
2021-02-27 23:44:53 +05:30
|
|
|
|
2020-04-22 16:22:47 +05:30
|
|
|
abstract interface
|
|
|
|
|
2023-06-04 10:47:38 +05:30
|
|
|
recursive function asFormattedStr(self)
|
2020-04-22 16:22:47 +05:30
|
|
|
import tNode
|
2023-06-04 10:47:38 +05:30
|
|
|
character(len=:), allocatable :: asFormattedStr
|
2020-04-22 16:22:47 +05:30
|
|
|
class(tNode), intent(in), target :: self
|
2023-06-04 10:47:38 +05:30
|
|
|
end function asFormattedStr
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
end interface
|
|
|
|
|
|
|
|
interface tScalar
|
|
|
|
module procedure tScalar_init__
|
|
|
|
end interface tScalar
|
|
|
|
|
|
|
|
interface assignment (=)
|
|
|
|
module procedure tScalar_assign__
|
|
|
|
end interface assignment (=)
|
|
|
|
|
2020-05-22 00:22:15 +05:30
|
|
|
public :: &
|
|
|
|
YAML_types_init, &
|
2022-10-25 21:39:36 +05:30
|
|
|
#ifdef __GFORTRAN__
|
2023-06-04 10:47:38 +05:30
|
|
|
output_as1dStr, & !ToDo: Hack for GNU. Remove later
|
2022-10-25 21:39:36 +05:30
|
|
|
#endif
|
2020-05-22 00:22:15 +05:30
|
|
|
assignment(=)
|
|
|
|
|
2020-04-22 16:22:47 +05:30
|
|
|
contains
|
|
|
|
|
2020-04-28 13:59:13 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2020-09-13 16:13:49 +05:30
|
|
|
!> @brief Do sanity checks.
|
2020-04-28 13:59:13 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
subroutine YAML_types_init
|
|
|
|
|
2021-11-15 23:05:44 +05:30
|
|
|
print'(/,1x,a)', '<<<+- YAML_types init -+>>>'
|
2020-04-28 13:59:13 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
call selfTest()
|
2020-04-28 13:59:13 +05:30
|
|
|
|
|
|
|
end subroutine YAML_types_init
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
2020-04-28 13:59:13 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2020-09-13 16:13:49 +05:30
|
|
|
!> @brief Check correctness of some type bound procedures.
|
2020-04-28 13:59:13 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-12-05 18:15:08 +05:30
|
|
|
subroutine selfTest()
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
scalar: block
|
2022-12-05 18:15:08 +05:30
|
|
|
type(tScalar), target :: s
|
|
|
|
type(tScalar), pointer :: s_pointer
|
2022-10-25 21:39:36 +05:30
|
|
|
|
2022-12-05 18:15:08 +05:30
|
|
|
|
|
|
|
s_pointer => s%asScalar()
|
2022-10-25 21:39:36 +05:30
|
|
|
s = '1'
|
2023-06-04 10:47:38 +05:30
|
|
|
if (s%asInt() /= 1) error stop 'tScalar_asInt'
|
|
|
|
if (s_pointer%asInt() /= 1) error stop 'tScalar_asInt(pointer)'
|
2023-06-04 10:52:25 +05:30
|
|
|
if (dNeq(s%asReal(),1.0_pREAL)) error stop 'tScalar_asReal'
|
2022-10-25 21:39:36 +05:30
|
|
|
s = 'true'
|
2023-06-04 10:47:38 +05:30
|
|
|
if (.not. s%asBool()) error stop 'tScalar_asBool'
|
|
|
|
if (.not. s_pointer%asBool()) error stop 'tScalar_asBool(pointer)'
|
|
|
|
if (s%asStr() /= 'true') error stop 'tScalar_asStr'
|
|
|
|
if (s%asFormattedStr() /= 'true') error stop 'tScalar_asFormattedStr'
|
2022-10-25 21:39:36 +05:30
|
|
|
|
2022-12-05 18:15:08 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end block scalar
|
|
|
|
|
|
|
|
list: block
|
2022-12-05 18:15:08 +05:30
|
|
|
type(tList), pointer :: l, l_pointer
|
2022-10-25 21:39:36 +05:30
|
|
|
type(tScalar), pointer :: s1,s2
|
|
|
|
|
2022-12-05 18:15:08 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
allocate(s1)
|
|
|
|
allocate(s2)
|
|
|
|
s1 = '1'
|
|
|
|
s2 = '2'
|
|
|
|
allocate(l)
|
2022-12-05 18:15:08 +05:30
|
|
|
l_pointer => l%asList()
|
2023-06-04 10:47:38 +05:30
|
|
|
if (l%contains('1')) error stop 'empty tList_contains'
|
|
|
|
if (l_pointer%contains('1')) error stop 'empty tList_contains(pointer)'
|
2022-10-25 21:39:36 +05:30
|
|
|
call l%append(s1)
|
|
|
|
call l%append(s2)
|
2023-06-04 10:47:38 +05:30
|
|
|
if (l%length /= 2) error stop 'tList%len'
|
2023-06-04 10:52:25 +05:30
|
|
|
if (dNeq(l%get_asReal(1),1.0_pREAL)) error stop 'tList_get_asReal'
|
2023-06-04 10:47:38 +05:30
|
|
|
if (l%get_asInt(1) /= 1) error stop 'tList_get_asInt'
|
|
|
|
if (l%get_asStr(2) /= '2') error stop 'tList_get_asStr'
|
|
|
|
if (any(l%as1dInt() /= [1,2])) error stop 'tList_as1dInt'
|
2023-06-04 10:52:25 +05:30
|
|
|
if (any(dNeq(l%as1dReal(),real([1.0,2.0],pREAL)))) error stop 'tList_as1dReal'
|
2022-10-25 21:39:36 +05:30
|
|
|
s1 = 'true'
|
|
|
|
s2 = 'false'
|
2023-06-04 10:47:38 +05:30
|
|
|
if (any(l%as1dBool() .neqv. [.true.,.false.])) error stop 'tList_as1dBool'
|
|
|
|
if (any(l%as1dStr() /= ['true ','false'])) error stop 'tList_as1dStr'
|
|
|
|
if (l%asFormattedStr() /= '[true, false]') error stop 'tList_asFormattedStr'
|
2022-11-25 13:25:31 +05:30
|
|
|
if ( .not. l%contains('true') &
|
2023-06-04 10:47:38 +05:30
|
|
|
.or. .not. l%contains('false')) error stop 'tList_contains'
|
2022-10-25 21:39:36 +05:30
|
|
|
|
|
|
|
end block list
|
|
|
|
|
|
|
|
dict: block
|
2022-12-05 18:15:08 +05:30
|
|
|
type(tDict), pointer :: d, d_pointer
|
2022-10-25 21:39:36 +05:30
|
|
|
type(tList), pointer :: l
|
|
|
|
type(tScalar), pointer :: s1,s2,s3,s4
|
|
|
|
|
2022-12-05 18:15:08 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
allocate(s1)
|
|
|
|
allocate(s2)
|
|
|
|
s1 = '1'
|
|
|
|
s2 = '2'
|
|
|
|
allocate(l)
|
|
|
|
call l%append(s1)
|
|
|
|
call l%append(s2)
|
|
|
|
|
|
|
|
allocate(s3)
|
|
|
|
allocate(s4)
|
|
|
|
s3 = '3'
|
|
|
|
s4 = '4'
|
|
|
|
allocate(d)
|
2022-12-05 18:15:08 +05:30
|
|
|
d_pointer => d%asDict()
|
2023-06-04 10:47:38 +05:30
|
|
|
if (d%contains('one-two')) error stop 'empty tDict_contains'
|
|
|
|
if (d_pointer%contains('one-two')) error stop 'empty tDict_contains(pointer)'
|
|
|
|
if (d%get_asInt('one-two',defaultVal=-1) /= -1) error stop 'empty tDict_get'
|
2022-10-25 21:39:36 +05:30
|
|
|
call d%set('one-two',l)
|
|
|
|
call d%set('three',s3)
|
|
|
|
call d%set('four',s4)
|
2023-06-04 10:47:38 +05:30
|
|
|
if (d%asFormattedStr() /= '{one-two: [1, 2], three: 3, four: 4}') &
|
|
|
|
error stop 'tDict_asFormattedStr'
|
|
|
|
if (d%get_asInt('three') /= 3) error stop 'tDict_get_asInt'
|
2023-06-04 10:52:25 +05:30
|
|
|
if (dNeq(d%get_asReal('three'),3.0_pREAL)) error stop 'tDict_get_asReal'
|
2023-06-04 10:47:38 +05:30
|
|
|
if (d%get_asStr('three') /= '3') error stop 'tDict_get_asStr'
|
|
|
|
if (any(d%get_as1dInt('one-two') /= [1,2])) error stop 'tDict_get_as1dInt'
|
2022-11-25 13:25:31 +05:30
|
|
|
call d%set('one-two',s4)
|
2023-06-04 10:47:38 +05:30
|
|
|
if (d%asFormattedStr() /= '{one-two: 4, three: 3, four: 4}') &
|
|
|
|
error stop 'tDict_set overwrite'
|
2022-11-25 13:25:31 +05:30
|
|
|
if ( .not. d%contains('one-two') &
|
|
|
|
.or. .not. d%contains('three') &
|
|
|
|
.or. .not. d%contains('four') &
|
2023-06-04 10:47:38 +05:30
|
|
|
) error stop 'tDict_contains'
|
2022-10-25 21:39:36 +05:30
|
|
|
|
|
|
|
end block dict
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2020-05-16 20:35:03 +05:30
|
|
|
end subroutine selfTest
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!---------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Init from string.
|
2020-04-22 16:22:47 +05:30
|
|
|
!---------------------------------------------------------------------------------------------------
|
|
|
|
type(tScalar) pure function tScalar_init__(value)
|
|
|
|
|
|
|
|
character(len=*), intent(in) :: value
|
|
|
|
|
2022-12-05 18:15:08 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
tScalar_init__%value = value
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
end function tScalar_init__
|
|
|
|
|
|
|
|
|
|
|
|
!---------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Set value from string.
|
2020-04-22 16:22:47 +05:30
|
|
|
!---------------------------------------------------------------------------------------------------
|
|
|
|
elemental pure subroutine tScalar_assign__(self,value)
|
|
|
|
|
|
|
|
type(tScalar), intent(out) :: self
|
|
|
|
character(len=*), intent(in) :: value
|
|
|
|
|
2022-12-05 18:15:08 +05:30
|
|
|
|
2020-04-22 16:22:47 +05:30
|
|
|
self%value = value
|
|
|
|
|
|
|
|
end subroutine tScalar_assign__
|
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Format as string (YAML flow style).
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-04 10:47:38 +05:30
|
|
|
recursive function tScalar_asFormattedStr(self) result(str)
|
2022-10-25 21:39:36 +05:30
|
|
|
|
|
|
|
class (tScalar), intent(in), target :: self
|
|
|
|
character(len=:), allocatable :: str
|
|
|
|
|
|
|
|
|
|
|
|
str = trim(self%value)
|
|
|
|
|
2023-06-04 10:47:38 +05:30
|
|
|
end function tScalar_asFormattedStr
|
2022-10-25 21:39:36 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
!> @brief Type guard, guarantee scalar.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
function tNode_asScalar(self) result(scalar)
|
|
|
|
|
2021-04-03 20:14:38 +05:30
|
|
|
class(tNode), intent(in), target :: self
|
|
|
|
class(tScalar), pointer :: scalar
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2020-04-22 16:22:47 +05:30
|
|
|
select type(self)
|
|
|
|
class is(tScalar)
|
|
|
|
scalar => self
|
2022-01-22 05:04:42 +05:30
|
|
|
class default
|
|
|
|
nullify(scalar)
|
2023-06-04 10:47:38 +05:30
|
|
|
call IO_error(706,'"'//trim(self%asFormattedStr())//'" is not a scalar')
|
2020-04-22 16:22:47 +05:30
|
|
|
end select
|
|
|
|
|
|
|
|
end function tNode_asScalar
|
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Type guard, guarantee list.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
function tNode_asList(self) result(list)
|
|
|
|
|
2021-04-03 20:14:38 +05:30
|
|
|
class(tNode), intent(in), target :: self
|
|
|
|
class(tList), pointer :: list
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2020-04-22 16:22:47 +05:30
|
|
|
select type(self)
|
|
|
|
class is(tList)
|
|
|
|
list => self
|
2022-01-22 05:04:42 +05:30
|
|
|
class default
|
|
|
|
nullify(list)
|
2023-06-04 10:47:38 +05:30
|
|
|
call IO_error(706,'"'//trim(self%asFormattedStr())//'" is not a list')
|
2020-04-22 16:22:47 +05:30
|
|
|
end select
|
|
|
|
|
|
|
|
end function tNode_asList
|
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Type guard, guarantee dict.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
function tNode_asDict(self) result(dict)
|
|
|
|
|
2021-04-03 20:14:38 +05:30
|
|
|
class(tNode), intent(in), target :: self
|
|
|
|
class(tDict), pointer :: dict
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2020-04-22 16:22:47 +05:30
|
|
|
select type(self)
|
|
|
|
class is(tDict)
|
|
|
|
dict => self
|
2022-01-22 05:04:42 +05:30
|
|
|
class default
|
|
|
|
nullify(dict)
|
2023-06-04 10:47:38 +05:30
|
|
|
call IO_error(706,'"'//trim(self%asFormattedStr())//'" is not a dict')
|
2020-04-22 16:22:47 +05:30
|
|
|
end select
|
|
|
|
|
|
|
|
end function tNode_asDict
|
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-03 20:36:32 +05:30
|
|
|
!> @brief Convert to real.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-03 20:36:32 +05:30
|
|
|
function tScalar_asReal(self)
|
2021-03-02 23:11:26 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tScalar), intent(in), target :: self
|
2023-06-04 10:52:25 +05:30
|
|
|
real(pREAL) :: tScalar_asReal
|
2021-02-27 23:44:53 +05:30
|
|
|
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2023-06-04 10:47:38 +05:30
|
|
|
tScalar_asReal = IO_strAsReal(self%value)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2023-06-03 20:36:32 +05:30
|
|
|
end function tScalar_asReal
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Convert to int.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tScalar_asInt(self)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tScalar), intent(in), target :: self
|
|
|
|
integer :: tScalar_asInt
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2023-06-04 10:47:38 +05:30
|
|
|
tScalar_asInt = IO_strAsInt(self%value)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tScalar_asInt
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Convert to bool.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tScalar_asBool(self)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tScalar), intent(in), target :: self
|
|
|
|
logical :: tScalar_asBool
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2023-06-04 10:47:38 +05:30
|
|
|
tScalar_asBool = IO_strAsBool(self%value)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tScalar_asBool
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Convert to string.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-04 10:47:38 +05:30
|
|
|
function tScalar_asStr(self)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tScalar), intent(in), target :: self
|
2023-06-04 10:47:38 +05:30
|
|
|
character(len=:), allocatable :: tScalar_asStr
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2023-06-04 10:47:38 +05:30
|
|
|
tScalar_asStr = self%value
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2023-06-04 10:47:38 +05:30
|
|
|
end function tScalar_asStr
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Format as string (YAML flow style).
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-04 10:47:38 +05:30
|
|
|
recursive function tList_asFormattedStr(self) result(str)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList),intent(in),target :: self
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
type(tItem), pointer :: item
|
|
|
|
character(len=:), allocatable :: str
|
|
|
|
integer :: i
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
str = '['
|
|
|
|
item => self%first
|
2022-11-25 13:25:31 +05:30
|
|
|
do i = 2, self%length
|
2023-06-04 10:47:38 +05:30
|
|
|
str = str//item%node%asFormattedStr()//', '
|
2022-10-25 21:39:36 +05:30
|
|
|
item => item%next
|
|
|
|
end do
|
2023-06-04 10:47:38 +05:30
|
|
|
str = str//item%node%asFormattedStr()//']'
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2023-06-04 10:47:38 +05:30
|
|
|
end function tList_asFormattedStr
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Append element.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
subroutine tList_append(self,node)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), intent(inout) :: self
|
|
|
|
class(tNode), intent(in), target :: node
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
type(tItem), pointer :: item
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
if (.not. associated(self%first)) then
|
|
|
|
allocate(item)
|
|
|
|
self%first => item
|
|
|
|
self%last => item
|
|
|
|
else
|
|
|
|
allocate(self%last%next)
|
|
|
|
item => self%last%next
|
|
|
|
self%last => item
|
|
|
|
end if
|
|
|
|
|
|
|
|
item%node => node
|
|
|
|
self%length = self%length + 1
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end subroutine tList_append
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-03 20:36:32 +05:30
|
|
|
!> @brief Convert to real array (1D).
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-03 20:36:32 +05:30
|
|
|
function tList_as1dReal(self)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), intent(in), target :: self
|
2023-06-04 10:52:25 +05:30
|
|
|
real(pREAL), dimension(:), allocatable :: tList_as1dReal
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
integer :: i
|
|
|
|
type(tItem), pointer :: item
|
|
|
|
type(tScalar), pointer :: scalar
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2023-06-03 20:36:32 +05:30
|
|
|
allocate(tList_as1dReal(self%length))
|
2022-10-25 21:39:36 +05:30
|
|
|
item => self%first
|
|
|
|
do i = 1, self%length
|
|
|
|
scalar => item%node%asScalar()
|
2023-06-03 20:36:32 +05:30
|
|
|
tList_as1dReal(i) = scalar%asReal()
|
2022-10-25 21:39:36 +05:30
|
|
|
item => item%next
|
|
|
|
end do
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2023-06-03 20:36:32 +05:30
|
|
|
end function tList_as1dReal
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-03 20:36:32 +05:30
|
|
|
!> @brief Convert to real array (2D).
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-03 20:36:32 +05:30
|
|
|
function tList_as2dReal(self)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), intent(in), target :: self
|
2023-06-04 10:52:25 +05:30
|
|
|
real(pREAL), dimension(:,:), allocatable :: tList_as2dReal
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
integer :: i
|
|
|
|
type(tList), pointer :: row_data
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
row_data => self%get_list(1)
|
2023-06-03 20:36:32 +05:30
|
|
|
allocate(tList_as2dReal(self%length,row_data%length))
|
2022-10-25 21:39:36 +05:30
|
|
|
|
2022-11-25 13:25:31 +05:30
|
|
|
do i = 1, self%length
|
2022-10-25 21:39:36 +05:30
|
|
|
row_data => self%get_list(i)
|
2023-06-03 20:36:32 +05:30
|
|
|
if (row_data%length /= size(tList_as2dReal,2)) call IO_error(709,ext_msg='inconsistent column count in tList_as2dReal')
|
|
|
|
tList_as2dReal(i,:) = self%get_as1dReal(i)
|
2022-10-25 21:39:36 +05:30
|
|
|
end do
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2023-06-03 20:36:32 +05:30
|
|
|
end function tList_as2dReal
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Convert to int array (1D).
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tList_as1dInt(self)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), intent(in), target :: self
|
|
|
|
integer, dimension(:), allocatable :: tList_as1dInt
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
integer :: i
|
|
|
|
type(tItem), pointer :: item
|
|
|
|
type(tScalar), pointer :: scalar
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
allocate(tList_as1dInt(self%length))
|
|
|
|
item => self%first
|
|
|
|
do i = 1, self%length
|
|
|
|
scalar => item%node%asScalar()
|
|
|
|
tList_as1dInt(i) = scalar%asInt()
|
|
|
|
item => item%next
|
|
|
|
end do
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tList_as1dInt
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
2020-10-24 20:56:24 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Convert to bool array (1D).
|
2020-10-24 20:56:24 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tList_as1dBool(self)
|
2020-06-16 19:27:16 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), intent(in), target :: self
|
|
|
|
logical, dimension(:), allocatable :: tList_as1dBool
|
2020-06-16 19:27:16 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
integer :: i
|
|
|
|
type(tItem), pointer :: item
|
|
|
|
type(tScalar), pointer :: scalar
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2021-03-31 20:25:25 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
allocate(tList_as1dBool(self%length))
|
|
|
|
item => self%first
|
|
|
|
do i = 1, self%length
|
|
|
|
scalar => item%node%asScalar()
|
|
|
|
tList_as1dBool(i) = scalar%asBool()
|
|
|
|
item => item%next
|
|
|
|
end do
|
2020-06-16 19:27:16 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tList_as1dBool
|
2020-06-16 19:27:16 +05:30
|
|
|
|
|
|
|
|
2022-01-21 05:15:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Convert to string array (1D).
|
2022-01-21 05:15:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-04 10:47:38 +05:30
|
|
|
function tList_as1dStr(self)
|
2022-01-21 05:15:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), intent(in), target :: self
|
2022-12-05 18:15:08 +05:30
|
|
|
#ifdef __GFORTRAN__
|
2023-06-04 10:47:38 +05:30
|
|
|
character(len=pSTRLEN), allocatable, dimension(:) :: tList_as1dStr
|
2022-12-05 18:15:08 +05:30
|
|
|
#else
|
2023-06-04 10:47:38 +05:30
|
|
|
character(len=:), allocatable, dimension(:) :: tList_as1dStr
|
2022-10-25 21:39:36 +05:30
|
|
|
#endif
|
2022-01-21 05:15:47 +05:30
|
|
|
|
2022-12-05 18:15:08 +05:30
|
|
|
integer :: j
|
2022-10-25 21:39:36 +05:30
|
|
|
type(tItem), pointer :: item
|
|
|
|
type(tScalar), pointer :: scalar
|
2022-01-21 05:15:47 +05:30
|
|
|
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2022-12-05 18:15:08 +05:30
|
|
|
#ifdef __GFORTRAN__
|
2023-06-04 10:47:38 +05:30
|
|
|
allocate(tList_as1dStr(self%length))
|
2022-12-05 18:15:08 +05:30
|
|
|
#else
|
|
|
|
integer :: len_max
|
2022-10-25 21:39:36 +05:30
|
|
|
len_max = 0
|
|
|
|
item => self%first
|
2022-01-21 05:15:47 +05:30
|
|
|
do j = 1, self%length
|
2022-10-25 21:39:36 +05:30
|
|
|
scalar => item%node%asScalar()
|
2023-06-04 10:47:38 +05:30
|
|
|
len_max = max(len_max, len_trim(scalar%asStr()))
|
2022-10-25 21:39:36 +05:30
|
|
|
item => item%next
|
2022-01-21 05:15:47 +05:30
|
|
|
end do
|
|
|
|
|
2023-06-04 10:47:38 +05:30
|
|
|
allocate(character(len=len_max) :: tList_as1dStr(self%length))
|
2022-10-25 21:39:36 +05:30
|
|
|
#endif
|
|
|
|
item => self%first
|
2022-01-21 05:15:47 +05:30
|
|
|
do j = 1, self%length
|
2022-10-25 21:39:36 +05:30
|
|
|
scalar => item%node%asScalar()
|
2023-06-04 10:47:38 +05:30
|
|
|
tList_as1dStr(j) = scalar%asStr()
|
2022-10-25 21:39:36 +05:30
|
|
|
item => item%next
|
2022-01-21 05:15:47 +05:30
|
|
|
end do
|
|
|
|
|
2023-06-04 10:47:38 +05:30
|
|
|
end function tList_as1dStr
|
2022-01-21 05:15:47 +05:30
|
|
|
|
|
|
|
|
2020-06-16 19:27:16 +05:30
|
|
|
!-------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Check for existence of (string) value.
|
2020-06-16 19:27:16 +05:30
|
|
|
!-------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tList_contains(self,k) result(exists)
|
2020-06-16 19:27:16 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), intent(in), target :: self
|
2020-06-16 19:27:16 +05:30
|
|
|
character(len=*), intent(in) :: k
|
|
|
|
logical :: exists
|
2022-10-25 21:39:36 +05:30
|
|
|
|
|
|
|
integer :: j
|
|
|
|
type(tItem), pointer :: item
|
|
|
|
type(tScalar), pointer :: scalar
|
|
|
|
|
2020-06-16 19:27:16 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
item => self%first
|
2022-11-25 13:25:31 +05:30
|
|
|
exists = .false.
|
|
|
|
j = 1
|
|
|
|
do while (j <= self%length .and. .not. exists)
|
2022-10-25 21:39:36 +05:30
|
|
|
scalar => item%node%asScalar()
|
2022-11-25 13:25:31 +05:30
|
|
|
exists = scalar%value == k
|
2022-10-25 21:39:36 +05:30
|
|
|
item => item%next
|
2022-11-25 13:25:31 +05:30
|
|
|
j = j + 1
|
2022-10-25 21:39:36 +05:30
|
|
|
end do
|
2020-06-16 19:27:16 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tList_contains
|
2020-06-16 19:27:16 +05:30
|
|
|
|
|
|
|
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Get by index.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tList_get(self,i) result(node)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), intent(in), target :: self
|
|
|
|
integer, intent(in) :: i
|
2022-10-28 00:54:36 +05:30
|
|
|
class(tNode), pointer :: node
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-28 00:54:36 +05:30
|
|
|
class(tItem), pointer :: item
|
2020-04-22 16:22:47 +05:30
|
|
|
integer :: j
|
|
|
|
|
|
|
|
|
2023-06-04 10:47:38 +05:30
|
|
|
if (i < 1 .or. i > self%length) call IO_error(150,ext_msg='tList_get @ '//IO_intAsStr(i) &
|
|
|
|
//' of '//IO_intAsStr(self%length) )
|
2022-10-25 21:39:36 +05:30
|
|
|
item => self%first
|
2022-11-25 13:25:31 +05:30
|
|
|
do j = 2, i
|
2020-04-22 16:22:47 +05:30
|
|
|
item => item%next
|
2022-06-09 02:36:01 +05:30
|
|
|
end do
|
2022-10-25 21:39:36 +05:30
|
|
|
node => item%node
|
2021-02-27 23:44:53 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tList_get
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Get scalar by index.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tList_get_scalar(self,i) result(nodeAsScalar)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), intent(in) :: self
|
|
|
|
integer, intent(in) :: i
|
|
|
|
type(tScalar), pointer :: nodeAsScalar
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tNode), pointer :: node
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
node => self%get(i)
|
|
|
|
nodeAsScalar => node%asScalar()
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tList_get_scalar
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Get list by index.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tList_get_list(self,i) result(nodeAsList)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), intent(in) :: self
|
|
|
|
integer, intent(in) :: i
|
|
|
|
type(tList), pointer :: nodeAsList
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tNode), pointer :: node
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
node => self%get(i)
|
|
|
|
nodeAsList => node%asList()
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tList_get_list
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Get dict by index.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tList_get_dict(self,i) result(nodeAsDict)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), intent(in) :: self
|
|
|
|
integer, intent(in) :: i
|
|
|
|
type(tDict), pointer :: nodeAsDict
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tNode), pointer :: node
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
node => self%get(i)
|
|
|
|
nodeAsDict => node%asDict()
|
2020-06-16 19:27:16 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tList_get_dict
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-03 20:36:32 +05:30
|
|
|
!> @brief Get scalar by index and convert to real.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-03 20:36:32 +05:30
|
|
|
function tList_get_asReal(self,i) result(nodeAsReal)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), intent(in) :: self
|
|
|
|
integer, intent(in) :: i
|
2023-06-04 10:52:25 +05:30
|
|
|
real(pREAL) :: nodeAsReal
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tScalar), pointer :: scalar
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
scalar => self%get_scalar(i)
|
2023-06-03 20:36:32 +05:30
|
|
|
nodeAsReal = scalar%asReal()
|
2020-06-16 19:27:16 +05:30
|
|
|
|
2023-06-03 20:36:32 +05:30
|
|
|
end function tList_get_asReal
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-03 20:36:32 +05:30
|
|
|
!> @brief Get list by index and convert to real array (1D).
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-03 20:36:32 +05:30
|
|
|
function tList_get_as1dReal(self,i) result(nodeAs1dReal)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), intent(in) :: self
|
|
|
|
integer, intent(in) :: i
|
2023-06-04 10:52:25 +05:30
|
|
|
real(pREAL), dimension(:), allocatable :: nodeAs1dReal
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), pointer :: list
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2020-08-15 19:32:10 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
list => self%get_list(i)
|
2023-06-03 20:36:32 +05:30
|
|
|
nodeAs1dReal = list%as1dReal()
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2023-06-03 20:36:32 +05:30
|
|
|
end function tList_get_as1dReal
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Get scalar by index and convert to int.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tList_get_asInt(self,i) result(nodeAsInt)
|
2021-03-01 23:33:50 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), intent(in) :: self
|
|
|
|
integer, intent(in) :: i
|
|
|
|
integer :: nodeAsInt
|
2021-03-01 23:33:50 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tScalar), pointer :: scalar
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2021-03-01 23:33:50 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
scalar => self%get_scalar(i)
|
|
|
|
nodeAsInt = scalar%asInt()
|
2021-07-24 17:57:00 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tList_get_asInt
|
2021-03-01 23:33:50 +05:30
|
|
|
|
|
|
|
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Get list by index and convert to int array (1D).
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tList_get_as1dInt(self,i) result(nodeAs1dInt)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), intent(in) :: self
|
|
|
|
integer, intent(in) :: i
|
2021-03-11 22:30:07 +05:30
|
|
|
integer, dimension(:), allocatable :: nodeAs1dInt
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), pointer :: list
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2020-08-15 19:32:10 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
list => self%get_list(i)
|
|
|
|
nodeAs1dInt = list%as1dInt()
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tList_get_as1dInt
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Get scalar by index and convert to bool
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tList_get_asBool(self,i) result(nodeAsBool)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), intent(in) :: self
|
|
|
|
integer, intent(in) :: i
|
|
|
|
logical :: nodeAsBool
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tScalar), pointer :: scalar
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
scalar => self%get_scalar(i)
|
|
|
|
nodeAsBool = scalar%asBool()
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tList_get_asBool
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Get list by index and convert to bool array (1D).
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tList_get_as1dBool(self,i) result(nodeAs1dBool)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), intent(in) :: self
|
|
|
|
integer, intent(in) :: i
|
|
|
|
logical, dimension(:), allocatable :: nodeAs1dBool
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), pointer :: list
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
list => self%get_list(i)
|
|
|
|
nodeAs1dBool = list%as1dBool()
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tList_get_as1dBool
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
2020-08-15 19:32:10 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Get scalar by index and convert to string.
|
2020-08-15 19:32:10 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-04 10:47:38 +05:30
|
|
|
function tList_get_asStr(self,i) result(nodeAsStr)
|
2020-08-15 19:32:10 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), intent(in) :: self
|
|
|
|
integer, intent(in) :: i
|
2023-06-04 10:47:38 +05:30
|
|
|
character(len=:), allocatable :: nodeAsStr
|
2020-08-15 19:32:10 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tScalar), pointer :: scalar
|
2020-08-15 19:32:10 +05:30
|
|
|
|
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
scalar => self%get_scalar(i)
|
2023-06-04 10:47:38 +05:30
|
|
|
nodeAsStr = scalar%asStr()
|
2022-10-25 21:39:36 +05:30
|
|
|
|
2023-06-04 10:47:38 +05:30
|
|
|
end function tList_get_asStr
|
2021-02-27 23:44:53 +05:30
|
|
|
|
2020-08-15 19:32:10 +05:30
|
|
|
|
2020-05-08 02:40:27 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Get list by index and convert to string array (1D).
|
2020-05-08 02:40:27 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-04 10:47:38 +05:30
|
|
|
function tList_get_as1dStr(self,i) result(nodeAs1dStr)
|
2020-05-01 00:59:59 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), intent(in) :: self
|
|
|
|
integer, intent(in) :: i
|
2023-06-04 10:47:38 +05:30
|
|
|
character(len=:), allocatable, dimension(:) :: nodeAs1dStr
|
2020-05-01 00:59:59 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
type(tList), pointer :: list
|
2020-05-01 00:59:59 +05:30
|
|
|
|
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
list => self%get_list(i)
|
2023-06-04 10:47:38 +05:30
|
|
|
nodeAs1dStr = list%as1dStr()
|
2021-02-27 23:44:53 +05:30
|
|
|
|
2023-06-04 10:47:38 +05:30
|
|
|
end function tList_get_as1dStr
|
2020-05-01 00:59:59 +05:30
|
|
|
|
|
|
|
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Free associated memory.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
recursive subroutine tList_finalize(self)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
type (tList),intent(inout) :: self
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
deallocate(self%first)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end subroutine tList_finalize
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Format as string (YAML flow style).
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-04 10:47:38 +05:30
|
|
|
recursive function tDict_asFormattedStr(self) result(str)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tDict),intent(in),target :: self
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
type(tItem),pointer :: item
|
2020-05-03 02:33:11 +05:30
|
|
|
character(len=:), allocatable :: str
|
2022-10-25 21:39:36 +05:30
|
|
|
integer :: i
|
2020-05-08 02:40:27 +05:30
|
|
|
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
str = '{'
|
2020-04-22 16:22:47 +05:30
|
|
|
item => self%first
|
2022-11-25 13:25:31 +05:30
|
|
|
do i = 2, self%length
|
2023-06-04 10:47:38 +05:30
|
|
|
str = str//trim(item%key)//': '//item%node%asFormattedStr()//', '
|
2020-04-22 16:22:47 +05:30
|
|
|
item => item%next
|
2022-01-22 05:04:42 +05:30
|
|
|
end do
|
2023-06-04 10:47:38 +05:30
|
|
|
str = str//trim(item%key)//': '//item%node%asFormattedStr()//'}'
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2023-06-04 10:47:38 +05:30
|
|
|
end function tDict_asFormattedStr
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Set value (either replace or add new).
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
subroutine tDict_set(self,key,node)
|
|
|
|
|
|
|
|
class (tDict), intent(inout) :: self
|
|
|
|
character(len=*), intent(in) :: key
|
|
|
|
class(tNode), intent(in), target :: node
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
type(tItem), pointer :: item
|
2020-05-08 02:40:27 +05:30
|
|
|
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
if (.not. associated(self%first)) then
|
|
|
|
allocate(self%first)
|
|
|
|
item => self%first
|
|
|
|
self%length = 1
|
2020-04-22 16:22:47 +05:30
|
|
|
else
|
2022-10-25 21:39:36 +05:30
|
|
|
item => self%first
|
2022-11-25 13:25:31 +05:30
|
|
|
searchExisting: do while (associated(item%next) .and. item%key /= key)
|
2022-10-25 21:39:36 +05:30
|
|
|
item => item%next
|
|
|
|
end do searchExisting
|
|
|
|
if (item%key /= key) then
|
|
|
|
allocate(item%next)
|
|
|
|
item => item%next
|
|
|
|
self%length = self%length + 1
|
|
|
|
end if
|
2021-12-06 12:27:31 +05:30
|
|
|
end if
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
item%key = key
|
|
|
|
item%node => node
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end subroutine tDict_set
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Return the index of a key.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tDict_index(self,key) result(keyIndex)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tDict), intent(in), target :: self
|
|
|
|
character(len=*), intent(in) :: key
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
integer :: keyIndex
|
|
|
|
type(tItem), pointer :: item
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
item => self%first
|
|
|
|
keyIndex = 1
|
|
|
|
do while (associated(item%next) .and. item%key /= key)
|
|
|
|
item => item%next
|
|
|
|
keyIndex = keyIndex+1
|
|
|
|
end do
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
if (item%key /= key) call IO_error(140,ext_msg=key)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tDict_index
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Get key of given index.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tDict_key(self,i) result(key)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tDict), intent(in), target :: self
|
|
|
|
integer, intent(in) :: i
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
character(len=:), allocatable :: key
|
|
|
|
integer :: j
|
|
|
|
type(tItem), pointer :: item
|
|
|
|
|
|
|
|
|
2023-06-04 10:47:38 +05:30
|
|
|
if (i < 1 .or. i > self%length) call IO_error(150,ext_msg='tDict_key @ '//IO_intAsStr(i) &
|
|
|
|
//' of '//IO_intAsStr(self%length) )
|
2022-10-25 21:39:36 +05:30
|
|
|
item => self%first
|
2022-11-25 13:25:31 +05:30
|
|
|
do j = 2, i
|
2022-10-25 21:39:36 +05:30
|
|
|
item => item%next
|
|
|
|
end do
|
|
|
|
|
|
|
|
key = item%key
|
|
|
|
|
|
|
|
end function tDict_key
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Get all keys.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tDict_keys(self) result(keys)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tDict), intent(in) :: self
|
|
|
|
character(len=:), dimension(:), allocatable :: keys
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2023-06-04 10:47:38 +05:30
|
|
|
character(len=pSTRLEN), dimension(:), allocatable :: temp
|
2022-10-25 21:39:36 +05:30
|
|
|
integer :: j, l
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
|
|
|
|
allocate(temp(self%length))
|
|
|
|
l = 0
|
|
|
|
do j = 1, self%length
|
|
|
|
temp(j) = self%key(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 tDict_keys
|
|
|
|
|
|
|
|
|
|
|
|
!-------------------------------------------------------------------------------------------------
|
|
|
|
!> @brief Check whether a given key is present.
|
|
|
|
!-------------------------------------------------------------------------------------------------
|
|
|
|
function tDict_contains(self,k) result(exists)
|
|
|
|
|
|
|
|
class(tDict), intent(in), target :: self
|
|
|
|
character(len=*), intent(in) :: k
|
|
|
|
logical :: exists
|
|
|
|
|
|
|
|
integer :: j
|
|
|
|
|
|
|
|
|
|
|
|
exists = .false.
|
2022-11-25 13:25:31 +05:30
|
|
|
j = 1
|
|
|
|
do while(j <= self%length .and. .not. exists)
|
|
|
|
exists = self%key(j) == k
|
|
|
|
j = j + 1
|
2022-10-25 21:39:36 +05:30
|
|
|
end do
|
|
|
|
|
|
|
|
end function tDict_contains
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Get by key.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tDict_get(self,k,defaultVal) result(node)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tDict), intent(in), target :: self
|
|
|
|
character(len=*), intent(in) :: k
|
|
|
|
class(tNode), intent(in),optional,target :: defaultVal
|
|
|
|
class(tNode), pointer :: node
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
type(tItem), pointer :: item
|
|
|
|
integer :: j
|
|
|
|
|
2020-04-22 16:22:47 +05:30
|
|
|
item => self%first
|
2022-11-25 13:25:31 +05:30
|
|
|
|
|
|
|
do j=1, self%length
|
2022-10-25 21:39:36 +05:30
|
|
|
if (item%key == k) then
|
2022-11-25 13:25:31 +05:30
|
|
|
node => item%node
|
|
|
|
return
|
2022-10-25 21:39:36 +05:30
|
|
|
end if
|
2020-04-22 16:22:47 +05:30
|
|
|
item => item%next
|
2022-01-22 05:04:42 +05:30
|
|
|
end do
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-11-25 13:25:31 +05:30
|
|
|
if (present(defaultVal)) then
|
|
|
|
node => defaultVal
|
2022-10-25 21:39:36 +05:30
|
|
|
else
|
2022-11-25 13:25:31 +05:30
|
|
|
call IO_error(143,ext_msg=k)
|
2022-10-25 21:39:36 +05:30
|
|
|
end if
|
|
|
|
|
|
|
|
end function tDict_get
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
2021-03-02 20:44:33 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Get scalar by key.
|
2021-03-02 20:44:33 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tDict_get_scalar(self,k,defaultVal) result(nodeAsScalar)
|
2021-03-02 20:44:33 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tDict), intent(in) :: self
|
|
|
|
character(len=*), intent(in) :: k
|
|
|
|
type(tScalar), intent(in), optional, target :: defaultVal
|
|
|
|
type(tScalar), pointer :: nodeAsScalar
|
2021-03-02 20:44:33 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tNode), pointer :: node
|
2021-03-02 20:44:33 +05:30
|
|
|
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
node => self%get(k,defaultVal)
|
|
|
|
nodeAsScalar => node%asScalar()
|
2021-03-02 20:44:33 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tDict_get_scalar
|
2021-03-02 20:44:33 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
!> @brief Get list by key.
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
function tDict_get_list(self,k,defaultVal) result(nodeAsList)
|
|
|
|
|
|
|
|
class(tDict), intent(in) :: self
|
|
|
|
character(len=*), intent(in) :: k
|
|
|
|
type(tList), intent(in), optional, target :: defaultVal
|
|
|
|
type(tList), pointer :: nodeAsList
|
|
|
|
|
|
|
|
class(tNode), pointer :: node
|
|
|
|
|
|
|
|
|
|
|
|
node => self%get(k,defaultVal)
|
|
|
|
nodeAsList => node%asList()
|
|
|
|
|
|
|
|
end function tDict_get_list
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Get dict by key.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tDict_get_dict(self,k,defaultVal) result(nodeAsDict)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tDict), intent(in) :: self
|
|
|
|
character(len=*), intent(in) :: k
|
|
|
|
type(tDict), intent(in), optional, target :: defaultVal
|
|
|
|
type(tDict), pointer :: nodeAsDict
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tNode), pointer :: node
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
node => self%get(k,defaultVal)
|
|
|
|
nodeAsDict => node%asDict()
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tDict_get_dict
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-03 20:36:32 +05:30
|
|
|
!> @brief Get scalar by key and convert to real.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-03 20:36:32 +05:30
|
|
|
function tDict_get_asReal(self,k,defaultVal) result(nodeAsReal)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tDict), intent(in) :: self
|
|
|
|
character(len=*), intent(in) :: k
|
2023-06-04 10:52:25 +05:30
|
|
|
real(pREAL), intent(in), optional :: defaultVal
|
|
|
|
real(pREAL) :: nodeAsReal
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
type(tScalar), pointer :: scalar
|
|
|
|
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
if (self%contains(k)) then
|
|
|
|
scalar => self%get_scalar(k)
|
2023-06-03 20:36:32 +05:30
|
|
|
nodeAsReal = scalar%asReal()
|
2022-10-25 21:39:36 +05:30
|
|
|
elseif (present(defaultVal)) then
|
2023-06-03 20:36:32 +05:30
|
|
|
nodeAsReal = defaultVal
|
2022-10-25 21:39:36 +05:30
|
|
|
else
|
|
|
|
call IO_error(143,ext_msg=k)
|
|
|
|
end if
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2023-06-03 20:36:32 +05:30
|
|
|
end function tDict_get_asReal
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-03 20:36:32 +05:30
|
|
|
!> @brief Get list by key and convert to real array (1D).
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-03 20:36:32 +05:30
|
|
|
function tDict_get_as1dReal(self,k,defaultVal,requiredSize) result(nodeAs1dReal)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tDict), intent(in) :: self
|
|
|
|
character(len=*), intent(in) :: k
|
2023-06-04 10:52:25 +05:30
|
|
|
real(pREAL), intent(in), dimension(:), optional :: defaultVal
|
2022-10-25 21:39:36 +05:30
|
|
|
integer, intent(in), optional :: requiredSize
|
2023-06-04 10:52:25 +05:30
|
|
|
real(pREAL), dimension(:), allocatable :: nodeAs1dReal
|
2022-10-25 21:39:36 +05:30
|
|
|
|
|
|
|
type(tList), pointer :: list
|
|
|
|
|
|
|
|
|
|
|
|
if (self%contains(k)) then
|
|
|
|
list => self%get_list(k)
|
2023-06-03 20:36:32 +05:30
|
|
|
nodeAs1dReal = list%as1dReal()
|
2022-10-25 21:39:36 +05:30
|
|
|
elseif (present(defaultVal)) then
|
2023-06-03 20:36:32 +05:30
|
|
|
nodeAs1dReal = defaultVal
|
2022-10-25 21:39:36 +05:30
|
|
|
else
|
|
|
|
call IO_error(143,ext_msg=k)
|
|
|
|
end if
|
|
|
|
|
|
|
|
if (present(requiredSize)) then
|
2023-06-03 20:36:32 +05:30
|
|
|
if (requiredSize /= size(nodeAs1dReal)) call IO_error(146,ext_msg=k)
|
2022-10-25 21:39:36 +05:30
|
|
|
end if
|
|
|
|
|
2023-06-03 20:36:32 +05:30
|
|
|
end function tDict_get_as1dReal
|
2022-10-25 21:39:36 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-03 20:36:32 +05:30
|
|
|
!> @brief Get list of lists by key and convert to real array (2D).
|
2022-10-25 21:39:36 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-03 20:36:32 +05:30
|
|
|
function tDict_get_as2dReal(self,k,defaultVal,requiredShape) result(nodeAs2dReal)
|
2022-10-25 21:39:36 +05:30
|
|
|
|
|
|
|
class(tDict), intent(in) :: self
|
|
|
|
character(len=*), intent(in) :: k
|
2023-06-04 10:52:25 +05:30
|
|
|
real(pREAL), intent(in), dimension(:,:), optional :: defaultVal
|
2022-10-25 21:39:36 +05:30
|
|
|
integer, intent(in), dimension(2), optional :: requiredShape
|
2023-06-04 10:52:25 +05:30
|
|
|
real(pREAL), dimension(:,:), allocatable :: nodeAs2dReal
|
2022-10-25 21:39:36 +05:30
|
|
|
|
|
|
|
type(tList), pointer :: list
|
|
|
|
|
|
|
|
|
|
|
|
if (self%contains(k)) then
|
|
|
|
list => self%get_list(k)
|
2023-06-03 20:36:32 +05:30
|
|
|
nodeAs2dReal = list%as2dReal()
|
2022-10-25 21:39:36 +05:30
|
|
|
elseif (present(defaultVal)) then
|
2023-06-03 20:36:32 +05:30
|
|
|
nodeAs2dReal = defaultVal
|
2022-10-25 21:39:36 +05:30
|
|
|
else
|
|
|
|
call IO_error(143,ext_msg=k)
|
|
|
|
end if
|
|
|
|
|
|
|
|
if (present(requiredShape)) then
|
2023-06-03 20:36:32 +05:30
|
|
|
if (any(requiredShape /= shape(nodeAs2dReal))) call IO_error(146,ext_msg=k)
|
2022-10-25 21:39:36 +05:30
|
|
|
end if
|
|
|
|
|
2023-06-03 20:36:32 +05:30
|
|
|
end function tDict_get_as2dReal
|
2022-10-25 21:39:36 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
!> @brief Get scalar by key and convert to int.
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
function tDict_get_asInt(self,k,defaultVal) result(nodeAsInt)
|
|
|
|
|
|
|
|
class(tDict), intent(in) :: self
|
|
|
|
character(len=*), intent(in) :: k
|
|
|
|
integer, intent(in), optional :: defaultVal
|
|
|
|
integer :: nodeAsInt
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
type(tScalar), pointer :: scalar
|
|
|
|
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
if (self%contains(k)) then
|
|
|
|
scalar => self%get_scalar(k)
|
|
|
|
nodeAsInt = scalar%asInt()
|
|
|
|
elseif (present(defaultVal)) then
|
|
|
|
nodeAsInt = defaultVal
|
|
|
|
else
|
|
|
|
call IO_error(143,ext_msg=k)
|
|
|
|
end if
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tDict_get_asInt
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
!> @brief Get list by key and convert to int array (1D).
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
function tDict_get_as1dInt(self,k,defaultVal,requiredSize) result(nodeAs1dInt)
|
|
|
|
|
|
|
|
class(tDict), intent(in) :: self
|
|
|
|
character(len=*), intent(in) :: k
|
|
|
|
integer, dimension(:), intent(in), optional :: defaultVal
|
|
|
|
integer, intent(in), optional :: requiredSize
|
|
|
|
integer, dimension(:), allocatable :: nodeAs1dInt
|
|
|
|
|
|
|
|
type(tList), pointer :: list
|
|
|
|
|
|
|
|
|
|
|
|
if (self%contains(k)) then
|
|
|
|
list => self%get_list(k)
|
|
|
|
nodeAs1dInt = list%as1dInt()
|
|
|
|
elseif (present(defaultVal)) then
|
|
|
|
nodeAs1dInt = defaultVal
|
|
|
|
else
|
|
|
|
call IO_error(143,ext_msg=k)
|
|
|
|
end if
|
|
|
|
|
|
|
|
if (present(requiredSize)) then
|
|
|
|
if (requiredSize /= size(nodeAs1dInt)) call IO_error(146,ext_msg=k)
|
|
|
|
end if
|
|
|
|
|
|
|
|
end function tDict_get_as1dInt
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Get scalar by key and convert to bool.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tDict_get_asBool(self,k,defaultVal) result(nodeAsBool)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tDict), intent(in) :: self
|
|
|
|
character(len=*), intent(in) :: k
|
|
|
|
logical, intent(in), optional :: defaultVal
|
|
|
|
logical :: nodeAsBool
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
type(tScalar), pointer :: scalar
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
|
|
|
|
if (self%contains(k)) then
|
|
|
|
scalar => self%get_scalar(k)
|
|
|
|
nodeAsBool = scalar%asBool()
|
|
|
|
elseif (present(defaultVal)) then
|
|
|
|
nodeAsBool = defaultVal
|
2020-04-22 16:22:47 +05:30
|
|
|
else
|
2022-10-25 21:39:36 +05:30
|
|
|
call IO_error(143,ext_msg=k)
|
2020-04-22 16:22:47 +05:30
|
|
|
end if
|
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tDict_get_asBool
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
!> @brief Get list by key and convert to bool array (1D).
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
function tDict_get_as1dBool(self,k,defaultVal) result(nodeAs1dBool)
|
|
|
|
|
|
|
|
class(tDict), intent(in) :: self
|
|
|
|
character(len=*), intent(in) :: k
|
|
|
|
logical, dimension(:), intent(in), optional :: defaultVal
|
|
|
|
logical, dimension(:), allocatable :: nodeAs1dBool
|
|
|
|
|
|
|
|
type(tList), pointer :: list
|
|
|
|
|
|
|
|
|
|
|
|
if (self%contains(k)) then
|
|
|
|
list => self%get_list(k)
|
|
|
|
nodeAs1dBool = list%as1dBool()
|
|
|
|
elseif (present(defaultVal)) then
|
|
|
|
nodeAs1dBool = defaultVal
|
|
|
|
else
|
|
|
|
call IO_error(143,ext_msg=k)
|
|
|
|
end if
|
|
|
|
|
|
|
|
end function tDict_get_as1dBool
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Get scalar by key and convert to string.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-04 10:47:38 +05:30
|
|
|
function tDict_get_asStr(self,k,defaultVal) result(nodeAsStr)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tDict), intent(in) :: self
|
|
|
|
character(len=*), intent(in) :: k
|
|
|
|
character(len=*), intent(in), optional :: defaultVal
|
2023-06-04 10:47:38 +05:30
|
|
|
character(len=:), allocatable :: nodeAsStr
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
type(tScalar), pointer :: scalar
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
|
|
|
|
if (self%contains(k)) then
|
|
|
|
scalar => self%get_scalar(k)
|
2023-06-04 10:47:38 +05:30
|
|
|
nodeAsStr = scalar%asStr()
|
2022-10-25 21:39:36 +05:30
|
|
|
elseif (present(defaultVal)) then
|
2023-06-04 10:47:38 +05:30
|
|
|
nodeAsStr = defaultVal
|
2020-04-22 16:22:47 +05:30
|
|
|
else
|
2022-10-25 21:39:36 +05:30
|
|
|
call IO_error(143,ext_msg=k)
|
2020-04-22 16:22:47 +05:30
|
|
|
end if
|
|
|
|
|
2023-06-04 10:47:38 +05:30
|
|
|
end function tDict_get_asStr
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
!> @brief Get list by key and convert to string array (1D).
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-04 10:47:38 +05:30
|
|
|
function tDict_get_as1dStr(self,k,defaultVal) result(nodeAs1dStr)
|
2022-10-25 21:39:36 +05:30
|
|
|
|
|
|
|
class(tDict), intent(in) :: self
|
|
|
|
character(len=*), intent(in) :: k
|
|
|
|
character(len=*), intent(in), dimension(:), optional :: defaultVal
|
2023-06-04 10:47:38 +05:30
|
|
|
character(len=:), allocatable, dimension(:) :: nodeAs1dStr
|
2022-10-25 21:39:36 +05:30
|
|
|
|
|
|
|
type(tList), pointer :: list
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
if (self%contains(k)) then
|
|
|
|
list => self%get_list(k)
|
2023-06-04 10:47:38 +05:30
|
|
|
nodeAs1dStr = list%as1dStr()
|
2022-10-25 21:39:36 +05:30
|
|
|
elseif (present(defaultVal)) then
|
2023-06-04 10:47:38 +05:30
|
|
|
nodeAs1dStr = defaultVal
|
2022-10-25 21:39:36 +05:30
|
|
|
else
|
|
|
|
call IO_error(143,ext_msg=k)
|
|
|
|
end if
|
|
|
|
|
2023-06-04 10:47:38 +05:30
|
|
|
end function tDict_get_as1dStr
|
2022-10-25 21:39:36 +05:30
|
|
|
|
|
|
|
|
|
|
|
#ifdef __GFORTRAN__
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Returns string output array (1D) (hack for GNU).
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-06-04 10:47:38 +05:30
|
|
|
function output_as1dStr(self) result(output)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tDict), pointer,intent(in) :: self
|
2023-06-04 10:47:38 +05:30
|
|
|
character(len=pSTRLEN), allocatable, dimension(:) :: output
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
type(tList), pointer :: output_list
|
|
|
|
integer :: o
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
output_list => self%get_list('output',defaultVal=emptyList)
|
|
|
|
allocate(output(output_list%length))
|
|
|
|
do o = 1, output_list%length
|
2023-06-04 10:47:38 +05:30
|
|
|
output(o) = output_list%get_asStr(o)
|
2022-10-25 21:39:36 +05:30
|
|
|
end do
|
|
|
|
|
2023-06-04 10:47:38 +05:30
|
|
|
end function output_as1dStr
|
2022-10-25 21:39:36 +05:30
|
|
|
#endif
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
2020-05-01 00:59:59 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Free associated memory.
|
2020-05-01 00:59:59 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
recursive subroutine tItem_finalize(self)
|
|
|
|
|
|
|
|
type(tItem),intent(inout) :: self
|
2020-05-08 02:40:27 +05:30
|
|
|
|
2020-05-01 00:59:59 +05:30
|
|
|
deallocate(self%node)
|
2021-02-27 23:44:53 +05:30
|
|
|
if (associated(self%next)) deallocate(self%next)
|
2020-05-01 00:59:59 +05:30
|
|
|
|
|
|
|
end subroutine tItem_finalize
|
|
|
|
|
2020-04-28 13:59:13 +05:30
|
|
|
end module YAML_types
|