get_netcdf_dim_length Function

public function get_netcdf_dim_length(file_id, dim_id) result(length)

Wrapper around nf90_inquire_dimension. Aborts if any errors are detected.

Arguments

Type IntentOptional Attributes Name
integer(kind=kind_nf), intent(in) :: file_id

NetCDF ID of the file

integer(kind=kind_nf), intent(in) :: dim_id

NetCDF ID of the dimension

Return Value integer


Contents

Source Code


Source Code

  function get_netcdf_dim_length(file_id, dim_id) result(length)
    integer :: length
    !> NetCDF ID of the file
    integer(kind_nf), intent(in) :: file_id
    !> NetCDF ID of the dimension
    integer(kind_nf), intent(in) :: dim_id

    ! Temporary variable for the dimension name
    character(len=NF90_MAX_NAME) :: dim_name
    ! NetCDF error status
    integer :: status

    ! This could be less reliant on module-level variables if we
    ! passed in the dimension name and used nf90_inq_dim to get the ID
    status = nf90_inquire_dimension(file_id, dim_id, dim_name, length)
    if (status /= NF90_NOERR) then
      call netcdf_error(status, &
                        dim=trim(dim_name), &
                        message="(get_netcdf_dim_length)", &
                        abort=.true.)
    end if
  end function get_netcdf_dim_length