source: trunk/sphinxdocs/build/html/_modules/G2pwd_fxye.html @ 1183

Last change on this file since 1183 was 1183, checked in by toby, 8 years ago

fixup number formatting; update produced doc files

  • Property svn:mime-type set to text/html
File size: 70.3 KB
Line 
1
2
3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
6
7<html xmlns="http://www.w3.org/1999/xhtml">
8  <head>
9    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
10   
11    <title>G2pwd_fxye &mdash; GSAS-II 0.2.0 documentation</title>
12   
13    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
14    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
15   
16    <script type="text/javascript">
17      var DOCUMENTATION_OPTIONS = {
18        URL_ROOT:    '../',
19        VERSION:     '0.2.0',
20        COLLAPSE_INDEX: false,
21        FILE_SUFFIX: '.html',
22        HAS_SOURCE:  true
23      };
24    </script>
25    <script type="text/javascript" src="../_static/jquery.js"></script>
26    <script type="text/javascript" src="../_static/underscore.js"></script>
27    <script type="text/javascript" src="../_static/doctools.js"></script>
28    <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
29    <link rel="top" title="GSAS-II 0.2.0 documentation" href="../index.html" />
30    <link rel="up" title="Module code" href="index.html" /> 
31  </head>
32  <body>
33    <div class="related">
34      <h3>Navigation</h3>
35      <ul>
36        <li class="right" style="margin-right: 10px">
37          <a href="../genindex.html" title="General Index"
38             accesskey="I">index</a></li>
39        <li class="right" >
40          <a href="../py-modindex.html" title="Python Module Index"
41             >modules</a> |</li>
42        <li><a href="../index.html">GSAS-II 0.2.0 documentation</a> &raquo;</li>
43          <li><a href="index.html" accesskey="U">Module code</a> &raquo;</li> 
44      </ul>
45    </div> 
46
47    <div class="document">
48      <div class="documentwrapper">
49        <div class="bodywrapper">
50          <div class="body">
51           
52  <h1>Source code for G2pwd_fxye</h1><div class="highlight"><pre>
53<span class="c"># -*- coding: utf-8 -*-</span>
54<span class="c">########### SVN repository information ###################</span>
55<span class="c"># $Date: 2013-12-16 10:43:01 -0600 (Mon, 16 Dec 2013) $</span>
56<span class="c"># $Author: toby $</span>
57<span class="c"># $Revision: 1168 $</span>
58<span class="c"># $URL: https://subversion.xor.aps.anl.gov/pyGSAS/trunk/imports/G2pwd_fxye.py $</span>
59<span class="c"># $Id: G2pwd_fxye.py 1168 2013-12-16 16:43:01Z toby $</span>
60<span class="c">########### SVN repository information ###################</span>
61<span class="sd">&#39;&#39;&#39;</span>
62<span class="sd">*Module G2pwd_fxye: GSAS data files*</span>
63<span class="sd">------------------------------------</span>
64<span class="sd">Routine to read in powder data in a variety of formats</span>
65<span class="sd">that are defined for GSAS.</span>
66
67<span class="sd">&#39;&#39;&#39;</span>
68<span class="kn">import</span> <span class="nn">sys</span>
69<span class="kn">import</span> <span class="nn">os.path</span> <span class="kn">as</span> <span class="nn">ospath</span>
70<span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>
71<span class="kn">import</span> <span class="nn">GSASIIIO</span> <span class="kn">as</span> <span class="nn">G2IO</span>
72<span class="kn">import</span> <span class="nn">GSASIIpath</span>
73<span class="n">GSASIIpath</span><span class="o">.</span><span class="n">SetVersionNumber</span><span class="p">(</span><span class="s">&quot;$Revision: 1168 $&quot;</span><span class="p">)</span>
74
75<div class="viewcode-block" id="GSAS_ReaderClass"><a class="viewcode-back" href="../imports.html#G2pwd_fxye.GSAS_ReaderClass">[docs]</a><span class="k">class</span> <span class="nc">GSAS_ReaderClass</span><span class="p">(</span><span class="n">G2IO</span><span class="o">.</span><span class="n">ImportPowderData</span><span class="p">):</span>
76    <span class="s">&#39;Routines to import powder data from a GSAS files&#39;</span>
77    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
78        <span class="nb">super</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__class__</span><span class="p">,</span><span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span> <span class="c"># fancy way to self-reference</span>
79            <span class="n">extensionlist</span><span class="o">=</span><span class="p">(</span><span class="s">&#39;.fxye&#39;</span><span class="p">,</span><span class="s">&#39;.raw&#39;</span><span class="p">,</span><span class="s">&#39;.gsas&#39;</span><span class="p">,</span><span class="s">&#39;.gsa&#39;</span><span class="p">,</span><span class="s">&#39;.RAW&#39;</span><span class="p">,</span><span class="s">&#39;.GSAS&#39;</span><span class="p">,</span><span class="s">&#39;.GSA&#39;</span><span class="p">),</span>
80            <span class="n">strictExtension</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>
81            <span class="n">formatName</span> <span class="o">=</span> <span class="s">&#39;GSAS powder data&#39;</span><span class="p">,</span>
82            <span class="n">longFormatName</span> <span class="o">=</span> <span class="s">&#39;GSAS powder data files (.fxye, .raw, .gsas...)&#39;</span>
83            <span class="p">)</span>
84        <span class="bp">self</span><span class="o">.</span><span class="n">clockWd</span> <span class="o">=</span> <span class="bp">None</span>
85
86    <span class="c"># Validate the contents -- look for a bank line</span>
87<div class="viewcode-block" id="GSAS_ReaderClass.ContentsValidator"><a class="viewcode-back" href="../imports.html#G2pwd_fxye.GSAS_ReaderClass.ContentsValidator">[docs]</a>    <span class="k">def</span> <span class="nf">ContentsValidator</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filepointer</span><span class="p">):</span>
88        <span class="s">&#39;Validate by checking to see if the file has BANK lines&#39;</span>
89        <span class="c">#print &#39;ContentsValidator: &#39;+self.formatName</span>
90        <span class="k">for</span> <span class="n">i</span><span class="p">,</span><span class="n">line</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">filepointer</span><span class="p">):</span>
91            <span class="bp">self</span><span class="o">.</span><span class="n">GSAS</span> <span class="o">=</span> <span class="bp">True</span>
92            <span class="k">if</span> <span class="n">i</span><span class="o">==</span><span class="mi">0</span><span class="p">:</span> <span class="c"># first line is always a comment</span>
93                <span class="k">continue</span>
94            <span class="k">if</span> <span class="n">i</span><span class="o">==</span><span class="mi">1</span> <span class="ow">and</span> <span class="n">line</span><span class="p">[:</span><span class="mi">4</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s">&#39;inst&#39;</span><span class="p">:</span>
95                <span class="c"># 2nd line is optional instrument parameter file</span>
96                <span class="k">continue</span>
97            <span class="k">if</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;#&#39;</span><span class="p">:</span> <span class="k">continue</span>
98            <span class="k">if</span> <span class="n">line</span><span class="p">[:</span><span class="mi">4</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;BANK&#39;</span><span class="p">:</span>
99                <span class="k">return</span> <span class="bp">True</span>
100            <span class="k">elif</span> <span class="n">line</span><span class="p">[:</span><span class="mi">7</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;Monitor&#39;</span><span class="p">:</span> <span class="k">continue</span>
101            <span class="k">elif</span> <span class="n">line</span> <span class="p">[:</span><span class="mi">8</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;TIME_MAP&#39;</span><span class="p">:</span>          <span class="c">#LANSCE TOF data</span>
102                <span class="k">return</span> <span class="bp">True</span>
103            <span class="k">else</span><span class="p">:</span>
104                <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;Unexpected information in line: &#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
105                <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">+=</span> <span class="s">&#39;  &#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
106                <span class="k">return</span> <span class="bp">False</span>
107        <span class="k">return</span> <span class="bp">False</span> <span class="c"># no bank records</span>
108</div>
109<div class="viewcode-block" id="GSAS_ReaderClass.Reader"><a class="viewcode-back" href="../imports.html#G2pwd_fxye.GSAS_ReaderClass.Reader">[docs]</a>    <span class="k">def</span> <span class="nf">Reader</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">filename</span><span class="p">,</span><span class="n">filepointer</span><span class="p">,</span> <span class="n">ParentFrame</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwarg</span><span class="p">):</span>
110        <span class="sd">&#39;&#39;&#39;Read a GSAS (old formats) file of type FXY, FXYE, ESD or STD types.</span>
111<span class="sd">        If multiple datasets are requested, use self.repeat and buffer caching.</span>
112<span class="sd">        &#39;&#39;&#39;</span>
113        <span class="k">def</span> <span class="nf">GetFXYEdata</span><span class="p">(</span><span class="n">File</span><span class="p">,</span><span class="n">Pos</span><span class="p">,</span><span class="n">Bank</span><span class="p">):</span>
114            <span class="n">File</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="n">Pos</span><span class="p">)</span>
115            <span class="n">x</span> <span class="o">=</span> <span class="p">[]</span>
116            <span class="n">y</span> <span class="o">=</span> <span class="p">[]</span>
117            <span class="n">w</span> <span class="o">=</span> <span class="p">[]</span>
118            <span class="n">S</span> <span class="o">=</span> <span class="n">File</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
119            <span class="k">while</span> <span class="n">S</span> <span class="ow">and</span> <span class="n">S</span><span class="p">[:</span><span class="mi">4</span><span class="p">]</span> <span class="o">!=</span> <span class="s">&#39;BANK&#39;</span><span class="p">:</span>
120                <span class="n">vals</span> <span class="o">=</span> <span class="n">S</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
121                <span class="n">x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">vals</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span><span class="o">/</span><span class="mf">100.</span><span class="p">)</span>               <span class="c">#CW: from centidegrees to degrees</span>
122                <span class="n">f</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">vals</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
123                <span class="n">s</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">vals</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
124                <span class="k">if</span> <span class="n">f</span> <span class="o">&lt;=</span> <span class="mf">0.0</span> <span class="ow">or</span> <span class="n">s</span> <span class="o">&lt;=</span> <span class="mf">0.0</span><span class="p">:</span>
125                    <span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
126                    <span class="n">w</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">1.0</span><span class="p">)</span>
127                <span class="k">else</span><span class="p">:</span>
128                    <span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">vals</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
129                    <span class="n">w</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">1.0</span><span class="o">/</span><span class="nb">float</span><span class="p">(</span><span class="n">vals</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
130                <span class="n">S</span> <span class="o">=</span> <span class="n">File</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
131            <span class="n">N</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
132            <span class="k">return</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">x</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">y</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">w</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">N</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">N</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">N</span><span class="p">)]</span>   
133           
134        <span class="k">def</span> <span class="nf">GetFXYdata</span><span class="p">(</span><span class="n">File</span><span class="p">,</span><span class="n">Pos</span><span class="p">,</span><span class="n">Bank</span><span class="p">):</span>
135            <span class="n">File</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="n">Pos</span><span class="p">)</span>
136            <span class="n">x</span> <span class="o">=</span> <span class="p">[]</span>
137            <span class="n">y</span> <span class="o">=</span> <span class="p">[]</span>
138            <span class="n">w</span> <span class="o">=</span> <span class="p">[]</span>
139            <span class="n">S</span> <span class="o">=</span> <span class="n">File</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
140            <span class="k">while</span> <span class="n">S</span> <span class="ow">and</span> <span class="n">S</span><span class="p">[:</span><span class="mi">4</span><span class="p">]</span> <span class="o">!=</span> <span class="s">&#39;BANK&#39;</span><span class="p">:</span>
141                <span class="n">vals</span> <span class="o">=</span> <span class="n">S</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
142                <span class="n">x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">float</span><span class="p">(</span><span class="n">vals</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span><span class="o">/</span><span class="mf">100.</span><span class="p">)</span>               <span class="c">#CW: from centidegrees to degrees</span>
143                <span class="n">f</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">vals</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
144                <span class="k">if</span> <span class="n">f</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">:</span>
145                    <span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
146                    <span class="n">w</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">1.0</span><span class="o">/</span><span class="n">f</span><span class="p">)</span>
147                <span class="k">else</span><span class="p">:</span>             
148                    <span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
149                    <span class="n">w</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">1.0</span><span class="p">)</span>
150                <span class="n">S</span> <span class="o">=</span> <span class="n">File</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
151            <span class="n">N</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
152            <span class="k">return</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">x</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">y</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">w</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">N</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">N</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">N</span><span class="p">)]</span>
153           
154        <span class="k">def</span> <span class="nf">GetESDdata</span><span class="p">(</span><span class="n">File</span><span class="p">,</span><span class="n">Pos</span><span class="p">,</span><span class="n">Bank</span><span class="p">):</span>
155            <span class="n">File</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="n">Pos</span><span class="p">)</span>
156            <span class="n">cons</span> <span class="o">=</span> <span class="n">Bank</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
157            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">clockWd</span><span class="p">:</span>
158                <span class="n">start</span> <span class="o">=</span> <span class="mi">0</span>
159                <span class="n">step</span> <span class="o">=</span> <span class="mi">1</span>
160            <span class="k">else</span><span class="p">:</span>
161                <span class="n">start</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">cons</span><span class="p">[</span><span class="mi">5</span><span class="p">])</span><span class="o">/</span><span class="mf">100.0</span>               <span class="c">#CW: from centidegrees to degrees</span>
162                <span class="n">step</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">cons</span><span class="p">[</span><span class="mi">6</span><span class="p">])</span><span class="o">/</span><span class="mf">100.0</span>
163            <span class="n">x</span> <span class="o">=</span> <span class="p">[]</span>
164            <span class="n">y</span> <span class="o">=</span> <span class="p">[]</span>
165            <span class="n">w</span> <span class="o">=</span> <span class="p">[]</span>
166            <span class="n">S</span> <span class="o">=</span> <span class="n">File</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
167            <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span>
168            <span class="k">while</span> <span class="n">S</span> <span class="ow">and</span> <span class="n">S</span><span class="p">[:</span><span class="mi">4</span><span class="p">]</span> <span class="o">!=</span> <span class="s">&#39;BANK&#39;</span><span class="p">:</span>
169                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">80</span><span class="p">,</span><span class="mi">16</span><span class="p">):</span>
170                    <span class="n">xi</span> <span class="o">=</span> <span class="n">start</span><span class="o">+</span><span class="n">step</span><span class="o">*</span><span class="n">j</span>
171                    <span class="n">yi</span> <span class="o">=</span> <span class="n">sfloat</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="n">i</span><span class="p">:</span><span class="n">i</span><span class="o">+</span><span class="mi">8</span><span class="p">])</span>
172                    <span class="n">ei</span> <span class="o">=</span> <span class="n">sfloat</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">8</span><span class="p">:</span><span class="n">i</span><span class="o">+</span><span class="mi">16</span><span class="p">])</span>
173                    <span class="n">x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">xi</span><span class="p">)</span>
174                    <span class="k">if</span> <span class="n">yi</span> <span class="o">&gt;</span> <span class="mf">0.0</span><span class="p">:</span>
175                        <span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">yi</span><span class="p">)</span>
176                        <span class="n">w</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">1.0</span><span class="o">/</span><span class="n">ei</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
177                    <span class="k">else</span><span class="p">:</span>             
178                        <span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span>
179                        <span class="n">w</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">1.0</span><span class="p">)</span>
180                    <span class="n">j</span> <span class="o">+=</span> <span class="mi">1</span>
181                <span class="n">S</span> <span class="o">=</span> <span class="n">File</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
182            <span class="n">N</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
183            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">clockWd</span><span class="p">:</span>
184                <span class="n">x</span> <span class="o">=</span> <span class="n">Tmap2TOF</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">TimeMap</span><span class="p">,</span><span class="n">clockWd</span><span class="p">)</span>
185            <span class="k">return</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">x</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">y</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">w</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">N</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">N</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">N</span><span class="p">)]</span>
186       
187        <span class="k">def</span> <span class="nf">GetSTDdata</span><span class="p">(</span><span class="n">File</span><span class="p">,</span><span class="n">Pos</span><span class="p">,</span><span class="n">Bank</span><span class="p">):</span>
188            <span class="n">File</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="n">Pos</span><span class="p">)</span>
189            <span class="n">cons</span> <span class="o">=</span> <span class="n">Bank</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
190            <span class="n">Nch</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">cons</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
191            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">clockWd</span><span class="p">:</span>
192                <span class="n">start</span> <span class="o">=</span> <span class="mi">0</span>
193                <span class="n">step</span> <span class="o">=</span> <span class="mi">1</span>
194            <span class="k">else</span><span class="p">:</span>
195                <span class="n">start</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">cons</span><span class="p">[</span><span class="mi">5</span><span class="p">])</span><span class="o">/</span><span class="mf">100.0</span>               <span class="c">#CW: from centidegrees to degrees</span>
196                <span class="n">step</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">cons</span><span class="p">[</span><span class="mi">6</span><span class="p">])</span><span class="o">/</span><span class="mf">100.0</span>                 <span class="c">#NB TOF 0.1*ms!</span>
197            <span class="n">x</span> <span class="o">=</span> <span class="p">[]</span>
198            <span class="n">y</span> <span class="o">=</span> <span class="p">[]</span>
199            <span class="n">w</span> <span class="o">=</span> <span class="p">[]</span>
200            <span class="n">S</span> <span class="o">=</span> <span class="n">File</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
201            <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span>
202            <span class="k">while</span> <span class="n">S</span> <span class="ow">and</span> <span class="n">S</span><span class="p">[:</span><span class="mi">4</span><span class="p">]</span> <span class="o">!=</span> <span class="s">&#39;BANK&#39;</span><span class="p">:</span>
203                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">80</span><span class="p">,</span><span class="mi">8</span><span class="p">):</span>
204                    <span class="n">xi</span> <span class="o">=</span> <span class="n">start</span><span class="o">+</span><span class="n">step</span><span class="o">*</span><span class="n">j</span>
205                    <span class="n">ni</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">sint</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="n">i</span><span class="p">:</span><span class="n">i</span><span class="o">+</span><span class="mi">2</span><span class="p">]),</span><span class="mi">1</span><span class="p">)</span>
206                    <span class="n">yi</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">sfloat</span><span class="p">(</span><span class="n">S</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">2</span><span class="p">:</span><span class="n">i</span><span class="o">+</span><span class="mi">8</span><span class="p">]),</span><span class="mf">0.0</span><span class="p">)</span>
207                    <span class="k">if</span> <span class="n">yi</span><span class="p">:</span>
208                        <span class="n">vi</span> <span class="o">=</span> <span class="n">yi</span><span class="o">/</span><span class="n">ni</span>
209                    <span class="k">else</span><span class="p">:</span>
210                        <span class="n">yi</span> <span class="o">=</span> <span class="mf">0.0</span>
211                        <span class="n">vi</span> <span class="o">=</span> <span class="mf">1.0</span>
212                    <span class="n">j</span> <span class="o">+=</span> <span class="mi">1</span>
213                    <span class="k">if</span> <span class="n">j</span> <span class="o">&lt;</span> <span class="n">Nch</span><span class="p">:</span>
214                        <span class="n">x</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">xi</span><span class="p">)</span>
215                        <span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">yi</span><span class="p">)</span>
216                        <span class="n">w</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">1.0</span><span class="o">/</span><span class="n">vi</span><span class="p">)</span>
217                <span class="n">S</span> <span class="o">=</span> <span class="n">File</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
218            <span class="n">N</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
219            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">clockWd</span><span class="p">:</span>
220                <span class="n">x</span> <span class="o">=</span> <span class="n">Tmap2TOF</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">TimeMap</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">clockWd</span><span class="p">)[:</span><span class="o">-</span><span class="mi">2</span><span class="p">]</span>
221            <span class="k">return</span> <span class="p">[</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">x</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">y</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">w</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">N</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">N</span><span class="p">),</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">N</span><span class="p">)]</span>
222           
223        <span class="k">def</span> <span class="nf">GetTimeMap</span><span class="p">(</span><span class="n">File</span><span class="p">,</span><span class="n">Pos</span><span class="p">,</span><span class="n">TimeMap</span><span class="p">):</span>
224            <span class="n">File</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="n">Pos</span><span class="p">)</span>
225            <span class="n">cons</span> <span class="o">=</span> <span class="n">TimeMap</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
226            <span class="n">Nch</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">cons</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
227            <span class="n">Nrec</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">cons</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
228            <span class="n">clockWd</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">cons</span><span class="p">[</span><span class="mi">4</span><span class="p">])</span><span class="o">/</span><span class="mf">1000.</span>          <span class="c">#in mus</span>
229            <span class="n">TMap</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="n">Nch</span><span class="o">+</span><span class="mi">2</span><span class="p">,</span><span class="n">dtype</span><span class="o">=</span><span class="nb">int</span><span class="p">)</span>
230            <span class="n">ind</span> <span class="o">=</span> <span class="mi">0</span>
231            <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">Nrec</span><span class="p">):</span>
232                <span class="n">S</span> <span class="o">=</span> <span class="n">File</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span><span class="o">.</span><span class="n">rstrip</span><span class="p">(</span><span class="s">&#39;</span><span class="se">\n</span><span class="s">&#39;</span><span class="p">)</span>
233                <span class="n">vals</span> <span class="o">=</span> <span class="n">S</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
234                <span class="k">for</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">vals</span><span class="p">:</span>
235                    <span class="n">TMap</span><span class="p">[</span><span class="n">ind</span><span class="p">]</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
236                    <span class="n">ind</span> <span class="o">+=</span> <span class="mi">1</span>
237            <span class="n">TMap</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">TMap</span><span class="p">,(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span>
238            <span class="n">TMax</span> <span class="o">=</span> <span class="n">TMap</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
239            <span class="n">Nch</span> <span class="o">=</span> <span class="n">TMap</span><span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span><span class="o">+</span><span class="p">(</span><span class="n">TMax</span><span class="o">-</span><span class="n">TMap</span><span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="o">+</span><span class="n">TMap</span><span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">/</span><span class="n">TMap</span><span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span>
240            <span class="n">TMap</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">Nch</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span><span class="n">TMax</span><span class="p">,</span><span class="mi">0</span><span class="p">]</span>
241            <span class="n">TMap</span> <span class="o">=</span> <span class="n">TMap</span><span class="o">.</span><span class="n">T</span>
242            <span class="n">TMap</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-=</span> <span class="mi">1</span>
243            <span class="k">return</span> <span class="n">TMap</span><span class="o">.</span><span class="n">T</span><span class="p">,</span><span class="n">clockWd</span>
244           
245        <span class="k">def</span> <span class="nf">Tmap2TOF</span><span class="p">(</span><span class="n">TMap</span><span class="p">,</span><span class="n">clockWd</span><span class="p">):</span>
246            <span class="n">TOF</span> <span class="o">=</span> <span class="p">[]</span>
247            <span class="n">chWdt</span> <span class="o">=</span> <span class="p">[]</span>
248            <span class="n">Tch</span><span class="p">,</span><span class="n">T</span><span class="p">,</span><span class="n">Step</span> <span class="o">=</span> <span class="n">TMap</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
249            <span class="k">for</span> <span class="n">tmap</span> <span class="ow">in</span> <span class="n">TMap</span><span class="p">[</span><span class="mi">1</span><span class="p">:]:</span>
250                <span class="n">tch</span><span class="p">,</span><span class="n">t</span><span class="p">,</span><span class="n">step</span> <span class="o">=</span> <span class="n">tmap</span>
251                <span class="n">TOF</span> <span class="o">+=</span> <span class="p">[</span><span class="n">T</span><span class="o">+</span><span class="n">Step</span><span class="o">*</span><span class="p">(</span><span class="n">i</span><span class="o">-</span><span class="n">Tch</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">Tch</span><span class="p">,</span><span class="n">tch</span><span class="p">)]</span>
252                <span class="n">Tch</span><span class="p">,</span><span class="n">T</span><span class="p">,</span><span class="n">Step</span> <span class="o">=</span> <span class="n">tmap</span>
253            <span class="n">TOF</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">TOF</span><span class="p">)</span><span class="o">*</span><span class="n">clockWd</span>
254            <span class="k">return</span> <span class="n">TOF</span>
255
256        <span class="n">x</span> <span class="o">=</span> <span class="p">[]</span>
257        <span class="n">y</span> <span class="o">=</span> <span class="p">[]</span>
258        <span class="n">w</span> <span class="o">=</span> <span class="p">[]</span>
259        <span class="n">Banks</span> <span class="o">=</span> <span class="p">[]</span>
260        <span class="n">Pos</span> <span class="o">=</span> <span class="p">[]</span>
261        <span class="n">rdbuffer</span> <span class="o">=</span> <span class="n">kwarg</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;buffer&#39;</span><span class="p">)</span>
262        <span class="n">title</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
263        <span class="n">comments</span> <span class="o">=</span> <span class="bp">None</span>
264        <span class="n">selections</span> <span class="o">=</span> <span class="bp">None</span>
265
266        <span class="c"># reload previously saved values</span>
267        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">repeat</span> <span class="ow">and</span> <span class="n">rdbuffer</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
268            <span class="n">Banks</span> <span class="o">=</span> <span class="n">rdbuffer</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;Banks&#39;</span><span class="p">)</span>
269            <span class="n">Pos</span> <span class="o">=</span> <span class="n">rdbuffer</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;Pos&#39;</span><span class="p">)</span>
270            <span class="n">selections</span> <span class="o">=</span> <span class="n">rdbuffer</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;selections&#39;</span><span class="p">)</span>
271            <span class="n">comments</span> <span class="o">=</span> <span class="n">rdbuffer</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;comments&#39;</span><span class="p">)</span>
272
273        <span class="c"># read through the file and find the beginning of each bank</span>
274        <span class="c"># Save the offset (Pos), BANK line (Banks), comments for each bank</span>
275        <span class="c">#</span>
276        <span class="c"># This is going to need a fair amount of work to track line numbers</span>
277        <span class="c"># in the input file. </span>
278        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">Banks</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">Pos</span><span class="p">)</span> <span class="ow">or</span> <span class="nb">len</span><span class="p">(</span><span class="n">Banks</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
279            <span class="k">try</span><span class="p">:</span>
280                <span class="n">i</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
281                <span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
282                    <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
283                    <span class="n">S</span> <span class="o">=</span> <span class="n">filepointer</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
284                    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">S</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> <span class="k">break</span>
285                       
286                    <span class="k">if</span> <span class="n">i</span><span class="o">==</span><span class="mi">0</span><span class="p">:</span> <span class="c"># first line is always a comment</span>
287                        <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;Error reading title&#39;</span>
288                        <span class="n">title</span> <span class="o">=</span> <span class="n">S</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
289                        <span class="n">comments</span> <span class="o">=</span> <span class="p">[[</span><span class="n">title</span><span class="p">,]]</span>
290                        <span class="k">continue</span>
291                    <span class="k">if</span> <span class="n">i</span><span class="o">==</span><span class="mi">1</span> <span class="ow">and</span> <span class="n">S</span><span class="p">[:</span><span class="mi">4</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s">&#39;inst&#39;</span> <span class="ow">and</span> <span class="s">&#39;:&#39;</span> <span class="ow">in</span> <span class="n">S</span><span class="p">:</span>
292                        <span class="c"># 2nd line is instrument parameter file (optional)</span>
293                        <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;Error reading instrument parameter filename&#39;</span>
294                        <span class="bp">self</span><span class="o">.</span><span class="n">instparm</span> <span class="o">=</span> <span class="n">S</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
295                        <span class="k">continue</span>
296                    <span class="k">if</span> <span class="n">S</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;#&#39;</span><span class="p">:</span> <span class="c"># allow comments anywhere in the file</span>
297                        <span class="c"># comments in fact should only preceed BANK lines</span>
298                        <span class="n">comments</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">S</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
299                        <span class="k">continue</span>
300                    <span class="k">if</span> <span class="n">S</span><span class="p">[:</span><span class="mi">4</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;BANK&#39;</span><span class="p">:</span>
301                        <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;Error reading bank:&#39;</span>
302                        <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">+=</span> <span class="s">&#39;  &#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">S</span><span class="p">)</span>
303                        <span class="n">comments</span><span class="o">.</span><span class="n">append</span><span class="p">([</span><span class="n">title</span><span class="p">,])</span>
304                        <span class="n">Banks</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">S</span><span class="p">)</span>
305                        <span class="n">Pos</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">filepointer</span><span class="o">.</span><span class="n">tell</span><span class="p">())</span>
306                    <span class="k">if</span> <span class="n">S</span><span class="p">[:</span><span class="mi">8</span><span class="p">]</span> <span class="o">==</span> <span class="s">&#39;TIME_MAP&#39;</span><span class="p">:</span>
307                        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">Banks</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
308                            <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;Error reading time map before any bank lines&#39;</span>
309                        <span class="k">else</span><span class="p">:</span>
310                            <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;Error reading time map after bank:</span><span class="se">\n</span><span class="s">  &#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">Banks</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
311                        <span class="bp">self</span><span class="o">.</span><span class="n">TimeMap</span><span class="p">,</span><span class="bp">self</span><span class="o">.</span><span class="n">clockWd</span> <span class="o">=</span> <span class="n">GetTimeMap</span><span class="p">(</span><span class="n">filepointer</span><span class="p">,</span><span class="n">filepointer</span><span class="o">.</span><span class="n">tell</span><span class="p">(),</span><span class="n">S</span><span class="p">)</span>
312            <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">detail</span><span class="p">:</span>
313                <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="se">\n</span><span class="s">  &#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">detail</span><span class="p">)</span>
314                <span class="k">print</span> <span class="bp">self</span><span class="o">.</span><span class="n">formatName</span><span class="o">+</span><span class="s">&#39; scan error:&#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">detail</span><span class="p">)</span> <span class="c"># for testing</span>
315                <span class="kn">import</span> <span class="nn">traceback</span>
316                <span class="n">traceback</span><span class="o">.</span><span class="n">print_exc</span><span class="p">(</span><span class="nb">file</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">)</span>
317                <span class="k">return</span> <span class="bp">False</span>
318
319        <span class="c"># Now select the bank to read</span>
320        <span class="k">if</span> <span class="ow">not</span> <span class="n">Banks</span><span class="p">:</span> <span class="c"># use of ContentsValidator should prevent this error</span>
321            <span class="k">print</span> <span class="bp">self</span><span class="o">.</span><span class="n">formatName</span><span class="o">+</span><span class="s">&#39; scan error: no BANK records&#39;</span>
322            <span class="n">selblk</span> <span class="o">=</span> <span class="bp">None</span> <span class="c"># no block to choose</span>
323            <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;No BANK records found (strange!)&#39;</span>
324            <span class="k">return</span> <span class="bp">False</span>
325        <span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">Banks</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span> <span class="c"># only one Bank, don&#39;t ask</span>
326            <span class="n">selblk</span> <span class="o">=</span> <span class="mi">0</span>
327        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">repeat</span> <span class="ow">and</span> <span class="n">selections</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
328            <span class="c"># we were called to repeat the read</span>
329            <span class="c">#print &#39;debug: repeat #&#39;,self.repeatcount,&#39;selection&#39;,selections[self.repeatcount]</span>
330            <span class="n">selblk</span> <span class="o">=</span> <span class="n">selections</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">repeatcount</span><span class="p">]</span>
331            <span class="bp">self</span><span class="o">.</span><span class="n">repeatcount</span> <span class="o">+=</span> <span class="mi">1</span>
332            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">repeatcount</span> <span class="o">&gt;=</span> <span class="nb">len</span><span class="p">(</span><span class="n">selections</span><span class="p">):</span> <span class="bp">self</span><span class="o">.</span><span class="n">repeat</span> <span class="o">=</span> <span class="bp">False</span>
333        <span class="k">else</span><span class="p">:</span>                       <span class="c"># choose from options</span>
334            <span class="n">selections</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">MultipleBlockSelector</span><span class="p">(</span>
335                <span class="n">Banks</span><span class="p">,</span>
336                <span class="n">ParentFrame</span><span class="o">=</span><span class="n">ParentFrame</span><span class="p">,</span>
337                <span class="n">title</span><span class="o">=</span><span class="s">&#39;Select Bank(s) to read from the list below&#39;</span><span class="p">,</span>
338                <span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="mi">600</span><span class="p">,</span><span class="mi">100</span><span class="p">),</span>
339                <span class="n">header</span><span class="o">=</span><span class="s">&#39;Dataset Selector&#39;</span><span class="p">)</span>
340            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">selections</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span> <span class="k">return</span> <span class="bp">False</span>
341            <span class="n">selblk</span> <span class="o">=</span> <span class="n">selections</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="c"># select first in list</span>
342            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">selections</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span> <span class="c"># prepare to loop through again</span>
343                <span class="bp">self</span><span class="o">.</span><span class="n">repeat</span> <span class="o">=</span> <span class="bp">True</span>
344                <span class="bp">self</span><span class="o">.</span><span class="n">repeatcount</span> <span class="o">=</span> <span class="mi">1</span>
345                <span class="k">if</span> <span class="n">rdbuffer</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
346                    <span class="n">rdbuffer</span><span class="p">[</span><span class="s">&#39;Banks&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">Banks</span>
347                    <span class="n">rdbuffer</span><span class="p">[</span><span class="s">&#39;Pos&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">Pos</span>
348                    <span class="n">rdbuffer</span><span class="p">[</span><span class="s">&#39;selections&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">selections</span>
349                    <span class="n">rdbuffer</span><span class="p">[</span><span class="s">&#39;comments&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">comments</span>
350
351        <span class="c"># got a selection, now read it</span>
352        <span class="n">Bank</span> <span class="o">=</span> <span class="n">Banks</span><span class="p">[</span><span class="n">selblk</span><span class="p">]</span>
353        <span class="k">try</span><span class="p">:</span>
354            <span class="k">if</span> <span class="s">&#39;FXYE&#39;</span> <span class="ow">in</span> <span class="n">Bank</span><span class="p">:</span>
355                <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;Error reading FXYE data in Bank</span><span class="se">\n</span><span class="s">  &#39;</span><span class="o">+</span><span class="n">Banks</span><span class="p">[</span><span class="n">selblk</span><span class="p">]</span>
356                <span class="bp">self</span><span class="o">.</span><span class="n">powderdata</span> <span class="o">=</span> <span class="n">GetFXYEdata</span><span class="p">(</span><span class="n">filepointer</span><span class="p">,</span><span class="n">Pos</span><span class="p">[</span><span class="n">selblk</span><span class="p">],</span><span class="n">Banks</span><span class="p">[</span><span class="n">selblk</span><span class="p">])</span>
357            <span class="k">elif</span> <span class="s">&#39;FXY&#39;</span> <span class="ow">in</span> <span class="n">Bank</span><span class="p">:</span>
358                <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;Error reading FXY data in Bank</span><span class="se">\n</span><span class="s">  &#39;</span><span class="o">+</span><span class="n">Banks</span><span class="p">[</span><span class="n">selblk</span><span class="p">]</span>
359                <span class="bp">self</span><span class="o">.</span><span class="n">powderdata</span> <span class="o">=</span> <span class="n">GetFXYdata</span><span class="p">(</span><span class="n">filepointer</span><span class="p">,</span><span class="n">Pos</span><span class="p">[</span><span class="n">selblk</span><span class="p">],</span><span class="n">Banks</span><span class="p">[</span><span class="n">selblk</span><span class="p">])</span>
360            <span class="k">elif</span> <span class="s">&#39;ESD&#39;</span> <span class="ow">in</span> <span class="n">Bank</span><span class="p">:</span>
361                <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;Error reading ESD data in Bank</span><span class="se">\n</span><span class="s">  &#39;</span><span class="o">+</span><span class="n">Banks</span><span class="p">[</span><span class="n">selblk</span><span class="p">]</span>
362                <span class="bp">self</span><span class="o">.</span><span class="n">powderdata</span> <span class="o">=</span> <span class="n">GetESDdata</span><span class="p">(</span><span class="n">filepointer</span><span class="p">,</span><span class="n">Pos</span><span class="p">[</span><span class="n">selblk</span><span class="p">],</span><span class="n">Banks</span><span class="p">[</span><span class="n">selblk</span><span class="p">])</span>
363            <span class="k">elif</span> <span class="s">&#39;STD&#39;</span> <span class="ow">in</span> <span class="n">Bank</span><span class="p">:</span>
364                <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;Error reading STD data in Bank</span><span class="se">\n</span><span class="s">  &#39;</span><span class="o">+</span><span class="n">Banks</span><span class="p">[</span><span class="n">selblk</span><span class="p">]</span>
365                <span class="bp">self</span><span class="o">.</span><span class="n">powderdata</span> <span class="o">=</span> <span class="n">GetSTDdata</span><span class="p">(</span><span class="n">filepointer</span><span class="p">,</span><span class="n">Pos</span><span class="p">[</span><span class="n">selblk</span><span class="p">],</span><span class="n">Banks</span><span class="p">[</span><span class="n">selblk</span><span class="p">])</span>
366            <span class="k">else</span><span class="p">:</span>
367                <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;Error reading STD data in Bank</span><span class="se">\n</span><span class="s">  &#39;</span><span class="o">+</span><span class="n">Banks</span><span class="p">[</span><span class="n">selblk</span><span class="p">]</span>
368                <span class="bp">self</span><span class="o">.</span><span class="n">powderdata</span> <span class="o">=</span> <span class="n">GetSTDdata</span><span class="p">(</span><span class="n">filepointer</span><span class="p">,</span><span class="n">Pos</span><span class="p">[</span><span class="n">selblk</span><span class="p">],</span><span class="n">Banks</span><span class="p">[</span><span class="n">selblk</span><span class="p">])</span>
369        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">detail</span><span class="p">:</span>
370            <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="se">\n</span><span class="s">  &#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">detail</span><span class="p">)</span>
371            <span class="k">print</span> <span class="bp">self</span><span class="o">.</span><span class="n">formatName</span><span class="o">+</span><span class="s">&#39; read error:&#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">detail</span><span class="p">)</span> <span class="c"># for testing</span>
372            <span class="kn">import</span> <span class="nn">traceback</span>
373            <span class="n">traceback</span><span class="o">.</span><span class="n">print_exc</span><span class="p">(</span><span class="nb">file</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">)</span>
374            <span class="k">return</span> <span class="bp">False</span>
375
376        <span class="bp">self</span><span class="o">.</span><span class="n">errors</span> <span class="o">=</span> <span class="s">&#39;Error processing information after read complete&#39;</span>
377        <span class="k">if</span> <span class="n">comments</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
378            <span class="bp">self</span><span class="o">.</span><span class="n">comments</span> <span class="o">=</span> <span class="n">comments</span><span class="p">[</span><span class="n">selblk</span><span class="p">]</span>
379        <span class="bp">self</span><span class="o">.</span><span class="n">powderentry</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">filename</span>
380        <span class="bp">self</span><span class="o">.</span><span class="n">powderentry</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">Pos</span> <span class="c"># position offset (never used, I hope)</span>
381        <span class="bp">self</span><span class="o">.</span><span class="n">powderentry</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">selblk</span><span class="o">+</span><span class="mi">1</span> <span class="c"># bank number</span>
382        <span class="bp">self</span><span class="o">.</span><span class="n">idstring</span> <span class="o">=</span> <span class="n">ospath</span><span class="o">.</span><span class="n">basename</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span> <span class="o">+</span> <span class="s">&#39; Bank &#39;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">selblk</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
383        <span class="bp">self</span><span class="o">.</span><span class="n">numbanks</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">Banks</span><span class="p">)</span>
384        <span class="c"># scan comments for temperature</span>
385        <span class="n">Temperature</span> <span class="o">=</span> <span class="mi">300</span>
386        <span class="n">Radius</span> <span class="o">=</span> <span class="mi">200</span>
387        <span class="k">for</span> <span class="n">S</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">comments</span><span class="p">:</span>
388            <span class="k">if</span> <span class="s">&#39;Temp&#39;</span> <span class="ow">in</span> <span class="n">S</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;=&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]:</span>
389                <span class="k">try</span><span class="p">:</span>
390                    <span class="n">Temperature</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;=&#39;</span><span class="p">)[</span><span class="mi">1</span><span class="p">])</span>
391                <span class="k">except</span><span class="p">:</span>
392                    <span class="k">pass</span>
393            <span class="k">elif</span> <span class="s">&#39;Gonio&#39;</span> <span class="ow">in</span> <span class="n">S</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;=&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]:</span>
394                <span class="k">try</span><span class="p">:</span>
395                    <span class="n">Radius</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;=&#39;</span><span class="p">)[</span><span class="mi">1</span><span class="p">])</span>
396                <span class="k">except</span><span class="p">:</span>
397                    <span class="k">pass</span>
398        <span class="bp">self</span><span class="o">.</span><span class="n">Sample</span><span class="p">[</span><span class="s">&#39;Temperature&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">Temperature</span>
399        <span class="bp">self</span><span class="o">.</span><span class="n">Sample</span><span class="p">[</span><span class="s">&#39;Gonio. radius&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">Radius</span>
400        <span class="k">return</span> <span class="bp">True</span>       
401</div></div>
402<div class="viewcode-block" id="sfloat"><a class="viewcode-back" href="../imports.html#G2pwd_fxye.sfloat">[docs]</a><span class="k">def</span> <span class="nf">sfloat</span><span class="p">(</span><span class="n">S</span><span class="p">):</span>
403    <span class="s">&#39;convert a string to a float, treating an all-blank string as zero&#39;</span>
404    <span class="k">if</span> <span class="n">S</span><span class="o">.</span><span class="n">strip</span><span class="p">():</span>
405        <span class="k">return</span> <span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="p">)</span>
406    <span class="k">else</span><span class="p">:</span>
407        <span class="k">return</span> <span class="mf">0.0</span>
408</div>
409<div class="viewcode-block" id="sint"><a class="viewcode-back" href="../imports.html#G2pwd_fxye.sint">[docs]</a><span class="k">def</span> <span class="nf">sint</span><span class="p">(</span><span class="n">S</span><span class="p">):</span>
410    <span class="s">&#39;convert a string to an integer, treating an all-blank string as zero&#39;</span>
411    <span class="k">if</span> <span class="n">S</span><span class="o">.</span><span class="n">strip</span><span class="p">():</span>
412        <span class="k">return</span> <span class="nb">int</span><span class="p">(</span><span class="n">S</span><span class="p">)</span>
413    <span class="k">else</span><span class="p">:</span>
414        <span class="k">return</span> <span class="mi">0</span></div>
415</pre></div>
416
417          </div>
418        </div>
419      </div>
420      <div class="sphinxsidebar">
421        <div class="sphinxsidebarwrapper">
422            <p class="logo"><a href="../index.html">
423              <img class="logo" src="../_static/G2_html_logo.png" alt="Logo"/>
424            </a></p>
425<div id="searchbox" style="display: none">
426  <h3>Quick search</h3>
427    <form class="search" action="../search.html" method="get">
428      <input type="text" name="q" />
429      <input type="submit" value="Go" />
430      <input type="hidden" name="check_keywords" value="yes" />
431      <input type="hidden" name="area" value="default" />
432    </form>
433    <p class="searchtip" style="font-size: 90%">
434    Enter search terms or a module, class or function name.
435    </p>
436</div>
437<script type="text/javascript">$('#searchbox').show(0);</script>
438        </div>
439      </div>
440      <div class="clearer"></div>
441    </div>
442    <div class="related">
443      <h3>Navigation</h3>
444      <ul>
445        <li class="right" style="margin-right: 10px">
446          <a href="../genindex.html" title="General Index"
447             >index</a></li>
448        <li class="right" >
449          <a href="../py-modindex.html" title="Python Module Index"
450             >modules</a> |</li>
451        <li><a href="../index.html">GSAS-II 0.2.0 documentation</a> &raquo;</li>
452          <li><a href="index.html" >Module code</a> &raquo;</li> 
453      </ul>
454    </div>
455    <div class="footer">
456        &copy; Copyright 2013, Von Dreele and Toby for Argonne National Laboratory.
457      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
458    </div>
459  </body>
460</html>
Note: See TracBrowser for help on using the repository browser.