r'''Determines the maximum length of a heat exchanger tube can go without
    a support, acording to TEMA [1]_. The limits provided apply for the 
    worst-case temperature allowed for the material to be used at.

    Parameters
    ----------
    Do : float
        Outer tube diameter, [m]
    material : str
        Material type, either 'CS' or 'aluminium', [-]

    Returns
    -------
    L_unsupported : float
        Maximum length of unsupported tube, [m]

    Notes
    -----
    The 'CS' results is also listed as representing high alloy steel, low 
    alloy steel, nickel-copper, nickel, and nickel-chromium-iron alloys.
    The 'aluminium' results are those of copper and copper alloys and
    also titanium alloys.
    
    The maximum and minimum tube outer diameter tabulated are 3 inch and 1/4  
    inch respectively. The result is returned for the nearest tube diameter
    equal or smaller than the provided diameter, which helps ensures the 
    returned tube length will not be optimistic. However, if the diameter is 
    under 0.25 inches, the result will be optimistic!
    
    
    Examples
    --------
    >>> L_unsupported_max(Do=.0254, material='CS')
    1.88

    References
    ----------
    .. [1] Standards of the Tubular Exchanger Manufacturers Association,
       Ninth edition, 2007, TEMA, New York, p 5.4-5.

def L_unsupported_max(Do, material='CS'):
    r'''Determines the maximum length of a heat exchanger tube can go without
    a support, acording to TEMA [1]_. The limits provided apply for the 
    worst-case temperature allowed for the material to be used at.

    Parameters
    ----------
    Do : float
        Outer tube diameter, [m]
    material : str
        Material type, either 'CS' or 'aluminium', [-]

    Returns
    -------
    L_unsupported : float
        Maximum length of unsupported tube, [m]

    Notes
    -----
    The 'CS' results is also listed as representing high alloy steel, low 
    alloy steel, nickel-copper, nickel, and nickel-chromium-iron alloys.
    The 'aluminium' results are those of copper and copper alloys and
    also titanium alloys.
    
    The maximum and minimum tube outer diameter tabulated are 3 inch and 1/4  
    inch respectively. The result is returned for the nearest tube diameter
    equal or smaller than the provided diameter, which helps ensures the 
    returned tube length will not be optimistic. However, if the diameter is 
    under 0.25 inches, the result will be optimistic!
    
    
    Examples
    --------
    >>> L_unsupported_max(Do=.0254, material='CS')
    1.88

    References
    ----------
    .. [1] Standards of the Tubular Exchanger Manufacturers Association,
       Ninth edition, 2007, TEMA, New York, p 5.4-5.
    '''
    Do = Do/inch # convert diameter to inches
    i = bisect(_L_unsupported_Do, Do)-1
    i = i if i < 11 else 11 # bisect returns 1+ if above the index
    i = 0 if i == -1 else i
    if material == 'CS':
        return _L_unsupported_steel[i]
    elif material == 'aluminium':
        return _L_unsupported_aluminium[i]
    else:
        raise Exception('Material argument should be one of "CS" or "aluminium"')