Index: Documentation/html/_modules/install.html
===================================================================
--- Documentation/html/_modules/install.html	(revision 08c90911f8a1c5051fd7421321897fe5517f12d9)
+++ Documentation/html/_modules/install.html	(revision 903ed4fd4d91f306e96a0cfec36f4e43ad82649e)
@@ -181,7 +181,12 @@
 <span class="c1">#    June 2020 - Anne Philipp</span>
 <span class="c1">#        - renamed &quot;convert&quot; functions to &quot;fortran&quot; functions</span>
-<span class="c1">#        - reconfigured mk_tarball to select *.template files instead </span>
+<span class="c1">#        - reconfigured mk_tarball to select *.template files instead</span>
 <span class="c1">#          of *.nl and *.temp</span>
 <span class="c1">#        - added check for makefile settings</span>
+<span class="c1">#    August 2020 - Leopold Haimberger</span>
+<span class="c1">#        - added a new installation section for system installation (if-else block)</span>
+<span class="c1">#        - read new argument from command line</span>
+<span class="c1">#        - write .setup.rc for a system installation into Run directory</span>
+<span class="c1">#        - copy executables to system path and user files to user path</span>
 <span class="c1">#</span>
 <span class="c1"># @License:</span>
@@ -237,4 +242,5 @@
 <span class="kn">import</span> <span class="nn">subprocess</span>
 <span class="kn">import</span> <span class="nn">tarfile</span>
+<span class="kn">import</span> <span class="nn">shutil</span>
 <span class="kn">from</span> <span class="nn">argparse</span> <span class="kn">import</span> <span class="n">ArgumentParser</span><span class="p">,</span> <span class="n">ArgumentDefaultsHelpFormatter</span>
 
@@ -244,5 +250,6 @@
 <span class="kn">from</span> <span class="nn">Classes.UioFiles</span> <span class="kn">import</span> <span class="n">UioFiles</span>
 <span class="kn">from</span> <span class="nn">Mods.tools</span> <span class="kn">import</span> <span class="p">(</span><span class="n">make_dir</span><span class="p">,</span> <span class="n">put_file_to_ecserver</span><span class="p">,</span> <span class="n">submit_job_to_ecserver</span><span class="p">,</span>
-                        <span class="n">silent_remove</span><span class="p">,</span> <span class="n">execute_subprocess</span><span class="p">,</span> <span class="n">none_or_str</span><span class="p">)</span>
+                        <span class="n">silent_remove</span><span class="p">,</span> <span class="n">execute_subprocess</span><span class="p">,</span> <span class="n">none_or_str</span><span class="p">,</span>
+                        <span class="n">overwrite_lines_in_file</span><span class="p">,</span> <span class="n">check_for_string_in_file</span><span class="p">)</span>
 
 <span class="c1"># ------------------------------------------------------------------------------</span>
@@ -265,9 +272,11 @@
     <span class="n">check_install_conditions</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
 
-    <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">install_target</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">!=</span> <span class="s1">&#39;local&#39;</span><span class="p">:</span> <span class="c1"># ecgate or cca</span>
+    <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">install_target</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;local&#39;</span><span class="p">,</span> <span class="s1">&#39;syslocal&#39;</span><span class="p">]:</span> <span class="c1"># ecgate or cca</span>
         <span class="n">install_via_gateway</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
     <span class="k">else</span><span class="p">:</span> <span class="c1"># local</span>
         <span class="n">install_local</span><span class="p">(</span><span class="n">c</span><span class="p">)</span>
 
+    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;SUCCESS: INSTALLATION FINISHED!&quot;</span><span class="p">)</span>
+
     <span class="k">return</span></div>
 
@@ -290,5 +299,5 @@
     <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">&#39;--target&#39;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s1">&#39;install_target&#39;</span><span class="p">,</span>
                         <span class="nb">type</span><span class="o">=</span><span class="n">none_or_str</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
-                        <span class="n">help</span><span class="o">=</span><span class="s2">&quot;Valid targets: local | ecgate | cca , </span><span class="se">\</span>
+                        <span class="n">help</span><span class="o">=</span><span class="s2">&quot;Valid targets: syslocal | local | ecgate | cca , </span><span class="se">\</span>
 <span class="s2">                        the latter two are at ECMWF&quot;</span><span class="p">)</span>
     <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--makefile&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;makefile&quot;</span><span class="p">,</span>
@@ -312,6 +321,10 @@
     <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--installdir&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;installdir&quot;</span><span class="p">,</span>
                         <span class="nb">type</span><span class="o">=</span><span class="n">none_or_str</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
