read_dp_scalar Subroutine

public subroutine read_dp_scalar(parent, nm, val, exists, default, required)

Arguments

Type IntentOptional Attributes Name
integer(kind=hid_t), intent(in) :: parent
character(len=*), intent(in) :: nm
real(kind=dp), intent(out) :: val
logical, intent(out), optional :: exists
real(kind=dp), intent(in), optional :: default
logical, intent(in), optional :: required

Contents

Source Code


Source Code

    subroutine read_dp_scalar(parent, nm, val, exists, default, required)

        integer(hid_t), intent(in) :: parent
        character(*), intent(in) :: nm
        real(dp), intent(out) :: val
        logical, intent(out), optional :: exists
        logical, intent(in), optional :: required
        real(dp), intent(in), optional :: default
        character(*), parameter :: t_r = 'read_dp_scalar'

        integer(hid_t) :: dataset
        integer(hdf_err) :: err
        logical(hdf_log) :: exists_

        ! Test if the relevant key exists
        call h5lexists_f(parent, nm, exists_, err)
        if (exists_) then
            call h5dopen_f(parent, nm, dataset, err)
            call h5dread_f(dataset, h5kind_to_type(dp, H5_REAL_KIND), val, [1_hsize_t], err)
            if (err /= 0) &
                call stop_all(t_r, 'Read error')
            call h5dclose_f(dataset, err)
        endif

        if (present(required)) then
            if (required .and. .not. exists_) then
                write(stdout, *) nm
                call stop_all(t_r, "Required field does not exist")
            end if
        end if
        if (present(exists)) exists = exists_
        if (present(default) .and. .not. exists_) val = default

    end subroutine read_dp_scalar