igorbinarywave.py 1.16 KB
Newer Older
1
#!/usr/bin/env python
2
3
#
# Copyright
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

"IBW -> ASCII conversion"

import optparse
import pprint
import sys

import numpy

from igor import __version__
from igor.binarywave import loadibw


p = optparse.OptionParser(version=__version__)

p.add_option('-f', '--infile', dest='infile', metavar='FILE',
             default='-', help='Input IGOR Binary Wave (.ibw) file.')
p.add_option('-o', '--outfile', dest='outfile', metavar='FILE',
             default='-', help='File for ASCII output.')
p.add_option('-v', '--verbose', dest='verbose', default=0,
             action='count', help='Increment verbosity')
p.add_option('-n', '--not-strict', dest='strict', default=True,
             action='store_false', help='Attempt to parse invalid IBW files.')

options,args = p.parse_args()

if len(args) > 0 and options.infile == None:
    options.infile = args[0]
if options.infile == '-':
    options.infile = sys.stdin
if options.outfile == '-':
    options.outfile = sys.stdout

data,bin_info,wave_info = loadibw(options.infile, strict=options.strict)
numpy.savetxt(options.outfile, data, fmt='%g', delimiter='\t')
if options.verbose > 0:
    pprint.pprint(bin_info)
    pprint.pprint(wave_info)