-                        <span class="n">help</span><span class="o">=</span><span class="s1">&#39;Root directory of the &#39;</span>
+                        <span class="n">help</span><span class="o">=</span><span class="s1">&#39;Root (user) directory of the &#39;</span>
                         <span class="s1">&#39;flex_extract installation&#39;</span><span class="p">)</span>
+    <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--sysinstalldir&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;sysinstalldir&quot;</span><span class="p">,</span>
+                        <span class="nb">type</span><span class="o">=</span><span class="n">none_or_str</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
+                        <span class="n">help</span><span class="o">=</span><span class="s1">&#39;System installation path; where &#39;</span>
+                        <span class="s1">&#39;executables are stored.&#39;</span><span class="p">)</span>
 
     <span class="c1"># arguments for job submission to ECMWF, only needed by submit.py</span>
@@ -390,14 +403,22 @@
                             <span class="n">_config</span><span class="o">.</span><span class="n">FLEXEXTRACT_DIRNAME</span> <span class="o">+</span> <span class="s1">&#39;.tar&#39;</span><span class="p">)</span>
 
-    <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">installdir</span> <span class="o">==</span> <span class="n">_config</span><span class="o">.</span><span class="n">PATH_FLEXEXTRACT_DIR</span><span class="p">:</span>
-        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;WARNING: installdir has not been specified&#39;</span><span class="p">)</span>
-        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;flex_extract will be installed in here by compiling the &#39;</span> <span class="o">+</span>
-              <span class="s1">&#39;Fortran source in &#39;</span> <span class="o">+</span> <span class="n">_config</span><span class="o">.</span><span class="n">PATH_FORTRAN_SRC</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">_config</span><span class="o">.</span><span class="n">PATH_FORTRAN_SRC</span><span class="p">)</span>
-    <span class="k">else</span><span class="p">:</span> <span class="c1"># creates the target working directory for flex_extract</span>
-        <span class="n">c</span><span class="o">.</span><span class="n">installdir</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">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">installdir</span><span class="p">))</span>
-        <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">_config</span><span class="o">.</span><span class="n">PATH_FLEXEXTRACT_DIR</span><span class="p">)</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">installdir</span><span class="p">):</span>
+    <span class="n">c</span><span class="o">.</span><span class="n">installdir</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">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">installdir</span><span class="p">)))</span>
+    <span class="n">c</span><span class="o">.</span><span class="n">sysinstalldir</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">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">sysinstalldir</span><span class="p">)))</span>
+
+    <span class="c1"># this is standard installation into a single directory</span>
+    <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">install_target</span> <span class="o">==</span> <span class="s1">&#39;local&#39;</span><span class="p">:</span>
+
+        <span class="c1"># installation into the current directory</span>
+        <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">_config</span><span class="o">.</span><span class="n">PATH_FLEXEXTRACT_DIR</span><span class="p">)</span> <span class="o">==</span> <span class="n">c</span><span class="o">.</span><span class="n">installdir</span><span class="p">:</span>
+            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;WARNING: installdir has not been specified&#39;</span><span class="p">)</span>
+            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;flex_extract will be installed in current dir by compiling the &#39;</span> <span class="o">+</span>
+                  <span class="s1">&#39;Fortran source in &#39;</span> <span class="o">+</span> <span class="n">_config</span><span class="o">.</span><span class="n">PATH_FORTRAN_SRC</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">_config</span><span class="o">.</span><span class="n">PATH_FORTRAN_SRC</span><span class="p">)</span>
+        <span class="c1"># installation into a different path</span>
+        <span class="k">elif</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">_config</span><span class="o">.</span><span class="n">PATH_FLEXEXTRACT_DIR</span><span class="p">)</span> <span class="o">!=</span> <span class="n">c</span><span class="o">.</span><span class="n">installdir</span> <span class="p">:</span>
+
+            <span class="c1"># creates the target working directory for flex_extract</span>
             <span class="n">mk_tarball</span><span class="p">(</span><span class="n">tar_file</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">install_target</span><span class="p">)</span>
             <span class="n">make_dir</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">installdir</span><span class="p">,</span>
@@ -410,11 +431,90 @@
                                   <span class="n">_config</span><span class="o">.</span><span class="n">PATH_REL_FORTRAN_SRC</span><span class="p">))</span>
 
