def filter_lines(infile,outfile,wind,nskip=0) :
    """ Read from input linelist file, output comments and lines falling in windows of [w1,w2] to outfile

    Args :
        infile (str) : name of input file
        outfile (str) : name of output file
        wind (list of [w1,w2] pairs) : list of window ranges
        nskip (int) : number of header lines to skip (default=0)

    Returns :
        nout (int) : number of windows
    """
    fin=open(infile,'r')
    fout=open(outfile,'w')
    nout = 0
    nwind=wind.shape[0]
    for iline,line in enumerate(fin) :
        if iline >= nskip : 
            w=line.split()[0]
            if w[0] == '#' :
                    fout.write(line)
            else :
              for i in range(nwind) :
                if (float(w) >= wind[i,0]) and (float(w) <=wind[i,1]) :
                    fout.write(line)
                    nout+=1
    fout.close()
    return nout