test_7 Subroutine

public subroutine test_7(error_cnt)

Arguments

Type IntentOptional AttributesName
integer, intent(out) :: error_cnt

Description

Indent test

Calls

proc~~test_7~~CallsGraph proc~test_7 test_7 interface~json_get json_get proc~test_7->interface~json_get proc~json_failed json_failed proc~test_7->proc~json_failed proc~json_print_error_message json_print_error_message proc~test_7->proc~json_print_error_message interface~json_get_child json_get_child proc~test_7->interface~json_get_child interface~json_print json_print proc~test_7->interface~json_print interface~json_destroy json_destroy proc~test_7->interface~json_destroy interface~json_create_array json_create_array proc~test_7->interface~json_create_array proc~json_initialize json_initialize proc~test_7->proc~json_initialize interface~json_add json_add proc~test_7->interface~json_add interface~json_create_object json_create_object proc~test_7->interface~json_create_object interface~json_remove json_remove proc~test_7->interface~json_remove proc~json_get_string json_get_string interface~json_get->proc~json_get_string proc~json_get_double_vec_with_path json_get_double_vec_with_path interface~json_get->proc~json_get_double_vec_with_path proc~json_get_logical json_get_logical interface~json_get->proc~json_get_logical proc~json_get_integer_vec_with_path json_get_integer_vec_with_path interface~json_get->proc~json_get_integer_vec_with_path proc~json_get_logical_vec_with_path json_get_logical_vec_with_path interface~json_get->proc~json_get_logical_vec_with_path proc~json_get_array json_get_array interface~json_get->proc~json_get_array proc~json_get_double json_get_double interface~json_get->proc~json_get_double proc~json_get_string_vec_with_path json_get_string_vec_with_path interface~json_get->proc~json_get_string_vec_with_path proc~json_get_by_path json_get_by_path interface~json_get->proc~json_get_by_path proc~json_get_integer json_get_integer interface~json_get->proc~json_get_integer proc~json_get_double_with_path json_get_double_with_path interface~json_get->proc~json_get_double_with_path proc~json_get_logical_with_path json_get_logical_with_path interface~json_get->proc~json_get_logical_with_path proc~json_get_integer_with_path json_get_integer_with_path interface~json_get->proc~json_get_integer_with_path proc~json_get_logical_vec json_get_logical_vec interface~json_get->proc~json_get_logical_vec proc~json_get_string_with_path json_get_string_with_path interface~json_get->proc~json_get_string_with_path proc~json_get_string_vec json_get_string_vec interface~json_get->proc~json_get_string_vec proc~json_get_integer_vec json_get_integer_vec interface~json_get->proc~json_get_integer_vec proc~json_get_array_with_path json_get_array_with_path interface~json_get->proc~json_get_array_with_path proc~json_get_double_vec json_get_double_vec interface~json_get->proc~json_get_double_vec proc~json_clear_exceptions json_clear_exceptions proc~json_print_error_message->proc~json_clear_exceptions proc~json_check_for_errors json_check_for_errors proc~json_print_error_message->proc~json_check_for_errors proc~json_value_get_by_index json_value_get_by_index interface~json_get_child->proc~json_value_get_by_index proc~json_value_get_by_name_chars json_value_get_by_name_chars interface~json_get_child->proc~json_value_get_by_name_chars proc~json_print_1 json_print_1 interface~json_print->proc~json_print_1 proc~json_print_2 json_print_2 interface~json_print->proc~json_print_2 proc~json_value_destroy json_value_destroy interface~json_destroy->proc~json_value_destroy proc~json_value_create_array json_value_create_array interface~json_create_array->proc~json_value_create_array interface~throw_exception throw_exception proc~json_initialize->interface~throw_exception proc~json_initialize->proc~json_clear_exceptions proc~json_value_add_logical json_value_add_logical interface~json_add->proc~json_value_add_logical proc~json_value_add_double json_value_add_double interface~json_add->proc~json_value_add_double proc~json_value_add_member json_value_add_member interface~json_add->proc~json_value_add_member proc~json_value_add_integer json_value_add_integer interface~json_add->proc~json_value_add_integer proc~json_value_add_double_vec json_value_add_double_vec interface~json_add->proc~json_value_add_double_vec proc~json_value_add_logical_vec json_value_add_logical_vec interface~json_add->proc~json_value_add_logical_vec proc~json_value_add_integer_vec json_value_add_integer_vec interface~json_add->proc~json_value_add_integer_vec proc~json_value_add_string_vec json_value_add_string_vec interface~json_add->proc~json_value_add_string_vec proc~json_value_add_string json_value_add_string interface~json_add->proc~json_value_add_string proc~json_value_create_object json_value_create_object interface~json_create_object->proc~json_value_create_object proc~json_value_remove json_value_remove interface~json_remove->proc~json_value_remove proc~unescape_string unescape_string proc~json_get_string->proc~unescape_string proc~json_get_string->interface~throw_exception proc~json_get_double_vec_with_path->interface~json_get proc~json_get_logical->interface~throw_exception proc~json_get_integer_vec_with_path->interface~json_get proc~json_get_logical_vec_with_path->interface~json_get proc~json_get_array->interface~throw_exception proc~json_count json_count proc~json_get_array->proc~json_count proc~json_get_double->interface~throw_exception proc~json_get_string_vec_with_path->interface~json_get proc~json_get_by_path->interface~json_get_child proc~json_get_by_path->interface~throw_exception proc~json_get_by_path->proc~json_clear_exceptions proc~string_to_integer string_to_integer proc~json_get_by_path->proc~string_to_integer proc~json_get_integer->interface~throw_exception proc~json_get_double_with_path->proc~json_get_double proc~json_get_double_with_path->proc~json_get_by_path proc~json_get_double_with_path->interface~throw_exception proc~json_get_double_with_path->proc~json_clear_exceptions proc~json_get_logical_with_path->proc~json_get_logical proc~json_get_logical_with_path->proc~json_get_by_path proc~json_get_logical_with_path->interface~throw_exception proc~json_get_logical_with_path->proc~json_clear_exceptions proc~json_get_integer_with_path->proc~json_get_by_path proc~json_get_integer_with_path->proc~json_get_integer proc~json_get_integer_with_path->interface~throw_exception proc~json_get_integer_with_path->proc~json_clear_exceptions proc~json_get_logical_vec->interface~json_get proc~json_get_string_with_path->proc~json_get_string proc~json_get_string_with_path->proc~json_get_by_path proc~json_get_string_with_path->interface~throw_exception proc~json_get_string_with_path->proc~json_clear_exceptions proc~json_get_string_vec->interface~json_get proc~json_get_integer_vec->interface~json_get proc~json_get_array_with_path->proc~json_get_array proc~json_get_array_with_path->proc~json_get_by_path proc~json_get_array_with_path->interface~throw_exception proc~json_get_array_with_path->proc~json_clear_exceptions proc~json_get_double_vec->interface~json_get proc~unescape_string->interface~throw_exception interface~to_unicode to_unicode proc~unescape_string->interface~to_unicode proc~json_throw_exception json_throw_exception interface~throw_exception->proc~json_throw_exception proc~to_uni to_uni interface~to_unicode->proc~to_uni proc~to_uni_vec to_uni_vec interface~to_unicode->proc~to_uni_vec proc~string_to_integer->interface~throw_exception proc~json_value_get_by_index->interface~throw_exception proc~json_value_get_by_name_chars->interface~throw_exception proc~json_value_get_by_name_chars->proc~json_count proc~json_print_1->interface~throw_exception proc~json_value_print json_value_print proc~json_print_1->proc~json_value_print proc~json_print_2->interface~json_print proc~json_print_2->interface~throw_exception proc~json_value_print->interface~throw_exception proc~json_value_print->proc~json_count proc~json_value_print->proc~json_value_print proc~real_to_string real_to_string proc~json_value_print->proc~real_to_string proc~integer_to_string integer_to_string proc~json_value_print->proc~integer_to_string none~write_it write_it proc~json_value_print->none~write_it proc~compact_real_string compact_real_string proc~real_to_string->proc~compact_real_string proc~json_value_destroy->proc~json_value_destroy proc~destroy_json_data destroy_json_data proc~json_value_destroy->proc~destroy_json_data proc~json_value_create json_value_create proc~json_value_create_array->proc~json_value_create proc~to_array to_array proc~json_value_create_array->proc~to_array proc~to_array->proc~destroy_json_data proc~json_value_add_logical->interface~json_add proc~json_value_add_logical->proc~json_value_create proc~to_logical to_logical proc~json_value_add_logical->proc~to_logical proc~json_value_add_double->interface~json_add proc~json_value_add_double->proc~json_value_create proc~to_double to_double proc~json_value_add_double->proc~to_double proc~json_value_add_integer->interface~json_add proc~json_value_add_integer->proc~json_value_create proc~to_integer to_integer proc~json_value_add_integer->proc~to_integer proc~json_value_add_double_vec->interface~json_add proc~json_value_add_double_vec->proc~json_value_create proc~json_value_add_double_vec->proc~to_array proc~json_value_add_logical_vec->interface~json_add proc~json_value_add_logical_vec->proc~json_value_create proc~json_value_add_logical_vec->proc~to_array proc~json_value_add_integer_vec->interface~json_add proc~json_value_add_integer_vec->proc~json_value_create proc~json_value_add_integer_vec->proc~to_array proc~json_value_add_string_vec->interface~json_add proc~json_value_add_string_vec->proc~json_value_create proc~json_value_add_string_vec->proc~to_array proc~json_value_add_string->interface~json_add proc~json_value_add_string->proc~json_value_create proc~escape_string escape_string proc~json_value_add_string->proc~escape_string proc~to_string to_string proc~json_value_add_string->proc~to_string proc~to_logical->proc~destroy_json_data proc~to_double->proc~destroy_json_data proc~to_integer->proc~destroy_json_data proc~to_string->proc~destroy_json_data proc~json_value_create_object->proc~json_value_create proc~to_object to_object proc~json_value_create_object->proc~to_object proc~to_object->proc~destroy_json_data proc~json_value_remove->proc~json_value_destroy
Help

