igor: Bump to 0.3
[igor.git] / bin / igorpackedexperiment.py
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2012 W. Trevor King <wking@tremily.us>
4 #
5 # This file is part of igor.
6 #
7 # igor is free software: you can redistribute it and/or modify it under the
8 # terms of the GNU Lesser General Public License as published by the Free
9 # Software Foundation, either version 3 of the License, or (at your option) any
10 # later version.
11 #
12 # igor is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
15 # details.
16 #
17 # You should have received a copy of the GNU Lesser General Public License
18 # along with igor.  If not, see <http://www.gnu.org/licenses/>.
19
20 "PXP -> ASCII conversion"
21
22 import pprint
23
24 from igor.packed import load, walk
25 from igor.record.wave import WaveRecord
26 from igor.script import Script
27
28
29 class PackedScript (Script):
30     def _run(self, args):
31         self.args = args
32         records,filesystem = load(args.infile)
33         if hasattr(args.outfile, 'write'):
34             f = args.outfile  # filename is actually a stream object
35         else:
36             f = open(args.outfile, 'w')
37         try:
38             f.write(pprint.pformat(records))
39             f.write('\n')
40         finally:
41             if f != args.outfile:
42                 f.close()
43         if args.verbose > 0:
44             pprint.pprint(filesystem)
45         walk(filesystem, self._plot_wave_callback)
46
47     def _plot_wave_callback(self, dirpath, key, value):
48         if isinstance(value, WaveRecord):
49             self.plot_wave(self.args, value.wave, title=dirpath + [key])
50
51
52 s = PackedScript(
53     description=__doc__, filetype='IGOR Packed Experiment (.pxp) file')
54 s.run()