Index: documentation/Sphinx/build/html/_modules/submit.html
===================================================================
--- documentation/Sphinx/build/html/_modules/submit.html	(revision 274f9efe4b8438ab5238967e39adc200c624b56e)
+++ documentation/Sphinx/build/html/_modules/submit.html	(revision 2625ca8faac35d65699e83e37bb42cdc24163490)
@@ -171,25 +171,40 @@
 <span class="c1">#        - changed path names to variables from config file</span>
 <span class="c1">#        - added option for writing mars requests to extra file</span>
-<span class="c1">#          additionally,as option without submitting the mars jobs</span>
+<span class="c1">#          additionally, as option without submitting the mars jobs</span>
+<span class="c1">#        - splitted submit function to use genshi templates for the</span>
+<span class="c1">#          job script and avoid code duplication</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"># @Program Functionality:</span>
-<span class="c1">#    This program is the main program of flex_extract and controls the</span>
-<span class="c1">#    program flow.</span>
-<span class="c1">#    If it is supposed to work locally then it works through the necessary</span>
-<span class="c1">#    functions get_mars_data and prepareFlexpart. Otherwise it prepares</span>
-<span class="c1">#    a shell job script which will do the necessary work on the</span>
-<span class="c1">#    ECMWF server and is submitted via ecaccess-job-submit.</span>
-<span class="c1">#</span>
-<span class="c1"># @Program Content:</span>
-<span class="c1">#    - main</span>
-<span class="c1">#    - submit</span>
-<span class="c1">#</span>
+<span class="c1">#    (C) Copyright 2014-2019.</span>
+<span class="c1">#    Anne Philipp, Leopold Haimberger</span>
+<span class="c1">#</span>
+<span class="c1">#    This work is licensed under the Creative Commons Attribution 4.0</span>
+<span class="c1">#    International License. To view a copy of this license, visit</span>
+<span class="c1">#    http://creativecommons.org/licenses/by/4.0/ or send a letter to</span>
+<span class="c1">#    Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.</span>
 <span class="c1">#*******************************************************************************</span>
+<span class="sd">&#39;&#39;&#39;This script allows the user to extract meteorological fields from the ECMWF.</span>
+
+<span class="sd">It prepares the settings for retrieving the data from ECMWF servers and</span>
+<span class="sd">process the resulting files to prepare them for the use with FLEXPART or</span>
+<span class="sd">FLEXTRA.</span>
+
+<span class="sd">If it is supposed to work locally then it works through the necessary</span>
+<span class="sd">functions get_mars_data and prepare_flexpart. Otherwise it prepares</span>
+<span class="sd">a job script (korn shell) which will do the necessary work on the</span>
+<span class="sd">ECMWF server. This script will de submitted via the ecaccess command</span>
+<span class="sd">ecaccess-job-submit.</span>
+
+<span class="sd">This file can also be imported as a module which then contains the following</span>
+<span class="sd">functions:</span>
+
+<span class="sd">    * main - the main function of the script</span>
+<span class="sd">    * submit - calls mk_jobscript depending on operation mode and submits its</span>
+<span class="sd">    * mk_jobscript - creates the job script from a template</span>
+
+<span class="sd">Type: submit.py --help</span>
+<span class="sd">to get information about command line parameters.</span>
+<span class="sd">Read the documentation for usage instructions.</span>
+<span class="sd">&#39;&#39;&#39;</span>
 
 <span class="c1"># ------------------------------------------------------------------------------</span>
@@ -201,8 +216,9 @@
 <span class="kn">import</span> <span class="nn">inspect</span>
 <span class="kn">import</span> <span class="nn">collections</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="c1"># software specific classes and modules from flex_extract</span>
 <span class="kn">import</span> <span class="nn">_config</span>
