#!/usr/bin/env python

"""
test of file_scanner -- to compare with Darren Dale's example
"""

import numpy as np
from maproomlib.utility import file_scanner

def gen_file():
    f = file('test.dat', 'w')
    for i in range(1200):
        f.write('1 ' * 2048)
        f.write('\n')
    f.close()
    
def read_file1():
    """ read unknown length: doubles"""
    f = file('test.dat')
    arr = file_scanner.FileScan(f)
    f.close()
    return arr

def read_file2():
    """ read known length: doubles"""
    f = file('test.dat')
    arr = file_scanner.FileScanN(f, 1200*2048)
    f.close()
    return arr

def read_file3():
    """ read known length: singles"""
    f = file('test.dat')
    arr = file_scanner.FileScanN_single(f, 1200*2048)
    f.close()
    return arr

def read_fromfile1():
    """ read unknown length with fromfile(): singles"""
    f = file('test.dat')
    arr = np.fromfile(f, dtype=np.float32, sep=' ')
    f.close()
    return arr

def read_fromfile2():
    """ read unknown length with fromfile(): doubles"""
    f = file('test.dat')
    arr = np.fromfile(f, dtype=np.float64, sep=' ')
    f.close()
    return arr

def read_fromstring1():
    """ read unknown length with fromfile(): singles"""
    f = file('test.dat')
    str = f.read()
    arr = np.fromstring(str, dtype=np.float32, sep=' ')
    f.close()
    return arr
    