Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
HTML
<div class="section" id="ecflow-variables">
<span id="add-variable"></span><span id="index-0"></span>
<div class="line-block">
<div class="line">We already saw that ecFlow has some <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-variable"><em class="xref std std-term">variable</em></a>&#8216;s, like ECF_HOME.</div>
<div class="line">There are three kinds of variables:</div>
</div>
<ul>
<li><p class="first">The variables that are used by <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecflow"><em class="xref std std-term">ecFlow</em></a>, like ECF_HOME.</p>
</li>
<li><div class="first line-block">
<div class="line">The variables that are defined by the user.</div>
<div class="line">They should <strong>not</strong> start with &#8220;ECF&#8221;.</div>
<div class="line">It is good practice to name these variables with capital letters.</div>
</div>
</li>
<li><div class="first line-block">
<div class="line">The variables that are generated by ecFlow, and that you can use in</div>
<div class="line">your jobs, like ECF_DATE which contains the date of the suite.</div>
</div>
</li>
</ul>
<div class="section" id="ecf-script">
<h2>Ecf Script<a class="headerlink" href="#ecf-script" title="Permalink to this headline">¶</a></h2>
<p>In the previous example, we have copied the file <tt class="file docutils literal"><span class="pre">t1.ecf</span></tt> to the file <tt class="file docutils literal"><span class="pre">t2.ecf</span></tt>.</p>
<div class="line-block">
<div class="line">Edit those two files so they call the unix sleep command with a <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-variable"><em class="xref std std-term">variable</em></a></div>
<div class="line">called SLEEP as a parameter</div>
</div>
<div class="highlight-python"><pre>%include &lt;head.h&gt;
echo "I will now sleep for %SLEEP% seconds"
sleep %SLEEP%
%include &lt;tail.h&gt;</pre>
</div>
</div>
<div class="section" id="text">
<h2>Text<a class="headerlink" href="#text" title="Permalink to this headline">¶</a></h2>
<p>Then add the <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-variable"><em class="xref std std-term">variable</em></a> to the <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-suite-definition"><em class="xref std std-term">suite definition</em></a>:</p>
<div class="highlight-python"><pre># Definition of the suite test.
suite test
   edit ECF_INCLUDE "$HOME/course"   # replace '$HOME' with the path to your home directory
   edit ECF_HOME    "$HOME/course"
   family f1
      task t1
         edit SLEEP 20
      task t2
         edit SLEEP 20
   endfamily
endsuite</pre>
</div>
</div>
<div class="section" id="python">
<h2>Python<a class="headerlink" href="#python" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><div class="highlight"><pre><span class="c">#!/usr/bin/env python2.7</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">ecflow</span>  

<span class="k">def</span> <span class="nf">create_family_f1</span><span class="p">():</span>
    <span class="n">f1</span> <span class="o">=</span> <span class="n">ecflow</span><span class="o">.</span><span class="n">Family</span><span class="p">(</span><span class="s">&quot;f1&quot;</span><span class="p">)</span>
    <span class="n">f1</span><span class="o">.</span><span class="n">add_task</span><span class="p">(</span><span class="s">&quot;t1&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">add_variable</span><span class="p">(</span><span class="s">&quot;SLEEP&quot;</span><span class="p">,</span> <span class="mi">20</span><span class="p">)</span>
    <span class="n">f1</span><span class="o">.</span><span class="n">add_task</span><span class="p">(</span><span class="s">&quot;t2&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">add_variable</span><span class="p">(</span><span class="s">&quot;SLEEP&quot;</span><span class="p">,</span> <span class="mi">20</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">f1</span>      
      
<span class="k">print</span> <span class="s">&quot;Creating suite definition&quot;</span>   
<span class="n">defs</span> <span class="o">=</span> <span class="n">ecflow</span><span class="o">.</span><span class="n">Defs</span><span class="p">()</span>
<span class="n">suite</span> <span class="o">=</span> <span class="n">defs</span><span class="o">.</span><span class="n">add_suite</span><span class="p">(</span><span class="s">&quot;test&quot;</span><span class="p">)</span>
<span class="n">suite</span><span class="o">.</span><span class="n">add_variable</span><span class="p">(</span><span class="s">&quot;ECF_INCLUDE&quot;</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">getenv</span><span class="p">(</span><span class="s">&quot;HOME&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="s">&quot;/course&quot;</span><span class="p">)</span>
<span class="n">suite</span><span class="o">.</span><span class="n">add_variable</span><span class="p">(</span><span class="s">&quot;ECF_HOME&quot;</span><span class="p">,</span>    <span class="n">os</span><span class="o">.</span><span class="n">getenv</span><span class="p">(</span><span class="s">&quot;HOME&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="s">&quot;/course&quot;</span><span class="p">)</span>

<span class="n">suite</span><span class="o">.</span><span class="n">add_family</span><span class="p">(</span> <span class="n">create_family_f1</span><span class="p">()</span> <span class="p">)</span>
<span class="k">print</span> <span class="n">defs</span>

<span class="k">print</span> <span class="s">&quot;Checking job creation: .ecf -&gt; .job0&quot;</span>   
<span class="k">print</span> <span class="n">defs</span><span class="o">.</span><span class="n">check_job_creation</span><span class="p">()</span>

<span class="k">print</span> <span class="s">&quot;Saving definition to file &#39;test.def&#39;&quot;</span>
<span class="n">defs</span><span class="o">.</span><span class="n">save_as_defs</span><span class="p">(</span><span class="s">&quot;test.def&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p><strong>What to do:</strong></p>
<ol class="arabic simple">
<li>Do the modifications</li>
<li>Replace the <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-suite"><em class="xref std std-term">suite</em></a></li>
<li>Watch in <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecflowview"><em class="xref std std-term">ecflowview</em></a>.
You should see the tasks with a <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-status"><em class="xref std std-term">status</em></a> <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-active"><em class="xref std std-term">active</em></a> for 20 seconds</li>
</ol>
</div>
</div>