Called By

proc~~test_7~~CalledByGraph proc~test_7 test_7 program~jf_test_7 jf_test_7 program~jf_test_7->proc~test_7
Help

Variables

TypeVisibility AttributesNameInitial
type(json_value), public, pointer:: root
type(json_value), public, pointer:: a
type(json_value), public, pointer:: b
type(json_value), public, pointer:: c
type(json_value), public, pointer:: d
type(json_value), public, pointer:: e
type(json_value), public, pointer:: e1
type(json_value), public, pointer:: e2
type(json_value), public, pointer:: escaped_string
type(json_value), public, pointer:: p
logical, public :: found
character(kind=CK,len=1), public, dimension(:), allocatable:: strvec
character(kind=CK,len=:), public, allocatable:: string

Source Code

    subroutine test_7(error_cnt)

    !! Indent test

    implicit none

    integer,intent(out) :: error_cnt

    type(json_value),pointer :: root,a,b,c,d,e,e1,e2,escaped_string,p
    logical :: found
    character(kind=CK,len=1), dimension(:), allocatable :: strvec
    character(kind=CK,len=:), allocatable :: string

    found=.false.
    error_cnt = 0
    call json_initialize()
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if

    write(error_unit,'(A)') ''
    write(error_unit,'(A)') '================================='
    write(error_unit,'(A)') '   EXAMPLE 7 : indent test'
    write(error_unit,'(A)') '================================='
    write(error_unit,'(A)') ''

