Page MenuHomec4science

FortranfileModule.html
No OneTemporary

File Metadata

Created
Fri, Feb 7, 17:30

FortranfileModule.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>the fortranfile module &mdash; pNbody v4 documentation</title>
<link rel="stylesheet" href="../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '4',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="top" title="pNbody v4 documentation" href="../index.html" />
<link rel="up" title="Reference" href="Reference.html" />
<link rel="next" title="the palette module" href="PaletteModule.html" />
<link rel="prev" title="the libqt module" href="LibqtModule.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="../np-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="PaletteModule.html" title="the palette module"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="LibqtModule.html" title="the libqt module"
accesskey="P">previous</a> |</li>
<li><a href="../index.html">pNbody v4 documentation</a> &raquo;</li>
<li><a href="Reference.html" accesskey="U">Reference</a> &raquo;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="module-pNbody.fortranfile">
<span id="the-fortranfile-module"></span><h1>the fortranfile module<a class="headerlink" href="#module-pNbody.fortranfile" title="Permalink to this headline"></a></h1>
<p>Defines a file-derived class to read/write Fortran unformatted files.</p>
<p>The assumption is that a Fortran unformatted file is being written by
the Fortran runtime as a sequence of records. Each record consists of
an integer (of the default size [usually 32 or 64 bits]) giving the
length of the following data in bytes, then the data itself, then the
same integer as before.</p>
<div class="section" id="examples">
<h2>Examples<a class="headerlink" href="#examples" title="Permalink to this headline"></a></h2>
<dl class="docutils">
<dt>To use the default endian and precision settings, one can just do::</dt>
<dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">FortranFile</span><span class="p">(</span><span class="s">&#39;filename&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">readReals</span><span class="p">()</span>
</pre></div>
</div>
</dd>
<dt>One can read arrays with varying precisions::</dt>
<dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">FortranFile</span><span class="p">(</span><span class="s">&#39;filename&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">readInts</span><span class="p">(</span><span class="s">&#39;h&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">readInts</span><span class="p">(</span><span class="s">&#39;q&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">readReals</span><span class="p">(</span><span class="s">&#39;f&#39;</span><span class="p">)</span>
</pre></div>
</div>
</dd>
</dl>
<p>Where the format codes are those used by Python&#8217;s struct module.</p>
<dl class="docutils">
<dt>One can change the default endian-ness and header precision::</dt>
<dd><div class="first last highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">FortranFile</span><span class="p">(</span><span class="s">&#39;filename&#39;</span><span class="p">,</span> <span class="n">endian</span><span class="o">=</span><span class="s">&#39;&gt;&#39;</span><span class="p">,</span> <span class="n">header_prec</span><span class="o">=</span><span class="s">&#39;l&#39;</span><span class="p">)</span>
</pre></div>
</div>
</dd>
</dl>
<p>for a file with little-endian data whose record headers are long
integers.</p>
<dl class="class">
<dt id="pNbody.fortranfile.FortranFile">
<em class="property">class </em><tt class="descclassname">pNbody.fortranfile.</tt><tt class="descname">FortranFile</tt><big>(</big><em>fname</em>, <em>endian='&#64;'</em>, <em>header_prec='i'</em>, <em>*args</em>, <em>**kwargs</em><big>)</big><a class="headerlink" href="#pNbody.fortranfile.FortranFile" title="Permalink to this definition"></a></dt>
<dd><p>File with methods for dealing with fortran unformatted data files</p>
<p class="rubric">Methods</p>
<dl class="attribute">
<dt id="pNbody.fortranfile.FortranFile.ENDIAN">
<tt class="descname">ENDIAN</tt><a class="headerlink" href="#pNbody.fortranfile.FortranFile.ENDIAN" title="Permalink to this definition"></a></dt>
<dd><p>Possible endian values are &#8216;&lt;&#8217;, &#8216;&gt;&#8217;, &#8216;&#64;&#8217;, &#8216;=&#8217;</p>
</dd></dl>
<dl class="attribute">
<dt id="pNbody.fortranfile.FortranFile.HEADER_PREC">
<tt class="descname">HEADER_PREC</tt><a class="headerlink" href="#pNbody.fortranfile.FortranFile.HEADER_PREC" title="Permalink to this definition"></a></dt>
<dd><p>Possible header precisions are &#8216;h&#8217;, &#8216;i&#8217;, &#8216;l&#8217;, &#8216;q&#8217;</p>
</dd></dl>
<dl class="method">
<dt id="pNbody.fortranfile.FortranFile.readInts">
<tt class="descname">readInts</tt><big>(</big><em>prec='i'</em><big>)</big><a class="headerlink" href="#pNbody.fortranfile.FortranFile.readInts" title="Permalink to this definition"></a></dt>
<dd><p>Read an array of integers.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><p class="first"><strong>prec</strong> : character, optional</p>
<blockquote class="last">
<p>Specify the precision of the data to be read using
character codes from Python&#8217;s struct module. Possible
values are &#8216;h&#8217;, &#8216;i&#8217;, &#8216;l&#8217; and &#8216;q&#8217;</p>
</blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="pNbody.fortranfile.FortranFile.readReals">
<tt class="descname">readReals</tt><big>(</big><em>prec='f'</em><big>)</big><a class="headerlink" href="#pNbody.fortranfile.FortranFile.readReals" title="Permalink to this definition"></a></dt>
<dd><p>Read in an array of real numbers.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><p class="first"><strong>prec</strong> : character, optional</p>
<blockquote class="last">
<p>Specify the precision of the array using character codes from
Python&#8217;s struct module. Possible values are &#8216;d&#8217; and &#8216;f&#8217;.</p>
</blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="pNbody.fortranfile.FortranFile.readRecord">
<tt class="descname">readRecord</tt><big>(</big><big>)</big><a class="headerlink" href="#pNbody.fortranfile.FortranFile.readRecord" title="Permalink to this definition"></a></dt>
<dd><p>Read a single fortran record</p>
</dd></dl>
<dl class="method">
<dt id="pNbody.fortranfile.FortranFile.readString">
<tt class="descname">readString</tt><big>(</big><big>)</big><a class="headerlink" href="#pNbody.fortranfile.FortranFile.readString" title="Permalink to this definition"></a></dt>
<dd><p>Read a string.</p>
</dd></dl>
<dl class="method">
<dt id="pNbody.fortranfile.FortranFile.writeInts">
<tt class="descname">writeInts</tt><big>(</big><em>ints</em>, <em>prec='i'</em><big>)</big><a class="headerlink" href="#pNbody.fortranfile.FortranFile.writeInts" title="Permalink to this definition"></a></dt>
<dd><p>Write an array of integers in given precision</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><p class="first"><strong>reals</strong> : array</p>
<blockquote>
<p>Data to write</p>
</blockquote>
<p><strong>prec</strong> : string</p>
<blockquote class="last">
<p>Character code for the precision to use in writing</p>
</blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="pNbody.fortranfile.FortranFile.writeReals">
<tt class="descname">writeReals</tt><big>(</big><em>reals</em>, <em>prec='f'</em><big>)</big><a class="headerlink" href="#pNbody.fortranfile.FortranFile.writeReals" title="Permalink to this definition"></a></dt>
<dd><p>Write an array of floats in given precision</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><p class="first"><strong>reals</strong> : array</p>
<blockquote>
<p>Data to write</p>
</blockquote>
<p><strong>prec`</strong> : string</p>
<blockquote class="last">
<p>Character code for the precision to use in writing</p>
</blockquote>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="pNbody.fortranfile.FortranFile.writeRecord">
<tt class="descname">writeRecord</tt><big>(</big><em>s</em><big>)</big><a class="headerlink" href="#pNbody.fortranfile.FortranFile.writeRecord" title="Permalink to this definition"></a></dt>
<dd><p>Write a record with the given bytes.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><strong>s</strong> : the string to write</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="pNbody.fortranfile.FortranFile.writeString">
<tt class="descname">writeString</tt><big>(</big><em>s</em><big>)</big><a class="headerlink" href="#pNbody.fortranfile.FortranFile.writeString" title="Permalink to this definition"></a></dt>
<dd><p>Write a string</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters :</th><td class="field-body"><strong>s</strong> : the string to write</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<p class="logo"><a href="../index.html">
<img class="logo" src="../_static/icon-small.jpg" alt="Logo"/>
</a></p>
<h3><a href="../index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">the fortranfile module</a><ul>
<li><a class="reference internal" href="#examples">Examples</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="LibqtModule.html"
title="previous chapter">the libqt module</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="PaletteModule.html"
title="next chapter">the palette module</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/rst/FortranfileModule.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="../np-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="PaletteModule.html" title="the palette module"
>next</a> |</li>
<li class="right" >
<a href="LibqtModule.html" title="the libqt module"
>previous</a> |</li>
<li><a href="../index.html">pNbody v4 documentation</a> &raquo;</li>
<li><a href="Reference.html" >Reference</a> &raquo;</li>
</ul>
</div>
<div class="footer">
&copy; Copyright 2011, Yves Revaz.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.4.
</div>
</body>
</html>

Event Timeline