Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(json_value), | intent(inout), | pointer | :: | me | ||
character(kind=CK,len=*), | intent(in) | :: | name | variable name |
||
character(kind=CK,len=*), | intent(in), | dimension(:) | :: | val | array of strings |
|
logical(kind=LK), | intent(in), | optional | :: | trim_str | if TRIM() should be called for each element |
|
logical(kind=LK), | intent(in), | optional | :: | adjustl_str | if ADJUSTL() should be called for each element |
Add an array of character strings to the structure.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
type(json_value), | public, | pointer | :: | var | |||
integer(kind=IK), | public | :: | i | ||||
logical(kind=LK), | public | :: | trim_string | ||||
logical(kind=LK), | public | :: | adjustl_string | ||||
character(kind=CK,len=:), | public, | allocatable | :: | str |
subroutine json_value_add_string_vec(me, name, val, trim_str, adjustl_str)
implicit none
type(json_value),pointer :: me
character(kind=CK,len=*),intent(in) :: name !! variable name
character(kind=CK,len=*),dimension(:),intent(in) :: val !! array of strings
logical(LK),intent(in),optional :: trim_str !! if TRIM() should be called for each element
logical(LK),intent(in),optional :: adjustl_str !! if ADJUSTL() should be called for each element
type(json_value),pointer :: var
integer(IK) :: i
logical(LK) :: trim_string, adjustl_string
character(kind=CK,len=:),allocatable :: str
!if the string is to be trimmed or not:
if (present(trim_str)) then
trim_string = trim_str
else
trim_string = .false.
end if
if (present(adjustl_str)) then
adjustl_string = adjustl_str
else
adjustl_string = .false.
end if
!create the variable as an array:
call json_value_create(var)
call to_array(var,name)
!populate the array:
do i=1,size(val)
!the string to write:
str = val(i)
if (adjustl_string) str = adjustl(str)
if (trim_string) str = trim(str)
!write it:
call json_add(var, '', str)
!cleanup
deallocate(str)
end do
!add it:
call json_add(me, var)
!cleanup:
nullify(var)
end subroutine json_value_add_string_vec