json_initialize Subroutine

public subroutine json_initialize(verbose, compact_reals, print_signs, real_format)

Arguments

Type IntentOptional AttributesName
logical(kind=LK), intent(in), optional :: verbose

mainly useful for debugging (default is false)

logical(kind=LK), intent(in), optional :: compact_reals

to compact the real number strings for output (default is true)

logical(kind=LK), intent(in), optional :: print_signs

always print numeric sign (default is false)

character(kind=len=*,CDK), intent(in), optional :: real_format

exponential (default), scientific, engineering or general

Description

Initialize the JSON-Fortran module. The routine must be called before any of the routines are used. It can also be called after using the module and encountering exceptions.

Modified

  • Izaak Beekman : 02/24/2015

Calls

proc~~json_initialize~~CallsGraph proc~json_initialize json_initialize proc~json_clear_exceptions json_clear_exceptions proc~json_initialize->proc~json_clear_exceptions interface~throw_exception throw_exception proc~json_initialize->interface~throw_exception proc~json_throw_exception json_throw_exception interface~throw_exception->proc~json_throw_exception
Help

Called By

proc~~json_initialize~~CalledByGraph proc~json_initialize json_initialize proc~test_7 test_7 proc~test_7->proc~json_initialize proc~test_9 test_9 proc~test_9->proc~json_initialize proc~test_12 test_12 proc~test_12->proc~json_initialize proc~test_3 test_3 proc~test_3->proc~json_initialize proc~test_2 test_2 proc~test_2->proc~json_initialize proc~test_8 test_8 proc~test_8->proc~json_initialize interface~json_parse json_parse proc~test_8->interface~json_parse proc~json_parse_string json_parse_string proc~json_parse_string->proc~json_initialize proc~test_13 test_13 proc~test_13->proc~json_initialize proc~test_1 test_1 proc~test_1->proc~json_initialize proc~test_10 test_10 proc~test_10->proc~json_initialize proc~test_5 test_5 proc~test_5->proc~json_initialize proc~test_4 test_4 proc~test_4->proc~json_initialize proc~test_14 test_14 proc~test_14->proc~json_initialize proc~test_14->interface~json_parse proc~test_6 test_6 proc~test_6->proc~json_initialize proc~test_11 test_11 proc~test_11->proc~json_initialize proc~json_parse_file json_parse_file proc~json_parse_file->proc~json_initialize program~jf_test_7 jf_test_7 program~jf_test_7->proc~test_7 program~jf_test_9 jf_test_9 program~jf_test_9->proc~test_9 program~jf_test_12 jf_test_12 program~jf_test_12->proc~test_12 program~jf_test_3 jf_test_3 program~jf_test_3->proc~test_3 program~jf_test_2 jf_test_2 program~jf_test_2->proc~test_2 program~jf_test_8 jf_test_8 program~jf_test_8->proc~test_8 proc~wrap_json_parse_string wrap_json_parse_string proc~wrap_json_parse_string->proc~json_parse_string interface~json_parse->proc~json_parse_string interface~json_parse->proc~json_parse_file proc~json_file_load json_file_load proc~json_file_load->interface~json_parse proc~json_file_load_from_string json_file_load_from_string proc~json_file_load_from_string->interface~json_parse proc~wrap_json_file_load_from_string wrap_json_file_load_from_string proc~wrap_json_file_load_from_string->proc~json_file_load_from_string program~jf_test_13 jf_test_13 program~jf_test_13->proc~test_13 program~jf_test_1 jf_test_1 program~jf_test_1->proc~test_1 program~jf_test_10 jf_test_10 program~jf_test_10->proc~test_10 program~jf_test_5 jf_test_5 program~jf_test_5->proc~test_5 program~jf_test_4 jf_test_4 program~jf_test_4->proc~test_4 program~jf_test_14 jf_test_14 program~jf_test_14->proc~test_14 program~jf_test_6 jf_test_6 program~jf_test_6->proc~test_6 program~jf_test_11 jf_test_11 program~jf_test_11->proc~test_11
Help

Variables

TypeVisibility AttributesNameInitial
character(kind=CDK,len=10), public :: w
character(kind=CDK,len=10), public :: d
character(kind=CDK,len=10), public :: e
character(kind=CDK,len=2), public :: sgn
character(kind=CDK,len=2), public :: rl_edit_desc
integer(kind=IK), public :: istat
logical(kind=LK), public :: sgn_prnt

Source Code

    subroutine json_initialize(verbose,compact_reals,print_signs,real_format)

    implicit none

    logical(LK),intent(in),optional :: verbose       !! mainly useful for debugging (default is false)
    logical(LK),intent(in),optional :: compact_reals !! to compact the real number strings for output (default is true)
    logical(LK),intent(in),optional :: print_signs   !! always print numeric sign (default is false)
    character(len=*,kind=CDK),intent(in),optional :: real_format !! exponential (default), scientific, engineering or general

    character(kind=CDK,len=10) :: w,d,e
    character(kind=CDK,len=2)  :: sgn, rl_edit_desc
    integer(IK) :: istat
    logical(LK) :: sgn_prnt

    !clear any errors from previous runs:
    call json_clear_exceptions()

    !Ensure gfortran bug work around "parameters" are set properly
    null_str  = 'null'
    true_str  = 'true'
    false_str = 'false'

    !Just in case, clear these global variables also:
    pushed_index = 0
    pushed_char  = ''
    char_count   = 0
    line_count   = 1
    ipos         = 1

# ifdef USE_UCS4
    ! reopen stdout and stderr with utf-8 encoding
    open(output_unit,encoding='utf-8')
    open(error_unit, encoding='utf-8')
# endif

    !verbose error printing:
    if (present(verbose)) is_verbose = verbose

    !Set the format for real numbers:
    ! [if not changing it, then it remains the same]

    if ( (.not. allocated(real_fmt)) .or. &  ! if this hasn't been done yet
          present(compact_reals)     .or. &
          present(print_signs)       .or. &
          present(real_format) ) then

        !allow the special case where real format is '*':
        ! [this overrides the other options]
        if (present(real_format)) then
            if (real_format==star) then
                compact_real = .false.
                real_fmt = star
                return
            end if
        end if

        if (present(compact_reals)) compact_real = compact_reals

        !set defaults
        sgn_prnt = .false.
        if ( present( print_signs) ) sgn_prnt = print_signs
        if ( sgn_prnt ) then
           sgn = 'sp'
        else
           sgn = 'ss'
        end if

        rl_edit_desc = 'E'
        if ( present( real_format ) ) then
           select case ( real_format )
           case ('g','G','e','E','en','EN','es','ES')
              rl_edit_desc = real_format
           case default
              call throw_exception('Invalid real format, "' // trim(real_format) // '", passed to json_initialize.'// &
                   new_line('a') // 'Acceptable formats are: "G", "E", "EN", and "ES".' )
           end select
        end if

        ! set the default output/input format for reals:
                      write(w,'(ss,I0)',iostat=istat) max_numeric_str_len
        if (istat==0) write(d,'(ss,I0)',iostat=istat) real_precision
        if (istat==0) write(e,'(ss,I0)',iostat=istat) real_exponent_digits
        if (istat==0) then
            real_fmt = '(' // sgn // ',' // trim(rl_edit_desc) // trim(w) // '.' // trim(d) // 'E' // trim(e) // ')'
        else
            real_fmt = '(' // sgn // ',' // trim(rl_edit_desc) // '30.16E3)'  !just use this one (should never happen)
        end if

    end if

    end subroutine json_initialize