def write_catalog(event_list, max_sep=<NUM_LIT:8>, min_link=<NUM_LIT:8>, debug=<NUM_LIT:0>):
<EOL>event_list = list(event_list)<EOL>f = open('<STR_LIT>', '<STR_LIT:w>')<EOL>f2 = open('<STR_LIT>', '<STR_LIT:w>')<EOL>fphase = open('<STR_LIT>', '<STR_LIT:w>')<EOL>stations = []<EOL>evcount = <NUM_LIT:0><EOL>for i, master in enumerate(event_list):<EOL><INDENT>master_sfile = master[<NUM_LIT:1>]<EOL>master_event_id = master[<NUM_LIT:0>]<EOL>master_event = read_nordic(master_sfile)[<NUM_LIT:0>]<EOL>master_ori_time = master_event.origins[<NUM_LIT:0>].time<EOL>master_location = (master_event.origins[<NUM_LIT:0>].latitude,<EOL>master_event.origins[<NUM_LIT:0>].longitude,<EOL>master_event.origins[<NUM_LIT:0>].depth / <NUM_LIT:1000>)<EOL>if len(master_event.magnitudes) > <NUM_LIT:0>:<EOL><INDENT>master_magnitude = master_event.magnitudes[<NUM_LIT:0>].mag or '<STR_LIT:U+0020>'<EOL><DEDENT>else:<EOL><INDENT>master_magnitude = '<STR_LIT:U+0020>'<EOL><DEDENT>header = '<STR_LIT>' +master_ori_time.strftime('<STR_LIT>') +'<STR_LIT:U+0020>' + str(master_location[<NUM_LIT:0>]).ljust(<NUM_LIT:8>) + '<STR_LIT:U+0020>' +str(master_location[<NUM_LIT:1>]).ljust(<NUM_LIT:8>) + '<STR_LIT:U+0020>' +str(master_location[<NUM_LIT:2>]).ljust(<NUM_LIT:4>) + '<STR_LIT:U+0020>' +str(master_magnitude).ljust(<NUM_LIT:4>) + '<STR_LIT>' +str(master_event_id).rjust(<NUM_LIT:4>)<EOL>fphase.write(header + '<STR_LIT:\n>')<EOL>for pick in master_event.picks:<EOL><INDENT>if not hasattr(pick, '<STR_LIT>') or len(pick.phase_hint) == <NUM_LIT:0>:<EOL><INDENT>warnings.warn('<STR_LIT>')<EOL>print(pick)<EOL>continue<EOL><DEDENT>if pick.phase_hint[<NUM_LIT:0>].upper() in ['<STR_LIT:P>', '<STR_LIT:S>']:<EOL><INDENT>weight = [arrival.time_weight<EOL>for arrival in master_event.origins[<NUM_LIT:0>].arrivals<EOL>if arrival.pick_id == pick.resource_id][<NUM_LIT:0>]<EOL>if weight == <NUM_LIT:0>:<EOL><INDENT>weight = <NUM_LIT:1.0><EOL><DEDENT>elif weight == <NUM_LIT:9>:<EOL><INDENT>weight = <NUM_LIT:0.0><EOL><DEDENT>else:<EOL><INDENT>weight = <NUM_LIT:1> - weight / <NUM_LIT><EOL><DEDENT>fphase.write(pick.waveform_id.station_code + '<STR_LIT:U+0020>' +<EOL>_cc_round(pick.time -<EOL>master_ori_time, <NUM_LIT:3>).rjust(<NUM_LIT:6>) +<EOL>'<STR_LIT:U+0020>' + str(weight).ljust(<NUM_LIT:5>) +<EOL>pick.phase_hint + '<STR_LIT:\n>')<EOL><DEDENT><DEDENT>for j in range(i + <NUM_LIT:1>, len(event_list)):<EOL><INDENT>slave_sfile = event_list[j][<NUM_LIT:1>]<EOL>slave_event_id = event_list[j][<NUM_LIT:0>]<EOL>event_text = '<STR_LIT:#>' + str(master_event_id).rjust(<NUM_LIT:10>) +str(slave_event_id).rjust(<NUM_LIT:10>) + '<STR_LIT:\n>'<EOL>event_text2 = '<STR_LIT:#>' + str(master_event_id).rjust(<NUM_LIT:10>) +str(slave_event_id).rjust(<NUM_LIT:10>) + '<STR_LIT:\n>'<EOL>slave_event = read_nordic(slave_sfile)[<NUM_LIT:0>]<EOL>slave_ori_time = slave_event.origins[<NUM_LIT:0>].time<EOL>slave_location = (slave_event.origins[<NUM_LIT:0>].latitude,<EOL>slave_event.origins[<NUM_LIT:0>].longitude,<EOL>slave_event.origins[<NUM_LIT:0>].depth / <NUM_LIT:1000>)<EOL>if dist_calc(master_location, slave_location) > max_sep:<EOL><INDENT>continue<EOL><DEDENT>links = <NUM_LIT:0>  <EOL>for pick in master_event.picks:<EOL><INDENT>if not hasattr(pick, '<STR_LIT>') orlen(pick.phase_hint) == <NUM_LIT:0>:<EOL><INDENT>continue<EOL><DEDENT>if pick.phase_hint[<NUM_LIT:0>].upper() not in ['<STR_LIT:P>', '<STR_LIT:S>']:<EOL><INDENT>continue<EOL><DEDENT>slave_matches = [p for p in slave_event.picks<EOL>if hasattr(p, '<STR_LIT>') and<EOL>p.phase_hint == pick.phase_hint and<EOL>p.waveform_id.station_code.upper() ==<EOL>pick.waveform_id.station_code.upper()]<EOL>for slave_pick in slave_matches:<EOL><INDENT>links += <NUM_LIT:1><EOL>master_weight = [arrival.time_weight<EOL>for arrival in master_event.<EOL>origins[<NUM_LIT:0>].arrivals<EOL>if arrival.pick_id == pick.resource_id][<NUM_LIT:0>]<EOL>slave_weight = [arrival.time_weight<EOL>for arrival in slave_event.<EOL>origins[<NUM_LIT:0>].arrivals<EOL>if arrival.pick_id ==<EOL>slave_pick.resource_id][<NUM_LIT:0>]<EOL>master_weight = str(int(master_weight))<EOL>slave_weight = str(int(slave_weight))<EOL>event_text += pick.waveform_id.station_code.ljust(<NUM_LIT:5>) +_cc_round(pick.time - master_ori_time, <NUM_LIT:3>).rjust(<NUM_LIT:11>) +_cc_round(slave_pick.time -<EOL>slave_ori_time, <NUM_LIT:3>).rjust(<NUM_LIT:8>) +_av_weight(master_weight, slave_weight).rjust(<NUM_LIT:7>) +'<STR_LIT:U+0020>' + pick.phase_hint + '<STR_LIT:\n>'<EOL>event_text2 += pick.waveform_id.station_code.ljust(<NUM_LIT:5>) +_cc_round(pick.time - master_ori_time, <NUM_LIT:3>).rjust(<NUM_LIT:11>) +_cc_round(slave_pick.time -<EOL>slave_ori_time, <NUM_LIT:3>).rjust(<NUM_LIT:8>) +_av_weight(master_weight, slave_weight).rjust(<NUM_LIT:7>) +'<STR_LIT:U+0020>' + pick.phase_hint + '<STR_LIT:\n>'<EOL>stations.append(pick.waveform_id.station_code)<EOL><DEDENT><DEDENT>if links >= min_link:<EOL><INDENT>f.write(event_text)<EOL>f2.write(event_text2)<EOL>evcount += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>print('<STR_LIT>' + str(evcount) + '<STR_LIT>')<EOL>f.close()<EOL>f2.close()<EOL>fphase.close()<EOL>return list(set(stations))<EOL>
Generate a dt.ct for hypoDD for a series of events.

Takes input event list from
:func:`eqcorrscan.utils.catalog_to_dd.write_event` as a list of tuples of
event id and sfile.  It will read the pick information from the seisan
formated s-file using the sfile_util utilities.

:type event_list: list
:param event_list: List of tuples of event_id (int) and sfile (String)
:type max_sep: float
:param max_sep: Maximum separation between event pairs in km
:type min_link: int
:param min_link:
    Minimum links for an event to be paired, e.g. minimum number of picks
    from the same station and channel (and phase) that are shared between
    two events for them to be paired.
:type debug: int
:param debug: Debug output level.

:returns: list of stations that have been used in this catalog

.. note::
    We have not yet implemented a method for taking unassociated event
    objects and wavefiles.  As such if you have events with associated
    wavefiles you are advised to generate Sfiles for each event using
    the :mod:`eqcorrscan.utils.sfile_util` module prior to this step.