Returns matrix information about a json_value, given the path.
If found
is present, no exceptions will be thrown if an
error occurs. Otherwise, an exception will be thrown if the
variable is not found.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
type(json_value), | pointer | :: | p | a JSON linked list |
||
character(kind=CK,len=*), | intent(in) | :: | path | path to the variable |
||
logical(kind=LK), | intent(out) | :: | is_matrix | true if it is a valid matrix |
||
logical(kind=LK), | intent(out), | optional | :: | found | true if it was found |
|
integer(kind=IK), | intent(out), | optional | :: | var_type | variable type of data in the matrix (if all elements have the same type) |
|
integer(kind=IK), | intent(out), | optional | :: | n_sets | number of data sets (i.e., matrix rows if using row-major order) |
|
integer(kind=IK), | intent(out), | optional | :: | set_size | size of each data set (i.e., matrix cols if using row-major order) |
|
character(kind=CK,len=:), | intent(out), | optional | allocatable | :: | name | variable name |
subroutine json_matrix_info_by_path(json,p,path,is_matrix,found,&
var_type,n_sets,set_size,name)
implicit none
class(json_core),intent(inout) :: json
type(json_value),pointer :: p !! a JSON linked list
character(kind=CK,len=*),intent(in) :: path !! path to the variable
logical(LK),intent(out) :: is_matrix !! true if it is a valid matrix
logical(LK),intent(out),optional :: found !! true if it was found
integer(IK),intent(out),optional :: var_type !! variable type of data in
!! the matrix (if all elements have
!! the same type)
integer(IK),intent(out),optional :: n_sets !! number of data sets (i.e., matrix
!! rows if using row-major order)
integer(IK),intent(out),optional :: set_size !! size of each data set (i.e., matrix
!! cols if using row-major order)
character(kind=CK,len=:),allocatable,intent(out),optional :: name !! variable name
type(json_value),pointer :: p_var
logical(LK) :: ok
#if defined __GFORTRAN__
character(kind=CK,len=:),allocatable :: p_name
#endif
call json%get(p,path,p_var,found)
!check if it was found:
if (present(found)) then
ok = found
else
ok = .not. json%failed()
end if
if (.not. ok) then
if (present(var_type)) var_type = json_unknown
if (present(n_sets)) n_sets = 0
if (present(set_size)) set_size = 0
if (present(name)) name = ''
else
!get info about the variable:
#if defined __GFORTRAN__
call json%matrix_info(p_var,is_matrix,var_type,n_sets,set_size)
if (present(name)) then !workaround for gfortran bug
if (allocated(p_var%name)) then
p_name = p_var%name
name = p_name
else
name = ''
end if
end if
#else
call json%matrix_info(p_var,is_matrix,var_type,n_sets,set_size,name)
#endif
if (json%failed() .and. present(found)) then
found = .false.
call json%clear_exceptions()
end if
end if
end subroutine json_matrix_info_by_path