ref: 1e37adec4dc504c99185e178b4a16934e53b6c55
dir: /python/aubio/txtfile.py/
"""Copyright (C) 2004 Paul Brossier <piem@altern.org>
print aubio.__LICENSE__ for the terms of use
"""
__LICENSE__ = """\
Copyright (C) 2004 Paul Brossier <piem@altern.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
"""
def read_datafile(filename,depth=-1):
"""read list data from a text file (columns of float)"""
if filename == '--' or filename == '-':
import sys
fres = sys.stdin
else:
fres = open(filename,'ro')
l = []
while 1:
tmp = fres.readline()
if not tmp : break
else: tmp = tmp.split()
if depth > 0:
for i in range(min(depth,len(tmp))):
tmp[i] = float(tmp[i])
l.append(tmp)
elif depth == 0:
l.append(float(tmp[0]))
else:
for i in range(len(tmp)):
tmp[i] = float(tmp[i])
l.append(tmp)
return l