# Path: hftools/utils.py
# def to_numeric(value, error=True):
#     """Translate string *value* to numeric type if possible
#     """
#     try:
#         return value + 0
#     except TypeError:
#         pass
#     try:
#         return int(value)
#     except ValueError:
#         try:
#             return float(value)
#         except ValueError:
#             try:
#                 if dateregexp.match(value):
#                     return np.datetime64(value)
#                 else:
#                     raise ValueError
#             except (ValueError, TypeError):
#                 if error:
#                     raise
#     return value
# 
# def isrealnumber(x):
#     return isinstance(x, (int, float))


import imp
import re
import numpy as np
import hftools.dataset
from hftools.utils import to_numeric, isrealnumber


def string_number_with_unit_to_value(string_number):
    if isrealnumber(string_number):
        return string_number
    res = reg_value.match(string_number)
    if res:
        value = float(res.group())
        reg_unit = re.compile(r"\s*[[]?([a-zA-Z%]+)[]]?")
        unit_res = reg_unit.match(string_number[res.span()[-1]:])
        if unit_res:
            unit = unit_res.group()
        else:
            unit = None
    else:
        msg = "Could not convert %r to value with unit" % (string_number)
        raise ValueError(msg)

    return convert_with_unit(unit, value)


def convert_with_unit(unit, value):
    if unit is None:
        return hftools.dataset.hfarray(value, unit=None)
    unit = unit.strip()
    if unit:
        mul, unit = unit_to_multiplier(unit)
    else:
        mul = 1
        unit = None

# Path: hftools/utils.py
# def to_numeric(value, error=True):
#     """Translate string *value* to numeric type if possible
#     """
#     try:
#         return value + 0
#     except TypeError:
#         pass
#     try:
#         return int(value)
#     except ValueError:
#         try:
#             return float(value)
#         except ValueError:
#             try:
#                 if dateregexp.match(value):
#                     return np.datetime64(value)
#                 else:
#                     raise ValueError
#             except (ValueError, TypeError):
#                 if error:
#                     raise
#     return value
# 
# def isrealnumber(x):
#     return isinstance(x, (int, float))


# Path: hftools/constants/si_units.py
import imp
import re
import numpy as np
import hftools.dataset
from hftools.utils import to_numeric, isrealnumber



def string_number_with_unit_to_value(string_number):
    if isrealnumber(string_number):
        return string_number
    res = reg_value.match(string_number)
    if res:
        value = float(res.group())
        reg_unit = re.compile(r"\s*[[]?([a-zA-Z%]+)[]]?")
        unit_res = reg_unit.match(string_number[res.span()[-1]:])
        if unit_res:
            unit = unit_res.group()
        else:
            unit = None
    else:
        msg = "Could not convert %r to value with unit" % (string_number)
        raise ValueError(msg)

    return convert_with_unit(unit, value)


def convert_with_unit(unit, value):
    if unit is None:
        return hftools.dataset.hfarray(value, unit=None)
    unit = unit.strip()
    if unit:
        mul, unit = unit_to_multiplier(unit)
    else:
        mul = 1
        unit = None

    return hftools.dataset.hfarray(to_numeric(value, error=True) * mul,