Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
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 &#8220;c&#8221; 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 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 sharing.
When you have several <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecf-script"><em class="xref std std-term">ecf script</em></a> that need to define common code, it should
be placed in a include file. This then provides a single point of maintenance.</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 head.h 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  provides:</p>
<ul class="simple">
<li>Environment for communication with the server</li>
<li>Defines script error handling. When a trap is raised, we inform the server the task has aborted.</li>
<li>Child command 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=$$


# Tell ecFlow we have started
ecflow_client --init=$$


# Defined a error hanlder
ERROR() {
   set +e                      # Clear -e flag, so we don't fail
   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 tail.h 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.</p>
<div class="highlight-python"><pre>ecflow_client --complete  # Notify ecFlow of a normal end
trap 0                    # Remove all traps
exit 0                    # End the shell</pre>
</div>
<p>What to do:</p>
<ul class="simple">
<li>In another window, change the current directory to course and copy the file <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> into it.</li>
</ul>
</div>
</div>