
<?xml-stylesheet type="text/xsl" href="../styles/pmathml.xsl"?>

<html xmlns="http://www.w3.org/1999/xhtml" xml:space="preserve"><head><title>
  NAG C Library, Mark 7 : 
  
    Essential Introduction
   </title><link rel="stylesheet" href="../styles/libdoc.css" type="text/css"/><script type="text/javascript">
   function showLevelb(_levelId){
    var thisLevel = document.getElementById(_levelId);
    var thisplus = document.getElementById( _levelId.concat('plus'));
    var thisminus = document.getElementById( _levelId.concat('minus'));
    if(thisLevel.style.display != "block"){
     thisLevel.style.display = "block";
     thisplus.style.display = "none";
     thisminus.style.display = "inline";
     }
    else{
     thisLevel.style.display = "none";
     thisminus.style.display = "none";
     thisplus.style.display = "inline";
     }
    }
  </script></head><body><hr/><div><a href="../../pdf/genint/essint.pdf">Essential Introduction (pdf version)</a></div><div><a href="../mark7.xml">NAG C Library Contents</a></div><hr/><img src="../images/topbar/title_numeric_cl.gif" alt="NAG C Library" hspace="0" width="506" height="117" border="0"/><h1 class="genint">Essential Introduction</h1><p><b>Note:</b>&#160;<i>this document is essential reading for any prospective user of the Library.</i></p>
<div class="toc"><h3>Contents</h3>
<h2 class="toc"><a class="rtnref" href="#libanddoc">1&#160;&#160;The Library and its Documentation</a></h2>
<h3 class="toc"><a class="rtnref" href="#libanddoc1">1.1&#160;&#160;Structure of the Library</a></h3>
<h3 class="toc"><a class="rtnref" href="#libanddoc2">1.2&#160;&#160;Structure of the Documentation</a></h3>
<h3 class="toc"><a class="rtnref" href="#libanddoc3">1.3&#160;&#160;Alternative Forms of Documentation</a></h3>
<h3 class="toc"><a class="rtnref" href="#libanddoc4">1.4&#160;&#160;Marks of the Library</a></h3>
<h3 class="toc"><a class="rtnref" href="#libanddoc5">1.5&#160;&#160;Implementations of the Library</a></h3>
<h3 class="toc"><a class="rtnref" href="#libanddoc6">1.6&#160;&#160;Precision of the Library</a></h3>
<h3 class="toc"><a class="rtnref" href="#libanddoc7">1.7&#160;&#160;Library Identification</a></h3>
<h3 class="toc"><a class="rtnref" href="#libanddoc8">1.8&#160;&#160;C Language Standards</a></h3>
<h2 class="toc"><a class="rtnref" href="#library">2&#160;&#160;Using the Library</a></h2>
<h3 class="toc"><a class="rtnref" href="#library1">2.1&#160;&#160;General Advice</a></h3>
<h3 class="toc"><a class="rtnref" href="#library2">2.2&#160;&#160;Programming Advice</a></h3>
<h4 class="toc"><a class="rtnref" href="#usingCenviron">2.2.1&#160;&#160;The NAG C environment</a></h4>
<h5 class="toc"><a class="rtnref" href="#usingdatatypes">2.2.1.1&#160;&#160;NAG data types</a></h5>
<h5 class="toc"><a class="rtnref" href="#usingmemory">2.2.1.2&#160;&#160;Memory management in the Library</a></h5>
<h5 class="toc"><a class="rtnref" href="#usingNagOrder">2.2.1.3&#160;&#160;The Nag_Order parameter</a></h5>
<h5 class="toc"><a class="rtnref" href="#usingarrayrefs">2.2.1.4&#160;&#160;Array references</a></h5>
<h5 class="toc"><a class="rtnref" href="#usinginternal">2.2.1.5&#160;&#160;Internal data structures in the NAG C Library</a></h5>
<h5 class="toc"><a class="rtnref" href="#usingheader">2.2.1.6&#160;&#160;Chapter header files</a></h5>
<h3 class="toc"><a class="rtnref" href="#usinglongnames">2.3&#160;&#160;Use of NAG Long Names</a></h3>
<h3 class="toc"><a class="rtnref" href="#usingio">2.4&#160;&#160;Input/Output</a></h3>
<h3 class="toc"><a class="rtnref" href="#usingauxiliary">2.5&#160;&#160;Auxiliary Functions</a></h3>
<h3 class="toc"><a class="rtnref" href="#usingerrorhand">2.6&#160;&#160;NAG Error Handling and the fail Parameter</a></h3>
<h4 class="toc"><a class="rtnref" href="#usenagerrdefault">2.6.1&#160;&#160;Use of <span class="mono">NAGERR_DEFAULT</span></a></h4>
<h4 class="toc"><a class="rtnref" href="#library3">2.6.2&#160;&#160;Use of the fail parameter</a></h4>
<h4 class="toc"><a class="rtnref" href="#usingnagerror">2.6.3&#160;&#160;The <span class="mono">NagError</span> structure</a></h4>
<h3 class="toc"><a class="rtnref" href="#threadsafety">2.7&#160;&#160;Thread Safety</a></h3>
<h3 class="toc"><a class="rtnref" href="#library7">2.8&#160;&#160;Calling the Library from Other Languages</a></h3>
<h2 class="toc"><a class="rtnref" href="#doc">3&#160;&#160;Using the Documentation</a></h2>
<h3 class="toc"><a class="rtnref" href="#doc1">3.1&#160;&#160;Using the Manual</a></h3>
<h3 class="toc"><a class="rtnref" href="#doc2">3.2&#160;&#160;Structure of Function Documents</a></h3>
<h3 class="toc"><a class="rtnref" href="#doc3">3.3&#160;&#160;Specification of Parameters</a></h3>
<h4 class="toc"><a class="rtnref" href="#doc31">3.3.1&#160;&#160;Classification of parameters</a></h4>
<h4 class="toc"><a class="rtnref" href="#doc32">3.3.2&#160;&#160;Constraints and suggested values</a></h4>
<h3 class="toc"><a class="rtnref" href="#doc5">3.4&#160;&#160;Example Programs and Results</a></h3>
<h3 class="toc"><a class="rtnref" href="#doc6">3.5&#160;&#160;Summary for New Users</a></h3>
<h2 class="toc"><a class="rtnref" href="#support">4&#160;&#160;Support from NAG</a></h2>
<h2 class="toc"><a class="rtnref" href="#further">5&#160;&#160;Background to NAG</a></h2>
<h2 class="toc"><a class="rtnref" href="#references">6&#160;&#160;References</a></h2></div>

<div class="htmltoc">
<h2><a class="xy" href="javascript:showLevelb( 'htmltoc');"><span class="htmltocplus" id="htmltocplus">+</span><span class="htmltocminus" id="htmltocminus">&#8722;</span></a>&#160;Contents</h2>
<div class="htmltocitem" id="htmltoc">
<div class="htmltoc">
<a class="htmltoc" href="javascript:showLevelb( 'toclibanddoc');"><span class="htmltocplus" id="toclibanddocplus">+</span><span class="htmltocminus" id="toclibanddocminus">&#8722;</span></a>
<a class="htmltoc" href="#libanddoc">&#160;1&#160;<b>The Library and its Documentation</b></a>
<div class="htmltocitem" id="toclibanddoc">
<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#libanddoc1">&#160;1.1&#160;<b>Structure of the Library</b></a>
<div class="htmltocitem" id="toclibanddoc1"/>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#libanddoc2">&#160;1.2&#160;<b>Structure of the Documentation</b></a>
<div class="htmltocitem" id="toclibanddoc2"/>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#libanddoc3">&#160;1.3&#160;<b>Alternative Forms of Documentation</b></a>
<div class="htmltocitem" id="toclibanddoc3"/>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#libanddoc4">&#160;1.4&#160;<b>Marks of the Library</b></a>
<div class="htmltocitem" id="toclibanddoc4"/>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#libanddoc5">&#160;1.5&#160;<b>Implementations of the Library</b></a>
<div class="htmltocitem" id="toclibanddoc5"/>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#libanddoc6">&#160;1.6&#160;<b>Precision of the Library</b></a>
<div class="htmltocitem" id="toclibanddoc6"/>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#libanddoc7">&#160;1.7&#160;<b>Library Identification</b></a>
<div class="htmltocitem" id="toclibanddoc7"/>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#libanddoc8">&#160;1.8&#160;<b>C Language Standards</b></a>
<div class="htmltocitem" id="toclibanddoc8"/>
</div>
</div>
</div>

