def METHOD_NAME(outdir, stationname, prefix, chan):
    longchan = longchannels[channel_dict[chan]]
    outfilename = '%s_%s.%s.mseed' % (stationname.upper(), prefix, longchan)
    outfn = op.join(outdir, outfilename)
    if op.exists(outfn):
        file_exists = True
        number = 1
        while file_exists:
            outfilename = '%s_%s.%s.%i.mseed' % (
                stationname.upper(), prefix, longchan, number)
            outfn = op.join(outdir, outfilename)
            if not op.exists(outfn):
                file_exists = False
            number += 1
    return outfn