Skip to content

Commit 901a11a

Browse files
committed
added alternate get_string routine that returns allocatable strings (length is the max length of any string in the array).
some other minor refactoring.
1 parent 309de97 commit 901a11a

File tree

3 files changed

+401
-109
lines changed

3 files changed

+401
-109
lines changed

src/json_file_module.F90

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ module json_file_module
101101
MAYBEWRAP(json_file_get_double_vec), &
102102
MAYBEWRAP(json_file_get_logical_vec), &
103103
MAYBEWRAP(json_file_get_string_vec), &
104+
MAYBEWRAP(json_file_get_alloc_string_vec), &
104105
json_file_get_root
105106

106107
generic,public :: update => MAYBEWRAP(json_file_update_integer), &
@@ -140,6 +141,7 @@ module json_file_module
140141
procedure :: MAYBEWRAP(json_file_get_double_vec)
141142
procedure :: MAYBEWRAP(json_file_get_logical_vec)
142143
procedure :: MAYBEWRAP(json_file_get_string_vec)
144+
procedure :: MAYBEWRAP(json_file_get_alloc_string_vec)
143145
procedure :: json_file_get_root
144146

145147
!update:
@@ -1116,6 +1118,52 @@ subroutine wrap_json_file_get_string_vec(me, path, vec, found)
11161118
end subroutine wrap_json_file_get_string_vec
11171119
!*****************************************************************************************
11181120

1121+
!*****************************************************************************************
1122+
!> author: Jacob Williams
1123+
! date: 12/17/2016
1124+
!
1125+
! Get an (allocatable length) string vector from a JSON file.
1126+
! This is just a wrapper for [[json_get_alloc_string_vec_with_path]].
1127+
1128+
subroutine json_file_get_alloc_string_vec(me, path, vec, ilen, found)
1129+
1130+
implicit none
1131+
1132+
class(json_file),intent(inout) :: me
1133+
character(kind=CK,len=*),intent(in) :: path
1134+
character(kind=CK,len=:),dimension(:),allocatable,intent(out) :: vec
1135+
integer(IK),dimension(:),allocatable,intent(out) :: ilen !! the actual length
1136+
!! of each character
1137+
!! string in the array
1138+
logical(LK),intent(out),optional :: found
1139+
1140+
call me%core%get(me%p, path, vec, ilen, found)
1141+
1142+
end subroutine json_file_get_alloc_string_vec
1143+
!*****************************************************************************************
1144+
1145+
!*****************************************************************************************
1146+
!>
1147+
! Alternate version of [[json_file_get_alloc_string_vec]], where "path" is kind=CDK.
1148+
! This is just a wrapper for [[wrap_json_get_alloc_string_vec_with_path]].
1149+
1150+
subroutine wrap_json_file_get_alloc_string_vec(me, path, vec, ilen, found)
1151+
1152+
implicit none
1153+
1154+
class(json_file),intent(inout) :: me
1155+
character(kind=CDK,len=*),intent(in) :: path
1156+
character(kind=CK,len=:),dimension(:),allocatable,intent(out) :: vec
1157+
integer(IK),dimension(:),allocatable,intent(out) :: ilen !! the actual length
1158+
!! of each character
1159+
!! string in the array
1160+
logical(LK),intent(out),optional :: found
1161+
1162+
call me%get(to_unicode(path), vec, ilen, found)
1163+
1164+
end subroutine wrap_json_file_get_alloc_string_vec
1165+
!*****************************************************************************************
1166+
11191167
!*****************************************************************************************
11201168
!> author: Jacob Williams
11211169
! date:1/10/2015

0 commit comments

Comments
 (0)