r'''Determines the thickness of baffles and support plates in TEMA HX
    [1]_. Applies to latitudinal baffles along the diameter of the HX, but
    not longitudinal baffles parallel to the tubes.

    Parameters
    ----------
    Dshell : float
        Shell inner diameter, [m]
    L_unsupported : float
        Distance between tube supports, [m]
    service : str
        Service type, C, R or B, [-]

    Returns
    -------
    t : float
        Baffle or support plate thickness, [m]

    Notes
    -----
    No checks are implemented to ensure the given shell size is TEMA compatible.
    The baffles do not need to be strongas the pressure is almost the same on 
    both of their sides. `L_unsupported` is a design choice; the more baffles
    in a given length, the higher the pressure drop.

    Examples
    --------
    >>> baffle_thickness(Dshell=.3, L_unsupported=50, service='R')
    0.0095

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

def baffle_thickness(Dshell, L_unsupported, service='C'):
    r'''Determines the thickness of baffles and support plates in TEMA HX
    [1]_. Applies to latitudinal baffles along the diameter of the HX, but
    not longitudinal baffles parallel to the tubes.

    Parameters
    ----------
    Dshell : float
        Shell inner diameter, [m]
    L_unsupported : float
        Distance between tube supports, [m]
    service : str
        Service type, C, R or B, [-]

    Returns
    -------
    t : float
        Baffle or support plate thickness, [m]

    Notes
    -----
    No checks are implemented to ensure the given shell size is TEMA compatible.
    The baffles do not need to be strongas the pressure is almost the same on 
    both of their sides. `L_unsupported` is a design choice; the more baffles
    in a given length, the higher the pressure drop.

    Examples
    --------
    >>> baffle_thickness(Dshell=.3, L_unsupported=50, service='R')
    0.0095

    References
    ----------
    .. [1] Standards of the Tubular Exchanger Manufacturers Association,
       Ninth edition, 2007, TEMA, New York.
    '''
    if Dshell < 0.381:
        j = 0
    elif 0.381 <= Dshell < 0.737:
        j = 1
    elif 0.737 <= Dshell < 0.991:
        j = 2
    elif 0.991 <= Dshell  < 1.524:
        j = 3
    else:
        j = 4

    if service == 'R':
        if L_unsupported <= 0.61:
            i = 0
        elif 0.61 < L_unsupported <= 0.914:
            i = 1
        elif 0.914 < L_unsupported <= 1.219:
            i = 2
        elif 1.219 < L_unsupported <= 1.524:
            i = 3
        else:
            i = 4
        t = _TEMA_baffles_refinery[j][i]

    elif service == 'C' or service == 'B':
        if L_unsupported <= 0.305:
            i = 0
        elif 0.305 < L_unsupported <= 0.610:
            i = 1
        elif 0.61 < L_unsupported <= 0.914:
            i = 2
        elif 0.914 < L_unsupported <= 1.219:
            i = 3
        elif 1.219 < L_unsupported <= 1.524:
            i = 4
        else:
            i = 5
        t = _TEMA_baffles_other[j][i]
    return t