<style type="text/css"> .highlight .hll { background-color: #ffffcc } .highlight { background: #eeffcc; } .highlight .c { color: #408090; font-style: italic } /* Comment */ .highlight .err { border: 1px solid #FF0000 } /* Error */ .highlight .k { color: #007020; font-weight: bold } /* Keyword */ .highlight .o { color: #666666 } /* Operator */ .highlight .cm { color: #408090; font-style: italic } /* Comment.Multiline */ .highlight .cp { color: #007020 } /* Comment.Preproc */ .highlight .c1 { color: #408090; font-style: italic } /* Comment.Single */ .highlight .cs { color: #408090; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #A00000 } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #FF0000 } /* Generic.Error */ .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ .highlight .gi { color: #00A000 } /* Generic.Inserted */ .highlight .go { color: #303030 } /* Generic.Output */ .highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ .highlight .gt { color: #0040D0 } /* Generic.Traceback */ .highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #007020 } /* Keyword.Pseudo */ .highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #902000 } /* Keyword.Type */ .highlight .m { color: #208050 } /* Literal.Number */ .highlight .s { color: #4070a0 } /* Literal.String */ .highlight .na { color: #4070a0 } /* Name.Attribute */ .highlight .nb { color: #007020 } /* Name.Builtin */ .highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */ .highlight .no { color: #60add5 } /* Name.Constant */ .highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */ .highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */ .highlight .ne { color: #007020 } /* Name.Exception */ .highlight .nf { color: #06287e } /* Name.Function */ .highlight .nl { color: #002070; font-weight: bold } /* Name.Label */ .highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */ .highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #bb60d5 } /* Name.Variable */ .highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mf { color: #208050 } /* Literal.Number.Float */ .highlight .mh { color: #208050 } /* Literal.Number.Hex */ .highlight .mi { color: #208050 } /* Literal.Number.Integer */ .highlight .mo { color: #208050 } /* Literal.Number.Oct */ .highlight .sb { color: #4070a0 } /* Literal.String.Backtick */ .highlight .sc { color: #4070a0 } /* Literal.String.Char */ .highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */ .highlight .s2 { color: #4070a0 } /* Literal.String.Double */ .highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */ .highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */ .highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */ .highlight .sx { color: #c65d09 } /* Literal.String.Other */ .highlight .sr { color: #235388 } /* Literal.String.Regex */ .highlight .s1 { color: #4070a0 } /* Literal.String.Single */ .highlight .ss { color: #517918 } /* Literal.String.Symbol */ .highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */ .highlight .vc { color: #bb60d5 } /* Name.Variable.Class */ .highlight .vg { color: #bb60d5 } /* Name.Variable.Global */ .highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */ .highlight .il { color: #208050 } /* Literal.Number.Integer.Long */ </style> <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 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> |