-    <span class="c1"># Create Fortran executable</span>
-    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Install &#39;</span> <span class="o">+</span>  <span class="n">_config</span><span class="o">.</span><span class="n">FLEXEXTRACT_DIRNAME</span> <span class="o">+</span> <span class="s1">&#39; software at &#39;</span> <span class="o">+</span>
-          <span class="n">c</span><span class="o">.</span><span class="n">install_target</span> <span class="o">+</span> <span class="s1">&#39; in directory &#39;</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">installdir</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="n">del_fortran_build</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">)</span>
-    <span class="n">mk_fortran_build</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">makefile</span><span class="p">)</span>
+        <span class="c1"># Create Fortran executable</span>
+        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Install &#39;</span> <span class="o">+</span>  <span class="n">_config</span><span class="o">.</span><span class="n">FLEXEXTRACT_DIRNAME</span> <span class="o">+</span> <span class="s1">&#39; software at &#39;</span> <span class="o">+</span>
+              <span class="n">c</span><span class="o">.</span><span class="n">install_target</span> <span class="o">+</span> <span class="s1">&#39; in directory &#39;</span> <span class="o">+</span> <span class="n">c</span><span class="o">.</span><span class="n">installdir</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">del_fortran_build</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">)</span>
+        <span class="n">mk_fortran_build</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">makefile</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="s1">&#39;../../&#39;</span><span class="p">)</span>
+        <span class="c1"># make sure that the correct calling of submit.py script is in run_local.sh</span>
+        <span class="n">overwrite_lines_in_file</span><span class="p">(</span><span class="s1">&#39;Run/run_local.sh&#39;</span><span class="p">,</span>
+                                <span class="s1">&#39;pyscript=&#39;</span><span class="p">,</span> <span class="s1">&#39;pyscript=../Source/Python/submit.py</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
+
+    <span class="c1"># this is system installation were executables and user files are separated</span>
+    <span class="k">elif</span> <span class="n">c</span><span class="o">.</span><span class="n">install_target</span> <span class="o">==</span> <span class="s1">&#39;syslocal&#39;</span><span class="p">:</span>
+        <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">_config</span><span class="o">.</span><span class="n">PATH_FLEXEXTRACT_DIR</span><span class="p">)</span> <span class="o">==</span> <span class="n">c</span><span class="o">.</span><span class="n">sysinstalldir</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;ERROR: System installation path is equal to user &#39;</span>
+                     <span class="s1">&#39;installation path.</span><span class="se">\n</span><span class="s1"> Please change either the system &#39;</span>
+                     <span class="s1">&#39;installation path or use installation target &quot;local&quot;.&#39;</span><span class="p">)</span>
+        <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">_config</span><span class="o">.</span><span class="n">PATH_FLEXEXTRACT_DIR</span><span class="p">)</span> <span class="o">==</span> <span class="n">c</span><span class="o">.</span><span class="n">installdir</span> <span class="p">:</span>
+            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Flex_extract will be installed in current directory!&#39;</span><span class="p">)</span>
+        <span class="k">else</span><span class="p">:</span> <span class="c1"># install user part in different dir</span>
+            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Flex_extract will be installed in &#39;</span> <span class="o">+</span> <span class="n">c</span><span class="o">.</span><span class="n">installdir</span> <span class="p">)</span>
+
+            <span class="n">c</span><span class="o">.</span><span class="n">installdir</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">installdir</span><span class="p">,</span><span class="n">_config</span><span class="o">.</span><span class="n">FLEXEXTRACT_DIRNAME</span><span class="p">)</span>
+            <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isdir</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">installdir</span><span class="p">):</span>
+                <span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">installdir</span><span class="p">)</span>
+
+            <span class="c1"># copy all files except Python and Fortranfiles to this dir</span>
+            <span class="n">shutil</span><span class="o">.</span><span class="n">copytree</span><span class="p">(</span><span class="n">_config</span><span class="o">.</span><span class="n">PATH_FLEXEXTRACT_DIR</span><span class="p">,</span>
+                            <span class="n">c</span><span class="o">.</span><span class="n">installdir</span><span class="p">,</span> <span class="n">symlinks</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
+            <span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</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">installdir</span><span class="p">,</span><span class="s1">&#39;Source&#39;</span><span class="p">))</span>
+            <span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</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">installdir</span><span class="p">,</span><span class="s1">&#39;.git&#39;</span><span class="p">))</span>
+            <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">UioFiles</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">installdir</span><span class="p">,</span> <span class="s1">&#39;*~&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">files</span><span class="p">:</span>
+                <span class="n">silent_remove</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
+
+            <span class="n">os</span><span class="o">.</span><span class="n">remove</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">installdir</span><span class="p">,</span><span class="s1">&#39;setup.sh&#39;</span><span class="p">))</span>
+            <span class="n">os</span><span class="o">.</span><span class="n">remove</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">installdir</span><span class="p">,</span><span class="s1">&#39;setup_local.sh&#39;</span><span class="p">))</span>
+
+        <span class="c1"># configure run_local script correctly</span>
+        <span class="c1"># check if source of system config file is already in run_local.sh,</span>
+        <span class="c1"># if not, add it</span>
+        <span class="k">if</span> <span class="ow">not</span> <span class="n">check_for_string_in_file</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">installdir</span><span class="p">,</span><span class="s1">&#39;Run/run_local.sh&#39;</span><span class="p">),</span>
+                                 <span class="s1">&#39;source .setup.rc&#39;</span><span class="p">):</span>
+            <span class="n">overwrite_lines_in_file</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">installdir</span><span class="p">,</span><span class="s1">&#39;Run/run_local.sh&#39;</span><span class="p">),</span>
+                                    <span class="s1">&#39;# PATH TO SUBMISSION SCRIPT&#39;</span><span class="p">,</span>
+                                    <span class="s1">&#39;# PATH TO SUBMISSION SCRIPT</span><span class="se">\n</span><span class="s1">source &#39;</span><span class="o">+</span><span class="n">_config</span><span class="o">.</span><span class="n">FILE_SYS_CONFIG</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"># make sure that the correct calling of submit.py script is in run_local.sh</span>
+        <span class="n">overwrite_lines_in_file</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">installdir</span><span class="p">,</span><span class="s1">&#39;Run/run_local.sh&#39;</span><span class="p">),</span>
+                                <span class="s1">&#39;pyscript=&#39;</span><span class="p">,</span> <span class="s1">&#39;pyscript=submit.py</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
+
+        <span class="c1"># change permission for file to executable</span>
+        <span class="n">execute_subprocess</span><span class="p">([</span><span class="s1">&#39;chmod&#39;</span><span class="p">,</span> <span class="s1">&#39;0775&#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">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">installdir</span><span class="p">),</span><span class="s1">&#39;Run/run_local.sh&#39;</span><span class="p">)])</span>
+
+
+        <span class="c1"># create systemdir</span>
+        <span class="n">c</span><span class="o">.</span><span class="n">sysinstalldir</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">sysinstalldir</span><span class="p">,</span><span class="n">_config</span><span class="o">.</span><span class="n">FLEXEXTRACT_DIRNAME</span><span class="p">)</span>
+        <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isdir</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">sysinstalldir</span><span class="p">):</span>
+            <span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">sysinstalldir</span><span class="p">)</span>
+
+        <span class="c1"># create setup file for running flex_extract with system installation</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">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">installdir</span><span class="p">),</span><span class="s1">&#39;Run/.setup.rc&#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">fio</span><span class="p">:</span>
+            <span class="n">fio</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;#!/bin/bash </span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
+            <span class="n">fio</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;export FLEXEXTRACT_USER_DIR=&#39;</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">installdir</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="n">fio</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;export PATH=&#39;</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">sysinstalldir</span><span class="p">)</span><span class="o">+</span><span class="s1">&#39;/Python:$</span><span class="si">{PATH}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
+            <span class="n">fio</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;export PATH=&#39;</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">sysinstalldir</span><span class="p">)</span><span class="o">+</span><span class="s1">&#39;:$</span><span class="si">{PATH}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
+
+        <span class="c1"># copy all Python and Fortranfiles to this dir</span>
+        <span class="n">shutil</span><span class="o">.</span><span class="n">copytree</span><span class="p">(</span><span class="n">_config</span><span class="o">.</span><span class="n">PATH_SOURCES</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">sysinstalldir</span><span class="p">,</span> <span class="n">symlinks</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">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">sysinstalldir</span><span class="p">,</span><span class="s1">&#39;Fortran&#39;</span><span class="p">))</span>
+        <span class="c1"># Create Fortran executable</span>
+        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Install &#39;</span> <span class="o">+</span>  <span class="n">_config</span><span class="o">.</span><span class="n">FLEXEXTRACT_DIRNAME</span> <span class="o">+</span> <span class="s1">&#39; software as &#39;</span> <span class="o">+</span>
+              <span class="n">c</span><span class="o">.</span><span class="n">install_target</span> <span class="o">+</span> <span class="s1">&#39; in directory &#39;</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">sysinstalldir</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="n">del_fortran_build</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">)</span>
+        <span class="n">mk_fortran_build</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">,</span> <span class="n">c</span><span class="o">.</span><span class="n">makefile</span><span class="p">)</span>
+
+        <span class="n">outfile</span> <span class="o">=</span> <span class="p">[</span><span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">UioFiles</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">,</span><span class="s1">&#39;*.out&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">files</span><span class="p">]</span>
+        <span class="n">test</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">sysinstalldir</span><span class="p">,</span><span class="s1">&#39;calc_etadot&#39;</span><span class="p">)</span>
+        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">outfile</span><span class="p">)</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;WARNING: Multiple executables for Fortran code are available!&#39;</span><span class="p">)</span>
+        <span class="c1"># move executable one dir up and delete Fortran dir</span>
+        <span class="n">os</span><span class="o">.</span><span class="n">chdir</span><span class="p">(</span><span class="s1">&#39;..&#39;</span><span class="p">)</span>
+        <span class="n">shutil</span><span class="o">.</span><span class="n">move</span><span class="p">(</span><span class="n">outfile</span><span class="p">[</span><span class="mi">0</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">sysinstalldir</span><span class="p">,</span><span class="s1">&#39;calc_etadot&#39;</span><span class="p">))</span>
+        <span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</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">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">sysinstalldir</span><span class="p">),</span><span class="s1">&#39;Fortran&#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">_config</span><span class="o">.</span><span class="n">PATH_FLEXEXTRACT_DIR</span><span class="p">)</span>
@@ -451,5 +551,5 @@
         <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
 
-    <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">install_target</span> <span class="ow">and</span> <span class="n">c</span><span class="o">.</span><span class="n">install_target</span> <span class="o">!=</span> <span class="s1">&#39;local&#39;</span><span class="p">:</span>
+    <span class="k">if</span> <span class="n">c</span><span class="o">.</span><span class="n">install_target</span> <span class="ow">and</span> <span class="n">c</span><span class="o">.</span><span class="n">install_target</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s1">&#39;local&#39;</span><span class="p">,</span> <span class="s1">&#39;syslocal&#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">ecgid</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">c</span><span class="o">.</span><span class="n">ecuid</span><span class="p">:</span>
             <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Please enter your ECMWF user id and group id &#39;</span>
@@ -467,7 +567,14 @@
         <span class="k">if</span> <span class="ow">not</span> <span class="n">c</span><span class="o">.</span><span class="n">installdir</span><span class="p">:</span>
             <span class="n">c</span><span class="o">.</span><span class="n">installdir</span> <span class="o">=</span> <span class="s1">&#39;$</span><span class="si">{HOME}</span><span class="s1">&#39;</span>
-    <span class="k">else</span><span class="p">:</span> <span class="c1"># local</span>
+    <span class="k">elif</span> <span class="n">c</span><span class="o">.</span><span class="n">install_target</span> <span class="o">==</span> <span class="s1">&#39;local&#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">installdir</span><span class="p">:</span>
             <span class="n">c</span><span class="o">.</span><span class="n">installdir</span> <span class="o">=</span> <span class="n">_config</span><span class="o">.</span><span class="n">PATH_FLEXEXTRACT_DIR</span>
+    <span class="k">elif</span> <span class="n">c</span><span class="o">.</span><span class="n">install_target</span> <span class="o">==</span> <span class="s1">&#39;syslocal&#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">installdir</span><span class="p">:</span>
+            <span class="n">c</span><span class="o">.</span><span class="n">installdir</span> <span class="o">=</span> <span class="n">_config</span><span class="o">.</span><span class="n">PATH_FLEXEXTRACT_DIR</span>
+        <span class="k">if</span> <span class="ow">not</span> <span class="n">c</span><span class="o">.</span><span class="n">sysinstalldir</span><span class="p">:</span>
+            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;ERROR: System installation was selected but &#39;</span>
+                  <span class="s1">&#39;no system installation path was defined.&#39;</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="k">if</span> <span class="ow">not</span> <span class="n">c</span><span class="o">.</span><span class="n">makefile</span><span class="p">:</span>
@@ -485,5 +592,5 @@
         <span class="k">else</span><span class="p">:</span>
             <span class="k">pass</span>
-        
+
     <span class="k">return</span></div>
 
@@ -877,5 +984,5 @@
         <span class="nb">print</span><span class="p">(</span><span class="n">e</span><span class="p">)</span>
     <span class="k">else</span><span class="p">:</span>
-        <span class="n">execute_subprocess</span><span class="p">([</span><span class="s1">&#39;ls&#39;</span><span class="p">,</span> <span class="s1">&#39;-l&#39;</span><span class="p">,</span> 
+        <span class="n">execute_subprocess</span><span class="p">([</span><span class="s1">&#39;ls&#39;</span><span class="p">,</span> <span class="s1">&#39;-l&#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">src_path</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">error_msg</span><span class="o">=</span><span class="s1">&#39;FORTRAN EXECUTABLE COULD NOT BE FOUND!&#39;</span><span class="p">)</span>