!-----------------------
! jsonlint indention is
!-----------------------
!{
!    "a": {
!        "ints": [
!            1,
!            2,
!            3
!        ],
!        "chars": [
!            "a",
!            "b",
!            "c"
!        ]
!    },
!    "b": {
!        "c": {
!            "val1": 1066
!        }
!    },
!    "d": {
!        "val2": 1815
!    },
!    "array": [
!        {
!            "int1": 1
!        },
!        {
!            "int1": 1,
!            "int2": 2
!        }
!    ]
!    "escaped string": "\\\/\b\f\n\r\t"
!}

    !create a json structure:
    call json_create_object(root,'root')
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_create_object(a,'a')
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_add(a,'ints', [1,2,3])
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_create_object(b,'b')
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_add(a,'chars', ['a','b','c'])
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_get_child(a,'chars',p)
    call json_get(p,strvec)
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_create_object(c,'c')
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_add(c,'val1', 1066)
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_create_object(d,'d')
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_add(d,'val2', 1815)
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if

    call json_create_array(e,'array')   !objects in an array
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_create_object(e1,'')
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_add(e1,'int1', 1)
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_create_object(e2,'')
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_add(e2,'int1', 1)
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_add(e2,'int2', 2)
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_add(e,e1)
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_add(e,e2)
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_add(root,a)
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_add(root,b)
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_add(b,c)
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_add(root,d)
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_add(root,e)
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_add(root,'escaped string',&
         '\/'//&
         achar(8)//&
         achar(12)//&
         achar(10)//&
         achar(13)//&
         achar(9))
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_add(root,'wacky string',['trim   ','  and  ',' adjust','   left'],&
         trim_str=.true.,adjustl_str=.true.)
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if

    nullify(a)  !don't need these anymore
    nullify(b)
    nullify(c)
    nullify(d)
    nullify(e)
    nullify(e1)
    nullify(e2)
    nullify(escaped_string)

    call json_print(root,output_unit)  !print to the console
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    ! look for the 'escaped string' entry
    call json_get(root,'escaped string',escaped_string,found)
    if (json_failed() .or. .not. found) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call json_get(escaped_string,string)
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    write(error_unit,'(A)') "Fetched unescaped 'escaped string': "//string

    ! remove the escaped string entry
    if (found) call json_remove(escaped_string,destroy=.true.)
    call json_print(root,error_unit)  !print to stderr
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if

    call json_destroy(root)  !cleanup
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if

    end subroutine test_7