def FindStarts(Start,
               End,
               AllGaps,
               RunTime,
               random_starts=True,
               interval=None):
    # find the start times:
    TotalHours = Timedelta2Hours(End - Start - RunTime)
    StartHours = []
    StartTimes = [[] for i in range(len(setup.Seasons))]
    Done = 0
    count = 1
    print TotalHours
    while not Done:
        if random_starts == False:
            StartHour = count * interval
            count = count + 1
        else:
            StartHour = random.randint(0, TotalHours)
        if not StartHour in StartHours:
            StartHours.append(StartHour)
            if len(StartHours) >= TotalHours:
                print "I can't find %i valid starts in the records!" % setup.NumStarts
                raise ValueError()
            StartTime = Start + timedelta(hours=StartHour)
            if not AllGaps.TimeInGap(StartTime, RunTime):
                for i in range(len(setup.Seasons)):
                    if StartTime.month in setup.Seasons[i][1]:
                        StartTimes[i].append(StartTime)
                        if len(StartTimes[i]) >= setup.NumStarts:
                            print "done with", setup.Seasons[i][0]
                            setup.Seasons[i][1] = []
                        StillToDo = 0
                        for season in setup.Seasons:
                            if season[1]:
                                StillToDo = 1
                        if not StillToDo:
                            Done = 1
            else:
                print StartTime, "is in a gap"

    for i in range(len(setup.Seasons)):
        stats = {}
        outfilename = os.path.join(setup.RootDir,
                                   setup.Seasons[i][0] + "Starts.txt")
        outfile = open(outfilename, 'w')
        print "Writing:", outfilename
        #print setup.Seasons[i][0]
        for time in StartTimes[i]:
            stats[time.year] = stats.setdefault(time.year, 1) + 1
            outfile.write(batch_gnome.DT2str(time) + "\n")
        outfile.close()
        for year, num in stats.items():
            print year, num
                                           "Machine%i" % MachineNum)
                if not os.path.isdir(MachinePath):
                    os.mkdir(MachinePath)
                    print "creating:", MachinePath
                cfile.CommandFileName = os.path.join(MachinePath,
                                                     "command.txt")
            RunNum += 1
            #print "Run number is:", RunNum
            start_time = time.rstrip()
            filename = "time" + string.zfill( ` i + 1 `, 3) + ".nc"
            TrajectoryFile.write(os.path.join(OutputFilePath, filename + '\n'))
            if setup.ReleaseLength == 0:
                end_time = None
            else:
                end_time = batch_gnome.str2DT(start_time) + timedelta(
                    hours=setup.ReleaseLength)
                end_time = batch_gnome.DT2str(end_time)
            Run = batch_gnome.TapRun(start_time,
                                     end_time,
                                     batch_gnome.ConvertToNW(Site),
                                     filename,
                                     OutputFilePath,
                                     Windage=setup.LE_Windage)
            cfile.AddRun(Run)

TrajectoryFile.close()

if cfile.Runs:
    print "Writing command file:", cfile.CommandFileName
    cfile.write()