<div class="section" id="add-a-meter">
<span id="add-meter"></span><span id="index-0"></span>
<div class="line-block">
<div class="line">A <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-meter"><em class="xref std std-term">meter</em></a> is very similar to an <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-event"><em class="xref std std-term">event</em></a>.</div>
<div class="line">Instead of being a boolean value (on/off), it can take a range of integer values.</div>
<div class="line">Other tasks are then triggered when the <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-meter"><em class="xref std std-term">meter</em></a> reaches a certain value.</div>
<div class="line">Like events, <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-meter"><em class="xref std std-term">meter</em></a>‘s have names and a <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-task"><em class="xref std std-term">task</em></a> can have several of them.</div>
</div>
<div class="section" id="ecf-script">
<h2>Ecf Script<a class="headerlink" href="#ecf-script" title="Permalink to this headline">¶</a></h2>
<div class="line-block">
<div class="line">We will create new tasks (t5, t6 and t7) that will be triggered</div>
<div class="line">when the <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-meter"><em class="xref std std-term">meter</em></a> in task t1 reaches certain values.</div>
</div>
<div class="line-block">
<div class="line">To notify <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecflow-server"><em class="xref std std-term">ecflow_server</em></a>, the <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-task"><em class="xref std std-term">task</em></a> ( <strong>t1</strong> in the example below) must call</div>
<div class="line">the <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecflow-client"><em class="xref std std-term">ecflow_client</em></a> –meter. This is also one of the <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-child-command"><em class="xref std std-term">child command</em></a>‘s.</div>
</div>
<div class="highlight-python"><pre>%include <head.h>
echo "I will now sleep for %SLEEP% seconds"
sleep %SLEEP%
n=1
while [[ $n -le 100 ]] # Loop 100 times
do
sleep 1 # Wait a short time
ecflow_client --meter progress $n # Notify ecFlow
(( n = $n + 1 ))
done
%include <tail.h></pre>
</div>
</div>
<div class="section" id="text">
<h2>Text<a class="headerlink" href="#text" title="Permalink to this headline">¶</a></h2>
<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
edit SLEEP 20
task t1
meter progress 1 100 90
task t2
trigger t1 eq complete
event a
event b
task t3
trigger t2:a
task t4
trigger t2 eq complete
complete t2:b
task t5
trigger t1:progress ge 30
task t6
trigger t1:progress ge 60
task t7
trigger t1:progress ge 90
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">"f1"</span><span class="p">)</span>
<span class="n">f1</span><span class="o">.</span><span class="n">add_variable</span><span class="p">(</span><span class="s">"SLEEP"</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">"t1"</span><span class="p">)</span><span class="o">.</span><span class="n">add_meter</span><span class="p">(</span><span class="s">"progress"</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">100</span><span class="p">,</span> <span class="mi">90</span><span class="p">)</span>
<span class="n">t2</span> <span class="o">=</span> <span class="n">f1</span><span class="o">.</span><span class="n">add_task</span><span class="p">(</span><span class="s">"t2"</span><span class="p">)</span>
<span class="n">t2</span><span class="o">.</span><span class="n">add_trigger</span><span class="p">(</span><span class="s">"t1 eq complete"</span><span class="p">)</span>
<span class="n">t2</span><span class="o">.</span><span class="n">add_event</span><span class="p">(</span><span class="s">"a"</span><span class="p">)</span>
<span class="n">t2</span><span class="o">.</span><span class="n">add_event</span><span class="p">(</span><span class="s">"b"</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">"t3"</span><span class="p">)</span><span class="o">.</span><span class="n">add_trigger</span><span class="p">(</span><span class="s">"t2:a"</span><span class="p">)</span>
<span class="n">t4</span> <span class="o">=</span> <span class="n">f1</span><span class="o">.</span><span class="n">add_task</span><span class="p">(</span><span class="s">"t4"</span><span class="p">)</span>
<span class="n">t4</span><span class="o">.</span><span class="n">add_trigger</span><span class="p">(</span><span class="s">"t2 eq complete"</span><span class="p">)</span>
<span class="n">t4</span><span class="o">.</span><span class="n">add_complete</span><span class="p">(</span><span class="s">"t2:b"</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">"t5"</span><span class="p">)</span><span class="o">.</span><span class="n">add_trigger</span><span class="p">(</span><span class="s">"t1:progress ge 30"</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">"t6"</span><span class="p">)</span><span class="o">.</span><span class="n">add_trigger</span><span class="p">(</span><span class="s">"t1:progress ge 60"</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">"t7"</span><span class="p">)</span><span class="o">.</span><span class="n">add_trigger</span><span class="p">(</span><span class="s">"t1:progress ge 90"</span><span class="p">)</span>
<span class="k">return</span> <span class="n">f1</span>
<span class="k">print</span> <span class="s">"Creating suite definition"</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">"test"</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">"ECF_INCLUDE"</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">"HOME"</span><span class="p">)</span> <span class="o">+</span> <span class="s">"/course"</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">"ECF_HOME"</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">"HOME"</span><span class="p">)</span> <span class="o">+</span> <span class="s">"/course"</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">"Checking job creation: .ecf -> .job0"</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">"Checking trigger expressions"</span>
<span class="k">print</span> <span class="n">defs</span><span class="o">.</span><span class="n">check</span><span class="p">()</span>
<span class="k">print</span> <span class="s">"Saving definition to file 'test.def'"</span>
<span class="n">defs</span><span class="o">.</span><span class="n">save_as_defs</span><span class="p">(</span><span class="s">"test.def"</span><span class="p">)</span>
</pre></div>
</div>
<p><strong>What to do:</strong></p>
<ol class="arabic simple">
<li>Edit the definition file or python to add the modifications.</li>
<li>Edit <tt class="file docutils literal"><span class="pre">t1.ecf</span></tt> to call <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecflow-client"><em class="xref std std-term">ecflow_client</em></a> –meter</li>
<li>Copy <tt class="file docutils literal"><span class="pre">t4.ecf</span></tt> to <tt class="file docutils literal"><span class="pre">t5.ecf</span></tt>, <tt class="file docutils literal"><span class="pre">t6.ecf</span></tt> and <tt class="file docutils literal"><span class="pre">t7.ecf</span></tt></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>Observe the tasks in <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecflowview"><em class="xref std std-term">ecflowview</em></a>.</li>
<li>See the triggers by selecting progress and clicking on the Triggers icon.</li>
<li>Move the mouse pointer over <img alt="progress" src="../../../_images/wiki/download/attachments/7373012/progress.jpg" /> then with the right mouse button, choose <strong>Edit...</strong></li>
<li>Modify the value of the <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-meter"><em class="xref std std-term">meter</em></a> and click on the Apply icon <img alt="apply" src="../../../_images/wiki/download/attachments/7373012/apply.jpg" /></li>
</ol>
</div>
</div>
|