1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-07-22 18:57:40 +02:00
qmckl/qmckl_context.html

1862 lines
95 KiB
HTML

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2021-03-23 Tue 21:25 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Context</title>
<meta name="generator" content="Org mode" />
<meta name="author" content="TREX CoE" />
<style type="text/css">
<!--/*--><![CDATA[/*><!--*/
.title { text-align: center;
margin-bottom: .2em; }
.subtitle { text-align: center;
font-size: medium;
font-weight: bold;
margin-top:0; }
.todo { font-family: monospace; color: red; }
.done { font-family: monospace; color: green; }
.priority { font-family: monospace; color: orange; }
.tag { background-color: #eee; font-family: monospace;
padding: 2px; font-size: 80%; font-weight: normal; }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
.org-right { margin-left: auto; margin-right: 0px; text-align: right; }
.org-left { margin-left: 0px; margin-right: auto; text-align: left; }
.org-center { margin-left: auto; margin-right: auto; text-align: center; }
.underline { text-decoration: underline; }
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
p.verse { margin-left: 3%; }
pre {
border: 1px solid #ccc;
box-shadow: 3px 3px 3px #eee;
padding: 8pt;
font-family: monospace;
overflow: auto;
margin: 1.2em;
}
pre.src {
position: relative;
overflow: visible;
padding-top: 1.2em;
}
pre.src:before {
display: none;
position: absolute;
background-color: white;
top: -10px;
right: 10px;
padding: 3px;
border: 1px solid black;
}
pre.src:hover:before { display: inline;}
/* Languages per Org manual */
pre.src-asymptote:before { content: 'Asymptote'; }
pre.src-awk:before { content: 'Awk'; }
pre.src-C:before { content: 'C'; }
/* pre.src-C++ doesn't work in CSS */
pre.src-clojure:before { content: 'Clojure'; }
pre.src-css:before { content: 'CSS'; }
pre.src-D:before { content: 'D'; }
pre.src-ditaa:before { content: 'ditaa'; }
pre.src-dot:before { content: 'Graphviz'; }
pre.src-calc:before { content: 'Emacs Calc'; }
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
pre.src-fortran:before { content: 'Fortran'; }
pre.src-gnuplot:before { content: 'gnuplot'; }
pre.src-haskell:before { content: 'Haskell'; }
pre.src-hledger:before { content: 'hledger'; }
pre.src-java:before { content: 'Java'; }
pre.src-js:before { content: 'Javascript'; }
pre.src-latex:before { content: 'LaTeX'; }
pre.src-ledger:before { content: 'Ledger'; }
pre.src-lisp:before { content: 'Lisp'; }
pre.src-lilypond:before { content: 'Lilypond'; }
pre.src-lua:before { content: 'Lua'; }
pre.src-matlab:before { content: 'MATLAB'; }
pre.src-mscgen:before { content: 'Mscgen'; }
pre.src-ocaml:before { content: 'Objective Caml'; }
pre.src-octave:before { content: 'Octave'; }
pre.src-org:before { content: 'Org mode'; }
pre.src-oz:before { content: 'OZ'; }
pre.src-plantuml:before { content: 'Plantuml'; }
pre.src-processing:before { content: 'Processing.js'; }
pre.src-python:before { content: 'Python'; }
pre.src-R:before { content: 'R'; }
pre.src-ruby:before { content: 'Ruby'; }
pre.src-sass:before { content: 'Sass'; }
pre.src-scheme:before { content: 'Scheme'; }
pre.src-screen:before { content: 'Gnu Screen'; }
pre.src-sed:before { content: 'Sed'; }
pre.src-sh:before { content: 'shell'; }
pre.src-sql:before { content: 'SQL'; }
pre.src-sqlite:before { content: 'SQLite'; }
/* additional languages in org.el's org-babel-load-languages alist */
pre.src-forth:before { content: 'Forth'; }
pre.src-io:before { content: 'IO'; }
pre.src-J:before { content: 'J'; }
pre.src-makefile:before { content: 'Makefile'; }
pre.src-maxima:before { content: 'Maxima'; }
pre.src-perl:before { content: 'Perl'; }
pre.src-picolisp:before { content: 'Pico Lisp'; }
pre.src-scala:before { content: 'Scala'; }
pre.src-shell:before { content: 'Shell Script'; }
pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
/* additional language identifiers per "defun org-babel-execute"
in ob-*.el */
pre.src-cpp:before { content: 'C++'; }
pre.src-abc:before { content: 'ABC'; }
pre.src-coq:before { content: 'Coq'; }
pre.src-groovy:before { content: 'Groovy'; }
/* additional language identifiers from org-babel-shell-names in
ob-shell.el: ob-shell is the only babel language using a lambda to put
the execution function name together. */
pre.src-bash:before { content: 'bash'; }
pre.src-csh:before { content: 'csh'; }
pre.src-ash:before { content: 'ash'; }
pre.src-dash:before { content: 'dash'; }
pre.src-ksh:before { content: 'ksh'; }
pre.src-mksh:before { content: 'mksh'; }
pre.src-posh:before { content: 'posh'; }
/* Additional Emacs modes also supported by the LaTeX listings package */
pre.src-ada:before { content: 'Ada'; }
pre.src-asm:before { content: 'Assembler'; }
pre.src-caml:before { content: 'Caml'; }
pre.src-delphi:before { content: 'Delphi'; }
pre.src-html:before { content: 'HTML'; }
pre.src-idl:before { content: 'IDL'; }
pre.src-mercury:before { content: 'Mercury'; }
pre.src-metapost:before { content: 'MetaPost'; }
pre.src-modula-2:before { content: 'Modula-2'; }
pre.src-pascal:before { content: 'Pascal'; }
pre.src-ps:before { content: 'PostScript'; }
pre.src-prolog:before { content: 'Prolog'; }
pre.src-simula:before { content: 'Simula'; }
pre.src-tcl:before { content: 'tcl'; }
pre.src-tex:before { content: 'TeX'; }
pre.src-plain-tex:before { content: 'Plain TeX'; }
pre.src-verilog:before { content: 'Verilog'; }
pre.src-vhdl:before { content: 'VHDL'; }
pre.src-xml:before { content: 'XML'; }
pre.src-nxml:before { content: 'XML'; }
/* add a generic configuration mode; LaTeX export needs an additional
(add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
pre.src-conf:before { content: 'Configuration File'; }
table { border-collapse:collapse; }
caption.t-above { caption-side: top; }
caption.t-bottom { caption-side: bottom; }
td, th { vertical-align:top; }
th.org-right { text-align: center; }
th.org-left { text-align: center; }
th.org-center { text-align: center; }
td.org-right { text-align: right; }
td.org-left { text-align: left; }
td.org-center { text-align: center; }
dt { font-weight: bold; }
.footpara { display: inline; }
.footdef { margin-bottom: 1em; }
.figure { padding: 1em; }
.figure p { text-align: center; }
.inlinetask {
padding: 10px;
border: 2px solid gray;
margin: 10px;
background: #ffffcc;
}
#org-div-home-and-up
{ text-align: right; font-size: 70%; white-space: nowrap; }
textarea { overflow-x: auto; }
.linenr { font-size: smaller }
.code-highlighted { background-color: #ffff00; }
.org-info-js_info-navigation { border-style: none; }
#org-info-js_console-label
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
.org-info-js_search-highlight
{ background-color: #ffff00; color: #000000; font-weight: bold; }
.org-svg { width: 90%; }
/*]]>*/-->
</style>
<link rel="stylesheet" title="Standard" href="qmckl.css" type="text/css" />
<script type="text/javascript" src="org-info.js">
/**
*
* @source: org-info.js
*
* @licstart The following is the entire license notice for the
* JavaScript code in org-info.js.
*
* Copyright (C) 2012-2019 Free Software Foundation, Inc.
*
*
* The JavaScript code in this tag is free software: you can
* redistribute it and/or modify it under the terms of the GNU
* General Public License (GNU GPL) as published by the Free Software
* Foundation, either version 3 of the License, or (at your option)
* any later version. The code is distributed WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
*
* As additional permission under GNU GPL version 3 section 7, you
* may distribute non-source (e.g., minimized or compacted) forms of
* that code without the copy of the GNU GPL normally required by
* section 4, provided you include this license notice and a URL
* through which recipients can access the Corresponding Source.
*
* @licend The above is the entire license notice
* for the JavaScript code in org-info.js.
*
*/
</script>
<script type="text/javascript">
/*
@licstart The following is the entire license notice for the
JavaScript code in this tag.
Copyright (C) 2012-2019 Free Software Foundation, Inc.
The JavaScript code in this tag is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
@licend The above is the entire license notice
for the JavaScript code in this tag.
*/
<!--/*--><![CDATA[/*><!--*/
org_html_manager.set("TOC_DEPTH", "4");
org_html_manager.set("LINK_HOME", "index.html");
org_html_manager.set("LINK_UP", "");
org_html_manager.set("LOCAL_TOC", "1");
org_html_manager.set("VIEW_BUTTONS", "0");
org_html_manager.set("MOUSE_HINT", "underline");
org_html_manager.set("FIXED_TOC", "0");
org_html_manager.set("TOC", "1");
org_html_manager.set("VIEW", "info");
org_html_manager.setup(); // activate after the parameters are set
/*]]>*///-->
</script>
<script type="text/javascript">
/*
@licstart The following is the entire license notice for the
JavaScript code in this tag.
Copyright (C) 2012-2019 Free Software Foundation, Inc.
The JavaScript code in this tag is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
@licend The above is the entire license notice
for the JavaScript code in this tag.
*/
<!--/*--><![CDATA[/*><!--*/
function CodeHighlightOn(elem, id)
{
var target = document.getElementById(id);
if(null != target) {
elem.cacheClassElem = elem.className;
elem.cacheClassTarget = target.className;
target.className = "code-highlighted";
elem.className = "code-highlighted";
}
}
function CodeHighlightOff(elem, id)
{
var target = document.getElementById(id);
if(elem.cacheClassElem)
elem.className = elem.cacheClassElem;
if(elem.cacheClassTarget)
target.className = elem.cacheClassTarget;
}
/*]]>*///-->
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
displayAlign: "center",
displayIndent: "0em",
"HTML-CSS": { scale: 100,
linebreaks: { automatic: "false" },
webFont: "TeX"
},
SVG: {scale: 100,
linebreaks: { automatic: "false" },
font: "TeX"},
NativeMML: {scale: 100},
TeX: { equationNumbers: {autoNumber: "AMS"},
MultLineWidth: "85%",
TagSide: "right",
TagIndent: ".8em"
}
});
</script>
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML"></script>
</head>
<body>
<div id="org-div-home-and-up">
<a accesskey="h" href=""> UP </a>
|
<a accesskey="H" href="index.html"> HOME </a>
</div><div id="content">
<h1 class="title">Context</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#org1f8bb26">1. Context handling</a>
<ul>
<li><a href="#org1bd1546">1.1. Data structure</a></li>
<li><a href="#org547611c">1.2. Creation</a></li>
<li><a href="#orgab98e7e">1.3. Access to the previous context</a></li>
<li><a href="#orgce17ec2">1.4. Locking</a></li>
<li><a href="#org54cd706">1.5. Copy</a></li>
<li><a href="#org96d5107">1.6. Destroy</a></li>
</ul>
</li>
<li><a href="#org7dfa449">2. Memory allocation handling</a>
<ul>
<li><a href="#org7f68145">2.1. Data structure</a></li>
<li><a href="#orgfe2faa6">2.2. Append memory</a></li>
<li><a href="#org6673d49">2.3. Remove memory</a></li>
</ul>
</li>
<li><a href="#org8ced40f">3. Error handling</a>
<ul>
<li><a href="#orge0001cb">3.1. Data structure</a></li>
<li><a href="#org73c6984">3.2. Updating errors</a></li>
</ul>
</li>
<li><a href="#orgb5bac03">4. Control of the numerical precision</a>
<ul>
<li><a href="#org14623c0">4.1. Precision</a></li>
<li><a href="#org63c3be2">4.2. Range</a></li>
<li><a href="#org7e8d441">4.3. Helper functions</a></li>
</ul>
</li>
<li><a href="#org726b951">5. <span class="todo TODO">TODO</span> Basis set</a>
<ul>
<li><a href="#org8ce7135">5.1. Data structure</a></li>
<li><a href="#org03947a0">5.2. <code>qmckl_context_update_ao_basis</code></a>
<ul>
<li><a href="#orgc421adc">5.2.1. Source</a></li>
<li><a href="#orge6b3490">5.2.2. Fortran interface</a></li>
<li><a href="#org2e8acd6">5.2.3. <span class="todo TODO">TODO</span> Test</a></li>
</ul>
</li>
<li><a href="#org8a4e904">5.3. <code>qmckl_context_set_ao_basis</code></a>
<ul>
<li><a href="#orgf7bcf78">5.3.1. Source</a></li>
<li><a href="#org35cd041">5.3.2. Fortran interface</a></li>
<li><a href="#org970a631">5.3.3. <span class="todo TODO">TODO</span> Test</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<p>
The context variable is a handle for the state of the library,
and is stored in a data structure which can't be seen outside of
the library. To simplify compatibility with other languages, the
pointer to the internal data structure is converted into a 64-bit
signed integer, defined in the <code>qmckl_context</code> type.
A value of <code>QMCKL_NULL_CONTEXT</code> for the context is equivalent to a
<code>NULL</code> pointer.
</p>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #a020f0;">typedef</span> <span style="color: #228b22;">int64_t</span> <span style="color: #228b22;">qmckl_context</span> ;
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_NULL_CONTEXT</span> (qmckl_context) 0
</pre>
</div>
<div id="outline-container-org1f8bb26" class="outline-2">
<h2 id="org1f8bb26"><span class="section-number-2">1</span> Context handling</h2>
<div class="outline-text-2" id="text-1">
<p>
The context appears as an immutable data structure: modifying a
context returns a new context with the modifications. Therefore, it
is necessary to store a pointer to the old version of context so
that it can be freed when necessary.
Note that we also provide a possibility to mutate the context, but
this should be done with caution, only when it is justified.
</p>
<p>
By convention, in this file <code>context</code> is a <code>qmckl_context</code> variable
and <code>ctx</code> is a <code>qmckl_context_struct*</code> pointer.
</p>
</div>
<div id="outline-container-org1bd1546" class="outline-3">
<h3 id="org1bd1546"><span class="section-number-3">1.1</span> Data structure</h3>
<div class="outline-text-3" id="text-1-1">
<p>
The main data structure contains pointers to other data structures,
containing the data specific to each given domain, such that the
modified contexts don't need to duplicate the data but only the
pointers.
</p>
<div class="org-src-container">
<pre class="src src-c" id="org529e80c"><span style="color: #a020f0;">typedef</span> <span style="color: #a020f0;">struct</span> <span style="color: #228b22;">qmckl_context_struct</span> {
/* <span style="color: #b22222;">Pointer to the previous context, before modification </span>*/
<span style="color: #a020f0;">struct</span> <span style="color: #228b22;">qmckl_context_struct</span> * <span style="color: #a0522d;">prev</span>;
/* <span style="color: #b22222;">Molecular system </span>*/
<span style="color: #228b22;">qmckl_ao_basis_struct</span> * <span style="color: #a0522d;">ao_basis</span>;
/* <span style="color: #b22222;">To be implemented:</span>
<span style="color: #b22222;"> qmckl_nucleus_struct * nucleus;</span>
<span style="color: #b22222;"> qmckl_electron_struct * electron;</span>
<span style="color: #b22222;"> qmckl_mo_struct * mo;</span>
<span style="color: #b22222;"> qmckl_determinant_struct * det;</span>
<span style="color: #b22222;"> </span>*/
/* <span style="color: #b22222;">Numerical precision </span>*/
<span style="color: #228b22;">qmckl_precision_struct</span> * <span style="color: #a0522d;">fp</span>;
/* <span style="color: #b22222;">Error handling </span>*/
<span style="color: #228b22;">qmckl_error_struct</span> * <span style="color: #a0522d;">error</span>;
/* <span style="color: #b22222;">Memory allocation </span>*/
<span style="color: #228b22;">qmckl_memory_struct</span> * <span style="color: #a0522d;">alloc</span>;
/* <span style="color: #b22222;">Thread lock </span>*/
<span style="color: #228b22;">int</span> <span style="color: #a0522d;">lock_count</span>;
<span style="color: #228b22;">pthread_mutex_t</span> <span style="color: #a0522d;">mutex</span>;
/* <span style="color: #b22222;">Validity checking </span>*/
<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">tag</span>;
} <span style="color: #228b22;">qmckl_context_struct</span>;
</pre>
</div>
<p>
A tag is used internally to check if the memory domain pointed
by a pointer is a valid context. This allows to check that even if
the pointer associated with a context is non-null, we can still
verify that it points to the expected data structure.
</p>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">VALID_TAG</span> 0xBEEFFACE
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">INVALID_TAG</span> 0xDEADBEEF
</pre>
</div>
<p>
The <code>qmckl_context_check</code> function checks if the domain pointed by
the pointer is a valid context. It returns the input <code>qmckl_context</code>
if the context is valid, <code>QMCKL_NULL_CONTEXT</code> otherwise.
</p>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_check</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>) ;
</pre>
</div>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_check</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>) {
<span style="color: #a020f0;">if</span> (context == QMCKL_NULL_CONTEXT)
<span style="color: #a020f0;">return</span> QMCKL_NULL_CONTEXT;
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
/* <span style="color: #b22222;">Try to access memory </span>*/
<span style="color: #a020f0;">if</span> (ctx-&gt;tag != VALID_TAG) {
<span style="color: #a020f0;">return</span> QMCKL_NULL_CONTEXT;
}
<span style="color: #a020f0;">return</span> context;
}
</pre>
</div>
</div>
</div>
<div id="outline-container-org547611c" class="outline-3">
<h3 id="org547611c"><span class="section-number-3">1.2</span> Creation</h3>
<div class="outline-text-3" id="text-1-2">
<p>
To create a new context, <code>qmckl_context_create()</code> should be used.
</p>
<ul class="org-ul">
<li>Upon success, it returns a pointer to a new context with the <code>qmckl_context</code> type</li>
<li>It returns <code>QMCKL_NULL_CONTEXT</code> upon failure to allocate the internal data structure</li>
</ul>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_create</span>() {
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> =
(<span style="color: #228b22;">qmckl_context_struct</span>*) <span style="color: #0000ff;">qmckl_malloc</span> (QMCKL_NULL_CONTEXT, <span style="color: #a020f0;">sizeof</span>(<span style="color: #228b22;">qmckl_context_struct</span>));
<span style="color: #a020f0;">if</span> (ctx == <span style="color: #008b8b;">NULL</span>) {
<span style="color: #a020f0;">return</span> QMCKL_NULL_CONTEXT;
}
/* <span style="color: #b22222;">Set all pointers to NULL </span>*/
memset(ctx, 0, <span style="color: #a020f0;">sizeof</span>(qmckl_context_struct));
/* <span style="color: #b22222;">Initialize lock </span>*/
init_lock(&amp;(ctx-&gt;mutex));
/* <span style="color: #b22222;">Initialize data </span>*/
ctx-&gt;tag = VALID_TAG;
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span> = (<span style="color: #228b22;">qmckl_context</span>) ctx;
assert ( qmckl_context_check(context) != QMCKL_NULL_CONTEXT );
<span style="color: #a020f0;">return</span> context;
}
</pre>
</div>
</div>
</div>
<div id="outline-container-orgab98e7e" class="outline-3">
<h3 id="orgab98e7e"><span class="section-number-3">1.3</span> Access to the previous context</h3>
<div class="outline-text-3" id="text-1-3">
<p>
<code>qmckl_context_previous</code> returns the previous context. It returns
<code>QMCKL_NULL_CONTEXT</code> for the initial context and for the <code>NULL</code> context.
</p>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_previous</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>) {
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">checked_context</span> = qmckl_context_check(context);
<span style="color: #a020f0;">if</span> (checked_context == (<span style="color: #228b22;">qmckl_context</span>) 0) {
<span style="color: #a020f0;">return</span> (<span style="color: #228b22;">qmckl_context</span>) 0;
}
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) checked_context;
<span style="color: #a020f0;">return</span> qmckl_context_check((<span style="color: #228b22;">qmckl_context</span>) ctx-&gt;prev);
}
</pre>
</div>
</div>
</div>
<div id="outline-container-orgce17ec2" class="outline-3">
<h3 id="orgce17ec2"><span class="section-number-3">1.4</span> Locking</h3>
<div class="outline-text-3" id="text-1-4">
<p>
For thread safety, the context may be locked/unlocked. The lock is
initialized with the <code>PTHREAD_MUTEX_RECURSIVE</code> attribute, and the
number of times the thread has locked it is saved in the
<code>lock_count</code> attribute.
</p>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #228b22;">void</span> <span style="color: #0000ff;">init_lock</span>(<span style="color: #228b22;">pthread_mutex_t</span>* <span style="color: #a0522d;">mutex</span>) {
<span style="color: #228b22;">pthread_mutexattr_t</span> <span style="color: #a0522d;">attr</span>;
<span style="color: #228b22;">int</span> <span style="color: #a0522d;">rc</span>;
rc = pthread_mutexattr_init(&amp;attr);
assert (rc == 0);
(<span style="color: #228b22;">void</span>) pthread_mutexattr_settype(&amp;attr, PTHREAD_MUTEX_RECURSIVE);
rc = pthread_mutex_init ( mutex, &amp;attr);
assert (rc == 0);
(<span style="color: #228b22;">void</span>)pthread_mutexattr_destroy(&amp;attr);
}
<span style="color: #228b22;">void</span> <span style="color: #0000ff;">qmckl_lock</span>(<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>) {
<span style="color: #a020f0;">if</span> (context == QMCKL_NULL_CONTEXT)
<span style="color: #a020f0;">return</span> ;
<span style="color: #228b22;">qmckl_context_struct</span> *<span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
errno = 0;
<span style="color: #228b22;">int</span> <span style="color: #a0522d;">rc</span> = pthread_mutex_lock( &amp;(ctx-&gt;mutex) );
<span style="color: #a020f0;">if</span> (rc != 0) {
fprintf(stderr, <span style="color: #8b2252;">"qmckl_lock:%s\n"</span>, strerror(rc) );
fflush(stderr);
}
assert (rc == 0);
ctx-&gt;lock_count++;
/*
<span style="color: #b22222;"> printf(" lock : %d\n", ctx-&gt;lock_count);</span>
*/
}
<span style="color: #228b22;">void</span> <span style="color: #0000ff;">qmckl_unlock</span>(<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>) {
<span style="color: #228b22;">qmckl_context_struct</span> *<span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
<span style="color: #228b22;">int</span> <span style="color: #a0522d;">rc</span> = pthread_mutex_unlock( &amp;(ctx-&gt;mutex) );
<span style="color: #a020f0;">if</span> (rc != 0) {
fprintf(stderr, <span style="color: #8b2252;">"qmckl_unlock:%s\n"</span>, strerror(rc) );
fflush(stderr);
}
assert (rc == 0);
ctx-&gt;lock_count--;
/*
<span style="color: #b22222;"> printf("unlock : %d\n", ctx-&gt;lock_count);</span>
*/
}
</pre>
</div>
</div>
</div>
<div id="outline-container-org54cd706" class="outline-3">
<h3 id="org54cd706"><span class="section-number-3">1.5</span> Copy</h3>
<div class="outline-text-3" id="text-1-5">
<p>
<code>qmckl_context_copy</code> makes a shallow copy of a context. It returns
<code>QMCKL_NULL_CONTEXT</code> upon failure.
</p>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_copy</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>) {
qmckl_lock(context);
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">checked_context</span> = qmckl_context_check(context);
<span style="color: #a020f0;">if</span> (checked_context == QMCKL_NULL_CONTEXT) {
qmckl_unlock(context);
<span style="color: #a020f0;">return</span> QMCKL_NULL_CONTEXT;
}
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">old_ctx</span> =
(<span style="color: #228b22;">qmckl_context_struct</span>*) checked_context;
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">new_ctx</span> =
(<span style="color: #228b22;">qmckl_context_struct</span>*) <span style="color: #0000ff;">qmckl_malloc</span> (context, <span style="color: #a020f0;">sizeof</span>(<span style="color: #228b22;">qmckl_context_struct</span>));
<span style="color: #a020f0;">if</span> (new_ctx == <span style="color: #008b8b;">NULL</span>) {
qmckl_unlock(context);
<span style="color: #a020f0;">return</span> QMCKL_NULL_CONTEXT;
}
/* <span style="color: #b22222;">Copy the old context on the new one </span>*/
memcpy(new_ctx, old_ctx, <span style="color: #a020f0;">sizeof</span>(qmckl_context_struct));
new_ctx-&gt;prev = old_ctx;
qmckl_unlock( (<span style="color: #228b22;">qmckl_context</span>) new_ctx );
qmckl_unlock( (<span style="color: #228b22;">qmckl_context</span>) old_ctx );
<span style="color: #a020f0;">return</span> (<span style="color: #228b22;">qmckl_context</span>) new_ctx;
}
</pre>
</div>
</div>
</div>
<div id="outline-container-org96d5107" class="outline-3">
<h3 id="org96d5107"><span class="section-number-3">1.6</span> Destroy</h3>
<div class="outline-text-3" id="text-1-6">
<p>
The context is destroyed with <code>qmckl_context_destroy</code>, leaving the ancestors untouched.
It frees the context, and returns the previous context.
</p>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_destroy</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>) {
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">checked_context</span> = qmckl_context_check(context);
<span style="color: #a020f0;">if</span> (checked_context == QMCKL_NULL_CONTEXT) <span style="color: #a020f0;">return</span> QMCKL_NULL_CONTEXT;
qmckl_lock(context);
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
assert (ctx != <span style="color: #008b8b;">NULL</span>); /* <span style="color: #b22222;">Shouldn't be true because the context is valid </span>*/
qmckl_unlock(context);
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">prev_context</span> = (<span style="color: #228b22;">qmckl_context</span>) ctx-&gt;prev;
<span style="color: #a020f0;">if</span> (prev_context == QMCKL_NULL_CONTEXT) {
/* <span style="color: #b22222;">This is the first context, free all memory. </span>*/
<span style="color: #a020f0;">struct</span> <span style="color: #228b22;">qmckl_memory_struct</span>* <span style="color: #a0522d;">new</span> = <span style="color: #008b8b;">NULL</span>;
<span style="color: #a020f0;">while</span> (ctx-&gt;alloc != <span style="color: #008b8b;">NULL</span>) {
new = ctx-&gt;alloc-&gt;next;
free(ctx-&gt;alloc-&gt;pointer);
ctx-&gt;alloc-&gt;pointer = <span style="color: #008b8b;">NULL</span>;
free(ctx-&gt;alloc);
ctx-&gt;alloc = new;
}
}
<span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #a0522d;">rc</span>;
rc = qmckl_context_remove_memory(context,ctx);
/*
<span style="color: #b22222;"> assert (rc == QMCKL_SUCCESS);</span>
<span style="color: #b22222;"> </span>*/
ctx-&gt;tag = INVALID_TAG;
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int</span> <span style="color: #a0522d;">rc_destroy</span> = pthread_mutex_destroy( &amp;(ctx-&gt;mutex) );
<span style="color: #a020f0;">if</span> (rc_destroy != 0) {
fprintf(stderr, <span style="color: #8b2252;">"qmckl_context_destroy: %s (count = %d)\n"</span>, strerror(rc_destroy), ctx-&gt;lock_count);
abort();
}
rc = qmckl_free(context,ctx);
assert (rc == QMCKL_SUCCESS);
//<span style="color: #b22222;">memset(ctx, 0, sizeof(qmckl_context_struct));</span>
<span style="color: #a020f0;">return</span> prev_context;
}
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-org7dfa449" class="outline-2">
<h2 id="org7dfa449"><span class="section-number-2">2</span> Memory allocation handling</h2>
<div class="outline-text-2" id="text-2">
</div>
<div id="outline-container-org7f68145" class="outline-3">
<h3 id="org7f68145"><span class="section-number-3">2.1</span> Data structure</h3>
<div class="outline-text-3" id="text-2-1">
<p>
Pointers to all allocated memory domains are stored in the context,
in a linked list. The size is also stored, to enable the
computation of the amount of currently used memory by the library.
</p>
<div class="org-src-container">
<pre class="src src-c" id="org44c9f15"><span style="color: #a020f0;">typedef</span> <span style="color: #a020f0;">struct</span> <span style="color: #228b22;">qmckl_memory_struct</span> {
<span style="color: #a020f0;">struct</span> <span style="color: #228b22;">qmckl_memory_struct</span> * <span style="color: #a0522d;">next</span> ;
<span style="color: #228b22;">void</span> * <span style="color: #a0522d;">pointer</span> ;
<span style="color: #228b22;">size_t</span> <span style="color: #a0522d;">size</span> ;
} <span style="color: #228b22;">qmckl_memory_struct</span>;
</pre>
</div>
</div>
</div>
<div id="outline-container-orgfe2faa6" class="outline-3">
<h3 id="orgfe2faa6"><span class="section-number-3">2.2</span> Append memory</h3>
<div class="outline-text-3" id="text-2-2">
<p>
The following function, called in <a href="./qmckl_memory.html"><code>qmckl_memory.c</code></a>, appends a new
pair (pointer, size) to the data structure.
It is forbidden to pass the <code>NULL</code> pointer, or a zero size.
If the context is <code>QMCKL_NULL_CONTEXT</code>, the function returns
immediately with <code>QMCKL_SUCCESS</code>.
</p>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_context_append_memory</span>(<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>,
<span style="color: #228b22;">void</span>* <span style="color: #a0522d;">pointer</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">size_t</span> <span style="color: #a0522d;">size</span>) {
assert (pointer != <span style="color: #008b8b;">NULL</span>);
assert (size &gt; 0L);
qmckl_lock(context);
<span style="color: #a020f0;">if</span> ( qmckl_context_check(context) == QMCKL_NULL_CONTEXT ) {
qmckl_unlock(context);
<span style="color: #a020f0;">return</span> QMCKL_SUCCESS;
}
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
<span style="color: #228b22;">qmckl_memory_struct</span>* <span style="color: #a0522d;">new_alloc</span> = (<span style="color: #228b22;">qmckl_memory_struct</span>*)
malloc(<span style="color: #a020f0;">sizeof</span>(qmckl_memory_struct));
<span style="color: #a020f0;">if</span> (new_alloc == <span style="color: #008b8b;">NULL</span>) {
qmckl_unlock(context);
<span style="color: #a020f0;">return</span> QMCKL_ALLOCATION_FAILED;
}
new_alloc-&gt;next = <span style="color: #008b8b;">NULL</span>;
new_alloc-&gt;pointer = pointer;
new_alloc-&gt;size = size;
<span style="color: #228b22;">qmckl_memory_struct</span>* <span style="color: #a0522d;">alloc</span> = ctx-&gt;alloc;
<span style="color: #a020f0;">if</span> (alloc == <span style="color: #008b8b;">NULL</span>) {
ctx-&gt;alloc = new_alloc;
} <span style="color: #a020f0;">else</span> {
<span style="color: #a020f0;">while</span> (alloc != <span style="color: #008b8b;">NULL</span>) {
alloc = alloc-&gt;next;
}
alloc-&gt;next = new_alloc;
}
qmckl_unlock(context);
<span style="color: #a020f0;">return</span> QMCKL_SUCCESS;
}
</pre>
</div>
</div>
</div>
<div id="outline-container-org6673d49" class="outline-3">
<h3 id="org6673d49"><span class="section-number-3">2.3</span> Remove memory</h3>
<div class="outline-text-3" id="text-2-3">
<p>
The following function, called in <a href="./qmckl_memory.html"><code>qmckl_memory.c</code></a>, removes a
pointer from the data structure.
It is forbidden to pass the <code>NULL</code> pointer.
If the context is <code>QMCKL_NULL_CONTEXT</code>, the function returns
immediately with <code>QMCKL_SUCCESS</code>.
</p>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_context_remove_memory</span>(<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">void</span>* <span style="color: #a0522d;">pointer</span>) {
assert (pointer != <span style="color: #008b8b;">NULL</span>);
qmckl_lock(context);
<span style="color: #a020f0;">if</span> ( qmckl_context_check(context) == QMCKL_NULL_CONTEXT ) {
qmckl_unlock(context);
<span style="color: #a020f0;">return</span> QMCKL_SUCCESS;
}
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
<span style="color: #228b22;">qmckl_memory_struct</span>* <span style="color: #a0522d;">alloc</span> = ctx-&gt;alloc;
<span style="color: #228b22;">qmckl_memory_struct</span>* <span style="color: #a0522d;">prev</span> = ctx-&gt;alloc;
<span style="color: #a020f0;">while</span> ( (alloc != <span style="color: #008b8b;">NULL</span>) &amp;&amp; (alloc-&gt;pointer != pointer) ) {
prev = alloc;
alloc = alloc-&gt;next;
}
<span style="color: #a020f0;">if</span> (alloc != <span style="color: #008b8b;">NULL</span>) {
prev-&gt;next = alloc-&gt;next;
free(alloc);
}
qmckl_unlock(context);
<span style="color: #a020f0;">if</span> (alloc != <span style="color: #008b8b;">NULL</span>) {
<span style="color: #a020f0;">return</span> QMCKL_SUCCESS;
} <span style="color: #a020f0;">else</span> {
<span style="color: #a020f0;">return</span> QMCKL_DEALLOCATION_FAILED;
}
}
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-org8ced40f" class="outline-2">
<h2 id="org8ced40f"><span class="section-number-2">3</span> Error handling</h2>
<div class="outline-text-2" id="text-3">
</div>
<div id="outline-container-orge0001cb" class="outline-3">
<h3 id="orge0001cb"><span class="section-number-3">3.1</span> Data structure</h3>
<div class="outline-text-3" id="text-3-1">
<div class="org-src-container">
<pre class="src src-c" id="org8d8d369"><span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_MAX_FUN_LEN</span> 256
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">QMCKL_MAX_MSG_LEN</span> 1024
<span style="color: #a020f0;">typedef</span> <span style="color: #a020f0;">struct</span> <span style="color: #228b22;">qmckl_error_struct</span> {
<span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #a0522d;">exit_code</span>;
<span style="color: #228b22;">char</span> <span style="color: #a0522d;">function</span>[QMCKL_MAX_FUN_LEN];
<span style="color: #228b22;">char</span> <span style="color: #a0522d;">message</span> [QMCKL_MAX_MSG_LEN];
} <span style="color: #228b22;">qmckl_error_struct</span>;
</pre>
</div>
</div>
</div>
<div id="outline-container-org73c6984" class="outline-3">
<h3 id="org73c6984"><span class="section-number-3">3.2</span> Updating errors</h3>
<div class="outline-text-3" id="text-3-2">
<p>
The error is updated in the context using
<code>qmckl_context_update_error</code>, although it is recommended to use
<code>qmckl_context_set_error</code> for the immutable variant.
When the error is set in the context, it is mandatory to specify
from which function the error is triggered, and a message
explaining the error. The exit code can't be <code>QMCKL_SUCCESS</code>.
</p>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #228b22;">qmckl_exit_code</span>
<span style="color: #0000ff;">qmckl_context_update_error</span>(<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #a0522d;">exit_code</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span>* <span style="color: #a0522d;">function_name</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span>* <span style="color: #a0522d;">message</span>)
{
/* <span style="color: #b22222;">Passing a function name and a message is mandatory. </span>*/
assert (function_name != <span style="color: #008b8b;">NULL</span>);
assert (message != <span style="color: #008b8b;">NULL</span>);
/* <span style="color: #b22222;">Exit codes are assumed valid. </span>*/
assert (exit_code &gt;= 0);
assert (exit_code != QMCKL_SUCCESS);
assert (exit_code &lt; QMCKL_INVALID_EXIT_CODE);
qmckl_lock(context);
/* <span style="color: #b22222;">The context is assumed to exist. </span>*/
assert (qmckl_context_check(context) != QMCKL_NULL_CONTEXT);
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
assert (ctx != <span style="color: #008b8b;">NULL</span>); /* <span style="color: #b22222;">Impossible because the context is valid. </span>*/
<span style="color: #a020f0;">if</span> (ctx-&gt;error != <span style="color: #008b8b;">NULL</span>) {
free(ctx-&gt;error);
ctx-&gt;error = <span style="color: #008b8b;">NULL</span>;
}
<span style="color: #228b22;">qmckl_error_struct</span>* <span style="color: #a0522d;">error</span> =
(<span style="color: #228b22;">qmckl_error_struct</span>*) <span style="color: #0000ff;">qmckl_malloc</span> (context, <span style="color: #a020f0;">sizeof</span>(<span style="color: #228b22;">qmckl_error_struct</span>));
error-&gt;exit_code = exit_code;
strcpy(error-&gt;function, function_name);
strcpy(error-&gt;message, message);
ctx-&gt;error = error;
qmckl_unlock(context);
<span style="color: #a020f0;">return</span> QMCKL_SUCCESS;
}
</pre>
</div>
<p>
The <code>qmckl_context_set_error</code> function returns a new context with
the error domain updated.
</p>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #228b22;">qmckl_context</span>
<span style="color: #0000ff;">qmckl_context_set_error</span>(<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #a0522d;">exit_code</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span>* <span style="color: #a0522d;">function_name</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span>* <span style="color: #a0522d;">message</span>)
{
/* <span style="color: #b22222;">Passing a function name and a message is mandatory. </span>*/
assert (function_name != <span style="color: #008b8b;">NULL</span>);
assert (message != <span style="color: #008b8b;">NULL</span>);
/* <span style="color: #b22222;">Exit codes are assumed valid. </span>*/
assert (exit_code &gt;= 0);
assert (exit_code != QMCKL_SUCCESS);
assert (exit_code &lt; QMCKL_INVALID_EXIT_CODE);
/* <span style="color: #b22222;">The context is assumed to be valid </span>*/
<span style="color: #a020f0;">if</span> (qmckl_context_check(context) == QMCKL_NULL_CONTEXT)
<span style="color: #a020f0;">return</span> QMCKL_NULL_CONTEXT;
<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">new_context</span> = qmckl_context_copy(context);
/* <span style="color: #b22222;">Should be impossible because the context is valid </span>*/
assert (new_context != QMCKL_NULL_CONTEXT);
<span style="color: #a020f0;">if</span> (qmckl_context_update_error(new_context,
exit_code,
function_name,
message) != QMCKL_SUCCESS) {
<span style="color: #a020f0;">return</span> context;
}
<span style="color: #a020f0;">return</span> new_context;
}
</pre>
</div>
<p>
To make a function fail, the <code>qmckl_failwith</code> function should be
called, such that information about the failure is stored in
the context. The desired exit code is given as an argument, as
well as the name of the function and an error message. The return
code of the function is the desired return code.
</p>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_failwith</span>(<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #a0522d;">exit_code</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span>* <span style="color: #a0522d;">function</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span>* <span style="color: #a0522d;">message</span>) {
assert (exit_code &gt; 0);
assert (exit_code &lt; QMCKL_INVALID_EXIT_CODE);
assert (function != <span style="color: #008b8b;">NULL</span>);
assert (message != <span style="color: #008b8b;">NULL</span>);
assert (strlen(function) &lt; QMCKL_MAX_FUN_LEN);
assert (strlen(message) &lt; QMCKL_MAX_MSG_LEN);
<span style="color: #a020f0;">if</span> (qmckl_context_check(context) == QMCKL_NULL_CONTEXT)
<span style="color: #a020f0;">return</span> QMCKL_NULL_CONTEXT;
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #a0522d;">rc</span> =
qmckl_context_update_error(context, exit_code, function, message);
assert (rc == QMCKL_SUCCESS);
<span style="color: #a020f0;">return</span> exit_code;
}
</pre>
</div>
<p>
For example, this function can be used as
</p>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #a020f0;">if</span> (x &lt; 0) {
<span style="color: #a020f0;">return</span> qmckl_failwith(context,
QMCKL_INVALID_ARG_2,
<span style="color: #8b2252;">"qmckl_function"</span>,
<span style="color: #8b2252;">"Expected x &gt;= 0"</span>);
}
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-orgb5bac03" class="outline-2">
<h2 id="orgb5bac03"><span class="section-number-2">4</span> Control of the numerical precision</h2>
<div class="outline-text-2" id="text-4">
<p>
Controlling numerical precision enables optimizations. Here, the
default parameters determining the target numerical precision and
range are defined.
</p>
<table id="org6c6e25f" border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
<col class="org-right" />
</colgroup>
<tbody>
<tr>
<td class="org-left"><code>QMCKL_DEFAULT_PRECISION</code></td>
<td class="org-right">53</td>
</tr>
<tr>
<td class="org-left"><code>QMCKL_DEFAULT_RANGE</code></td>
<td class="org-right">11</td>
</tr>
</tbody>
</table>
<div class="org-src-container">
<pre class="src src-python"><span style="color: #8b2252;">""" This script generates the C and Fortran constants for the error</span>
<span style="color: #8b2252;"> codes from the org-mode table.</span>
<span style="color: #8b2252;">"""</span>
<span style="color: #a0522d;">result</span> = [ <span style="color: #8b2252;">"#+begin_src c :comments org :tangle (eval h)"</span> ]
<span style="color: #a020f0;">for</span> (text, code) <span style="color: #a020f0;">in</span> table:
<span style="color: #a0522d;">text</span>=text.replace(<span style="color: #8b2252;">"~"</span>,<span style="color: #8b2252;">""</span>)
<span style="color: #a0522d;">result</span> += [ f<span style="color: #8b2252;">"#define {text:30s} {code:d}"</span> ]
<span style="color: #a0522d;">result</span> += [ <span style="color: #8b2252;">"#+end_src"</span> ]
<span style="color: #a0522d;">result</span> += [ <span style="color: #8b2252;">""</span> ]
<span style="color: #a0522d;">result</span> += [ <span style="color: #8b2252;">"#+begin_src f90 :comments org :tangle (eval fh) :exports none"</span> ]
<span style="color: #a020f0;">for</span> (text, code) <span style="color: #a020f0;">in</span> table:
<span style="color: #a0522d;">text</span>=text.replace(<span style="color: #8b2252;">"~"</span>,<span style="color: #8b2252;">""</span>)
<span style="color: #a0522d;">result</span> += [ f<span style="color: #8b2252;">" integer, parameter :: {text:30s} = {code:d}"</span> ]
<span style="color: #a0522d;">result</span> += [ <span style="color: #8b2252;">"#+end_src"</span> ]
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">'\n'</span>.join(result)
</pre>
</div>
<div class="org-src-container">
<pre class="src src-c" id="org4ec6b22"><span style="color: #a020f0;">typedef</span> <span style="color: #a020f0;">struct</span> <span style="color: #228b22;">qmckl_precision_struct</span> {
<span style="color: #228b22;">int</span> <span style="color: #a0522d;">precision</span>;
<span style="color: #228b22;">int</span> <span style="color: #a0522d;">range</span>;
} <span style="color: #228b22;">qmckl_precision_struct</span>;
</pre>
</div>
<p>
The following functions set and get the required precision and
range. <code>precision</code> is an integer between 2 and 53, and <code>range</code> is an
integer between 2 and 11.
</p>
<p>
The setter functions functions return a new context as a 64-bit
integer. The getter functions return the value, as a 32-bit
integer. The update functions return <code>QMCKL_SUCCESS</code> or
<code>QMCKL_FAILURE</code>.
</p>
</div>
<div id="outline-container-org14623c0" class="outline-3">
<h3 id="org14623c0"><span class="section-number-3">4.1</span> Precision</h3>
<div class="outline-text-3" id="text-4-1">
<p>
<code>qmckl_context_update_precision</code> modifies the parameter for the
numerical precision in a context. If the context doesn't have any
precision set yet, the default values are used.
</p>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_context_update_precision</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int</span> <span style="color: #a0522d;">precision</span>) {
<span style="color: #a020f0;">if</span> (qmckl_context_check(context) == QMCKL_NULL_CONTEXT)
<span style="color: #a020f0;">return</span> QMCKL_INVALID_CONTEXT;
<span style="color: #a020f0;">if</span> (precision &lt; 2) {
<span style="color: #a020f0;">return</span> qmckl_failwith(context,
QMCKL_INVALID_ARG_2,
<span style="color: #8b2252;">"qmckl_context_update_precision"</span>,
<span style="color: #8b2252;">"precision &lt; 2"</span>);
}
<span style="color: #a020f0;">if</span> (precision &gt; 53) {
<span style="color: #a020f0;">return</span> qmckl_failwith(context,
QMCKL_INVALID_ARG_2,
<span style="color: #8b2252;">"qmckl_context_update_precision"</span>,
<span style="color: #8b2252;">"precision &gt; 53"</span>);
}
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
/* <span style="color: #b22222;">This should be always true </span>*/
assert (ctx != <span style="color: #008b8b;">NULL</span>);
qmckl_lock(context);
<span style="color: #a020f0;">if</span> (ctx-&gt;fp == <span style="color: #008b8b;">NULL</span>) {
ctx-&gt;fp = (<span style="color: #228b22;">qmckl_precision_struct</span>*)
qmckl_malloc(context, <span style="color: #a020f0;">sizeof</span>(qmckl_precision_struct));
<span style="color: #a020f0;">if</span> (ctx-&gt;fp == <span style="color: #008b8b;">NULL</span>) {
<span style="color: #a020f0;">return</span> qmckl_failwith(context,
QMCKL_ALLOCATION_FAILED,
<span style="color: #8b2252;">"qmckl_context_update_precision"</span>,
<span style="color: #8b2252;">"ctx-&gt;fp"</span>);
}
ctx-&gt;fp-&gt;precision = QMCKL_DEFAULT_PRECISION;
ctx-&gt;fp-&gt;range = QMCKL_DEFAULT_RANGE;
}
ctx-&gt;fp-&gt;precision = precision;
qmckl_unlock(context);
<span style="color: #a020f0;">return</span> QMCKL_SUCCESS;
}
</pre>
</div>
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_context_update_precision</span>(context, precision) <span style="color: #a020f0;">bind</span>(C)
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> context</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> precision</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_update_precision</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
<p>
<code>qmckl_context_set_precision</code> returns a copy of the context with a
different precision parameter.
</p>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_set_precision</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int</span> <span style="color: #a0522d;">precision</span>) {
<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">new_context</span> = qmckl_context_copy(context);
<span style="color: #a020f0;">if</span> (new_context == 0) <span style="color: #a020f0;">return</span> 0;
<span style="color: #a020f0;">if</span> (qmckl_context_update_precision(new_context, precision) == QMCKL_FAILURE) <span style="color: #a020f0;">return</span> 0;
<span style="color: #a020f0;">return</span> new_context;
}
</pre>
</div>
<p>
<code>qmckl_context_get_precision</code> returns the value of the numerical precision in the context.
</p>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #228b22;">int</span> <span style="color: #0000ff;">qmckl_context_get_precision</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>) {
<span style="color: #a020f0;">if</span> (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
<span style="color: #a020f0;">return</span> qmckl_failwith(context,
QMCKL_INVALID_CONTEXT,
<span style="color: #8b2252;">"qmckl_context_get_precision"</span>,
<span style="color: #8b2252;">""</span>);
}
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
<span style="color: #a020f0;">if</span> (ctx-&gt;fp != <span style="color: #008b8b;">NULL</span>)
<span style="color: #a020f0;">return</span> ctx-&gt;fp-&gt;precision;
<span style="color: #a020f0;">else</span>
<span style="color: #a020f0;">return</span> QMCKL_DEFAULT_PRECISION;
}
</pre>
</div>
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_context_get_precision</span>(context) <span style="color: #a020f0;">bind</span>(C)
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> context</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_get_precision</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org63c3be2" class="outline-3">
<h3 id="org63c3be2"><span class="section-number-3">4.2</span> Range</h3>
<div class="outline-text-3" id="text-4-2">
<p>
<code>qmckl_context_update_range</code> modifies the parameter for the numerical range in a given context.
</p>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #228b22;">qmckl_exit_code</span> <span style="color: #0000ff;">qmckl_context_update_range</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int</span> <span style="color: #a0522d;">range</span>) {
<span style="color: #a020f0;">if</span> (qmckl_context_check(context) == QMCKL_NULL_CONTEXT)
<span style="color: #a020f0;">return</span> QMCKL_INVALID_CONTEXT;
<span style="color: #a020f0;">if</span> (range &lt; 2) {
<span style="color: #a020f0;">return</span> qmckl_failwith(context,
QMCKL_INVALID_ARG_2,
<span style="color: #8b2252;">"qmckl_context_update_range"</span>,
<span style="color: #8b2252;">"range &lt; 2"</span>);
}
<span style="color: #a020f0;">if</span> (range &gt; 11) {
<span style="color: #a020f0;">return</span> qmckl_failwith(context,
QMCKL_INVALID_ARG_2,
<span style="color: #8b2252;">"qmckl_context_update_range"</span>,
<span style="color: #8b2252;">"range &gt; 11"</span>);
}
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
/* <span style="color: #b22222;">This should be always true </span>*/
assert (ctx != <span style="color: #008b8b;">NULL</span>);
qmckl_lock(context);
<span style="color: #a020f0;">if</span> (ctx-&gt;fp == <span style="color: #008b8b;">NULL</span>) {
ctx-&gt;fp = (<span style="color: #228b22;">qmckl_precision_struct</span>*)
qmckl_malloc(context, <span style="color: #a020f0;">sizeof</span>(qmckl_precision_struct));
<span style="color: #a020f0;">if</span> (ctx-&gt;fp == <span style="color: #008b8b;">NULL</span>) {
<span style="color: #a020f0;">return</span> qmckl_failwith(context,
QMCKL_ALLOCATION_FAILED,
<span style="color: #8b2252;">"qmckl_context_update_range"</span>,
<span style="color: #8b2252;">"ctx-&gt;fp"</span>);
}
ctx-&gt;fp-&gt;precision = QMCKL_DEFAULT_PRECISION;
ctx-&gt;fp-&gt;range = QMCKL_DEFAULT_RANGE;
}
ctx-&gt;fp-&gt;range = range;
qmckl_unlock(context);
<span style="color: #a020f0;">return</span> QMCKL_SUCCESS;
}
</pre>
</div>
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">qmckl_context_update_range</span>(context, range) <span style="color: #a020f0;">bind</span>(C)
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> context</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> range</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_update_range</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
<p>
<code>qmckl_context_set_range</code> returns a copy of the context with a different precision parameter.
</p>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #228b22;">qmckl_context</span> <span style="color: #0000ff;">qmckl_context_set_range</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int</span> <span style="color: #a0522d;">range</span>) {
<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">new_context</span> = qmckl_context_copy(context);
<span style="color: #a020f0;">if</span> (new_context == 0) <span style="color: #a020f0;">return</span> 0;
<span style="color: #a020f0;">if</span> (qmckl_context_update_range(new_context, range) == QMCKL_FAILURE) <span style="color: #a020f0;">return</span> 0;
<span style="color: #a020f0;">return</span> new_context;
}
</pre>
</div>
<p>
<code>qmckl_context_get_range</code> returns the value of the numerical range in the context.
</p>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #228b22;">int</span> <span style="color: #0000ff;">qmckl_context_get_range</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>) {
<span style="color: #a020f0;">if</span> (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) {
<span style="color: #a020f0;">return</span> qmckl_failwith(context,
QMCKL_INVALID_CONTEXT,
<span style="color: #8b2252;">"qmckl_context_get_range"</span>,
<span style="color: #8b2252;">""</span>);
}
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
<span style="color: #a020f0;">if</span> (ctx-&gt;fp != <span style="color: #008b8b;">NULL</span>)
<span style="color: #a020f0;">return</span> ctx-&gt;fp-&gt;range;
<span style="color: #a020f0;">else</span>
<span style="color: #a020f0;">return</span> QMCKL_DEFAULT_RANGE;
}
</pre>
</div>
</div>
</div>
<div id="outline-container-org7e8d441" class="outline-3">
<h3 id="org7e8d441"><span class="section-number-3">4.3</span> Helper functions</h3>
<div class="outline-text-3" id="text-4-3">
<p>
<code>qmckl_context_get_epsilon</code> returns \(\epsilon = 2^{1-n}\) where <code>n</code> is the precision.
</p>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #228b22;">double</span> <span style="color: #0000ff;">qmckl_context_get_epsilon</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span>) {
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int</span> <span style="color: #a0522d;">precision</span> = qmckl_context_get_precision(context);
<span style="color: #a020f0;">return</span> 1. / (<span style="color: #228b22;">double</span>) (1L &lt;&lt; (precision-1));
}
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-org726b951" class="outline-2">
<h2 id="org726b951"><span class="section-number-2">5</span> <span class="todo TODO">TODO</span> Basis set</h2>
<div class="outline-text-2" id="text-5">
<p>
For H<sub>2</sub> with the following basis set,
</p>
<pre class="example">
HYDROGEN
S 5
1 3.387000E+01 6.068000E-03
2 5.095000E+00 4.530800E-02
3 1.159000E+00 2.028220E-01
4 3.258000E-01 5.039030E-01
5 1.027000E-01 3.834210E-01
S 1
1 3.258000E-01 1.000000E+00
S 1
1 1.027000E-01 1.000000E+00
P 1
1 1.407000E+00 1.000000E+00
P 1
1 3.880000E-01 1.000000E+00
D 1
1 1.057000E+00 1.0000000
</pre>
<p>
we have:
</p>
<pre class="example">
type = 'G'
shell_num = 12
prim_num = 20
SHELL_CENTER = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2]
SHELL_ANG_MOM = ['S', 'S', 'S', 'P', 'P', 'D', 'S', 'S', 'S', 'P', 'P', 'D']
SHELL_PRIM_NUM = [5, 1, 1, 1, 1, 1, 5, 1, 1, 1, 1, 1]
prim_index = [1, 6, 7, 8, 9, 10, 11, 16, 17, 18, 19, 20]
EXPONENT = [ 33.87, 5.095, 1.159, 0.3258, 0.1027, 0.3258, 0.1027,
1.407, 0.388, 1.057, 33.87, 5.095, 1.159, 0.3258, 0.1027,
0.3258, 0.1027, 1.407, 0.388, 1.057]
COEFFICIENT = [ 0.006068, 0.045308, 0.202822, 0.503903, 0.383421,
1.0, 1.0, 1.0, 1.0, 1.0, 0.006068, 0.045308, 0.202822,
0.503903, 0.383421, 1.0, 1.0, 1.0, 1.0, 1.0]
</pre>
</div>
<div id="outline-container-org8ce7135" class="outline-3">
<h3 id="org8ce7135"><span class="section-number-3">5.1</span> Data structure</h3>
<div class="outline-text-3" id="text-5-1">
<div class="org-src-container">
<pre class="src src-c" id="orgd0c68c6"><span style="color: #a020f0;">typedef</span> <span style="color: #a020f0;">struct</span> <span style="color: #228b22;">qmckl_ao_basis_struct</span> {
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">shell_num</span>;
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">prim_num</span>;
<span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">shell_center</span>;
<span style="color: #228b22;">int32_t</span> * <span style="color: #a0522d;">shell_ang_mom</span>;
<span style="color: #228b22;">double</span> * <span style="color: #a0522d;">shell_factor</span>;
<span style="color: #228b22;">double</span> * <span style="color: #a0522d;">exponent</span> ;
<span style="color: #228b22;">double</span> * <span style="color: #a0522d;">coefficient</span> ;
<span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">shell_prim_num</span>;
<span style="color: #228b22;">char</span> <span style="color: #a0522d;">type</span>;
} <span style="color: #228b22;">qmckl_ao_basis_struct</span>;
</pre>
</div>
</div>
</div>
<div id="outline-container-org03947a0" class="outline-3">
<h3 id="org03947a0"><span class="section-number-3">5.2</span> <code>qmckl_context_update_ao_basis</code></h3>
<div class="outline-text-3" id="text-5-2">
<p>
Updates the data describing the AO basis set into the context.
</p>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
<col class="org-left" />
</colgroup>
<tbody>
<tr>
<td class="org-left"><code>type</code></td>
<td class="org-left">Gaussian or Slater</td>
</tr>
<tr>
<td class="org-left"><code>shell_num</code></td>
<td class="org-left">Number of shells</td>
</tr>
<tr>
<td class="org-left"><code>prim_num</code></td>
<td class="org-left">Total number of primitives</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_CENTER(shell_num)</code></td>
<td class="org-left">Id of the nucleus on which the shell is centered</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_ANG_MOM(shell_num)</code></td>
<td class="org-left">Id of the nucleus on which the shell is centered</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_FACTOR(shell_num)</code></td>
<td class="org-left">Normalization factor for the shell</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_PRIM_NUM(shell_num)</code></td>
<td class="org-left">Number of primitives in the shell</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_PRIM_INDEX(shell_num)</code></td>
<td class="org-left">Address of the first primitive of the shelll in the <code>EXPONENT</code> array</td>
</tr>
<tr>
<td class="org-left"><code>EXPONENT(prim_num)</code></td>
<td class="org-left">Array of exponents</td>
</tr>
<tr>
<td class="org-left"><code>COEFFICIENT(prim_num)</code></td>
<td class="org-left">Array of coefficients</td>
</tr>
</tbody>
</table>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #228b22;">qmckl_exit_code</span>
<span style="color: #0000ff;">qmckl_context_update_ao_basis</span>(<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span> ,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span> <span style="color: #a0522d;">type</span> ,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">shell_num</span> ,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">prim_num</span> ,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_CENTER</span> ,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> * <span style="color: #a0522d;">SHELL_ANG_MOM</span> ,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">SHELL_FACTOR</span> ,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_NUM</span> ,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_INDEX</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">EXPONENT</span> ,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">COEFFICIENT</span>);
</pre>
</div>
</div>
<div id="outline-container-orgc421adc" class="outline-4">
<h4 id="orgc421adc"><span class="section-number-4">5.2.1</span> Source</h4>
<div class="outline-text-4" id="text-5-2-1">
<div class="org-src-container">
<pre class="src src-c"><span style="color: #228b22;">qmckl_exit_code</span>
<span style="color: #0000ff;">qmckl_context_update_ao_basis</span>(<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span> <span style="color: #a0522d;">type</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">shell_num</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">prim_num</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_CENTER</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> * <span style="color: #a0522d;">SHELL_ANG_MOM</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">SHELL_FACTOR</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_NUM</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_INDEX</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">EXPONENT</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">COEFFICIENT</span>)
{
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">i</span>;
/* <span style="color: #b22222;">Check input </span>*/
<span style="color: #a020f0;">if</span> (type != <span style="color: #8b2252;">'G'</span> &amp;&amp; type != <span style="color: #8b2252;">'S'</span>) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">if</span> (shell_num &lt;= 0) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">if</span> (prim_num &lt;= 0) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">if</span> (prim_num &lt; shell_num) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">for</span> (i=0 ; i&lt;shell_num ; i++) {
<span style="color: #a020f0;">if</span> (SHELL_CENTER[i] &lt;= 0) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">if</span> (SHELL_PRIM_NUM[i] &lt;= 0) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">if</span> (SHELL_ANG_MOM[i] &lt; 0) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #a020f0;">if</span> (SHELL_PRIM_INDEX[i] &lt; 0) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
<span style="color: #a020f0;">for</span> (i=0 ; i&lt;prim_num ; i++) {
<span style="color: #a020f0;">if</span> (EXPONENT[i] &lt;= 0) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
<span style="color: #228b22;">qmckl_context_struct</span>* <span style="color: #a0522d;">ctx</span> = (<span style="color: #228b22;">qmckl_context_struct</span>*) context;
<span style="color: #a020f0;">if</span> (ctx == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> QMCKL_FAILURE;
<span style="color: #228b22;">qmckl_ao_basis_struct</span>* <span style="color: #a0522d;">basis</span> =
(<span style="color: #228b22;">qmckl_ao_basis_struct</span>*) <span style="color: #0000ff;">qmckl_malloc</span> (context, <span style="color: #a020f0;">sizeof</span>(<span style="color: #228b22;">qmckl_ao_basis_struct</span>));
<span style="color: #a020f0;">if</span> (basis == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> QMCKL_ALLOCATION_FAILED;
/* <span style="color: #b22222;">Memory allocations </span>*/
assert (basis-&gt;shell_center == <span style="color: #008b8b;">NULL</span>);
basis-&gt;shell_center = (<span style="color: #228b22;">int64_t</span>*) qmckl_malloc (context, <span style="color: #228b22;">shell_num</span> * <span style="color: #a020f0;">sizeof</span>(int64_t));
<span style="color: #a020f0;">if</span> (basis-&gt;shell_center == <span style="color: #008b8b;">NULL</span>) {
qmckl_free(context, basis);
basis = <span style="color: #008b8b;">NULL</span>;
<span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
assert (basis-&gt;shell_ang_mom == <span style="color: #008b8b;">NULL</span>);
basis-&gt;shell_ang_mom = (<span style="color: #228b22;">int32_t</span>*) qmckl_malloc (context, <span style="color: #228b22;">shell_num</span> * <span style="color: #a020f0;">sizeof</span>(int32_t));
<span style="color: #a020f0;">if</span> (basis-&gt;shell_ang_mom == <span style="color: #008b8b;">NULL</span>) {
qmckl_free(context, basis-&gt;shell_center);
basis-&gt;shell_center = <span style="color: #008b8b;">NULL</span>;
qmckl_free(context, basis);
basis = <span style="color: #008b8b;">NULL</span>;
<span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
assert (basis-&gt;shell_prim_num == <span style="color: #008b8b;">NULL</span>);
basis-&gt;shell_prim_num= (<span style="color: #228b22;">int64_t</span>*) qmckl_malloc (context, <span style="color: #228b22;">shell_num</span> * <span style="color: #a020f0;">sizeof</span>(int64_t));
<span style="color: #a020f0;">if</span> (basis-&gt;shell_prim_num == <span style="color: #008b8b;">NULL</span>) {
qmckl_free(context, basis-&gt;shell_ang_mom);
basis-&gt;shell_ang_mom = <span style="color: #008b8b;">NULL</span>;
qmckl_free(context, basis-&gt;shell_center);
basis-&gt;shell_center = <span style="color: #008b8b;">NULL</span>;
qmckl_free(context, basis);
basis = <span style="color: #008b8b;">NULL</span>;
<span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
assert (basis-&gt;shell_factor == <span style="color: #008b8b;">NULL</span>);
basis-&gt;shell_factor = (<span style="color: #228b22;">double</span> *) qmckl_malloc (context, <span style="color: #228b22;">shell_num</span> * <span style="color: #a020f0;">sizeof</span>(<span style="color: #228b22;">double</span>));
<span style="color: #a020f0;">if</span> (basis-&gt;shell_factor == <span style="color: #008b8b;">NULL</span>) {
qmckl_free(context, basis-&gt;shell_prim_num);
basis-&gt;shell_prim_num = <span style="color: #008b8b;">NULL</span>;
qmckl_free(context, basis-&gt;shell_ang_mom);
basis-&gt;shell_ang_mom = <span style="color: #008b8b;">NULL</span>;
qmckl_free(context, basis-&gt;shell_center);
basis-&gt;shell_center = <span style="color: #008b8b;">NULL</span>;
qmckl_free(context, basis);
basis = <span style="color: #008b8b;">NULL</span>;
<span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
assert (basis-&gt;exponent == <span style="color: #008b8b;">NULL</span>);
basis-&gt;exponent = (<span style="color: #228b22;">double</span> *) qmckl_malloc (context, <span style="color: #228b22;">prim_num</span> * <span style="color: #a020f0;">sizeof</span>(<span style="color: #228b22;">double</span>));
<span style="color: #a020f0;">if</span> (basis-&gt;exponent == <span style="color: #008b8b;">NULL</span>) {
qmckl_free(context, basis-&gt;shell_factor);
basis-&gt;shell_factor = <span style="color: #008b8b;">NULL</span>;
qmckl_free(context, basis-&gt;shell_prim_num);
basis-&gt;shell_prim_num = <span style="color: #008b8b;">NULL</span>;
qmckl_free(context, basis-&gt;shell_ang_mom);
basis-&gt;shell_ang_mom = <span style="color: #008b8b;">NULL</span>;
qmckl_free(context, basis-&gt;shell_center);
basis-&gt;shell_center = <span style="color: #008b8b;">NULL</span>;
qmckl_free(context, basis);
basis = <span style="color: #008b8b;">NULL</span>;
<span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
assert (basis-&gt;coefficient == <span style="color: #008b8b;">NULL</span>);
basis-&gt;coefficient = (<span style="color: #228b22;">double</span> *) qmckl_malloc (context, <span style="color: #228b22;">prim_num</span> * <span style="color: #a020f0;">sizeof</span>(<span style="color: #228b22;">double</span>));
<span style="color: #a020f0;">if</span> (basis-&gt;coefficient == <span style="color: #008b8b;">NULL</span>) {
qmckl_free(context, basis-&gt;exponent);
basis-&gt;exponent = <span style="color: #008b8b;">NULL</span>;
qmckl_free(context, basis-&gt;shell_factor);
basis-&gt;shell_factor = <span style="color: #008b8b;">NULL</span>;
qmckl_free(context, basis-&gt;shell_prim_num);
basis-&gt;shell_prim_num = <span style="color: #008b8b;">NULL</span>;
qmckl_free(context, basis-&gt;shell_ang_mom);
basis-&gt;shell_ang_mom = <span style="color: #008b8b;">NULL</span>;
qmckl_free(context, basis-&gt;shell_center);
basis-&gt;shell_center = <span style="color: #008b8b;">NULL</span>;
qmckl_free(context, basis);
basis = <span style="color: #008b8b;">NULL</span>;
<span style="color: #a020f0;">return</span> QMCKL_FAILURE;
}
/* <span style="color: #b22222;">Assign data </span>*/
basis-&gt;type = type;
basis-&gt;shell_num = shell_num;
basis-&gt;prim_num = prim_num;
<span style="color: #a020f0;">for</span> (i=0 ; i&lt;shell_num ; i++) {
basis-&gt;shell_center [i] = SHELL_CENTER [i];
basis-&gt;shell_ang_mom [i] = SHELL_ANG_MOM [i];
basis-&gt;shell_prim_num[i] = SHELL_PRIM_NUM[i];
basis-&gt;shell_factor [i] = SHELL_FACTOR [i];
}
<span style="color: #a020f0;">for</span> (i=0 ; i&lt;prim_num ; i++) {
basis-&gt;exponent [i] = EXPONENT[i];
basis-&gt;coefficient[i] = COEFFICIENT[i];
}
ctx-&gt;ao_basis = basis;
<span style="color: #a020f0;">return</span> QMCKL_SUCCESS;
}
</pre>
</div>
</div>
</div>
<div id="outline-container-orge6b3490" class="outline-4">
<h4 id="orge6b3490"><span class="section-number-4">5.2.2</span> Fortran interface</h4>
<div class="outline-text-4" id="text-5-2-2">
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>)<span style="color: #a0522d;"> function qmckl_context_update_ao_basis(context, </span><span style="color: #a020f0;">&amp;</span>
typ, shell_num, prim_num, SHELL_CENTER, SHELL_ANG_MOM, SHELL_FACTOR, <span style="color: #a020f0;">&amp;</span>
SHELL_PRIM_NUM, SHELL_PRIM_INDEX, EXPONENT, COEFFICIENT) <span style="color: #a020f0;">bind</span>(C)
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> context</span>
<span style="color: #228b22;">character</span>(<span style="color: #008b8b;">c_char</span>) , <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> typ</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> shell_num</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> prim_num</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> SHELL_CENTER(shell_num)</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> SHELL_ANG_MOM(shell_num)</span>
<span style="color: #228b22;">double precision</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> SHELL_FACTOR(shell_num)</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> SHELL_PRIM_NUM(shell_num)</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> SHELL_PRIM_INDEX(shell_num)</span>
<span style="color: #228b22;">double precision</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> EXPONENT(prim_num)</span>
<span style="color: #228b22;">double precision</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> COEFFICIENT(prim_num)</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_update_ao_basis</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org2e8acd6" class="outline-4">
<h4 id="org2e8acd6"><span class="section-number-4">5.2.3</span> <span class="todo TODO">TODO</span> Test</h4>
</div>
</div>
<div id="outline-container-org8a4e904" class="outline-3">
<h3 id="org8a4e904"><span class="section-number-3">5.3</span> <code>qmckl_context_set_ao_basis</code></h3>
<div class="outline-text-3" id="text-5-3">
<p>
Sets the data describing the AO basis set into the context.
</p>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
<col class="org-left" />
</colgroup>
<tbody>
<tr>
<td class="org-left"><code>type</code></td>
<td class="org-left">Gaussian or Slater</td>
</tr>
<tr>
<td class="org-left"><code>shell_num</code></td>
<td class="org-left">Number of shells</td>
</tr>
<tr>
<td class="org-left"><code>prim_num</code></td>
<td class="org-left">Total number of primitives</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_CENTER(shell_num)</code></td>
<td class="org-left">Id of the nucleus on which the shell is centered</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_ANG_MOM(shell_num)</code></td>
<td class="org-left">Id of the nucleus on which the shell is centered</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_FACTOR(shell_num)</code></td>
<td class="org-left">Normalization factor for the shell</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_PRIM_NUM(shell_num)</code></td>
<td class="org-left">Number of primitives in the shell</td>
</tr>
<tr>
<td class="org-left"><code>SHELL_PRIM_INDEX(shell_num)</code></td>
<td class="org-left">Address of the first primitive of the shelll in the <code>EXPONENT</code> array</td>
</tr>
<tr>
<td class="org-left"><code>EXPONENT(prim_num)</code></td>
<td class="org-left">Array of exponents</td>
</tr>
<tr>
<td class="org-left"><code>COEFFICIENT(prim_num)</code></td>
<td class="org-left">Array of coefficients</td>
</tr>
</tbody>
</table>
<div class="org-src-container">
<pre class="src src-c"><span style="color: #228b22;">qmckl_context</span>
<span style="color: #0000ff;">qmckl_context_set_ao_basis</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span> <span style="color: #a0522d;">type</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">shell_num</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">prim_num</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_CENTER</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> * <span style="color: #a0522d;">SHELL_ANG_MOM</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">SHELL_FACTOR</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_NUM</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_INDEX</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">EXPONENT</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">COEFFICIENT</span>);
</pre>
</div>
</div>
<div id="outline-container-orgf7bcf78" class="outline-4">
<h4 id="orgf7bcf78"><span class="section-number-4">5.3.1</span> Source</h4>
<div class="outline-text-4" id="text-5-3-1">
<div class="org-src-container">
<pre class="src src-c"><span style="color: #228b22;">qmckl_context</span>
<span style="color: #0000ff;">qmckl_context_set_ao_basis</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">context</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span> <span style="color: #a0522d;">type</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">shell_num</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">prim_num</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_CENTER</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> * <span style="color: #a0522d;">SHELL_ANG_MOM</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">SHELL_FACTOR</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_NUM</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> * <span style="color: #a0522d;">SHELL_PRIM_INDEX</span>,
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">EXPONENT</span> , <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> * <span style="color: #a0522d;">COEFFICIENT</span>)
{
<span style="color: #228b22;">qmckl_context</span> <span style="color: #a0522d;">new_context</span> = qmckl_context_copy(context);
<span style="color: #a020f0;">if</span> (new_context == 0) <span style="color: #a020f0;">return</span> 0;
<span style="color: #a020f0;">if</span> (qmckl_context_update_ao_basis(new_context, type, shell_num, prim_num,
SHELL_CENTER, SHELL_ANG_MOM, SHELL_FACTOR,
SHELL_PRIM_NUM, SHELL_PRIM_INDEX, EXPONENT,
COEFFICIENT
) == QMCKL_FAILURE)
<span style="color: #a020f0;">return</span> 0;
<span style="color: #a020f0;">return</span> new_context;
}
</pre>
</div>
</div>
</div>
<div id="outline-container-org35cd041" class="outline-4">
<h4 id="org35cd041"><span class="section-number-4">5.3.2</span> Fortran interface</h4>
<div class="outline-text-4" id="text-5-3-2">
<div class="org-src-container">
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>)<span style="color: #a0522d;"> function qmckl_context_set_ao_basis(context, </span><span style="color: #a020f0;">&amp;</span>
typ, shell_num, prim_num, SHELL_CENTER, SHELL_ANG_MOM, SHELL_FACTOR, <span style="color: #a020f0;">&amp;</span>
SHELL_PRIM_NUM, SHELL_PRIM_INDEX, EXPONENT, COEFFICIENT) <span style="color: #a020f0;">bind</span>(C)
<span style="color: #a020f0;">use</span>, <span style="color: #a020f0;">intrinsic</span> :: <span style="color: #0000ff;">iso_c_binding</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> context</span>
<span style="color: #228b22;">character</span>(<span style="color: #008b8b;">c_char</span>) , <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> typ</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> shell_num</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> prim_num</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> SHELL_CENTER(shell_num)</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> SHELL_ANG_MOM(shell_num)</span>
<span style="color: #228b22;">double precision</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> SHELL_FACTOR(shell_num)</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> SHELL_PRIM_NUM(shell_num)</span>
<span style="color: #228b22;">integer</span> (<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> SHELL_PRIM_INDEX(shell_num)</span>
<span style="color: #228b22;">double precision</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> EXPONENT(prim_num)</span>
<span style="color: #228b22;">double precision</span> , <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> COEFFICIENT(prim_num)</span>
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">qmckl_context_set_ao_basis</span>
<span style="color: #a020f0;">end interface</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org970a631" class="outline-4">
<h4 id="org970a631"><span class="section-number-4">5.3.3</span> <span class="todo TODO">TODO</span> Test</h4>
</div>
</div>
</div>
</div>
<div id="postamble" class="status">
<p class="author">Author: TREX CoE</p>
<p class="date">Created: 2021-03-23 Tue 21:25</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
</body>
</html>