def modulated_laser(l_par, m_par, modes_dictionary=None,
                    output_node='n_source_out',
                    print_code=False):
    """Generates the kat script for a simple modulated laser source

    Args:
        l_par (LaserParams): laser parameters class instance
        m_par (ModulatorParams): modulator parameters class instance
        modes_dictionary (dict of dicts): dictionary with tem modes
            settings for the laser source. i.e
            {'0 0': {'pwr': 0.7, 'phase': 180},
            '0 1': {'pwr': 0.3, 'phase': -90}}
        output_node(str): name of the source output node
        print_code (bool): whether or not to print the resulting code

    Returns:
        string: kat code for this laser source, can  be attached to other
        pieces to form the kat code for the whole system"""

    kat_code = f"""
    #------------------> Modulated Laser source <-----------------------
    l i1 {l_par.power} {l_par.freq} {l_par.phase} nin1       # input laser 

    s s_i1 0.01 nin1 n_EOM_in            # space between laser and eom

    mod eom1 {m_par.freq} {m_par.midx} {m_par.order} {m_par.mode} {m_par.phase} n_EOM_in {output_node}
    \n"""

    if modes_dictionary:
        kat_code += "    #----- l1 tem modes ---------\n"
        for mode, settings in modes_dictionary.items():
            kat_code += (
                "    tem i1 {mode} {settings['pwr']} {settings['phase']}\n")

    if print_code:
        print(kat_code)

    return kat_code + "\n"