32 integer(kind=i_kind) :: num_elem = 0
73 procedure,
private ::
get
96 character(:),
allocatable :: key_name
98 class(*),
pointer :: val => null()
145 recursive subroutine load(this, json, j_obj, as_object, owner_name, &
151 type(json_core),
pointer,
intent(in) :: json
153 type(json_value),
pointer,
intent(in) :: j_obj
157 logical,
intent(in) :: as_object
159 character(len=*),
intent(in):: owner_name
161 logical,
intent(in),
optional :: allow_duplicates
163 type(json_value),
pointer :: child, next
165 character(kind=json_ck, len=:),
allocatable :: unicode_prop_key
166 character(len=:),
allocatable :: prop_key
169 character(kind=json_ck, len=:),
allocatable :: unicode_val
170 character(len=:),
allocatable :: str_val
171 logical(json_lk) :: bool_val
172 real(json_rk) :: real_val
173 integer(json_ik) :: int_val
175 integer(json_ik) :: var_type
179 if (
present(allow_duplicates)) allow_dup = allow_duplicates
186 call json%get_child(j_obj, child)
192 do while (
associated(child))
195 call json%info(child, name=unicode_prop_key, var_type=var_type)
196 prop_key = unicode_prop_key
199 select case (var_type)
206 call json%get(child, int_val)
207 call this%put(prop_key, int(int_val,
i_kind), allow_dup, &
212 call json%get(child, real_val)
213 call this%put(prop_key, real(real_val,
dp), allow_dup, &
218 call json%get(child, bool_val)
219 call this%put(prop_key,
logical(bool_val), allow_dup, &
224 call json%get(child, unicode_val)
225 str_val = unicode_val
226 call this%put(prop_key, str_val, allow_dup, owner_name)
231 call sub_prop%load(json, child, .true., owner_name, allow_dup)
232 call this%put(prop_key, sub_prop, allow_dup, owner_name)
238 call sub_prop%load(json, child, .true., owner_name, allow_dup)
239 call this%put(prop_key, sub_prop, allow_dup, owner_name)
247 if (as_object)
call json%get_next(child, next)
253 subroutine load(this)
258 call warn_msg(733896496,
"No support for input files.")
265 recursive subroutine put(this, key, val, allow_duplicates, owner_name)
270 character(len=*),
intent(in) ::
key
272 class(*),
intent(in) :: val
274 logical,
intent(in) :: allow_duplicates
276 character(len=*),
intent(in) :: owner_name
280 class(*),
pointer :: curr_val
283 if (len(
key).ge.1)
then
286 if (.not.allow_duplicates)
then
288 new_link => this%get(
key)
292 if (
associated(new_link))
then
293 curr_val => new_link%val
294 select type (curr_val)
298 sub_link => val%first_link
299 do while (
associated(sub_link))
300 call curr_val%put(sub_link%key_name, sub_link%val, .false., &
302 sub_link => sub_link%next_link
305 call new_link%print(
"")
306 call die_msg(698012538,
"Property type mismatch for "//
key// &
307 " in property set of "//owner_name)
310 call new_link%print(
"")
311 call die_msg(359604264,
"Trying to overwrite property "//
key// &
312 " in property set of "//owner_name)
325 allocate(sub_prop_set)
326 sub_link => val%first_link
327 do while (
associated(sub_link))
328 call sub_prop_set%put(sub_link%key_name, sub_link%val, &
329 allow_duplicates, owner_name)
330 sub_link => sub_link%next_link
333 sub_prop_set%first_link => null()
334 sub_prop_set%last_link => null()
335 deallocate(sub_prop_set)
342 if (.not.
associated(this%first_link))
then
343 this%first_link => new_link
344 this%last_link => this%first_link
346 this%last_link%next_link => new_link
347 this%last_link => new_link
350 this%num_elem = this%num_elem + 1
360 logical function get_key(this, key)
result (found)
365 character(len=:),
allocatable,
intent(out) ::
key
368 if (.not.
associated(this%curr_link))
return
369 key = this%curr_link%key()
381 logical function get_int(this, key, val)
result(found)
386 character(len=*),
intent(in),
optional ::
key
388 integer(kind=i_kind),
intent(out) :: val
393 if (
present(
key))
then
395 if (.not.
associated(link))
return
396 val = link%value_int()
398 if (.not.
associated(this%curr_link))
return
399 val = this%curr_link%value_int()
412 logical function get_real(this, key, val)
result(found)
417 character(len=*),
intent(in),
optional ::
key
419 real(kind=
dp),
intent(out) :: val
424 if (
present(
key))
then
426 if (.not.
associated(link))
return
427 val = link%value_real()
429 if (.not.
associated(this%curr_link))
return
430 val = this%curr_link%value_real()
448 character(len=*),
intent(in),
optional ::
key
450 logical,
intent(out) :: val
455 if (
present(
key))
then
457 if (.not.
associated(link))
return
458 val = link%value_logical()
460 if (.not.
associated(this%curr_link))
return
461 val = this%curr_link%value_logical()
479 character(len=*),
intent(in),
optional ::
key
481 character(len=:),
allocatable,
intent(out) :: val
486 if (
present(
key))
then
488 if (.not.
associated(link))
return
489 val = link%value_string()
491 if (.not.
associated(this%curr_link))
return
492 val = this%curr_link%value_string()
510 character(len=*),
intent(in),
optional ::
key
518 if (
present(
key))
then
520 if (.not.
associated(link))
return
521 val => link%value_property_t()
523 if (.not.
associated(this%curr_link))
return
524 val => this%curr_link%value_property_t()
543 curr_link => this%first_link
544 do while (
associated(curr_link))
546 curr_link => curr_link%next_link
560 this%curr_link => this%first_link
572 if (
associated(this%curr_link))
then
573 this%curr_link => this%curr_link%next_link
575 call warn_msg(365476096,
"Trying to iterate NULL iterator.")
583 elemental subroutine move(this, dest)
590 dest%first_link => this%first_link
591 dest%curr_link => this%curr_link
592 dest%last_link => this%last_link
593 dest%num_elem = this%num_elem
594 this%first_link => null()
595 this%curr_link => null()
596 this%last_link => null()
604 subroutine update(this, source, owner_name)
611 character(len=*),
intent(in) :: owner_name
615 curr_prop => source%first_link
616 do while (
associated(curr_prop))
617 call this%put(curr_prop%key_name, curr_prop%val, .false., owner_name)
618 curr_prop => curr_prop%next_link
631 integer(kind=i_kind),
optional,
intent(in) :: file_unit
634 integer(kind=i_kind) :: f_unit
638 if (
present(file_unit)) f_unit = file_unit
640 curr_link => this%first_link
641 do while (
associated(curr_link))
642 if (
associated(curr_link%next_link))
then
643 call curr_link%print(
",", f_unit)
645 call curr_link%print(
"", f_unit)
647 curr_link => curr_link%next_link
663 do while (
associated(this%first_link))
664 next => this%first_link%next_link
665 deallocate(this%first_link)
666 this%first_link => next
675 function get(this, key)
result(found_pair)
682 character(len=*),
intent(in) ::
key
687 if (.not.
associated(this%first_link))
return
688 curr_link => this%first_link
689 do while (
associated(curr_link))
690 if (
key .eq. curr_link%key())
then
691 found_pair => curr_link
694 curr_link => curr_link%next_link
711 character(len=*),
intent(in) ::
key
713 class(*),
intent(in) :: val
716 new_obj%key_name = trim(
key)
717 new_obj%next_link => null()
718 call new_obj%set_value(val)
728 character(:),
allocatable ::
key
744 class(*),
intent(in) :: val
752 type is (
integer(kind=
i_kind))
753 type is (real(kind=
dp))
759 if (.not.
associated(val%first_link))
then
765 type is (
character(len=*))
773 call die_msg(728532218,
"Unsupported property type")
776 allocate(this%val, source=val)
786 integer(kind=i_kind) :: val
790 class(*),
pointer :: this_val
793 select type(this_val)
794 type is (
integer(kind=
i_kind))
797 call die_msg(509101133,
"Property type mismatch for key "//&
813 class(*),
pointer :: this_val
816 select type(this_val)
817 type is (
integer(kind=
i_kind))
818 val = real(this_val, kind=
dp)
819 type is (real(kind=
dp))
822 call die_msg(151463892,
"Property type mismatch for key "//&
838 class(*),
pointer :: this_val
841 select type(this_val)
845 call die_msg(371288570,
"Property type mismatch for key "//&
857 character(len=:),
allocatable :: val
861 class(*),
pointer :: this_val
864 select type (this_val)
866 val = this_val%string
868 call die_msg(153505401,
"Property type mismatch for key "//&
884 class(*),
pointer :: this_val
887 select type(this_val)
891 call die_msg(641781966,
"Property type mismatch for key "//&
905 character(len=*),
intent(in) :: suffix
907 integer(kind=i_kind),
optional,
intent(in) :: file_unit
909 class(*),
pointer :: val
910 integer(kind=i_kind) :: f_unit
914 if (
present(file_unit)) f_unit = file_unit
918 type is (
integer(kind=
i_kind))
919 write(f_unit,*)
'"'//this%key_name//
'" : '//trim(
to_string(val))// &
921 type is (real(kind=
dp))
922 write(f_unit,*)
'"'//this%key_name//
'" : '//trim(
to_string(val))// &
925 write(f_unit,*)
'"'//this%key_name//
'" : '//trim(
to_string(val))// &
928 write(f_unit,*)
'"'//this%key_name//
'" : "'//val%string//
'"'//suffix
930 write(f_unit,*)
'"'//this%key_name//
'" : {'
931 call val%print(f_unit)
932 write(f_unit,*)
'}'//suffix
934 call die_msg(711028956,
"Unsupported property type")
947 if (
associated(this%val))
deallocate(this%val)
Interface for to_string functions.
integer, parameter dp
Kind of a double precision real number.
integer, parameter i_kind
Kind of an integer.
The property_t structure and associated subroutines.
logical function get_logical(this, key, val)
Get a logical value. The return value is true if the key-value pair was found, and false otherwise....
logical function get_string(this, key, val)
Get a string value. The return value is true if the key-value pair was found, and false otherwise....
recursive subroutine do_print(this, file_unit)
Print the contents of a property set.
type(property_link_t) function, pointer link_constructor(key, val)
Constructor for property_link_t.
subroutine update(this, source, owner_name)
Update this property_t instance with data from another instance.
recursive subroutine link_do_print(this, suffix, file_unit)
Print the contents of a property key-value pair.
character(len=:) function, allocatable value_string(this)
Get the string value of a property.
recursive subroutine load(this, json, j_obj, as_object, owner_name, allow_duplicates)
Load a property set from input data.
real(kind=dp) function value_real(this)
Get the real value of a property.
character(:) function, allocatable key(this)
Get the key name of a property.
logical function get_key(this, key)
Get the key name of the element currently pointed to by the iterator. Returns true if the iterator po...
integer(kind=i_kind) function value_int(this)
Get the int value of a property.
type(property_link_t) function, pointer get(this, key)
Find a key-value pair by key name. Returns a null pointer if the key name is not found.
recursive subroutine put(this, key, val, allow_duplicates, owner_name)
Put an element in the property data set.
integer(kind=i_kind) function get_size(this)
Get the number of elements in the property set.
type(property_t) function, pointer constructor()
Constructor for property_t.
elemental subroutine link_finalize(this)
Finalize the property_link_t variable.
logical function get_real(this, key, val)
Get a real value. The return value is true if the key-value pair was found, and false otherwise....
subroutine set_value(this, val)
Set the value of a property key-value pair.
type(property_t) function, pointer value_property_t(this)
Get the property_t value of a property.
logical function get_property_t(this, key, val)
Get a property sub-set. The return value is true if the key-value pair was found, and false otherwise...
elemental subroutine finalize(this)
Finalize a property_t variable.
subroutine iter_reset(this)
Initialize the iterator. It will now point to the first property in the dataset, or be NULL in the ca...
elemental subroutine move(this, dest)
Move data from one property_t instance to another.
subroutine iter_next(this)
Increment the interator.
logical function value_logical(this)
Get the logical value of a property.
logical function get_int(this, key, val)
Get an integer value. The return value is true if the key-value pair was found, and false otherwise....
Common utility subroutines.
subroutine die_msg(code, error_msg)
Error immediately.
subroutine warn_msg(code, warning_msg, already_warned)
Prints a warning message.
String type for building arrays of string of various size.