<div class="htmltoc">
<a class="htmltoc" href="javascript:showLevelb( 'toclibrary');"><span class="htmltocplus" id="toclibraryplus">+</span><span class="htmltocminus" id="toclibraryminus">&#8722;</span></a>
<a class="htmltoc" href="#library">&#160;2&#160;<b>Using the Library</b></a>
<div class="htmltocitem" id="toclibrary">
<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#library1">&#160;2.1&#160;<b>General Advice</b></a>
<div class="htmltocitem" id="toclibrary1"/>
</div>

<div class="htmltoc">
<a class="htmltoc" href="javascript:showLevelb( 'toclibrary2');"><span class="htmltocplus" id="toclibrary2plus">+</span><span class="htmltocminus" id="toclibrary2minus">&#8722;</span></a>
<a class="htmltoc" href="#library2">&#160;2.2&#160;<b>Programming Advice</b></a>
<div class="htmltocitem" id="toclibrary2">
<div class="htmltoc">
<a class="htmltoc" href="javascript:showLevelb( 'tocusingCenviron');"><span class="htmltocplus" id="tocusingCenvironplus">+</span><span class="htmltocminus" id="tocusingCenvironminus">&#8722;</span></a>
<a class="htmltoc" href="#usingCenviron">&#160;2.2.1&#160;<b>The NAG C environment</b></a>
<div class="htmltocitem" id="tocusingCenviron">
<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#usingdatatypes">&#160;2.2.1.1&#160;<b>NAG data types</b></a>
<div class="htmltocitem" id="tocusingdatatypes"/>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#usingmemory">&#160;2.2.1.2&#160;<b>Memory management in the Library</b></a>
<div class="htmltocitem" id="tocusingmemory"/>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#usingNagOrder">&#160;2.2.1.3&#160;<b>The Nag_Order parameter</b></a>
<div class="htmltocitem" id="tocusingNagOrder"/>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#usingarrayrefs">&#160;2.2.1.4&#160;<b>Array references</b></a>
<div class="htmltocitem" id="tocusingarrayrefs"/>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#usinginternal">&#160;2.2.1.5&#160;<b>Internal data structures in the NAG C Library</b></a>
<div class="htmltocitem" id="tocusinginternal"/>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#usingheader">&#160;2.2.1.6&#160;<b>Chapter header files</b></a>
<div class="htmltocitem" id="tocusingheader"/>
</div>
</div>
</div>
</div>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#usinglongnames">&#160;2.3&#160;<b>Use of NAG Long Names</b></a>
<div class="htmltocitem" id="tocusinglongnames"/>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#usingio">&#160;2.4&#160;<b>Input/Output</b></a>
<div class="htmltocitem" id="tocusingio"/>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#usingauxiliary">&#160;2.5&#160;<b>Auxiliary Functions</b></a>
<div class="htmltocitem" id="tocusingauxiliary"/>
</div>

<div class="htmltoc">
<a class="htmltoc" href="javascript:showLevelb( 'tocusingerrorhand');"><span class="htmltocplus" id="tocusingerrorhandplus">+</span><span class="htmltocminus" id="tocusingerrorhandminus">&#8722;</span></a>
<a class="htmltoc" href="#usingerrorhand">&#160;2.6&#160;<b>NAG Error Handling and the fail Parameter</b></a>
<div class="htmltocitem" id="tocusingerrorhand">
<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#usenagerrdefault">&#160;2.6.1&#160;<b>Use of NAGERR_DEFAULT</b></a>
<div class="htmltocitem" id="tocusenagerrdefault"/>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#library3">&#160;2.6.2&#160;<b>Use of the fail parameter</b></a>
<div class="htmltocitem" id="toclibrary3"/>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#usingnagerror">&#160;2.6.3&#160;<b>The NagError structure</b></a>
<div class="htmltocitem" id="tocusingnagerror"/>
</div>
</div>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#threadsafety">&#160;2.7&#160;<b>Thread Safety</b></a>
<div class="htmltocitem" id="tocthreadsafety"/>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#library7">&#160;2.8&#160;<b>Calling the Library from Other Languages</b></a>
<div class="htmltocitem" id="toclibrary7"/>
</div>
</div>
</div>

<div class="htmltoc">
<a class="htmltoc" href="javascript:showLevelb( 'tocdoc');"><span class="htmltocplus" id="tocdocplus">+</span><span class="htmltocminus" id="tocdocminus">&#8722;</span></a>
<a class="htmltoc" href="#doc">&#160;3&#160;<b>Using the Documentation</b></a>
<div class="htmltocitem" id="tocdoc">
<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#doc1">&#160;3.1&#160;<b>Using the Manual</b></a>
<div class="htmltocitem" id="tocdoc1"/>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#doc2">&#160;3.2&#160;<b>Structure of Function Documents</b></a>
<div class="htmltocitem" id="tocdoc2"/>
</div>

<div class="htmltoc">
<a class="htmltoc" href="javascript:showLevelb( 'tocdoc3');"><span class="htmltocplus" id="tocdoc3plus">+</span><span class="htmltocminus" id="tocdoc3minus">&#8722;</span></a>
<a class="htmltoc" href="#doc3">&#160;3.3&#160;<b>Specification of Parameters</b></a>
<div class="htmltocitem" id="tocdoc3">
<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#doc31">&#160;3.3.1&#160;<b>Classification of parameters</b></a>
<div class="htmltocitem" id="tocdoc31"/>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#doc32">&#160;3.3.2&#160;<b>Constraints and suggested values</b></a>
<div class="htmltocitem" id="tocdoc32"/>
</div>
</div>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#doc5">&#160;3.4&#160;<b>Example Programs and Results</b></a>
<div class="htmltocitem" id="tocdoc5"/>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#doc6">&#160;3.5&#160;<b>Summary for New Users</b></a>
<div class="htmltocitem" id="tocdoc6"/>
</div>
</div>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#support">&#160;4&#160;<b>Support from NAG</b></a>
<div class="htmltocitem" id="tocsupport"/>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#further">&#160;5&#160;<b>Background to NAG</b></a>
<div class="htmltocitem" id="tocfurther"/>
</div>

<div class="htmltoc">
<span class="htmltocplus">&#160;&#160;&#160;</span>
<a class="htmltoc" href="#references">&#160;6&#160;<b>References</b></a>
<div class="htmltocitem" id="tocreferences"/>
</div>
</div>
</div>



<h2><a name="libanddoc"/>1&#160;&#160;The Library and its Documentation</h2>




<h3><a name="libanddoc1"/>1.1&#160;&#160;Structure of the Library</h3>

