Skip to content

Commit 131d37f

Browse files
committed
Added optional name output to json_info. Fixes #141
1 parent 5ad9381 commit 131d37f

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/json_module.F90

+5-3
Original file line numberDiff line numberDiff line change
@@ -1248,16 +1248,18 @@ end subroutine wrap_json_file_variable_info
12481248
!
12491249
! Returns information about a [[json_value]].
12501250

1251-
subroutine json_info(p,var_type,n_children)
1251+
subroutine json_info(p,var_type,n_children,name)
12521252

12531253
implicit none
12541254

12551255
type(json_value),pointer :: p
12561256
integer(IK),intent(out),optional :: var_type !! variable type
12571257
integer(IK),intent(out),optional :: n_children !! number of children
1258+
character(kind=CK,len=:),allocatable,intent(out),optional :: name !! variable name
12581259

1259-
if (present(var_type)) var_type = p%var_type !variable type
1260-
if (present(n_children)) n_children = json_count(p) !number of children
1260+
if (present(var_type)) var_type = p%var_type
1261+
if (present(n_children)) n_children = json_count(p)
1262+
if (present(name)) name = p%name
12611263

12621264
end subroutine json_info
12631265
!*****************************************************************************************

src/tests/jf_test_10.f90

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ subroutine test_10(error_cnt)
6565
character(kind=CK,len=256),dimension(:),allocatable :: str_vec
6666
type(json_file) :: f,f2
6767
type(json_value),pointer :: p
68-
character(kind=CK,len=:),allocatable :: str
68+
character(kind=CK,len=:),allocatable :: str,name
6969
logical :: found,lval
7070
integer :: var_type,n_children
7171

@@ -249,7 +249,7 @@ subroutine test_10(error_cnt)
249249
write(error_unit,'(A)') '...success'
250250

251251
write(error_unit,'(A)') 'json_info...'
252-
call json_info(p,var_type,n_children)
252+
call json_info(p,var_type,n_children,name)
253253
if (json_failed()) then
254254
call json_print_error_message(error_unit)
255255
error_cnt = error_cnt + 1

0 commit comments

Comments
 (0)