Index: documentation/Sphinx/build/html/_modules/GribUtil.html
===================================================================
--- documentation/Sphinx/build/html/_modules/GribUtil.html	(revision 2625ca8faac35d65699e83e37bb42cdc24163490)
+++ documentation/Sphinx/build/html/_modules/GribUtil.html	(revision 2625ca8faac35d65699e83e37bb42cdc24163490)
@@ -0,0 +1,529 @@
+
+
+<!DOCTYPE html>
+<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
+<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
+<head>
+  <meta charset="utf-8">
+  
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  
+  <title>GribUtil &mdash; flex_extract 7.1 alpha documentation</title>
+  
+
+  
+  
+  
+  
+
+  
+
+  
+  
+    
+
+  
+
+  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
+  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
+    <link rel="index" title="Index" href="../genindex.html" />
+    <link rel="search" title="Search" href="../search.html" /> 
+
+  
+  <script src="../_static/js/modernizr.min.js"></script>
+
+</head>
+
+<body class="wy-body-for-nav">
+
+   
+  <div class="wy-grid-for-nav">
+
+    
+    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
+      <div class="wy-side-scroll">
+        <div class="wy-side-nav-search">
+          
+
+          
+            <a href="../index.html" class="icon icon-home"> flex_extract
+          
+
+          
+          </a>
+
+          
+            
+            
+              <div class="version">
+                7.1
+              </div>
+            
+          
+
+          
+<div role="search">
+  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
+    <input type="text" name="q" placeholder="Search docs" />
+    <input type="hidden" name="check_keywords" value="yes" />
+    <input type="hidden" name="area" value="default" />
+  </form>
+</div>
+
+          
+        </div>
+
+        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
+          
+            
+            
+              
+            
+            
+              <p class="caption"><span class="caption-text">Table of Contents:</span></p>
+<ul>
+<li class="toctree-l1"><a class="reference internal" href="../downloads.html">Downloads</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../program_structure.html">Program Structure</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../user_guide.html">User Guide</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../api.html">Auto Generated Documentation</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../support.html">Support</a></li>
+</ul>
+
+            
+          
+        </div>
+      </div>
+    </nav>
+
+    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
+
+      
+      <nav class="wy-nav-top" aria-label="top navigation">
+        
+          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
+          <a href="../index.html">flex_extract</a>
+        
+      </nav>
+
+
+      <div class="wy-nav-content">
+        
+        <div class="rst-content">
+        
+          
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+<div role="navigation" aria-label="breadcrumbs navigation">
+
+  <ul class="wy-breadcrumbs">
+    
+      <li><a href="../index.html">Docs</a> &raquo;</li>
+        
+          <li><a href="index.html">Module code</a> &raquo;</li>
+        
+      <li>GribUtil</li>
+    
+    
+      <li class="wy-breadcrumbs-aside">
+        
+      </li>
+    
+  </ul>
+
+  
+  <hr/>
+</div>
+          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
+           <div itemprop="articleBody">
+            
+  <h1>Source code for GribUtil</h1><div class="highlight"><pre>
+<span></span><span class="ch">#!/usr/bin/env python</span>
+<span class="c1"># -*- coding: utf-8 -*-</span>
+<span class="c1">#*******************************************************************************</span>
+<span class="c1"># @Author: Anne Fouilloux (University of Oslo)</span>
+<span class="c1">#</span>
+<span class="c1"># @Date: July 2014</span>
+<span class="c1">#</span>
+<span class="c1"># @Change History:</span>
+<span class="c1">#   February 2018 - Anne Philipp (University of Vienna):</span>
+<span class="c1">#        - applied PEP8 style guide</span>
+<span class="c1">#        - added documentation</span>
+<span class="c1">#        - changed some naming</span>
+<span class="c1">#</span>
+<span class="c1"># @License:</span>
+<span class="c1">#    (C) Copyright 2014-2018.</span>
+<span class="c1">#</span>
+<span class="c1">#    This software is licensed under the terms of the Apache Licence Version 2.0</span>
+<span class="c1">#    which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.</span>
+<span class="c1">#</span>
+<span class="c1"># @Class Description:</span>
+<span class="c1">#    The GRIB API provides all necessary tools to work directly with the</span>
+<span class="c1">#    grib files. Nevertheless, the GRIB API tools are very basic and are in</span>
+<span class="c1">#    direct connection with the grib files. This class provides some higher</span>
+<span class="c1">#    functions which apply a set of GRIB API tools together in the respective</span>
+<span class="c1">#    context. So, the class initially contains a list of grib files (their</span>
+<span class="c1">#    names) and the using program then applies the methods directly on the</span>
+<span class="c1">#    class objects without having to think about how the actual GRIB API</span>
+<span class="c1">#    tools have to be arranged.</span>
+<span class="c1">#</span>
+<span class="c1"># @Class Content:</span>
+<span class="c1">#    - __init__</span>
+<span class="c1">#    - get_keys</span>
+<span class="c1">#    - set_keys</span>
+<span class="c1">#    - copy_dummy_msg</span>
+<span class="c1">#    - index</span>
+<span class="c1">#</span>
+<span class="c1"># @Class Attributes:</span>
+<span class="c1">#    - filenames</span>
+<span class="c1">#</span>
+<span class="c1">#*******************************************************************************</span>
+
+<span class="c1"># ------------------------------------------------------------------------------</span>
+<span class="c1"># MODULES</span>
+<span class="c1"># ------------------------------------------------------------------------------</span>
+<span class="kn">import</span> <span class="nn">os</span>
+
+<span class="kn">from</span> <span class="nn">eccodes</span> <span class="k">import</span> <span class="p">(</span><span class="n">codes_grib_new_from_file</span><span class="p">,</span> <span class="n">codes_is_defined</span><span class="p">,</span> <span class="n">codes_get</span><span class="p">,</span>
+                     <span class="n">codes_release</span><span class="p">,</span> <span class="n">codes_set</span><span class="p">,</span> <span class="n">codes_write</span><span class="p">,</span> <span class="n">codes_index_read</span><span class="p">,</span>
+                     <span class="n">codes_index_new_from_file</span><span class="p">,</span> <span class="n">codes_index_add_file</span><span class="p">,</span>
+                     <span class="n">codes_index_write</span><span class="p">,</span> <span class="n">codes_set_values</span><span class="p">)</span>
+
+<span class="c1"># ------------------------------------------------------------------------------</span>
+<span class="c1"># CLASS</span>
+<span class="c1"># ------------------------------------------------------------------------------</span>
+<div class="viewcode-block" id="GribUtil"><a class="viewcode-back" href="../api.html#GribUtil.GribUtil">[docs]</a><span class="k">class</span> <span class="nc">GribUtil</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
+    <span class="sd">&#39;&#39;&#39;</span>
+<span class="sd">    Class for GRIB utilities (new methods) based on GRIB API</span>
+<span class="sd">    &#39;&#39;&#39;</span>
+    <span class="c1"># --------------------------------------------------------------------------</span>
+    <span class="c1"># CLASS FUNCTIONS</span>
+    <span class="c1"># --------------------------------------------------------------------------</span>
+    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filenames</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39;Initialise an object of GribUtil and assign a list of filenames.</span>
+
+<span class="sd">        Parameters</span>
+<span class="sd">        ----------</span>
+<span class="sd">        filenames : :obj:`list` of :obj:`strings`</span>
+<span class="sd">             A list of filenames.</span>
+
+<span class="sd">        Return</span>
+<span class="sd">        ------</span>
+
+<span class="sd">        &#39;&#39;&#39;</span>
+
+        <span class="bp">self</span><span class="o">.</span><span class="n">filenames</span> <span class="o">=</span> <span class="n">filenames</span>
+
+        <span class="k">return</span>
+
+
+<div class="viewcode-block" id="GribUtil.get_keys"><a class="viewcode-back" href="../api.html#GribUtil.GribUtil.get_keys">[docs]</a>    <span class="k">def</span> <span class="nf">get_keys</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">keynames</span><span class="p">,</span> <span class="n">wherekeynames</span><span class="o">=</span><span class="p">[],</span> <span class="n">wherekeyvalues</span><span class="o">=</span><span class="p">[]):</span>
+        <span class="sd">&#39;&#39;&#39;Get keyvalues for a given list of keynames a where statement</span>
+<span class="sd">        can be given (list of key and list of values)</span>
+
+<span class="sd">        Parameters</span>
+<span class="sd">        ----------</span>
+<span class="sd">        keynames : :obj:`list` of :obj:`string`</span>
+<span class="sd">            List of keynames.</span>
+
+<span class="sd">        wherekeynames : :obj:`list` of :obj:`string`, optional</span>
+<span class="sd">            Default value is an empty list.</span>
+
+<span class="sd">        wherekeyvalues : :obj:`list` of :obj:`string`, optional</span>
+<span class="sd">            Default value is an empty list.</span>
+
+<span class="sd">        Return</span>
+<span class="sd">        ------</span>
+<span class="sd">        return_list : :obj:`list` of :obj:`string`</span>
+<span class="sd">            List of keyvalues for given keynames.</span>
+<span class="sd">        &#39;&#39;&#39;</span>
+
+        <span class="n">fileid</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filenames</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span>
+
+        <span class="n">return_list</span> <span class="o">=</span> <span class="p">[]</span>
+
+        <span class="k">while</span> <span class="mi">1</span><span class="p">:</span>
+            <span class="n">gid</span> <span class="o">=</span> <span class="n">codes_new_from_file</span><span class="p">(</span><span class="n">fileid</span><span class="p">)</span>
+
+            <span class="k">if</span> <span class="n">gid</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
+                <span class="k">break</span>
+
+            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">wherekeynames</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">wherekeyvalues</span><span class="p">):</span>
+                <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;Number of key values and key names must be </span><span class="se">\</span>
+<span class="s2">                                 the same. Give a value for each keyname!&quot;</span><span class="p">)</span>
+
+            <span class="n">select</span> <span class="o">=</span> <span class="kc">True</span>
+            <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
+            <span class="k">for</span> <span class="n">wherekey</span> <span class="ow">in</span> <span class="n">wherekeynames</span><span class="p">:</span>
+                <span class="k">if</span> <span class="ow">not</span> <span class="n">codes_is_defined</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">wherekey</span><span class="p">):</span>
+                    <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;where key was not defined&quot;</span><span class="p">)</span>
+
+                <span class="n">select</span> <span class="o">=</span> <span class="p">(</span><span class="n">select</span> <span class="ow">and</span> <span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">wherekeyvalues</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">==</span>
+                                      <span class="nb">str</span><span class="p">(</span><span class="n">codes_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">wherekey</span><span class="p">))))</span>
+                <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
+
+            <span class="k">if</span> <span class="n">select</span><span class="p">:</span>
+                <span class="n">llist</span> <span class="o">=</span> <span class="p">[]</span>
+                <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">keynames</span><span class="p">:</span>
+                    <span class="n">llist</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="nb">str</span><span class="p">(</span><span class="n">codes_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">key</span><span class="p">))])</span>
+                <span class="n">return_list</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">llist</span><span class="p">)</span>
+
+            <span class="n">codes_release</span><span class="p">(</span><span class="n">gid</span><span class="p">)</span>
+
+        <span class="n">fileid</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
+
+        <span class="k">return</span> <span class="n">return_list</span></div>
+
+
+<div class="viewcode-block" id="GribUtil.set_keys"><a class="viewcode-back" href="../api.html#GribUtil.GribUtil.set_keys">[docs]</a>    <span class="k">def</span> <span class="nf">set_keys</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fromfile</span><span class="p">,</span> <span class="n">keynames</span><span class="p">,</span> <span class="n">keyvalues</span><span class="p">,</span> <span class="n">wherekeynames</span><span class="o">=</span><span class="p">[],</span>
+                 <span class="n">wherekeyvalues</span><span class="o">=</span><span class="p">[],</span> <span class="n">strict</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">filemode</span><span class="o">=</span><span class="s1">&#39;w&#39;</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39;Opens the file to read the grib messages and then write</span>
+<span class="sd">        the selected messages (with wherekeys) to a new output file.</span>
+<span class="sd">        Also, the keyvalues of the passed list of keynames are set.</span>
+
+<span class="sd">        Parameters</span>
+<span class="sd">        ----------</span>
+<span class="sd">        fromfile : :obj:`string`</span>
+<span class="sd">            Filename of the input file to read the grib messages from.</span>
+
+<span class="sd">        keynames : :obj:`list` of :obj:`string`</span>
+<span class="sd">            List of keynames to set in the selected messages.</span>
+<span class="sd">            Default is an empty list.</span>
+
+<span class="sd">        keyvalues : :obj:`list` of :obj:`string`</span>
+<span class="sd">            List of keyvalues to set in the selected messages.</span>
+<span class="sd">            Default is an empty list.</span>
+
+<span class="sd">        wherekeynames : :obj:`list` of :obj:`string`, optional</span>
+<span class="sd">            List of keynames to select correct message.</span>
+<span class="sd">            Default value is an empty list.</span>
+
+<span class="sd">        wherekeyvalues : :obj:`list` of :obj:`string`, optional</span>
+<span class="sd">            List of keyvalues for keynames to select correct message.</span>
+<span class="sd">            Default value is an empty list.</span>
+
+<span class="sd">        strict : :obj:`boolean`, optional</span>
+<span class="sd">            Decides if everything from keynames and keyvalues</span>
+<span class="sd">            is written out the grib file (False) or only those</span>
+<span class="sd">            meeting the where statement (True). Default is False.</span>
+
+<span class="sd">        filemode : :obj:`string`, optional</span>
+<span class="sd">            Sets the mode for the output file. Default is &quot;w&quot;.</span>
+
+<span class="sd">        Return</span>
+<span class="sd">        ------</span>
+
+<span class="sd">        &#39;&#39;&#39;</span>
+        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">wherekeynames</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">wherekeyvalues</span><span class="p">):</span>
+            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;Give a value for each keyname!&quot;</span><span class="p">)</span>
+
+        <span class="n">fout</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filenames</span><span class="p">,</span> <span class="n">filemode</span><span class="p">)</span>
+        <span class="n">fin</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">fromfile</span><span class="p">)</span>
+
+        <span class="k">while</span> <span class="mi">1</span><span class="p">:</span>
+            <span class="n">gid</span> <span class="o">=</span> <span class="n">codes_grib_new_from_file</span><span class="p">(</span><span class="n">fin</span><span class="p">)</span>
+
+            <span class="k">if</span> <span class="n">gid</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
+                <span class="k">break</span>
+
+            <span class="n">select</span> <span class="o">=</span> <span class="kc">True</span>
+            <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
+            <span class="k">for</span> <span class="n">wherekey</span> <span class="ow">in</span> <span class="n">wherekeynames</span><span class="p">:</span>
+                <span class="k">if</span> <span class="ow">not</span> <span class="n">codes_is_defined</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">wherekey</span><span class="p">):</span>
+                    <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;wherekey was not defined&quot;</span><span class="p">)</span>
+
+                <span class="n">select</span> <span class="o">=</span> <span class="p">(</span><span class="n">select</span> <span class="ow">and</span> <span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">wherekeyvalues</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">==</span>
+                                      <span class="nb">str</span><span class="p">(</span><span class="n">codes_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">wherekey</span><span class="p">))))</span>
+                <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
+
+            <span class="k">if</span> <span class="n">select</span><span class="p">:</span>
+                <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
+                <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">keynames</span><span class="p">:</span>
+                    <span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="s1">&#39;values&#39;</span><span class="p">:</span>
+                        <span class="n">codes_set_values</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">keyvalues</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
+                    <span class="k">else</span><span class="p">:</span>
+                        <span class="n">codes_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">keyvalues</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">1</span>
+
+                <span class="n">codes_write</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">fout</span><span class="p">)</span>
+
+            <span class="n">codes_release</span><span class="p">(</span><span class="n">gid</span><span class="p">)</span>
+
+        <span class="n">fin</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
+        <span class="n">fout</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
+
+        <span class="k">return</span></div>
+
+<div class="viewcode-block" id="GribUtil.copy_dummy_msg"><a class="viewcode-back" href="../api.html#GribUtil.GribUtil.copy_dummy_msg">[docs]</a>    <span class="k">def</span> <span class="nf">copy_dummy_msg</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename_in</span><span class="p">,</span> <span class="n">selectWhere</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
+                 <span class="n">keynames</span><span class="o">=</span><span class="p">[],</span> <span class="n">keyvalues</span><span class="o">=</span><span class="p">[],</span> <span class="n">filemode</span><span class="o">=</span><span class="s1">&#39;w&#39;</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39;Add the content of another input grib file to the objects file but</span>
+<span class="sd">        only messages corresponding to keys/values passed to the function.</span>
+<span class="sd">        The selectWhere switch decides if to copy the keys equal to (True) or</span>
+<span class="sd">        different to (False) the keynames/keyvalues list passed to the function.</span>
+
+<span class="sd">        Parameters</span>
+<span class="sd">        ----------</span>
+<span class="sd">        filename_in : :obj:`string`</span>
+<span class="sd">            Filename of the input file to read the grib messages from.</span>
+
+<span class="sd">        selectWhere : :obj:`boolean`, optional</span>
+<span class="sd">            Decides if to copy the keynames and values equal to (True) or</span>
+<span class="sd">            different to (False) the keynames/keyvalues list passed to the</span>
+<span class="sd">            function. Default is True.</span>
+
+<span class="sd">        keynames : :obj:`list` of :obj:`string`, optional</span>
+<span class="sd">            List of keynames. Default is an empty list.</span>
+
+<span class="sd">        keyvalues : :obj:`list` of :obj:`string`, optional</span>
+<span class="sd">            List of keyvalues. Default is an empty list.</span>
+
+<span class="sd">        filemode : :obj:`string`, optional</span>
+<span class="sd">            Sets the mode for the output file. Default is &quot;w&quot;.</span>
+
+<span class="sd">        Return</span>
+<span class="sd">        ------</span>
+
+<span class="sd">        &#39;&#39;&#39;</span>
+        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">keynames</span><span class="p">)</span> <span class="o">!=</span> <span class="nb">len</span><span class="p">(</span><span class="n">keyvalues</span><span class="p">):</span>
+            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;Give a value for each keyname!&quot;</span><span class="p">)</span>
+
+        <span class="n">fin</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">filename_in</span><span class="p">)</span>
+        <span class="n">fout</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filenames</span><span class="p">,</span> <span class="n">filemode</span><span class="p">)</span>
+
+        <span class="n">fields</span> <span class="o">=</span> <span class="mi">0</span>
+
+        <span class="k">while</span> <span class="n">fields</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
+            <span class="n">gid</span> <span class="o">=</span> <span class="n">codes_grib_new_from_file</span><span class="p">(</span><span class="n">fin</span><span class="p">)</span>
+
+            <span class="k">if</span> <span class="n">gid</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
+                <span class="k">break</span>
+
+            <span class="n">select</span> <span class="o">=</span> <span class="kc">True</span>
+            <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
+            <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">keynames</span><span class="p">:</span>
+                <span class="k">if</span> <span class="ow">not</span> <span class="n">codes_is_defined</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">key</span><span class="p">):</span>
+                    <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;Key was not defined&quot;</span><span class="p">)</span>
+
+                <span class="k">if</span> <span class="n">selectWhere</span><span class="p">:</span>
+                    <span class="n">select</span> <span class="o">=</span> <span class="p">(</span><span class="n">select</span> <span class="ow">and</span> <span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">keyvalues</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">==</span>
+                                          <span class="nb">str</span><span class="p">(</span><span class="n">codes_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">key</span><span class="p">))))</span>
+                <span class="k">else</span><span class="p">:</span>
+                    <span class="n">select</span> <span class="o">=</span> <span class="p">(</span><span class="n">select</span> <span class="ow">and</span> <span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">keyvalues</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">!=</span>
+                                          <span class="nb">str</span><span class="p">(</span><span class="n">codes_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">key</span><span class="p">))))</span>
+                <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
+
+            <span class="k">if</span> <span class="n">select</span><span class="p">:</span>
+                <span class="n">fields</span> <span class="o">=</span> <span class="n">fields</span> <span class="o">+</span> <span class="mi">1</span>
+                <span class="n">codes_write</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">fout</span><span class="p">)</span>
+
+            <span class="n">codes_release</span><span class="p">(</span><span class="n">gid</span><span class="p">)</span>
+
+        <span class="n">fin</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
+        <span class="n">fout</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
+
+        <span class="k">return</span></div>
+
+<div class="viewcode-block" id="GribUtil.index"><a class="viewcode-back" href="../api.html#GribUtil.GribUtil.index">[docs]</a>    <span class="k">def</span> <span class="nf">index</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">index_keys</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;mars&quot;</span><span class="p">],</span> <span class="n">index_file</span><span class="o">=</span><span class="s2">&quot;my.idx&quot;</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39;Create index file from a list of files if it does not exist or</span>
+<span class="sd">        read an index file.</span>
+
+<span class="sd">        Parameters</span>
+<span class="sd">        ----------</span>
+<span class="sd">        index_keys: :obj:`list` of :obj:`string`, optional</span>
+<span class="sd">            Contains the list of key parameter names from</span>
+<span class="sd">            which the index is to be created.</span>
+<span class="sd">            Default is a list with a single entry string &quot;mars&quot;.</span>
+
+<span class="sd">        index_file: :obj:`string`, optional</span>
+<span class="sd">            Filename where the indices are stored.</span>
+<span class="sd">            Default is &quot;my.idx&quot;.</span>
+
+<span class="sd">        Return</span>
+<span class="sd">        ------</span>
+<span class="sd">        iid: :obj:`integer`</span>
+<span class="sd">            Grib index id.</span>
+<span class="sd">        &#39;&#39;&#39;</span>
+        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;... index will be done&quot;</span><span class="p">)</span>
+        <span class="n">iid</span> <span class="o">=</span> <span class="kc">None</span>
+
+        <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">index_file</span><span class="p">):</span>
+            <span class="n">iid</span> <span class="o">=</span> <span class="n">codes_index_read</span><span class="p">(</span><span class="n">index_file</span><span class="p">)</span>
+            <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Use existing index file: </span><span class="si">%s</span><span class="s2"> &quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">index_file</span><span class="p">))</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="k">for</span> <span class="n">filename</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">filenames</span><span class="p">:</span>
+                <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Inputfile: </span><span class="si">%s</span><span class="s2"> &quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">filename</span><span class="p">))</span>
+                <span class="k">if</span> <span class="n">iid</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
+                    <span class="n">iid</span> <span class="o">=</span> <span class="n">codes_index_new_from_file</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">index_keys</span><span class="p">)</span>
+                <span class="k">else</span><span class="p">:</span>
+                    <span class="n">codes_index_add_file</span><span class="p">(</span><span class="n">iid</span><span class="p">,</span> <span class="n">filename</span><span class="p">)</span>
+
+            <span class="k">if</span> <span class="n">iid</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
+                <span class="n">codes_index_write</span><span class="p">(</span><span class="n">iid</span><span class="p">,</span> <span class="n">index_file</span><span class="p">)</span>
+
+        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;... index done&#39;</span><span class="p">)</span>
+
+        <span class="k">return</span> <span class="n">iid</span></div></div>
+</pre></div>
+
+           </div>
+           
+          </div>
+          <footer>
+  
+
+  <hr/>
+
+  <div role="contentinfo">
+    <p>
+        &copy; Copyright 2018, Anne Philipp and Leopold Haimberger
+
+    </p>
+  </div>
+  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 
+
+</footer>
+
+        </div>
+      </div>
+
+    </section>
+
+  </div>
+  
+
+
+  
+
+    
+    
+      <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></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>
+    
+
+  
+
+  <script type="text/javascript" src="../_static/js/theme.js"></script>
+
+  <script type="text/javascript">
+      jQuery(function () {
+          SphinxRtdTheme.Navigation.enable(true);
+      });
+  </script> 
+
+</body>
+</html>
