Split igorbinarywave.py off of Hooke into its own package.
[igor.git] / bin / igorbinarywave.py
1 #!/usr/bin/env python
2
3 "IBW -> ASCII conversion"
4
5 import optparse
6 import pprint
7 import sys
8
9 import numpy
10
11 from igor import __version__
12 from igor.binarywave import loadibw
13
14
15 p = optparse.OptionParser(version=__version__)
16
17 p.add_option('-f', '--infile', dest='infile', metavar='FILE',
18              default='-', help='Input IGOR Binary Wave (.ibw) file.')
19 p.add_option('-o', '--outfile', dest='outfile', metavar='FILE',
20              default='-', help='File for ASCII output.')
21 p.add_option('-v', '--verbose', dest='verbose', default=0,
22              action='count', help='Increment verbosity')
23 p.add_option('-n', '--not-strict', dest='strict', default=True,
24              action='store_false', help='Attempt to parse invalid IBW files.')
25
26 options,args = p.parse_args()
27
28 if len(args) > 0 and options.infile == None:
29     options.infile = args[0]
30 if options.infile == '-':
31     options.infile = sys.stdin
32 if options.outfile == '-':
33     options.outfile = sys.stdout
34
35 data,bin_info,wave_info = loadibw(options.infile, strict=options.strict)
36 numpy.savetxt(options.outfile, data, fmt='%g', delimiter='\t')
37 if options.verbose > 0:
38     pprint.pprint(bin_info)
39     pprint.pprint(wave_info)