fson_parse Function

public function fson_parse(file, unit) result(p)

Arguments

Type IntentOptional AttributesName
character(len=*), intent(in) :: file
integer, intent(inout), optional :: unit

Return Value type(fson_value), pointer


Contents

Source Code


Source Code

  function fson_parse(file, unit) result(p)
    use fson_value_m, only: fson_value_create
    implicit none

    type(fson_value), pointer :: p
    integer, optional, intent(inout) :: unit
    character(len = *), intent(in) :: file
    logical :: unit_available
    integer :: u
    ! init the pointer to null
    nullify(p)

    ! select the file unit to use
    if (present(unit)) then
       u = unit
    else
       ! find the first available unit
       unit_available = .false.
       u = 20

       do while (.not.unit_available)
          inquire(unit=u, exist=unit_available)
          u = u + 1
       end do
    end if

    ! open the file
    open (unit=u, file=file, status="old", action="read", &
         form="formatted", position="rewind")

    ! create the value and associate the pointer
    p => fson_value_create()

    ! parse as a value
    call parse_value(unit=u, value=p)

    ! close the file
    if ( .not. present(unit)) then
       close (u)
    end if

  end function fson_parse