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
|
2022-10-25 21:39:36 +05:30
|
|
|
procedure(asFormattedString), deferred :: &
|
|
|
|
asFormattedString
|
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 :: &
|
2022-10-25 21:39:36 +05:30
|
|
|
asFormattedString => tScalar_asFormattedString, &
|
|
|
|
asFloat => tScalar_asFloat, &
|
|
|
|
asInt => tScalar_asInt, &
|
|
|
|
asBool => tScalar_asBool, &
|
2020-04-22 16:22:47 +05:30
|
|
|
asString => tScalar_asString
|
|
|
|
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 :: &
|
2022-10-25 21:39:36 +05:30
|
|
|
asFormattedString => tList_asFormattedString, &
|
|
|
|
append => tList_append, &
|
|
|
|
as1dFloat => tList_as1dFloat, &
|
|
|
|
as2dFloat => tList_as2dFloat, &
|
|
|
|
as1dInt => tList_as1dInt, &
|
|
|
|
as1dBool => tList_as1dBool, &
|
|
|
|
as1dString => tList_as1dString, &
|
|
|
|
contains => tList_contains, &
|
|
|
|
tList_get, &
|
|
|
|
tList_get_scalar, &
|
|
|
|
tList_get_list, &
|
|
|
|
tList_get_dict, &
|
|
|
|
tList_get_asFloat, &
|
|
|
|
tList_get_as1dFloat, &
|
|
|
|
tList_get_asInt, &
|
|
|
|
tList_get_as1dInt, &
|
|
|
|
tList_get_asBool, &
|
|
|
|
tList_get_as1dBool, &
|
|
|
|
tList_get_asString, &
|
|
|
|
tList_get_as1dString
|
|
|
|
generic :: get => tList_get
|
|
|
|
generic :: get_scalar => tList_get_scalar
|
|
|
|
generic :: get_list => tList_get_list
|
|
|
|
generic :: get_dict => tList_get_dict
|
|
|
|
generic :: get_asFloat => tList_get_asFloat
|
|
|
|
generic :: get_as1dFloat => tList_get_as1dFloat
|
|
|
|
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_asString => tList_get_asString
|
|
|
|
generic :: get_as1dString => tList_get_as1dString
|
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 :: &
|
|
|
|
asFormattedString => tDict_asFormattedString, &
|
|
|
|
set => tDict_set, &
|
|
|
|
index => tDict_index, &
|
|
|
|
key => tDict_key, &
|
|
|
|
keys => tDict_keys, &
|
|
|
|
contains => tDict_contains, &
|
|
|
|
tDict_get, &
|
|
|
|
tDict_get_scalar, &
|
|
|
|
tDict_get_list, &
|
|
|
|
tDict_get_dict, &
|
|
|
|
tDict_get_asFloat, &
|
|
|
|
tDict_get_as1dFloat, &
|
|
|
|
tDict_get_as2dFloat, &
|
|
|
|
tDict_get_asInt, &
|
|
|
|
tDict_get_as1dInt, &
|
|
|
|
tDict_get_asBool, &
|
|
|
|
tDict_get_as1dBool, &
|
|
|
|
tDict_get_asString, &
|
|
|
|
tDict_get_as1dString
|
|
|
|
generic :: get => tDict_get
|
|
|
|
generic :: get_scalar => tDict_get_scalar
|
|
|
|
generic :: get_list => tDict_get_list
|
|
|
|
generic :: get_dict => tDict_get_dict
|
|
|
|
generic :: get_asFloat => tDict_get_asFloat
|
|
|
|
generic :: get_as1dFloat => tDict_get_as1dFloat
|
|
|
|
generic :: get_as2dFloat => tDict_get_as2dFloat
|
|
|
|
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_asString => tDict_get_asString
|
|
|
|
generic :: get_as1dString => tDict_get_as1dString
|
|
|
|
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
|
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
recursive function asFormattedString(self)
|
2020-04-22 16:22:47 +05:30
|
|
|
import tNode
|
2020-05-03 02:33:11 +05:30
|
|
|
character(len=:), allocatable :: asFormattedString
|
2020-04-22 16:22:47 +05:30
|
|
|
class(tNode), intent(in), target :: self
|
2020-05-03 02:33:11 +05:30
|
|
|
end function asFormattedString
|
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__
|
2021-03-11 22:30:07 +05:30
|
|
|
output_as1dString, & !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
|
|
|
!--------------------------------------------------------------------------------------------------
|
2020-05-16 20:35:03 +05:30
|
|
|
subroutine selfTest
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
scalar: block
|
|
|
|
type(tScalar) :: s
|
|
|
|
|
|
|
|
s = '1'
|
|
|
|
if (s%asInt() /= 1) error stop 'tScalar_asInt'
|
|
|
|
if (dNeq(s%asFloat(),1.0_pReal)) error stop 'tScalar_asFloat'
|
|
|
|
s = 'true'
|
|
|
|
if (.not. s%asBool()) error stop 'tScalar_asBool'
|
|
|
|
if (s%asString() /= 'true') error stop 'tScalar_asString'
|
|
|
|
if (s%asFormattedString() /= 'true') error stop 'tScalar_asFormattedString'
|
|
|
|
|
|
|
|
end block scalar
|
|
|
|
|
|
|
|
list: block
|
|
|
|
type(tList), pointer :: l
|
|
|
|
type(tScalar), pointer :: s1,s2
|
|
|
|
|
|
|
|
allocate(s1)
|
|
|
|
allocate(s2)
|
|
|
|
s1 = '1'
|
|
|
|
s2 = '2'
|
|
|
|
allocate(l)
|
|
|
|
call l%append(s1)
|
|
|
|
call l%append(s2)
|
|
|
|
if (any(l%as1dInt() /= [1,2])) error stop 'tList_as1dInt'
|
|
|
|
if (any(dNeq(l%as1dFloat(),real([1.0,2.0],pReal)))) error stop 'tList_as1dFloat'
|
|
|
|
s1 = 'true'
|
|
|
|
s2 = 'false'
|
|
|
|
if (any(l%as1dBool() .neqv. [.true.,.false.])) error stop 'tList_as1dBool'
|
|
|
|
if (any(l%as1dString() /= ['true ','false'])) error stop 'tList_as1dString'
|
|
|
|
if (l%asFormattedString() /= '[true, false]') error stop 'tScalar_asFormattedString'
|
|
|
|
|
|
|
|
end block list
|
|
|
|
|
|
|
|
dict: block
|
|
|
|
type(tDict), pointer :: d
|
|
|
|
type(tList), pointer :: l
|
|
|
|
type(tScalar), pointer :: s1,s2,s3,s4
|
|
|
|
|
|
|
|
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)
|
|
|
|
call d%set('one-two',l)
|
|
|
|
call d%set('three',s3)
|
|
|
|
call d%set('four',s4)
|
|
|
|
if (d%asFormattedString() /= '{one-two: [1, 2], three: 3, four: 4}') &
|
|
|
|
error stop 'tDict_asFormattedString'
|
|
|
|
if (d%get_asInt('three') /= 3) error stop 'tDict_get_asInt'
|
|
|
|
if (any(d%get_as1dInt('one-two') /= [1,2])) error stop 'tDict_get_as1dInt'
|
|
|
|
|
|
|
|
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-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
|
|
|
|
|
|
|
|
self%value = value
|
|
|
|
|
|
|
|
end subroutine tScalar_assign__
|
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Format as string (YAML flow style).
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
recursive function tScalar_asFormattedString(self) result(str)
|
|
|
|
|
|
|
|
class (tScalar), intent(in), target :: self
|
|
|
|
character(len=:), allocatable :: str
|
|
|
|
|
|
|
|
|
|
|
|
str = trim(self%value)
|
|
|
|
|
|
|
|
end function tScalar_asFormattedString
|
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
!> @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)
|
2022-10-25 21:39:36 +05:30
|
|
|
call IO_error(706,'"'//trim(self%asFormattedString())//'" 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)
|
2022-10-25 21:39:36 +05:30
|
|
|
call IO_error(706,'"'//trim(self%asFormattedString())//'" 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)
|
2022-10-25 21:39:36 +05:30
|
|
|
call IO_error(706,'"'//trim(self%asFormattedString())//'" is not a dict')
|
2020-04-22 16:22:47 +05:30
|
|
|
end select
|
|
|
|
|
|
|
|
end function tNode_asDict
|
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Convert to float.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tScalar_asFloat(self)
|
2021-03-02 23:11:26 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tScalar), intent(in), target :: self
|
|
|
|
real(pReal) :: tScalar_asFloat
|
2021-02-27 23:44:53 +05:30
|
|
|
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
tScalar_asFloat = IO_stringAsFloat(self%value)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tScalar_asFloat
|
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
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
tScalar_asInt = IO_stringAsInt(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
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
tScalar_asBool = IO_stringAsBool(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
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tScalar_asString(self)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tScalar), intent(in), target :: self
|
|
|
|
character(len=:), allocatable :: tScalar_asString
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
tScalar_asString = self%value
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tScalar_asString
|
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
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
recursive function tList_asFormattedString(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
|
|
|
|
do i = 1, self%length -1
|
|
|
|
str = str//item%node%asFormattedString()//', '
|
|
|
|
item => item%next
|
|
|
|
end do
|
|
|
|
str = str//item%node%asFormattedString()//']'
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tList_asFormattedString
|
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
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Convert to float array (1D).
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tList_as1dFloat(self)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), intent(in), target :: self
|
|
|
|
real(pReal), dimension(:), allocatable :: tList_as1dFloat
|
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_as1dFloat(self%length))
|
|
|
|
item => self%first
|
|
|
|
do i = 1, self%length
|
|
|
|
scalar => item%node%asScalar()
|
|
|
|
tList_as1dFloat(i) = scalar%asFloat()
|
|
|
|
item => item%next
|
|
|
|
end do
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tList_as1dFloat
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Convert to float array (2D).
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tList_as2dFloat(self)
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), intent(in), target :: self
|
|
|
|
real(pReal), dimension(:,:), allocatable :: tList_as2dFloat
|
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)
|
|
|
|
allocate(tList_as2dFloat(self%length,row_data%length))
|
|
|
|
|
|
|
|
do i=1,self%length
|
|
|
|
row_data => self%get_list(i)
|
2022-10-28 00:54:36 +05:30
|
|
|
if (row_data%length /= size(tList_as2dFloat,2)) call IO_error(709,ext_msg='inconsistent column count in tList_as2dFloat')
|
2022-10-25 21:39:36 +05:30
|
|
|
tList_as2dFloat(i,:) = self%get_as1dFloat(i)
|
|
|
|
end do
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tList_as2dFloat
|
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
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tList_as1dString(self)
|
2022-01-21 05:15:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
class(tList), intent(in), target :: self
|
|
|
|
#ifndef __GFORTRAN__
|
|
|
|
character(len=:), allocatable, dimension(:) :: tList_as1dString
|
|
|
|
#else
|
|
|
|
character(len=pStringLen), allocatable, dimension(:) :: tList_as1dString
|
|
|
|
#endif
|
2022-01-21 05:15:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
integer :: j,len_max
|
|
|
|
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-10-25 21:39:36 +05:30
|
|
|
#ifndef __GFORTRAN__
|
|
|
|
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()
|
|
|
|
len_max = max(len_max, len_trim(scalar%asString()))
|
|
|
|
item => item%next
|
2022-01-21 05:15:47 +05:30
|
|
|
end do
|
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
allocate(character(len=len_max) :: tList_as1dString(self%length))
|
|
|
|
#else
|
|
|
|
allocate(tList_as1dString(self%length))
|
|
|
|
#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()
|
|
|
|
tList_as1dString(j) = scalar%asString()
|
|
|
|
item => item%next
|
2022-01-21 05:15:47 +05:30
|
|
|
end do
|
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tList_as1dString
|
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
|
|
|
|
|
|
|
exists = .false.
|
2022-10-25 21:39:36 +05:30
|
|
|
item => self%first
|
|
|
|
do j = 1, self%length
|
|
|
|
scalar => item%node%asScalar()
|
|
|
|
if (scalar%value == k) then
|
|
|
|
exists = .true.
|
|
|
|
exit
|
|
|
|
endif
|
|
|
|
item => item%next
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2022-10-28 00:54:36 +05:30
|
|
|
if (i < 1 .or. i > self%length) call IO_error(150,ext_msg='tList_get @ '//IO_intAsString(i))
|
2022-10-25 21:39:36 +05:30
|
|
|
item => self%first
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Get scalar by index and convert to float.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tList_get_asFloat(self,i) result(nodeAsFloat)
|
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
|
|
|
|
real(pReal) :: nodeAsFloat
|
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)
|
|
|
|
nodeAsFloat = scalar%asFloat()
|
2020-06-16 19:27:16 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tList_get_asFloat
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Get list by index and convert to float array (1D).
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tList_get_as1dFloat(self,i) result(nodeAs1dFloat)
|
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
|
|
|
real(pReal), dimension(:), allocatable :: nodeAs1dFloat
|
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)
|
|
|
|
nodeAs1dFloat = list%as1dFloat()
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tList_get_as1dFloat
|
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
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tList_get_asString(self,i) result(nodeAsString)
|
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
|
|
|
|
character(len=:), allocatable :: nodeAsString
|
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)
|
|
|
|
nodeAsString = scalar%asString()
|
|
|
|
|
|
|
|
end function tList_get_asString
|
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
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tList_get_as1dString(self,i) result(nodeAs1dString)
|
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
|
|
|
|
character(len=:), allocatable, dimension(:) :: nodeAs1dString
|
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)
|
|
|
|
nodeAs1dString = list%as1dString()
|
2021-02-27 23:44:53 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tList_get_as1dString
|
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
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
recursive function tDict_asFormattedString(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-10-25 21:39:36 +05:30
|
|
|
do i = 1, self%length -1
|
|
|
|
str = str//trim(item%key)//': '//item%node%asFormattedString()//', '
|
2020-04-22 16:22:47 +05:30
|
|
|
item => item%next
|
2022-01-22 05:04:42 +05:30
|
|
|
end do
|
2022-10-25 21:39:36 +05:30
|
|
|
str = str//trim(item%key)//': '//item%node%asFormattedString()//'}'
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
end function tDict_asFormattedString
|
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
|
|
|
|
searchExisting: do while (associated(item%next))
|
|
|
|
if (item%key == key) exit
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2022-10-28 00:54:36 +05:30
|
|
|
if (i < 1 .or. i > self%length) call IO_error(150,ext_msg='tDict_key @ '//IO_intAsString(i))
|
2022-10-25 21:39:36 +05:30
|
|
|
item => self%first
|
|
|
|
do j = 1, i-1
|
|
|
|
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
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
character(len=pStringLen), dimension(:), allocatable :: temp
|
|
|
|
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.
|
|
|
|
do j=1, self%length
|
|
|
|
if (self%key(j) == k) then
|
|
|
|
exists = .true.
|
|
|
|
return
|
|
|
|
end if
|
|
|
|
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
|
|
|
|
logical :: found
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-01-22 05:04:42 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
found = present(defaultVal)
|
|
|
|
if (found) node => defaultVal
|
|
|
|
|
|
|
|
j = 1
|
2020-04-22 16:22:47 +05:30
|
|
|
item => self%first
|
2022-10-25 21:39:36 +05:30
|
|
|
do while(j <= self%length)
|
|
|
|
if (item%key == k) then
|
|
|
|
found = .true.
|
|
|
|
exit
|
|
|
|
end if
|
2020-04-22 16:22:47 +05:30
|
|
|
item => item%next
|
2022-10-25 21:39:36 +05:30
|
|
|
j = j + 1
|
2022-01-22 05:04:42 +05:30
|
|
|
end do
|
2020-04-22 16:22:47 +05:30
|
|
|
|
2022-10-25 21:39:36 +05:30
|
|
|
if (.not. found) then
|
|
|
|
call IO_error(143,ext_msg=k)
|
|
|
|
else
|
|
|
|
if (associated(item)) node => item%node
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Get scalar by key and convert to float.
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tDict_get_asFloat(self,k,defaultVal) result(nodeAsFloat)
|
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
|
|
|
|
real(pReal), intent(in), optional :: defaultVal
|
|
|
|
real(pReal) :: nodeAsFloat
|
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)
|
|
|
|
nodeAsFloat = scalar%asFloat()
|
|
|
|
elseif (present(defaultVal)) then
|
|
|
|
nodeAsFloat = 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_asFloat
|
2020-04-22 16:22:47 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
!> @brief Get list by key and convert to float array (1D).
|
2020-04-22 16:22:47 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tDict_get_as1dFloat(self,k,defaultVal,requiredSize) result(nodeAs1dFloat)
|
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
|
|
|
|
real(pReal), intent(in), dimension(:), optional :: defaultVal
|
|
|
|
integer, intent(in), optional :: requiredSize
|
|
|
|
real(pReal), dimension(:), allocatable :: nodeAs1dFloat
|
|
|
|
|
|
|
|
type(tList), pointer :: list
|
|
|
|
|
|
|
|
|
|
|
|
if (self%contains(k)) then
|
|
|
|
list => self%get_list(k)
|
|
|
|
nodeAs1dFloat = list%as1dFloat()
|
|
|
|
elseif (present(defaultVal)) then
|
|
|
|
nodeAs1dFloat = defaultVal
|
|
|
|
else
|
|
|
|
call IO_error(143,ext_msg=k)
|
|
|
|
end if
|
|
|
|
|
|
|
|
if (present(requiredSize)) then
|
|
|
|
if (requiredSize /= size(nodeAs1dFloat)) call IO_error(146,ext_msg=k)
|
|
|
|
end if
|
|
|
|
|
|
|
|
end function tDict_get_as1dFloat
|
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
!> @brief Get list of lists by key and convert to float array (2D).
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
function tDict_get_as2dFloat(self,k,defaultVal,requiredShape) result(nodeAs2dFloat)
|
|
|
|
|
|
|
|
class(tDict), intent(in) :: 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
|
|
|
|
|
|
|
|
type(tList), pointer :: list
|
|
|
|
|
|
|
|
|
|
|
|
if (self%contains(k)) then
|
|
|
|
list => self%get_list(k)
|
|
|
|
nodeAs2dFloat = list%as2dFloat()
|
|
|
|
elseif (present(defaultVal)) then
|
|
|
|
nodeAs2dFloat = defaultVal
|
|
|
|
else
|
|
|
|
call IO_error(143,ext_msg=k)
|
|
|
|
end if
|
|
|
|
|
|
|
|
if (present(requiredShape)) then
|
|
|
|
if (any(requiredShape /= shape(nodeAs2dFloat))) call IO_error(146,ext_msg=k)
|
|
|
|
end if
|
|
|
|
|
|
|
|
end function tDict_get_as2dFloat
|
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
!> @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
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function tDict_get_asString(self,k,defaultVal) result(nodeAsString)
|
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
|
|
|
|
character(len=:), allocatable :: nodeAsString
|
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)
|
|
|
|
nodeAsString = scalar%asString()
|
|
|
|
elseif (present(defaultVal)) then
|
|
|
|
nodeAsString = 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_asString
|
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).
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
function tDict_get_as1dString(self,k,defaultVal) result(nodeAs1dString)
|
|
|
|
|
|
|
|
class(tDict), intent(in) :: self
|
|
|
|
character(len=*), intent(in) :: k
|
|
|
|
character(len=*), intent(in), dimension(:), optional :: defaultVal
|
|
|
|
character(len=:), allocatable, dimension(:) :: nodeAs1dString
|
|
|
|
|
|
|
|
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)
|
|
|
|
nodeAs1dString = list%as1dString()
|
|
|
|
elseif (present(defaultVal)) then
|
|
|
|
nodeAs1dString = defaultVal
|
|
|
|
else
|
|
|
|
call IO_error(143,ext_msg=k)
|
|
|
|
end if
|
|
|
|
|
|
|
|
end function tDict_get_as1dString
|
|
|
|
|
|
|
|
|
|
|
|
#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
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-10-25 21:39:36 +05:30
|
|
|
function output_as1dString(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
|
|
|
|
character(len=pStringLen), 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
|
|
|
|
output(o) = output_list%get_asString(o)
|
|
|
|
end do
|
|
|
|
|
|
|
|
end function output_as1dString
|
|
|
|
#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
|