From 101d0300c24d79689dd79a42af418c6138805868 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 4 Jun 2010 02:46:11 -0400 Subject: [PATCH] Automatically split version 5 Igor wave files into columns --- hooke/driver/igorbinarywave.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/hooke/driver/igorbinarywave.py b/hooke/driver/igorbinarywave.py index d0cf2e9..07e3f03 100644 --- a/hooke/driver/igorbinarywave.py +++ b/hooke/driver/igorbinarywave.py @@ -1,8 +1,5 @@ #!/usr/bin/python # -# igorbinarywave provides pure Python interface between IGOR Binary -# Wave files and Numpy arrays. -# # Copyright (C) 2010 W. Trevor King # # This file is part of Hooke. @@ -21,6 +18,14 @@ # License along with Hooke. If not, see # . +"""igorbinarywave provides pure Python interface between IGOR Binary +Wave files and Numpy arrays. + +This is basically a stand-alone package that we bundle into Hooke for +convenience. It is used by the mfp*d drivers, whose data is saved in +IBW files. +""" + # Based on WaveMetric's Technical Note 003, "Igor Binary Format" # ftp://ftp.wavemetrics.net/IgorPro/Technical_Notes/TN003.zip # From ftp://ftp.wavemetrics.net/IgorPro/Technical_Notes/TN000.txt @@ -469,10 +474,15 @@ def loadibw(filename): ('%d, %d, %d, %s' % (waveDataSize, wave_info['npnts'], t.itemsize, t)) tail_data = array.array('f', b[-tail:]) data_b = buffer(buffer(tail_data) + f.read(waveDataSize-tail)) + if version == 5: + shape = [n for n in wave_info['nDim'] if n > 0] + else: + shape = (wave_info['npnts'],) data = numpy.ndarray( - wave_info['npnts'], + shape=shape, dtype=t.newbyteorder(byteOrder), - buffer=data_b + buffer=data_b, + order='F', ) finally: if not hasattr(filename, 'read'): @@ -517,7 +527,7 @@ if __name__ == '__main__': options.outfile = sys.stdout data,bin_info,wave_info = loadibw(options.infile) - numpy.savetxt(options.outfile, data, fmt='%g', delimiter='\n') + numpy.savetxt(options.outfile, data, fmt='%g', delimiter='\t') if options.verbose > 0: import pprint pprint.pprint(bin_info) -- 2.26.2