import re


def check_conventions_version_number(ds, attr, conv_type, min_ver, max_ver):
    """
    Checks global attribute values in a NetCDF Dataset and returns integer
    regarding whether the `attr` matches number+unit format

    :param ds: netCDF4 Dataset object
    :param attr: global attribute name [string]
    :param conv_type: Name of convention string to be checked for version
    :param min_ver: Minimum version allowed
    :param max_ver: Maximum version allowed
    :return: Integer (0: not found; 1: convention to be checked for not found; 2: convention out of valid range;
    3: all correct)
    """

    if attr not in ds.ncattrs():
        return 0
    global_attr = getattr(ds, attr)

    version = None
    global_attr_split = global_attr.split(' ')
    for conv in global_attr_split:
        if conv_type in conv:
            version = float(re.findall(r"[+]?\d*\.\d+|\d+", conv)[0])

    if not version:
        return 1

    range_check = None
    if conv_type == 'CF':
        range_check = min_ver <= version <= max_ver
    elif conv_type == 'ATMODAT':
        range_check = (version == min_ver) and (version == max_ver)

    if not range_check:
        return 2
    else:
        return 3