<div class="paramtext">The NAG C Library is a comprehensive collection of <b>functions</b> for the solution of numerical and statistical problems.  The word &#8216;function&#8217; is used to denote &#8216;subroutine&#8217; or &#8216;function&#8217;.</div>
<div class="paramtext">The Library is divided into <b>chapters</b>, each devoted to a branch of numerical analysis or statistics.  Each chapter has a three-character name and a title, 
e.g.,
</div><ul class="listind"><li class="listind"><a class="secref" href="../D01/d01_conts.xml">d01 &#8211; Quadrature</a></li></ul><div class="specialparamtext">
</div>
<div class="paramtext">Exceptionally, Chapters <a class="secref" href="../H/h_conts.xml">h</a> and <a class="secref" href="../S/s_conts.xml">s</a> have one-character names. (The chapters and their names are based on the ACM modified SHARE classification index (see <a class="litref" href="#ref226">ACM (1960&#8211;1976)</a>).)</div>

<div class="paramtext">All documented functions have two names. One is based on the SHARE index classification and consists of a six-character name which begins with the characters of the chapter/subchapter name, for example 
</div><ul class="listind"><li class="listind"><a class="rtnref" href="../C06/c06ebc.xml">c06ebc</a></li></ul><div class="specialparamtext">
</div> 
<div class="paramtext">The letters of this type of function name are always lower case, the second and third characters being digits and the last letter being c. This function name is referred to as the short name. Each function (except the <a class="secref" href="../F06/f06_conts.xml">Linear Algebra Support Functions</a> in Chapter <a class="secref" href="../F16/f16_conts.xml">f16</a>) also has a more meaningful and longer name, for example 
</div><ul class="listind"><li class="listind"><a class="rtnref" href="../C06/c06ebc.xml">nag_fft_hermitian</a></li></ul><div class="specialparamtext"> 
which we refer to as the long name. The long name may be used as an alternative to the short name when calling the function. See Section <a class="secref" href="#usinglongnames">2.3</a> for further details.</div>







<h3><a name="libanddoc2"/>1.2&#160;&#160;Structure of the Documentation</h3>

<div class="paramtext"><b>The NAG C Library Manual</b> is the principal printed form of documentation for the NAG C Library.  It has the same chapter structure as the Library: each chapter of functions in the Library has a corresponding chapter (of the same name) in the Manual.  The chapters occur in alphanumeric order.  General introductory documents are placed in Volume 1 of the Manual.</div>
<div class="paramtext">Each chapter consists of the following documents:
</div><ul class="listind"><li class="listind"><b>Chapter Contents</b>, e.g., Contents &#8211; <a class="secref" href="../D01/d01_conts.xml">d01</a>;</li><li class="listind"><b>Chapter Introduction</b>, e.g., Introduction &#8211; <a class="secref" href="../D01/d01_conts.xml">d01</a>;</li><li class="listind"><b>Function Documents</b>, one for each documented function in the chapter.</li></ul><div class="specialparamtext">
</div>
<div class="paramtext">A function document has the same short name as the function which it describes.  Within each chapter, function documents occur in alphanumeric order. Exceptionally, some chapters (Chapters <a class="secref" href="../F16/f16_conts.xml">f16</a>, <a class="secref" href="../X01/x01_conts.xml">x01</a> and <a class="secref" href="../X02/x02_conts.xml">x02</a>) do not have individual function documents; instead, all the functions are described together in the Chapter Introduction.  </div>
<div class="paramtext">In addition to the full printed Manual, NAG also produces a printed <b>Introductory Guide</b>, which contains all the introductory material from the Manual, together with all the Chapter Contents and Chapter Introductions.</div>




<h3><a name="libanddoc3"/>1.3&#160;&#160;Alternative Forms of Documentation</h3>

<div class="paramtext">NAG also provides machine-based documentation.  Currently NAG provides online documentation in the form of unlinked PDF files accompanied by an HTML index.  Introductory material is provided in both PDF and HTML but the <a class="secref" href="../indexes/kwic/cl_kwic.xml">Keywords in Context</a> and <a class="secref" href="../indexes/gams/cl_gams.xml">GAMS Classification Index</a> are provided in HTML only.  It is anticipated that future releases will provide HTML files (taking advantage of technology that is currently being developed, e.g., MathML) for the full manual and fully linked PDF files for all but the <a class="secref" href="../indexes/kwic/cl_kwic.xml">Keywords in Context</a> and <a class="secref" href="../indexes/gams/cl_gams.xml">GAMS Classification Index</a>.  The most up-to-date version of the online documentation is accessible via the NAG Web site (see Section <a class="secref" href="#support">4</a>).</div>




<h3><a name="libanddoc4"/>1.4&#160;&#160;Marks of the Library</h3>

<div class="paramtext">Periodically a new <b>Mark</b> of the NAG C Library is released: new functions are added, corrections and/or improvements are made to existing functions; occasionally functions are withdrawn if they have been superseded by improved functions.</div>
<div class="paramtext">At each Mark, the documentation of the Library is updated.  You must make sure that your documentation has been updated to the same Mark as the Library software that you are using.</div>
<div class="paramtext">Marks are numbered, e.g., 4, 5, 6.  The current Mark is 
  Mark 7.</div>




<h3><a name="libanddoc5"/>1.5&#160;&#160;Implementations of the Library</h3>

<div class="paramtext">The NAG C Library is available on many different computer systems.  For each distinct system, an <b>implementation</b> of the Library is prepared by NAG, e.g., the Sun Solaris implementation.  The implementation is distributed to sites as one or more tested compiled libararies.</div>
<div class="paramtext">An implementation is usually specific to a range of machines (e.g., the PCs running Windows); it may also be specific to a particular operating system, C compiler, or compiler option (such as threaded mode).</div>
<div class="paramtext">Essentially the same facilities are provided in all implementations of the Library, but, because of differences in arithmetic behaviour and in the compilation system, functions cannot be expected to give identical results on different systems, especially for sensitive numerical problems.</div>
<div class="paramtext">The documentation supports all implementations of the Library, with the help of a few simple conventions, and a small amount of implementation-dependent information, which is published in a separate <b><a class="secref" href="http://www.nag.co.uk/numeric/cl/clinuns.asp">Users' Note</a></b> for each implementation.</div>




<h3><a name="libanddoc6"/>1.6&#160;&#160;Precision of the Library</h3>

<div class="paramtext">The NAG C Library is developed in 

<b>double precision</b> only.</div>







<h3><a name="libanddoc7"/>1.7&#160;&#160;Library Identification</h3>

<div class="paramtext">You must know <b>which implementation</b> and <b>which Mark</b> of the Library you are using or intend to use. 
To find out which implementation, precision and Mark of the Library is available at your site, you can run a program which calls the NAG Library function <a class="rtnref" href="../A00/a00aac.xml">nag_implementation_details (a00aac)</a>. 
This function has no parameters; it simply outputs text to the standard output.
</div>







<h3><a name="libanddoc8"/>1.8&#160;&#160;C Language Standards</h3>

<div class="paramtext">All functions in the NAG C Library conform fully to ANSI C, and functions introduced since Mark 6 take advantage of the <span class="mono">const</span> keyword to allow for safer code which can be more easily optimised.  Although pre-Mark 6 functions have not yet been modified, it is our intention to extend the use of <span class="mono">const</span> and other features of the C99 standard in future releases.</div>





<h2><a name="library"/>2&#160;&#160;Using the Library</h2>




<h3><a name="library1"/>2.1&#160;&#160;General Advice</h3>

<div class="paramtext">A NAG C Library function <b>cannot</b> be guaranteed to return meaningful results irrespective of the data supplied to it.  Care and thought <b>must</b> be exercised in:
</div><ol class="listalpha"><li class="listalpha">formulating the problem;</li><li class="listalpha">programming the use of library functions;</li><li class="listalpha">assessing the significance of the results.</li></ol><div class="specialparamtext">
</div>
<div class="paramtext">The Foreword to the Manual provides some further discussion of points (a) and (c); the remainder of Section <a class="secref" href="#library">2</a> is concerned with (b).</div>




<h3><a name="library2"/>2.2&#160;&#160;Programming Advice</h3>

<div class="paramtext">The NAG C Library and its documentation are designed on the assumption that you know how to write a calling program in C.</div>




<div class="paramtext">When a suitable NAG function has been selected, the function must be called from the C Library via a suitable user-written C program, the calling program. This Manual assumes that the user has sufficient knowledge of the C programming language to be able to write such a program. Each C Library function document contains an example of a suitable calling program (see Section <a class="secref" href="#doc2">3.2</a>).</div> 
<div class="paramtext">When writing a calling program, a number of environmental features common to all such NAG programs must be observed in addition to specific features which are relevant to the particular NAG function being called. These features are discussed below; the user should refer to the above example calling program while studying the description of these features. Users are also recommended to pay particular attention to the specification of the function parameters, array sizes and array indices.
</div>


<h4><a name="usingCenviron"/>2.2.1&#160;&#160;The NAG C environment</h4>

<div class="paramtext">The environment for the NAG C Library is defined in a number of include files; a list is given in Section <a class="secref" href="#usingheader">2.2.1.6</a>.  The most important of the header files is <span class="mono">&lt;nag.h&gt;</span>, which must be included in any program that calls a NAG C Library function and must precede any other NAG header file.</div>
<div class="paramtext">These include files are normally located in the standard directory for C include files.  The exact location is installation dependent; please see the <b><a class="secref" href="http://www.nag.co.uk/numeric/cl/clinuns.asp">Users' Note</a></b> or other local documentation.</div>
<div class="paramtext">The file <span class="mono">nag.h</span> defines data types and error codes used in the NAG C Library together with a number of macros used in example programs.  File <span class="mono">nag.h</span> also contains the definitions for the input/output and string handling functions <span class="mono">Vscanf</span>, <span class="mono">Vprintf</span>, <span class="mono">Vfprintf</span>, <span class="mono">Vsprintf</span>, <span class="mono">Vstrcpy</span> which are the C functions <span class="mono">scanf</span>, <span class="mono">printf</span>, etc., cast to void.</div>
<div class="paramtext">The user may also need to include the header file <span class="mono">nag_stdlib.h</span> in the calling program; see Section <a class="secref" href="#usingheader">2.2.1.6</a>.</div>




<h5><a name="usingdatatypes"/>2.2.1.1&#160;&#160;NAG data types</h5>

<div class="paramtext"><b>Integer</b></div>
<div class="paramtext">This data type is used for almost all integer parameters to NAG C Library functions.  It is normally defined to be <span class="mono">long</span>.</div>
<div class="paramtext"><b>Boolean</b></div>
<div class="paramtext">This data type is used for all parameters that take a true or false value.  If <b>TRUE</b> and <b>FALSE</b> have not previously been defined, then the following definitions are used:
</div><pre class="verbatim">#define TRUE 1#define FALSE 0</pre><div class="specialparamtext">
</div>
<div class="paramtext"><b>Complex</b></div>
<div class="paramtext">This data type is a structure defined for use with complex numbers:
</div><pre class="verbatim"> typedef struct {double re, im;} Complex;</pre><div class="specialparamtext">
</div>
<div class="paramtext"><b>Pointer</b></div>
<div class="paramtext">This data type represents a generic pointer and is defined as <span class="mono">void *</span>.</div>
<div class="paramtext"><b>Nag_User</b></div>
<div class="paramtext">This data type is a structure containing a generic pointer used for communicating information between a user defined function and the user's calling program, where the user defined function is supplied as an argument to the NAG function.  This avoids the necessity of using global variables for such communication.  A brief example of use (taken from Chapter <a class="secref" href="../D02/d02_conts.xml">d02</a>) is given below:

</div><div><a href="../../examples/vrb/essint5.vrb">Brief example of use</a></div><div class="specialparamtext"/>
<div class="paramtext"><b>Enumeration Types</b></div>
<div class="paramtext">A number of enumerated types are defined in <span class="mono">&lt;nag_types.h&gt;</span> for use in calls to various NAG C Library functions.  Users must use these enumerated types in their calling programs.</div>
<div class="paramtext"><b>Other structure types</b></div>
<div class="paramtext">A number of structures have been defined to facilitate calls to NAG functions.  The components of a structure that are relevant to a call to a NAG function are described in the corresponding function document.  A complete specification of a NAG defined structure can be found in the NAG C Library header file <span class="mono">nag_types.h</span> included in the distribution materials.  For futher details please contact NAG.</div>




<h5><a name="usingmemory"/>2.2.1.2&#160;&#160;Memory management in the Library</h5>

<div class="paramtext">Memory is frequently dynamically allocated within NAG C Library functions.  All requests for memory are checked for success or failure.  In the unlikely event of failure occurring the Library function returns or terminates with the error state <b>NE_ALLOC_FAIL</b> (details of error handling in the Library are given in Section <a class="secref" href="#usingerrorhand">2.6</a>).</div>
<div class="paramtext">The macros <span class="mono">NAG_ALLOC</span> and <span class="mono">NAG_FREE</span> are defined to select suitable memory management functions for the NAG C Library. <span class="mono">NAG_ALLOC</span> has two arguments; the first specifies the number of elements to be allocated while the second specifies the type of element.  The statement
</div><pre class="verbatim">p = NAG_ALLOC(n, double);</pre><div class="specialparamtext">
</div>
<div class="paramtext">allocates <span class="mono">n</span> elements of memory of type <span class="mono">double</span> to <span class="mono">p</span>, a pointer to <span class="mono">double</span>.</div>
<div class="paramtext"><span class="mono">NAG_FREE</span> frees memory allocated by <span class="mono">NAG_ALLOC</span>; its single argument is the pointer which specifies the memory to be deallocated.  The statement
</div><pre class="verbatim">NAG_FREE(p);</pre><div class="specialparamtext">
</div>
<div class="paramtext">deallocates memory pointed to by <span class="mono">p</span>.</div>
<div class="paramtext">These macros are defined in the header file <span class="mono">nag_stdlib.h</span> which must be included if these macros are used in the calling program. <span class="mono">NAG_FREE</span> must be used to free memory allocated and returned from a NAG function.  If memory is allocated using <span class="mono">NAG_ALLOC</span> for whatever reason, it must be freed using <span class="mono">NAG_FREE</span>.  For an illustration of its use, see Section <a class="secref" href="../D01/d01asc.xml#examtext">9.1</a> of the document for nag_1d_quad_inf_wt_trig (d01asc).</div>




<h5><a name="usingNagOrder"/>2.2.1.3&#160;&#160;The Nag_Order parameter</h5>

<div class="paramtext">Different programming languages lay out two-dimensional data in memory in different ways.  The C language treats a two-dimensional array as a single block of memory arranged in rows, the so called &#8216;row-major&#8217; ordering.  Some other languages, notably Fortran 77, arrange two-dimensional arrays by column (&#8216;column-major&#8217; ordering).  Commencing at Mark 7, those functions in the C Library that deal with two-dimensional arrays and where it is sensible to do so, have an extra parameter, called order, which allows the user to specify that their data is arranged in rows (by setting order to Nag_RowMajor) or in columns (by setting order to Nag_ColMajor).  This is particularly useful if the NAG C Library is being called from a language which uses the column-major ordering or if you wish to call a function from a language which supports column-major ordering.</div>




<h5><a name="usingarrayrefs"/>2.2.1.4&#160;&#160;Array references</h5>

<div class="paramtext">In C it is possible to declare a two-dimensional variable using notation of the form:
</div><pre class="verbatim"> double a[dim1][dim2];</pre><div class="specialparamtext">
When this variable is a parameter to a function, it is effectively treated by the compiler as a pointer, <span class="mono">*a</span>, of type <span class="mono">double</span> with an allocated memory of <span class="mono">dim1*dim2</span> on the stack.  The address of an element of this array, say <span class="mono">a[3][5]</span> is then an explicit address computed to be <span class="mono">*(a+3*dim2+5)</span>, since C stores data in row-major order.  The C pre-processor allows a succinct notation for computing this explicit address by using a macro definition:
</div><table><tr><td width="85%"><span class="mono">#define A(I,J) A[I*dim2+J]</span></td><td width="15%" align="right">[1]<a name="vrb1"/></td></tr></table><div class="specialparamtext">
Alternatively it is possible for a user to allocate memory explicitly (on the heap) to a pointer of type <span class="mono">double *</span>, using the form:
</div><table><tr><td width="85%"><span class="mono">a=(double *)malloc((size_t)(dim1*dim2*sizeof(double));</span></td><td width="15%" align="right">[2]<a name="vrb2"/></td></tr></table><div class="specialparamtext">
The <math xmlns="http://www.w3.org/1998/Math/MathML" xmlns:dsi="http://www.w3.org/1999/xlink"><mi>i</mi><mi>j</mi></math>th element of this array is then indexed using the pointer
notation <span class="mono">*(a+i*dim2+j)</span> or by using the array notation <span class="mono">a[i*dim2+j]</span>; or by using <span class="mono">A(I,J)</span> assuming the macro [<a class="verbatimref" href="#vrb1">1</a>] is already defined.</div>
<div class="paramtext">If the data is to be stored using column-major ordering and we have declared an array variable as
</div><pre class="verbatim"> double a[dim1][dim2];</pre><div class="specialparamtext">
then the <math xmlns="http://www.w3.org/1998/Math/MathML" xmlns:dsi="http://www.w3.org/1999/xlink"><mi>i</mi><mi>j</mi></math>th element is effectively transposed.  That is, the element <span class="mono">a[i][j]</span> under row-major ordering is the element <span class="mono">a[j][i]</span> under column-major ordering.</div>
<div class="paramtext">As another alternative the user may choose to malloc the required memory as in [<a class="verbatimref" href="#vrb2">2</a>] above.  In this case, the <math xmlns="http://www.w3.org/1998/Math/MathML" xmlns:dsi="http://www.w3.org/1999/xlink"><mi>i</mi><mi>j</mi></math>th element of this array is indexed using the pointer notation <span class="mono">*(a+j*dim1+i)</span>; or by using the array notation <span class="mono">a[j*dim1+i]</span>; or by using <span class="mono">A(I,J)</span> if the macro is defined as
</div><table><tr><td width="85%"><span class="mono">#define A(I,J) A[J*dim1+I]</span></td><td width="15%" align="right">[3]<a name="vrb3"/></td></tr></table><div class="specialparamtext">
Note the difference in definition between [<a class="verbatimref" href="#vrb1">1</a>] and [<a class="verbatimref" href="#vrb3">3</a>] above.</div>
<div class="paramtext">In order to simplify the documentation, we refer to array elements using the macro definitions above.  Further, we note that in the pre-processor directive [<a class="verbatimref" href="#vrb1">1</a>] and [<a class="verbatimref" href="#vrb3">3</a>], the critical dimension is either <span class="mono">dim2</span> if the row-major ordering is used or <span class="mono">dim1</span> if column-major ordering is used.  We designate either <span class="mono">dim2</span> or <span class="mono">dim1</span> as the principal dimension depending on the storage ordering scheme.  The principal dimension can be thought of as a stride which must be taken to traverse either a row or a column depending on the order parameter.</div>
<div class="paramtext">We illustrate these concepts using two examples.  In the first example, memory is allocated while in the second example memory is declared.  In both examples, row or column modes are demarcated using the pre-processor macro <span class="mono">NAG_ROW_MAJOR</span>.</div>



<div class="paramtext"><b>Example 1</b>
</div><div><a href="../../examples/vrb/essint18.vrb">Example 1</a></div><div class="specialparamtext"/>
<div class="paramtext"><b>Example 2</b>
</div><div><a href="../../examples/vrb/essint19.vrb">Example 2</a></div><div class="specialparamtext"/>




<h5><a name="usinginternal"/>2.2.1.5&#160;&#160;Internal data structures in the NAG C Library</h5>

<div class="paramtext">For efficiency, and wherever possible, the NAG C Library is designed to make use of the Basic Linear Algebra Subprograms (BLAS), a suite of low-level functions tuned by many computer manufacturers for their particular hardware.  Since the BLAS are specified in Fortran, and therefore use the column-major storage order, the NAG C Library also uses this scheme internally, for new functions introduced at Mark 7 wherever it is practical.  Thus any two-dimensional arrays provided by the user may be re-ordered on entry and/or on exit from the NAG functions, as appropriate.  It is therefore slightly more efficient to use the column-major ordering; however, except for very large data sets, the effect is negligible in practice.</div>




<h5><a name="usingheader"/>2.2.1.6&#160;&#160;Chapter header files</h5>

<div class="paramtext">Chapter header files contain the function declarations for the NAG C Library with ANSI function prototyping.  The appropriate chapter header file must be included for each NAG function called by your program.  For example, to call the function <a class="rtnref" href="../C06/c06ecc.xml">nag_fft_complex (c06ecc)</a> the chapter header file <span class="mono">nagc06.h</span> must be included as
</div><pre class="verbatim"> #include &lt;nagc06.h&gt;</pre><div class="specialparamtext">
</div>
<div class="paramtext">The naming convention is to prefix the first three characters of the function name in lower case by <span class="mono">nag</span> and use <span class="mono">.h</span> as the postfix as in normal C practice, except that all functions in Chapter <a class="secref" href="../S/s_conts.xml">s</a> use the header file <span class="mono">nags.h</span>.</div>
<div class="paramtext"><b>(a) Header files intended for inclusion by the user within calling programs to the NAG C Library</b></div>
<div class="paramtext"><span class="mono">&lt;nag.h&gt;</span> defines the basic environment for use of the NAG C Library.  This header file must be included in each calling program to the NAG C Library and must precede all other header files that are included.  This must be followed by one or more of the following chapter header files. 
</div><div><table style="align:center" cellpadding="4">






<tbody>
<tr>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;naga00.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;naga02.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagc02.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagc05.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagc06.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagd01.h&gt;</span></td>
</tr><tr>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagd02.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagd03.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagd06.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nage01.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nage02.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nage04.h&gt;</span></td>
</tr><tr>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagf01.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagf02.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagf03.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagf04.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagf06.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagf07.h&gt;</span></td>
</tr><tr>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagf08.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagf11.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagg01.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagg02.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagg03.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagg04.h&gt;</span></td>
</tr><tr>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagg05.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagg07.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagg08.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagg10.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagg11.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagg12.h&gt;</span></td>
</tr><tr>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagg13.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagh02.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagh03.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagm01.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nags.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagx01.h&gt;</span></td>
</tr><tr>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagx02.h&gt;</span></td>
<td class="libdoc" align="left" valign="top"><span class="mono">&lt;nagx04.h&gt;</span></td>
</tr>
</tbody>
</table></div><div class="specialparamtext"/>
<div class="paramtext"><span class="mono">&lt;nag_stdlib.h&gt;</span> defines <span class="mono">EXIT_SUCCESS</span> and <span class="mono">EXIT_FAILURE</span> and the memory allocation macro <br/><span class="mono">NAG_ALLOC</span> and <span class="mono">NAG_FREE</span>.  This header file must be included by the user if the NAG definitions of <span class="mono">EXIT_SUCCESS</span>, <span class="mono">EXIT_FAILURE</span>, <span class="mono">NAG_ALLOC</span> and <span class="mono">NAG_FREE</span>, as used in the example programs, are required.</div>
<div class="paramtext"><b>(b) The following three header files are included by</b> <span class="mono">nag.h</span> <b>(the user does not need to supply a specific statement to include them)</b></div>
<div class="paramtext"><span class="mono">&lt;nag_types.h&gt;</span> defines the NAG types used in the Library.</div>
<div class="paramtext"><span class="mono">&lt;nag_errlist.h&gt;</span> defines the NAG error codes and messages used in the Library.</div>
<div class="paramtext"><span class="mono">&lt;nag_names.h&gt;</span> maps the NAG long names to short names.</div> 
 




<h3><a name="usinglongnames"/>2.3&#160;&#160;Use of NAG Long Names</h3>

<div class="paramtext">The long names defined in the header file <span class="mono">nag_names.h</span> are #defines.  Users should note that the short function names given in upper case in this file are also #defines and therefore their corresponding long names will not require a terminating pair of brackets.  These declarations are to be found in <span class="mono">nagx01.h</span> and <span class="mono">nagx02.h</span>.  As the header file <span class="mono">nag_names.h</span> is already included via <span class="mono">nag.h</span>, users need not include <span class="mono">nag_names.h</span> in their calling programs.</div>




<h3><a name="usingio"/>2.4&#160;&#160;Input/Output</h3>

<div class="paramtext">NAG C Library functions output all error and warning messages to the C standard error stream <span class="mono">stderr</span>. Chapters <a class="secref" href="../E04/e04_conts.xml">e04</a>, <a class="secref" href="../G02/g02_conts.xml">g02</a> and <a class="secref" href="../G13/g13_conts.xml">g13</a> will optionally output results to the C standard output stream <span class="mono">stdout</span> or to an alternative user-specified file.  A number of functions in the <a class="secref" href="../E04/e04_conts.xml">Minimizing or Maximizing a Function</a> (<a class="secref" href="../E04/e04_conts.xml">e04</a>) and <a class="secref" href="../H/h_conts.xml">Operations Research</a> (Chapter <a class="secref" href="../H/h_conts.xml">h</a>) areas read input from external files.</div>




<h3><a name="usingauxiliary"/>2.5&#160;&#160;Auxiliary Functions</h3>

<div class="paramtext">In addition to the documented functions available to the user, the NAG C Library contains a much larger number of auxiliary functions.  Users do not normally need to concern themselves with these functions, as they will automatically be called as required by the user-callable function selected by the user.  The function declarations of these auxiliary functions can be found in the relevant chapter header files together with the user-callable function declarations.</div>




<h3><a name="usingerrorhand"/>2.6&#160;&#160;NAG Error Handling and the fail Parameter</h3>

<div class="paramtext">All functions that have error exits have a parameter that allows the user control over the printing of error messages when an error is detected.  There is a further option which allows users either to continue running their program, having returned from the NAG function, or to stop with either an exit statement or an abort within the NAG function.  The different ways of using these error handling facilities are described below.</div>
<div class="paramtext">Note that in some implementations, the Library is linked with the vendor library containing LAPACK functions and the <a class="secref" href="../F07/f07_conts.xml">f07</a> and <a class="secref" href="../F08/f08_conts.xml">f08</a> function interfaces, where appropriate, act as wrappers to the corresponding vendor LAPACK functions.  In this case, the <b>fail</b> parameter passed through the <a class="secref" href="../F07/f07_conts.xml">f07</a> and <a class="secref" href="../F08/f08_conts.xml">f08</a> interfaces does not have full control over the printing of error messages; nor does it determine whether or not control is returned to the calling program when an error is detected.</div>



<h4><a name="usenagerrdefault"/>2.6.1&#160;&#160;Use of <span class="mono">NAGERR_DEFAULT</span></h4>

<div class="paramtext">The simplest method of using the error handling facility is to put <span class="mono">NAGERR_DEFAULT</span> in place of the <b>fail</b> parameter in calls to the NAG C functions.  If an error is detected the appropriate NAG error message is output on <span class="mono">stderr</span> and the program is stopped by the use of <span class="mono">abort</span> (in some implementations the program may be stopped with <span class="mono">exit</span> rather than <span class="mono">abort</span>).  This method of use is illustrated in the above example program for <a class="rtnref" href="../F02/f02agc.xml">nag_real_eigensystem (f02agc)</a>. <span class="mono">NAGERR_DEFAULT</span> is defined in <span class="mono">&lt;nag.h&gt;</span> as <span class="mono">(NagError&#160;*)0</span>.</div>





<h4><a name="library3"/>2.6.2&#160;&#160;Use of the fail parameter</h4>

<div class="paramtext">The two remaining ways of using the NAG error handling facility both involve defining the <b>fail</b> parameter in the calling program.  The <b>fail</b> parameter is of type <span class="mono">NagError</span> which is a structure defined in <br/><span class="mono">&lt;nag_types.h&gt;</span> as:
</div><div><a href="../../examples/vrb/essint11.vrb">Components in the NagError Structure</a></div><div class="specialparamtext"/>
<div class="paramtext">where the symbol <span class="mono">NAG_ERROR_BUF_LEN</span> is normally defined to be 512.</div>
<div class="paramtext">This structure will contain the NAG error code and message on return from a call to a NAG C Library function.  The NAG error codes and associated NAG error messages are defined in <span class="mono">&lt;nag_errlist.h&gt;</span>.  A detailed description of the individual members of this structure is given below (see Section <a class="secref" href="#usingnagerror">2.6.3</a>).</div>
<div class="paramtext">The NAG error parameter <b>fail</b> is declared in the calling program as:
</div><pre class="verbatim"> NagError fail;</pre><div class="specialparamtext">
</div>
<div class="paramtext">The address of the parameter is then passed to the NAG C function being called.  All members of the structure must be initialised before passing the parameter to the called function, even though a member may not actually be required by the user.  It is recommended that the NAG defined macro <span class="mono">INIT_FAIL</span> be used for this purpose.  The <span class="mono">SET_FAIL</span> macros is also available.  This sets <b>fail.print</b> to <b>TRUE</b>.</div>
<div class="paramtext"><b>(a) Use of the fail parameter with the print member set to <b>TRUE</b></b></div>
<div class="paramtext">If the user requires that the NAG error message be printed when an error is found, but that the called function should return control to the calling program, then the <b>fail</b> parameter must be declared with all members initialised and the <b>print</b> member set to <b>TRUE</b>.  Use of the NAG-defined macro <span class="mono">SET_FAIL</span> with the statement <span class="mono">SET_FAIL(fail);</span> performs the appropriate assignments.  Alternatively the initialisation could be done by declaring the <b>fail</b> parameter with <b>static</b> (see the example declaration above) and then setting <b>fail.print</b> to <b>TRUE</b>.</div>
<div class="paramtext">If no error occurs, <b>fail.code</b> will contain the error code <b>NE_NOERROR</b> on return from the called function.  However, if an error is found, the appropriate NAG error message will be output on <span class="mono">stderr</span> before returning control to the calling program; <b>fail.code</b> will contain the relevant NAG error code.  The user must ensure that the calling program tests the <b>code</b> member of the <b>fail</b> parameter on return from the NAG C function; the user may then choose whether to exit the calling program or continue.  See the example program for <a class="rtnref" href="../F02/f02wec.xml">nag_real_svd (f02wec)</a> for such a case.  The option of continuing may be advantageous if the results being returned are of some value even when an error has been detected.  In the case of <a class="rtnref" href="../F02/f02wec.xml">nag_real_svd (f02wec)</a> the code could be altered to allow the program to continue if the specific error code of <b>NE_QR_NOT_CONV</b> occurs, as in such a case useful partial results are returned (see the routine document for <a class="rtnref" href="../F02/f02wec.xml">nag_real_svd (f02wec)</a>).</div>
<div class="paramtext"><b>(b) Use of the fail parameter with the print member set to <b>FALSE</b></b></div>
<div class="paramtext">If the user does not wish the NAG error messages to be printed automatically when an error is found then the <b>fail</b> parameter must be declared with all members initialised and the <b>print</b> member set to <b>FALSE</b>.  Use of <b>static</b> in the declaration of <b>fail</b> will automatically leave the <b>print</b> member as <b>FALSE</b> as will the use of <span class="mono">INIT_FAIL(fail)</span>.</div>
<div class="paramtext">This method is suitable for users who wish to produce their own error messages rather than use the NAG C Library versions.  Alternative error messages may be coded directly into the calling program or be produced via a user-written error-handling function which is assigned to the <b>handler</b> member of the <b>fail</b> parameter (see the description of the <span class="mono">handler</span> member below).</div>




<h4><a name="usingnagerror"/>2.6.3&#160;&#160;The <span class="mono">NagError</span> structure</h4>

<div class="paramtext">The individual members of the <span class="mono">NagError</span> structure are described in full below.</div>
<div class="paramtext"><span class="mono">code</span></div>
<div class="paramtext">On successful exit, <span class="mono">code</span> contains the NAG error code <b>NE_NOERROR</b>; if an error or warning has been detected, then <span class="mono">code</span> contains the specific error or warning code.  Error codes are prefixed with <b>NE_</b> whereas warning codes have the prefix <b>NW_</b>.</div>
<div class="paramtext"><span class="mono">print</span></div>
<div class="paramtext"><span class="mono">print</span> must be set before calling any NAG C Library function with a <b>fail</b> parameter.  It should be set to <b>TRUE</b> if the NAG error message is to be printed, otherwise <b>FALSE</b>.  It is not changed by the NAG C Library function.</div>
<div class="paramtext"><span class="mono">message</span></div>
<div class="paramtext">On successful exit the array <span class="mono">message</span> contains the character string <span class="mono">"NE_NOERROR:\n&#160;&#160;&#160;No error"</span>.  If an error has been detected, then <span class="mono">message</span> contains the error message text, whether or not this is printed.</div>
<div class="paramtext"><span class="mono">errnum</span></div>
<div class="paramtext">On successful exit, <span class="mono">errnum</span> is unchanged.  For certain error or warning exits <span class="mono">errnum</span> will contain a value specifying additional information concerning the error.  For example if a vector is supplied incorrectly, then <span class="mono">errnum</span> may specify which component of the vector is wrong.  Cases where <span class="mono">errnum</span> returns information are described in the relevant function documents.</div>
<div class="paramtext"><span class="mono">handler</span></div>
<div class="paramtext"><span class="mono">handler</span> must be set to <span class="mono">0</span> if control is to be returned to the calling function after an error has been detected.  Otherwise it must point to a user-supplied error-handling function.  An example of the ANSI C declaration of a user-supplied error function (here called <span class="mono">errhan</span>) is:
</div><pre class="verbatim"> void errhan(const char *string, int code, const char *name)</pre><div class="specialparamtext">
where <span class="mono">string</span> contains the NAG error message on input, <span class="mono">code</span> is the NAG error code and <span class="mono">name</span> is the short name of the NAG C Library function which detected the error.  If <span class="mono">print</span> (see above) is <b>TRUE</b>, then the NAG error message is printed before the user-supplied error handler is called.  If the user-supplied error handler returns control, then the NAG error handler will return control to the calling program; otherwise the user-supplied error handler may abort, exit or longjmp.</div>
<div class="paramtext">An elementary example of where this feature might be used is if it is preferred to print error messages on <span class="mono">stdout</span> rather than the default <span class="mono">stderr</span>.  In this case <span class="mono">errhan</span> could be defined as:
</div><div><a href="../../examples/vrb/essint12.vrb">errhan</a></div><div class="specialparamtext"/>











<h3><a name="threadsafety"/>2.7&#160;&#160;Thread Safety</h3>


<div class="paramtext">The NAG C Library is thread safe by design; all communication between functions is via argument lists, and, with the exception of Chapter <a class="secref" href="../G05/g05_conts.xml">g05</a> (<a class="secref" href="../G05/g05_conts.xml">Random Number Generators</a>), no use of read and write static storage is made.</div>
<div class="paramtext">In Chapter <a class="secref" href="../G05/g05_conts.xml">g05</a>, for efficiency, 
functions in the range <a class="secref" href="../G05/g05_conts.xml">g05</a>c&#8211;<a class="secref" href="../G05/g05_conts.xml">g05</a>h use 
global variables 
 
internally for communication.  Simultaneous access to these global variables by multiple threads has been guarded against using thread mutexes.  For UNIX machines, these mutexes come from the POSIX standard thread library (<a class="litref" href="#ref721">ANSI/IEEE POSIX (1995)</a>), also known as pthreads.  For PC implementations of the NAG C Library, the mutexes are those implemented by the Microsoft thread package.</div>
<div class="paramtext">The NAG C Library is therefore thread safe with respect to the thread package against which it was built, either pthreads or Microsoft threads.  Some older UNIX architectures did not have implementations of pthreads available, and implementations of the NAG C Library on such architectures could not therefore be made thread safe - though of course on such machines it would not be possible to write a POSIX multi-threaded program anyway.  Current implementations of the NAG C Library that are NOT thread safe are:</div>
<div class="paramtext">CLSG506DA</div>
<div class="paramtext">Although the NAG C Library is thread safe, sometimes care must be taken to use it in a thread-safe way.  In particular, this is the case with Chapter <a class="secref" href="../C05/c05_conts.xml">c05</a> (<a class="secref" href="../C05/c05_conts.xml">Roots of One or More Transcendental Equations</a>), and <br/>Chapter <a class="secref" href="../D01/d01_conts.xml">d01</a> (<a class="secref" href="../D01/d01_conts.xml">Quadrature</a>).  In these chapters, the solution of a problem usually involves a user-supplied function being passed to the NAG Library function, the user-supplied C function being called to evaluate the mathematical function which is the object of the problem.  It is sometimes the case that the user would like the evaluation function to communicate with the main program, to pass relevant information involved in the function evaluation.  The simplest way to do this is to use global variables for communication, but these global variables render the resulting code unsuitable for use by multiple threads simultaneously.</div>
<div class="paramtext">Using pthread or Microsoft thread package functionality, it is perfectly possible for the user to avoid this problem by writing code which passes thread-specific data between main program and evaluation function.  As an alternative to this method, however, where relevant we have provided alternative versions of the NAG Library functions.  These alternative functions have an extra argument which can be used for safe communication of additional data if it is required.  Please see documentation for <a class="rtnref" href="../D01/d01ajc.xml">nag_1d_quad_gen (d01ajc)</a> and <a class="rtnref" href="../D01/d01sjc.xml">nag_1d_quad_gen_1 (d01sjc)</a> for examples.</div>
<div class="paramtext">Finally we recommend that when using the C Library error mechanism, the output is switched off (by setting <math xmlns="http://www.w3.org/1998/Math/MathML" xmlns:dsi="http://www.w3.org/1999/xlink"><mi mathvariant="bold">fail.print</mi> <mo>=</mo> <mi mathvariant="bold">FALSE</mi></math>).</div>
<div class="paramtext">Note that in some implementations, the Library is linked with one or more vendor libraries to provide, for example, efficient BLAS routines.  NAG cannot guarantee that any such vendor library is thread safe.</div>




<h3><a name="library7"/>2.8&#160;&#160;Calling the Library from Other Languages</h3>

<div class="paramtext">In general the NAG C Library can be called from other computer languages (such as C++, Java and Visual Basic) provided that appropriate mappings exist between their data types.</div>









<h2><a name="doc"/>3&#160;&#160;Using the Documentation</h2>




<h3><a name="doc1"/>3.1&#160;&#160;Using the Manual</h3>

<div class="paramtext">The Manual is designed to serve the following functions:
</div><ul class="listind"><li class="listind">to give background information about different areas of numerical and statistical computation;</li><li class="listind">to advise on the choice of the most suitable NAG Library function or functions to solve a particular problem;</li><li class="listind">to give all the information needed to call a NAG Library function correctly from a C program, and to assess the results.</li></ul><div class="specialparamtext">
</div>
<div class="paramtext">At the beginning of the Manual are some general introductory documents which provide some background and additional information.  The <a class="secref" href="../genint/libconts.xml">Library Contents</a> (a structured list of functions in the Library, by chapter) may help you to find the chapter, and possibly the function, which you need to solve your problem.  Online documentation provides you with a fully linked HTML <a class="secref" href="../indexes/kwic/cl_kwic.xml">Keywords in Context</a> (a keyword index to chapters and functions) and <a class="secref" href="../indexes/gams/cl_gams.xml">GAMS Classification Index</a> (a list of NAG functions classified according to the GAMS scheme).</div>
<div class="paramtext">Having found a likely chapter or function, you should read the corresponding <b>Chapter Introduction,</b> which gives background information about that area of numerical computation, and recommendations on the choice of a function, including indexes, tables or decision trees.</div>
<div class="paramtext">When you have chosen a function, you must consult the <b>function document</b>.  Each function document is essentially self-contained (it may, however, contain references to related documents).  It includes a description of the method, detailed specifications of each parameter, explanations of each error exit, remarks on accuracy, and (in most cases) an example program to illustrate the use of the function.</div>




<h3><a name="doc2"/>3.2&#160;&#160;Structure of Function Documents</h3>


<div class="paramtext">Note that at Mark 7 a new typesetting scheme was used to generate documentation.  If you have a Manual which contains pre-Mark 7 function documents, you will find that it contains older documents which differ in style, although they contain essentially the same information.</div>
<div class="paramtext">All function documents have the same structure, consisting of nine numbered sections:
</div><table><tr>
<td style="width:NaNem;" valign="top"><b>1.</b></td>
<td valign="top"><b>Purpose</b></td>
</tr><tr>
<td style="width:NaNem;" valign="top"><b>2.</b></td>
<td valign="top"><b>Specification</b></td>
</tr><tr>
<td style="width:NaNem;" valign="top"><b>3.</b></td>
<td valign="top"><b>Description</b></td>
</tr><tr>
<td style="width:NaNem;" valign="top"><b>4.</b></td>
<td valign="top"><b>References</b></td>
</tr><tr>
<td style="width:NaNem;" valign="top"><b>5.</b></td>
<td valign="top"><b>Parameters</b> (see Section <a class="secref" href="#doc3">3.3</a> below)</td>
</tr><tr>
<td style="width:NaNem;" valign="top"><b>6.</b></td>
<td valign="top"><b>Error Indicators and Warnings</b></td>
</tr><tr>
<td style="width:NaNem;" valign="top"><b>7.</b></td>
<td valign="top"><b>Accuracy</b></td>
</tr><tr>
<td style="width:NaNem;" valign="top"><b>8.</b></td>
<td valign="top"><b>Further Comments</b></td>
</tr><tr>
<td style="width:NaNem;" valign="top"><b>9.</b></td>
<td valign="top"><b>Example</b> (see Section <a class="secref" href="#doc5">3.4</a> below)</td>
</tr></table><div class="specialparamtext">
</div>
<div class="paramtext">In a few documents (notably Chapter <a class="secref" href="../E04/e04_conts.xml">e04</a>) there are a further three sections:
</div><table><tr>
<td style="width:NaNem;" valign="top"><b>10.</b></td>
<td valign="top"><b>Algorithmic Details</b></td>
</tr><tr>
<td style="width:NaNem;" valign="top"><b>11.</b></td>
<td valign="top"><b>Optional Parameters</b></td>
</tr><tr>
<td style="width:NaNem;" valign="top"><b>12.</b></td>
<td valign="top"><b>Description of Monitoring Information</b></td>
</tr></table><div class="specialparamtext">
</div>




<h3><a name="doc3"/>3.3&#160;&#160;Specification of Parameters</h3>

<div class="paramtext">Section 5 of each function document contains the specification of the parameters, in the order of their appearance in the parameter list.</div>


<h4><a name="doc31"/>3.3.1&#160;&#160;Classification of parameters</h4>

<div class="paramtext">Parameters are classified as follows.</div>
<div class="paramtext"><span class="italic">Input</span>: you must assign values to these parameters on or before entry to the function, and these values are unchanged on exit from the function.</div>
<div class="paramtext"><span class="italic">Output</span>: you need not assign values to these parameters on or before entry to the function; the function may assign values to them.</div>
<div class="paramtext"><span class="italic">Input/Output</span>: you must assign values to these parameters on or before entry to the function, and the function may then change these values.</div>

<div class="paramtext"><span class="italic">External Procedure</span>: a subfunction or function which must be supplied (e.g., to evaluate an integrand or to print intermediate output).  Usually it must be supplied as part of your calling program, in which case its specification includes full details of its parameter list and specifications of its parameters (all enclosed in a box).  Its parameters are classified in the same way as those of the Library function, but because you must write the procedure rather than call it, the significance of the classification is different.
</div><ul class="listind"><li class="listind"><span class="italic">Input</span>: values may be supplied on entry.</li><li class="listind"><span class="italic">Output</span>: you may or must assign values to these parameters before exit from your procedure.</li><li class="listind"><span class="italic">Input/Output</span>: values may be supplied on entry, and you may or must assign values to them before exit from your procedure.</li></ul><div class="specialparamtext">
</div>







<h4><a name="doc32"/>3.3.2&#160;&#160;Constraints and suggested values</h4>

<div class="paramtext">The word &#8216;<span class="italic">Constraint</span>:&#8217; or &#8216;<span class="italic">Constraints</span>:&#8217; in the specification of an <span class="italic">Input</span> parameter introduces a statement of the range of valid values for that parameter, e.g.,
</div><ul class="listind"><li class="listind"><span class="italic">Constraint</span>: <math xmlns="http://www.w3.org/1998/Math/MathML" xmlns:dsi="http://www.w3.org/1999/xlink"><mi mathvariant="bold">n</mi> <mo>&gt;</mo> <mn mathvariant="normal">0</mn></math>.</li></ul><div class="specialparamtext">
</div>
<div class="paramtext">If the function is called with an invalid value for the parameter
(e.g., <math xmlns="http://www.w3.org/1998/Math/MathML" xmlns:dsi="http://www.w3.org/1999/xlink"><mi mathvariant="bold">n</mi> <mo>=</mo> <mn mathvariant="normal">0</mn></math>), the function will usually take an error exit.</div>


<div class="paramtext">The phrase &#8216;<span class="italic">Suggested Value</span>:&#8217; introduces a suggestion for a reasonable initial setting for an <span class="italic">Input</span> parameter (e.g., accuracy or maximum number of iterations) in case you are unsure what value to use; you should be prepared to use a different setting if the suggested value turns out to be unsuitable for your problem.</div>









<h3><a name="doc5"/>3.4&#160;&#160;Example Programs and Results</h3>

<div class="paramtext">The <b>example program</b> in Section 9 of each function document illustrates a simple call of the function.  The programs are designed so that they can fairly easily be modified, and so serve as the basis for a simple program to solve your problem.</div>



<div class="paramtext">For each implementation of the Library, NAG distributes the example programs in machine-readable form, with all necessary modifications already applied.  Many sites make the programs accessible to you in this form.  They may also be obtained directly from the NAG Web site.</div>
<div class="paramtext">Note that the results from running the example programs may not be identical in all implementations, and may not agree exactly with the results which are printed in the Manual and which were obtained from a double precision implementation (with approximately 16 digits of precision).</div>
<div class="paramtext">The <a class="secref" href="http://www.nag.co.uk/numeric/cl/clinuns.asp">Users' Note</a> for your implementation will mention any special changes which need to be made to the example programs, and any significant differences in the results.</div>




<h3><a name="doc6"/>3.5&#160;&#160;Summary for New Users</h3>
 <div class="paramtext">If you are unfamiliar with this Library and are thinking of using a function from it, please follow these instructions: </div><ol class="listalpha"><li class="listalpha">read the whole of this <b>Essential Introduction</b>;</li><li class="listalpha">consult the <a class="secref" href="../genint/libconts.xml">Library Contents</a> list to select an appropriate chapter or function;</li><li class="listalpha">or search through the <b><a class="secref" href="../indexes/kwic/cl_kwic.xml">Keywords in Context</a></b>, <b><a class="secref" href="../indexes/gams/cl_gams.xml">GAMS Classification Index</a></b>;</li><li class="listalpha">read the relevant <b>Chapter Introduction</b>;</li><li class="listalpha">choose a function, and read the <b>function document</b>. If the function does not after all meet your needs, return to step (b), (c) or (d);</li><li class="listalpha">read the <b><a class="secref" href="http://www.nag.co.uk/numeric/cl/clinuns.asp">Users' Note</a></b> for your implementation;</li><li class="listalpha">consult local documentation, which should be provided by your local support staff, about access to the this Library on your computing system;</li><li class="listalpha">obtain an online copy of the example program for the particular function of interest and experiment with it.</li></ol><div class="specialparamtext"/><div class="paramtext">You should now be in a position to include a call to the function in a program, and to attempt to compile and run it. You may of course need to refer back to the relevant documentation in the case of difficulties, for advice on assessment of results, and so on.</div><div class="paramtext">As you become familiar with the Library, some of steps (a) to (h) can be omitted, but it is always essential to: </div><ul class="listind"><li class="listind">be familiar with the Chapter Introduction;</li><li class="listind">read the function document;</li><li class="listind">be aware of the <b><a class="secref" href="http://www.nag.co.uk/numeric/cl/clinuns.asp">Users' Note</a></b> for your implementation.</li></ul><div class="specialparamtext"/> 






<h2><a name="support"/>4&#160;&#160;Support from NAG</h2>
<div class="paramtext"><b>(a) Contact with NAG</b></div><div class="paramtext">Queries concerning this library should be directed initially to your local Advisory Service.  If you have difficulty in making contact locally, you can contact NAG directly.</div><div class="paramtext"><b>(b) NAG Response Centres</b></div><div class="paramtext">The NAG Response Centres are available for general enquiries from all users and also for technical queries from users with Support.</div><div class="paramtext">The Response Centres are open during office hours, but contact is possible by fax, email and telephone (answering machine) at all times.  Please see the <a class="secref" href="http://www.nag.co.uk/numeric/cl/clinuns.asp">Users' Note</a> or the NAG web sites for contact details.</div><div class="paramtext">When contacting one of our Response Centres it helps us to deal with you query quickly if you can quote your NAG user reference and NAG product code.</div><div class="paramtext"><b>(c) NAG Web Site</b></div><div class="paramtext">The NAG web site is an information service providing items of interest to users and prospective users of NAG products and services.  The information is regularly updated and reviewed, and includes implementation availability, descriptions of products, down-loadable software and technical reports.  NAG web sites can be accessed at </div><ul class="listind"><li class="listind"><span class="mono">http://www.nag.co.uk</span> or</li><li class="listind"><span class="mono">http://www.nag.com</span> or</li><li class="listind"><span class="mono">http://www.naggmbh.de</span> or</li><li class="listind"><span class="mono">http://www.nag-j.co.jp</span></li></ul><div class="specialparamtext"/>



<h2><a name="further"/>5&#160;&#160;Background to NAG</h2>

<div class="paramtext">Various aspects of the design and development of the NAG Library, and NAG's technical policies and organisation are given in <a class="litref" href="#ref227">Ford (1982)</a>, <a class="litref" href="#ref228">Ford <i>et al.</i> (1979)</a>, <a class="litref" href="#ref229">Ford  and Pool (1984)</a>, and <a class="litref" href="#ref230">Hague <i>et al.</i> (1982)</a>.</div>







<h2><a name="references"/>6&#160;&#160;References</h2>

<div class="paramtext">
<p><a name="ref226"/>ACM  (1960&#8211;1976) Collected algorithms from ACM index by subject to algorithms </p>
<p><a name="ref546"/>ANSI  (1966) USA standard Fortran <i>Publication X3.9</i> American National Standards Institute </p>
<p><a name="ref232"/>ANSI  (1978) American National Standard Fortran <i>Publication X3.9</i> American National Standards Institute </p>
<p><a name="ref721"/>ANSI/IEEE POSIX  (1995) POSIX Standard Thread Library ANSI/IEEE POSIX 1003.1c:1995 </p>
<p><a name="ref227"/>Ford B (1982) Transportable numerical software <i>Lecture Notes in Computer Science</i> <b>142</b> 128&#8211;140 Springer&#8211;Verlag </p>
<p><a name="ref228"/>Ford B, Bentley J, Du Croz J J and Hague S J (1979) The NAG Library &#8216;machine&#8217; <i>Softw. Pract. Exper.</i> <b>9 (1)</b> 65&#8211;72 </p>
<p><a name="ref229"/>Ford B and Pool J C T (1984) The evolving NAG Library service <i>Sources and Development of Mathematical Software</i> (ed W Cowell) 375&#8211;397 Prentice&#8211;Hall </p>
<p><a name="ref230"/>Hague S J, Nugent S M and Ford B (1982) Computer-based documentation for the NAG Library <i>Lecture Notes in Computer Science</i> <b>142</b> 91&#8211;127 Springer&#8211;Verlag </p>
<p><a name="ref643"/>ISO  (1997) ISO Fortran 95 programming language (ISO/IEC 1539-1:1997) </p>
<p><a name="ref701"/>ISO/IEC  (1990) Information technology &#8211; Programming Language C <i>Current C Language Standard</i> ISO/IEC 9899:1990 </p>
<p><a name="ref702"/>Kernighan B W and Ritchie D M (1988) <i>The C Programming Language</i> (2nd Edition) Prentice&#8211;Hall </p>
</div>


<hr/><div><a href="../../pdf/genint/essint.pdf">Essential Introduction (pdf version)</a></div><div><a href="../mark7.xml">NAG C Library Contents</a></div>
<div><hr/>
  &#169; The Numerical Algorithms Group Ltd, Oxford, UK. 2004
  </div></body></html>
