Index: documentation/Sphinx/build/html/_modules/EcFlexpart.html
===================================================================
--- documentation/Sphinx/build/html/_modules/EcFlexpart.html	(revision 274f9efe4b8438ab5238967e39adc200c624b56e)
+++ documentation/Sphinx/build/html/_modules/EcFlexpart.html	(revision 274f9efe4b8438ab5238967e39adc200c624b56e)
@@ -0,0 +1,1510 @@
+
+
+<!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>EcFlexpart &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>EcFlexpart</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 EcFlexpart</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: October 2014</span>
+<span class="c1">#</span>
+<span class="c1"># @Change History:</span>
+<span class="c1">#</span>
+<span class="c1">#    November 2015 - Leopold Haimberger (University of Vienna):</span>
+<span class="c1">#        - extended with class Control</span>
+<span class="c1">#        - removed functions mkdir_p, daterange, years_between, months_between</span>
+<span class="c1">#        - added functions darain, dapoly, to_param_id, init128, normal_exit,</span>
+<span class="c1">#          my_error, clean_up, install_args_and_control,</span>
+<span class="c1">#          interpret_args_and_control,</span>
+<span class="c1">#        - removed function __del__ in class EIFLexpart</span>
+<span class="c1">#        - added the following functions in EIFlexpart:</span>
+<span class="c1">#            - create_namelist</span>
+<span class="c1">#            - process_output</span>
+<span class="c1">#            - deacc_fluxes</span>
+<span class="c1">#        - modified existing EIFlexpart - functions for the use in</span>
+<span class="c1">#          flex_extract</span>
+<span class="c1">#        - retrieve also longer term forecasts, not only analyses and</span>
+<span class="c1">#          short term forecast data</span>
+<span class="c1">#        - added conversion into GRIB2</span>
+<span class="c1">#        - added conversion into .fp format for faster execution of FLEXPART</span>
+<span class="c1">#          (see https://www.flexpart.eu/wiki/FpCtbtoWo4FpFormat)</span>
+<span class="c1">#</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">#        - removed function getFlexpartTime in class EcFlexpart</span>
+<span class="c1">#        - outsourced class ControlFile</span>
+<span class="c1">#        - outsourced class MarsRetrieval</span>
+<span class="c1">#        - changed class name from EIFlexpart to EcFlexpart</span>
+<span class="c1">#        - applied minor code changes (style)</span>
+<span class="c1">#        - removed &quot;dead code&quot; , e.g. retrieval of Q since it is not needed</span>
+<span class="c1">#        - removed &quot;times&quot; parameter from retrieve-method since it is not used</span>
+<span class="c1">#        - seperated function &quot;retrieve&quot; into smaller functions (less code</span>
+<span class="c1">#          duplication, easier testing)</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">#    FLEXPART needs grib files in a specifc format. All necessary data fields</span>
+<span class="c1">#    for one time step are stored in a single file. The class represents an</span>
+<span class="c1">#    instance with all the parameter and settings necessary for retrieving</span>
+<span class="c1">#    MARS data and modifing them so they are fitting FLEXPART need. The class</span>
+<span class="c1">#    is able to disaggregate the fluxes and convert grid types to the one needed</span>
+<span class="c1">#    by FLEXPART, therefore using the FORTRAN program.</span>
+<span class="c1">#</span>
+<span class="c1"># @Class Content:</span>
+<span class="c1">#    - __init__</span>
+<span class="c1">#    - write_namelist</span>
+<span class="c1">#    - retrieve</span>
+<span class="c1">#    - process_output</span>
+<span class="c1">#    - create</span>
+<span class="c1">#    - deacc_fluxes</span>
+<span class="c1">#</span>
+<span class="c1"># @Class Attributes:</span>
+<span class="c1">#</span>
+<span class="c1">#  TODO</span>
+<span class="c1">#</span>
+<span class="c1">#*******************************************************************************</span>
+<span class="c1">#pylint: disable=unsupported-assignment-operation</span>
+<span class="c1"># this is disabled because for this specific case its an error in pylint</span>
+<span class="c1">#pylint: disable=consider-using-enumerate</span>
+<span class="c1"># this is not useful in this case</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">import</span> <span class="nn">sys</span>
+<span class="kn">import</span> <span class="nn">glob</span>
+<span class="kn">import</span> <span class="nn">shutil</span>
+<span class="kn">import</span> <span class="nn">subprocess</span>
+<span class="kn">from</span> <span class="nn">datetime</span> <span class="k">import</span> <span class="n">datetime</span><span class="p">,</span> <span class="n">timedelta</span>
+<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
+
+<span class="kn">from</span> <span class="nn">gribapi</span> <span class="k">import</span> <span class="p">(</span><span class="n">grib_set</span><span class="p">,</span> <span class="n">grib_index_select</span><span class="p">,</span> <span class="n">grib_new_from_index</span><span class="p">,</span> <span class="n">grib_get</span><span class="p">,</span>
+                     <span class="n">grib_write</span><span class="p">,</span> <span class="n">grib_get_values</span><span class="p">,</span> <span class="n">grib_set_values</span><span class="p">,</span> <span class="n">grib_release</span><span class="p">,</span>
+                     <span class="n">grib_index_release</span><span class="p">,</span> <span class="n">grib_index_get</span><span class="p">)</span>
+
+<span class="c1"># from eccodes import (codes_index_select, codes_new_from_index, codes_get,</span>
+                     <span class="c1"># codes_get_values, codes_set_values, codes_set,</span>
+                     <span class="c1"># codes_write, codes_release, codes_new_from_index,</span>
+                     <span class="c1"># codes_index_release, codes_index_get)</span>
+
+<span class="c1"># software specific classes and modules from flex_extract</span>
+<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;../&#39;</span><span class="p">)</span>
+<span class="kn">import</span> <span class="nn">_config</span>
+<span class="kn">from</span> <span class="nn">GribTools</span> <span class="k">import</span> <span class="n">GribTools</span>
+<span class="kn">from</span> <span class="nn">mods.tools</span> <span class="k">import</span> <span class="p">(</span><span class="n">init128</span><span class="p">,</span> <span class="n">to_param_id</span><span class="p">,</span> <span class="n">silent_remove</span><span class="p">,</span> <span class="n">product</span><span class="p">,</span>
+                        <span class="n">my_error</span><span class="p">,</span> <span class="n">make_dir</span><span class="p">)</span>
+<span class="kn">from</span> <span class="nn">MarsRetrieval</span> <span class="k">import</span> <span class="n">MarsRetrieval</span>
+<span class="kn">import</span> <span class="nn">mods.disaggregation</span> <span class="k">as</span> <span class="nn">disaggregation</span>
+
+<span class="c1"># ------------------------------------------------------------------------------</span>
+<span class="c1"># CLASS</span>
+<span class="c1"># ------------------------------------------------------------------------------</span>
+<div class="viewcode-block" id="EcFlexpart"><a class="viewcode-back" href="../api.html#EcFlexpart.EcFlexpart">[docs]</a><span class="k">class</span> <span class="nc">EcFlexpart</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 to retrieve FLEXPART specific ECMWF data.</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">c</span><span class="p">,</span> <span class="n">fluxes</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39;Creates an object/instance of EcFlexpart with the associated</span>
+<span class="sd">        settings of its attributes for the retrieval.</span>
+
+<span class="sd">        Parameters:</span>
+<span class="sd">        -----------</span>
+<span class="sd">        c : :obj:`ControlFile`</span>
+<span class="sd">            Contains all the parameters of CONTROL file and</span>
+<span class="sd">            command line.</span>
+
+<span class="sd">        fluxes : :obj:`boolean`, optional</span>
+<span class="sd">            Decides if the flux parameter settings are stored or</span>
+<span class="sd">            the rest of the parameter list.</span>
+<span class="sd">            Default value is False.</span>
+
+<span class="sd">        Return</span>
+<span class="sd">        ------</span>
+
+<span class="sd">        &#39;&#39;&#39;</span>
+        <span class="c1"># set a counter for the number of mars requests generated</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">mreq_count</span> <span class="o">=</span> <span class="mi">0</span>
+
+        <span class="c1"># different mars types for retrieving data for flexpart</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">types</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span>
+
+        <span class="c1"># Pure forecast mode</span>
+        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">maxstep</span> <span class="o">&gt;</span> <span class="nb">len</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">type</span><span class="p">)</span> <span class="ow">and</span> <span class="s1">&#39;AN&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">c</span><span class="o">.</span><span class="n">type</span><span class="p">:</span>
+            <span class="n">c</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="p">[</span><span class="n">c</span><span class="o">.</span><span class="n">type</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span>
+            <span class="n">c</span><span class="o">.</span><span class="n">step</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;</span><span class="si">{:0&gt;3}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">step</span><span class="p">[</span><span class="mi">0</span><span class="p">]))]</span>
+            <span class="n">c</span><span class="o">.</span><span class="n">time</span> <span class="o">=</span> <span class="p">[</span><span class="n">c</span><span class="o">.</span><span class="n">time</span><span class="p">[</span><span class="mi">0</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="mi">1</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">maxstep</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
+                <span class="n">c</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">type</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
+                <span class="n">c</span><span class="o">.</span><span class="n">step</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">{:0&gt;3}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">i</span><span class="p">))</span>
+                <span class="n">c</span><span class="o">.</span><span class="n">time</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">time</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
+
+        <span class="bp">self</span><span class="o">.</span><span class="n">inputdir</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">inputdir</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">dataset</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">dataset</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">basetime</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">basetime</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">dtime</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">dtime</span>
+        <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
+        <span class="k">if</span> <span class="n">fluxes</span> <span class="ow">and</span> <span class="n">c</span><span class="o">.</span><span class="n">maxstep</span> <span class="o">&lt;=</span> <span class="mi">24</span><span class="p">:</span>
+            <span class="c1"># no forecast beyond one day is needed!</span>
+            <span class="c1"># Thus, prepare flux data manually as usual</span>
+            <span class="c1"># with only forecast fields with start times at 00/12</span>
+            <span class="c1"># (but without 00/12 fields since these are</span>
+            <span class="c1"># the initialisation times of the flux fields</span>
+            <span class="c1"># and therefore are zero all the time)</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">acctype</span><span class="p">)]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;times&#39;</span><span class="p">:</span> <span class="nb">str</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">acctime</span><span class="p">),</span>
+                                          <span class="s1">&#39;steps&#39;</span><span class="p">:</span> <span class="s1">&#39;</span><span class="si">{}</span><span class="s1">/to/</span><span class="si">{}</span><span class="s1">/by/</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
+                                              <span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">accmaxstep</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">)}</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="k">for</span> <span class="n">ty</span><span class="p">,</span> <span class="n">st</span><span class="p">,</span> <span class="n">ti</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">type</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">step</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">time</span><span class="p">):</span>
+                <span class="n">btlist</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="mi">24</span><span class="p">)</span>
+                <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">basetime</span> <span class="o">==</span> <span class="s1">&#39;12&#39;</span><span class="p">:</span>
+                    <span class="n">btlist</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">11</span><span class="p">,</span> <span class="mi">12</span><span class="p">]</span>
+                <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">basetime</span> <span class="o">==</span> <span class="s1">&#39;00&#39;</span><span class="p">:</span>
+                    <span class="n">btlist</span> <span class="o">=</span> <span class="p">[</span><span class="mi">13</span><span class="p">,</span> <span class="mi">14</span><span class="p">,</span> <span class="mi">15</span><span class="p">,</span> <span class="mi">16</span><span class="p">,</span> <span class="mi">17</span><span class="p">,</span> <span class="mi">18</span><span class="p">,</span> <span class="mi">19</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">21</span><span class="p">,</span> <span class="mi">22</span><span class="p">,</span> <span class="mi">23</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span>
+
+                <span class="k">if</span> <span class="p">((</span><span class="n">ty</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;AN&#39;</span> <span class="ow">and</span> <span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">time</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">%</span> <span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">))</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="ow">or</span>
+                    <span class="p">(</span><span class="n">ty</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="o">!=</span> <span class="s1">&#39;AN&#39;</span> <span class="ow">and</span> <span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">step</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">%</span> <span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">))</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">and</span>
+                     <span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">step</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="o">%</span> <span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">))</span> <span class="p">)</span> <span class="ow">and</span> \
+                    <span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">time</span><span class="p">[</span><span class="n">i</span><span class="p">])</span> <span class="ow">in</span> <span class="n">btlist</span> <span class="ow">or</span> <span class="n">c</span><span class="o">.</span><span class="n">maxstep</span> <span class="o">&gt;</span> <span class="mi">24</span><span class="p">):</span>
+
+                    <span class="k">if</span> <span class="n">ty</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="n">ty</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;times&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="s1">&#39;steps&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">}</span>
+
+                    <span class="k">if</span> <span class="n">ti</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="n">ty</span><span class="p">][</span><span class="s1">&#39;times&#39;</span><span class="p">]:</span>
+                        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="n">ty</span><span class="p">][</span><span class="s1">&#39;times&#39;</span><span class="p">]:</span>
+                            <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="n">ty</span><span class="p">][</span><span class="s1">&#39;times&#39;</span><span class="p">]</span> <span class="o">+=</span> <span class="s1">&#39;/&#39;</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="n">ty</span><span class="p">][</span><span class="s1">&#39;times&#39;</span><span class="p">]</span> <span class="o">+=</span> <span class="n">ti</span>
+
+                    <span class="k">if</span> <span class="n">st</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="n">ty</span><span class="p">][</span><span class="s1">&#39;steps&#39;</span><span class="p">]:</span>
+                        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="n">ty</span><span class="p">][</span><span class="s1">&#39;steps&#39;</span><span class="p">]:</span>
+                            <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="n">ty</span><span class="p">][</span><span class="s1">&#39;steps&#39;</span><span class="p">]</span> <span class="o">+=</span> <span class="s1">&#39;/&#39;</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="n">ty</span><span class="p">][</span><span class="s1">&#39;steps&#39;</span><span class="p">]</span> <span class="o">+=</span> <span class="n">st</span>
+                <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
+
+        <span class="bp">self</span><span class="o">.</span><span class="n">marsclass</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">marsclass</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">stream</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">stream</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">number</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">number</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">resol</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">resol</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">accuracy</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">accuracy</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">level</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">level</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">expver</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">expver</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">levelist</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">levelist</span>
+        <span class="c1"># for gaussian grid retrieval</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">glevelist</span> <span class="o">=</span> <span class="s1">&#39;1/to/&#39;</span> <span class="o">+</span> <span class="n">c</span><span class="o">.</span><span class="n">level</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">gaussian</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">gaussian</span>
+
+        <span class="k">if</span> <span class="s1">&#39;N&#39;</span> <span class="ow">in</span> <span class="n">c</span><span class="o">.</span><span class="n">grid</span><span class="p">:</span>  <span class="c1"># Gaussian output grid</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">grid</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">grid</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">area</span> <span class="o">=</span> <span class="s1">&#39;G&#39;</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">grid</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{}</span><span class="s1">/</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">grid</span><span class="p">)</span> <span class="o">/</span> <span class="mf">1000.</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">grid</span><span class="p">)</span> <span class="o">/</span> <span class="mf">1000.</span><span class="p">)</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">area</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{}</span><span class="s1">/</span><span class="si">{}</span><span class="s1">/</span><span class="si">{}</span><span class="s1">/</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">upper</span><span class="p">)</span> <span class="o">/</span> <span class="mf">1000.</span><span class="p">,</span>
+                                             <span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">left</span><span class="p">)</span> <span class="o">/</span> <span class="mf">1000.</span><span class="p">,</span>
+                                             <span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">lower</span><span class="p">)</span> <span class="o">/</span> <span class="mf">1000.</span><span class="p">,</span>
+                                             <span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">right</span><span class="p">)</span> <span class="o">/</span> <span class="mf">1000.</span><span class="p">)</span>
+
+        <span class="bp">self</span><span class="o">.</span><span class="n">outputfilelist</span> <span class="o">=</span> <span class="p">[]</span>
+
+
+        <span class="c1"># Now comes the nasty part that deals with the different</span>
+        <span class="c1"># scenarios we have:</span>
+        <span class="c1"># 1) Calculation of etadot on</span>
+        <span class="c1">#    a) Gaussian grid</span>
+        <span class="c1">#    b) Output grid</span>
+        <span class="c1">#    c) Output grid using parameter 77 retrieved from MARS</span>
+        <span class="c1"># 3) Calculation/Retrieval of omega</span>
+        <span class="c1"># 4) Download also data for WRF</span>
+
+        <span class="c1"># Different grids need different retrievals</span>
+        <span class="c1"># SH = Spherical Harmonics, GG = Gaussian Grid,</span>
+        <span class="c1"># OG = Output Grid, ML = MultiLevel, SL = SingleLevel</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">params</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;SH__ML&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="s1">&#39;SH__SL&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">,</span>
+                       <span class="s1">&#39;GG__ML&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="s1">&#39;GG__SL&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">,</span>
+                       <span class="s1">&#39;OG__ML&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="s1">&#39;OG__SL&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">,</span>
+                       <span class="s1">&#39;OG_OROLSM_SL&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="s1">&#39;OG_acc_SL&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">}</span>
+        <span class="c1"># the self.params dictionary stores a list of</span>
+        <span class="c1"># [param, levtype, levelist, grid] per key</span>
+
+        <span class="k">if</span> <span class="n">fluxes</span> <span class="ow">is</span> <span class="kc">False</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;SH__SL&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;LNSP&#39;</span><span class="p">,</span> <span class="s1">&#39;ML&#39;</span><span class="p">,</span> <span class="s1">&#39;1&#39;</span><span class="p">,</span> <span class="s1">&#39;OFF&#39;</span><span class="p">]</span>
+            <span class="c1">#                        &quot;SD/MSL/TCC/10U/10V/2T/2D/129/172&quot;</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__SL&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;141/151/164/165/166/167/168/129/172&quot;</span><span class="p">,</span> \
+                                     <span class="s1">&#39;SFC&#39;</span><span class="p">,</span> <span class="s1">&#39;1&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">grid</span><span class="p">]</span>
+            <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">addpar</span><span class="p">:</span>
+                <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">addpar</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;/&#39;</span><span class="p">:</span>
+                    <span class="n">c</span><span class="o">.</span><span class="n">addpar</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">addpar</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__SL&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="s1">&#39;/&#39;</span> <span class="o">+</span> <span class="s1">&#39;/&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">addpar</span><span class="p">)</span>
+
+            <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">marsclass</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;EA&#39;</span> <span class="ow">or</span> <span class="n">c</span><span class="o">.</span><span class="n">marsclass</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;EP&#39;</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG_OROLSM__SL&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;160/27/28/244&quot;</span><span class="p">,</span>
+                                                <span class="s1">&#39;SFC&#39;</span><span class="p">,</span> <span class="s1">&#39;1&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">grid</span><span class="p">]</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG_OROLSM__SL&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;160/27/28/173&quot;</span><span class="p">,</span> \
+                                                <span class="s1">&#39;SFC&#39;</span><span class="p">,</span> <span class="s1">&#39;1&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">grid</span><span class="p">]</span>
+
+            <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__ML&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;T/Q&#39;</span><span class="p">,</span> <span class="s1">&#39;ML&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">levelist</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">grid</span><span class="p">]</span>
+
+            <span class="c1">#if c.gauss == &#39;0&#39; and c.eta == &#39;1&#39;:</span>
+            <span class="k">if</span> <span class="ow">not</span> <span class="n">c</span><span class="o">.</span><span class="n">gauss</span> <span class="ow">and</span> <span class="n">c</span><span class="o">.</span><span class="n">eta</span><span class="p">:</span>
+                <span class="c1"># the simplest case</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__ML&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="s1">&#39;/U/V/77&#39;</span>
+            <span class="c1">#elif c.gauss == &#39;0&#39; and c.eta == &#39;0&#39;:</span>
+            <span class="k">elif</span> <span class="ow">not</span> <span class="n">c</span><span class="o">.</span><span class="n">gauss</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">c</span><span class="o">.</span><span class="n">eta</span><span class="p">:</span>
+            <span class="c1"># this is not recommended (inaccurate)</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__ML&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="s1">&#39;/U/V&#39;</span>
+            <span class="c1">#elif c.gauss == &#39;1&#39; and c.eta == &#39;0&#39;:</span>
+            <span class="k">elif</span> <span class="n">c</span><span class="o">.</span><span class="n">gauss</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">c</span><span class="o">.</span><span class="n">eta</span><span class="p">:</span>
+                <span class="c1"># this is needed for data before 2008, or for reanalysis data</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;GG__SL&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;Q&#39;</span><span class="p">,</span> <span class="s1">&#39;ML&#39;</span><span class="p">,</span> <span class="s1">&#39;1&#39;</span><span class="p">,</span> \
+                                         <span class="s1">&#39;</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">((</span><span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">resol</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">)]</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;SH__ML&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;U/V/D&#39;</span><span class="p">,</span> <span class="s1">&#39;ML&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">glevelist</span><span class="p">,</span> <span class="s1">&#39;OFF&#39;</span><span class="p">]</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Warning: This is a very costly parameter combination, </span><span class="se">\</span>
+<span class="s1">                      use only for debugging!&#39;</span><span class="p">)</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;GG__SL&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;Q&#39;</span><span class="p">,</span> <span class="s1">&#39;ML&#39;</span><span class="p">,</span> <span class="s1">&#39;1&#39;</span><span class="p">,</span> \
+                                         <span class="s1">&#39;</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">((</span><span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">resol</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">)]</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;GG__ML&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;U/V/D/77&#39;</span><span class="p">,</span> <span class="s1">&#39;ML&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">glevelist</span><span class="p">,</span> \
+                                         <span class="s1">&#39;</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">((</span><span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">resol</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">)]</span>
+
+            <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">omega</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__ML&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="s1">&#39;/W&#39;</span>
+
+            <span class="c1"># add cloud water content if necessary</span>
+            <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">cwc</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__ML&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="s1">&#39;/CLWC/CIWC&#39;</span>
+
+            <span class="c1"># add vorticity and geopotential height for WRF if necessary</span>
+            <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">wrf</span><span class="p">:</span>
+                <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__ML&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="s1">&#39;/Z/VO&#39;</span>
+                <span class="k">if</span> <span class="s1">&#39;/D&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__ML&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]:</span>
+                    <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__ML&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="s1">&#39;/D&#39;</span>
+                <span class="c1">#wrf_sfc = &#39;sp/msl/skt/2t/10u/10v/2d/z/lsm/sst/ci/sd/stl1/ /</span>
+                <span class="c1">#           stl2/stl3/stl4/swvl1/swvl2/swvl3/swvl4&#39;.upper()</span>
+                <span class="n">wrf_sfc</span> <span class="o">=</span> <span class="s1">&#39;134/235/167/165/166/168/129/172/34/31/141/ </span><span class="se">\</span>
+<span class="s1">                           139/170/183/236/39/40/41/42&#39;</span>
+                <span class="n">lwrt_sfc</span> <span class="o">=</span> <span class="n">wrf_sfc</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)</span>
+                <span class="k">for</span> <span class="n">par</span> <span class="ow">in</span> <span class="n">lwrt_sfc</span><span class="p">:</span>
+                    <span class="k">if</span> <span class="n">par</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__SL&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]:</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG__SL&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">+=</span> <span class="s1">&#39;/&#39;</span> <span class="o">+</span> <span class="n">par</span>
+
+        <span class="k">else</span><span class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG_acc_SL&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;LSP/CP/SSHF/EWSS/NSSS/SSR&quot;</span><span class="p">,</span> \
+                                        <span class="s1">&#39;SFC&#39;</span><span class="p">,</span> <span class="s1">&#39;1&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">grid</span><span class="p">]</span>
+
+        <span class="k">return</span>
+
+
+    <span class="k">def</span> <span class="nf">_mk_targetname</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ftype</span><span class="p">,</span> <span class="n">param</span><span class="p">,</span> <span class="n">date</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39;Creates the filename for the requested grib data to be stored in.</span>
+<span class="sd">        This name is passed as the &quot;target&quot; parameter in the request.</span>
+
+<span class="sd">        Parameters</span>
+<span class="sd">        ----------</span>
+<span class="sd">        ftype : :obj:`string`</span>
+<span class="sd">            Shortcut name of the type of the field. E.g. AN, FC, PF, ...</span>
+
+<span class="sd">        param : :obj:`string`</span>
+<span class="sd">            Shortcut of the grid type. E.g. SH__ML, SH__SL, GG__ML,</span>
+<span class="sd">            GG__SL, OG__ML, OG__SL, OG_OROLSM_SL, OG_acc_SL</span>
+
+<span class="sd">        date : :obj:`string`</span>
+<span class="sd">            The date period of the grib data to be stored in this file.</span>
+
+<span class="sd">        Return</span>
+<span class="sd">        ------</span>
+<span class="sd">        targetname : :obj:`string`</span>
+<span class="sd">            The target filename for the grib data.</span>
+<span class="sd">        &#39;&#39;&#39;</span>
+        <span class="n">targetname</span> <span class="o">=</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">inputdir</span> <span class="o">+</span> <span class="s1">&#39;/&#39;</span> <span class="o">+</span> <span class="n">ftype</span> <span class="o">+</span> <span class="n">param</span> <span class="o">+</span> <span class="s1">&#39;.&#39;</span> <span class="o">+</span> <span class="n">date</span> <span class="o">+</span> <span class="s1">&#39;.&#39;</span> <span class="o">+</span>
+                      <span class="nb">str</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">getppid</span><span class="p">())</span> <span class="o">+</span> <span class="s1">&#39;.&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">getpid</span><span class="p">())</span> <span class="o">+</span> <span class="s1">&#39;.grb&#39;</span><span class="p">)</span>
+
+        <span class="k">return</span> <span class="n">targetname</span>
+
+
+    <span class="k">def</span> <span class="nf">_start_retrievement</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">par_dict</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39;Creates the Mars Retrieval and prints or submits the request</span>
+<span class="sd">        depending on the status of the request variable.</span>
+
+<span class="sd">        Parameters</span>
+<span class="sd">        ----------</span>
+<span class="sd">        request : :obj:`integer`</span>
+<span class="sd">            Selects the mode of retrieval.</span>
+<span class="sd">            0: Retrieves the data from ECMWF.</span>
+<span class="sd">            1: Prints the mars requests to an output file.</span>
+<span class="sd">            2: Retrieves the data and prints the mars request.</span>
+
+<span class="sd">        par_dict : :obj:`dictionary`</span>
+<span class="sd">            Contains all parameter which have to be set for creating the</span>
+<span class="sd">            Mars Retrievals. The parameter are:</span>
+<span class="sd">            marsclass, dataset, stream, type, levtype, levelist, resol,</span>
+<span class="sd">            gaussian, accuracy, grid, target, area, date, time, number,</span>
+<span class="sd">            step, expver, param</span>
+
+<span class="sd">        Return</span>
+<span class="sd">        ------</span>
+
+<span class="sd">        &#39;&#39;&#39;</span>
+        <span class="c1"># increase number of mars requests</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">mreq_count</span> <span class="o">+=</span> <span class="mi">1</span>
+
+        <span class="n">MR</span> <span class="o">=</span> <span class="n">MarsRetrieval</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">server</span><span class="p">,</span>
+                           <span class="bp">self</span><span class="o">.</span><span class="n">public</span><span class="p">,</span>
+                           <span class="n">marsclass</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;marsclass&#39;</span><span class="p">],</span>
+                           <span class="n">dataset</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;dataset&#39;</span><span class="p">],</span>
+                           <span class="n">stream</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;stream&#39;</span><span class="p">],</span>
+                           <span class="nb">type</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">],</span>
+                           <span class="n">levtype</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;levtype&#39;</span><span class="p">],</span>
+                           <span class="n">levelist</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;levelist&#39;</span><span class="p">],</span>
+                           <span class="n">resol</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;resol&#39;</span><span class="p">],</span>
+                           <span class="n">gaussian</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;gaussian&#39;</span><span class="p">],</span>
+                           <span class="n">accuracy</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;accuracy&#39;</span><span class="p">],</span>
+                           <span class="n">grid</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;grid&#39;</span><span class="p">],</span>
+                           <span class="n">target</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;target&#39;</span><span class="p">],</span>
+                           <span class="n">area</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;area&#39;</span><span class="p">],</span>
+                           <span class="n">date</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">],</span>
+                           <span class="n">time</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">],</span>
+                           <span class="n">number</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;number&#39;</span><span class="p">],</span>
+                           <span class="n">step</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;step&#39;</span><span class="p">],</span>
+                           <span class="n">expver</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;expver&#39;</span><span class="p">],</span>
+                           <span class="n">param</span><span class="o">=</span><span class="n">par_dict</span><span class="p">[</span><span class="s1">&#39;param&#39;</span><span class="p">])</span>
+
+        <span class="k">if</span> <span class="n">request</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">MR</span><span class="o">.</span><span class="n">display_info</span><span class="p">()</span>
+            <span class="n">MR</span><span class="o">.</span><span class="n">data_retrieve</span><span class="p">()</span>
+        <span class="k">elif</span> <span class="n">request</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
+            <span class="n">MR</span><span class="o">.</span><span class="n">print_infodata_csv</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mreq_count</span><span class="p">)</span>
+        <span class="k">elif</span> <span class="n">request</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
+            <span class="n">MR</span><span class="o">.</span><span class="n">print_infodata_csv</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mreq_count</span><span class="p">)</span>
+            <span class="n">MR</span><span class="o">.</span><span class="n">display_info</span><span class="p">()</span>
+            <span class="n">MR</span><span class="o">.</span><span class="n">data_retrieve</span><span class="p">()</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Failure&#39;</span><span class="p">)</span>
+
+        <span class="k">return</span>
+
+
+    <span class="k">def</span> <span class="nf">_mk_index_values</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">inputdir</span><span class="p">,</span> <span class="n">inputfiles</span><span class="p">,</span> <span class="n">keys</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39;Creates an index file for a set of grib parameter keys.</span>
+<span class="sd">        The values from the index keys are returned in a list.</span>
+
+<span class="sd">        Parameters</span>
+<span class="sd">        ----------</span>
+<span class="sd">        keys : :obj:`dictionary`</span>
+<span class="sd">            List of parameter names which serves as index.</span>
+
+<span class="sd">        inputfiles : :obj:`UioFiles`</span>
+<span class="sd">            Contains a list of files.</span>
+
+<span class="sd">        Return</span>
+<span class="sd">        ------</span>
+<span class="sd">        iid : :obj:`grib_index`</span>
+<span class="sd">            This is a grib specific index structure to access</span>
+<span class="sd">            messages in a file.</span>
+
+<span class="sd">        index_vals : :obj:`list`</span>
+<span class="sd">            Contains the values from the keys used for a distinct selection</span>
+<span class="sd">            of grib messages in processing  the grib files.</span>
+<span class="sd">            Content looks like e.g.:</span>
+<span class="sd">            index_vals[0]: (&#39;20171106&#39;, &#39;20171107&#39;, &#39;20171108&#39;) ; date</span>
+<span class="sd">            index_vals[1]: (&#39;0&#39;, &#39;1200&#39;, &#39;1800&#39;, &#39;600&#39;) ; time</span>
+<span class="sd">            index_vals[2]: (&#39;0&#39;, &#39;12&#39;, &#39;3&#39;, &#39;6&#39;, &#39;9&#39;) ; stepRange</span>
+<span class="sd">        &#39;&#39;&#39;</span>
+        <span class="n">iid</span> <span class="o">=</span> <span class="kc">None</span>
+        <span class="n">index_keys</span> <span class="o">=</span> <span class="n">keys</span>
+
+        <span class="n">indexfile</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">inputdir</span><span class="p">,</span> <span class="n">_config</span><span class="o">.</span><span class="n">FILE_GRIB_INDEX</span><span class="p">)</span>
+        <span class="n">silent_remove</span><span class="p">(</span><span class="n">indexfile</span><span class="p">)</span>
+        <span class="n">grib</span> <span class="o">=</span> <span class="n">GribTools</span><span class="p">(</span><span class="n">inputfiles</span><span class="o">.</span><span class="n">files</span><span class="p">)</span>
+        <span class="c1"># creates new index file</span>
+        <span class="n">iid</span> <span class="o">=</span> <span class="n">grib</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">index_keys</span><span class="o">=</span><span class="n">index_keys</span><span class="p">,</span> <span class="n">index_file</span><span class="o">=</span><span class="n">indexfile</span><span class="p">)</span>
+
+        <span class="c1"># read the values of index keys</span>
+        <span class="n">index_vals</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">index_keys</span><span class="p">:</span>
+            <span class="c1">#index_vals.append(grib_index_get(iid, key))</span>
+            <span class="c1">#print(index_vals[-1])</span>
+            <span class="n">key_vals</span> <span class="o">=</span> <span class="n">grib_index_get</span><span class="p">(</span><span class="n">iid</span><span class="p">,</span> <span class="n">key</span><span class="p">)</span>
+            <span class="nb">print</span><span class="p">(</span><span class="n">key_vals</span><span class="p">)</span>
+            <span class="c1"># have to sort the steps for disaggregation,</span>
+            <span class="c1"># therefore convert to int first</span>
+            <span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="s1">&#39;step&#39;</span><span class="p">:</span>
+                <span class="n">key_vals</span> <span class="o">=</span> <span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">k</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">key_vals</span><span class="p">]</span>
+                <span class="n">key_vals</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span>
+                <span class="n">key_vals</span> <span class="o">=</span> <span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">k</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">key_vals</span><span class="p">]</span>
+            <span class="n">index_vals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">key_vals</span><span class="p">)</span>
+            <span class="c1"># index_vals looks for example like:</span>
+            <span class="c1"># index_vals[0]: (&#39;20171106&#39;, &#39;20171107&#39;, &#39;20171108&#39;) ; date</span>
+            <span class="c1"># index_vals[1]: (&#39;0&#39;, &#39;1200&#39;) ; time</span>
+            <span class="c1"># index_vals[2]: (3&#39;, &#39;6&#39;, &#39;9&#39;, &#39;12&#39;) ; stepRange</span>
+
+        <span class="k">return</span> <span class="n">iid</span><span class="p">,</span> <span class="n">index_vals</span>
+
+
+<div class="viewcode-block" id="EcFlexpart.retrieve"><a class="viewcode-back" href="../api.html#EcFlexpart.EcFlexpart.retrieve">[docs]</a>    <span class="k">def</span> <span class="nf">retrieve</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">server</span><span class="p">,</span> <span class="n">dates</span><span class="p">,</span> <span class="n">public</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">inputdir</span><span class="o">=</span><span class="s1">&#39;.&#39;</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39;Finalizing the retrieval information by setting final details</span>
+<span class="sd">        depending on grid type.</span>
+<span class="sd">        Prepares MARS retrievals per grid type and submits them.</span>
+
+<span class="sd">        Parameters</span>
+<span class="sd">        ----------</span>
+<span class="sd">        server : :obj:`ECMWFService` or :obj:`ECMWFDataServer`</span>
+<span class="sd">            The connection to the ECMWF server. This is different</span>
+<span class="sd">            for member state users which have full access and non</span>
+<span class="sd">            member state users which have only access to the public</span>
+<span class="sd">            data sets. The decision is made from command line argument</span>
+<span class="sd">            &quot;public&quot;; for public access its True (ECMWFDataServer)</span>
+<span class="sd">            for member state users its False (ECMWFService)</span>
+
+<span class="sd">        dates : :obj:`string`</span>
+<span class="sd">            Contains start and end date of the retrieval in the format</span>
+<span class="sd">            &quot;YYYYMMDD/to/YYYYMMDD&quot;</span>
+
+<span class="sd">        request : :obj:`integer`</span>
+<span class="sd">            Selects the mode of retrieval.</span>
+<span class="sd">            0: Retrieves the data from ECMWF.</span>
+<span class="sd">            1: Prints the mars requests to an output file.</span>
+<span class="sd">            2: Retrieves the data and prints the mars request.</span>
+
+<span class="sd">        inputdir : :obj:`string`, optional</span>
+<span class="sd">            Path to the directory where the retrieved data is about</span>
+<span class="sd">            to be stored. The default is the current directory (&#39;.&#39;).</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">dates</span> <span class="o">=</span> <span class="n">dates</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">server</span> <span class="o">=</span> <span class="n">server</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">public</span> <span class="o">=</span> <span class="n">public</span>
+        <span class="bp">self</span><span class="o">.</span><span class="n">inputdir</span> <span class="o">=</span> <span class="n">inputdir</span>
+        <span class="n">oro</span> <span class="o">=</span> <span class="kc">False</span>
+
+        <span class="c1"># define times with datetime module</span>
+        <span class="n">t12h</span> <span class="o">=</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">hours</span><span class="o">=</span><span class="mi">12</span><span class="p">)</span>
+        <span class="n">t24h</span> <span class="o">=</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">hours</span><span class="o">=</span><span class="mi">24</span><span class="p">)</span>
+
+        <span class="c1"># dictionary which contains all parameter for the mars request,</span>
+        <span class="c1"># entries with a &quot;None&quot; will change in different requests and will</span>
+        <span class="c1"># therefore be set in each request seperately</span>
+        <span class="n">retr_param_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;marsclass&#39;</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">marsclass</span><span class="p">,</span>
+                           <span class="s1">&#39;dataset&#39;</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">dataset</span><span class="p">,</span>
+                           <span class="s1">&#39;stream&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
+                           <span class="s1">&#39;type&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
+                           <span class="s1">&#39;levtype&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
+                           <span class="s1">&#39;levelist&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
+                           <span class="s1">&#39;resol&#39;</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">resol</span><span class="p">,</span>
+                           <span class="s1">&#39;gaussian&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
+                           <span class="s1">&#39;accuracy&#39;</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">accuracy</span><span class="p">,</span>
+                           <span class="s1">&#39;grid&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
+                           <span class="s1">&#39;target&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
+                           <span class="s1">&#39;area&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
+                           <span class="s1">&#39;date&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
+                           <span class="s1">&#39;time&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
+                           <span class="s1">&#39;number&#39;</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">number</span><span class="p">,</span>
+                           <span class="s1">&#39;step&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
+                           <span class="s1">&#39;expver&#39;</span><span class="p">:</span><span class="bp">self</span><span class="o">.</span><span class="n">expver</span><span class="p">,</span>
+                           <span class="s1">&#39;param&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">}</span>
+
+        <span class="k">for</span> <span class="n">ftype</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">:</span>
+            <span class="c1"># fk contains field types such as</span>
+            <span class="c1">#     [AN, FC, PF, CV]</span>
+            <span class="c1"># fv contains all of the items of the belonging key</span>
+            <span class="c1">#     [times, steps]</span>
+            <span class="k">for</span> <span class="n">pk</span><span class="p">,</span> <span class="n">pv</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
+                <span class="c1"># pk contains one of these keys of params</span>
+                <span class="c1">#     [SH__ML, SH__SL, GG__ML, GG__SL, OG__ML, OG__SL,</span>
+                <span class="c1">#      OG_OROLSM_SL, OG_acc_SL]</span>
+                <span class="c1"># pv contains all of the items of the belonging key</span>
+                <span class="c1">#     [param, levtype, levelist, grid]</span>
+                <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">pv</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
+                    <span class="k">continue</span>
+                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ftype</span>
+                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="n">ftype</span><span class="p">][</span><span class="s1">&#39;times&#39;</span><span class="p">]</span>
+                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;step&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="p">[</span><span class="n">ftype</span><span class="p">][</span><span class="s1">&#39;steps&#39;</span><span class="p">]</span>
+                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dates</span>
+                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;stream&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">stream</span>
+                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;target&#39;</span><span class="p">]</span> <span class="o">=</span> \
+                    <span class="bp">self</span><span class="o">.</span><span class="n">_mk_targetname</span><span class="p">(</span><span class="n">ftype</span><span class="p">,</span>
+                                        <span class="n">pk</span><span class="p">,</span>
+                                        <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>
+                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;param&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">pv</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
+                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;levtype&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">pv</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
+                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;levelist&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">pv</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
+                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;grid&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">pv</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span>
+                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;area&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">area</span>
+                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;gaussian&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">gaussian</span>
+
+                <span class="k">if</span> <span class="n">pk</span> <span class="o">==</span> <span class="s1">&#39;OG__SL&#39;</span><span class="p">:</span>
+                    <span class="k">pass</span>
+                <span class="k">if</span> <span class="n">pk</span> <span class="o">==</span> <span class="s1">&#39;OG_OROLSM__SL&#39;</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">oro</span><span class="p">:</span>
+                    <span class="n">oro</span> <span class="o">=</span> <span class="kc">True</span>
+                    <span class="c1"># in CERA20C (class EP) there is no stream &quot;OPER&quot;!</span>
+                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">marsclass</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="o">!=</span> <span class="s1">&#39;EP&#39;</span><span class="p">:</span>
+                        <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;stream&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;OPER&#39;</span>
+                    <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;AN&#39;</span>
+                    <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;00&#39;</span>
+                    <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;step&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;000&#39;</span>
+                    <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dates</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
+                    <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;target&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_mk_targetname</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">,</span>
+                                            <span class="n">pk</span><span class="p">,</span> <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">])</span>
+                <span class="k">elif</span> <span class="n">pk</span> <span class="o">==</span> <span class="s1">&#39;OG_OROLSM__SL&#39;</span> <span class="ow">and</span> <span class="n">oro</span><span class="p">:</span>
+                    <span class="k">continue</span>
+                <span class="k">if</span> <span class="n">pk</span> <span class="o">==</span> <span class="s1">&#39;GG__SL&#39;</span> <span class="ow">and</span> <span class="n">pv</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;Q&#39;</span><span class="p">:</span>
+                    <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;area&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
+                    <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;gaussian&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;reduced&#39;</span>
+
+    <span class="c1"># ------  on demand path  --------------------------------------------------</span>
+                <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">basetime</span><span class="p">:</span>
+                    <span class="c1"># ******* start retrievement</span>
+                    <span class="bp">self</span><span class="o">.</span><span class="n">_start_retrievement</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">retr_param_dict</span><span class="p">)</span>
+    <span class="c1"># ------  operational path  ------------------------------------------------</span>
+                <span class="k">else</span><span class="p">:</span>
+                    <span class="c1"># check if mars job requests fields beyond basetime.</span>
+                    <span class="c1"># if yes eliminate those fields since they may not</span>
+                    <span class="c1"># be accessible with user&#39;s credentials</span>
+
+                    <span class="n">enddate</span> <span class="o">=</span> <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
+                    <span class="n">elimit</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">enddate</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">basetime</span><span class="p">,</span>
+                                               <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">)</span>
+
+                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">basetime</span> <span class="o">==</span> <span class="s1">&#39;12&#39;</span><span class="p">:</span>
+                        <span class="c1"># --------------  flux data ----------------------------</span>
+                        <span class="k">if</span> <span class="s1">&#39;acc&#39;</span> <span class="ow">in</span> <span class="n">pk</span><span class="p">:</span>
+
+                        <span class="c1"># Strategy:</span>
+                        <span class="c1"># if maxtime-elimit &gt;= 24h reduce date by 1,</span>
+                        <span class="c1"># if 12h &lt;= maxtime-elimit&lt;12h reduce time for last date</span>
+                        <span class="c1"># if maxtime-elimit&lt;12h reduce step for last time</span>
+                        <span class="c1"># A split of the MARS job into 2 is likely necessary.</span>
+
+
+                            <span class="n">startdate</span> <span class="o">=</span> <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
+                            <span class="n">enddate</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="n">elimit</span> <span class="o">-</span> <span class="n">t24h</span><span class="p">,</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)</span>
+                            <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;/&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">startdate</span><span class="p">,</span>
+                                                                <span class="s1">&#39;to&#39;</span><span class="p">,</span>
+                                                                <span class="n">enddate</span><span class="p">])</span>
+
+                            <span class="c1"># ******* start retrievement</span>
+                            <span class="bp">self</span><span class="o">.</span><span class="n">_start_retrievement</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">retr_param_dict</span><span class="p">)</span>
+
+                            <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">]</span> <span class="o">=</span> \
+                                <span class="n">datetime</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="n">elimit</span> <span class="o">-</span> <span class="n">t12h</span><span class="p">,</span> <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)</span>
+                            <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;00&#39;</span>
+                            <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;target&#39;</span><span class="p">]</span> <span class="o">=</span> \
+                                <span class="bp">self</span><span class="o">.</span><span class="n">_mk_targetname</span><span class="p">(</span><span class="n">ftype</span><span class="p">,</span> <span class="n">pk</span><span class="p">,</span>
+                                                    <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">])</span>
+
+                            <span class="c1"># ******* start retrievement</span>
+                            <span class="bp">self</span><span class="o">.</span><span class="n">_start_retrievement</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">retr_param_dict</span><span class="p">)</span>
+
+                        <span class="c1"># --------------  non flux data ------------------------</span>
+                        <span class="k">else</span><span class="p">:</span>
+                            <span class="c1"># ******* start retrievement</span>
+                            <span class="bp">self</span><span class="o">.</span><span class="n">_start_retrievement</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">retr_param_dict</span><span class="p">)</span>
+
+                    <span class="k">else</span><span class="p">:</span> <span class="c1"># basetime = 0</span>
+                        <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">]</span> <span class="o">=</span> \
+                            <span class="n">datetime</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="n">elimit</span> <span class="o">-</span> <span class="n">t24h</span><span class="p">,</span> <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)</span>
+
+                        <span class="n">timesave</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">])</span>
+
+                        <span class="k">if</span> <span class="s1">&#39;/&#39;</span> <span class="ow">in</span> <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">]:</span>
+                            <span class="n">times</span> <span class="o">=</span> <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)</span>
+                            <span class="n">steps</span> <span class="o">=</span> <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;step&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)</span>
+                            <span class="k">while</span> <span class="p">(</span><span class="n">pk</span> <span class="o">!=</span> <span class="s1">&#39;OG_OROLSM__SL&#39;</span> <span class="ow">and</span>
+                                   <span class="s1">&#39;acc&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">pk</span> <span class="ow">and</span>
+                                   <span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">times</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">+</span> <span class="nb">int</span><span class="p">(</span><span class="n">steps</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span> <span class="o">&lt;=</span> <span class="mi">12</span><span class="p">):</span>
+                                <span class="n">times</span> <span class="o">=</span> <span class="n">times</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
+
+                            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">times</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
+                                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;/&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">times</span><span class="p">)</span>
+                            <span class="k">else</span><span class="p">:</span>
+                                <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">times</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
+
+                        <span class="c1"># ******* start retrievement</span>
+                        <span class="bp">self</span><span class="o">.</span><span class="n">_start_retrievement</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">retr_param_dict</span><span class="p">)</span>
+
+                        <span class="k">if</span> <span class="p">(</span><span class="n">pk</span> <span class="o">!=</span> <span class="s1">&#39;OG_OROLSM__SL&#39;</span> <span class="ow">and</span>
+                            <span class="nb">int</span><span class="p">(</span><span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;step&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">and</span>
+                            <span class="nb">int</span><span class="p">(</span><span class="n">timesave</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="mi">0</span><span class="p">):</span>
+
+                            <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">]</span> <span class="o">=</span> \
+                                <span class="n">datetime</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="n">elimit</span><span class="p">,</span> <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)</span>
+                            <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;time&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;00&#39;</span>
+                            <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;step&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;000&#39;</span>
+                            <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;target&#39;</span><span class="p">]</span> <span class="o">=</span> \
+                                <span class="bp">self</span><span class="o">.</span><span class="n">_mk_targetname</span><span class="p">(</span><span class="n">ftype</span><span class="p">,</span> <span class="n">pk</span><span class="p">,</span>
+                                                    <span class="n">retr_param_dict</span><span class="p">[</span><span class="s1">&#39;date&#39;</span><span class="p">])</span>
+
+                            <span class="c1"># ******* start retrievement</span>
+                            <span class="bp">self</span><span class="o">.</span><span class="n">_start_retrievement</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">retr_param_dict</span><span class="p">)</span>
+
+        <span class="k">if</span> <span class="n">request</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">or</span> <span class="n">request</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
+            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;MARS retrieve done ... &#39;</span><span class="p">)</span>
+        <span class="k">elif</span> <span class="n">request</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
+            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;MARS request printed ...&#39;</span><span class="p">)</span>
+
+        <span class="k">return</span></div>
+
+
+<div class="viewcode-block" id="EcFlexpart.write_namelist"><a class="viewcode-back" href="../api.html#EcFlexpart.EcFlexpart.write_namelist">[docs]</a>    <span class="k">def</span> <span class="nf">write_namelist</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39;Creates a namelist file in the temporary directory and writes</span>
+<span class="sd">        the following values to it: maxl, maxb, mlevel,</span>
+<span class="sd">        mlevelist, mnauf, metapar, rlo0, rlo1, rla0, rla1,</span>
+<span class="sd">        momega, momegadiff, mgauss, msmooth, meta, metadiff, mdpdeta</span>
+
+<span class="sd">        Parameters</span>
+<span class="sd">        ----------</span>
+<span class="sd">        c : :obj:`ControlFile`</span>
+<span class="sd">            Contains all the parameters of CONTROL file and</span>
+<span class="sd">            command line.</span>
+
+<span class="sd">        filename : :obj:`string`</span>
+<span class="sd">                Name of the namelist file.</span>
+
+<span class="sd">        Return</span>
+<span class="sd">        ------</span>
+
+<span class="sd">        &#39;&#39;&#39;</span>
+
+        <span class="kn">from</span> <span class="nn">genshi.template.text</span> <span class="k">import</span> <span class="n">NewTextTemplate</span>
+        <span class="kn">from</span> <span class="nn">genshi.template</span> <span class="k">import</span>  <span class="n">TemplateLoader</span>
+
+        <span class="n">loader</span> <span class="o">=</span> <span class="n">TemplateLoader</span><span class="p">(</span><span class="n">_config</span><span class="o">.</span><span class="n">PATH_TEMPLATES</span><span class="p">,</span> <span class="n">auto_reload</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
+        <span class="n">namelist_template</span> <span class="o">=</span> <span class="n">loader</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">_config</span><span class="o">.</span><span class="n">TEMPFILE_NAMELIST</span><span class="p">,</span>
+                                       <span class="bp">cls</span><span class="o">=</span><span class="n">NewTextTemplate</span><span class="p">)</span>
+
+        <span class="bp">self</span><span class="o">.</span><span class="n">inputdir</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">inputdir</span>
+        <span class="n">area</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">area</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">))</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">float</span><span class="p">)</span>
+        <span class="n">grid</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">asarray</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">grid</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">))</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">float</span><span class="p">)</span>
+
+        <span class="k">if</span> <span class="n">area</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">area</span><span class="p">[</span><span class="mi">3</span><span class="p">]:</span>
+            <span class="n">area</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">-=</span> <span class="mi">360</span>
+        <span class="n">maxl</span> <span class="o">=</span> <span class="nb">int</span><span class="p">((</span><span class="n">area</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">-</span> <span class="n">area</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">/</span> <span class="n">grid</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">+</span> <span class="mi">1</span>
+        <span class="n">maxb</span> <span class="o">=</span> <span class="nb">int</span><span class="p">((</span><span class="n">area</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">area</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span> <span class="o">/</span> <span class="n">grid</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> <span class="o">+</span> <span class="mi">1</span>
+
+        <span class="n">stream</span> <span class="o">=</span> <span class="n">namelist_template</span><span class="o">.</span><span class="n">generate</span><span class="p">(</span>
+            <span class="n">maxl</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">maxl</span><span class="p">),</span>
+            <span class="n">maxb</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">maxb</span><span class="p">),</span>
+            <span class="n">mlevel</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">level</span><span class="p">),</span>
+            <span class="n">mlevelist</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">levelist</span><span class="p">),</span>
+            <span class="n">mnauf</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">resol</span><span class="p">),</span>
+            <span class="n">metapar</span> <span class="o">=</span> <span class="s1">&#39;77&#39;</span><span class="p">,</span>
+            <span class="n">rlo0</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">area</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
+            <span class="n">rlo1</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">area</span><span class="p">[</span><span class="mi">3</span><span class="p">]),</span>
+            <span class="n">rla0</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">area</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
+            <span class="n">rla1</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">area</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span>
+            <span class="n">momega</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">omega</span><span class="p">),</span>
+            <span class="n">momegadiff</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">omegadiff</span><span class="p">),</span>
+            <span class="n">mgauss</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">gauss</span><span class="p">),</span>
+            <span class="n">msmooth</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">smooth</span><span class="p">),</span>
+            <span class="n">meta</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">eta</span><span class="p">),</span>
+            <span class="n">metadiff</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">etadiff</span><span class="p">),</span>
+            <span class="n">mdpdeta</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dpdeta</span><span class="p">)</span>
+        <span class="p">)</span>
+
+        <span class="n">namelistfile</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="n">_config</span><span class="o">.</span><span class="n">FILE_NAMELIST</span><span class="p">)</span>
+
+        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">namelistfile</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
+            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">stream</span><span class="o">.</span><span class="n">render</span><span class="p">(</span><span class="s1">&#39;text&#39;</span><span class="p">))</span>
+
+        <span class="k">return</span></div>
+
+
+<div class="viewcode-block" id="EcFlexpart.deacc_fluxes"><a class="viewcode-back" href="../api.html#EcFlexpart.EcFlexpart.deacc_fluxes">[docs]</a>    <span class="k">def</span> <span class="nf">deacc_fluxes</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">inputfiles</span><span class="p">,</span> <span class="n">c</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39;Goes through all flux fields in ordered time and de-accumulate</span>
+<span class="sd">        the fields. Afterwards the fields are disaggregated in time.</span>
+<span class="sd">        Different versions of disaggregation is provided for rainfall</span>
+<span class="sd">        data (darain, modified linear) and the surface fluxes and</span>
+<span class="sd">        stress data (dapoly, cubic polynomial).</span>
+
+<span class="sd">        Parameters</span>
+<span class="sd">        ----------</span>
+<span class="sd">        inputfiles : :obj:`UioFiles`</span>
+<span class="sd">            Contains a list of files.</span>
+
+<span class="sd">        c : :obj:`ControlFile`</span>
+<span class="sd">            Contains all the parameters of CONTROL file and</span>
+<span class="sd">            command line.</span>
+
+<span class="sd">        Return</span>
+<span class="sd">        ------</span>
+
+<span class="sd">        &#39;&#39;&#39;</span>
+
+        <span class="n">table128</span> <span class="o">=</span> <span class="n">init128</span><span class="p">(</span><span class="n">_config</span><span class="o">.</span><span class="n">PATH_GRIBTABLE</span><span class="p">)</span>
+        <span class="n">pars</span> <span class="o">=</span> <span class="n">to_param_id</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">params</span><span class="p">[</span><span class="s1">&#39;OG_acc_SL&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">table128</span><span class="p">)</span>
+
+        <span class="n">iid</span> <span class="o">=</span> <span class="kc">None</span>
+        <span class="n">index_vals</span> <span class="o">=</span> <span class="kc">None</span>
+
+        <span class="c1"># get the values of the keys which are used for distinct access</span>
+        <span class="c1"># of grib messages via product</span>
+        <span class="n">index_keys</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;date&quot;</span><span class="p">,</span> <span class="s2">&quot;time&quot;</span><span class="p">,</span> <span class="s2">&quot;step&quot;</span><span class="p">]</span>
+        <span class="n">iid</span><span class="p">,</span> <span class="n">index_vals</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_mk_index_values</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span>
+                                                <span class="n">inputfiles</span><span class="p">,</span>
+                                                <span class="n">index_keys</span><span class="p">)</span>
+        <span class="c1"># index_vals looks like e.g.:</span>
+        <span class="c1"># index_vals[0]: (&#39;20171106&#39;, &#39;20171107&#39;, &#39;20171108&#39;) ; date</span>
+        <span class="c1"># index_vals[1]: (&#39;0&#39;, &#39;1200&#39;, &#39;1800&#39;, &#39;600&#39;) ; time</span>
+        <span class="c1"># index_vals[2]: (&#39;0&#39;, &#39;12&#39;, &#39;3&#39;, &#39;6&#39;, &#39;9&#39;) ; stepRange</span>
+
+        <span class="n">valsdict</span> <span class="o">=</span> <span class="p">{}</span>
+        <span class="n">svalsdict</span> <span class="o">=</span> <span class="p">{}</span>
+<span class="c1">#        stepsdict = {}</span>
+        <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">pars</span><span class="p">:</span>
+            <span class="n">valsdict</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">p</span><span class="p">)]</span> <span class="o">=</span> <span class="p">[]</span>
+            <span class="n">svalsdict</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">p</span><span class="p">)]</span> <span class="o">=</span> <span class="p">[]</span>
+<span class="c1">#            stepsdict[str(p)] = []</span>
+
+        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;maxstep: &#39;</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">maxstep</span><span class="p">)</span>
+
+        <span class="c1"># &quot;product&quot; genereates each possible combination between the</span>
+        <span class="c1"># values of the index keys</span>
+        <span class="k">for</span> <span class="n">prod</span> <span class="ow">in</span> <span class="n">product</span><span class="p">(</span><span class="o">*</span><span class="n">index_vals</span><span class="p">):</span>
+            <span class="c1"># e.g. prod = (&#39;20170505&#39;, &#39;0&#39;, &#39;12&#39;)</span>
+            <span class="c1">#             (  date    ,time, step)</span>
+
+            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;current product: &#39;</span><span class="p">,</span> <span class="n">prod</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="nb">len</span><span class="p">(</span><span class="n">index_keys</span><span class="p">)):</span>
+                <span class="n">grib_index_select</span><span class="p">(</span><span class="n">iid</span><span class="p">,</span> <span class="n">index_keys</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">prod</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
+
+            <span class="c1"># get first id from current product</span>
+            <span class="n">gid</span> <span class="o">=</span> <span class="n">grib_new_from_index</span><span class="p">(</span><span class="n">iid</span><span class="p">)</span>
+
+            <span class="c1"># if there is no data for this specific time combination / product</span>
+            <span class="c1"># skip the rest of the for loop and start with next timestep/product</span>
+            <span class="k">if</span> <span class="ow">not</span> <span class="n">gid</span><span class="p">:</span>
+                <span class="k">continue</span>
+
+            <span class="c1"># create correct timestamp from the three time informations</span>
+            <span class="n">cdate</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">grib_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;date&#39;</span><span class="p">))</span>
+            <span class="n">ctime</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{:0&gt;2}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">grib_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;time&#39;</span><span class="p">)</span><span class="o">/</span><span class="mi">100</span><span class="p">)</span>
+            <span class="n">cstep</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{:0&gt;3}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">grib_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;step&#39;</span><span class="p">))</span>
+            <span class="n">t_date</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">cdate</span> <span class="o">+</span> <span class="n">ctime</span><span class="p">,</span> <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">)</span>
+            <span class="n">t_dt</span> <span class="o">=</span> <span class="n">t_date</span> <span class="o">+</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">hours</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">cstep</span><span class="p">))</span>
+            <span class="n">t_m1dt</span> <span class="o">=</span> <span class="n">t_date</span> <span class="o">+</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">hours</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">cstep</span><span class="p">)</span><span class="o">-</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">))</span>
+            <span class="n">t_m2dt</span> <span class="o">=</span> <span class="n">t_date</span> <span class="o">+</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">hours</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">cstep</span><span class="p">)</span><span class="o">-</span><span class="mi">2</span><span class="o">*</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">))</span>
+            <span class="n">t_enddate</span> <span class="o">=</span> <span class="kc">None</span>
+
+            <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">maxstep</span> <span class="o">&gt;</span> <span class="mi">12</span><span class="p">:</span>
+                <span class="n">fnout</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="s1">&#39;flux&#39;</span> <span class="o">+</span>
+                                     <span class="n">t_date</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">.%H&#39;</span><span class="p">)</span> <span class="o">+</span>
+                                     <span class="s1">&#39;.</span><span class="si">{:0&gt;3}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">step</span><span class="o">-</span><span class="mi">2</span><span class="o">*</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">)))</span>
+                <span class="n">gnout</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="s1">&#39;flux&#39;</span> <span class="o">+</span>
+                                     <span class="n">t_date</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">.%H&#39;</span><span class="p">)</span> <span class="o">+</span>
+                                     <span class="s1">&#39;.</span><span class="si">{:0&gt;3}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">step</span><span class="o">-</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">)))</span>
+                <span class="n">hnout</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="s1">&#39;flux&#39;</span> <span class="o">+</span>
+                                     <span class="n">t_date</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">.%H&#39;</span><span class="p">)</span> <span class="o">+</span>
+                                     <span class="s1">&#39;.</span><span class="si">{:0&gt;3}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">step</span><span class="p">))</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="n">fnout</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="s1">&#39;flux&#39;</span> <span class="o">+</span>
+                                     <span class="n">t_m2dt</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">))</span>
+                <span class="n">gnout</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="s1">&#39;flux&#39;</span> <span class="o">+</span>
+                                     <span class="n">t_m1dt</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">))</span>
+                <span class="n">hnout</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="s1">&#39;flux&#39;</span> <span class="o">+</span>
+                                     <span class="n">t_dt</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">))</span>
+
+            <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;outputfile = &quot;</span> <span class="o">+</span> <span class="n">fnout</span><span class="p">)</span>
+
+            <span class="c1"># read message for message and store relevant data fields</span>
+            <span class="c1"># data keywords are stored in pars</span>
+            <span class="k">while</span> <span class="mi">1</span><span class="p">:</span>
+                <span class="k">if</span> <span class="ow">not</span> <span class="n">gid</span><span class="p">:</span>
+                    <span class="k">break</span>
+                <span class="n">cparamId</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">grib_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;paramId&#39;</span><span class="p">))</span>
+                <span class="n">step</span> <span class="o">=</span> <span class="n">grib_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;step&#39;</span><span class="p">)</span>
+                <span class="n">time</span> <span class="o">=</span> <span class="n">grib_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;time&#39;</span><span class="p">)</span>
+                <span class="n">ni</span> <span class="o">=</span> <span class="n">grib_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;Ni&#39;</span><span class="p">)</span>
+                <span class="n">nj</span> <span class="o">=</span> <span class="n">grib_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;Nj&#39;</span><span class="p">)</span>
+                <span class="k">if</span> <span class="n">cparamId</span> <span class="ow">in</span> <span class="n">valsdict</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
+                    <span class="n">values</span> <span class="o">=</span> <span class="n">grib_get_values</span><span class="p">(</span><span class="n">gid</span><span class="p">)</span>
+                    <span class="n">vdp</span> <span class="o">=</span> <span class="n">valsdict</span><span class="p">[</span><span class="n">cparamId</span><span class="p">]</span>
+                    <span class="n">svdp</span> <span class="o">=</span> <span class="n">svalsdict</span><span class="p">[</span><span class="n">cparamId</span><span class="p">]</span>
+ <span class="c1">#                   sd = stepsdict[cparamId]</span>
+
+                    <span class="k">if</span> <span class="n">cparamId</span> <span class="o">==</span> <span class="s1">&#39;142&#39;</span> <span class="ow">or</span> <span class="n">cparamId</span> <span class="o">==</span> <span class="s1">&#39;143&#39;</span><span class="p">:</span>
+                        <span class="n">fak</span> <span class="o">=</span> <span class="mf">1.</span> <span class="o">/</span> <span class="mf">1000.</span>
+                    <span class="k">else</span><span class="p">:</span>
+                        <span class="n">fak</span> <span class="o">=</span> <span class="mf">3600.</span>
+
+                    <span class="n">values</span> <span class="o">=</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">values</span><span class="p">,</span> <span class="p">(</span><span class="n">nj</span><span class="p">,</span> <span class="n">ni</span><span class="p">)))</span><span class="o">.</span><span class="n">flatten</span><span class="p">()</span> <span class="o">/</span> <span class="n">fak</span>
+                    <span class="n">vdp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">values</span><span class="p">[:])</span>  <span class="c1"># save the accumulated values</span>
+                    <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">marsclass</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;EA&#39;</span> <span class="ow">or</span> \
+                       <span class="n">step</span> <span class="o">&lt;=</span> <span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">):</span>
+                        <span class="n">svdp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">values</span><span class="p">[:]</span> <span class="o">/</span> <span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">))</span>
+                    <span class="k">else</span><span class="p">:</span>  <span class="c1"># deaccumulate values</span>
+                        <span class="n">svdp</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">vdp</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">vdp</span><span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">])</span> <span class="o">/</span> <span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">))</span>
+
+                    <span class="nb">print</span><span class="p">(</span><span class="n">cparamId</span><span class="p">,</span> <span class="n">time</span><span class="p">,</span> <span class="n">step</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">values</span><span class="p">),</span>
+                          <span class="n">values</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">np</span><span class="o">.</span><span class="n">std</span><span class="p">(</span><span class="n">values</span><span class="p">))</span>
+
+                    <span class="c1"># len(svdp) correspond to the time</span>
+                    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">svdp</span><span class="p">)</span> <span class="o">&gt;=</span> <span class="mi">3</span><span class="p">:</span>
+                        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">svdp</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">3</span><span class="p">:</span>
+                            <span class="k">if</span> <span class="n">cparamId</span> <span class="o">==</span> <span class="s1">&#39;142&#39;</span> <span class="ow">or</span> <span class="n">cparamId</span> <span class="o">==</span> <span class="s1">&#39;143&#39;</span><span class="p">:</span>
+                                <span class="n">values</span> <span class="o">=</span> <span class="n">disaggregation</span><span class="o">.</span><span class="n">darain</span><span class="p">(</span><span class="n">svdp</span><span class="p">)</span>
+                            <span class="k">else</span><span class="p">:</span>
+                                <span class="n">values</span> <span class="o">=</span> <span class="n">disaggregation</span><span class="o">.</span><span class="n">dapoly</span><span class="p">(</span><span class="n">svdp</span><span class="p">)</span>
+
+                            <span class="k">if</span> <span class="ow">not</span> <span class="p">(</span><span class="n">step</span> <span class="o">==</span> <span class="n">c</span><span class="o">.</span><span class="n">maxstep</span> <span class="ow">and</span> <span class="n">c</span><span class="o">.</span><span class="n">maxstep</span> <span class="o">&gt;</span> <span class="mi">12</span> \
+                                    <span class="ow">or</span> <span class="n">t_dt</span> <span class="o">==</span> <span class="n">t_enddate</span><span class="p">):</span>
+                                <span class="n">vdp</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
+                                <span class="n">svdp</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
+                        <span class="k">else</span><span class="p">:</span>
+                            <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">maxstep</span> <span class="o">&gt;</span> <span class="mi">12</span><span class="p">:</span>
+                                <span class="n">values</span> <span class="o">=</span> <span class="n">svdp</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
+                            <span class="k">else</span><span class="p">:</span>
+                                <span class="n">values</span> <span class="o">=</span> <span class="n">svdp</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
+
+                        <span class="n">grib_set_values</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span>
+
+                        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">maxstep</span> <span class="o">&gt;</span> <span class="mi">12</span><span class="p">:</span>
+                            <span class="n">grib_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;step&#39;</span><span class="p">,</span> <span class="nb">max</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">step</span><span class="o">-</span><span class="mi">2</span><span class="o">*</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">)))</span>
+                        <span class="k">else</span><span class="p">:</span>
+                            <span class="n">grib_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;step&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
+                            <span class="n">grib_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;time&#39;</span><span class="p">,</span> <span class="n">t_m2dt</span><span class="o">.</span><span class="n">hour</span><span class="o">*</span><span class="mi">100</span><span class="p">)</span>
+                            <span class="n">grib_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;date&#39;</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">t_m2dt</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)))</span>
+
+                        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">fnout</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f_handle</span><span class="p">:</span>
+                            <span class="n">grib_write</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">f_handle</span><span class="p">)</span>
+
+                        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">basetime</span><span class="p">:</span>
+                            <span class="n">t_enddate</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">end_date</span> <span class="o">+</span>
+                                                          <span class="n">c</span><span class="o">.</span><span class="n">basetime</span><span class="p">,</span>
+                                                          <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">)</span>
+                        <span class="k">else</span><span class="p">:</span>
+                            <span class="n">t_enddate</span> <span class="o">=</span> <span class="n">t_date</span> <span class="o">+</span> <span class="n">timedelta</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">))</span>
+
+                        <span class="c1"># squeeze out information of last two steps contained</span>
+                        <span class="c1"># in svdp</span>
+                        <span class="c1"># if step+int(c.dtime) == c.maxstep and c.maxstep&gt;12</span>
+                        <span class="c1"># or t_dt+timedelta(hours = int(c.dtime))</span>
+                        <span class="c1"># &gt;= t_enddate:</span>
+                        <span class="c1"># Note that svdp[0] has not been popped in this case</span>
+
+                        <span class="k">if</span> <span class="n">step</span> <span class="o">==</span> <span class="n">c</span><span class="o">.</span><span class="n">maxstep</span> <span class="ow">and</span> <span class="n">c</span><span class="o">.</span><span class="n">maxstep</span> <span class="o">&gt;</span> <span class="mi">12</span> <span class="ow">or</span> \
+                           <span class="n">t_dt</span> <span class="o">==</span> <span class="n">t_enddate</span><span class="p">:</span>
+
+                            <span class="n">values</span> <span class="o">=</span> <span class="n">svdp</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span>
+                            <span class="n">grib_set_values</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span>
+                            <span class="n">grib_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;step&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
+                            <span class="n">truedatetime</span> <span class="o">=</span> <span class="n">t_m2dt</span> <span class="o">+</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">hours</span><span class="o">=</span>
+                                                              <span class="mi">2</span><span class="o">*</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">))</span>
+                            <span class="n">grib_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;time&#39;</span><span class="p">,</span> <span class="n">truedatetime</span><span class="o">.</span><span class="n">hour</span> <span class="o">*</span> <span class="mi">100</span><span class="p">)</span>
+                            <span class="n">grib_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;date&#39;</span><span class="p">,</span> <span class="n">truedatetime</span><span class="o">.</span><span class="n">year</span> <span class="o">*</span> <span class="mi">10000</span> <span class="o">+</span>
+                                      <span class="n">truedatetime</span><span class="o">.</span><span class="n">month</span> <span class="o">*</span> <span class="mi">100</span> <span class="o">+</span>
+                                      <span class="n">truedatetime</span><span class="o">.</span><span class="n">day</span><span class="p">)</span>
+                            <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">hnout</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">h_handle</span><span class="p">:</span>
+                                <span class="n">grib_write</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">h_handle</span><span class="p">)</span>
+
+                            <span class="c1">#values = (svdp[1]+svdp[2])/2.</span>
+                            <span class="k">if</span> <span class="n">cparamId</span> <span class="o">==</span> <span class="s1">&#39;142&#39;</span> <span class="ow">or</span> <span class="n">cparamId</span> <span class="o">==</span> <span class="s1">&#39;143&#39;</span><span class="p">:</span>
+                                <span class="n">values</span> <span class="o">=</span> <span class="n">disaggregation</span><span class="o">.</span><span class="n">darain</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span><span class="n">svdp</span><span class="p">)))</span>
+                            <span class="k">else</span><span class="p">:</span>
+                                <span class="n">values</span> <span class="o">=</span> <span class="n">disaggregation</span><span class="o">.</span><span class="n">dapoly</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">reversed</span><span class="p">(</span><span class="n">svdp</span><span class="p">)))</span>
+
+                            <span class="n">grib_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;step&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
+                            <span class="n">truedatetime</span> <span class="o">=</span> <span class="n">t_m2dt</span> <span class="o">+</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">hours</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">dtime</span><span class="p">))</span>
+                            <span class="n">grib_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;time&#39;</span><span class="p">,</span> <span class="n">truedatetime</span><span class="o">.</span><span class="n">hour</span> <span class="o">*</span> <span class="mi">100</span><span class="p">)</span>
+                            <span class="n">grib_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;date&#39;</span><span class="p">,</span> <span class="n">truedatetime</span><span class="o">.</span><span class="n">year</span> <span class="o">*</span> <span class="mi">10000</span> <span class="o">+</span>
+                                     <span class="n">truedatetime</span><span class="o">.</span><span class="n">month</span> <span class="o">*</span> <span class="mi">100</span> <span class="o">+</span>
+                                     <span class="n">truedatetime</span><span class="o">.</span><span class="n">day</span><span class="p">)</span>
+                            <span class="n">grib_set_values</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">values</span><span class="p">)</span>
+                            <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">gnout</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">g_handle</span><span class="p">:</span>
+                                <span class="n">grib_write</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">g_handle</span><span class="p">)</span>
+
+                <span class="n">grib_release</span><span class="p">(</span><span class="n">gid</span><span class="p">)</span>
+
+                <span class="n">gid</span> <span class="o">=</span> <span class="n">grib_new_from_index</span><span class="p">(</span><span class="n">iid</span><span class="p">)</span>
+
+        <span class="n">grib_index_release</span><span class="p">(</span><span class="n">iid</span><span class="p">)</span>
+
+        <span class="k">return</span></div>
+
+
+<div class="viewcode-block" id="EcFlexpart.create"><a class="viewcode-back" href="../api.html#EcFlexpart.EcFlexpart.create">[docs]</a>    <span class="k">def</span> <span class="nf">create</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">inputfiles</span><span class="p">,</span> <span class="n">c</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39;An index file will be created which depends on the combination</span>
+<span class="sd">        of &quot;date&quot;, &quot;time&quot; and &quot;stepRange&quot; values. This is used to iterate</span>
+<span class="sd">        over all messages in each grib file which were passed through the</span>
+<span class="sd">        parameter &quot;inputfiles&quot; to seperate specific parameters into fort.*</span>
+<span class="sd">        files. Afterwards the FORTRAN program is called to convert</span>
+<span class="sd">        the data fields all to the same grid and put them in one file</span>
+<span class="sd">        per unique time step (combination of &quot;date&quot;, &quot;time&quot; and</span>
+<span class="sd">        &quot;stepRange&quot;).</span>
+
+<span class="sd">        Note</span>
+<span class="sd">        ----</span>
+<span class="sd">        This method is based on the ECMWF example index.py</span>
+<span class="sd">        https://software.ecmwf.int/wiki/display/GRIB/index.py</span>
+
+<span class="sd">        Parameters</span>
+<span class="sd">        ----------</span>
+<span class="sd">        inputfiles : :obj:`UioFiles`</span>
+<span class="sd">            Contains a list of files.</span>
+
+<span class="sd">        c : :obj:`ControlFile`</span>
+<span class="sd">            Contains all the parameters of CONTROL file and</span>
+<span class="sd">            command line.</span>
+
+<span class="sd">        Return</span>
+<span class="sd">        ------</span>
+
+<span class="sd">        &#39;&#39;&#39;</span>
+
+        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">wrf</span><span class="p">:</span>
+            <span class="n">table128</span> <span class="o">=</span> <span class="n">init128</span><span class="p">(</span><span class="n">_config</span><span class="o">.</span><span class="n">PATH_GRIBTABLE</span><span class="p">)</span>
+            <span class="n">wrfpars</span> <span class="o">=</span> <span class="n">to_param_id</span><span class="p">(</span><span class="s1">&#39;sp/mslp/skt/2t/10u/10v/2d/z/lsm/sst/ci/sd/</span><span class="se">\</span>
+<span class="s1">                                   stl1/stl2/stl3/stl4/swvl1/swvl2/swvl3/swvl4&#39;</span><span class="p">,</span>
+                                  <span class="n">table128</span><span class="p">)</span>
+
+        <span class="c1"># these numbers are indices for the temporary files &quot;fort.xx&quot;</span>
+        <span class="c1"># which are used to seperate the grib fields to,</span>
+        <span class="c1"># for the Fortran program input</span>
+        <span class="c1"># 10: U,V | 11: T | 12: lnsp | 13: D | 16: sfc fields</span>
+        <span class="c1"># 17: Q | 18: Q , gaussian| 19: w | 21: etadot | 22: clwc+ciwc</span>
+        <span class="n">fdict</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;10&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;11&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;12&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;13&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;16&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span>
+                 <span class="s1">&#39;17&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;18&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;19&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;21&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;22&#39;</span><span class="p">:</span><span class="kc">None</span><span class="p">}</span>
+
+        <span class="n">iid</span> <span class="o">=</span> <span class="kc">None</span>
+        <span class="n">index_vals</span> <span class="o">=</span> <span class="kc">None</span>
+
+        <span class="c1"># get the values of the keys which are used for distinct access</span>
+        <span class="c1"># of grib messages via product</span>
+        <span class="n">index_keys</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;date&quot;</span><span class="p">,</span> <span class="s2">&quot;time&quot;</span><span class="p">,</span> <span class="s2">&quot;step&quot;</span><span class="p">]</span>
+        <span class="n">iid</span><span class="p">,</span> <span class="n">index_vals</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_mk_index_values</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span>
+                                                <span class="n">inputfiles</span><span class="p">,</span>
+                                                <span class="n">index_keys</span><span class="p">)</span>
+        <span class="c1"># index_vals looks like e.g.:</span>
+        <span class="c1"># index_vals[0]: (&#39;20171106&#39;, &#39;20171107&#39;, &#39;20171108&#39;) ; date</span>
+        <span class="c1"># index_vals[1]: (&#39;0&#39;, &#39;1200&#39;, &#39;1800&#39;, &#39;600&#39;) ; time</span>
+        <span class="c1"># index_vals[2]: (&#39;0&#39;, &#39;12&#39;, &#39;3&#39;, &#39;6&#39;, &#39;9&#39;) ; stepRange</span>
+
+        <span class="c1"># &quot;product&quot; genereates each possible combination between the</span>
+        <span class="c1"># values of the index keys</span>
+        <span class="k">for</span> <span class="n">prod</span> <span class="ow">in</span> <span class="n">product</span><span class="p">(</span><span class="o">*</span><span class="n">index_vals</span><span class="p">):</span>
+            <span class="c1"># e.g. prod = (&#39;20170505&#39;, &#39;0&#39;, &#39;12&#39;)</span>
+            <span class="c1">#             (  date    ,time, step)</span>
+
+            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;current product: &#39;</span><span class="p">,</span> <span class="n">prod</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="nb">len</span><span class="p">(</span><span class="n">index_keys</span><span class="p">)):</span>
+                <span class="n">grib_index_select</span><span class="p">(</span><span class="n">iid</span><span class="p">,</span> <span class="n">index_keys</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">prod</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
+
+            <span class="c1"># get first id from current product</span>
+            <span class="n">gid</span> <span class="o">=</span> <span class="n">grib_new_from_index</span><span class="p">(</span><span class="n">iid</span><span class="p">)</span>
+
+            <span class="c1"># if there is no data for this specific time combination / product</span>
+            <span class="c1"># skip the rest of the for loop and start with next timestep/product</span>
+            <span class="k">if</span> <span class="ow">not</span> <span class="n">gid</span><span class="p">:</span>
+                <span class="k">continue</span>
+
+            <span class="c1"># remove old fort.* files and open new ones</span>
+            <span class="c1"># they are just valid for a single product</span>
+            <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">fdict</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
+                <span class="n">fortfile</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="s1">&#39;fort.&#39;</span> <span class="o">+</span> <span class="n">k</span><span class="p">)</span>
+                <span class="n">silent_remove</span><span class="p">(</span><span class="n">fortfile</span><span class="p">)</span>
+                <span class="n">fdict</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">fortfile</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span>
+
+            <span class="c1"># create correct timestamp from the three time informations</span>
+            <span class="n">cdate</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">grib_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;date&#39;</span><span class="p">))</span>
+            <span class="n">ctime</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{:0&gt;2}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">grib_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;time&#39;</span><span class="p">)</span><span class="o">/</span><span class="mi">100</span><span class="p">)</span>
+            <span class="n">cstep</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{:0&gt;3}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">grib_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;step&#39;</span><span class="p">))</span>
+            <span class="n">timestamp</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">cdate</span> <span class="o">+</span> <span class="n">ctime</span><span class="p">,</span> <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">)</span>
+            <span class="n">timestamp</span> <span class="o">+=</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">hours</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">cstep</span><span class="p">))</span>
+            <span class="n">cdate_hour</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="n">timestamp</span><span class="p">,</span> <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">)</span>
+
+            <span class="c1"># if the timestamp is out of basetime start/end date period,</span>
+            <span class="c1"># skip this specific product</span>
+            <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">basetime</span><span class="p">:</span>
+                <span class="n">start_time</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">end_date</span> <span class="o">+</span> <span class="n">c</span><span class="o">.</span><span class="n">basetime</span><span class="p">,</span>
+                                                <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">)</span> <span class="o">-</span> <span class="n">time_delta</span>
+                <span class="n">end_time</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">end_date</span> <span class="o">+</span> <span class="n">c</span><span class="o">.</span><span class="n">basetime</span><span class="p">,</span>
+                                             <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">)</span>
+                <span class="k">if</span> <span class="n">timestamp</span> <span class="o">&lt;</span> <span class="n">start_time</span> <span class="ow">or</span> <span class="n">timestamp</span> <span class="o">&gt;</span> <span class="n">end_time</span><span class="p">:</span>
+                    <span class="k">continue</span>
+
+            <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">wrf</span><span class="p">:</span>
+                <span class="k">if</span> <span class="s1">&#39;olddate&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="nb">locals</span><span class="p">()</span> <span class="ow">or</span> <span class="n">cdate</span> <span class="o">!=</span> <span class="n">olddate</span><span class="p">:</span>
+                    <span class="n">fwrf</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">outputdir</span><span class="p">,</span>
+                                <span class="s1">&#39;WRF&#39;</span> <span class="o">+</span> <span class="n">cdate</span> <span class="o">+</span> <span class="s1">&#39;.&#39;</span> <span class="o">+</span> <span class="n">ctime</span> <span class="o">+</span> <span class="s1">&#39;.000.grb2&#39;</span><span class="p">),</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span>
+                    <span class="n">olddate</span> <span class="o">=</span> <span class="n">cdate</span><span class="p">[:]</span>
+
+            <span class="c1"># savedfields remembers which fields were already used.</span>
+            <span class="n">savedfields</span> <span class="o">=</span> <span class="p">[]</span>
+            <span class="c1"># sum of cloud liquid and ice water content</span>
+            <span class="n">scwc</span> <span class="o">=</span> <span class="kc">None</span>
+            <span class="k">while</span> <span class="mi">1</span><span class="p">:</span>
+                <span class="k">if</span> <span class="ow">not</span> <span class="n">gid</span><span class="p">:</span>
+                    <span class="k">break</span>
+                <span class="n">paramId</span> <span class="o">=</span> <span class="n">grib_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;paramId&#39;</span><span class="p">)</span>
+                <span class="n">gridtype</span> <span class="o">=</span> <span class="n">grib_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;gridType&#39;</span><span class="p">)</span>
+                <span class="n">levtype</span> <span class="o">=</span> <span class="n">grib_get</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;typeOfLevel&#39;</span><span class="p">)</span>
+                <span class="k">if</span> <span class="n">paramId</span> <span class="o">==</span> <span class="mi">77</span><span class="p">:</span> <span class="c1"># ETADOT</span>
+                    <span class="n">grib_write</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">fdict</span><span class="p">[</span><span class="s1">&#39;21&#39;</span><span class="p">])</span>
+                <span class="k">elif</span> <span class="n">paramId</span> <span class="o">==</span> <span class="mi">130</span><span class="p">:</span> <span class="c1"># T</span>
+                    <span class="n">grib_write</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">fdict</span><span class="p">[</span><span class="s1">&#39;11&#39;</span><span class="p">])</span>
+                <span class="k">elif</span> <span class="n">paramId</span> <span class="o">==</span> <span class="mi">131</span> <span class="ow">or</span> <span class="n">paramId</span> <span class="o">==</span> <span class="mi">132</span><span class="p">:</span> <span class="c1"># U, V wind component</span>
+                    <span class="n">grib_write</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">fdict</span><span class="p">[</span><span class="s1">&#39;10&#39;</span><span class="p">])</span>
+                <span class="k">elif</span> <span class="n">paramId</span> <span class="o">==</span> <span class="mi">133</span> <span class="ow">and</span> <span class="n">gridtype</span> <span class="o">!=</span> <span class="s1">&#39;reduced_gg&#39;</span><span class="p">:</span> <span class="c1"># Q</span>
+                    <span class="n">grib_write</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">fdict</span><span class="p">[</span><span class="s1">&#39;17&#39;</span><span class="p">])</span>
+                <span class="k">elif</span> <span class="n">paramId</span> <span class="o">==</span> <span class="mi">133</span> <span class="ow">and</span> <span class="n">gridtype</span> <span class="o">==</span> <span class="s1">&#39;reduced_gg&#39;</span><span class="p">:</span> <span class="c1"># Q, gaussian</span>
+                    <span class="n">grib_write</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">fdict</span><span class="p">[</span><span class="s1">&#39;18&#39;</span><span class="p">])</span>
+                <span class="k">elif</span> <span class="n">paramId</span> <span class="o">==</span> <span class="mi">135</span><span class="p">:</span> <span class="c1"># W</span>
+                    <span class="n">grib_write</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">fdict</span><span class="p">[</span><span class="s1">&#39;19&#39;</span><span class="p">])</span>
+                <span class="k">elif</span> <span class="n">paramId</span> <span class="o">==</span> <span class="mi">152</span><span class="p">:</span> <span class="c1"># LNSP</span>
+                    <span class="n">grib_write</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">fdict</span><span class="p">[</span><span class="s1">&#39;12&#39;</span><span class="p">])</span>
+                <span class="k">elif</span> <span class="n">paramId</span> <span class="o">==</span> <span class="mi">155</span> <span class="ow">and</span> <span class="n">gridtype</span> <span class="o">==</span> <span class="s1">&#39;sh&#39;</span><span class="p">:</span> <span class="c1"># D</span>
+                    <span class="n">grib_write</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">fdict</span><span class="p">[</span><span class="s1">&#39;13&#39;</span><span class="p">])</span>
+                <span class="k">elif</span> <span class="n">paramId</span> <span class="o">==</span> <span class="mi">246</span> <span class="ow">or</span> <span class="n">paramId</span> <span class="o">==</span> <span class="mi">247</span><span class="p">:</span> <span class="c1"># CLWC, CIWC</span>
+                    <span class="c1"># sum cloud liquid water and ice</span>
+                    <span class="k">if</span> <span class="n">scwc</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
+                        <span class="n">scwc</span> <span class="o">=</span> <span class="n">grib_get_values</span><span class="p">(</span><span class="n">gid</span><span class="p">)</span>
+                    <span class="k">else</span><span class="p">:</span>
+                        <span class="n">scwc</span> <span class="o">+=</span> <span class="n">grib_get_values</span><span class="p">(</span><span class="n">gid</span><span class="p">)</span>
+                        <span class="n">grib_set_values</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">scwc</span><span class="p">)</span>
+                        <span class="n">grib_set</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="s1">&#39;paramId&#39;</span><span class="p">,</span> <span class="mi">201031</span><span class="p">)</span>
+                        <span class="n">grib_write</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">fdict</span><span class="p">[</span><span class="s1">&#39;22&#39;</span><span class="p">])</span>
+                <span class="k">elif</span> <span class="n">c</span><span class="o">.</span><span class="n">wrf</span> <span class="ow">and</span> <span class="n">paramId</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">129</span><span class="p">,</span> <span class="mi">138</span><span class="p">,</span> <span class="mi">155</span><span class="p">]</span> <span class="ow">and</span> \
+                      <span class="n">levtype</span> <span class="o">==</span> <span class="s1">&#39;hybrid&#39;</span><span class="p">:</span> <span class="c1"># Z, VO, D</span>
+                    <span class="c1"># do not do anything right now</span>
+                    <span class="c1"># these are specific parameter for WRF</span>
+                    <span class="k">pass</span>
+                <span class="k">else</span><span class="p">:</span>
+                    <span class="k">if</span> <span class="n">paramId</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">savedfields</span><span class="p">:</span>
+                        <span class="c1"># SD/MSL/TCC/10U/10V/2T/2D/Z/LSM/SDOR/CVL/CVH/SR</span>
+                        <span class="c1"># and all ADDPAR parameter</span>
+                        <span class="n">grib_write</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">fdict</span><span class="p">[</span><span class="s1">&#39;16&#39;</span><span class="p">])</span>
+                        <span class="n">savedfields</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">paramId</span><span class="p">)</span>
+                    <span class="k">else</span><span class="p">:</span>
+                        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;duplicate &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">paramId</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39; not written&#39;</span><span class="p">)</span>
+
+                <span class="k">try</span><span class="p">:</span>
+                    <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">wrf</span><span class="p">:</span>
+                        <span class="c1"># model layer</span>
+                        <span class="k">if</span> <span class="n">levtype</span> <span class="o">==</span> <span class="s1">&#39;hybrid&#39;</span> <span class="ow">and</span> \
+                           <span class="n">paramId</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">129</span><span class="p">,</span> <span class="mi">130</span><span class="p">,</span> <span class="mi">131</span><span class="p">,</span> <span class="mi">132</span><span class="p">,</span> <span class="mi">133</span><span class="p">,</span> <span class="mi">138</span><span class="p">,</span> <span class="mi">155</span><span class="p">]:</span>
+                            <span class="n">grib_write</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">fwrf</span><span class="p">)</span>
+                        <span class="c1"># sfc layer</span>
+                        <span class="k">elif</span> <span class="n">paramId</span> <span class="ow">in</span> <span class="n">wrfpars</span><span class="p">:</span>
+                            <span class="n">grib_write</span><span class="p">(</span><span class="n">gid</span><span class="p">,</span> <span class="n">fwrf</span><span class="p">)</span>
+                <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
+                    <span class="k">pass</span>
+
+                <span class="n">grib_release</span><span class="p">(</span><span class="n">gid</span><span class="p">)</span>
+                <span class="n">gid</span> <span class="o">=</span> <span class="n">grib_new_from_index</span><span class="p">(</span><span class="n">iid</span><span class="p">)</span>
+
+            <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">fdict</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
+                <span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
+
+            <span class="c1"># call for Fortran program to convert e.g. reduced_gg grids to</span>
+            <span class="c1"># regular_ll and calculate detadot/dp</span>
+            <span class="n">pwd</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">getcwd</span><span class="p">()</span>
+            <span class="n">os</span><span class="o">.</span><span class="n">chdir</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">)</span>
+            <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">stat</span><span class="p">(</span><span class="s1">&#39;fort.21&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">st_size</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">c</span><span class="o">.</span><span class="n">eta</span><span class="p">:</span>
+                <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Parameter 77 (etadot) is missing, most likely it is </span><span class="se">\</span>
+<span class="s1">                       not available for this type or date/time</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
+                <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Check parameters CLASS, TYPE, STREAM, START_DATE</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
+                <span class="n">my_error</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">mailfail</span><span class="p">,</span> <span class="s1">&#39;fort.21 is empty while parameter eta </span><span class="se">\</span>
+<span class="s1">                         is set to 1 in CONTROL file&#39;</span><span class="p">)</span>
+
+            <span class="c1"># Fortran program creates file fort.15 (with u,v,etadot,t,sp,q)</span>
+            <span class="n">p</span> <span class="o">=</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">check_call</span><span class="p">([</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span>
+                <span class="n">c</span><span class="o">.</span><span class="n">exedir</span><span class="p">,</span> <span class="n">_config</span><span class="o">.</span><span class="n">FORTRAN_EXECUTABLE</span><span class="p">)],</span> <span class="n">shell</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
+            <span class="n">os</span><span class="o">.</span><span class="n">chdir</span><span class="p">(</span><span class="n">pwd</span><span class="p">)</span>
+
+            <span class="c1"># create name of final output file, e.g. EN13040500 (ENYYMMDDHH)</span>
+            <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">maxstep</span> <span class="o">&gt;</span> <span class="mi">12</span><span class="p">:</span>
+                <span class="n">suffix</span> <span class="o">=</span> <span class="n">cdate</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">8</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;.&#39;</span> <span class="o">+</span> <span class="n">ctime</span> <span class="o">+</span> <span class="s1">&#39;.&#39;</span> <span class="o">+</span> <span class="n">cstep</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="n">suffix</span> <span class="o">=</span> <span class="n">cdate_hour</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">10</span><span class="p">]</span>
+            <span class="n">fnout</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">prefix</span> <span class="o">+</span> <span class="n">suffix</span><span class="p">)</span>
+            <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;outputfile = &quot;</span> <span class="o">+</span> <span class="n">fnout</span><span class="p">)</span>
+            <span class="c1"># collect for final processing</span>
+            <span class="bp">self</span><span class="o">.</span><span class="n">outputfilelist</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">basename</span><span class="p">(</span><span class="n">fnout</span><span class="p">))</span>
+
+            <span class="c1"># create outputfile and copy all data from intermediate files</span>
+            <span class="c1"># to the outputfile (final GRIB input files for FLEXPART)</span>
+            <span class="n">orolsm</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">basename</span><span class="p">(</span><span class="n">glob</span><span class="o">.</span><span class="n">glob</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span> <span class="o">+</span>
+                                        <span class="s1">&#39;/OG_OROLSM__SL.*.&#39;</span> <span class="o">+</span> <span class="n">c</span><span class="o">.</span><span class="n">ppid</span> <span class="o">+</span> <span class="s1">&#39;*&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>
+            <span class="n">fluxfile</span> <span class="o">=</span> <span class="s1">&#39;flux&#39;</span> <span class="o">+</span> <span class="n">cdate</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">2</span><span class="p">]</span> <span class="o">+</span> <span class="n">suffix</span>
+            <span class="k">if</span> <span class="ow">not</span> <span class="n">c</span><span class="o">.</span><span class="n">cwc</span><span class="p">:</span>
+                <span class="n">flist</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;fort.15&#39;</span><span class="p">,</span> <span class="n">fluxfile</span><span class="p">,</span> <span class="s1">&#39;fort.16&#39;</span><span class="p">,</span> <span class="n">orolsm</span><span class="p">]</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="n">flist</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;fort.15&#39;</span><span class="p">,</span> <span class="s1">&#39;fort.22&#39;</span><span class="p">,</span> <span class="n">fluxfile</span><span class="p">,</span> <span class="s1">&#39;fort.16&#39;</span><span class="p">,</span> <span class="n">orolsm</span><span class="p">]</span>
+
+            <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">fnout</span><span class="p">,</span> <span class="s1">&#39;wb&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fout</span><span class="p">:</span>
+                <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">flist</span><span class="p">:</span>
+                    <span class="n">shutil</span><span class="o">.</span><span class="n">copyfileobj</span><span class="p">(</span><span class="nb">open</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="n">f</span><span class="p">),</span> <span class="s1">&#39;rb&#39;</span><span class="p">),</span>
+                                       <span class="n">fout</span><span class="p">)</span>
+
+            <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">omega</span><span class="p">:</span>
+                <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">outputdir</span><span class="p">,</span> <span class="s1">&#39;OMEGA&#39;</span><span class="p">),</span> <span class="s1">&#39;wb&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fout</span><span class="p">:</span>
+                    <span class="n">shutil</span><span class="o">.</span><span class="n">copyfileobj</span><span class="p">(</span><span class="nb">open</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="s1">&#39;fort.25&#39;</span><span class="p">),</span>
+                                            <span class="s1">&#39;rb&#39;</span><span class="p">),</span> <span class="n">fout</span><span class="p">)</span>
+
+        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">wrf</span><span class="p">:</span>
+            <span class="n">fwrf</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
+
+        <span class="n">grib_index_release</span><span class="p">(</span><span class="n">iid</span><span class="p">)</span>
+
+        <span class="k">return</span></div>
+
+
+<div class="viewcode-block" id="EcFlexpart.process_output"><a class="viewcode-back" href="../api.html#EcFlexpart.EcFlexpart.process_output">[docs]</a>    <span class="k">def</span> <span class="nf">process_output</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39;The grib files are postprocessed depending on the selection in</span>
+<span class="sd">        CONTROL file. The resulting files are moved to the output</span>
+<span class="sd">        directory if its not equal to the input directory.</span>
+<span class="sd">        The following modifications might be done if</span>
+<span class="sd">        properly switched in CONTROL file:</span>
+<span class="sd">        GRIB2 - Conversion to GRIB2</span>
+<span class="sd">        ECTRANS - Transfer of files to gateway server</span>
+<span class="sd">        ECSTORAGE - Storage at ECMWF server</span>
+
+<span class="sd">        Parameters</span>
+<span class="sd">        ----------</span>
+<span class="sd">        c : :obj:`ControlFile`</span>
+<span class="sd">            Contains all the parameters of CONTROL file and</span>
+<span class="sd">            command line.</span>
+
+<span class="sd">        Return</span>
+<span class="sd">        ------</span>
+
+<span class="sd">        &#39;&#39;&#39;</span>
+
+        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n\n</span><span class="s1">Postprocessing:</span><span class="se">\n</span><span class="s1"> Format: </span><span class="si">{}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">format</span><span class="p">))</span>
+
+        <span class="k">if</span> <span class="ow">not</span> <span class="n">c</span><span class="o">.</span><span class="n">ecapi</span><span class="p">:</span>
+            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ecstorage: </span><span class="si">{}</span><span class="se">\n</span><span class="s1"> ecfsdir: </span><span class="si">{}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span>
+                  <span class="nb">format</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">ecstorage</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">ecfsdir</span><span class="p">))</span>
+            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ectrans: </span><span class="si">{}</span><span class="se">\n</span><span class="s1"> gateway: </span><span class="si">{}</span><span class="se">\n</span><span class="s1"> destination: </span><span class="si">{}</span><span class="se">\n</span><span class="s1"> &#39;</span>
+                  <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">ectrans</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">gateway</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">destination</span><span class="p">))</span>
+
+        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Output filelist: &#39;</span><span class="p">)</span>
+        <span class="nb">print</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">outputfilelist</span><span class="p">)</span>
+
+        <span class="k">for</span> <span class="n">ofile</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">outputfilelist</span><span class="p">:</span>
+            <span class="n">ofile</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="n">ofile</span><span class="p">)</span>
+
+            <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">format</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s1">&#39;grib2&#39;</span><span class="p">:</span>
+                <span class="n">p</span> <span class="o">=</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">check_call</span><span class="p">([</span><span class="s1">&#39;grib_set&#39;</span><span class="p">,</span> <span class="s1">&#39;-s&#39;</span><span class="p">,</span> <span class="s1">&#39;edition=2, </span><span class="se">\</span>
+<span class="s1">                                           productDefinitionTemplateNumber=8&#39;</span><span class="p">,</span>
+                                           <span class="n">ofile</span><span class="p">,</span> <span class="n">ofile</span> <span class="o">+</span> <span class="s1">&#39;_2&#39;</span><span class="p">])</span>
+                <span class="n">p</span> <span class="o">=</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">check_call</span><span class="p">([</span><span class="s1">&#39;mv&#39;</span><span class="p">,</span> <span class="n">ofile</span> <span class="o">+</span> <span class="s1">&#39;_2&#39;</span><span class="p">,</span> <span class="n">ofile</span><span class="p">])</span>
+
+            <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">ectrans</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">c</span><span class="o">.</span><span class="n">ecapi</span><span class="p">:</span>
+                <span class="n">p</span> <span class="o">=</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">check_call</span><span class="p">([</span><span class="s1">&#39;ectrans&#39;</span><span class="p">,</span> <span class="s1">&#39;-overwrite&#39;</span><span class="p">,</span> <span class="s1">&#39;-gateway&#39;</span><span class="p">,</span>
+                                           <span class="n">c</span><span class="o">.</span><span class="n">gateway</span><span class="p">,</span> <span class="s1">&#39;-remote&#39;</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">destination</span><span class="p">,</span>
+                                           <span class="s1">&#39;-source&#39;</span><span class="p">,</span> <span class="n">ofile</span><span class="p">])</span>
+
+            <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">ecstorage</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">c</span><span class="o">.</span><span class="n">ecapi</span><span class="p">:</span>
+                <span class="n">p</span> <span class="o">=</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">check_call</span><span class="p">([</span><span class="s1">&#39;ecp&#39;</span><span class="p">,</span> <span class="s1">&#39;-o&#39;</span><span class="p">,</span> <span class="n">ofile</span><span class="p">,</span>
+                                           <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">expandvars</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">ecfsdir</span><span class="p">)])</span>
+
+            <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">outputdir</span> <span class="o">!=</span> <span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">:</span>
+                <span class="n">p</span> <span class="o">=</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">check_call</span><span class="p">([</span><span class="s1">&#39;mv&#39;</span><span class="p">,</span>
+                                           <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">inputdir</span><span class="p">,</span> <span class="n">ofile</span><span class="p">),</span>
+                                           <span class="n">c</span><span class="o">.</span><span class="n">outputdir</span><span class="p">])</span>
+
+        <span class="k">return</span></div>
+
+
+<div class="viewcode-block" id="EcFlexpart.prepare_fp_files"><a class="viewcode-back" href="../api.html#EcFlexpart.EcFlexpart.prepare_fp_files">[docs]</a>    <span class="k">def</span> <span class="nf">prepare_fp_files</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">c</span><span class="p">):</span>
+        <span class="sd">&#39;&#39;&#39;Conversion of GRIB files to FLEXPART binary format.</span>
+
+<span class="sd">        Parameters</span>
+<span class="sd">        ----------</span>
+<span class="sd">        c : :obj:`ControlFile`</span>
+<span class="sd">            Contains all the parameters of CONTROL file and</span>
+<span class="sd">            command line.</span>
+
+<span class="sd">        Return</span>
+<span class="sd">        ------</span>
+
+<span class="sd">        &#39;&#39;&#39;</span>
+        <span class="c1"># generate AVAILABLE file</span>
+        <span class="c1"># Example of AVAILABLE file data:</span>
+        <span class="c1"># 20131107 000000      EN13110700              ON DISC</span>
+        <span class="n">clist</span> <span class="o">=</span> <span class="p">[]</span>
+        <span class="k">for</span> <span class="n">ofile</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">outputfilelist</span><span class="p">:</span>
+            <span class="n">fname</span> <span class="o">=</span> <span class="n">ofile</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)</span>
+            <span class="k">if</span> <span class="s1">&#39;.&#39;</span> <span class="ow">in</span> <span class="n">fname</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]:</span>
+                <span class="n">l</span> <span class="o">=</span> <span class="n">fname</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">split</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">)</span>
+                <span class="n">timestamp</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">l</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="o">-</span><span class="mi">6</span><span class="p">:]</span> <span class="o">+</span> <span class="n">l</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
+                                              <span class="s1">&#39;%y%m</span><span class="si">%d</span><span class="s1">%H&#39;</span><span class="p">)</span>
+                <span class="n">timestamp</span> <span class="o">+=</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">hours</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">l</span><span class="p">[</span><span class="mi">2</span><span class="p">]))</span>
+                <span class="n">cdate</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="n">timestamp</span><span class="p">,</span> <span class="s1">&#39;%Y%m</span><span class="si">%d</span><span class="s1">&#39;</span><span class="p">)</span>
+                <span class="n">chms</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="n">timestamp</span><span class="p">,</span> <span class="s1">&#39;%H%M%S&#39;</span><span class="p">)</span>
+            <span class="k">else</span><span class="p">:</span>
+                <span class="n">cdate</span> <span class="o">=</span> <span class="s1">&#39;20&#39;</span> <span class="o">+</span> <span class="n">fname</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="o">-</span><span class="mi">8</span><span class="p">:</span><span class="o">-</span><span class="mi">2</span><span class="p">]</span>
+                <span class="n">chms</span> <span class="o">=</span> <span class="n">fname</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][</span><span class="o">-</span><span class="mi">2</span><span class="p">:]</span> <span class="o">+</span> <span class="s1">&#39;0000&#39;</span>
+            <span class="n">clist</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">cdate</span> <span class="o">+</span> <span class="s1">&#39; &#39;</span> <span class="o">+</span> <span class="n">chms</span> <span class="o">+</span> <span class="s1">&#39; &#39;</span><span class="o">*</span><span class="mi">6</span> <span class="o">+</span>
+                         <span class="n">fname</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39; &#39;</span><span class="o">*</span><span class="mi">14</span> <span class="o">+</span> <span class="s1">&#39;ON DISC&#39;</span><span class="p">)</span>
+        <span class="n">clist</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span>
+        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">outputdir</span> <span class="o">+</span> <span class="s1">&#39;/&#39;</span> <span class="o">+</span> <span class="s1">&#39;AVAILABLE&#39;</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
+            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">clist</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
+
+        <span class="c1"># generate pathnames file</span>
+        <span class="n">pwd</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">outputdir</span><span class="p">)</span>
+        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">pwd</span> <span class="o">+</span> <span class="s1">&#39;/pathnames&#39;</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
+            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">pwd</span> <span class="o">+</span> <span class="s1">&#39;/Options/</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
+            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">pwd</span> <span class="o">+</span> <span class="s1">&#39;/</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
+            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">pwd</span> <span class="o">+</span> <span class="s1">&#39;/</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
+            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">pwd</span> <span class="o">+</span> <span class="s1">&#39;/AVAILABLE</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
+            <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39; = == = == = == = == = == ==  = </span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
+
+        <span class="c1"># create Options dir if necessary</span>
+        <span class="k">if</span> <span class="ow">not</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">pwd</span> <span class="o">+</span> <span class="s1">&#39;/Options&#39;</span><span class="p">):</span>
+            <span class="n">make_dir</span><span class="p">(</span><span class="n">pwd</span><span class="o">+</span><span class="s1">&#39;/Options&#39;</span><span class="p">)</span>
+
+        <span class="c1"># read template COMMAND file</span>
+        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">expandvars</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">expanduser</span><span class="p">(</span>
+            <span class="n">c</span><span class="o">.</span><span class="n">flexpart_root_scripts</span><span class="p">))</span> <span class="o">+</span> <span class="s1">&#39;/../Options/COMMAND&#39;</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
+            <span class="n">lflist</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
+
+        <span class="c1"># find index of list where to put in the</span>
+        <span class="c1"># date and time information</span>
+        <span class="c1"># usually after the LDIRECT parameter</span>
+        <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
+        <span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="n">lflist</span><span class="p">:</span>
+            <span class="k">if</span> <span class="s1">&#39;LDIRECT&#39;</span> <span class="ow">in</span> <span class="n">l</span><span class="o">.</span><span class="n">upper</span><span class="p">():</span>
+                <span class="k">break</span>
+            <span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
+
+        <span class="c1"># insert the date and time information of run start and end</span>
+        <span class="c1"># into the list of lines of COMMAND file</span>
+        <span class="n">lflist</span> <span class="o">=</span> <span class="n">lflist</span><span class="p">[:</span><span class="n">i</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">clist</span><span class="p">[</span><span class="mi">0</span><span class="p">][:</span><span class="mi">16</span><span class="p">],</span> <span class="n">clist</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">][:</span><span class="mi">16</span><span class="p">]]</span> <span class="o">+</span> \
+                 <span class="n">lflist</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">3</span><span class="p">:]</span>
+
+        <span class="c1"># write the new COMMAND file</span>
+        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">pwd</span> <span class="o">+</span> <span class="s1">&#39;/Options/COMMAND&#39;</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">g</span><span class="p">:</span>
+            <span class="n">g</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">lflist</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
+
+        <span class="c1"># change to outputdir and start the grib2flexpart run</span>
+        <span class="c1"># afterwards switch back to the working dir</span>
+        <span class="n">os</span><span class="o">.</span><span class="n">chdir</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">outputdir</span><span class="p">)</span>
+        <span class="n">p</span> <span class="o">=</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">check_call</span><span class="p">([</span>
+            <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">expandvars</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">expanduser</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">flexpart_root_scripts</span><span class="p">))</span>
+            <span class="o">+</span> <span class="s1">&#39;/../FLEXPART_PROGRAM/grib2flexpart&#39;</span><span class="p">,</span> <span class="s1">&#39;useAvailable&#39;</span><span class="p">,</span> <span class="s1">&#39;.&#39;</span><span class="p">])</span>
+        <span class="n">os</span><span class="o">.</span><span class="n">chdir</span><span class="p">(</span><span class="n">pwd</span><span class="p">)</span>
+
+        <span class="k">return</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">
+        var DOCUMENTATION_OPTIONS = {
+            URL_ROOT:'../',
+            VERSION:'7.1 alpha',
+            LANGUAGE:'None',
+            COLLAPSE_INDEX:false,
+            FILE_SUFFIX:'.html',
+            HAS_SOURCE:  true,
+            SOURCELINK_SUFFIX: '.txt'
+        };
+    </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="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
+
+  
+
+  <script type="text/javascript" src="../_static/js/theme.js"></script>
+
+  <script type="text/javascript">
+      jQuery(function () {
+          SphinxRtdTheme.Navigation.enable(true);
+      });
+  </script> 
+
+</body>
+</html>
