<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># -*- coding: utf-8 -*-
# Nicolas Enfon - 01/04/14 - LSIS DYNI
""" Reading of .log files from MobySound and .dat files
 produced by scattering """
import csv
#TODO: chuck the other readfile.py versions, keep this one

def readlog(logname, freq=False):
    """ Returns the .log file in a matrix """
    #Reading the file (start time, end time, low freq, high freq)
    file = open(logname, 'r')
    data = []
    #skipping header
    line = file.readline()
    line = file.readline()
    #we read the file and store the values into data
    while line != '':
        linesplit = line.split()
        if freq == True:
            data.append([float(linesplit[0]),float(linesplit[1]),float(linesplit[2]),float(linesplit[3])])
        else:
            data.append([float(linesplit[0]),float(linesplit[1])])
        line = file.readline()
    file.close()
    return data


def readdat(datname):
    """ Returns the .dat file in a matrix (list of lists) """
    file = open(datname, 'r')
    reader = csv.reader(file)
    data = []
    for row in reader:
	data.append([])
	for col in row:
	    data[-1].append(float(col))
    file.close()
    return data


def cutdat(datname, n):
    """ Returns part of the .dat file: only the first n columns """
    file = open(datname, 'r')
    reader = csv.reader(file)
    data = []
    for row in reader:
        data.append([])
	i = 0
        for col in row:
            data[-1].append(float(col))
	    i += 1
	    if i &gt;= n:
		break
    file.close()
    return data



if __name__ == "__main__":
    matrix = readdat('ANTARES_66458.8._01_09_2012_22.59.54_02.00.41_T4_Q20_J40_scalo1_L1.dat')
    print 'len(mat)', len(matrix)
    print 'len(mat[0])', len(matrix[0])
</pre></body></html>