-<span class="kn">from</span> <span class="nn">mods.tools</span> <span class="k">import</span> <span class="p">(</span><span class="n">normal_exit</span><span class="p">,</span> <span class="n">get_cmdline_arguments</span><span class="p">,</span>
+<span class="kn">from</span> <span class="nn">mods.tools</span> <span class="k">import</span> <span class="p">(</span><span class="n">normal_exit</span><span class="p">,</span> <span class="n">get_cmdline_args</span><span class="p">,</span>
                         <span class="n">submit_job_to_ecserver</span><span class="p">,</span> <span class="n">read_ecenv</span><span class="p">)</span>
 <span class="kn">from</span> <span class="nn">mods.get_mars_data</span> <span class="k">import</span> <span class="n">get_mars_data</span>
@@ -211,5 +227,5 @@
 
 <span class="c1"># ------------------------------------------------------------------------------</span>
-<span class="c1"># FUNCTIONS</span>
+<span class="c1"># METHODS</span>
 <span class="c1"># ------------------------------------------------------------------------------</span>
 
@@ -228,5 +244,5 @@
 <span class="sd">    &#39;&#39;&#39;</span>
 
-    <span class="n">args</span> <span class="o">=</span> <span class="n">get_cmdline_arguments</span><span class="p">()</span>
+    <span class="n">args</span> <span class="o">=</span> <span class="n">get_cmdline_args</span><span class="p">()</span>
     <span class="n">c</span> <span class="o">=</span> <span class="n">ControlFile</span><span class="p">(</span><span class="n">args</span><span class="o">.</span><span class="n">controlfile</span><span class="p">)</span>
 
@@ -247,19 +263,22 @@
         <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">request</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">or</span> <span class="n">c</span><span class="o">.</span><span class="n">request</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
             <span class="n">prepare_flexpart</span><span class="p">(</span><span class="n">args</span><span class="o">.</span><span class="n">ppid</span><span class="p">,</span> <span class="n">c</span><span class="p">)</span>
-            <span class="n">normal_exit</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;FLEX_EXTRACT IS DONE!&#39;</span><span class="p">)</span>
+            <span class="n">exit_message</span> <span class="o">=</span> <span class="s1">&#39;FLEX_EXTRACT IS DONE!&#39;</span>
         <span class="k">else</span><span class="p">:</span>
-            <span class="n">normal_exit</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;PRINTING MARS_REQUESTS DONE!&#39;</span><span class="p">)</span>
-    <span class="c1"># send files to ECMWF server and install there</span>
+            <span class="n">exit_message</span> <span class="o">=</span> <span class="s1">&#39;PRINTING MARS_REQUESTS DONE!&#39;</span>
+    <span class="c1"># send files to ECMWF server</span>
     <span class="k">else</span><span class="p">:</span>
         <span class="n">submit</span><span class="p">(</span><span class="n">args</span><span class="o">.</span><span class="n">job_template</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">args</span><span class="o">.</span><span class="n">queue</span><span class="p">)</span>
+        <span class="n">exit_message</span> <span class="o">=</span> <span class="s1">&#39;FLEX_EXTRACT JOB SCRIPT IS SUBMITED!&#39;</span>
+
+    <span class="n">normal_exit</span><span class="p">(</span><span class="n">exit_message</span><span class="p">)</span>
 
     <span class="k">return</span></div>
 
 <div class="viewcode-block" id="submit"><a class="viewcode-back" href="../api.html#submit.submit">[docs]</a><span class="k">def</span> <span class="nf">submit</span><span class="p">(</span><span class="n">jtemplate</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">queue</span><span class="p">):</span>
-    <span class="sd">&#39;&#39;&#39;Prepares the job script and submit it to the specified queue.</span>
+    <span class="sd">&#39;&#39;&#39;Prepares the job script and submits it to the specified queue.</span>
 
 <span class="sd">    Parameters</span>
 <span class="sd">    ----------</span>
-<span class="sd">    jtemplate : :obj:`string`</span>
+<span class="sd">    jtemplate : str</span>
 <span class="sd">        Job template file from sub-directory &quot;_templates&quot; for</span>
 <span class="sd">        submission to ECMWF. It contains all necessary</span>
@@ -268,9 +287,9 @@
 <span class="sd">        Default is &quot;job.temp&quot;.</span>
 
-<span class="sd">    c : :obj:`ControlFile`</span>
+<span class="sd">    c : ControlFile</span>
 <span class="sd">        Contains all the parameters of CONTROL file and</span>
 <span class="sd">        command line.</span>
 
-<span class="sd">    queue : :obj:`string`</span>
+<span class="sd">    queue : str</span>
 <span class="sd">        Name of queue for submission to ECMWF (e.g. ecgate or cca )</span>
 
@@ -280,56 +299,124 @@
 <span class="sd">    &#39;&#39;&#39;</span>
 
-    <span class="c1"># read template file and get index for CONTROL input</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">_config</span><span class="o">.</span><span class="n">PATH_TEMPLATES</span><span class="p">,</span> <span class="n">jtemplate</span><span class="p">))</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
-        <span class="n">lftext</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="n">insert_point</span> <span class="o">=</span> <span class="n">lftext</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="s1">&#39;EOF&#39;</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">basetime</span><span class="p">:</span>
     <span class="c1"># --------- create on demand job script ------------------------------------</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">24</span><span class="p">:</span>
+        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">purefc</span><span class="p">:</span>
             <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;---- Pure forecast mode! ----&#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;---- On-demand mode! ----&#39;</span><span class="p">)</span>
+
         <span class="n">job_file</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">_config</span><span class="o">.</span><span class="n">PATH_JOBSCRIPTS</span><span class="p">,</span>
-                                <span class="n">jtemplate</span><span class="p">[:</span><span class="o">-</span><span class="mi">4</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;ksh&#39;</span><span class="p">)</span>
-        <span class="n">clist</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">to_list</span><span class="p">()</span>
-
-        <span class="n">lftextondemand</span> <span class="o">=</span> <span class="n">lftext</span><span class="p">[:</span><span class="n">insert_point</span><span class="p">]</span> <span class="o">+</span> <span class="n">clist</span> <span class="o">+</span> <span class="n">lftext</span><span class="p">[</span><span class="n">insert_point</span><span class="p">:]</span>
-
-        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">job_file</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">lftextondemand</span><span class="p">))</span>
-
-        <span class="n">submit_job_to_ecserver</span><span class="p">(</span><span class="n">queue</span><span class="p">,</span> <span class="n">job_file</span><span class="p">)</span>
+                                <span class="n">jtemplate</span><span class="p">[:</span><span class="o">-</span><span class="mi">5</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;.ksh&#39;</span><span class="p">)</span>
+
+        <span class="c1"># divide time periode into specified number of job chunks</span>
+        <span class="c1"># to have multiple job scripts</span>
+        <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">job_chunk</span><span class="p">:</span>
+            <span class="n">start</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">start_date</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">end</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="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">chunk</span> <span class="o">=</span> <span class="n">timedelta</span><span class="p">(</span><span class="n">days</span><span class="o">=</span><span class="n">c</span><span class="o">.</span><span class="n">job_chunk</span><span class="p">)</span>
+
+            <span class="k">while</span> <span class="n">start</span> <span class="o">&lt;=</span> <span class="n">end</span><span class="p">:</span>
+                <span class="k">if</span> <span class="p">(</span><span class="n">start</span> <span class="o">+</span> <span class="n">chunk</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="n">end</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="p">(</span><span class="n">start</span> <span class="o">+</span> <span class="n">chunk</span><span class="p">)</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s2">&quot;%Y%m</span><span class="si">%d</span><span class="s2">&quot;</span><span class="p">)</span>
+                <span class="k">else</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">end</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s2">&quot;%Y%m</span><span class="si">%d</span><span class="s2">&quot;</span><span class="p">)</span>
+
+                <span class="n">clist</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">to_list</span><span class="p">()</span>
+
+                <span class="n">mk_jobscript</span><span class="p">(</span><span class="n">jtemplate</span><span class="p">,</span> <span class="n">job_file</span><span class="p">,</span> <span class="n">clist</span><span class="p">)</span>
+
+                <span class="n">job_id</span> <span class="o">=</span> <span class="n">submit_job_to_ecserver</span><span class="p">(</span><span class="n">queue</span><span class="p">,</span> <span class="n">job_file</span><span class="p">)</span>
+                <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;The job id is: &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">job_id</span><span class="o">.</span><span class="n">strip</span><span class="p">()))</span>
+
+                <span class="n">start</span> <span class="o">=</span> <span class="n">start</span> <span class="o">+</span> <span class="n">chunk</span>
+                <span class="n">c</span><span class="o">.</span><span class="n">start_date</span> <span class="o">=</span> <span class="n">start</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s2">&quot;%Y%m</span><span class="si">%d</span><span class="s2">&quot;</span><span class="p">)</span>
+        <span class="c1"># submit a single job script</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="n">clist</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">to_list</span><span class="p">()</span>
+
+            <span class="n">mk_jobscript</span><span class="p">(</span><span class="n">jtemplate</span><span class="p">,</span> <span class="n">job_file</span><span class="p">,</span> <span class="n">clist</span><span class="p">)</span>
+
+            <span class="n">job_id</span> <span class="o">=</span> <span class="n">submit_job_to_ecserver</span><span class="p">(</span><span class="n">queue</span><span class="p">,</span> <span class="n">job_file</span><span class="p">)</span>
+            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;The job id is: &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">job_id</span><span class="o">.</span><span class="n">strip</span><span class="p">()))</span>
 
     <span class="k">else</span><span class="p">:</span>
     <span class="c1"># --------- create operational job script ----------------------------------</span>
         <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;---- Operational mode! ----&#39;</span><span class="p">)</span>
+
         <span class="n">job_file</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">_config</span><span class="o">.</span><span class="n">PATH_JOBSCRIPTS</span><span class="p">,</span>
                                 <span class="n">jtemplate</span><span class="p">[:</span><span class="o">-</span><span class="mi">5</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;oper.ksh&#39;</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="p">:</span>
-            <span class="n">mt</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">maxstep</span><span class="p">)</span>
-        <span class="k">else</span><span class="p">:</span>
-            <span class="n">mt</span> <span class="o">=</span> <span class="mi">0</span>
 
         <span class="n">c</span><span class="o">.</span><span class="n">start_date</span> <span class="o">=</span> <span class="s1">&#39;$</span><span class="si">{MSJ_YEAR}</span><span class="s1">$</span><span class="si">{MSJ_MONTH}</span><span class="s1">$</span><span class="si">{MSJ_DAY}</span><span class="s1">&#39;</span>
         <span class="n">c</span><span class="o">.</span><span class="n">end_date</span> <span class="o">=</span> <span class="s1">&#39;$</span><span class="si">{MSJ_YEAR}</span><span class="s1">$</span><span class="si">{MSJ_MONTH}</span><span class="s1">$</span><span class="si">{MSJ_DAY}</span><span class="s1">&#39;</span>
         <span class="n">c</span><span class="o">.</span><span class="n">base_time</span> <span class="o">=</span> <span class="s1">&#39;$</span><span class="si">{MSJ_BASETIME}</span><span class="s1">&#39;</span>
-        <span class="k">if</span> <span class="n">mt</span> <span class="o">&gt;</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">maxstep</span> <span class="o">&gt;</span> <span class="mi">24</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="s1">&#39;$</span><span class="si">{MSJ_BASETIME}</span><span class="s1"> </span><span class="si">{MSJ_BASETIME}</span><span class="s1">&#39;</span>
 
-        <span class="n">colist</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">to_list</span><span class="p">()</span>
-
-        <span class="n">lftextoper</span> <span class="o">=</span> <span class="n">lftext</span><span class="p">[:</span><span class="n">insert_point</span><span class="p">]</span> <span class="o">+</span> <span class="n">colist</span> <span class="o">+</span> <span class="n">lftext</span><span class="p">[</span><span class="n">insert_point</span> <span class="o">+</span> <span class="mi">2</span><span class="p">:]</span>
-
+        <span class="n">clist</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">to_list</span><span class="p">()</span>
+
+        <span class="n">mk_jobscript</span><span class="p">(</span><span class="n">jtemplate</span><span class="p">,</span> <span class="n">job_file</span><span class="p">,</span> <span class="n">clist</span><span class="p">)</span>
+
+        <span class="n">job_id</span> <span class="o">=</span> <span class="n">submit_job_to_ecserver</span><span class="p">(</span><span class="n">queue</span><span class="p">,</span> <span class="n">job_file</span><span class="p">)</span>
+        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;The job id is: &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">job_id</span><span class="o">.</span><span class="n">strip</span><span class="p">()))</span>
+
+    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;You should get an email per job with subject flex.hostname.pid&#39;</span><span class="p">)</span>
+
+    <span class="k">return</span></div>
+
+<div class="viewcode-block" id="mk_jobscript"><a class="viewcode-back" href="../api.html#submit.mk_jobscript">[docs]</a><span class="k">def</span> <span class="nf">mk_jobscript</span><span class="p">(</span><span class="n">jtemplate</span><span class="p">,</span> <span class="n">job_file</span><span class="p">,</span> <span class="n">clist</span><span class="p">):</span>
+    <span class="sd">&#39;&#39;&#39;Creates the job script from template.</span>
+
+<span class="sd">    Parameters</span>
+<span class="sd">    ----------</span>
+<span class="sd">    jtemplate : str</span>
+<span class="sd">        Job template file from sub-directory &quot;_templates&quot; for</span>
+<span class="sd">        submission to ECMWF. It contains all necessary</span>
+<span class="sd">        module and variable settings for the ECMWF environment as well as</span>
+<span class="sd">        the job call and mail report instructions.</span>
+<span class="sd">        Default is &quot;job.temp&quot;.</span>
+
+<span class="sd">    job_file : str</span>
+<span class="sd">        Path to the job script file.</span>
+
+<span class="sd">    clist : list of str</span>
+<span class="sd">        Contains all necessary parameters for ECMWF CONTROL 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="kn">from</span> <span class="nn">genshi.template.eval</span> <span class="k">import</span> <span class="n">UndefinedError</span>
+
+    <span class="c1"># load template and insert control content as list</span>
+    <span class="k">try</span><span class="p">:</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">control_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">jtemplate</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="n">stream</span> <span class="o">=</span> <span class="n">control_template</span><span class="o">.</span><span class="n">generate</span><span class="p">(</span><span class="n">control_content</span><span class="o">=</span><span class="n">clist</span><span class="p">)</span>
+    <span class="k">except</span> <span class="n">UndefinedError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
+        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;... ERROR &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
+
+        <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">... error occured while trying to generate jobscript&#39;</span><span class="p">)</span>
+    <span class="k">except</span> <span class="ne">OSError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
+        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;... ERROR CODE: &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">errno</span><span class="p">))</span>
+        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;... ERROR MESSAGE:</span><span class="se">\n</span><span class="s1"> </span><span class="se">\t</span><span class="s1"> &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">strerror</span><span class="p">))</span>
+
+        <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">... error occured while trying to generate jobscript&#39;</span><span class="p">)</span>
+
+    <span class="c1"># create jobscript file</span>
+    <span class="k">try</span><span class="p">:</span>
         <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">job_file</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">lftextoper</span><span class="p">))</span>
-
-        <span class="n">submit_job_to_ecserver</span><span class="p">(</span><span class="n">queue</span><span class="p">,</span> <span class="n">job_file</span><span class="p">)</span>
-
-    <span class="c1"># --------------------------------------------------------------------------</span>
-    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;You should get an email with subject flex.hostname.pid&#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">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">except</span> <span class="ne">OSError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
+        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;... ERROR CODE: &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">errno</span><span class="p">))</span>
+        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;... ERROR MESSAGE:</span><span class="se">\n</span><span class="s1"> </span><span class="se">\t</span><span class="s1"> &#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">strerror</span><span class="p">))</span>
+
+        <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">... error occured while trying to write &#39;</span> <span class="o">+</span> <span class="n">job_file</span><span class="p">)</span>
 
     <span class="k">return</span></div>
+
 
 <span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">&quot;__main__&quot;</span><span class="p">:</span>
@@ -347,5 +434,5 @@
   <div role="contentinfo">
     <p>
-        &copy; Copyright 2018, Anne Philipp and Leopold Haimberger.
+        &copy; Copyright 2018, Anne Philipp and Leopold Haimberger
 
     </p>
@@ -366,19 +453,11 @@
   
 
-    <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" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
+        <script type="text/javascript" src="../_static/jquery.js"></script>
+        <script type="text/javascript" src="../_static/underscore.js"></script>
+        <script type="text/javascript" src="../_static/doctools.js"></script>
+    
 
   
