parse_initialiser_section_line Subroutine

subroutine parse_initialiser_section_line(line, state, parsed, section)

Parse one line from the initialiser section.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: line

Current JSON line to parse

type(json_initialiser_state_type), intent(inout) :: state

Mutable parser state for the active initialiser object

type(json_parse_result_type), intent(inout) :: parsed

Parsed ONNX content accumulated so far

character(len=32), intent(inout) :: section

Current top-level JSON section name


Source Code

  subroutine parse_initialiser_section_line(line, state, parsed, section)
    !! Parse one line from the initialiser section.
    implicit none

    ! Arguments
    character(*), intent(in) :: line
    !! Current JSON line to parse
    type(json_initialiser_state_type), intent(inout) :: state
    !! Mutable parser state for the active initialiser object
    type(json_parse_result_type), intent(inout) :: parsed
    !! Parsed ONNX content accumulated so far
    character(32), intent(inout) :: section
    !! Current top-level JSON section name

    ! Local variables
    integer :: pos, pos2
    !! Temporary string positions used to slice the rawData field

    if(.not.state%in_object .and. is_json_object_start(line))then
       call reset_initialiser_state(state)
       state%in_object = .true.
       return
    end if

    if(state%in_object)then
       if(state%in_dims_array)then
          call append_json_int_string_item(line, state%dims)
          if(index(line, ']') .gt. 0) state%in_dims_array = .false.
          return
       end if

       if(index(line, '}') .gt. 0 .and. index(line, '"rawData"') .eq. 0 .and. &
            index(line, '"dims"') .eq. 0)then
          call store_initialiser_state(state, parsed)
          state%in_object = .false.
          return
       end if

       if(index(line, '"dims"') .gt. 0)then
          call parse_json_int_array_from_strings(line, state%dims)
          if(index(line, '[') .gt. 0 .and. index(line, ']') .eq. 0)then
             state%in_dims_array = .true.
          end if
          return
       end if

       if(index(line, '"dataType"') .gt. 0)then
          call extract_json_int(line, '"dataType"', state%data_type)
          return
       end if

       if(index(line, '"name"') .gt. 0)then
          call extract_json_string(line, '"name"', state%name)
          return
       end if

       if(index(line, '"rawData"') .gt. 0)then
          pos = index(line, '"rawData"') + 9
          pos2 = index(line(pos:), '"')
          if(pos2 .gt. 0)then
             pos = pos + pos2
             pos2 = index(line(pos:), '"')
             if(pos2 .gt. 0) state%raw_data = line(pos:pos+pos2-2)
          end if
          return
       end if
    end if

    if(index(line, ']') .gt. 0 .and. .not.state%in_object) section = ''

  end subroutine parse_initialiser_section_line