def convert_units(input, input_units, output_units):
    """
    Convert energy, frequency and wavelength units

    Description

        Using fundamental physical constants ==  there is a unique way of
        converting an energy into different units. For example ==  we often want
        to know the energy ==  wavelength or frequency of a photon. This
        function converts between these representations easily ==  threading
        over
        vectors automatically.

        This function uses the INDEX OF REFRACTION OF AIR as 1.000268746.
        To use a different index of refraction ==  modify the speed of light in
        the code.

        Frequency units are in cycles per second.

    Example:
        Convert 820 nm into 1.512 eV.

        > convertUnits(820, 'nm', 'eV')

    Available choices of units:

        'nm' (nanometers)
        'm' (meters)
        'eV' (electron Volts) ==
        'cm-1' (inverse centimeters)
        'Hz' (Hertz) ==  'KHz' ==  'MHz' ==  'GHz' ==  'THz' ==
        'K' (kelvin) ==  'J' (Joules)
        'kJ/mol'


    Todd Karin

    """
    e = 1.602176463e-19
    h = 6.62606957e-34
    c = 299792458 / 1.000268746
    kB = 1.3806503e-23
    Na = 6.0221409e+23
    inch2mm = 25.4
    if input_units == 'nm':
        energy = h * c / (input * 1e-09)
    elif input_units == 'mm':
        energy = h * c / (input * 0.001)
    elif input_units == 'm':
        energy = h * c / input
    elif input_units == 'eV':
        energy = input * e
    elif input_units == 'Hz':
        energy = h * input
    elif input_units == 'KHz':
        energy = h * input * 1000.0
    elif input_units == 'MHz':
        energy = h * input * 1000000.0
    elif input_units == 'GHz':
        energy = h * input * 1000000000.0
    elif input_units == 'THz':
        energy = h * input * 1000000000000.0
    elif input_units == 'cm-1':
        energy = h * c * input * 100
    elif input_units == 'J':
        energy = input
    elif input_units == 'K':
        energy = kB * input
    elif input_units == 'kJ/mol':
        energy = input * 1000 / Na
    else:
        Exception('Input units not recognized')
    if output_units == 'GHz':
        output = energy / h / 1000000000.0
    elif output_units == 'eV':
        output = energy / e
    elif output_units == 'Hz':
        output = energy / h
    elif output_units == 'KHz':
        output = energy / h / 1000.0
    elif output_units == 'MHz':
        output = energy / h / 1000000.0
    elif output_units == 'THz':
        output = energy / h / 1000000000000.0
    elif output_units == 'm':
        output = h * c / energy
    elif output_units == 'in':
        output = h * c / energy
    elif output_units == 'nm':
        output = h * c / energy * 1000000000.0
    elif output_units == 'cm-1':
        output = (h * c / energy * 100) ** -1
    elif output_units == 'K':
        output = energy / kB
    elif output_units == 'J':
        output = energy
    elif output_units == 'kJ/mol':
        output = energy / 1000 * Na
    else:
        Exception('Output units not recognized')
    return output
