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

Last change on this file since 1168 was 1168, checked in by toby, 9 years ago

update imports to provide error messages

  • Property svn:mime-type set to text/html
File size: 65.2 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-10-25 14:24:22 -0500 (Fri, 25 Oct 2013) $</span>
56<span class="c"># $Author: toby $</span>
57<span class="c"># $Revision: 1123 $</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 1123 2013-10-25 19:24:22Z 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: 1123 $&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="c">#print &#39;ContentsValidator: &#39;+self.formatName</span>
89        <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>
90            <span class="bp">self</span><span class="o">.</span><span class="n">GSAS</span> <span class="o">=</span> <span class="bp">True</span>
91            <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>
92                <span class="k">continue</span>
93<span class="c">#            if i==1 and line[:4].lower() == &#39;inst&#39; and &#39;:&#39; in line:</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="k">print</span> <span class="s">&#39;ContentsValidator: &#39;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">formatName</span>
105                <span class="k">print</span> <span class="s">&#39;Unexpected information in line:&#39;</span><span class="p">,</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span> <span class="c"># debug info</span>
106                <span class="k">print</span> <span class="n">line</span>
107                <span class="k">return</span> <span class="bp">False</span>
108        <span class="k">return</span> <span class="bp">False</span> <span class="c"># no bank records</span>
109</div>
110<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>
111       
112        <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>
113            <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>
114            <span class="n">x</span> <span class="o">=</span> <span class="p">[]</span>
115            <span class="n">y</span> <span class="o">=</span> <span class="p">[]</span>
116            <span class="n">w</span> <span class="o">=</span> <span class="p">[]</span>
117            <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>
118            <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>
119                <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>
120                <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>
121                <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>
122                <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>
123                <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>
124                    <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>
125                    <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>
126                <span class="k">else</span><span class="p">:</span>
127                    <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>
128                    <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>
129                <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>
130            <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>
131            <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>   
132           
133        <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>
134            <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>
135            <span class="n">x</span> <span class="o">=</span> <span class="p">[]</span>
136            <span class="n">y</span> <span class="o">=</span> <span class="p">[]</span>
137            <span class="n">w</span> <span class="o">=</span> <span class="p">[]</span>
138            <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>
139            <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>
140                <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>
141                <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>
142                <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>
143                <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>
144                    <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>
145                    <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>
146                <span class="k">else</span><span class="p">:</span>             
147                    <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>
148                    <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>
149                <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>
150            <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>
151            <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>
152           
153        <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>
154            <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>
155            <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>
156            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">clockWd</span><span class="p">:</span>
157                <span class="n">start</span> <span class="o">=</span> <span class="mi">0</span>
158                <span class="n">step</span> <span class="o">=</span> <span class="mi">1</span>
159            <span class="k">else</span><span class="p">:</span>
160                <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>
161                <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>
162            <span class="n">x</span> <span class="o">=</span> <span class="p">[]</span>
163            <span class="n">y</span> <span class="o">=</span> <span class="p">[]</span>
164            <span class="n">w</span> <span class="o">=</span> <span class="p">[]</span>
165            <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>
166            <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span>
167            <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>
168                <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>
169                    <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>
170                    <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>
171                    <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>
172                    <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>
173                    <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>
174                        <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>
175                        <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>
176                    <span class="k">else</span><span class="p">:</span>             
177                        <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>
178                        <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>
179                    <span class="n">j</span> <span class="o">+=</span> <span class="mi">1</span>
180                <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>
181            <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>
182            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">clockWd</span><span class="p">:</span>
183                <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>
184            <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>
185       
186        <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>
187            <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>
188            <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>
189            <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>
190            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">clockWd</span><span class="p">:</span>
191                <span class="n">start</span> <span class="o">=</span> <span class="mi">0</span>
192                <span class="n">step</span> <span class="o">=</span> <span class="mi">1</span>
193            <span class="k">else</span><span class="p">:</span>
194                <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>
195                <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>
196            <span class="n">x</span> <span class="o">=</span> <span class="p">[]</span>
197            <span class="n">y</span> <span class="o">=</span> <span class="p">[]</span>
198            <span class="n">w</span> <span class="o">=</span> <span class="p">[]</span>
199            <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>
200            <span class="n">j</span> <span class="o">=</span> <span class="mi">0</span>
201            <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>
202                <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>
203                    <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>
204                    <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>
205                    <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>
206                    <span class="k">if</span> <span class="n">yi</span><span class="p">:</span>
207                        <span class="n">vi</span> <span class="o">=</span> <span class="n">yi</span><span class="o">/</span><span class="n">ni</span>
208                    <span class="k">else</span><span class="p">:</span>
209                        <span class="n">yi</span> <span class="o">=</span> <span class="mf">0.0</span>
210                        <span class="n">vi</span> <span class="o">=</span> <span class="mf">1.0</span>
211                    <span class="n">j</span> <span class="o">+=</span> <span class="mi">1</span>
212                    <span class="k">if</span> <span class="n">j</span> <span class="o">&lt;</span> <span class="n">Nch</span><span class="p">:</span>
213                        <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>
214                        <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>
215                        <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>
216                <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>
217            <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>
218            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">clockWd</span><span class="p">:</span>
219                <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>
220            <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>
221           
222        <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>
223            <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>
224            <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>
225            <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>
226            <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>
227            <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>
228            <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>
229            <span class="n">ind</span> <span class="o">=</span> <span class="mi">0</span>
230            <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>
231                <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>
232                <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>
233                <span class="k">for</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">vals</span><span class="p">:</span>
234                    <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>
235                    <span class="n">ind</span> <span class="o">+=</span> <span class="mi">1</span>
236            <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>
237            <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>
238            <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>
239            <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>
240            <span class="n">TMap</span> <span class="o">=</span> <span class="n">TMap</span><span class="o">.</span><span class="n">T</span>
241            <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>
242            <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>
243           
244        <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>
245            <span class="n">TOF</span> <span class="o">=</span> <span class="p">[]</span>
246            <span class="n">chWdt</span> <span class="o">=</span> <span class="p">[]</span>
247            <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>
248            <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>
249                <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>
250                <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>
251                <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>
252            <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>
253            <span class="k">return</span> <span class="n">TOF</span>
254
255        <span class="n">x</span> <span class="o">=</span> <span class="p">[]</span>
256        <span class="n">y</span> <span class="o">=</span> <span class="p">[]</span>
257        <span class="n">w</span> <span class="o">=</span> <span class="p">[]</span>
258        <span class="n">Banks</span> <span class="o">=</span> <span class="p">[]</span>
259        <span class="n">Pos</span> <span class="o">=</span> <span class="p">[]</span>
260        <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>
261        <span class="n">title</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
262        <span class="n">comments</span> <span class="o">=</span> <span class="bp">None</span>
263        <span class="n">selections</span> <span class="o">=</span> <span class="bp">None</span>
264
265        <span class="c"># reload previously saved values</span>
266        <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>
267            <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>
268            <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>
269            <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>
270            <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>
271
272        <span class="c"># read through the file and find the beginning of each bank</span>
273        <span class="c"># Save the offset (Pos), BANK line (Banks), comments for each</span>
274        <span class="c"># bank</span>
275        <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>
276            <span class="k">try</span><span class="p">:</span>
277                <span class="n">i</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
278                <span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
279                    <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
280                    <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>
281                    <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>
282                       
283                    <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>
284                        <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>
285                        <span class="n">comments</span> <span class="o">=</span> <span class="p">[[</span><span class="n">title</span><span class="p">,]]</span>
286                        <span class="k">continue</span>
287                    <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>
288                        <span class="c"># 2nd line is instrument parameter file (optional)</span>
289                        <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>
290                        <span class="k">continue</span>
291                    <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>
292                        <span class="c"># comments in fact should only preceed BANK lines</span>
293                        <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>
294                        <span class="k">continue</span>
295                    <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>
296                        <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>
297                        <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>
298                        <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>
299                    <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>
300                        <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>
301            <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">detail</span><span class="p">:</span>
302                <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>
303                <span class="kn">import</span> <span class="nn">traceback</span>
304                <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>
305                <span class="k">return</span> <span class="bp">False</span>
306
307        <span class="c"># Now select the bank to read</span>
308        <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>
309            <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>
310            <span class="n">selblk</span> <span class="o">=</span> <span class="bp">None</span> <span class="c"># no block to choose</span>
311            <span class="k">return</span> <span class="bp">False</span>
312        <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>
313            <span class="n">selblk</span> <span class="o">=</span> <span class="mi">0</span>
314        <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>
315            <span class="c"># we were called to repeat the read</span>
316            <span class="c">#print &#39;debug: repeat #&#39;,self.repeatcount,&#39;selection&#39;,selections[self.repeatcount]</span>
317            <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>
318            <span class="bp">self</span><span class="o">.</span><span class="n">repeatcount</span> <span class="o">+=</span> <span class="mi">1</span>
319            <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>
320        <span class="k">else</span><span class="p">:</span>                       <span class="c"># choose from options</span>
321            <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>
322                <span class="n">Banks</span><span class="p">,</span>
323                <span class="n">ParentFrame</span><span class="o">=</span><span class="n">ParentFrame</span><span class="p">,</span>
324                <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>
325                <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>
326                <span class="n">header</span><span class="o">=</span><span class="s">&#39;Dataset Selector&#39;</span><span class="p">)</span>
327            <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>
328            <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>
329            <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>
330                <span class="bp">self</span><span class="o">.</span><span class="n">repeat</span> <span class="o">=</span> <span class="bp">True</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="n">rdbuffer</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
333                    <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>
334                    <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>
335                    <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>
336                    <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>
337
338        <span class="c"># got a selection, now read it</span>
339        <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>
340        <span class="k">try</span><span class="p">:</span>
341            <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>
342                <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>
343            <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>
344                <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>
345            <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>
346                <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>
347            <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>
348                <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>
349            <span class="k">else</span><span class="p">:</span>
350                <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>
351        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">detail</span><span class="p">:</span>
352            <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>
353            <span class="kn">import</span> <span class="nn">traceback</span>
354            <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>
355            <span class="k">return</span> <span class="bp">False</span>
356        <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>
357            <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>
358        <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>
359        <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>
360        <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>
361        <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>
362        <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>
363        <span class="c"># scan comments for temperature</span>
364        <span class="n">Temperature</span> <span class="o">=</span> <span class="mi">300</span>
365        <span class="n">Radius</span> <span class="o">=</span> <span class="mi">200</span>
366        <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>
367            <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>
368                <span class="k">try</span><span class="p">:</span>
369                    <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>
370                <span class="k">except</span><span class="p">:</span>
371                    <span class="k">pass</span>
372            <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>
373                <span class="k">try</span><span class="p">:</span>
374                    <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>
375                <span class="k">except</span><span class="p">:</span>
376                    <span class="k">pass</span>
377        <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>
378        <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>
379        <span class="k">return</span> <span class="bp">True</span>       
380</div></div>
381<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>
382    <span class="s">&#39;convert a string to a float, treating an all-blank string as zero&#39;</span>
383    <span class="k">if</span> <span class="n">S</span><span class="o">.</span><span class="n">strip</span><span class="p">():</span>
384        <span class="k">return</span> <span class="nb">float</span><span class="p">(</span><span class="n">S</span><span class="p">)</span>
385    <span class="k">else</span><span class="p">:</span>
386        <span class="k">return</span> <span class="mf">0.0</span>
387</div>
388<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>
389    <span class="s">&#39;convert a string to an integer, treating an all-blank string as zero&#39;</span>
390    <span class="k">if</span> <span class="n">S</span><span class="o">.</span><span class="n">strip</span><span class="p">():</span>
391        <span class="k">return</span> <span class="nb">int</span><span class="p">(</span><span class="n">S</span><span class="p">)</span>
392    <span class="k">else</span><span class="p">:</span>
393        <span class="k">return</span> <span class="mi">0</span></div>
394</pre></div>
395
396          </div>
397        </div>
398      </div>
399      <div class="sphinxsidebar">
400        <div class="sphinxsidebarwrapper">
401            <p class="logo"><a href="../index.html">
402              <img class="logo" src="../_static/G2_html_logo.png" alt="Logo"/>
403            </a></p>
404<div id="searchbox" style="display: none">
405  <h3>Quick search</h3>
406    <form class="search" action="../search.html" method="get">
407      <input type="text" name="q" />
408      <input type="submit" value="Go" />
409      <input type="hidden" name="check_keywords" value="yes" />
410      <input type="hidden" name="area" value="default" />
411    </form>
412    <p class="searchtip" style="font-size: 90%">
413    Enter search terms or a module, class or function name.
414    </p>
415</div>
416<script type="text/javascript">$('#searchbox').show(0);</script>
417        </div>
418      </div>
419      <div class="clearer"></div>
420    </div>
421    <div class="related">
422      <h3>Navigation</h3>
423      <ul>
424        <li class="right" style="margin-right: 10px">
425          <a href="../genindex.html" title="General Index"
426             >index</a></li>
427        <li class="right" >
428          <a href="../py-modindex.html" title="Python Module Index"
429             >modules</a> |</li>
430        <li><a href="../index.html">GSAS-II 0.2.0 documentation</a> &raquo;</li>
431          <li><a href="index.html" >Module code</a> &raquo;</li> 
432      </ul>
433    </div>
434    <div class="footer">
435        &copy; Copyright 2013, Von Dreele and Toby for Argonne National Laboratory.
436      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
437    </div>
438  </body>
439</html>
Note: See TracBrowser for help on using the repository browser.