a93adfdc547325db4f6faefb36b67b3801b12a91
[calibcant.git] / calibcant / common.py
1 import config
2
3 VERSION="0.2"
4
5 # handle extra verbose input modules, only imported if we need them
6 _flush_plot = None
7 _final_flush_plot = None
8 _pylab = None
9
10 def _import_pylab() :
11     """Import pylab plotting functions for when we need to plot.  This
12     function can be called multiple times, and ensures that the pylab
13     setup is only imported once.  It defines the functions
14       _flush_plot() to be called after incremental changes,
15       _final_flush_plot(), to be called at the end of any graphical processing, and
16       _pylab, a reference to the pylab module."""
17     global _pylab
18     global _flush_plot
19     global _final_flush_plot
20     if _pylab == None :
21         import pylab as _pylab
22     if _flush_plot == None :
23         if config.PYLAB_INTERACTIVE :
24             _flush_plot = _pylab.draw
25         else :
26             def _flush_plot () : pass
27     if _final_flush_plot == None :
28         if config.PYLAB_INTERACTIVE :
29             _final_flush_plot = _pylab.draw
30         else :
31             _final_flush_plot = _pylab.show
32
33 def write_array(ofile, array, seperator):
34     """Erite an iterable array seperated by seperator.
35     Terminate the output with an endline."""
36     strings = [repr(x) for x in array]
37     ofile.write(seperator.join(strings))
38     ofile.write('\n')