Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/json_file_module.F90
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ end subroutine json_file_move_pointer
! end program main
!```

subroutine json_file_load(me, filename, unit)
subroutine json_file_load(me, filename, unit, destroy_pointer)

implicit none

Expand All @@ -860,8 +860,14 @@ subroutine json_file_load(me, filename, unit)
integer(IK),intent(in),optional :: unit !! the unit number to use
!! (if not present, a newunit
!! is used)
logical(LK),intent(in),optional :: destroy_pointer !! destroy the pointer before
!! loading (default is True)

call me%destroy()
if (present(destroy_pointer)) then
if (destroy_pointer) call me%destroy()
else ! by default it is destroyed
call me%destroy()
end if
call me%core%load(file=filename, p=me%p, unit=unit)

end subroutine json_file_load
Expand All @@ -881,14 +887,20 @@ end subroutine json_file_load
! call f%deserialize('{ "name": "Leonidas" }')
!```

subroutine json_file_load_from_string(me, str)
subroutine json_file_load_from_string(me, str, destroy_pointer)

implicit none

class(json_file),intent(inout) :: me
character(kind=CK,len=*),intent(in) :: str !! string to load JSON data from
logical(LK),intent(in),optional :: destroy_pointer !! destroy the pointer before
!! loading (default is True)

call me%destroy()
if (present(destroy_pointer)) then
if (destroy_pointer) call me%destroy()
else ! by default it is destroyed
call me%destroy()
end if
call me%core%deserialize(me%p, str)

end subroutine json_file_load_from_string
Expand Down