"IBW -> ASCII conversion"
-import logging
-import optparse
import pprint
-import sys
import numpy
-from igor import __version__, LOG
from igor.binarywave import load
+from igor.script import Script
-p = optparse.OptionParser(version=__version__)
+def run(args):
+ wave = load(args.infile)
+ numpy.savetxt(args.outfile, wave['wave']['wData'], fmt='%g', delimiter='\t')
+ if args.verbose > 0:
+ wave['wave'].pop('wData')
+ pprint.pprint(wave)
-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')
-
-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
-
-if options.verbose > 1:
- log_levels = [logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG]
- log_level = log_levels[min(options.verbose-1, len(log_levels)-1)]
- LOG.setLevel(log_level)
-
-wave = load(options.infile)
-numpy.savetxt(options.outfile, wave['wave']['wData'], fmt='%g', delimiter='\t')
-if options.verbose > 0:
- wave['wave'].pop('wData')
- pprint.pprint(wave)
+s = Script(description=__doc__)
+s._run = run
+s.run()
--- /dev/null
+#!/usr/bin/env python
+#
+# Copyright
+
+"PXP -> ASCII conversion"
+
+import pprint
+
+import numpy
+
+from igor.packed import load
+from igor.script import Script
+
+
+def run(args):
+ records,filesystem = load(args.infile)
+ if hasattr(args.outfile, 'write'):
+ f = args.outfile # filename is actually a stream object
+ else:
+ f = open(args.outfile, 'w')
+ try:
+ f.write(pprint.pformat(records))
+ f.write('\n')
+ finally:
+ if f != args.outfile:
+ f.close()
+ if args.verbose > 0:
+ pprint.pprint(filesystem)
+
+s = Script(description=__doc__, filetype='IGOR Packed Experiment (.pxp) file')
+s._run = run
+s.run()
--- /dev/null
+# Copyright
+
+"Common code for scripts distributed with the `igor` package."
+
+from __future__ import absolute_import
+import argparse as _argparse
+import logging as _logging
+import sys as _sys
+
+from . import __version__
+from . import LOG as _LOG
+
+
+class Script (object):
+ log_levels = [_logging.ERROR, _logging.WARNING, _logging.INFO, _logging.DEBUG]
+
+ def __init__(self, description=None, filetype='IGOR Binary Wave (.ibw) file'):
+ self.parser = _argparse.ArgumentParser(
+ description=description, version=__version__)
+ self.parser.add_argument(
+ '-f', '--infile', metavar='FILE', default='-',
+ help='input {}'.format(filetype))
+ self.parser.add_argument(
+ '-o', '--outfile', metavar='FILE', default='-',
+ help='file for ASCII output')
+ self.parser.add_argument(
+ '-V', '--verbose', action='count', default=0,
+ help='increment verbosity')
+
+ def run(self, *args, **kwargs):
+ args = self.parser.parse_args(*args, **kwargs)
+ if args.infile == '-':
+ args.infile = _sys.stdin
+ if args.outfile == '-':
+ args.outfile = _sys.stdout
+ if args.verbose > 1:
+ log_level = self.log_levels[min(args.verbose-1, len(self.log_levels)-1)]
+ _LOG.setLevel(log_level)
+ self._run(args)
+
+ def _run(self, args):
+ raise NotImplementedError()