Page History
HTML |
---|
<div class="section" id="understanding-includes"> <span id="index-0"></span><span id="id1"></span> <p>In the previous section we created a <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-task"><em class="xref std std-term">task</em></a>.</p> <p>A task has corresponding <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecf-script"><em class="xref std std-term">ecf script</em></a> which defines the work to be carried out. Scripts are similar to UNIX shell scripts.</p> <p>However <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecf-script"><em class="xref std std-term">ecf script</em></a> includes the addition of “c” like <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-pre-processing"><em class="xref std std-term">pre-processing</em></a> <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-directives"><em class="xref std std-term">directives</em></a> and <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-variable"><em class="xref std std-term">variable</em></a> s.</p> <p>The default <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-pre-processing"><em class="xref std std-term">pre-processing</em></a> <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-directives"><em class="xref std std-term">directives</em></a> are specified by default using the % character.</p> <p>One of the <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-pre-processing"><em class="xref std std-term">pre-processing</em></a> <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-directives"><em class="xref std std-term">directives</em></a> is an include.</p> <p>The include is used to inject code into a script, and provide a mechanism for code reuse. If the same code appears in several different <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecf-script"><em class="xref std std-term">ecf script</em></a> files, it should be placed in a include file instead. This then provides a single point of maintenance. For example, every <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-task"><em class="xref std std-term">task</em></a> needs to set up the communication with the <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecflow-server"><em class="xref std std-term">ecflow_server</em></a> and then tell the server that it (task) has started. This ‘boilerplate’ code is placed in an include file.</p> <div class="section" id="head-h"> <span id="id2"></span><h2>head.h<a class="headerlink" href="#head-h" title="Permalink to this headline">¶</a></h2> <p>The <tt class="file docutils literal"><span class="pre">head.h</span></tt> include file is placed at the start of <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecf-script"><em class="xref std std-term">ecf script</em></a>. It:</p> <ul class="simple"> <li>Provides the environment for communication with the <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecflow-server"><em class="xref std std-term">ecflow_server</em></a></li> <li>Defines script error handling. When the script fails a trap is raised, we inform the server the <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-task"><em class="xref std std-term">task</em></a> has <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-aborted"><em class="xref std std-term">aborted</em></a>.</li> <li>Issues a <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-child-command"><em class="xref std std-term">child command</em></a> to inform the server that job has started.</li> </ul> <div class="highlight-python"><pre>#!/bin/ksh set -e # stop the shell on first error set -u # fail when using an undefined variable set -x # echo script lines as they are executed # Defines the variables that are needed for any communication with ECF export ECF_PORT=%ECF_PORT% # The server port number export ECF_NODE=%ECF_NODE% # The name of ecf host that issued this task export ECF_NAME=%ECF_NAME% # The name of this current task export ECF_PASS=%ECF_PASS% # A unique password export ECF_TRYNO=%ECF_TRYNO% # Current try number of the task export ECF_RID=$$ # Define the path where to find ecflow_client # make sure client and server use the *same* version. # Important when there are multiple versions of ecFlow export PATH=/usr/local/apps/ecflow/%ECF_VERSION%/bin:$PATH # Tell ecFlow we have started ecflow_client --init=$$ # Define a error handler ERROR() { set +e # Clear -e flag, so we don't fail wait # wait for background process to stop ecflow_client --abort=trap # Notify ecFlow that something went wrong, using 'trap' as the reason trap 0 # Remove the trap exit 0 # End the script } # Trap any calls to exit and errors caught by the -e flag trap ERROR 0 # Trap any signal that may cause the script to fail trap '{ echo "Killed by a signal"; ERROR ; }' 1 2 3 4 5 6 7 8 10 12 13 15</pre> </div> </div> <div class="section" id="tail-h"> <span id="id3"></span><h2>tail.h<a class="headerlink" href="#tail-h" title="Permalink to this headline">¶</a></h2> <p>The <tt class="file docutils literal"><span class="pre">tail.h</span></tt> include file is placed at the end of <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecf-script"><em class="xref std std-term">ecf script</em></a> and is used to inform the server that job has completed. It issues the complete <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-child-command"><em class="xref std std-term">child command</em></a></p> <div class="highlight-python"><pre>ecflow><pre>wait # wait for background process to stop ecflow_client --complete # Notify ecFlow of a normal end trap 0 # Remove all traps exit 0 # End the shell</pre> </div> <p><strong>What to do:</strong></p> <ul class="simple"> <li>Create the <a class="reference internal" href="#head-h"><em>head.h</em></a> and <a class="reference internal" href="#tail-h"><em>tail.h</em></a> files in your $HOME/course directory.</li> </ul> </div> </div> |