<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write(tsdict, outfile, start=None, end=None, name='gwpy', run=0):
 """Write data to a GWF file using the LALFrame API """

    if not start:
        start = list(tsdict.values())[0].xspan[0]
    if not end:
        end = list(tsdict.values())[0].xspan[1]
    duration = end - start

    # get ifos list
    detectors = 0
    for series in tsdict.values():
        try:
            idx = list(lalutils.LAL_DETECTORS.keys()).index(series.channel.ifo)
            detectors |= 1 << 2*idx
        except (KeyError, AttributeError):
            continue

    # create new frame
    frame = lalframe.FrameNew(start, duration, name, run, 0, detectors)

    for series in tsdict.values():
        # convert to LAL
        lalseries = series.to_lal()

        # find adder
        add_ = lalutils.find_typed_function(
            series.dtype, 'FrameAdd', 'TimeSeriesProcData', module=lalframe)

        # add time series to frame
        add_(frame, lalseries)

    # write frame
    lalframe.FrameWrite(frame, outfile)