mirror of
https://github.com/TREX-CoE/trexio.git
synced 2024-11-03 20:54:07 +01:00
8196 lines
496 KiB
HTML
8196 lines
496 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>
|
|
<!-- 2024-05-23 Thu 15:59 -->
|
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<title>Front end API</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; }
|
|
.equation-container {
|
|
display: table;
|
|
text-align: center;
|
|
width: 100%;
|
|
}
|
|
.equation {
|
|
vertical-align: middle;
|
|
}
|
|
.equation-label {
|
|
display: table-cell;
|
|
text-align: right;
|
|
vertical-align: middle;
|
|
}
|
|
.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="trexio.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-2020 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-2020 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", "0");
|
|
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-2020 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">Front end API</h1>
|
|
<div id="table-of-contents">
|
|
<h2>Table of Contents</h2>
|
|
<div id="text-table-of-contents">
|
|
<ul>
|
|
<li><a href="#org578a267">1. Coding conventions</a>
|
|
<ul>
|
|
<li><a href="#org7284b59">1.1. Memory allocation</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#orgca3a9a9">2. Front end</a>
|
|
<ul>
|
|
<li><a href="#orgdac3f31">2.1. Error handling</a>
|
|
<ul>
|
|
<li><a href="#org9a81de1">2.1.1. Decoding errors</a>
|
|
<ul>
|
|
<li><a href="#orge664bf7">2.1.1.1. C source code</a></li>
|
|
<li><a href="#orgf7b2253">2.1.1.2. Fortran interface</a></li>
|
|
<li><a href="#org8eb3629">2.1.1.3. Python interface</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#org300904d">2.2. Back ends</a>
|
|
<ul>
|
|
<li><a href="#org780c46b">2.2.1. C</a></li>
|
|
<li><a href="#org2bf61ff">2.2.2. Fortran</a></li>
|
|
<li><a href="#orge58f298">2.2.3. Python</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#org0b247fc">2.3. Read/write behavior</a></li>
|
|
<li><a href="#org4de6ab6">2.4. TREXIO file type</a></li>
|
|
<li><a href="#orge353a83">2.5. File opening</a>
|
|
<ul>
|
|
<li><a href="#org27173a5">2.5.1. C</a></li>
|
|
<li><a href="#org9f788cb">2.5.2. Fortran</a></li>
|
|
<li><a href="#org96e7db5">2.5.3. Python</a></li>
|
|
<li><a href="#org9db402f">2.5.4. Zero-based versus one-based arrays of indices</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#orgf3938ff">2.6. File closing</a>
|
|
<ul>
|
|
<li><a href="#orgcf29d82">2.6.1. C</a></li>
|
|
<li><a href="#orgfa8738c">2.6.2. Fortran</a></li>
|
|
<li><a href="#orgf5a0f72">2.6.3. Python</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#org7fb1fb1">2.7. File flushing</a>
|
|
<ul>
|
|
<li><a href="#org7595d71">2.7.1. C</a></li>
|
|
<li><a href="#org36ae999">2.7.2. Fortran</a></li>
|
|
<li><a href="#org1523cd6">2.7.3. Python</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#orga643af7">2.8. File existence</a>
|
|
<ul>
|
|
<li><a href="#orgc0c01f1">2.8.1. C</a></li>
|
|
<li><a href="#org2d7f0c5">2.8.2. Fortran</a></li>
|
|
<li><a href="#org416ec80">2.8.3. Python</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#org51e5009">2.9. File copy</a>
|
|
<ul>
|
|
<li><a href="#orgfc2aeec">2.9.1. C</a></li>
|
|
<li><a href="#org8718234">2.9.2. Fortran</a></li>
|
|
<li><a href="#org0e3799e">2.9.3. Python</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#org353b3fb">2.10. File state</a>
|
|
<ul>
|
|
<li><a href="#orgf60d4c7">2.10.1. C</a></li>
|
|
<li><a href="#org1eb0296">2.10.2. Fortran</a></li>
|
|
<li><a href="#org8a21037">2.10.3. Python</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#org2e9b5d4">2.11. Tasks to be done before closing</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#org590ccb0">3. Templates for front end</a>
|
|
<ul>
|
|
<li><a href="#org1275000">3.1. Description</a></li>
|
|
<li><a href="#org0e1ed16">3.2. Templates for front end has<sub>group</sub> functions</a>
|
|
<ul>
|
|
<li><a href="#org354ca8b">3.2.1. Introduction</a></li>
|
|
<li><a href="#org31eafa9">3.2.2. C templates for front end</a>
|
|
<ul>
|
|
<li><a href="#orgff8fde1">3.2.2.1. Function declarations</a></li>
|
|
<li><a href="#org7e56d89">3.2.2.2. Source code</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#orga28a769">3.2.3. Fortran templates for front end</a></li>
|
|
<li><a href="#orga428446">3.2.4. Python templates for front end</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#org344cc35">3.3. Templates for front end has/read/write a single numerical attribute</a>
|
|
<ul>
|
|
<li><a href="#org86e4182">3.3.1. Introduction</a></li>
|
|
<li><a href="#orgdf95cb6">3.3.2. C templates for front end</a>
|
|
<ul>
|
|
<li><a href="#org696e05b">3.3.2.1. Function declarations</a></li>
|
|
<li><a href="#orgfcb88b8">3.3.2.2. Source code for double precision functions</a></li>
|
|
<li><a href="#orgc1923c4">3.3.2.3. Source code for single precision functions</a></li>
|
|
<li><a href="#org9ad1d67">3.3.2.4. Source code for default functions</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#org6d161ae">3.3.3. Fortran templates for front end</a></li>
|
|
<li><a href="#orgc920bfb">3.3.4. Python templates for front end</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#org5288e80">3.4. Templates for front end has/read/write a dataset of numerical data</a>
|
|
<ul>
|
|
<li><a href="#org4b90115">3.4.1. Introduction</a></li>
|
|
<li><a href="#org431bd83">3.4.2. C templates for front end</a>
|
|
<ul>
|
|
<li><a href="#org0bed97d">3.4.2.1. Function declarations</a></li>
|
|
<li><a href="#org4a79b76">3.4.2.2. Source code for double precision functions</a></li>
|
|
<li><a href="#org5e7ced2">3.4.2.3. Source code for single precision functions</a></li>
|
|
<li><a href="#org04136d1">3.4.2.4. Source code for memory-safe functions</a></li>
|
|
<li><a href="#orgb86367a">3.4.2.5. Source code for default functions</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#org9ad6138">3.4.3. Fortran templates for front end</a></li>
|
|
<li><a href="#orgf1178d2">3.4.4. Python templates for front end</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#orge9a36ea">3.5. Templates for front end has/read/write a dataset of sparse data</a>
|
|
<ul>
|
|
<li><a href="#orgf42d80a">3.5.1. Introduction</a></li>
|
|
<li><a href="#org28d4b56">3.5.2. C templates for front end</a>
|
|
<ul>
|
|
<li><a href="#org01087cb">3.5.2.1. Function declarations</a></li>
|
|
<li><a href="#orga7a85b5">3.5.2.2. Source code for default functions</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#org8e8da9f">3.5.3. Fortran templates for front end</a></li>
|
|
<li><a href="#orgebddbab">3.5.4. Python templates for front end</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#org1c5a7c4">3.6. Templates for front end has/read/write a dataset of strings</a>
|
|
<ul>
|
|
<li><a href="#org63007b3">3.6.1. Introduction</a></li>
|
|
<li><a href="#orgca104c4">3.6.2. C templates for front end</a>
|
|
<ul>
|
|
<li><a href="#org5014035">3.6.2.1. Function declarations</a></li>
|
|
<li><a href="#org42702d7">3.6.2.2. Source code for default functions</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#org6ed6e3d">3.6.3. Fortran templates for front end</a></li>
|
|
<li><a href="#org8abff32">3.6.4. Python templates for front end</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#orgcb8af3e">3.7. Templates for front end has/read/write a buffered vector</a>
|
|
<ul>
|
|
<li><a href="#org79d57e1">3.7.1. C source code</a></li>
|
|
<li><a href="#org67c1b95">3.7.2. Fortran interface</a></li>
|
|
<li><a href="#orgb45e5aa">3.7.3. Python interface</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#org34592b0">3.8. Templates for front end has/read/write a single string attribute</a>
|
|
<ul>
|
|
<li><a href="#org6271871">3.8.1. Introduction</a></li>
|
|
<li><a href="#orgedc74b8">3.8.2. C templates for front end</a>
|
|
<ul>
|
|
<li><a href="#org33fe29c">3.8.2.1. Function declarations</a></li>
|
|
<li><a href="#orgfe93ff7">3.8.2.2. Source code for default functions</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#org863cc63">3.8.3. Fortran templates for front end</a></li>
|
|
<li><a href="#org6cf7c9f">3.8.4. Python templates for front end</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#org87fce9e">3.9. Templates for front end delete an entire group (UNSAFE MODE)</a>
|
|
<ul>
|
|
<li><a href="#org6a7f139">3.9.1. Introduction</a></li>
|
|
<li><a href="#org7958c2a">3.9.2. C templates for front end</a></li>
|
|
<li><a href="#orga1014f8">3.9.3. Fortran templates for front end</a></li>
|
|
<li><a href="#orgcd08ae9">3.9.4. Python templates for front end</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#orgf4b6a01">4. Source code for the determinant part</a>
|
|
<ul>
|
|
<li>
|
|
<ul>
|
|
<li><a href="#orge2b3d27">4.0.1. C source code</a></li>
|
|
<li><a href="#org464b9fd">4.0.2. Fortran interface</a></li>
|
|
<li><a href="#org4b51a49">4.0.3. Python interface</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#orge298f0c">5. General helper functions</a>
|
|
<ul>
|
|
<li><a href="#org0c731ce">5.1. C</a></li>
|
|
<li><a href="#orgfc8ba1e">5.2. Fortran</a></li>
|
|
<li><a href="#orgeeeacd3">5.3. Python</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#orge3876be">6. Fortran helper/wrapper functions</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org578a267" class="outline-2">
|
|
<h2 id="org578a267"><span class="section-number-2">1</span> Coding conventions</h2>
|
|
<div class="outline-text-2" id="text-1">
|
|
<ul class="org-ul">
|
|
<li>integer types will be defined using types given in <code>stdint.h</code></li>
|
|
<li>pointers are always initialized to <code>NULL</code></li>
|
|
<li>when memory is freed, the pointer is set to <code>NULL</code></li>
|
|
<li><code>assert.h</code> should be used extensively</li>
|
|
<li>variable names are in lower case</li>
|
|
<li><code>#define</code> constants are in upper case</li>
|
|
<li>structs are suffixed by <code>_s</code></li>
|
|
<li>types are suffixed by <code>_t</code></li>
|
|
<li>API calls return <code>trexio_exit_code</code> (except for <code>trexio_open</code> function)</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div id="outline-container-org7284b59" class="outline-3">
|
|
<h3 id="org7284b59"><span class="section-number-3">1.1</span> Memory allocation</h3>
|
|
<div class="outline-text-3" id="text-1-1">
|
|
<p>
|
|
Memory allocation of structures can be facilitated by using the
|
|
following macros, which ensure that the size of the allocated
|
|
object is the same as the size of the data type pointed by the pointer.
|
|
For CALLOC, we allocate N+1 to avoid errors when N=0.
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #483d8b;">#define</span> <span style="color: #0000ff;">MALLOC</span>(<span style="color: #a0522d;">T</span>) (<span style="color: #228b22;">T</span>*) malloc (<span style="color: #a020f0;">sizeof</span>(T))
|
|
<span style="color: #483d8b;">#define</span> <span style="color: #0000ff;">CALLOC</span>(<span style="color: #a0522d;">N</span>,<span style="color: #a0522d;">T</span>) (<span style="color: #228b22;">T</span>*) calloc ( (N)+1 , <span style="color: #a020f0;">sizeof</span>(T) )
|
|
</pre>
|
|
</div>
|
|
|
|
<p>
|
|
When a pointer is freed, it should be set to <code>NULL</code>.
|
|
This can be facilitated by the use of the following macro:
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #483d8b;">#define</span> <span style="color: #0000ff;">FREE</span>(<span style="color: #a0522d;">X</span>) { free(X) ; (X)=<span style="color: #008b8b;">NULL</span>; }
|
|
</pre>
|
|
</div>
|
|
|
|
<p>
|
|
The maximum string size for the filenames is 4096 characters.
|
|
</p>
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">TREXIO_MAX_FILENAME_LENGTH</span> 4096
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orgca3a9a9" class="outline-2">
|
|
<h2 id="orgca3a9a9"><span class="section-number-2">2</span> Front end</h2>
|
|
<div class="outline-text-2" id="text-2">
|
|
<p>
|
|
All calls to TREXIO are thread-safe.
|
|
TREXIO front end is modular, which simplifies implementation of new back ends.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="outline-container-orgdac3f31" class="outline-3">
|
|
<h3 id="orgdac3f31"><span class="section-number-3">2.1</span> Error handling</h3>
|
|
<div class="outline-text-3" id="text-2-1">
|
|
<table id="org8713f71" border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
|
|
|
|
|
|
<colgroup>
|
|
<col class="org-left" />
|
|
|
|
<col class="org-right" />
|
|
|
|
<col class="org-left" />
|
|
</colgroup>
|
|
<thead>
|
|
<tr>
|
|
<th scope="col" class="org-left">Macro</th>
|
|
<th scope="col" class="org-right">Code</th>
|
|
<th scope="col" class="org-left">Description</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_FAILURE</code></td>
|
|
<td class="org-right">-1</td>
|
|
<td class="org-left">'Unknown failure'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_SUCCESS</code></td>
|
|
<td class="org-right">0</td>
|
|
<td class="org-left">'Success'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_INVALID_ARG_1</code></td>
|
|
<td class="org-right">1</td>
|
|
<td class="org-left">'Invalid argument 1'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_INVALID_ARG_2</code></td>
|
|
<td class="org-right">2</td>
|
|
<td class="org-left">'Invalid argument 2'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_INVALID_ARG_3</code></td>
|
|
<td class="org-right">3</td>
|
|
<td class="org-left">'Invalid argument 3'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_INVALID_ARG_4</code></td>
|
|
<td class="org-right">4</td>
|
|
<td class="org-left">'Invalid argument 4'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_INVALID_ARG_5</code></td>
|
|
<td class="org-right">5</td>
|
|
<td class="org-left">'Invalid argument 5'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_END</code></td>
|
|
<td class="org-right">6</td>
|
|
<td class="org-left">'End of file'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_READONLY</code></td>
|
|
<td class="org-right">7</td>
|
|
<td class="org-left">'Read-only file'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_ERRNO</code></td>
|
|
<td class="org-right">8</td>
|
|
<td class="org-left">strerror(errno)</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_INVALID_ID</code></td>
|
|
<td class="org-right">9</td>
|
|
<td class="org-left">'Invalid ID'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_ALLOCATION_FAILED</code></td>
|
|
<td class="org-right">10</td>
|
|
<td class="org-left">'Allocation failed'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_HAS_NOT</code></td>
|
|
<td class="org-right">11</td>
|
|
<td class="org-left">'Element absent'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_INVALID_NUM</code></td>
|
|
<td class="org-right">12</td>
|
|
<td class="org-left">'Invalid (negative or 0) dimension'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_ATTR_ALREADY_EXISTS</code></td>
|
|
<td class="org-right">13</td>
|
|
<td class="org-left">'Attribute already exists'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_DSET_ALREADY_EXISTS</code></td>
|
|
<td class="org-right">14</td>
|
|
<td class="org-left">'Dataset already exists'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_OPEN_ERROR</code></td>
|
|
<td class="org-right">15</td>
|
|
<td class="org-left">'Error opening file'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_LOCK_ERROR</code></td>
|
|
<td class="org-right">16</td>
|
|
<td class="org-left">'Error locking file'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_UNLOCK_ERROR</code></td>
|
|
<td class="org-right">17</td>
|
|
<td class="org-left">'Error unlocking file'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_FILE_ERROR</code></td>
|
|
<td class="org-right">18</td>
|
|
<td class="org-left">'Invalid file'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_GROUP_READ_ERROR</code></td>
|
|
<td class="org-right">19</td>
|
|
<td class="org-left">'Error reading group'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_GROUP_WRITE_ERROR</code></td>
|
|
<td class="org-right">20</td>
|
|
<td class="org-left">'Error writing group'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_ELEM_READ_ERROR</code></td>
|
|
<td class="org-right">21</td>
|
|
<td class="org-left">'Error reading element'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_ELEM_WRITE_ERROR</code></td>
|
|
<td class="org-right">22</td>
|
|
<td class="org-left">'Error writing element'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_UNSAFE_ARRAY_DIM</code></td>
|
|
<td class="org-right">23</td>
|
|
<td class="org-left">'Access to memory beyond allocated'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_ATTR_MISSING</code></td>
|
|
<td class="org-right">24</td>
|
|
<td class="org-left">'Attribute does not exist in the file'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_DSET_MISSING</code></td>
|
|
<td class="org-right">25</td>
|
|
<td class="org-left">'Dataset does not exist in the file'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_BACK_END_MISSING</code></td>
|
|
<td class="org-right">26</td>
|
|
<td class="org-left">'Requested back end is disabled'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_INVALID_ARG_6</code></td>
|
|
<td class="org-right">27</td>
|
|
<td class="org-left">'Invalid argument 6'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_INVALID_ARG_7</code></td>
|
|
<td class="org-right">28</td>
|
|
<td class="org-left">'Invalid argument 7'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_INVALID_ARG_8</code></td>
|
|
<td class="org-right">29</td>
|
|
<td class="org-left">'Invalid argument 8'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_INVALID_STR_LEN</code></td>
|
|
<td class="org-right">30</td>
|
|
<td class="org-left">'Invalid max<sub>str</sub><sub>len</sub>'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_INT_SIZE_OVERFLOW</code></td>
|
|
<td class="org-right">31</td>
|
|
<td class="org-left">'Possible integer overflow'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_SAFE_MODE</code></td>
|
|
<td class="org-right">32</td>
|
|
<td class="org-left">'Unsafe operation in safe mode'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_INVALID_ELECTRON_NUM</code></td>
|
|
<td class="org-right">33</td>
|
|
<td class="org-left">'Inconsistent number of electrons'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_INVALID_DETERMINANT_NUM</code></td>
|
|
<td class="org-right">34</td>
|
|
<td class="org-left">'Inconsistent number of determinants'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_INVALID_STATE</code></td>
|
|
<td class="org-right">35</td>
|
|
<td class="org-left">'Inconsistent state of the file'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_VERSION_PARSING_ISSUE</code></td>
|
|
<td class="org-right">36</td>
|
|
<td class="org-left">'Failed to parse package<sub>version</sub>'</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>TREXIO_PHASE_CHANGE</code></td>
|
|
<td class="org-right">37</td>
|
|
<td class="org-left">'The function succeeded with a change of sign'</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<p>
|
|
<b>IMPORTANT!</b>
|
|
The code below has to be executed within Emacs each time
|
|
a new error code is added to the table above. Otherwise, the codes
|
|
and the corresponding message are not propagated to the source code.
|
|
</p>
|
|
|
|
<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 :tangle prefix_front.h :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;">"#define {text:30s} ((trexio_exit_code) {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 :tangle prefix_fortran.f90 :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(trexio_exit_code), parameter :: {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 python :tangle prefix_python.py :exports none"</span> ]
|
|
<span style="color: #a0522d;">result</span> += [ <span style="color: #8b2252;">"# define TREXIO exit codes"</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;">"{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>
|
|
|
|
<div id="outline-container-org9a81de1" class="outline-4">
|
|
<h4 id="org9a81de1"><span class="section-number-4">2.1.1</span> Decoding errors</h4>
|
|
<div class="outline-text-4" id="text-2-1-1">
|
|
<p>
|
|
The <code>trexio_string_of_error</code> converts an exit code into a string. The
|
|
string is assumed to be large enough to contain the error message
|
|
(typically 128 characters).
|
|
</p>
|
|
|
|
<p>
|
|
To decode the error messages, <code>trexio_string_of_error</code> converts an
|
|
error code into a string.
|
|
</p>
|
|
|
|
<pre class="example">
|
|
128
|
|
</pre>
|
|
|
|
|
|
<p>
|
|
<b>IMPORTANT!</b>
|
|
The code below has to be executed within Emacs each time
|
|
a new error code is added to the table above. Otherwise, the codes
|
|
and the corresponding message are not propagated to the source code.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="outline-container-orge664bf7" class="outline-5">
|
|
<h5 id="orge664bf7"><span class="section-number-5">2.1.1.1</span> C source code</h5>
|
|
<div class="outline-text-5" id="text-2-1-1-1">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span>*
|
|
<span style="color: #0000ff;">trexio_string_of_error</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">error</span>)
|
|
{
|
|
<span style="color: #a020f0;">switch</span> (error) {
|
|
<span style="color: #a020f0;">case</span> TREXIO_FAILURE:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Unknown failure"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Success"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_INVALID_ARG_1:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Invalid argument 1"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_INVALID_ARG_2:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Invalid argument 2"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_INVALID_ARG_3:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Invalid argument 3"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_INVALID_ARG_4:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Invalid argument 4"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_INVALID_ARG_5:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Invalid argument 5"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_END:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"End of file"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_READONLY:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Read-only file"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_ERRNO:
|
|
<span style="color: #a020f0;">return</span> strerror(errno);
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_INVALID_ID:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Invalid ID"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_ALLOCATION_FAILED:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Allocation failed"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_HAS_NOT:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Element absent"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_INVALID_NUM:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Invalid (negative or 0) dimension"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_ATTR_ALREADY_EXISTS:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Attribute already exists"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_DSET_ALREADY_EXISTS:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Dataset already exists"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_OPEN_ERROR:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Error opening file"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_LOCK_ERROR:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Error locking file"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_UNLOCK_ERROR:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Error unlocking file"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_FILE_ERROR:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Invalid file"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_GROUP_READ_ERROR:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Error reading group"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_GROUP_WRITE_ERROR:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Error writing group"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_ELEM_READ_ERROR:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Error reading element"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_ELEM_WRITE_ERROR:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Error writing element"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_UNSAFE_ARRAY_DIM:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Access to memory beyond allocated"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_ATTR_MISSING:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Attribute does not exist in the file"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_DSET_MISSING:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Dataset does not exist in the file"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_BACK_END_MISSING:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Requested back end is disabled"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_INVALID_ARG_6:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Invalid argument 6"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_INVALID_ARG_7:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Invalid argument 7"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_INVALID_ARG_8:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Invalid argument 8"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_INVALID_STR_LEN:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Invalid max_str_len"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_INT_SIZE_OVERFLOW:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Possible integer overflow"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_SAFE_MODE:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Unsafe operation in safe mode"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_INVALID_ELECTRON_NUM:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Inconsistent number of electrons"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_INVALID_DETERMINANT_NUM:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Inconsistent number of determinants"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_INVALID_STATE:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Inconsistent state of the file"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_VERSION_PARSING_ISSUE:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Failed to parse package_version"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_PHASE_CHANGE:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"The function succeeded with a change of sign"</span>;
|
|
<span style="color: #a020f0;">break</span>;
|
|
}
|
|
<span style="color: #a020f0;">return</span> <span style="color: #8b2252;">"Unknown error"</span>;
|
|
}
|
|
|
|
<span style="color: #228b22;">void</span>
|
|
<span style="color: #0000ff;">trexio_string_of_error_f</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">error</span>, <span style="color: #228b22;">char</span> <span style="color: #a0522d;">result</span>[128])
|
|
{
|
|
strncpy(result, trexio_string_of_error(error), 128);
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orgf7b2253" class="outline-5">
|
|
<h5 id="orgf7b2253"><span class="section-number-5">2.1.1.2</span> Fortran interface</h5>
|
|
<div class="outline-text-5" id="text-2-1-1-2">
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #a020f0;">subroutine</span> <span style="color: #0000ff;">trexio_string_of_error</span> (error, string) <span style="color: #a020f0;">bind</span>(C, name=<span style="color: #8b2252;">'trexio_string_of_error_f'</span>)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> error</span>
|
|
<span style="color: #228b22;">character</span>(kind=<span style="color: #008b8b;">c_char</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> string(128)</span>
|
|
<span style="color: #a020f0;">end subroutine</span> <span style="color: #0000ff;">trexio_string_of_error</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org8eb3629" class="outline-5">
|
|
<h5 id="org8eb3629"><span class="section-number-5">2.1.1.3</span> Python interface</h5>
|
|
<div class="outline-text-5" id="text-2-1-1-3">
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">class</span> <span style="color: #228b22;">Error</span>(<span style="color: #228b22;">Exception</span>):
|
|
<span style="color: #8b2252;">"""Base class for TREXIO errors.</span>
|
|
|
|
<span style="color: #8b2252;"> Attributes:</span>
|
|
<span style="color: #8b2252;"> error: int -- exit code returned by the call to TREXIO library;</span>
|
|
<span style="color: #8b2252;"> message: str -- decoded string corresponding to trexio_exit_code.</span>
|
|
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a020f0;">def</span> <span style="color: #0000ff;">__init__</span>(<span style="color: #a020f0;">self</span>, trexio_return_code):
|
|
<span style="color: #a020f0;">self</span>.error = trexio_return_code
|
|
<span style="color: #a020f0;">self</span>.message = string_of_error(trexio_return_code)
|
|
<span style="color: #483d8b;">super</span>().__init__(<span style="color: #a020f0;">self</span>.message)
|
|
|
|
|
|
<span style="color: #a020f0;">def</span> <span style="color: #0000ff;">string_of_error</span>(return_code: <span style="color: #483d8b;">int</span>) -> <span style="color: #483d8b;">str</span>:
|
|
<span style="color: #8b2252;">"""Decode the TREXIO exit code.</span>
|
|
|
|
<span style="color: #8b2252;"> Argument is an integer return code that correspond to one of the TREXIO errors.</span>
|
|
<span style="color: #8b2252;"> Returns a string that contains description of TREXIO ~return_code~.</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a020f0;">return</span> pytr.trexio_string_of_error(return_code)
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org300904d" class="outline-3">
|
|
<h3 id="org300904d"><span class="section-number-3">2.2</span> Back ends</h3>
|
|
<div class="outline-text-3" id="text-2-2">
|
|
<p>
|
|
TREXIO has several back ends:
|
|
</p>
|
|
|
|
<ol class="org-ol">
|
|
<li><code>TREXIO_HDF5</code> relies on extensive use of the HDF5 library and the associated file format. The HDF5 file is binary and tailored to high-performance I/O. This back end is the default one. HDF5 can be compiled with MPI for parallel I/O. Note, that HDF5 has to be downloaded and installed independently of TREXIO, which may cause some obstacles, especially when the user is not allowed to install external software. The produced files usually have <code>.h5</code> extension.</li>
|
|
|
|
<li><code>TREXIO_TEXT</code> relies on basic file I/O in C, namely <code>fopen, fclose, fprintf, fscanf</code> etc. from <code>stdio.h</code> library. This back end is not optimized for performance. It is supposed to be used for debug purposes or, for example, when the user wants to modify some data manually within the file. This back end is supposed to work "out-of-the-box" since there are no external dependencies, which might be useful for users that do not have access to HDF5 library. The produced files usually have <code>.txt</code> extension.</li>
|
|
</ol>
|
|
|
|
<p>
|
|
<code>TREXIO_AUTO</code> can be provided as a back end when opening an existing TREXIO file in read-only <code>'r'</code> mode.
|
|
In this case, TREXIO will try to automatically detect the back end, which should be used to open the file.
|
|
</p>
|
|
|
|
<p>
|
|
Additional back ends can be implemented thanks to the modular nature of the front end.
|
|
This can be achieved by adding a new <code>case</code> (corresponding to the desired back end) in the front-end <code>switch</code>.
|
|
Then the corresponding back-end <code>has/read/write</code> functions has to be implemented. For example, see the commented
|
|
lines that correspond to the <code>TREXIO_JSON</code> back end (not implemented yet).
|
|
</p>
|
|
|
|
<p>
|
|
<span class="underline">Note</span>: It is important to increment the value of <code>TREXIO_INVALID_BACK_END</code> when a new back end is implemented. Otherwise, it will not be available.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="outline-container-org780c46b" class="outline-4">
|
|
<h4 id="org780c46b"><span class="section-number-4">2.2.1</span> C</h4>
|
|
<div class="outline-text-4" id="text-2-2-1">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #a020f0;">typedef</span> <span style="color: #228b22;">int32_t</span> <span style="color: #228b22;">back_end_t</span>;
|
|
|
|
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">TREXIO_HDF5</span> ( (<span style="color: #228b22;">back_end_t</span>) 0 )
|
|
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">TREXIO_TEXT</span> ( (<span style="color: #228b22;">back_end_t</span>) 1 )
|
|
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">TREXIO_INVALID_BACK_END</span> ( (<span style="color: #228b22;">back_end_t</span>) 2 )
|
|
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">TREXIO_AUTO</span> TREXIO_INVALID_BACK_END
|
|
/*<span style="color: #b22222;">#define TREXIO_JSON ( (back_end_t) 2 )</span>*/
|
|
|
|
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">TREXIO_DELIM</span> <span style="color: #8b2252;">"\n"</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<p>
|
|
The helper function <code>trexio_has_back_end</code> returns <code>true</code> if TREXIO compilation includes a back end provided as an argument; <code>false</code> otherwise.
|
|
This is useful due to the fact that HDF5 back end can be disabled at configure step.
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">bool</span> <span style="color: #0000ff;">trexio_has_backend</span>(<span style="color: #228b22;">back_end_t</span> <span style="color: #a0522d;">back_end</span>);
|
|
<span style="color: #228b22;">bool</span> <span style="color: #0000ff;">trexio_has_back_end</span>(<span style="color: #228b22;">back_end_t</span> <span style="color: #a0522d;">back_end</span>);
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">bool</span> <span style="color: #0000ff;">trexio_has_back_end</span>(<span style="color: #228b22;">back_end_t</span> <span style="color: #a0522d;">back_end</span>) {
|
|
<span style="color: #a020f0;">switch</span> (back_end) {
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">true</span>;
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">true</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">false</span>;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
}
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">false</span>;
|
|
}
|
|
|
|
<span style="color: #228b22;">bool</span> <span style="color: #0000ff;">trexio_has_backend</span>(<span style="color: #228b22;">back_end_t</span> <span style="color: #a0522d;">back_end</span>) {
|
|
<span style="color: #a020f0;">return</span> trexio_has_back_end(back_end);
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org2bf61ff" class="outline-4">
|
|
<h4 id="org2bf61ff"><span class="section-number-4">2.2.2</span> Fortran</h4>
|
|
<div class="outline-text-4" id="text-2-2-2">
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"> <span style="color: #228b22;">integer</span>(trexio_back_end_t), <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> TREXIO_HDF5 = 0</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_back_end_t), <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> TREXIO_TEXT = 1</span>
|
|
! <span style="color: #b22222;">integer(trexio_back_end_t), parameter :: TREXIO_JSON = 2</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_back_end_t), <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> TREXIO_INVALID_BACK_END = 2</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_back_end_t), <span style="color: #a020f0;">parameter</span> ::<span style="color: #a0522d;"> TREXIO_AUTO = TREXIO_INVALID_BACK_END</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<p>
|
|
The function below is a Fortran interface for the aforementioned C-compatible <code>trexio_has_back_end</code> function.
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">logical</span>(<span style="color: #008b8b;">c_bool</span>) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_has_back_end</span> (back_end) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_back_end_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> back_end</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_has_back_end</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
|
|
<span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">logical</span>(<span style="color: #008b8b;">c_bool</span>) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_has_backend</span> (back_end) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_back_end_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> back_end</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_has_backend</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<p>
|
|
Originally, the function was named <code>trexio_has_backend</code>. For
|
|
consistency, in version 2.2 it was renamed <code>trexio_has_back_end</code>.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orge58f298" class="outline-4">
|
|
<h4 id="orge58f298"><span class="section-number-4">2.2.3</span> Python</h4>
|
|
<div class="outline-text-4" id="text-2-2-3">
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"># <span style="color: #b22222;">define TREXIO back ends</span>
|
|
<span style="color: #a0522d;">TREXIO_HDF5</span> = 0
|
|
<span style="color: #a0522d;">TREXIO_TEXT</span> = 1
|
|
#<span style="color: #b22222;">TREXIO_JSON = 2</span>
|
|
<span style="color: #a0522d;">TREXIO_INVALID_BACK_END</span> = 2
|
|
<span style="color: #a0522d;">TREXIO_AUTO</span> = TREXIO_INVALID_BACK_END
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org0b247fc" class="outline-3">
|
|
<h3 id="org0b247fc"><span class="section-number-3">2.3</span> Read/write behavior</h3>
|
|
<div class="outline-text-3" id="text-2-3">
|
|
<p>
|
|
Every time a reading function is called, the data is read from the
|
|
disk. If data needs to be cached, this is left to the user of the
|
|
library.
|
|
</p>
|
|
|
|
<p>
|
|
Writing to TREXIO files is done with transactions (all-or-nothing
|
|
effect). File writes are attempted by
|
|
calling explicitly the write (<code>TREXIO_HDF5</code>) or flush (<code>TREXIO_TEXT</code>)
|
|
function, or when the TREXIO file is closed.
|
|
If writing is impossible because the data is not valid, no data is written.
|
|
</p>
|
|
|
|
<p>
|
|
The order in which the data is written is not necessarily consistent
|
|
with the order in which the function calls were made.
|
|
</p>
|
|
|
|
<p>
|
|
The TREXIO files are supposed to be opened by only one program at a
|
|
time: if the same TREXIO file is modified simultaneously by multiple
|
|
concurrent programs, the behavior is not specified.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org4de6ab6" class="outline-3">
|
|
<h3 id="org4de6ab6"><span class="section-number-3">2.4</span> TREXIO file type</h3>
|
|
<div class="outline-text-3" id="text-2-4">
|
|
<p>
|
|
<code>trexio_s</code> is the the main type for TREXIO files, visible to the users
|
|
of the library. This type is kept opaque, and all modifications to
|
|
the files will be necessarily done through the use of functions,
|
|
taking such a type as argument.
|
|
</p>
|
|
|
|
<p>
|
|
File creation and opening functions will return <i>TREXIO file handles</i>,
|
|
namely pointers to <code>trexio_s</code> types. All functions accessing to the
|
|
TREXIO files will have as a first argument the TREXIO file handle.
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #a020f0;">typedef</span> <span style="color: #a020f0;">struct</span> <span style="color: #228b22;">trexio_s</span> <span style="color: #228b22;">trexio_t</span>;
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #a020f0;">struct</span> <span style="color: #228b22;">trexio_s</span> {
|
|
<span style="color: #228b22;">pthread_mutex_t</span> <span style="color: #a0522d;">thread_lock</span>;
|
|
<span style="color: #228b22;">back_end_t</span> <span style="color: #a0522d;">back_end</span>;
|
|
<span style="color: #228b22;">char</span> <span style="color: #a0522d;">mode</span>;
|
|
<span style="color: #228b22;">bool</span> <span style="color: #a0522d;">one_based</span>;
|
|
<span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">state</span>;
|
|
<span style="color: #228b22;">int16_t</span> <span style="color: #a0522d;">version_major</span>;
|
|
<span style="color: #228b22;">int16_t</span> <span style="color: #a0522d;">version_minor</span>;
|
|
<span style="color: #228b22;">int16_t</span> <span style="color: #a0522d;">version_patch</span>;
|
|
<span style="color: #228b22;">char</span> <span style="color: #a0522d;">version</span>[16];
|
|
<span style="color: #228b22;">char</span> <span style="color: #a0522d;">file_name</span>[TREXIO_MAX_FILENAME_LENGTH];
|
|
};
|
|
</pre>
|
|
</div>
|
|
|
|
|
|
<p>
|
|
File class for the Python API is defined below.
|
|
Use of Python class make it more intuitive and more python-ic
|
|
to work with TREXIO files.
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">class</span> <span style="color: #228b22;">File</span>:
|
|
<span style="color: #8b2252;">"""trexio.File class.</span>
|
|
|
|
<span style="color: #8b2252;"> General information about the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameters:</span>
|
|
|
|
<span style="color: #8b2252;"> filename: str</span>
|
|
<span style="color: #8b2252;"> Is a name of the full path to the TREXIO file.</span>
|
|
<span style="color: #8b2252;"> back_end: int</span>
|
|
<span style="color: #8b2252;"> One of the currently supported TREXIO back ends.</span>
|
|
<span style="color: #8b2252;"> For example, TREXIO_HDF5 (0) or TREXIO_TEXT (1).</span>
|
|
<span style="color: #8b2252;"> mode: str</span>
|
|
<span style="color: #8b2252;"> One of the currently supported TREXIO open modes.</span>
|
|
<span style="color: #8b2252;"> For example, 'r' or 'w'.</span>
|
|
<span style="color: #8b2252;"> state: int</span>
|
|
<span style="color: #8b2252;"> Active (excited or ground) state of the file.</span>
|
|
<span style="color: #8b2252;"> Default is 0.</span>
|
|
<span style="color: #8b2252;"> isOpen: bool</span>
|
|
<span style="color: #8b2252;"> Flag indicating whether the current object is still open for I/O</span>
|
|
<span style="color: #8b2252;"> pytrexio_s:</span>
|
|
<span style="color: #8b2252;"> A PyObject corresponding to SWIG proxy of the trexio_s struct in C.</span>
|
|
<span style="color: #8b2252;"> This argument is in fact a TREXIO file handle, which is required for</span>
|
|
<span style="color: #8b2252;"> communicating with the C back end.</span>
|
|
<span style="color: #8b2252;"> info: dict</span>
|
|
<span style="color: #8b2252;"> Dictionary of key-value pairs with additional information about the file.</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
|
|
<span style="color: #a020f0;">def</span> <span style="color: #0000ff;">__init__</span>(<span style="color: #a020f0;">self</span>, filename, mode=<span style="color: #8b2252;">'r'</span>, back_end=TREXIO_HDF5,
|
|
pytrexio_s=<span style="color: #008b8b;">None</span>, info=<span style="color: #008b8b;">None</span>):
|
|
<span style="color: #8b2252;">"""TREXIO File class constructor."""</span>
|
|
<span style="color: #a020f0;">self</span>.filename = filename
|
|
<span style="color: #a020f0;">self</span>.mode = mode
|
|
<span style="color: #a020f0;">self</span>.state = 0
|
|
|
|
<span style="color: #a020f0;">self</span>.isOpen = <span style="color: #008b8b;">False</span>
|
|
<span style="color: #a020f0;">self</span>.exists = <span style="color: #008b8b;">False</span>
|
|
<span style="color: #a020f0;">if</span> pytrexio_s <span style="color: #a020f0;">is</span> <span style="color: #008b8b;">None</span>:
|
|
<span style="color: #a020f0;">self</span>.pytrexio_s = _open(filename, mode, back_end)
|
|
<span style="color: #a020f0;">self</span>.isOpen = <span style="color: #008b8b;">True</span>
|
|
<span style="color: #a020f0;">self</span>.exists = <span style="color: #008b8b;">True</span>
|
|
<span style="color: #a020f0;">else</span>:
|
|
<span style="color: #a020f0;">self</span>.pytrexio_s = pytrexio_s
|
|
<span style="color: #a020f0;">self</span>.isOpen = <span style="color: #008b8b;">None</span>
|
|
<span style="color: #a020f0;">self</span>.exists = <span style="color: #008b8b;">None</span>
|
|
|
|
<span style="color: #a020f0;">self</span>.back_end = <span style="color: #a020f0;">self</span>.pytrexio_s.back_end
|
|
<span style="color: #a020f0;">self</span>.info = info
|
|
|
|
|
|
<span style="color: #a020f0;">def</span> <span style="color: #0000ff;">__enter__</span>(<span style="color: #a020f0;">self</span>):
|
|
<span style="color: #8b2252;">"""Enter statement for with ... as ... handling."""</span>
|
|
<span style="color: #a020f0;">return</span> <span style="color: #a020f0;">self</span>
|
|
|
|
|
|
<span style="color: #a020f0;">def</span> <span style="color: #0000ff;">__exit__</span>(<span style="color: #a020f0;">self</span>, *args):
|
|
<span style="color: #8b2252;">"""Exit statement for with ... as ... handling."""</span>
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">self</span>.isOpen:
|
|
<span style="color: #a020f0;">self</span>.close()
|
|
|
|
|
|
<span style="color: #a020f0;">def</span> <span style="color: #0000ff;">close</span>(<span style="color: #a020f0;">self</span>):
|
|
<span style="color: #8b2252;">"""Close a TREXIO File."""</span>
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">self</span>.isOpen:
|
|
_close(<span style="color: #a020f0;">self</span>.pytrexio_s)
|
|
<span style="color: #a020f0;">self</span>.isOpen = <span style="color: #008b8b;">False</span>
|
|
<span style="color: #a020f0;">else</span>:
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">Exception</span>(<span style="color: #8b2252;">"TREXIO File object has not been opened."</span>)
|
|
|
|
|
|
<span style="color: #a020f0;">def</span> <span style="color: #0000ff;">set_state</span>(<span style="color: #a020f0;">self</span>, state):
|
|
<span style="color: #8b2252;">"""Set the state of the TREXIO File."""</span>
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">not</span> <span style="color: #483d8b;">isinstance</span>(state, <span style="color: #483d8b;">int</span>):
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">TypeError</span>(<span style="color: #8b2252;">"state argument has to be int"</span>)
|
|
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_set_state(<span style="color: #a020f0;">self</span>.pytrexio_s, state)
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
|
|
<span style="color: #a020f0;">self</span>.state = state
|
|
|
|
|
|
<span style="color: #a020f0;">def</span> <span style="color: #0000ff;">get_state</span>(<span style="color: #a020f0;">self</span>):
|
|
<span style="color: #8b2252;">"""Get the state of the TREXIO File."""</span>
|
|
<span style="color: #a0522d;">rc</span>, <span style="color: #a0522d;">state</span> = pytr.trexio_get_state(<span style="color: #a020f0;">self</span>.pytrexio_s)
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
|
|
<span style="color: #a020f0;">if</span> state != <span style="color: #a020f0;">self</span>.state:
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">Exception</span>(<span style="color: #8b2252;">"Inconsistent state of the TREXIO file."</span>)
|
|
|
|
<span style="color: #a020f0;">return</span> <span style="color: #a020f0;">self</span>.state
|
|
|
|
|
|
<span style="color: #a020f0;">def</span> <span style="color: #0000ff;">flush</span>(<span style="color: #a020f0;">self</span>):
|
|
<span style="color: #8b2252;">"""Flush the data on disk."""</span>
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_flush(<span style="color: #a020f0;">self</span>.pytrexio_s)
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
|
|
|
|
<span style="color: #a020f0;">def</span> <span style="color: #0000ff;">inquire</span>(<span style="color: #a020f0;">self</span>):
|
|
<span style="color: #8b2252;">"""Inquire whether a TREXIO file exists."""</span>
|
|
<span style="color: #a020f0;">self</span>.exists = _inquire(<span style="color: #a020f0;">self</span>.filename)
|
|
|
|
|
|
<span style="color: #a020f0;">def</span> <span style="color: #0000ff;">__del__</span>(<span style="color: #a020f0;">self</span>):
|
|
<span style="color: #8b2252;">"""TREXIO File class destructor."""</span>
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">self</span>.isOpen:
|
|
_close(<span style="color: #a020f0;">self</span>.pytrexio_s)
|
|
<span style="color: #a020f0;">elif</span> <span style="color: #a020f0;">self</span>.isOpen <span style="color: #a020f0;">is</span> <span style="color: #008b8b;">None</span>:
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">Exception</span>(<span style="color: #8b2252;">"[WIP]: TREXIO file handle provided but what if the file is already closed?"</span>)
|
|
<span style="color: #a020f0;">else</span>:
|
|
<span style="color: #a020f0;">pass</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orge353a83" class="outline-3">
|
|
<h3 id="orge353a83"><span class="section-number-3">2.5</span> File opening</h3>
|
|
<div class="outline-text-3" id="text-2-5">
|
|
<p>
|
|
<code>trexio_open</code> creates a new TREXIO file or opens the existing one.
|
|
</p>
|
|
|
|
<p>
|
|
<b><b>Input parameters:</b></b>
|
|
</p>
|
|
<ol class="org-ol">
|
|
<li><code>file_name</code> - string containing file name</li>
|
|
<li><code>mode</code> - character containing open mode (see below)
|
|
<ul class="org-ul">
|
|
<li><code>'w'</code> - (write) creates a new file as READWRITE</li>
|
|
<li><code>'r'</code> - (read) opens existing file as READONLY</li>
|
|
<li><code>'u'</code> - (unsafe) opens existing file as READWRITE with the possibility to overwrite blocks and delete full groups.</li>
|
|
</ul></li>
|
|
<li><code>back_end</code> - integer number (or the corresponding global parameter) specifying the back end
|
|
<ul class="org-ul">
|
|
<li><code>TREXIO_HDF5</code> - for HDF5 back end (integer alternative: 0)</li>
|
|
<li><code>TREXIO_TEXT</code> - for TEXT back end (integer alternative: 1)</li>
|
|
<li><code>TREXIO_AUTO</code> - to automatically detect the applicable back end</li>
|
|
</ul></li>
|
|
</ol>
|
|
|
|
<p>
|
|
<b><b>Output:</b></b>
|
|
</p>
|
|
<ul class="org-ul">
|
|
<li>Pointer to the <code>trexio_t</code> (struct) file handle.</li>
|
|
</ul>
|
|
|
|
<p>
|
|
Upon creation of the TREXIO file, the <code>package_version</code> attribute of the
|
|
<code>metadata</code> group is set to the <code>TREXIO_PACKAGE_VERSION</code> string.
|
|
This attribute <b><b>is not</b></b> automatically updated when the file is modified with
|
|
newer versions. However, this can be done manually by the user in unsafe mode.
|
|
</p>
|
|
|
|
<p>
|
|
<b><b>Note:</b></b> internal consistency is not guaranteed once the file has been modified in <code>'u'</code> (unsafe) mode.
|
|
Upon the first unsafe call to <code>trexio_open</code> the <code>unsafe</code> attribute of the <code>metadata</code> group will be set
|
|
to 1 (true) in order to indicate that the file might be inconsistent due to the use of <code>'u'</code> mode.
|
|
</p>
|
|
|
|
<p>
|
|
<b><b>Note:</b></b> the <code>file_name</code> in TEXT back end actually corresponds to the
|
|
name of the directory where <code>.txt</code> data files are stored. The
|
|
actual name of each <code>.txt</code> file corresponds to the group name
|
|
provided in <code>trex.config</code> (e.g. <code>nucleus.txt</code> for nuclei-related
|
|
data). These names are populated by the generator.py (i.e. they
|
|
are hard-coded), which is why the user should tend to avoid
|
|
renaming the <code>.txt</code> data files.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="outline-container-org27173a5" class="outline-4">
|
|
<h4 id="org27173a5"><span class="section-number-4">2.5.1</span> C</h4>
|
|
<div class="outline-text-4" id="text-2-5-1">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_t</span>*
|
|
<span style="color: #0000ff;">trexio_open</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span>* <span style="color: #a0522d;">file_name</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span> <span style="color: #a0522d;">mode</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">back_end_t</span> <span style="color: #a0522d;">back_end</span>, <span style="color: #228b22;">trexio_exit_code</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">rc_open</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file_name == <span style="color: #008b8b;">NULL</span> || file_name[0] == <span style="color: #8b2252;">'\0'</span>) {
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
|
}
|
|
/* <span style="color: #b22222;">Check overflow in file_name</span> */
|
|
|
|
/* <span style="color: #b22222;">Check that the mode is valid</span> */
|
|
<span style="color: #a020f0;">if</span> (mode != <span style="color: #8b2252;">'r'</span> && mode != <span style="color: #8b2252;">'w'</span> && mode != <span style="color: #8b2252;">'u'</span>) {
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
|
}
|
|
|
|
/* <span style="color: #b22222;">Check that the back end is valid in non-read mode</span> */
|
|
<span style="color: #a020f0;">if</span> ((back_end < 0 || back_end >= TREXIO_INVALID_BACK_END) && mode != <span style="color: #8b2252;">'r'</span>) {
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = TREXIO_INVALID_ARG_3;
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
|
}
|
|
|
|
/* <span style="color: #b22222;">Check that the back end is valid in read-only mode</span> */
|
|
<span style="color: #a020f0;">if</span> ((back_end < 0 || back_end > TREXIO_INVALID_BACK_END) && mode == <span style="color: #8b2252;">'r'</span>) {
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = TREXIO_INVALID_ARG_3;
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
|
}
|
|
|
|
<span style="color: #228b22;">back_end_t</span> <span style="color: #a0522d;">back_end_local</span> = back_end;
|
|
/* <span style="color: #b22222;">Try to determine the applicable backend if the back_end argument is TREXIO_AUTO</span> */
|
|
<span style="color: #a020f0;">if</span> (back_end == TREXIO_AUTO && mode == <span style="color: #8b2252;">'r'</span>) {
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
/* <span style="color: #b22222;">Check if the TREXIO file exists and if it is a directory</span> */
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc_text</span> = trexio_text_inquire(file_name);
|
|
<span style="color: #a020f0;">if</span> (rc_text == TREXIO_SUCCESS) {
|
|
back_end_local = TREXIO_TEXT;
|
|
} <span style="color: #a020f0;">else</span> {
|
|
/* <span style="color: #b22222;">If not, check if it is an HDF5 file</span> */
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc_hdf5</span> = trexio_hdf5_inquire(file_name);
|
|
<span style="color: #a020f0;">if</span> (rc_hdf5 == TREXIO_SUCCESS) {
|
|
back_end_local = TREXIO_HDF5;
|
|
} <span style="color: #a020f0;">else</span> {
|
|
/* <span style="color: #b22222;">File is neither a directory nor an HDF5 file -> return an error</span> */
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = TREXIO_FILE_ERROR;
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
|
}
|
|
}
|
|
<span style="color: #483d8b;">#else</span>
|
|
/* <span style="color: #b22222;">In the current implementation if HDF5 back end is not available - then there is only back end left</span> */
|
|
back_end_local = TREXIO_TEXT;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
}
|
|
|
|
<span style="color: #228b22;">trexio_t</span>* <span style="color: #a0522d;">result</span> = <span style="color: #008b8b;">NULL</span>;
|
|
<span style="color: #228b22;">void</span>* <span style="color: #a0522d;">result_tmp</span> = <span style="color: #008b8b;">NULL</span>;
|
|
|
|
/* <span style="color: #b22222;">Allocate data structures</span> */
|
|
<span style="color: #a020f0;">switch</span> (back_end_local) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
result_tmp = malloc(<span style="color: #a020f0;">sizeof</span>(trexio_text_t));
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
result_tmp = malloc(<span style="color: #a020f0;">sizeof</span>(trexio_hdf5_t));
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = TREXIO_BACK_END_MISSING;
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
|
|
<span style="color: #a020f0;">default</span>:
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = TREXIO_FILE_ERROR;
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
|
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> result = (trexio_t*) malloc (sizeof(trexio_json_t));</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
result = (<span style="color: #228b22;">trexio_t</span>*) result_tmp;
|
|
|
|
assert (result != <span style="color: #008b8b;">NULL</span>); /* <span style="color: #b22222;">TODO: Error handling</span> */
|
|
|
|
/* <span style="color: #b22222;">Data for the parent type</span> */
|
|
|
|
strncpy(result->file_name, file_name, TREXIO_MAX_FILENAME_LENGTH);
|
|
<span style="color: #a020f0;">if</span> (result->file_name[TREXIO_MAX_FILENAME_LENGTH-1] != <span style="color: #8b2252;">'\0'</span>) {
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = TREXIO_INVALID_ARG_1;
|
|
free(result);
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
|
}
|
|
|
|
result->back_end = back_end_local;
|
|
result->mode = mode;
|
|
result->one_based = <span style="color: #008b8b;">false</span>; // <span style="color: #b22222;">Need to be flipped in Fortran interface</span>
|
|
result->state = 0; // <span style="color: #b22222;">By default the file corresponds to a ground state</span>
|
|
<span style="color: #228b22;">int</span> <span style="color: #a0522d;">irc</span> = pthread_mutex_init ( &(result->thread_lock), <span style="color: #008b8b;">NULL</span>);
|
|
<span style="color: #a020f0;">if</span> (irc != 0) {
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = TREXIO_FAILURE;
|
|
free(result);
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
|
}
|
|
// <span style="color: #b22222;">assert (irc == 0);</span>
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span>;
|
|
|
|
/* <span style="color: #b22222;">Back end initialization</span> */
|
|
|
|
rc = TREXIO_OPEN_ERROR;
|
|
|
|
<span style="color: #a020f0;">switch</span> (back_end_local) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
rc = trexio_text_init(result);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
rc = trexio_hdf5_init(result);
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = TREXIO_BACK_END_MISSING;
|
|
free(result);
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> rc = trexio_json_init(result);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) {
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = TREXIO_OPEN_ERROR;
|
|
free(result);
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
|
}
|
|
|
|
|
|
/* <span style="color: #b22222;">File locking</span> */
|
|
|
|
rc = TREXIO_LOCK_ERROR;
|
|
|
|
<span style="color: #a020f0;">switch</span> (back_end_local) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
rc = trexio_text_lock(result);
|
|
<span style="color: #a020f0;">break</span>;
|
|
/* <span style="color: #b22222;">HDF5 v.>=1.10 has file locking activated by default</span> */
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
rc = TREXIO_SUCCESS;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = TREXIO_BACK_END_MISSING;
|
|
free(result);
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> rc = trexio_json_lock(result);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) {
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = TREXIO_LOCK_ERROR;
|
|
free(result);
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
|
}
|
|
|
|
/* <span style="color: #b22222;">Write metadata (i.e. package version) upon creation</span> */
|
|
rc = trexio_has_metadata_package_version(result);
|
|
<span style="color: #a020f0;">if</span> (rc == TREXIO_FAILURE) {
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = TREXIO_OPEN_ERROR;
|
|
free(result);
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
|
}
|
|
|
|
<span style="color: #a020f0;">if</span> (rc == TREXIO_HAS_NOT) {
|
|
/* <span style="color: #b22222;">Write TREXIO_PACKAGE_VERSION upon creation of the file</span> */
|
|
<span style="color: #a020f0;">switch</span> (back_end_local) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
rc = trexio_text_write_metadata_package_version(result, TREXIO_PACKAGE_VERSION);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
rc = trexio_hdf5_write_metadata_package_version(result, TREXIO_PACKAGE_VERSION);
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = TREXIO_BACK_END_MISSING;
|
|
free(result);
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
|
|
}
|
|
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) {
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = rc;
|
|
free(result);
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
|
}
|
|
|
|
result->version_major = TREXIO_VERSION_MAJOR;
|
|
result->version_minor = TREXIO_VERSION_MINOR;
|
|
result->version_patch = TREXIO_VERSION_PATCH;
|
|
strncpy(result->version, TREXIO_PACKAGE_VERSION, 16);
|
|
|
|
} <span style="color: #a020f0;">else</span> {
|
|
/* <span style="color: #b22222;">Otherwise read the metadata_package_version to get the TREXIO version upon creation of the file</span> */
|
|
<span style="color: #228b22;">char</span> <span style="color: #a0522d;">version_origin</span>[16];
|
|
|
|
<span style="color: #a020f0;">switch</span> (back_end_local) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
rc = trexio_text_read_metadata_package_version(result, version_origin, 16);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
rc = trexio_hdf5_read_metadata_package_version(result, version_origin, 16);
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = TREXIO_BACK_END_MISSING;
|
|
free(result);
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
|
|
}
|
|
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) {
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = rc;
|
|
free(result);
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
|
}
|
|
|
|
<span style="color: #228b22;">int16_t</span> <span style="color: #a0522d;">version_major</span>, <span style="color: #a0522d;">version_minor</span>, <span style="color: #a0522d;">version_patch</span>;
|
|
<span style="color: #228b22;">int</span> <span style="color: #a0522d;">rc_scan</span> = sscanf(version_origin,
|
|
<span style="color: #8b2252;">"%3"</span> SCNd16 <span style="color: #8b2252;">".%5"</span> SCNd16 <span style="color: #8b2252;">".%5"</span> SCNd16,
|
|
&version_major, &version_minor, &version_patch);
|
|
<span style="color: #a020f0;">if</span> (rc_scan != 3) {
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = TREXIO_VERSION_PARSING_ISSUE;
|
|
free(result);
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
|
}
|
|
|
|
result->version_major = version_major;
|
|
result->version_minor = version_minor;
|
|
result->version_patch = version_patch;
|
|
strncpy(result->version, version_origin, 16);
|
|
|
|
}
|
|
|
|
<span style="color: #a020f0;">if</span> (result->version[15] != <span style="color: #8b2252;">'\0'</span> || result->version_major == 0) {
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = TREXIO_FAILURE;
|
|
free(result);
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
|
}
|
|
|
|
/* <span style="color: #b22222;">Mark the file as unsafe upon opening in UNSAFE 'u' mode</span> */
|
|
<span style="color: #a020f0;">if</span> (mode == <span style="color: #8b2252;">'u'</span>) {
|
|
|
|
rc = trexio_has_metadata_unsafe(result);
|
|
<span style="color: #a020f0;">if</span> (rc == TREXIO_FAILURE) {
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = TREXIO_OPEN_ERROR;
|
|
free(result);
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
|
}
|
|
|
|
<span style="color: #a020f0;">if</span> (rc == TREXIO_HAS_NOT) {
|
|
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">unsafe_val</span> = 1;
|
|
<span style="color: #a020f0;">switch</span> (back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
rc = trexio_text_write_metadata_unsafe(result, unsafe_val);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
rc = trexio_hdf5_write_metadata_unsafe(result, unsafe_val);
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = TREXIO_BACK_END_MISSING;
|
|
free(result);
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
}
|
|
}
|
|
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) {
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = rc;
|
|
free(result);
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">NULL</span>;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/* <span style="color: #b22222;">Exit upon success</span> */
|
|
<span style="color: #a020f0;">if</span> (rc_open != <span style="color: #008b8b;">NULL</span>) *rc_open = TREXIO_SUCCESS;
|
|
|
|
<span style="color: #a020f0;">return</span> result;
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org9f788cb" class="outline-4">
|
|
<h4 id="org9f788cb"><span class="section-number-4">2.5.2</span> Fortran</h4>
|
|
<div class="outline-text-4" id="text-2-5-2">
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_open_c</span> (filename, mode, back_end, rc_open)<span style="color: #a0522d;"> </span><span style="color: #a020f0;">&</span>
|
|
<span style="color: #a020f0;">bind</span>(C, name=<span style="color: #8b2252;">"trexio_open"</span>)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">character</span>(kind=<span style="color: #008b8b;">c_char</span>), <span style="color: #a020f0;">dimension</span>(*) ::<span style="color: #a0522d;"> filename</span>
|
|
<span style="color: #228b22;">character</span>(kind=<span style="color: #008b8b;">c_char</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> mode</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_back_end_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> back_end</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> rc_open</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_open_c</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org96e7db5" class="outline-4">
|
|
<h4 id="org96e7db5"><span class="section-number-4">2.5.3</span> Python</h4>
|
|
<div class="outline-text-4" id="text-2-5-3">
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">_open</span>(file_name: <span style="color: #483d8b;">str</span>, mode: <span style="color: #483d8b;">str</span>, back_end: <span style="color: #483d8b;">int</span>):
|
|
<span style="color: #8b2252;">"""Create TREXIO file or open existing one.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameters:</span>
|
|
|
|
<span style="color: #8b2252;"> file_name: str</span>
|
|
<span style="color: #8b2252;"> Name of the TREXIO file</span>
|
|
|
|
<span style="color: #8b2252;"> mode: str</span>
|
|
<span style="color: #8b2252;"> One of the currently supported ~open~ modes (e.g. 'w', 'r')</span>
|
|
|
|
<span style="color: #8b2252;"> back_end: int</span>
|
|
<span style="color: #8b2252;"> One of the currently supported TREXIO back ends (e.g. TREXIO_HDF5, TREXIO_TEXT)</span>
|
|
|
|
<span style="color: #8b2252;"> Return:</span>
|
|
<span style="color: #8b2252;"> SWIG object of type trexio_s.</span>
|
|
|
|
<span style="color: #8b2252;"> Examples:</span>
|
|
<span style="color: #8b2252;"> >>> from trexio import open as tr_open</span>
|
|
<span style="color: #8b2252;"> >>> trex_file = tr_open("example.h5", "w", TREXIO_HDF5)</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
# <span style="color: #b22222;">The new trexio_open function is capable of returning error code which SWIG can append to the output trexio_s file struct</span>
|
|
# <span style="color: #b22222;">However, if trexio_s* == NULL, then SWIG returns only an error code rc_open instead of a list [trexio_s, rc_open]</span>
|
|
# <span style="color: #b22222;">Thus, the following try/except sequence is needed</span>
|
|
<span style="color: #a020f0;">try</span>:
|
|
<span style="color: #a0522d;">return_obj</span> = pytr.trexio_open(file_name, mode, back_end)
|
|
<span style="color: #a020f0;">assert</span> return_obj <span style="color: #a020f0;">is</span> <span style="color: #a020f0;">not</span> <span style="color: #008b8b;">None</span>
|
|
<span style="color: #a020f0;">if</span> <span style="color: #483d8b;">isinstance</span>(return_obj, <span style="color: #483d8b;">int</span>):
|
|
<span style="color: #a020f0;">raise</span> Error(return_obj)
|
|
<span style="color: #a020f0;">else</span>:
|
|
<span style="color: #a0522d;">rc_open</span> = return_obj[1]
|
|
# <span style="color: #b22222;">this is a sanity check in case the code evolves and SWIG issue is patched</span>
|
|
<span style="color: #a020f0;">if</span> rc_open == TREXIO_SUCCESS:
|
|
<span style="color: #a0522d;">trexio_file</span> = return_obj[0]
|
|
<span style="color: #a020f0;">assert</span> trexio_file <span style="color: #a020f0;">is</span> <span style="color: #a020f0;">not</span> <span style="color: #008b8b;">None</span>
|
|
<span style="color: #a020f0;">except</span> <span style="color: #228b22;">AssertionError</span>:
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">Exception</span>(f<span style="color: #8b2252;">"Could not open TREXIO file {file_name} using trexio_open function. The return value is None (NULL pointer)."</span>)
|
|
|
|
<span style="color: #a020f0;">return</span> trexio_file
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org9db402f" class="outline-4">
|
|
<h4 id="org9db402f"><span class="section-number-4">2.5.4</span> Zero-based versus one-based arrays of indices</h4>
|
|
<div class="outline-text-4" id="text-2-5-4">
|
|
<p>
|
|
Because arrays are zero-based in Fortran, we need to set a flag to
|
|
know if we need to shift by 1 arrays of indices.
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span> <span style="color: #0000ff;">trexio_set_one_based</span>(<span style="color: #228b22;">trexio_t</span>* <span style="color: #a0522d;">file</span>)
|
|
{
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_FILE_ERROR;
|
|
|
|
file->one_based = <span style="color: #008b8b;">true</span>;
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_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>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_set_one_based</span>(trex_file) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_set_one_based</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orgf3938ff" class="outline-3">
|
|
<h3 id="orgf3938ff"><span class="section-number-3">2.6</span> File closing</h3>
|
|
<div class="outline-text-3" id="text-2-6">
|
|
<p>
|
|
<code>trexio_close</code> closes an existing <code>trexio_t</code> file.
|
|
</p>
|
|
|
|
<p>
|
|
input parameters:
|
|
<code>file</code> – TREXIO file handle.
|
|
</p>
|
|
|
|
<p>
|
|
output:
|
|
<code>trexio_exit_code</code> exit code.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="outline-container-orgcf29d82" class="outline-4">
|
|
<h4 id="orgcf29d82"><span class="section-number-4">2.6.1</span> C</h4>
|
|
<div class="outline-text-4" id="text-2-6-1">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_close</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a0522d;">file</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_FILE_ERROR;
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span> = TREXIO_FAILURE;
|
|
|
|
assert(file->back_end < TREXIO_INVALID_BACK_END);
|
|
|
|
/* <span style="color: #b22222;">Things to be done before closing the file in the back-end</span> */
|
|
rc = trexio_pre_close(file);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
/* <span style="color: #b22222;">Terminate the back end</span> */
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
rc = trexio_text_deinit(file);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
rc = trexio_hdf5_deinit(file);
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
FREE(file);
|
|
<span style="color: #a020f0;">return</span> TREXIO_BACK_END_MISSING;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> rc = trexio_json_deinit(file);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) {
|
|
FREE(file);
|
|
<span style="color: #a020f0;">return</span> rc;
|
|
}
|
|
|
|
/* <span style="color: #b22222;">File unlocking</span> */
|
|
|
|
rc = TREXIO_UNLOCK_ERROR;
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
rc = trexio_text_unlock(file);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
rc = TREXIO_SUCCESS;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
FREE(file);
|
|
<span style="color: #a020f0;">return</span> TREXIO_BACK_END_MISSING;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> rc = trexio_json_unlock(file);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
|
|
/* <span style="color: #b22222;">Terminate front end</span> */
|
|
|
|
<span style="color: #228b22;">int</span> <span style="color: #a0522d;">irc</span> = pthread_mutex_destroy( &(file->thread_lock) );
|
|
|
|
free(file);
|
|
|
|
<span style="color: #a020f0;">if</span> (irc != 0) <span style="color: #a020f0;">return</span> TREXIO_ERRNO;
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orgfa8738c" class="outline-4">
|
|
<h4 id="orgfa8738c"><span class="section-number-4">2.6.2</span> Fortran</h4>
|
|
<div class="outline-text-4" id="text-2-6-2">
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_close</span> (trex_file) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_close</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orgf5a0f72" class="outline-4">
|
|
<h4 id="orgf5a0f72"><span class="section-number-4">2.6.3</span> Python</h4>
|
|
<div class="outline-text-4" id="text-2-6-3">
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">_close</span>(trexio_file):
|
|
<span style="color: #8b2252;">"""Close TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameter is a ~trexio_file~ object that has been created by a call to ~open~ function.</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_close(trexio_file)
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org7fb1fb1" class="outline-3">
|
|
<h3 id="org7fb1fb1"><span class="section-number-3">2.7</span> File flushing</h3>
|
|
<div class="outline-text-3" id="text-2-7">
|
|
<p>
|
|
<code>trexio_flush</code> flushes all buffers into the <code>trexio_t</code> file.
|
|
</p>
|
|
|
|
<p>
|
|
input parameters:
|
|
<code>file</code> – TREXIO file handle.
|
|
</p>
|
|
|
|
<p>
|
|
output:
|
|
<code>trexio_exit_code</code> exit code.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="outline-container-org7595d71" class="outline-4">
|
|
<h4 id="org7595d71"><span class="section-number-4">2.7.1</span> C</h4>
|
|
<div class="outline-text-4" id="text-2-7-1">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_flush</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a0522d;">file</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_FILE_ERROR;
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span> = TREXIO_FAILURE;
|
|
|
|
assert(file->back_end < TREXIO_INVALID_BACK_END);
|
|
|
|
/* <span style="color: #b22222;">Terminate the back end</span> */
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
rc = trexio_text_flush(file);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
rc = trexio_hdf5_flush(file);
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">return</span> TREXIO_BACK_END_MISSING;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> rc = trexio_json_flush(file);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> rc;
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org36ae999" class="outline-4">
|
|
<h4 id="org36ae999"><span class="section-number-4">2.7.2</span> Fortran</h4>
|
|
<div class="outline-text-4" id="text-2-7-2">
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_flush</span> (trex_file) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_flush</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org1523cd6" class="outline-4">
|
|
<h4 id="org1523cd6"><span class="section-number-4">2.7.3</span> Python</h4>
|
|
<div class="outline-text-4" id="text-2-7-3">
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">flush</span>(trexio_file):
|
|
<span style="color: #8b2252;">"""Flush buffers into the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameter is a ~trexio_file~ object that has been created by a call to ~open~ function.</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_flush(trexio_file.pytrexio_s)
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orga643af7" class="outline-3">
|
|
<h3 id="orga643af7"><span class="section-number-3">2.8</span> File existence</h3>
|
|
<div class="outline-text-3" id="text-2-8">
|
|
<p>
|
|
<code>trexio_inquire</code> check whether TREXIO file exists.
|
|
</p>
|
|
|
|
<p>
|
|
input parameters:
|
|
<code>file_name</code> - string containing file name
|
|
</p>
|
|
|
|
<p>
|
|
output:
|
|
<code>trexio_exit_code</code> exit code.
|
|
</p>
|
|
|
|
<p>
|
|
It returns:
|
|
</p>
|
|
|
|
<ul class="org-ul">
|
|
<li><code>TREXIO_SUCCESS</code> if the <code>file_name</code> exists and if it correspond to a valid TREXIO file (i.e. a directory OR an HDF5 file)</li>
|
|
<li><code>TREXIO_FILE_ERROR</code> if <code>file_name</code> exists but it is not a TREXIO file</li>
|
|
<li><code>TREXIO_FAILURE</code> otherwise</li>
|
|
</ul>
|
|
|
|
<p>
|
|
Also, there is an implicit way to have the aforementioned functionality.
|
|
Attempt to open a non-existing file with <code>trexio_open</code> function will result in a <code>TREXIO_OPEN_ERROR</code> exit code
|
|
(see the modified value that has been passed as a 4-th argument to <code>trexio_open</code>).
|
|
</p>
|
|
|
|
<p>
|
|
You can see examples of both functionalities in <code>test_f.f90</code> (search for calls with <code>_void</code> suffix).
|
|
</p>
|
|
</div>
|
|
|
|
<div id="outline-container-orgc0c01f1" class="outline-4">
|
|
<h4 id="orgc0c01f1"><span class="section-number-4">2.8.1</span> C</h4>
|
|
<div class="outline-text-4" id="text-2-8-1">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_inquire</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span>* <span style="color: #a0522d;">file_name</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file_name == <span style="color: #008b8b;">NULL</span> || file_name[0] == <span style="color: #8b2252;">'\0'</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
|
|
/* <span style="color: #b22222;">First check if the TREXIO file exists and if it is a directory</span> */
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc_text</span> = trexio_text_inquire(file_name);
|
|
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
/* <span style="color: #b22222;">FILE_ERROR here means that the file exists but it is not a directory -> check with HDF5</span> */
|
|
<span style="color: #a020f0;">if</span> (rc_text == TREXIO_FILE_ERROR) {
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc_hdf5</span> = trexio_hdf5_inquire(file_name);
|
|
<span style="color: #a020f0;">return</span> rc_hdf5;
|
|
/* <span style="color: #b22222;">If rc_text is TREXIO_SUCCESS -> file is a TREXIO directory; TREXIO_FAILURE -> file/directory does not exist</span> */
|
|
} <span style="color: #a020f0;">else</span> {
|
|
<span style="color: #a020f0;">return</span> rc_text;
|
|
}
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">return</span> rc_text;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org2d7f0c5" class="outline-4">
|
|
<h4 id="org2d7f0c5"><span class="section-number-4">2.8.2</span> Fortran</h4>
|
|
<div class="outline-text-4" id="text-2-8-2">
|
|
<p>
|
|
The function below is a C binding.
|
|
The front end Fortran function for <code>trexio_inquire</code> can be found in the <code>Fortran helper/wrapper functions</code>.
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_inquire_c</span> (filename) <span style="color: #a020f0;">bind</span>(C, name=<span style="color: #8b2252;">"trexio_inquire"</span>)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">character</span>(kind=<span style="color: #008b8b;">c_char</span>), <span style="color: #a020f0;">dimension</span>(*) ::<span style="color: #a0522d;"> filename</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_inquire_c</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org416ec80" class="outline-4">
|
|
<h4 id="org416ec80"><span class="section-number-4">2.8.3</span> Python</h4>
|
|
<div class="outline-text-4" id="text-2-8-3">
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">_inquire</span>(file_name: <span style="color: #483d8b;">str</span>) -> <span style="color: #483d8b;">bool</span>:
|
|
<span style="color: #8b2252;">"""Check whether ~file_name~ TREXIO file exists.</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_inquire(trexio_file_name)
|
|
<span style="color: #a020f0;">if</span> rc == TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">True</span>
|
|
<span style="color: #a020f0;">elif</span> rc == TREXIO_FAILURE:
|
|
<span style="color: #a020f0;">return</span> <span style="color: #008b8b;">False</span>
|
|
<span style="color: #a020f0;">else</span>:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org51e5009" class="outline-3">
|
|
<h3 id="org51e5009"><span class="section-number-3">2.9</span> File copy</h3>
|
|
<div class="outline-text-3" id="text-2-9">
|
|
<p>
|
|
<code>trexio_cp</code> copies a TREXIO file using <code>cp</code>. The destination file
|
|
is not overwritten if it exists, an error is returned.
|
|
</p>
|
|
|
|
<p>
|
|
<b><b>Input parameters:</b></b>
|
|
</p>
|
|
<ol class="org-ol">
|
|
<li><code>source_file_name</code> - string containing the name of the source file</li>
|
|
<li><code>destination_file_name</code> - string containing the name of the new file</li>
|
|
</ol>
|
|
|
|
<p>
|
|
<b><b>Output:</b></b>
|
|
</p>
|
|
<ul class="org-ul">
|
|
<li><code>trexio_exit_code</code></li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div id="outline-container-orgfc2aeec" class="outline-4">
|
|
<h4 id="orgfc2aeec"><span class="section-number-4">2.9.1</span> C</h4>
|
|
<div class="outline-text-4" id="text-2-9-1">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c">
|
|
<span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_cp</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span>* <span style="color: #a0522d;">source</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span>* <span style="color: #a0522d;">dest</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (source == <span style="color: #008b8b;">NULL</span> || source[0] == <span style="color: #8b2252;">'\0'</span>) {
|
|
<span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
}
|
|
|
|
<span style="color: #a020f0;">if</span> (dest == <span style="color: #008b8b;">NULL</span> || dest[0] == <span style="color: #8b2252;">'\0'</span>) {
|
|
<span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
}
|
|
|
|
|
|
<span style="color: #228b22;">back_end_t</span> <span style="color: #a0522d;">back_end_local</span> = TREXIO_AUTO;
|
|
/* <span style="color: #b22222;">Try to determine the applicable backend if the back_end argument is TREXIO_AUTO</span> */
|
|
/* <span style="color: #b22222;">Check if the TREXIO file exists and if it is a directory</span> */
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc_text</span> = trexio_text_inquire(source);
|
|
<span style="color: #a020f0;">if</span> (rc_text == TREXIO_SUCCESS) {
|
|
back_end_local = TREXIO_TEXT;
|
|
}
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
<span style="color: #a020f0;">else</span> {
|
|
/* <span style="color: #b22222;">If not, check if it is an HDF5 file</span> */
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc_hdf5</span> = trexio_hdf5_inquire(source);
|
|
<span style="color: #a020f0;">if</span> (rc_hdf5 == TREXIO_SUCCESS) {
|
|
back_end_local = TREXIO_HDF5;
|
|
} <span style="color: #a020f0;">else</span> {
|
|
/* <span style="color: #b22222;">File is neither a directory nor an HDF5 file -> return an error</span> */
|
|
<span style="color: #a020f0;">return</span> TREXIO_FILE_ERROR;
|
|
}
|
|
}
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">else</span> {
|
|
<span style="color: #a020f0;">return</span> TREXIO_FILE_ERROR;
|
|
}
|
|
<span style="color: #483d8b;">#endif</span>
|
|
assert (back_end_local != TREXIO_AUTO);
|
|
|
|
<span style="color: #a020f0;">if</span> (trexio_inquire(dest) == TREXIO_SUCCESS) {
|
|
/* <span style="color: #b22222;">Destination file already exists</span> */
|
|
<span style="color: #a020f0;">return</span> TREXIO_FILE_ERROR;
|
|
}
|
|
|
|
/* <span style="color: #b22222;">Call cp</span> */
|
|
|
|
<span style="color: #483d8b;">#if</span><span style="color: #483d8b;">n</span><span style="color: #483d8b;">def</span> CP_COMMAND
|
|
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">CP_COMMAND</span> <span style="color: #8b2252;">"cp"</span>, <span style="color: #8b2252;">"-r"</span>
|
|
<span style="color: #483d8b;">#endif</span>
|
|
|
|
|
|
<span style="color: #228b22;">pid_t</span> <span style="color: #a0522d;">pid</span> = fork();
|
|
<span style="color: #a020f0;">if</span> (pid == 0) {
|
|
execlp(<span style="color: #8b2252;">"cp"</span>, CP_COMMAND, source, dest, (<span style="color: #228b22;">char</span> *)0);
|
|
} <span style="color: #a020f0;">else</span> <span style="color: #a020f0;">if</span> (pid < 0) {
|
|
<span style="color: #a020f0;">return</span> TREXIO_FILE_ERROR;
|
|
} <span style="color: #a020f0;">else</span> {
|
|
<span style="color: #228b22;">int</span> <span style="color: #a0522d;">wstatus</span>;
|
|
<span style="color: #228b22;">pid_t</span> <span style="color: #a0522d;">ws</span> = waitpid( pid, &wstatus, 0);
|
|
<span style="color: #a020f0;">if</span> (ws != pid || !WIFEXITED(wstatus) )
|
|
<span style="color: #a020f0;">return</span> TREXIO_FILE_ERROR;
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org8718234" class="outline-4">
|
|
<h4 id="org8718234"><span class="section-number-4">2.9.2</span> Fortran</h4>
|
|
<div class="outline-text-4" id="text-2-9-2">
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_cp_c</span> (source, destination) <span style="color: #a020f0;">bind</span>(C, name=<span style="color: #8b2252;">"trexio_cp"</span>)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">character</span>(kind=<span style="color: #008b8b;">c_char</span>), <span style="color: #a020f0;">dimension</span>(*) ::<span style="color: #a0522d;"> source, destination</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_cp_c</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org0e3799e" class="outline-4">
|
|
<h4 id="org0e3799e"><span class="section-number-4">2.9.3</span> Python</h4>
|
|
<div class="outline-text-4" id="text-2-9-3">
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">_cp</span>(source: <span style="color: #483d8b;">str</span>, destination: <span style="color: #483d8b;">str</span>):
|
|
<span style="color: #8b2252;">"""Copies a TREXIO file</span>
|
|
|
|
<span style="color: #8b2252;"> Parameters:</span>
|
|
|
|
<span style="color: #8b2252;"> source: str</span>
|
|
<span style="color: #8b2252;"> Name of the source file</span>
|
|
|
|
<span style="color: #8b2252;"> destination: str</span>
|
|
<span style="color: #8b2252;"> Name of the destination file</span>
|
|
|
|
<span style="color: #8b2252;"> Examples:</span>
|
|
<span style="color: #8b2252;"> >>> from trexio import cp as tr_cp</span>
|
|
<span style="color: #8b2252;"> >>> tr_cp("example.h5", "new.h5")</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a020f0;">from</span> shutil <span style="color: #a020f0;">import</span> copytree, copyfile
|
|
|
|
<span style="color: #a0522d;">f</span> = File(filename=source, mode=<span style="color: #8b2252;">'r'</span>, back_end=TREXIO_AUTO)
|
|
<span style="color: #a020f0;">if</span> f.back_end == TREXIO_TEXT:
|
|
copytree(source, destination)
|
|
<span style="color: #a020f0;">elif</span> f.back_end == TREXIO_HDF5:
|
|
copyfile(source, destination)
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org353b3fb" class="outline-3">
|
|
<h3 id="org353b3fb"><span class="section-number-3">2.10</span> File state</h3>
|
|
<div class="outline-text-3" id="text-2-10">
|
|
<p>
|
|
<b><b>Note:</b></b> the use of the functions below is discouraged as of version 2.3.0.
|
|
Please use <code>trexio_write_state_id</code> and <code>trexio_read_state_id</code> to get the state
|
|
corresponding to a given <code>trexio_t</code> file. There can be only one <code>state_id</code> per file,
|
|
namely data for excited state wave functions have to go in a file different from
|
|
the ground state one (see the <code>state</code> group description for more info about how
|
|
you can link the ground state TREXIO file with its excited states).
|
|
</p>
|
|
|
|
<p>
|
|
<code>trexio_set_state</code> set an existing <code>trexio_t</code> file handle to a given state
|
|
and write it as <code>state_id</code> attribute.
|
|
<code>trexio_get_state</code> returns current state of the <code>trexio_t</code> file handle.
|
|
</p>
|
|
|
|
<p>
|
|
<b><b>Warning:</b></b> The <code>trexio_set_state</code> and <code>trexio_get_state</code> functions still
|
|
use the old convention where the ground state was state <code>0</code>. From version 2.4.0,
|
|
the <code>state_id</code> variable has changed to <code>index</code> type, so using the more recent
|
|
<code>trexio_write_state_id</code> and <code>trexio_read_state_id</code> will give different results
|
|
in Fortran.
|
|
</p>
|
|
|
|
<p>
|
|
input parameters:
|
|
<code>file</code> – TREXIO file handle.
|
|
<code>state</code> – <code>int32_t</code> ID of a state (0 for ground state).
|
|
</p>
|
|
|
|
<p>
|
|
output:
|
|
<code>trexio_exit_code</code> exit code.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="outline-container-orgf60d4c7" class="outline-4">
|
|
<h4 id="orgf60d4c7"><span class="section-number-4">2.10.1</span> C</h4>
|
|
<div class="outline-text-4" id="text-2-10-1">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_set_state</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a0522d;">file</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">num</span>)
|
|
{
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
|
|
/* <span style="color: #b22222;">Write state_id in the file (as of v.2.3.0)</span> */
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span> = trexio_has_state_id(file);
|
|
<span style="color: #a020f0;">if</span> (rc == TREXIO_HAS_NOT || file->mode == <span style="color: #8b2252;">'u'</span>) {
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc_w</span> = trexio_write_state_id(file, num);
|
|
<span style="color: #a020f0;">if</span> (rc_w != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc_w;
|
|
}
|
|
|
|
file->state = num;
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
}
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_get_state</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a0522d;">file</span>, <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">num</span>)
|
|
{
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (num == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
|
|
/* <span style="color: #b22222;">Read state_id from the file (as of v.2.3.0)</span> */
|
|
<span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">state_id</span> = 0;
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span> = trexio_has_state_id(file);
|
|
<span style="color: #a020f0;">if</span> (rc == TREXIO_SUCCESS) {
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc_r</span> = trexio_read_state_id(file, &state_id);
|
|
<span style="color: #a020f0;">if</span> (rc_r != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc_r;
|
|
}
|
|
|
|
/* <span style="color: #b22222;">If the state is not in a file then state_id=0, i.e. ground state</span> */
|
|
*num = state_id;
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org1eb0296" class="outline-4">
|
|
<h4 id="org1eb0296"><span class="section-number-4">2.10.2</span> Fortran</h4>
|
|
<div class="outline-text-4" id="text-2-10-2">
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_set_state</span> (trex_file, state) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</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;"> state</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_set_state</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
|
|
<span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_get_state</span> (trex_file, state) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> state</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_get_state</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org8a21037" class="outline-4">
|
|
<h4 id="org8a21037"><span class="section-number-4">2.10.3</span> Python</h4>
|
|
<div class="outline-text-4" id="text-2-10-3">
|
|
<p>
|
|
See TREXIO File Python class.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org2e9b5d4" class="outline-3">
|
|
<h3 id="org2e9b5d4"><span class="section-number-3">2.11</span> Tasks to be done before closing</h3>
|
|
<div class="outline-text-3" id="text-2-11">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_pre_close</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a0522d;">file</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_FILE_ERROR;
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span>;
|
|
|
|
/* <span style="color: #b22222;">Check consistency between number of determinants and coefficients stored in the file</span> */
|
|
|
|
<span style="color: #a020f0;">if</span> (file->version_major >= 2 && file->version_minor >= 2) {
|
|
|
|
<span style="color: #228b22;">bool</span> <span style="color: #a0522d;">has_det</span> = (trexio_has_determinant_list(file) == TREXIO_SUCCESS);
|
|
<span style="color: #228b22;">bool</span> <span style="color: #a0522d;">has_coeff</span> = (trexio_has_determinant_coefficient(file) == TREXIO_SUCCESS);
|
|
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">ndet</span>, <span style="color: #a0522d;">ncoeff</span>;
|
|
|
|
<span style="color: #a020f0;">if</span> (has_det && has_coeff) {
|
|
rc = trexio_read_determinant_num_64(file, &ndet);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
rc = trexio_read_determinant_coefficient_size(file, &ncoeff);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
/* <span style="color: #b22222;">Maybe be even more direct and use assert here so that the user's code crushes in case of inconsistency</span> */
|
|
<span style="color: #a020f0;">if</span> (ndet != ncoeff) <span style="color: #a020f0;">return</span> TREXIO_INVALID_DETERMINANT_NUM;
|
|
}
|
|
|
|
}
|
|
/* <span style="color: #b22222;">Up-spin and down-spin electrons</span> */
|
|
|
|
<span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">nup</span>, <span style="color: #a0522d;">ndn</span>, <span style="color: #a0522d;">nelec</span>;
|
|
<span style="color: #228b22;">bool</span> <span style="color: #a0522d;">has_up</span> = (trexio_has_electron_up_num(file) == TREXIO_SUCCESS);
|
|
<span style="color: #228b22;">bool</span> <span style="color: #a0522d;">has_dn</span> = (trexio_has_electron_dn_num(file) == TREXIO_SUCCESS);
|
|
<span style="color: #228b22;">bool</span> <span style="color: #a0522d;">has_updn</span> = (trexio_has_electron_num(file) == TREXIO_SUCCESS);
|
|
|
|
<span style="color: #a020f0;">if</span> (file->mode != <span style="color: #8b2252;">'r'</span>) {
|
|
<span style="color: #a020f0;">if</span> (has_updn && has_up && has_dn) {
|
|
rc = trexio_read_electron_up_num(file, &nup);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
rc = trexio_read_electron_dn_num(file, &ndn);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
rc = trexio_read_electron_num(file, &nelec);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
<span style="color: #a020f0;">if</span> (nelec != nup + ndn) {
|
|
<span style="color: #a020f0;">if</span> (file->mode == <span style="color: #8b2252;">'u'</span>) {
|
|
nelec = nup + ndn;
|
|
rc = trexio_write_electron_num(file, nelec);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
} <span style="color: #a020f0;">else</span> {
|
|
<span style="color: #a020f0;">return</span> TREXIO_INVALID_ELECTRON_NUM;
|
|
}
|
|
}
|
|
} <span style="color: #a020f0;">else</span> <span style="color: #a020f0;">if</span> (has_up && has_dn) {
|
|
rc = trexio_read_electron_up_num(file, &nup);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
rc = trexio_read_electron_dn_num(file, &ndn);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
nelec = nup + ndn;
|
|
rc = trexio_write_electron_num(file, nelec);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
} <span style="color: #a020f0;">else</span> <span style="color: #a020f0;">if</span> (has_up) {
|
|
rc = trexio_read_electron_up_num(file, &nup);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
ndn = 0;
|
|
rc = trexio_write_electron_dn_num(file, ndn);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
nelec = nup;
|
|
rc = trexio_write_electron_num(file, nelec);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
} <span style="color: #a020f0;">else</span> <span style="color: #a020f0;">if</span> (has_dn) {
|
|
rc = trexio_read_electron_dn_num(file, &ndn);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
nup = 0;
|
|
rc = trexio_write_electron_up_num(file, nup);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
nelec = ndn;
|
|
rc = trexio_write_electron_num(file, nelec);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
}
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org590ccb0" class="outline-2">
|
|
<h2 id="org590ccb0"><span class="section-number-2">3</span> Templates for front end</h2>
|
|
<div class="outline-text-2" id="text-3">
|
|
</div>
|
|
<div id="outline-container-org1275000" class="outline-3">
|
|
<h3 id="org1275000"><span class="section-number-3">3.1</span> Description</h3>
|
|
<div class="outline-text-3" id="text-3-1">
|
|
<p>
|
|
Consider the following block of <code>trex.json</code>:
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-python">{
|
|
<span style="color: #8b2252;">"nucleus"</span>: {
|
|
<span style="color: #8b2252;">"num"</span> : [ <span style="color: #8b2252;">"int"</span> , [ ] ]
|
|
, <span style="color: #8b2252;">"charge"</span> : [ <span style="color: #8b2252;">"float"</span>, [ <span style="color: #8b2252;">"nucleus.num"</span> ] ]
|
|
, <span style="color: #8b2252;">"coord"</span> : [ <span style="color: #8b2252;">"float"</span>, [ <span style="color: #8b2252;">"nucleus.num"</span>, <span style="color: #8b2252;">"3"</span> ] ]
|
|
, <span style="color: #8b2252;">"label"</span> : [ <span style="color: #8b2252;">"str"</span> , [ <span style="color: #8b2252;">"nucleus.num"</span> ] ]
|
|
, <span style="color: #8b2252;">"point_group"</span> : [ <span style="color: #8b2252;">"str"</span> , [ ] ]
|
|
}
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<p>
|
|
<code>TREXIO</code> is generated automatically by the <code>generator.py</code> Python
|
|
script based on the tree-like configuration provided in the
|
|
<code>trex.json</code> file. Because of that, generalized templates can be
|
|
implemented and re-used. This approach minimizes the number of bugs
|
|
as compared with manual copy-paste-modify scheme.
|
|
</p>
|
|
|
|
<p>
|
|
All templates presented below use the <code>$var$</code> notation to indicate
|
|
the variable, which will be replaced by the
|
|
<code>generator.py</code>. Sometimes the upper case is used, i.e. <code>$VAR$</code> (for
|
|
example, in <code>#define</code> statements). More detailed description of
|
|
each variable can be found below:
|
|
</p>
|
|
|
|
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
|
|
|
|
|
|
<colgroup>
|
|
<col class="org-left" />
|
|
|
|
<col class="org-left" />
|
|
|
|
<col class="org-left" />
|
|
</colgroup>
|
|
<thead>
|
|
<tr>
|
|
<th scope="col" class="org-left">Template variable</th>
|
|
<th scope="col" class="org-left">Description</th>
|
|
<th scope="col" class="org-left">Example</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="org-left"><code>$group$</code></td>
|
|
<td class="org-left">Name of the group</td>
|
|
<td class="org-left"><code>nucleus</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>$group_num$</code></td>
|
|
<td class="org-left">Name of the numerical attribute (scalar)</td>
|
|
<td class="org-left"><code>nucleus_num</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>$group_str$</code></td>
|
|
<td class="org-left">Name of the string attribute (scalar)</td>
|
|
<td class="org-left"><code>nucleus_point_group</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>$group_dset$</code></td>
|
|
<td class="org-left">Name of the dataset (vector/matrix/tensor)</td>
|
|
<td class="org-left"><code>nucleus_coord</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>$group_dset_rank$</code></td>
|
|
<td class="org-left">Rank of the dataset</td>
|
|
<td class="org-left"><code>2</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>$group_dset_dim$</code></td>
|
|
<td class="org-left">Selected dimension of the dataset</td>
|
|
<td class="org-left"><code>nucleus_num</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>$group_dset_dim_list$</code></td>
|
|
<td class="org-left">All dimensions of the dataset</td>
|
|
<td class="org-left"><code>{nucleus_num, 3}</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>$group_dset_dtype$</code></td>
|
|
<td class="org-left">Basic type of the dataset (int/float/char)</td>
|
|
<td class="org-left"><code>float</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>$group_dset_h5_dtype$</code></td>
|
|
<td class="org-left">Type of the dataset in HDF5</td>
|
|
<td class="org-left"><code>double</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>$group_dset_format_scanf$</code></td>
|
|
<td class="org-left">Input type of the dataset in TEXT [fscanf]</td>
|
|
<td class="org-left"><code>%lf</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>$group_dset_format_printf$</code></td>
|
|
<td class="org-left">Output type of the dataset in TEXT [fprintf]</td>
|
|
<td class="org-left"><code>%24.16e</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>$group_dset_dtype_default$</code></td>
|
|
<td class="org-left">Default datatype of the dataset [C]</td>
|
|
<td class="org-left"><code>double/int32_t</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>$group_dset_dtype_single$</code></td>
|
|
<td class="org-left">Single precision datatype of the dataset [C]</td>
|
|
<td class="org-left"><code>float/int32_t</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>$group_dset_dtype_double$</code></td>
|
|
<td class="org-left">Double precision datatype of the dataset [C]</td>
|
|
<td class="org-left"><code>double/int64_t</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>$group_dset_f_dtype_default$</code></td>
|
|
<td class="org-left">Default datatype of the dataset [Fortran]</td>
|
|
<td class="org-left"><code>real(c_double)/integer(c_int32_t)</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>$group_dset_f_dtype_single$</code></td>
|
|
<td class="org-left">Single precision datatype of the dataset [Fortran]</td>
|
|
<td class="org-left"><code>real(c_float)/integer(c_int32_t)</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>$group_dset_f_dtype_double$</code></td>
|
|
<td class="org-left">Double precision datatype of the dataset [Fortran]</td>
|
|
<td class="org-left"><code>real(c_double)/integer(c_int64_t)</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>$group_dset_f_dims$</code></td>
|
|
<td class="org-left">Dimensions in Fortran</td>
|
|
<td class="org-left"><code>(:,:)</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>$group_dset_py_dtype$</code></td>
|
|
<td class="org-left">Standard datatype of the dataset [Python]</td>
|
|
<td class="org-left"><code>float/int</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>$default_prec$</code></td>
|
|
<td class="org-left">Default precision for read/write without suffix [C]</td>
|
|
<td class="org-left"><code>64/32</code></td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>$is_index$</code></td>
|
|
<td class="org-left">Expands to <code>true</code> if dataset has a type <code>index</code> [C]</td>
|
|
<td class="org-left"><code>true/false</code></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
<p>
|
|
Some of the aforementioned template variables with <code>group_dset</code> prefix are duplicated with <code>group_num</code> prefix,
|
|
e.g. you might find \(group_num_dtype_double\) in the templates corresponding to numerical attributes.
|
|
The expanding values are the same as for <code>group_dset</code> and thus are not listed in the table above.
|
|
</p>
|
|
|
|
<p>
|
|
Note: parent group name is always added to the child objects upon
|
|
construction of TREXIO (e.g. <code>num</code> of <code>nucleus</code> group becomes
|
|
<code>nucleus_num</code> and should be accessed accordingly within TREXIO).
|
|
</p>
|
|
|
|
<p>
|
|
TREXIO generator parses the <code>trex.json</code> file. TREXIO operates with
|
|
names of variables based on the 1-st (parent group) and 2-nd (child
|
|
object) levels of <code>trex.json</code> . The parsed data is divided in 2
|
|
parts:
|
|
</p>
|
|
|
|
<ol class="org-ol">
|
|
<li>Single attributes. These can be numerical values or strings.</li>
|
|
<li>Datasets. These can be vectors, matrices or tensors. The types are indicated in <code>trex.json</code>.
|
|
Currently supported data types: int, float and strings.</li>
|
|
</ol>
|
|
|
|
<p>
|
|
For each of the aforementioned objects, TREXIO provides <b>has</b>,
|
|
<b>read</b> and <b>write</b> functionality. TREXIO supports I/O with single
|
|
or double precision for integer and floating point numbers.
|
|
</p>
|
|
|
|
<p>
|
|
<b>Note:</b> single integer attributes that contain <code>num</code> in their name (e.g. <code>nucleus_num</code>) are
|
|
considered dimensioning variables and cannot be negative or 0. An attempt to write negative or 0
|
|
value will result in <code>TREXIO_INVALID_ARG_2</code> exit code.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org0e1ed16" class="outline-3">
|
|
<h3 id="org0e1ed16"><span class="section-number-3">3.2</span> Templates for front end has<sub>group</sub> functions</h3>
|
|
<div class="outline-text-3" id="text-3-2">
|
|
</div>
|
|
<div id="outline-container-org354ca8b" class="outline-4">
|
|
<h4 id="org354ca8b"><span class="section-number-4">3.2.1</span> Introduction</h4>
|
|
<div class="outline-text-4" id="text-3-2-1">
|
|
<p>
|
|
This section concerns API calls related to TREXIO groups
|
|
</p>
|
|
|
|
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
|
|
|
|
|
|
<colgroup>
|
|
<col class="org-left" />
|
|
|
|
<col class="org-left" />
|
|
</colgroup>
|
|
<thead>
|
|
<tr>
|
|
<th scope="col" class="org-left">Function name</th>
|
|
<th scope="col" class="org-left">Description</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="org-left"><code>trexio_has_$group$</code></td>
|
|
<td class="org-left">Check if a group exists in a file</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org31eafa9" class="outline-4">
|
|
<h4 id="org31eafa9"><span class="section-number-4">3.2.2</span> C templates for front end</h4>
|
|
<div class="outline-text-4" id="text-3-2-2">
|
|
<p>
|
|
The <code>C</code> templates that correspond to each of the abovementioned
|
|
functions can be found below. First parameter is the <code>TREXIO</code> file
|
|
handle.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="outline-container-orgff8fde1" class="outline-5">
|
|
<h5 id="orgff8fde1"><span class="section-number-5">3.2.2.1</span> Function declarations</h5>
|
|
</div>
|
|
|
|
<div id="outline-container-org7e56d89" class="outline-5">
|
|
<h5 id="org7e56d89"><span class="section-number-5">3.2.2.2</span> Source code</h5>
|
|
<div class="outline-text-5" id="text-3-2-2-2">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_has_$group$</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
|
|
assert(file->back_end < TREXIO_INVALID_BACK_END);
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
<span style="color: #a020f0;">return</span> trexio_text_has_$group$(file);
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
<span style="color: #a020f0;">return</span> trexio_hdf5_has_$group$(file);
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">return</span> TREXIO_BACK_END_MISSING;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> return trexio_json_has_$group$(file);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_FAILURE;
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orga28a769" class="outline-4">
|
|
<h4 id="orga28a769"><span class="section-number-4">3.2.3</span> Fortran templates for front end</h4>
|
|
<div class="outline-text-4" id="text-3-2-3">
|
|
<p>
|
|
The <code>Fortran</code> templates that provide an access to the <code>C</code> API calls from Fortran.
|
|
These templates are based on the use of <code>iso_c_binding</code>. Pointers have to be passed by value.
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_has_$group$</span> (trex_file) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_has_$group$</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orga428446" class="outline-4">
|
|
<h4 id="orga428446"><span class="section-number-4">3.2.4</span> Python templates for front end</h4>
|
|
<div class="outline-text-4" id="text-3-2-4">
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">has_</span>$group$(trexio_file) -> <span style="color: #483d8b;">bool</span>:
|
|
<span style="color: #8b2252;">"""Check that $group$ group exists in the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function.</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> True if the variable exists, False otherwise</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - trexio.Error if TREXIO return code ~rc~ is TREXIO_FAILURE and prints the error message using string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_has_$group$(trexio_file.pytrexio_s)
|
|
<span style="color: #a020f0;">if</span> rc == TREXIO_FAILURE:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
|
|
<span style="color: #a020f0;">return</span> rc == TREXIO_SUCCESS
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org344cc35" class="outline-3">
|
|
<h3 id="org344cc35"><span class="section-number-3">3.3</span> Templates for front end has/read/write a single numerical attribute</h3>
|
|
<div class="outline-text-3" id="text-3-3">
|
|
</div>
|
|
<div id="outline-container-org86e4182" class="outline-4">
|
|
<h4 id="org86e4182"><span class="section-number-4">3.3.1</span> Introduction</h4>
|
|
<div class="outline-text-4" id="text-3-3-1">
|
|
<p>
|
|
This section concerns API calls related to numerical attributes,
|
|
namely single value of int/float types.
|
|
</p>
|
|
|
|
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
|
|
|
|
|
|
<colgroup>
|
|
<col class="org-left" />
|
|
|
|
<col class="org-left" />
|
|
|
|
<col class="org-left" />
|
|
</colgroup>
|
|
<thead>
|
|
<tr>
|
|
<th scope="col" class="org-left">Function name</th>
|
|
<th scope="col" class="org-left">Description</th>
|
|
<th scope="col" class="org-left">Precision</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="org-left"><code>trexio_has_$group_num$</code></td>
|
|
<td class="org-left">Check if an attribute exists in a file</td>
|
|
<td class="org-left">---</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_read_$group_num$</code></td>
|
|
<td class="org-left">Read a attribute</td>
|
|
<td class="org-left">Single</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_write_$group_num$</code></td>
|
|
<td class="org-left">Write a attribute</td>
|
|
<td class="org-left">Single</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_read_$group_num$_32</code></td>
|
|
<td class="org-left">Read a attribute</td>
|
|
<td class="org-left">Single</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_write_$group_num$_32</code></td>
|
|
<td class="org-left">Write a attribute</td>
|
|
<td class="org-left">Single</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_read_$group_num$_64</code></td>
|
|
<td class="org-left">Read a attribute</td>
|
|
<td class="org-left">Double</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_write_$group_num$_64</code></td>
|
|
<td class="org-left">Write a attribute</td>
|
|
<td class="org-left">Double</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orgdf95cb6" class="outline-4">
|
|
<h4 id="orgdf95cb6"><span class="section-number-4">3.3.2</span> C templates for front end</h4>
|
|
<div class="outline-text-4" id="text-3-3-2">
|
|
<p>
|
|
The <code>C</code> templates that correspond to each of the abovementioned
|
|
functions can be found below. First parameter is the <code>TREXIO</code> file
|
|
handle. Second parameter is the variable to be written/read
|
|
to/from the <code>TREXIO</code> file (except for <code>trexio_has_</code> functions).
|
|
Suffixes <code>_32</code> and <code>_64</code> correspond to API calls dealing with
|
|
single and real(c<sub>double</sub>), respectively. The basic
|
|
(non-suffixed) API call on dimensioning variables deals with single
|
|
precision (see Table above).
|
|
</p>
|
|
</div>
|
|
|
|
<div id="outline-container-org696e05b" class="outline-5">
|
|
<h5 id="org696e05b"><span class="section-number-5">3.3.2.1</span> Function declarations</h5>
|
|
</div>
|
|
|
|
<div id="outline-container-orgfcb88b8" class="outline-5">
|
|
<h5 id="orgfcb88b8"><span class="section-number-5">3.3.2.2</span> Source code for double precision functions</h5>
|
|
<div class="outline-text-5" id="text-3-3-2-2">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_read_$group_num$_64</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, $group_num_dtype_double$* <span style="color: #a020f0;">const</span> num)
|
|
{
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (num == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (trexio_has_$group_num$(file) != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> TREXIO_ATTR_MISSING;
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span> = TREXIO_GROUP_READ_ERROR;
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
rc = trexio_text_read_$group_num$(file, num);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
rc = trexio_hdf5_read_$group_num$(file, num);
|
|
<span style="color: #483d8b;">#else</span>
|
|
rc = TREXIO_BACK_END_MISSING;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
<span style="color: #a020f0;">break</span>;
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> rc = trexio_json_read_$group_num$(file, num);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
/* <span style="color: #b22222;">Handle index type</span> */
|
|
<span style="color: #a020f0;">if</span> ($is_index$) {
|
|
*num += ($group_num_dtype_double$) 1;
|
|
}
|
|
<span style="color: #a020f0;">return</span> rc;
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_write_$group_num$_64</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #a020f0;">const</span> $group_num_dtype_double$ num)
|
|
{
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
//<span style="color: #b22222;">if (num <= 0L) return TREXIO_INVALID_NUM; /* this line is uncommented by the generator for dimensioning variables; do NOT remove! */</span>
|
|
<span style="color: #a020f0;">if</span> (trexio_has_$group_num$(file) == TREXIO_SUCCESS && file->mode != <span style="color: #8b2252;">'u'</span>) <span style="color: #a020f0;">return</span> TREXIO_ATTR_ALREADY_EXISTS;
|
|
|
|
/* <span style="color: #b22222;">Handle index type</span> */
|
|
$group_num_dtype_double$ num_write = num;
|
|
<span style="color: #a020f0;">if</span> ($is_index$) {
|
|
num_write -= ($group_num_dtype_double$) 1;
|
|
}
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
<span style="color: #a020f0;">return</span> trexio_text_write_$group_num$(file, num_write);
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
<span style="color: #a020f0;">return</span> trexio_hdf5_write_$group_num$(file, num_write);
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">return</span> TREXIO_BACK_END_MISSING;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> return trexio_json_write_$group_num$(file, num_write);</span>
|
|
*/
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_FAILURE;
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orgc1923c4" class="outline-5">
|
|
<h5 id="orgc1923c4"><span class="section-number-5">3.3.2.3</span> Source code for single precision functions</h5>
|
|
<div class="outline-text-5" id="text-3-3-2-3">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_read_$group_num$_32</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, $group_num_dtype_single$* <span style="color: #a020f0;">const</span> num)
|
|
{
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (num == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (trexio_has_$group_num$(file) != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> TREXIO_ATTR_MISSING;
|
|
|
|
$group_num_dtype_double$ num_64 = 0;
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span> = TREXIO_GROUP_READ_ERROR;
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
rc = trexio_text_read_$group_num$(file, &num_64);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
rc = trexio_hdf5_read_$group_num$(file, &num_64);
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
rc = TREXIO_BACK_END_MISSING;
|
|
<span style="color: #a020f0;">break</span> ;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> rc =trexio_json_read_$group_num$(file, &num_64);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
*num = ($group_num_dtype_single$) num_64;
|
|
|
|
/* <span style="color: #b22222;">Handle index type</span> */
|
|
<span style="color: #a020f0;">if</span> ($is_index$) {
|
|
*num += ($group_num_dtype_single$) 1;
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_write_$group_num$_32</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #a020f0;">const</span> $group_num_dtype_single$ num)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
//<span style="color: #b22222;">if (num <= 0) return TREXIO_INVALID_NUM; /* this line is uncommented by the generator for dimensioning variables; do NOT remove! */</span>
|
|
<span style="color: #a020f0;">if</span> (trexio_has_$group_num$(file) == TREXIO_SUCCESS && file->mode != <span style="color: #8b2252;">'u'</span>) <span style="color: #a020f0;">return</span> TREXIO_ATTR_ALREADY_EXISTS;
|
|
|
|
/* <span style="color: #b22222;">Handle index type</span> */
|
|
$group_num_dtype_single$ num_write = num;
|
|
<span style="color: #a020f0;">if</span> ($is_index$) {
|
|
num_write -= ($group_num_dtype_single$) 1;
|
|
}
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
<span style="color: #a020f0;">return</span> trexio_text_write_$group_num$(file, ($group_num_dtype_double$) num_write);
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
<span style="color: #a020f0;">return</span> trexio_hdf5_write_$group_num$(file, ($group_num_dtype_double$) num_write);
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">return</span> TREXIO_BACK_END_MISSING;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> return trexio_json_write_$group_num$(file, ($group_num_dtype_double$) num_write);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_FAILURE;
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org9ad1d67" class="outline-5">
|
|
<h5 id="org9ad1d67"><span class="section-number-5">3.3.2.4</span> Source code for default functions</h5>
|
|
<div class="outline-text-5" id="text-3-3-2-4">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_read_$group_num$</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, $group_num_dtype_default$* <span style="color: #a020f0;">const</span> num)
|
|
{
|
|
<span style="color: #a020f0;">return</span> trexio_read_$group_num$_$default_prec$(file, num);
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_write_$group_num$</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #a020f0;">const</span> $group_num_dtype_default$ num)
|
|
{
|
|
<span style="color: #a020f0;">return</span> trexio_write_$group_num$_$default_prec$(file, num);
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_has_$group_num$</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
|
|
assert(file->back_end < TREXIO_INVALID_BACK_END);
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
<span style="color: #a020f0;">return</span> trexio_text_has_$group_num$(file);
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
<span style="color: #a020f0;">return</span> trexio_hdf5_has_$group_num$(file);
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">return</span> TREXIO_BACK_END_MISSING;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> return trexio_json_has_$group_num$(file);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_FAILURE;
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org6d161ae" class="outline-4">
|
|
<h4 id="org6d161ae"><span class="section-number-4">3.3.3</span> Fortran templates for front end</h4>
|
|
<div class="outline-text-4" id="text-3-3-3">
|
|
<p>
|
|
The <code>Fortran</code> templates that provide an access to the <code>C</code> API calls from Fortran.
|
|
These templates are based on the use of <code>iso_c_binding</code>. Pointers have to be passed by value.
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_write_$group_num$_64</span> (trex_file, num) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
$group_num_f_dtype_double$, <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> :: num
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_write_$group_num$_64</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_read_$group_num$_64</span> (trex_file, num) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
$group_num_f_dtype_double$, <span style="color: #a020f0;">intent</span>(out) :: num
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_read_$group_num$_64</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_write_$group_num$_32</span> (trex_file, num) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
$group_num_f_dtype_single$, <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> :: num
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_write_$group_num$_32</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_read_$group_num$_32</span> (trex_file, num) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
$group_num_f_dtype_single$, <span style="color: #a020f0;">intent</span>(out) :: num
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_read_$group_num$_32</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_write_$group_num$</span> (trex_file, num) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
$group_num_f_dtype_default$, <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> :: num
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_write_$group_num$</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_read_$group_num$</span> (trex_file, num) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
$group_num_f_dtype_default$, <span style="color: #a020f0;">intent</span>(out) :: num
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_read_$group_num$</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_has_$group_num$</span> (trex_file) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_has_$group_num$</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orgc920bfb" class="outline-4">
|
|
<h4 id="orgc920bfb"><span class="section-number-4">3.3.4</span> Python templates for front end</h4>
|
|
<div class="outline-text-4" id="text-3-3-4">
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">write_</span>$group_num$(trexio_file, num_w: $group_num_py_dtype$) -> <span style="color: #008b8b;">None</span>:
|
|
<span style="color: #8b2252;">"""Write the $group_num$ variable in the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameters:</span>
|
|
|
|
<span style="color: #8b2252;"> trexio_file:</span>
|
|
<span style="color: #8b2252;"> TREXIO File object.</span>
|
|
|
|
<span style="color: #8b2252;"> num_w: int</span>
|
|
<span style="color: #8b2252;"> Value of the $group_num$ variable to be written.</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_write_$group_num$(trexio_file.pytrexio_s, num_w)
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">read_</span>$group_num$(trexio_file) -> $group_num_py_dtype$:
|
|
<span style="color: #8b2252;">"""Read the $group_num$ variable from the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function.</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> ~num_r~: int</span>
|
|
<span style="color: #8b2252;"> Integer value of $group_num$ variable read from ~trexio_file~.</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a0522d;">rc</span>, <span style="color: #a0522d;">num_r</span> = pytr.trexio_read_$group_num$(trexio_file.pytrexio_s)
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
|
|
<span style="color: #a020f0;">return</span> num_r
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">has_</span>$group_num$(trexio_file) -> <span style="color: #483d8b;">bool</span>:
|
|
<span style="color: #8b2252;">"""Check that $group_num$ variable exists in the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function.</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> True if the variable exists, False otherwise</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - trexio.Error if TREXIO return code ~rc~ is TREXIO_FAILURE and prints the error message using string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_has_$group_num$(trexio_file.pytrexio_s)
|
|
<span style="color: #a020f0;">if</span> rc == TREXIO_FAILURE:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
|
|
<span style="color: #a020f0;">return</span> rc == TREXIO_SUCCESS
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org5288e80" class="outline-3">
|
|
<h3 id="org5288e80"><span class="section-number-3">3.4</span> Templates for front end has/read/write a dataset of numerical data</h3>
|
|
<div class="outline-text-3" id="text-3-4">
|
|
</div>
|
|
<div id="outline-container-org4b90115" class="outline-4">
|
|
<h4 id="org4b90115"><span class="section-number-4">3.4.1</span> Introduction</h4>
|
|
<div class="outline-text-4" id="text-3-4-1">
|
|
<p>
|
|
This section concerns API calls related to datasets.
|
|
</p>
|
|
|
|
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
|
|
|
|
|
|
<colgroup>
|
|
<col class="org-left" />
|
|
|
|
<col class="org-left" />
|
|
|
|
<col class="org-left" />
|
|
</colgroup>
|
|
<thead>
|
|
<tr>
|
|
<th scope="col" class="org-left">Function name</th>
|
|
<th scope="col" class="org-left">Description</th>
|
|
<th scope="col" class="org-left">Precision</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="org-left"><code>trexio_has_$group_dset$</code></td>
|
|
<td class="org-left">Check if a dataset exists in a file</td>
|
|
<td class="org-left">---</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_read_$group_dset$</code></td>
|
|
<td class="org-left">Read a dataset in default precision</td>
|
|
<td class="org-left">Double/Single for float/int</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_write_$group_dset$</code></td>
|
|
<td class="org-left">Write a dataset in default precision</td>
|
|
<td class="org-left">Double/Single for float/int</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_read_safe_$group_dset$</code></td>
|
|
<td class="org-left">Read a bounded dataset</td>
|
|
<td class="org-left">Double</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_write_safe_$group_dset$</code></td>
|
|
<td class="org-left">Write a bounded dataset</td>
|
|
<td class="org-left">Double</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_read_$group_dset$_32</code></td>
|
|
<td class="org-left">Read a dataset in single precision</td>
|
|
<td class="org-left">Single</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_write_$group_dset$_32</code></td>
|
|
<td class="org-left">Write a dataset in single precision</td>
|
|
<td class="org-left">Single</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_read_$group_dset$_64</code></td>
|
|
<td class="org-left">Read a dataset in double precision</td>
|
|
<td class="org-left">Double</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_write_$group_dset$_64</code></td>
|
|
<td class="org-left">Write a dataset in double precision</td>
|
|
<td class="org-left">Double</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org431bd83" class="outline-4">
|
|
<h4 id="org431bd83"><span class="section-number-4">3.4.2</span> C templates for front end</h4>
|
|
<div class="outline-text-4" id="text-3-4-2">
|
|
<p>
|
|
The C templates that correspond to each of the abovementioned functions can be found below.
|
|
First parameter is the <code>TREXIO</code> file handle. Second parameter is the variable to be written/read
|
|
to/from the <code>TREXIO</code> file (except for <code>trexio_has_</code> functions).
|
|
Suffixes <code>_32</code> and <code>_64</code> correspond to API calls dealing with single and double precision, respectively.
|
|
The basic (non-suffixed) API call on datasets deals with real(c<sub>double</sub>) (see Table above).
|
|
</p>
|
|
</div>
|
|
|
|
<div id="outline-container-org0bed97d" class="outline-5">
|
|
<h5 id="org0bed97d"><span class="section-number-5">3.4.2.1</span> Function declarations</h5>
|
|
</div>
|
|
|
|
<div id="outline-container-org4a79b76" class="outline-5">
|
|
<h5 id="org4a79b76"><span class="section-number-5">3.4.2.2</span> Source code for double precision functions</h5>
|
|
<div class="outline-text-5" id="text-3-4-2-2">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_read_$group_dset$_64</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, $group_dset_dtype_double$* <span style="color: #a020f0;">const</span> $group_dset$)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> ($group_dset$ == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> TREXIO_DSET_MISSING;
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span>;
|
|
int64_t $group_dset_dim$ = 0;
|
|
|
|
/* <span style="color: #b22222;">Error handling for this call is added by the generator</span> */
|
|
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
|
|
|
|
<span style="color: #a020f0;">if</span> ($group_dset_dim$ == 0L) <span style="color: #a020f0;">return</span> TREXIO_INVALID_NUM;
|
|
|
|
<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">rank</span> = $group_dset_rank$;
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dims</span>[$group_dset_rank$] = {$group_dset_dim_list$};
|
|
|
|
assert(file->back_end < TREXIO_INVALID_BACK_END);
|
|
|
|
rc = TREXIO_FAILURE;
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
rc = trexio_text_read_$group_dset$(file, $group_dset$, rank, dims);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
rc = trexio_hdf5_read_$group_dset$(file, $group_dset$, rank, dims);
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
rc = TREXIO_BACK_END_MISSING;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> rc = trexio_json_read_$group_dset$(file, $group_dset$, rank, dims);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
/* <span style="color: #b22222;">Handle index type</span> */
|
|
<span style="color: #a020f0;">if</span> ($is_index$) {
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dim_size</span> = 1;
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">i</span>=0; i<rank; ++i){
|
|
dim_size *= dims[i];
|
|
}
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">i</span>=0; i<dim_size; ++i){
|
|
$group_dset$[i] += ($group_dset_dtype_double$) 1;
|
|
}
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_write_$group_dset$_64</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #a020f0;">const</span> $group_dset_dtype_double$* $group_dset$)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
assert(file->back_end < TREXIO_INVALID_BACK_END);
|
|
|
|
<span style="color: #a020f0;">if</span> ($group_dset$ == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (trexio_has_$group_dset$(file) == TREXIO_SUCCESS && file->mode != <span style="color: #8b2252;">'u'</span>) <span style="color: #a020f0;">return</span> TREXIO_DSET_ALREADY_EXISTS;
|
|
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span>;
|
|
int64_t $group_dset_dim$ = 0;
|
|
|
|
/* <span style="color: #b22222;">Error handling for this call is added by the generator</span> */
|
|
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
|
|
|
|
<span style="color: #a020f0;">if</span> ($group_dset_dim$ == 0L) <span style="color: #a020f0;">return</span> TREXIO_INVALID_NUM;
|
|
|
|
<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">rank</span> = $group_dset_rank$;
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dims</span>[$group_dset_rank$] = {$group_dset_dim_list$};
|
|
|
|
<span style="color: #a020f0;">if</span> ($is_index$) {
|
|
/* <span style="color: #b22222;">Handle index type : is_index = $is_index$</span> */
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dim_size</span> = 1;
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">i</span>=0; i<rank; ++i){
|
|
dim_size *= dims[i];
|
|
}
|
|
|
|
$group_dset_dtype_double$* $group_dset$_p =
|
|
CALLOC(dim_size, $group_dset_dtype_double$);
|
|
|
|
<span style="color: #a020f0;">if</span> ($group_dset$_p == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_ALLOCATION_FAILED;
|
|
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">i</span>=0; i<dim_size; ++i){
|
|
$group_dset$_p[i] = $group_dset$[i] - ($group_dset_dtype_double$) 1;
|
|
}
|
|
|
|
rc = TREXIO_FAILURE;
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
rc = trexio_text_write_$group_dset$(file,
|
|
(<span style="color: #a020f0;">const</span> $group_dset_dtype_double$*) $group_dset$_p,
|
|
rank, dims);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
rc = trexio_hdf5_write_$group_dset$(file,
|
|
(<span style="color: #a020f0;">const</span> $group_dset_dtype_double$*) $group_dset$_p,
|
|
rank, dims);
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
rc = TREXIO_BACK_END_MISSING;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> rc = trexio_json_write_$group_dset$(file, $group_dset$_p, rank, dims);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
FREE($group_dset$_p);
|
|
|
|
}
|
|
|
|
} <span style="color: #a020f0;">else</span> {
|
|
|
|
rc = TREXIO_FAILURE;
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
rc = trexio_text_write_$group_dset$(file, $group_dset$, rank, dims);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
rc = trexio_hdf5_write_$group_dset$(file, $group_dset$, rank, dims);
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
rc = TREXIO_BACK_END_MISSING;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> rc = trexio_json_write_$group_dset$(file, $group_dset$, rank, dims);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> rc;
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org5e7ced2" class="outline-5">
|
|
<h5 id="org5e7ced2"><span class="section-number-5">3.4.2.3</span> Source code for single precision functions</h5>
|
|
<div class="outline-text-5" id="text-3-4-2-3">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_read_$group_dset$_32</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, $group_dset_dtype_single$* <span style="color: #a020f0;">const</span> $group_dset$)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> ($group_dset$ == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> TREXIO_DSET_MISSING;
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span>;
|
|
int64_t $group_dset_dim$ = 0;
|
|
|
|
/* <span style="color: #b22222;">Error handling for this call is added by the generator</span> */
|
|
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
|
|
|
|
<span style="color: #a020f0;">if</span> ($group_dset_dim$ == 0L) <span style="color: #a020f0;">return</span> TREXIO_INVALID_NUM;
|
|
|
|
<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">rank</span> = $group_dset_rank$;
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dims</span>[$group_dset_rank$] = {$group_dset_dim_list$};
|
|
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dim_size</span> = 1;
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">i</span>=0; i<rank; ++i){
|
|
dim_size *= dims[i];
|
|
}
|
|
|
|
$group_dset_dtype_double$* $group_dset$_64 = CALLOC(dim_size, $group_dset_dtype_double$);
|
|
<span style="color: #a020f0;">if</span> ($group_dset$_64 == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_ALLOCATION_FAILED;
|
|
|
|
assert(file->back_end < TREXIO_INVALID_BACK_END);
|
|
|
|
rc = TREXIO_FAILURE;
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
rc = trexio_text_read_$group_dset$(file, $group_dset$_64, rank, dims);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
rc = trexio_hdf5_read_$group_dset$(file, $group_dset$_64, rank, dims);
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
rc = TREXIO_BACK_END_MISSING;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> rc = trexio_json_read_$group_dset$(file, $group_dset$_64, rank, dims);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS){
|
|
FREE($group_dset$_64);
|
|
<span style="color: #a020f0;">return</span> rc;
|
|
}
|
|
|
|
<span style="color: #a020f0;">if</span> ($is_index$) {
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">i</span>=0; i<dim_size; ++i){
|
|
$group_dset$[i] = ($group_dset_dtype_single$) $group_dset$_64[i] + 1;
|
|
}
|
|
} <span style="color: #a020f0;">else</span> {
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">i</span>=0; i<dim_size; ++i){
|
|
$group_dset$[i] = ($group_dset_dtype_single$) $group_dset$_64[i];
|
|
}
|
|
}
|
|
|
|
FREE($group_dset$_64);
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_write_$group_dset$_32</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #a020f0;">const</span> $group_dset_dtype_single$* $group_dset$)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> ($group_dset$ == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (trexio_has_$group_dset$(file) == TREXIO_SUCCESS && file->mode != <span style="color: #8b2252;">'u'</span>) <span style="color: #a020f0;">return</span> TREXIO_DSET_ALREADY_EXISTS;
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span>;
|
|
int64_t $group_dset_dim$ = 0;
|
|
|
|
/* <span style="color: #b22222;">Error handling for this call is added by the generator</span> */
|
|
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
|
|
|
|
<span style="color: #a020f0;">if</span> ($group_dset_dim$ == 0L) <span style="color: #a020f0;">return</span> TREXIO_INVALID_NUM;
|
|
|
|
<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">rank</span> = $group_dset_rank$;
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dims</span>[$group_dset_rank$] = {$group_dset_dim_list$};
|
|
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dim_size</span> = 1;
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">i</span>=0; i<rank; ++i){
|
|
dim_size *= dims[i];
|
|
}
|
|
|
|
$group_dset_dtype_double$* $group_dset$_64 = CALLOC(dim_size, $group_dset_dtype_double$);
|
|
<span style="color: #a020f0;">if</span> ($group_dset$_64 == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_ALLOCATION_FAILED;
|
|
|
|
/* <span style="color: #b22222;">A type conversion from single precision to double required since back end only accepts 64-bit data</span> */
|
|
<span style="color: #a020f0;">if</span> ($is_index$) {
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">i</span>=0; i<dim_size; ++i){
|
|
$group_dset$_64[i] = ($group_dset_dtype_double$) $group_dset$[i] - ($group_dset_dtype_double$) 1;
|
|
}
|
|
} <span style="color: #a020f0;">else</span> {
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">i</span>=0; i<dim_size; ++i){
|
|
$group_dset$_64[i] = ($group_dset_dtype_double$) $group_dset$[i];
|
|
}
|
|
}
|
|
|
|
assert(file->back_end < TREXIO_INVALID_BACK_END);
|
|
|
|
rc = TREXIO_FAILURE;
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
rc = trexio_text_write_$group_dset$(file, $group_dset$_64, rank, dims);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
rc = trexio_hdf5_write_$group_dset$(file, $group_dset$_64, rank, dims);
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
rc = TREXIO_BACK_END_MISSING;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> rc = trexio_json_write_$group_dset$(file, $group_dset$_64, rank, dims);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
|
|
FREE($group_dset$_64);
|
|
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org04136d1" class="outline-5">
|
|
<h5 id="org04136d1"><span class="section-number-5">3.4.2.4</span> Source code for memory-safe functions</h5>
|
|
<div class="outline-text-5" id="text-3-4-2-4">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c" id="org8e93794"><span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span>;
|
|
int64_t $group_dset_dim$ = 0;
|
|
|
|
/* <span style="color: #b22222;">Error handling for this call is added by the generator</span> */
|
|
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
|
|
|
|
<span style="color: #a020f0;">if</span> ($group_dset_dim$ == 0L) <span style="color: #a020f0;">return</span> TREXIO_INVALID_NUM;
|
|
|
|
<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">rank</span> = $group_dset_rank$;
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dims</span>[$group_dset_rank$] = {$group_dset_dim_list$};
|
|
|
|
/* <span style="color: #b22222;">The block below is specific to safe API as it checks the boundaries</span> */
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dim_size</span> = 1;
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">i</span>=0; i<rank; ++i){
|
|
dim_size *= dims[i];
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_read_safe_$group_dset$_32</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, $group_dset_dtype_single$* <span style="color: #a020f0;">const</span> dset_out, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">dim_out</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (dset_out == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> TREXIO_DSET_MISSING;
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span>;
|
|
int64_t $group_dset_dim$ = 0;
|
|
|
|
/* <span style="color: #b22222;">Error handling for this call is added by the generator</span> */
|
|
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
|
|
|
|
<span style="color: #a020f0;">if</span> ($group_dset_dim$ == 0L) <span style="color: #a020f0;">return</span> TREXIO_INVALID_NUM;
|
|
|
|
<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">rank</span> = $group_dset_rank$;
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dims</span>[$group_dset_rank$] = {$group_dset_dim_list$};
|
|
|
|
/* <span style="color: #b22222;">The block below is specific to safe API as it checks the boundaries</span> */
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dim_size</span> = 1;
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">i</span>=0; i<rank; ++i){
|
|
dim_size *= dims[i];
|
|
}
|
|
|
|
<span style="color: #a020f0;">if</span> (dim_out > (<span style="color: #228b22;">int64_t</span>) dim_size) <span style="color: #a020f0;">return</span> TREXIO_UNSAFE_ARRAY_DIM;
|
|
|
|
<span style="color: #a020f0;">return</span> trexio_read_$group_dset$_32(file, dset_out);
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_write_safe_$group_dset$_32</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #a020f0;">const</span> $group_dset_dtype_single$* dset_in, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">dim_in</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (dset_in == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (trexio_has_$group_dset$(file) == TREXIO_SUCCESS && file->mode != <span style="color: #8b2252;">'u'</span>) <span style="color: #a020f0;">return</span> TREXIO_DSET_ALREADY_EXISTS;
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span>;
|
|
int64_t $group_dset_dim$ = 0;
|
|
|
|
/* <span style="color: #b22222;">Error handling for this call is added by the generator</span> */
|
|
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
|
|
|
|
<span style="color: #a020f0;">if</span> ($group_dset_dim$ == 0L) <span style="color: #a020f0;">return</span> TREXIO_INVALID_NUM;
|
|
|
|
<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">rank</span> = $group_dset_rank$;
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dims</span>[$group_dset_rank$] = {$group_dset_dim_list$};
|
|
|
|
/* <span style="color: #b22222;">The block below is specific to safe API as it checks the boundaries</span> */
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dim_size</span> = 1;
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">i</span>=0; i<rank; ++i){
|
|
dim_size *= dims[i];
|
|
}
|
|
|
|
<span style="color: #a020f0;">if</span> (dim_in > (<span style="color: #228b22;">int64_t</span>) dim_size) <span style="color: #a020f0;">return</span> TREXIO_UNSAFE_ARRAY_DIM;
|
|
|
|
<span style="color: #a020f0;">return</span> trexio_write_$group_dset$_32(file, dset_in);
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_read_safe_$group_dset$_64</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, $group_dset_dtype_double$* <span style="color: #a020f0;">const</span> dset_out, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">dim_out</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (dset_out == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> TREXIO_DSET_MISSING;
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span>;
|
|
int64_t $group_dset_dim$ = 0;
|
|
|
|
/* <span style="color: #b22222;">Error handling for this call is added by the generator</span> */
|
|
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
|
|
|
|
<span style="color: #a020f0;">if</span> ($group_dset_dim$ == 0L) <span style="color: #a020f0;">return</span> TREXIO_INVALID_NUM;
|
|
|
|
<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">rank</span> = $group_dset_rank$;
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dims</span>[$group_dset_rank$] = {$group_dset_dim_list$};
|
|
|
|
/* <span style="color: #b22222;">The block below is specific to safe API as it checks the boundaries</span> */
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dim_size</span> = 1;
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">i</span>=0; i<rank; ++i){
|
|
dim_size *= dims[i];
|
|
}
|
|
|
|
<span style="color: #a020f0;">if</span> (dim_out > (<span style="color: #228b22;">int64_t</span>) dim_size) <span style="color: #a020f0;">return</span> TREXIO_UNSAFE_ARRAY_DIM;
|
|
|
|
<span style="color: #a020f0;">return</span> trexio_read_$group_dset$_64(file, dset_out);
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_write_safe_$group_dset$_64</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #a020f0;">const</span> $group_dset_dtype_double$* dset_in, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">dim_in</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (dset_in == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (trexio_has_$group_dset$(file) == TREXIO_SUCCESS && file->mode != <span style="color: #8b2252;">'u'</span>) <span style="color: #a020f0;">return</span> TREXIO_DSET_ALREADY_EXISTS;
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span>;
|
|
int64_t $group_dset_dim$ = 0;
|
|
|
|
/* <span style="color: #b22222;">Error handling for this call is added by the generator</span> */
|
|
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
|
|
|
|
<span style="color: #a020f0;">if</span> ($group_dset_dim$ == 0L) <span style="color: #a020f0;">return</span> TREXIO_INVALID_NUM;
|
|
|
|
<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">rank</span> = $group_dset_rank$;
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dims</span>[$group_dset_rank$] = {$group_dset_dim_list$};
|
|
|
|
/* <span style="color: #b22222;">The block below is specific to safe API as it checks the boundaries</span> */
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dim_size</span> = 1;
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">i</span>=0; i<rank; ++i){
|
|
dim_size *= dims[i];
|
|
}
|
|
|
|
<span style="color: #a020f0;">if</span> (dim_in > (<span style="color: #228b22;">int64_t</span>) dim_size) <span style="color: #a020f0;">return</span> TREXIO_UNSAFE_ARRAY_DIM;
|
|
|
|
<span style="color: #a020f0;">return</span> trexio_write_$group_dset$_64(file, dset_in);
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orgb86367a" class="outline-5">
|
|
<h5 id="orgb86367a"><span class="section-number-5">3.4.2.5</span> Source code for default functions</h5>
|
|
<div class="outline-text-5" id="text-3-4-2-5">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_read_safe_$group_dset$</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, $group_dset_dtype_default$* <span style="color: #a020f0;">const</span> $group_dset$, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">dim_out</span>)
|
|
{
|
|
<span style="color: #a020f0;">return</span> trexio_read_safe_$group_dset$_$default_prec$(file, $group_dset$, dim_out);
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_write_safe_$group_dset$</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #a020f0;">const</span> $group_dset_dtype_default$* $group_dset$, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">dim_in</span>)
|
|
{
|
|
<span style="color: #a020f0;">return</span> trexio_write_safe_$group_dset$_$default_prec$(file, $group_dset$, dim_in);
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_read_$group_dset$</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, $group_dset_dtype_default$* <span style="color: #a020f0;">const</span> $group_dset$)
|
|
{
|
|
<span style="color: #a020f0;">return</span> trexio_read_$group_dset$_$default_prec$(file, $group_dset$);
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_write_$group_dset$</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #a020f0;">const</span> $group_dset_dtype_default$* $group_dset$)
|
|
{
|
|
<span style="color: #a020f0;">return</span> trexio_write_$group_dset$_$default_prec$(file, $group_dset$);
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_has_$group_dset$</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
|
|
assert(file->back_end < TREXIO_INVALID_BACK_END);
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
<span style="color: #a020f0;">return</span> trexio_text_has_$group_dset$(file);
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
<span style="color: #a020f0;">return</span> trexio_hdf5_has_$group_dset$(file);
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">return</span> TREXIO_BACK_END_MISSING;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> return trexio_json_has_$group_dset$(file);</span>
|
|
*/
|
|
}
|
|
<span style="color: #a020f0;">return</span> TREXIO_FAILURE;
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org9ad6138" class="outline-4">
|
|
<h4 id="org9ad6138"><span class="section-number-4">3.4.3</span> Fortran templates for front end</h4>
|
|
<div class="outline-text-4" id="text-3-4-3">
|
|
<p>
|
|
The <code>Fortran</code> templates that provide an access to the <code>C</code> API calls from <code>Fortran</code>.
|
|
These templates are based on the use of <code>iso_c_binding</code>. Pointers have to be passed by value.
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_write_$group_dset$_64</span> (trex_file, dset) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
$group_dset_f_dtype_double$, <span style="color: #a020f0;">intent</span>(in) :: dset$group_dset_f_dims$
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_write_$group_dset$_64</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_read_$group_dset$_64</span> (trex_file, dset) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
$group_dset_f_dtype_double$, <span style="color: #a020f0;">intent</span>(out) :: dset$group_dset_f_dims$
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_read_$group_dset$_64</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_write_$group_dset$_32</span> (trex_file, dset) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
$group_dset_f_dtype_single$, <span style="color: #a020f0;">intent</span>(in) :: dset$group_dset_f_dims$
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_write_$group_dset$_32</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_read_$group_dset$_32</span> (trex_file, dset) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
$group_dset_f_dtype_single$, <span style="color: #a020f0;">intent</span>(out) :: dset$group_dset_f_dims$
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_read_$group_dset$_32</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_write_$group_dset$</span> (trex_file, dset) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
$group_dset_f_dtype_default$, <span style="color: #a020f0;">intent</span>(in) :: dset$group_dset_f_dims$
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_write_$group_dset$</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_read_$group_dset$</span> (trex_file, dset) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
$group_dset_f_dtype_default$, <span style="color: #a020f0;">intent</span>(out) :: dset$group_dset_f_dims$
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_read_$group_dset$</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_has_$group_dset$</span> (trex_file) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_has_$group_dset$</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orgf1178d2" class="outline-4">
|
|
<h4 id="orgf1178d2"><span class="section-number-4">3.4.4</span> Python templates for front end</h4>
|
|
<div class="outline-text-4" id="text-3-4-4">
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">write_</span>$group_dset$(trexio_file, dset_w) -> <span style="color: #008b8b;">None</span>:
|
|
<span style="color: #8b2252;">"""Write the $group_dset$ array of numbers in the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameters:</span>
|
|
|
|
<span style="color: #8b2252;"> trexio_file:</span>
|
|
<span style="color: #8b2252;"> TREXIO File object.</span>
|
|
|
|
<span style="color: #8b2252;"> dset_w: list OR numpy.ndarray</span>
|
|
<span style="color: #8b2252;"> Array of $group_dset$ values to be written. If array data type does not correspond to int64 or float64, the conversion is performed.</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - trexio.Error if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a0522d;">doConversion</span> = <span style="color: #008b8b;">False</span>
|
|
<span style="color: #a0522d;">doFlatten</span> = <span style="color: #008b8b;">False</span>
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">not</span> <span style="color: #483d8b;">isinstance</span>(dset_w, (<span style="color: #483d8b;">list</span>, <span style="color: #483d8b;">tuple</span>)):
|
|
# <span style="color: #b22222;">if input array is not a list or tuple then it is probably a numpy array</span>
|
|
<span style="color: #a020f0;">if</span> <span style="color: #483d8b;">isinstance</span>(dset_w, np.ndarray) <span style="color: #a020f0;">and</span> (<span style="color: #a020f0;">not</span> dset_w.dtype==np.int64 <span style="color: #a020f0;">or</span> <span style="color: #a020f0;">not</span> dset_w.dtype==np.float64):
|
|
<span style="color: #a0522d;">doConversion</span> = <span style="color: #008b8b;">True</span>
|
|
|
|
<span style="color: #a020f0;">if</span> <span style="color: #483d8b;">len</span>(dset_w.shape) > 1:
|
|
<span style="color: #a0522d;">doFlatten</span> = <span style="color: #008b8b;">True</span>
|
|
<span style="color: #a020f0;">if</span> doConversion:
|
|
<span style="color: #a0522d;">dset_64</span> = np.$group_dset_py_dtype$64(dset_w).flatten()
|
|
<span style="color: #a020f0;">else</span>:
|
|
<span style="color: #a0522d;">dset_flat</span> = np.array(dset_w, dtype=np.$group_dset_py_dtype$64).flatten()
|
|
<span style="color: #a020f0;">else</span>:
|
|
<span style="color: #a020f0;">if</span> doConversion:
|
|
<span style="color: #a0522d;">dset_64</span> = np.$group_dset_py_dtype$64(dset_w)
|
|
|
|
<span style="color: #a020f0;">else</span>:
|
|
# <span style="color: #b22222;">if input array is a multidimensional list or tuple, we have to convert it</span>
|
|
<span style="color: #a020f0;">try</span>:
|
|
<span style="color: #a0522d;">doFlatten</span> = <span style="color: #008b8b;">True</span>
|
|
<span style="color: #a0522d;">ncol</span> = <span style="color: #483d8b;">len</span>(dset_w[0])
|
|
<span style="color: #a0522d;">dset_flat</span> = np.array(dset_w, dtype=np.$group_dset_py_dtype$64).flatten()
|
|
<span style="color: #a020f0;">except</span> <span style="color: #228b22;">TypeError</span>:
|
|
<span style="color: #a0522d;">doFlatten</span> = <span style="color: #008b8b;">False</span>
|
|
<span style="color: #a020f0;">pass</span>
|
|
|
|
|
|
<span style="color: #a020f0;">if</span> doConversion:
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_write_safe_$group_dset$_64(trexio_file.pytrexio_s, dset_64)
|
|
<span style="color: #a020f0;">elif</span> doFlatten:
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_write_safe_$group_dset$_64(trexio_file.pytrexio_s, dset_flat)
|
|
<span style="color: #a020f0;">else</span>:
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_write_safe_$group_dset$_64(trexio_file.pytrexio_s, dset_w)
|
|
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">read_</span>$group_dset$(trexio_file, dim = <span style="color: #008b8b;">None</span>, doReshape = <span style="color: #008b8b;">None</span>, dtype = <span style="color: #008b8b;">None</span>):
|
|
<span style="color: #8b2252;">"""Read the $group_dset$ array of numbers from the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameters:</span>
|
|
|
|
<span style="color: #8b2252;"> trexio_file:</span>
|
|
<span style="color: #8b2252;"> TREXIO File object.</span>
|
|
|
|
<span style="color: #8b2252;"> dim (Optional): int</span>
|
|
<span style="color: #8b2252;"> Size of the block to be read from the file (i.e. how many items of $group_dset$ will be returned)</span>
|
|
<span style="color: #8b2252;"> If None, the function will read all necessary array dimensions from the file.</span>
|
|
|
|
<span style="color: #8b2252;"> dtype (Optional): type</span>
|
|
<span style="color: #8b2252;"> NumPy data type of the output (e.g. np.int32|int16 or np.float32|float16). If specified, the output array will be converted from the default double precision.</span>
|
|
|
|
<span style="color: #8b2252;"> doReshape (Optional): bool</span>
|
|
<span style="color: #8b2252;"> Flag to determine whether the output NumPy array has be reshaped or not. Be default, reshaping is performed</span>
|
|
<span style="color: #8b2252;"> based on the dimensions from the ~trex.json~ file. Otherwise, ~shape~ array (list or tuple) is used if provided by the user.</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> ~dset_64~ if dtype is None or ~dset_converted~ otherwise: numpy.ndarray</span>
|
|
<span style="color: #8b2252;"> 1D NumPy array with ~dim~ elements corresponding to $group_dset$ values read from the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - trexio.Error if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;">"""</span>
|
|
|
|
<span style="color: #a020f0;">if</span> doReshape <span style="color: #a020f0;">is</span> <span style="color: #008b8b;">None</span>:
|
|
<span style="color: #a0522d;">doReshape</span> = <span style="color: #008b8b;">True</span>
|
|
|
|
# <span style="color: #b22222;">if dim is not specified, read dimensions from the TREXIO file</span>
|
|
<span style="color: #a0522d;">dims_list</span> = <span style="color: #008b8b;">None</span>
|
|
<span style="color: #a020f0;">if</span> doReshape:
|
|
$group_dset_dim$ = read_$group_dset_dim$(trexio_file)
|
|
|
|
<span style="color: #a0522d;">dims_list</span> = [$group_dset_dim_list$]
|
|
<span style="color: #a0522d;">dim_real</span> = 1
|
|
<span style="color: #a020f0;">for</span> i <span style="color: #a020f0;">in</span> <span style="color: #483d8b;">range</span>($group_dset_rank$):
|
|
<span style="color: #a0522d;">dim_real</span> *= dims_list[i]
|
|
|
|
<span style="color: #a020f0;">if</span> dim:
|
|
<span style="color: #a020f0;">if</span> dim_real != dim:
|
|
<span style="color: #a020f0;">raise</span> Error(TREXIO_UNSAFE_ARRAY_DIM)
|
|
<span style="color: #a020f0;">else</span>:
|
|
<span style="color: #a0522d;">dim</span> = dim_real
|
|
|
|
<span style="color: #a0522d;">shape</span> = <span style="color: #483d8b;">tuple</span>(dims_list)
|
|
<span style="color: #a020f0;">if</span> shape <span style="color: #a020f0;">is</span> <span style="color: #008b8b;">None</span> <span style="color: #a020f0;">and</span> doReshape:
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">ValueError</span>(<span style="color: #8b2252;">"Reshaping failure: shape is None."</span>)
|
|
|
|
|
|
<span style="color: #a0522d;">rc</span>, <span style="color: #a0522d;">dset_64</span> = pytr.trexio_read_safe_$group_dset$_64(trexio_file.pytrexio_s, dim)
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
|
|
|
|
<span style="color: #a0522d;">isConverted</span> = <span style="color: #008b8b;">False</span>
|
|
<span style="color: #a0522d;">dset_converted</span> = <span style="color: #008b8b;">None</span>
|
|
<span style="color: #a020f0;">if</span> dtype <span style="color: #a020f0;">is</span> <span style="color: #a020f0;">not</span> <span style="color: #008b8b;">None</span>:
|
|
<span style="color: #a020f0;">try</span>:
|
|
<span style="color: #a020f0;">assert</span> <span style="color: #483d8b;">isinstance</span>(dtype, <span style="color: #483d8b;">type</span>)
|
|
<span style="color: #a020f0;">except</span> <span style="color: #228b22;">AssertionError</span>:
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">TypeError</span>(<span style="color: #8b2252;">"dtype argument has to be an instance of the type class (e.g. np.float32)."</span>)
|
|
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">not</span> dtype==np.int64 <span style="color: #a020f0;">or</span> <span style="color: #a020f0;">not</span> dtype==np.float64:
|
|
<span style="color: #a0522d;">dset_converted</span> = np.array(dset_64, dtype=dtype)
|
|
<span style="color: #a0522d;">isConverted</span> = <span style="color: #008b8b;">True</span>
|
|
|
|
# <span style="color: #b22222;">additional assert can be added here to check that read_safe functions returns numpy array of proper dimension</span>
|
|
|
|
<span style="color: #a020f0;">if</span> doReshape:
|
|
# <span style="color: #b22222;">in-place reshaping did not work so I have to make a copy</span>
|
|
<span style="color: #a020f0;">if</span> isConverted:
|
|
<span style="color: #a0522d;">dset_reshaped</span> = np.reshape(dset_converted, shape, order=<span style="color: #8b2252;">'C'</span>)
|
|
<span style="color: #a020f0;">else</span>:
|
|
<span style="color: #a0522d;">dset_reshaped</span> = np.reshape(dset_64, shape, order=<span style="color: #8b2252;">'C'</span>)
|
|
|
|
<span style="color: #a020f0;">if</span> isConverted:
|
|
<span style="color: #a020f0;">return</span> dset_converted
|
|
<span style="color: #a020f0;">elif</span> doReshape:
|
|
<span style="color: #a020f0;">return</span> dset_reshaped
|
|
<span style="color: #a020f0;">else</span>:
|
|
<span style="color: #a020f0;">return</span> dset_64
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">has_</span>$group_dset$(trexio_file) -> <span style="color: #483d8b;">bool</span>:
|
|
<span style="color: #8b2252;">"""Check that $group_dset$ variable exists in the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function.</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> True if the variable exists, False otherwise</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - trexio.Error if TREXIO return code ~rc~ is TREXIO_FAILURE and prints the error message using string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_has_$group_dset$(trexio_file.pytrexio_s)
|
|
<span style="color: #a020f0;">if</span> rc == TREXIO_FAILURE:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
|
|
<span style="color: #a020f0;">return</span> rc == TREXIO_SUCCESS
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orge9a36ea" class="outline-3">
|
|
<h3 id="orge9a36ea"><span class="section-number-3">3.5</span> Templates for front end has/read/write a dataset of sparse data</h3>
|
|
<div class="outline-text-3" id="text-3-5">
|
|
</div>
|
|
<div id="outline-container-orgf42d80a" class="outline-4">
|
|
<h4 id="orgf42d80a"><span class="section-number-4">3.5.1</span> Introduction</h4>
|
|
<div class="outline-text-4" id="text-3-5-1">
|
|
<p>
|
|
Sparse data structures are used typically for large tensors such as
|
|
two-electron integrals. For example, in the <code>trex.json</code> file sparse
|
|
arrays appear as for the <code>eri</code> :
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #8b2252;">"ao_2e_int"</span> : {
|
|
<span style="color: #8b2252;">"eri"</span> : [ <span style="color: #8b2252;">"float sparse"</span>, [ <span style="color: #8b2252;">"ao.num"</span>, <span style="color: #8b2252;">"ao.num"</span>, <span style="color: #8b2252;">"ao.num"</span>, <span style="color: #8b2252;">"ao.num"</span> ] ]
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<p>
|
|
The electron repulsion integral (eri) \(\langle ij | kl \rangle\) is
|
|
represented as a quartet of integers \((i,j,k,l)\) and a floating
|
|
point value.
|
|
</p>
|
|
|
|
<p>
|
|
To store \(N\) integrals in the file, we store
|
|
</p>
|
|
|
|
<ul class="org-ul">
|
|
<li>An array of quartets of integers</li>
|
|
<li>An array of values (floats)</li>
|
|
</ul>
|
|
|
|
<p>
|
|
Both arrays have the same size, \(N\), the number of non-zero integrals.
|
|
Knowing the maximum dimensions allows to check that the integers are
|
|
in a valid range, and also lets the library choose the smallest
|
|
integer representation to compress the storage.
|
|
</p>
|
|
|
|
<p>
|
|
Fortran uses 1-based array indexing, while C uses 0-based indexing.
|
|
Internally, we use a 0-based representation but the Fortran binding
|
|
does the appropriate conversion when reading or writing.
|
|
</p>
|
|
|
|
<p>
|
|
As the number of integrals to store can be prohibitively large, we
|
|
provide the possibility to read/write the integrals in chunks. So the
|
|
functions take two extra parameters:
|
|
</p>
|
|
|
|
<ul class="org-ul">
|
|
<li><code>offset_file</code> : how many integrals in the file should be skipped when reading/writing.
|
|
An offset of zero implies to read the first integral.</li>
|
|
<li><code>buffer_size</code> : the number of integrals to read/write.
|
|
If EOF is encountered upon reading, the <code>buffer_size</code> is overwritten with the number
|
|
of integrals that have been read before EOF and the <code>trexio_read_</code> function return
|
|
<code>TREXIO_END</code> exit code instead of <code>TREXIO_SUCCESS</code>.</li>
|
|
</ul>
|
|
|
|
<p>
|
|
The storage of <code>int</code> indices is internally compressed based on the maximum possible value of an index,
|
|
which is derived from the corresponding dimension of the sparse array (e.g. <code>ao_num</code> is the upper bound
|
|
of indices in the aforementioned <code>ao_2e_int_eri</code> dataset).
|
|
The upper bounds for different <code>int</code> types (e.g. <code>uint16_t</code>) can be found in the in the <code>stdint.h</code> C library.
|
|
Currently implemented list of compressions based on the upper bound of indices can be found below:
|
|
</p>
|
|
|
|
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
|
|
|
|
|
|
<colgroup>
|
|
<col class="org-left" />
|
|
|
|
<col class="org-left" />
|
|
</colgroup>
|
|
<thead>
|
|
<tr>
|
|
<th scope="col" class="org-left">Max value of indices</th>
|
|
<th scope="col" class="org-left">Internal representation (in the TREXIO file)</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="org-left"><code>UINT8_MAX</code> (e.g. \(< 255\))</td>
|
|
<td class="org-left">8-bit unsigned int</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>UINT16_MAX</code> (e.g. \(< 65535\))</td>
|
|
<td class="org-left">16-bit unsigned int</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left">Otherwise (e.g. \(\ge 65535\))</td>
|
|
<td class="org-left">32-bit signed int</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
<p>
|
|
This section concerns API calls related to sparse data structures.
|
|
</p>
|
|
|
|
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
|
|
|
|
|
|
<colgroup>
|
|
<col class="org-left" />
|
|
|
|
<col class="org-left" />
|
|
|
|
<col class="org-left" />
|
|
</colgroup>
|
|
<thead>
|
|
<tr>
|
|
<th scope="col" class="org-left">Function name</th>
|
|
<th scope="col" class="org-left">Description</th>
|
|
<th scope="col" class="org-left">Precision</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="org-left"><code>trexio_has_$group_dset$</code></td>
|
|
<td class="org-left">Check if a sparse dset is present in a file</td>
|
|
<td class="org-left">---</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_read_$group_dset$</code></td>
|
|
<td class="org-left">Read indices and values of a sparse dset</td>
|
|
<td class="org-left">Single/Double for indices/values</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_read_$group_dset$_size</code></td>
|
|
<td class="org-left">Read the number of sparse data elements stored in the file</td>
|
|
<td class="org-left">Double for size</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_write_$group_dset$</code></td>
|
|
<td class="org-left">Write indices and values of a sparse dset</td>
|
|
<td class="org-left">Single/Double for indices/values</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_read_safe_$group_dset$</code></td>
|
|
<td class="org-left">Safe (bounded) read of indices and values (for Python API)</td>
|
|
<td class="org-left">Single/Double for indices/values</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_write_safe_$group_dset$</code></td>
|
|
<td class="org-left">Safe (bounded) write of indices and values (for Python API)</td>
|
|
<td class="org-left">Single/Double for indices/values</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org28d4b56" class="outline-4">
|
|
<h4 id="org28d4b56"><span class="section-number-4">3.5.2</span> C templates for front end</h4>
|
|
<div class="outline-text-4" id="text-3-5-2">
|
|
</div>
|
|
<div id="outline-container-org01087cb" class="outline-5">
|
|
<h5 id="org01087cb"><span class="section-number-5">3.5.2.1</span> Function declarations</h5>
|
|
</div>
|
|
|
|
<div id="outline-container-orga7a85b5" class="outline-5">
|
|
<h5 id="orga7a85b5"><span class="section-number-5">3.5.2.2</span> Source code for default functions</h5>
|
|
<div class="outline-text-5" id="text-3-5-2-2">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span> <span style="color: #0000ff;">trexio_read_safe_$group_dset$</span>(<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">offset_file</span>,
|
|
<span style="color: #228b22;">int64_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">buffer_size_read</span>,
|
|
<span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">index_sparse_read</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">size_index_read</span>,
|
|
<span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">value_sparse_read</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">size_value_read</span>
|
|
)
|
|
{
|
|
<span style="color: #a020f0;">return</span> trexio_read_$group_dset$(file, offset_file, buffer_size_read, index_sparse_read, value_sparse_read);
|
|
}
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_read_$group_dset$</span>(<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">offset_file</span>,
|
|
<span style="color: #228b22;">int64_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">buffer_size</span>,
|
|
<span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">index_sparse</span>,
|
|
<span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">value_sparse</span>
|
|
)
|
|
{
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (offset_file < 0L) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (*buffer_size <= 0L) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_3;
|
|
<span style="color: #a020f0;">if</span> (index_sparse == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_4;
|
|
<span style="color: #a020f0;">if</span> (value_sparse == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_5;
|
|
<span style="color: #a020f0;">if</span> (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> TREXIO_DSET_MISSING;
|
|
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">rank</span> = $group_dset_rank$; // <span style="color: #b22222;">To be set by generator : number of indices</span>
|
|
|
|
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">size_max</span>; // <span style="color: #b22222;">Max number of integrals (already in the file)</span>
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span>;
|
|
|
|
/* <span style="color: #b22222;">Read the max number of integrals stored in the file</span> */
|
|
rc = trexio_read_$group_dset$_size(file, &size_max);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
/* <span style="color: #b22222;">To be set by generator : number of unique dimensions</span>
|
|
<span style="color: #b22222;"> (e.g. 1 for ERI in AO basis because only ao_num is present in the list of dimensions)</span> */
|
|
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">unique_rank</span> $group_dset_unique_rank$
|
|
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">unique_dims</span>[$group_dset_unique_rank$];
|
|
|
|
// <span style="color: #b22222;">Below part is populated by the generator when unique_rank > 1</span>
|
|
rc = trexio_read_$group_dset_unique_dim$_64(file, &unique_dims[$dim_id$]); <span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
/* <span style="color: #b22222;">Find the maximal value along all dimensions to define the compression technique in the back end</span> */
|
|
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">max_dim</span> = unique_dims[0];
|
|
<span style="color: #483d8b;">#if</span> (unique_rank != 1)
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">i</span> = 1; i < unique_rank; i++) {
|
|
<span style="color: #a020f0;">if</span> (unique_dims[i] > max_dim) max_dim = unique_dims[i];
|
|
}
|
|
<span style="color: #483d8b;">#endif</span>
|
|
<span style="color: #483d8b;">#undef</span> unique_rank
|
|
|
|
// <span style="color: #b22222;">introduce a new variable which will be modified with the number of integrals being read if EOF is encountered</span>
|
|
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">eof_read_size</span> = 0L;
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
rc = trexio_text_read_$group_dset$(file, offset_file, *buffer_size, max_dim, &eof_read_size, index_sparse, value_sparse);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
rc = trexio_hdf5_read_$group_dset$(file, offset_file, *buffer_size, max_dim, &eof_read_size, index_sparse, value_sparse);
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
rc = TREXIO_BACK_END_MISSING;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> return trexio_json_read_$group_dset$(...);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
<span style="color: #a020f0;">default</span>:
|
|
rc = TREXIO_FAILURE; /* <span style="color: #b22222;">Impossible case</span> */
|
|
<span style="color: #a020f0;">break</span>;
|
|
}
|
|
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS && rc != TREXIO_END) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
<span style="color: #a020f0;">if</span> (rc == TREXIO_END) *buffer_size = eof_read_size;
|
|
|
|
// <span style="color: #b22222;">shift indices to be one-based if Fortran API is used</span>
|
|
<span style="color: #a020f0;">if</span> (file->one_based) {
|
|
// <span style="color: #b22222;">if EOF is reached - shift only indices that have been read, not an entire buffer</span>
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">index_size</span> = rank*(*buffer_size) ;
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">i</span>=0; i<index_size; ++i){
|
|
index_sparse[i] += 1;
|
|
}
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> rc;
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_read_$group_dset$_size</span>(<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #228b22;">int64_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">size_max</span>)
|
|
{
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (size_max == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> TREXIO_DSET_MISSING;
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
<span style="color: #a020f0;">return</span> trexio_text_read_$group_dset$_size(file, size_max);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
<span style="color: #a020f0;">return</span> trexio_hdf5_read_$group_dset$_size(file, size_max);
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">return</span> TREXIO_BACK_END_MISSING;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> return trexio_json_read_$group_dset$_size(...);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
<span style="color: #a020f0;">default</span>:
|
|
<span style="color: #a020f0;">return</span> TREXIO_FAILURE; /* <span style="color: #b22222;">Impossible case</span> */
|
|
}
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span> <span style="color: #0000ff;">trexio_write_safe_$group_dset$</span>(<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">offset_file</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">buffer_size</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span>* <span style="color: #a0522d;">index_sparse_write</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">size_index_write</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span>* <span style="color: #a0522d;">value_sparse_write</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">size_value_write</span>
|
|
)
|
|
{
|
|
<span style="color: #a020f0;">return</span> trexio_write_$group_dset$(file, offset_file, buffer_size, index_sparse_write, value_sparse_write);
|
|
}
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_write_$group_dset$</span>(<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">offset_file</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">buffer_size</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span>* <span style="color: #a0522d;">index_sparse</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span>* <span style="color: #a0522d;">value_sparse</span>
|
|
)
|
|
{
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (offset_file < 0L) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (buffer_size <= 0L) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_3;
|
|
<span style="color: #a020f0;">if</span> (index_sparse == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_4;
|
|
<span style="color: #a020f0;">if</span> (value_sparse == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_5;
|
|
|
|
/* <span style="color: #b22222;">To be set by generator : number of indices</span> */
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">rank</span> = $group_dset_rank$;
|
|
|
|
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">size_max</span> = 0L; // <span style="color: #b22222;">Max number of integrals (already in the file)</span>
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span>;
|
|
|
|
/* <span style="color: #b22222;">Read the max number of integrals stored in the file</span> */
|
|
rc = trexio_read_$group_dset$_size(file, &size_max);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS && rc != TREXIO_DSET_MISSING) <span style="color: #a020f0;">return</span> rc;
|
|
<span style="color: #a020f0;">if</span> (rc == TREXIO_DSET_MISSING) size_max = 0L;
|
|
|
|
/* <span style="color: #b22222;">To be set by generator : number of unique dimensions</span>
|
|
<span style="color: #b22222;"> (e.g. 1 for ERI in AO basis because only ao_num is present in the list of dimensions)</span> */
|
|
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">unique_rank</span> $group_dset_unique_rank$
|
|
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">unique_dims</span>[$group_dset_unique_rank$];
|
|
|
|
// <span style="color: #b22222;">Below part is populated by the generator when unique_rank > 1</span>
|
|
rc = trexio_read_$group_dset_unique_dim$_64(file, &unique_dims[$dim_id$]); <span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
/* <span style="color: #b22222;">Find the maximal value along all dimensions to define the compression technique in the back end</span> */
|
|
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">max_dim</span> = unique_dims[0];
|
|
<span style="color: #483d8b;">#if</span> (unique_rank != 1)
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">i</span> = 1; i < unique_rank; i++) {
|
|
<span style="color: #a020f0;">if</span> (unique_dims[i] > max_dim) max_dim = unique_dims[i];
|
|
}
|
|
<span style="color: #483d8b;">#endif</span>
|
|
<span style="color: #483d8b;">#undef</span> unique_rank
|
|
|
|
// <span style="color: #b22222;">shift indices to be zero-based if Fortran API is used</span>
|
|
<span style="color: #a020f0;">if</span> (file->one_based) {
|
|
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">index_size</span> = rank * buffer_size;
|
|
|
|
<span style="color: #228b22;">int32_t</span>* <span style="color: #a0522d;">index_sparse_p</span> = CALLOC(index_size, int32_t);
|
|
<span style="color: #a020f0;">if</span> (index_sparse_p == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_ALLOCATION_FAILED;
|
|
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">i</span>=0; i<index_size; ++i){
|
|
index_sparse_p[i] = index_sparse[i] - 1;
|
|
}
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
rc = trexio_text_write_$group_dset$(file, offset_file, buffer_size, max_dim,
|
|
size_max, index_sparse_p, value_sparse);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
rc = trexio_hdf5_write_$group_dset$(file, offset_file, buffer_size, max_dim,
|
|
index_sparse_p, value_sparse);
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
rc = TREXIO_BACK_END_MISSING;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> rc = trexio_json_write_$group_dset$(...);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
<span style="color: #a020f0;">default</span>:
|
|
rc = TREXIO_FAILURE; /* <span style="color: #b22222;">Impossible case</span> */
|
|
<span style="color: #a020f0;">break</span>;
|
|
}
|
|
|
|
FREE(index_sparse_p);
|
|
|
|
}
|
|
<span style="color: #a020f0;">else</span> {
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
rc = trexio_text_write_$group_dset$(file, offset_file, buffer_size, max_dim,
|
|
size_max, index_sparse, value_sparse);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
rc = trexio_hdf5_write_$group_dset$(file, offset_file, buffer_size, max_dim,
|
|
index_sparse, value_sparse);
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
rc = TREXIO_BACK_END_MISSING;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> rc = trexio_json_write_$group_dset$(...);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
<span style="color: #a020f0;">default</span>:
|
|
rc = TREXIO_FAILURE; /* <span style="color: #b22222;">Impossible case</span> */
|
|
<span style="color: #a020f0;">break</span>;
|
|
}
|
|
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> rc;
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_has_$group_dset$</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
|
|
assert(file->back_end < TREXIO_INVALID_BACK_END);
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
<span style="color: #a020f0;">return</span> trexio_text_has_$group_dset$(file);
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
<span style="color: #a020f0;">return</span> trexio_hdf5_has_$group_dset$(file);
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">return</span> TREXIO_BACK_END_MISSING;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> return trexio_json_has_$group_dset$(file);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_FAILURE;
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org8e8da9f" class="outline-4">
|
|
<h4 id="org8e8da9f"><span class="section-number-4">3.5.3</span> Fortran templates for front end</h4>
|
|
<div class="outline-text-4" id="text-3-5-3">
|
|
<p>
|
|
The <code>Fortran</code> templates that provide an access to the <code>C</code> API calls from <code>Fortran</code>.
|
|
These templates are based on the use of <code>iso_c_binding</code>. Pointers have to be passed by value.
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code)<span style="color: #a0522d;"> function trexio_write_$group_dset$ (trex_file, </span><span style="color: #a020f0;">&</span>
|
|
offset_file, buffer_size, <span style="color: #a020f0;">&</span>
|
|
index_sparse, value_sparse) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</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;"> offset_file</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;"> buffer_size</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;"> index_sparse(*)</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> value_sparse(*)</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_write_$group_dset$</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
|
|
<span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code)<span style="color: #a0522d;"> function trexio_write_safe_$group_dset$ (trex_file, </span><span style="color: #a020f0;">&</span>
|
|
offset_file, buffer_size, <span style="color: #a020f0;">&</span>
|
|
index_sparse, index_size, <span style="color: #a020f0;">&</span>
|
|
value_sparse, value_size) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</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;"> offset_file</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;"> buffer_size</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;"> index_sparse(*)</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;"> index_size</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> value_sparse(*)</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;"> value_size</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_write_safe_$group_dset$</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code)<span style="color: #a0522d;"> function trexio_read_$group_dset$ (trex_file, </span><span style="color: #a020f0;">&</span>
|
|
offset_file, buffer_size, <span style="color: #a020f0;">&</span>
|
|
index_sparse, value_sparse) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</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;"> offset_file</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(inout) ::<span style="color: #a0522d;"> buffer_size</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> index_sparse(*)</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> value_sparse(*)</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_read_$group_dset$</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
|
|
<span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code)<span style="color: #a0522d;"> function trexio_read_safe_$group_dset$ (trex_file, </span><span style="color: #a020f0;">&</span>
|
|
offset_file, buffer_size, <span style="color: #a020f0;">&</span>
|
|
index_sparse, index_size, <span style="color: #a020f0;">&</span>
|
|
value_sparse, value_size) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</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;"> offset_file</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(inout) ::<span style="color: #a0522d;"> buffer_size</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> index_sparse(*)</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;"> index_size</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> value_sparse(*)</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;"> value_size</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_read_safe_$group_dset$</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code)<span style="color: #a0522d;"> function trexio_read_$group_dset$_size (trex_file, </span><span style="color: #a020f0;">&</span>
|
|
size_max) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> size_max</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_read_$group_dset$_size</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_has_$group_dset$</span> (trex_file) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_has_$group_dset$</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orgebddbab" class="outline-4">
|
|
<h4 id="orgebddbab"><span class="section-number-4">3.5.4</span> Python templates for front end</h4>
|
|
<div class="outline-text-4" id="text-3-5-4">
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">write_</span>$group_dset$(trexio_file: File, offset_file: <span style="color: #483d8b;">int</span>, buffer_size: <span style="color: #483d8b;">int</span>, indices: <span style="color: #483d8b;">list</span>, values: <span style="color: #483d8b;">list</span>) -> <span style="color: #008b8b;">None</span>:
|
|
<span style="color: #8b2252;">"""Write the $group_dset$ indices and values in the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameters:</span>
|
|
|
|
<span style="color: #8b2252;"> trexio_file:</span>
|
|
<span style="color: #8b2252;"> TREXIO File object.</span>
|
|
|
|
<span style="color: #8b2252;"> offset_file: int</span>
|
|
<span style="color: #8b2252;"> The number of integrals to be skipped in the file when writing.</span>
|
|
|
|
<span style="color: #8b2252;"> buffer_size: int</span>
|
|
<span style="color: #8b2252;"> The number of integrals to write in the file from the provided sparse arrays.</span>
|
|
|
|
<span style="color: #8b2252;"> indices: list OR numpy.ndarray</span>
|
|
<span style="color: #8b2252;"> Array of $group_dset$ indices to be written. If array data type does not correspond to int32, the conversion is performed.</span>
|
|
|
|
<span style="color: #8b2252;"> values: list OR numpy.ndarray</span>
|
|
<span style="color: #8b2252;"> Array of $group_dset$ values to be written. If array data type does not correspond to float64, the conversion is performed.</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - trexio.Error if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">not</span> <span style="color: #483d8b;">isinstance</span>(offset_file, <span style="color: #483d8b;">int</span>):
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">TypeError</span>(<span style="color: #8b2252;">"offset_file argument has to be an integer."</span>)
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">not</span> <span style="color: #483d8b;">isinstance</span>(buffer_size, <span style="color: #483d8b;">int</span>):
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">TypeError</span>(<span style="color: #8b2252;">"buffer_size argument has to be an integer."</span>)
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">not</span> <span style="color: #483d8b;">isinstance</span>(indices, (<span style="color: #483d8b;">list</span>, <span style="color: #483d8b;">tuple</span>, np.ndarray)):
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">TypeError</span>(<span style="color: #8b2252;">"indices argument has to be an array (list, tuple or NumPy ndarray)."</span>)
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">not</span> <span style="color: #483d8b;">isinstance</span>(values, (<span style="color: #483d8b;">list</span>, <span style="color: #483d8b;">tuple</span>, np.ndarray)):
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">TypeError</span>(<span style="color: #8b2252;">"values argument has to be an array (list, tuple or NumPy ndarray)."</span>)
|
|
|
|
<span style="color: #a0522d;">convertIndices</span> = <span style="color: #008b8b;">False</span>
|
|
<span style="color: #a0522d;">convertValues</span> = <span style="color: #008b8b;">False</span>
|
|
<span style="color: #a0522d;">flattenIndices</span> = <span style="color: #008b8b;">False</span>
|
|
<span style="color: #a020f0;">if</span> <span style="color: #483d8b;">isinstance</span>(indices, np.ndarray):
|
|
# <span style="color: #b22222;">convert to int32 if input indices are in a different precision</span>
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">not</span> indices.dtype==np.int32:
|
|
<span style="color: #a0522d;">convertIndices</span> = <span style="color: #008b8b;">True</span>
|
|
|
|
<span style="color: #a020f0;">if</span> <span style="color: #483d8b;">len</span>(indices.shape) > 1:
|
|
<span style="color: #a0522d;">flattenIndices</span> = <span style="color: #008b8b;">True</span>
|
|
<span style="color: #a020f0;">if</span> convertIndices:
|
|
<span style="color: #a0522d;">indices_32</span> = np.int32(indices).flatten()
|
|
<span style="color: #a020f0;">else</span>:
|
|
<span style="color: #a0522d;">indices_32</span> = np.array(indices, dtype=np.int32).flatten()
|
|
<span style="color: #a020f0;">else</span>:
|
|
<span style="color: #a020f0;">if</span> convertIndices:
|
|
<span style="color: #a0522d;">indices_32</span> = np.int32(indices)
|
|
<span style="color: #a020f0;">else</span>:
|
|
# <span style="color: #b22222;">if input array is a multidimensional list or tuple, we have to convert it</span>
|
|
<span style="color: #a020f0;">try</span>:
|
|
<span style="color: #a0522d;">doFlatten</span> = <span style="color: #008b8b;">True</span>
|
|
# <span style="color: #b22222;">if list of indices is flat - the attempt to compute len(indices[0]) will raise a TypeError</span>
|
|
<span style="color: #a0522d;">ncol</span> = <span style="color: #483d8b;">len</span>(indices[0])
|
|
<span style="color: #a0522d;">indices_32</span> = np.array(indices, dtype=np.int32).flatten()
|
|
<span style="color: #a020f0;">except</span> <span style="color: #228b22;">TypeError</span>:
|
|
<span style="color: #a0522d;">doFlatten</span> = <span style="color: #008b8b;">False</span>
|
|
<span style="color: #a020f0;">pass</span>
|
|
|
|
<span style="color: #a020f0;">if</span> <span style="color: #483d8b;">isinstance</span>(values, np.ndarray):
|
|
# <span style="color: #b22222;">convert to float64 if input values are in a different precision</span>
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">not</span> values.dtype==np.float64:
|
|
<span style="color: #a0522d;">convertValues</span> = <span style="color: #008b8b;">True</span>
|
|
<span style="color: #a020f0;">if</span> convertValues:
|
|
<span style="color: #a0522d;">values_64</span> = np.float64(values)
|
|
|
|
<span style="color: #a020f0;">if</span> (convertIndices <span style="color: #a020f0;">or</span> flattenIndices) <span style="color: #a020f0;">and</span> convertValues:
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_write_safe_$group_dset$(trexio_file.pytrexio_s, offset_file, buffer_size, indices_32, values_64)
|
|
<span style="color: #a020f0;">elif</span> (convertIndices <span style="color: #a020f0;">or</span> flattenIndices) <span style="color: #a020f0;">and</span> <span style="color: #a020f0;">not</span> convertValues:
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_write_safe_$group_dset$(trexio_file.pytrexio_s, offset_file, buffer_size, indices_32, values)
|
|
<span style="color: #a020f0;">elif</span> <span style="color: #a020f0;">not</span> (convertIndices <span style="color: #a020f0;">or</span> flattenIndices) <span style="color: #a020f0;">and</span> convertValues:
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_write_safe_$group_dset$(trexio_file.pytrexio_s, offset_file, buffer_size, indices, values_64)
|
|
<span style="color: #a020f0;">else</span>:
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_write_safe_$group_dset$(trexio_file.pytrexio_s, offset_file, buffer_size, indices, values)
|
|
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">read_</span>$group_dset$(trexio_file: File, offset_file: <span style="color: #483d8b;">int</span>, buffer_size: <span style="color: #483d8b;">int</span>) -> <span style="color: #483d8b;">tuple</span>:
|
|
<span style="color: #8b2252;">"""Read the $group_dset$ indices and values from the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameters:</span>
|
|
|
|
<span style="color: #8b2252;"> trexio_file:</span>
|
|
<span style="color: #8b2252;"> TREXIO File object.</span>
|
|
|
|
<span style="color: #8b2252;"> offset_file: int</span>
|
|
<span style="color: #8b2252;"> The number of integrals to be skipped in the file when reading.</span>
|
|
|
|
<span style="color: #8b2252;"> buffer_size: int</span>
|
|
<span style="color: #8b2252;"> The number of integrals to read from the file.</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> (indices, values, n_int_read, eof_flag) tuple where</span>
|
|
<span style="color: #8b2252;"> - indices and values are NumPy arrays [numpy.ndarray] with the default int32 and float64 precision, respectively;</span>
|
|
<span style="color: #8b2252;"> - n_int_read [int] is the number of integrals read from the trexio_file</span>
|
|
<span style="color: #8b2252;"> (either strictly equal to buffer_size or less than buffer_size if EOF has been reached);</span>
|
|
<span style="color: #8b2252;"> - eof_flag [bool] is True when EOF has been reached (i.e. when call to low-level pytrexio API returns TREXIO_END)</span>
|
|
<span style="color: #8b2252;"> False otherwise.</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS</span>
|
|
<span style="color: #8b2252;"> and prints the error message using trexio_string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">not</span> <span style="color: #483d8b;">isinstance</span>(offset_file, <span style="color: #483d8b;">int</span>):
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">TypeError</span>(<span style="color: #8b2252;">"offset_file argument has to be an integer."</span>)
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">not</span> <span style="color: #483d8b;">isinstance</span>(buffer_size, <span style="color: #483d8b;">int</span>):
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">TypeError</span>(<span style="color: #8b2252;">"buffer_size argument has to be an integer."</span>)
|
|
|
|
|
|
# <span style="color: #b22222;">read the number of integrals already in the file</span>
|
|
<span style="color: #a0522d;">integral_num</span> = read_$group_dset$_size(trexio_file)
|
|
|
|
# <span style="color: #b22222;">additional modification needed to avoid allocating more memory than needed if EOF will be reached during read</span>
|
|
<span style="color: #a0522d;">overflow</span> = offset_file + buffer_size - integral_num
|
|
<span style="color: #a0522d;">eof_flag</span> = <span style="color: #008b8b;">False</span>
|
|
<span style="color: #a020f0;">if</span> overflow > 0:
|
|
<span style="color: #a0522d;">verified_size</span> = buffer_size - overflow
|
|
<span style="color: #a0522d;">eof_flag</span> = <span style="color: #008b8b;">True</span>
|
|
<span style="color: #a020f0;">else</span>:
|
|
<span style="color: #a0522d;">verified_size</span> = buffer_size
|
|
|
|
# <span style="color: #b22222;">main call to the low-level (SWIG-wrapped) trexio_read function, which also requires the sizes of the output to be provided</span>
|
|
# <span style="color: #b22222;">as the last 2 arguments (for numpy arrays of indices and values, respectively)</span>
|
|
# <span style="color: #b22222;">read_buf_size contains the number of elements being read from the file, useful when EOF has been reached</span>
|
|
<span style="color: #a0522d;">rc</span>, <span style="color: #a0522d;">n_int_read</span>, <span style="color: #a0522d;">indices</span>, <span style="color: #a0522d;">values</span> = pytr.trexio_read_safe_$group_dset$(trexio_file.pytrexio_s,
|
|
offset_file,
|
|
verified_size,
|
|
verified_size * $group_dset_rank$,
|
|
verified_size)
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
<span style="color: #a020f0;">if</span> n_int_read == 0:
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">ValueError</span>(<span style="color: #8b2252;">"No integrals have been read from the file."</span>)
|
|
<span style="color: #a020f0;">if</span> indices <span style="color: #a020f0;">is</span> <span style="color: #008b8b;">None</span> <span style="color: #a020f0;">or</span> values <span style="color: #a020f0;">is</span> <span style="color: #008b8b;">None</span>:
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">ValueError</span>(<span style="color: #8b2252;">"Returned NULL array from the low-level pytrexio API."</span>)
|
|
|
|
# <span style="color: #b22222;">conversion to custom types can be performed on the user side, here we only reshape the returned flat array of indices according to group_dset_rank</span>
|
|
<span style="color: #a0522d;">shape</span> = <span style="color: #483d8b;">tuple</span>([verified_size, $group_dset_rank$])
|
|
<span style="color: #a0522d;">indices_reshaped</span> = np.reshape(indices, shape, order=<span style="color: #8b2252;">'C'</span>)
|
|
|
|
<span style="color: #a020f0;">return</span> (indices_reshaped, values, n_int_read, eof_flag)
|
|
|
|
|
|
<span style="color: #a020f0;">def</span> <span style="color: #0000ff;">read_</span>$group_dset$_size(trexio_file) -> <span style="color: #483d8b;">int</span>:
|
|
<span style="color: #8b2252;">"""Read the number of $group_dset$ integrals stored in the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function.</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> ~num_integral~: int</span>
|
|
<span style="color: #8b2252;"> Integer value of corresponding to the size of the $group_dset$ sparse array from ~trexio_file~.</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a0522d;">rc</span>, <span style="color: #a0522d;">num_integral</span> = pytr.trexio_read_$group_dset$_size(trexio_file.pytrexio_s)
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
|
|
<span style="color: #a020f0;">return</span> num_integral
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">has_</span>$group_dset$(trexio_file) -> <span style="color: #483d8b;">bool</span>:
|
|
<span style="color: #8b2252;">"""Check that $group_dset$ variable exists in the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function.</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> True if the variable exists, False otherwise</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - trexio.Error if TREXIO return code ~rc~ is TREXIO_FAILURE and prints the error message using string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_has_$group_dset$(trexio_file.pytrexio_s)
|
|
<span style="color: #a020f0;">if</span> rc == TREXIO_FAILURE:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
|
|
<span style="color: #a020f0;">return</span> rc == TREXIO_SUCCESS
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org1c5a7c4" class="outline-3">
|
|
<h3 id="org1c5a7c4"><span class="section-number-3">3.6</span> Templates for front end has/read/write a dataset of strings</h3>
|
|
<div class="outline-text-3" id="text-3-6">
|
|
</div>
|
|
<div id="outline-container-org63007b3" class="outline-4">
|
|
<h4 id="org63007b3"><span class="section-number-4">3.6.1</span> Introduction</h4>
|
|
<div class="outline-text-4" id="text-3-6-1">
|
|
<p>
|
|
This section concerns API calls related to datasets of strings.
|
|
</p>
|
|
|
|
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
|
|
|
|
|
|
<colgroup>
|
|
<col class="org-left" />
|
|
|
|
<col class="org-left" />
|
|
</colgroup>
|
|
<thead>
|
|
<tr>
|
|
<th scope="col" class="org-left">Function name</th>
|
|
<th scope="col" class="org-left">Description</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="org-left"><code>trexio_has_$group_dset$</code></td>
|
|
<td class="org-left">Check if a dataset exists in a file</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_read_$group_dset$</code></td>
|
|
<td class="org-left">Read a dataset</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_write_$group_dset$</code></td>
|
|
<td class="org-left">Write a dataset</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orgca104c4" class="outline-4">
|
|
<h4 id="orgca104c4"><span class="section-number-4">3.6.2</span> C templates for front end</h4>
|
|
<div class="outline-text-4" id="text-3-6-2">
|
|
<p>
|
|
First parameter is the <code>TREXIO</code> file handle. Second parameter is the variable to be written/read
|
|
to/from the <code>TREXIO</code> file (except for <code>trexio_has_</code> functions).
|
|
</p>
|
|
</div>
|
|
|
|
<div id="outline-container-org5014035" class="outline-5">
|
|
<h5 id="org5014035"><span class="section-number-5">3.6.2.1</span> Function declarations</h5>
|
|
</div>
|
|
|
|
<div id="outline-container-org42702d7" class="outline-5">
|
|
<h5 id="org42702d7"><span class="section-number-5">3.6.2.2</span> Source code for default functions</h5>
|
|
<div class="outline-text-5" id="text-3-6-2-2">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_read_$group_dset$_low</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #228b22;">char</span>* <span style="color: #a0522d;">dset_out</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">max_str_len</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (dset_out == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (max_str_len <= 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_3;
|
|
<span style="color: #a020f0;">if</span> (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> TREXIO_DSET_MISSING;
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span>;
|
|
int64_t $group_dset_dim$ = 0;
|
|
|
|
/* <span style="color: #b22222;">Error handling for this call is added by the generator</span> */
|
|
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
|
|
|
|
<span style="color: #a020f0;">if</span> ($group_dset_dim$ == 0L) <span style="color: #a020f0;">return</span> TREXIO_INVALID_NUM;
|
|
|
|
<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">rank</span> = $group_dset_rank$;
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dims</span>[$group_dset_rank$] = {$group_dset_dim_list$};
|
|
|
|
assert(file->back_end < TREXIO_INVALID_BACK_END);
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
<span style="color: #a020f0;">return</span> trexio_text_read_$group_dset$(file, dset_out, rank, dims, (<span style="color: #228b22;">uint32_t</span>) max_str_len);
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
<span style="color: #a020f0;">return</span> trexio_hdf5_read_$group_dset$(file, dset_out, rank, dims, (<span style="color: #228b22;">uint32_t</span>) max_str_len);
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">return</span> TREXIO_BACK_END_MISSING;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> rc = trexio_json_read_$group_dset$(file, dset_out, rank, dims);</span>
|
|
*/
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_FAILURE;
|
|
}
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_read_$group_dset$</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #228b22;">char</span>** <span style="color: #a0522d;">dset_out</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">max_str_len</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (dset_out == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (max_str_len <= 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_3;
|
|
<span style="color: #a020f0;">if</span> (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> TREXIO_DSET_MISSING;
|
|
|
|
assert(file->back_end < TREXIO_INVALID_BACK_END);
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span>;
|
|
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">dset_dim</span> = 0;
|
|
|
|
/* <span style="color: #b22222;">Error handling for this call is added by the generator</span> */
|
|
rc = trexio_read_$group_dset_dim$_64(file, &(dset_dim));
|
|
|
|
<span style="color: #a020f0;">if</span> (dset_dim == 0L) <span style="color: #a020f0;">return</span> TREXIO_INVALID_NUM;
|
|
|
|
<span style="color: #228b22;">char</span>* <span style="color: #a0522d;">str_compiled</span> = CALLOC(dset_dim*(max_str_len+1) + 1, <span style="color: #228b22;">char</span>);
|
|
<span style="color: #a020f0;">if</span> (str_compiled == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_ALLOCATION_FAILED;
|
|
|
|
rc = trexio_read_$group_dset$_low(file, str_compiled, max_str_len);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) {
|
|
FREE(str_compiled);
|
|
<span style="color: #a020f0;">return</span> rc;
|
|
}
|
|
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">i</span>=0; i < (<span style="color: #228b22;">uint64_t</span>) dset_dim; i++) {
|
|
|
|
<span style="color: #228b22;">char</span> * <span style="color: #a0522d;">pch</span>;
|
|
pch = i == 0 ? strtok(str_compiled, TREXIO_DELIM) : strtok(<span style="color: #008b8b;">NULL</span>, TREXIO_DELIM) ;
|
|
<span style="color: #a020f0;">if</span> (pch == <span style="color: #008b8b;">NULL</span>) {
|
|
FREE(str_compiled);
|
|
<span style="color: #a020f0;">return</span> TREXIO_FAILURE;
|
|
}
|
|
|
|
strcpy(dset_out[i], <span style="color: #8b2252;">""</span>);
|
|
strcat(dset_out[i], pch);
|
|
|
|
}
|
|
|
|
FREE(str_compiled);
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_write_$group_dset$_low</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #228b22;">char</span>* <span style="color: #a0522d;">dset_in</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">max_str_len</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (dset_in == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (max_str_len <= 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_3;
|
|
<span style="color: #a020f0;">if</span> (trexio_has_$group_dset$(file) == TREXIO_SUCCESS && file->mode != <span style="color: #8b2252;">'u'</span>) <span style="color: #a020f0;">return</span> TREXIO_DSET_ALREADY_EXISTS;
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span>;
|
|
int64_t $group_dset_dim$ = 0;
|
|
|
|
/* <span style="color: #b22222;">Error handling for this call is added by the generator</span> */
|
|
rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
|
|
|
|
<span style="color: #a020f0;">if</span> ($group_dset_dim$ == 0L) <span style="color: #a020f0;">return</span> TREXIO_INVALID_NUM;
|
|
|
|
<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">rank</span> = $group_dset_rank$;
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dims</span>[$group_dset_rank$] = {$group_dset_dim_list$};
|
|
|
|
assert(file->back_end < TREXIO_INVALID_BACK_END);
|
|
|
|
<span style="color: #228b22;">char</span>* <span style="color: #a0522d;">tmp_str</span> = CALLOC(dims[0]*(max_str_len+1), <span style="color: #228b22;">char</span>);
|
|
<span style="color: #a020f0;">if</span> (tmp_str == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_ALLOCATION_FAILED;
|
|
<span style="color: #228b22;">char</span>** <span style="color: #a0522d;">dset_str</span> = CALLOC(dims[0], <span style="color: #228b22;">char</span>*);
|
|
<span style="color: #a020f0;">if</span> (dset_str == <span style="color: #008b8b;">NULL</span>) {
|
|
FREE(tmp_str);
|
|
<span style="color: #a020f0;">return</span> TREXIO_ALLOCATION_FAILED;
|
|
}
|
|
|
|
/* <span style="color: #b22222;">parse the string using strtok</span> */
|
|
<span style="color: #a020f0;">for</span>(<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">i</span>=0; i<dims[0]; i++) {
|
|
|
|
<span style="color: #228b22;">char</span>* <span style="color: #a0522d;">pch</span>;
|
|
pch = i == 0 ? strtok(dset_in, TREXIO_DELIM) : strtok(<span style="color: #008b8b;">NULL</span>, TREXIO_DELIM) ;
|
|
|
|
<span style="color: #a020f0;">if</span> (pch == <span style="color: #008b8b;">NULL</span>) {
|
|
FREE(dset_str[0]);
|
|
FREE(dset_str);
|
|
<span style="color: #a020f0;">return</span> TREXIO_FAILURE;
|
|
}
|
|
|
|
<span style="color: #228b22;">size_t</span> <span style="color: #a0522d;">pch_len</span> = strlen(pch) + 1;
|
|
|
|
<span style="color: #a020f0;">if</span> (pch_len > (<span style="color: #228b22;">size_t</span>) max_str_len) {
|
|
FREE(dset_str[0]);
|
|
FREE(dset_str);
|
|
<span style="color: #a020f0;">return</span> TREXIO_INVALID_STR_LEN;
|
|
}
|
|
|
|
dset_str[i] = tmp_str;
|
|
strncpy(tmp_str, pch, pch_len);
|
|
tmp_str += pch_len + 1;
|
|
}
|
|
|
|
rc = TREXIO_FAILURE;
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
rc = trexio_text_write_$group_dset$(file, (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span>**) dset_str, rank, dims);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
rc = trexio_hdf5_write_$group_dset$(file, (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span>**) dset_str, rank, dims);
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
rc =TREXIO_BACK_END_MISSING;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> rc = trexio_json_write_$group_dset$(file, dset, rank, dims);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
|
|
FREE(dset_str[0]);
|
|
FREE(dset_str);
|
|
|
|
<span style="color: #a020f0;">return</span> rc;
|
|
|
|
}
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_write_$group_dset$</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span>** <span style="color: #a0522d;">dset_in</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">max_str_len</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (dset_in == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (max_str_len <= 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_3;
|
|
<span style="color: #a020f0;">if</span> (trexio_has_$group_dset$(file) == TREXIO_SUCCESS && file->mode != <span style="color: #8b2252;">'u'</span>) <span style="color: #a020f0;">return</span> TREXIO_DSET_ALREADY_EXISTS;
|
|
|
|
assert(file->back_end < TREXIO_INVALID_BACK_END);
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span>;
|
|
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">dset_dim</span> = 0;
|
|
|
|
/* <span style="color: #b22222;">Error handling for this call is added by the generator</span> */
|
|
rc = trexio_read_$group_dset_dim$_64(file, &(dset_dim));
|
|
|
|
<span style="color: #a020f0;">if</span> (dset_dim == 0L) <span style="color: #a020f0;">return</span> TREXIO_INVALID_NUM;
|
|
|
|
<span style="color: #228b22;">char</span>* <span style="color: #a0522d;">str_compiled</span> = CALLOC(dset_dim*max_str_len + 1, <span style="color: #228b22;">char</span>);
|
|
<span style="color: #a020f0;">if</span> (str_compiled == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_ALLOCATION_FAILED;
|
|
|
|
strcpy(str_compiled, <span style="color: #8b2252;">""</span>);
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">i</span>=0; i < (<span style="color: #228b22;">uint64_t</span>) dset_dim; i++) {
|
|
strcat(str_compiled, dset_in[i]);
|
|
strcat(str_compiled, TREXIO_DELIM);
|
|
}
|
|
|
|
rc = trexio_write_$group_dset$_low(file, str_compiled, max_str_len);
|
|
|
|
FREE(str_compiled);
|
|
|
|
<span style="color: #a020f0;">return</span> rc;
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_has_$group_dset$</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
|
|
assert(file->back_end < TREXIO_INVALID_BACK_END);
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
<span style="color: #a020f0;">return</span> trexio_text_has_$group_dset$(file);
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
<span style="color: #a020f0;">return</span> trexio_hdf5_has_$group_dset$(file);
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">return</span> TREXIO_BACK_END_MISSING;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> return trexio_json_has_$group_dset$(file);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_FAILURE;
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org6ed6e3d" class="outline-4">
|
|
<h4 id="org6ed6e3d"><span class="section-number-4">3.6.3</span> Fortran templates for front end</h4>
|
|
<div class="outline-text-4" id="text-3-6-3">
|
|
<p>
|
|
The <code>Fortran</code> templates that provide an access to the <code>C</code> API calls from <code>Fortran</code>.
|
|
These templates are based on the use of <code>iso_c_binding</code>. Pointers have to be passed by value.
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_write_$group_dset$_low</span> (trex_file, dset, max_str_len) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
<span style="color: #228b22;">character</span>(kind=<span style="color: #008b8b;">c_char</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> dset(*)</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;"> max_str_len</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_write_$group_dset$_low</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_read_$group_dset$_low</span> (trex_file, dset, max_str_len) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</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;"> trex_file</span>
|
|
<span style="color: #228b22;">character</span>(kind=<span style="color: #008b8b;">c_char</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> dset(*)</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;"> max_str_len</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_read_$group_dset$_low</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_has_$group_dset$</span> (trex_file) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_has_$group_dset$</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_read_$group_dset$</span> (trex_file, dset, max_str_len)
|
|
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</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;"> max_str_len</span>
|
|
<span style="color: #228b22;">character</span>(len=*), <span style="color: #a020f0;">intent</span>(inout) ::<span style="color: #a0522d;"> dset(*)</span>
|
|
|
|
<span style="color: #228b22;">character</span>, <span style="color: #a020f0;">allocatable</span> ::<span style="color: #a0522d;"> str_compiled(:)</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int64_t</span>) ::<span style="color: #a0522d;"> $group_dset_dim$</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) ::<span style="color: #a0522d;"> rc</span>
|
|
|
|
rc = trexio_read_$group_dset_dim$_64(trex_file, $group_dset_dim$)
|
|
<span style="color: #a020f0;">if</span> (rc /= TREXIO_SUCCESS) trexio_read_$group_dset$ = rc
|
|
|
|
<span style="color: #a020f0;">allocate</span>(str_compiled($group_dset_dim$*(max_str_len+1)+1))
|
|
|
|
rc = trexio_read_$group_dset$_low(trex_file, str_compiled, max_str_len)
|
|
<span style="color: #a020f0;">if</span> (rc /= TREXIO_SUCCESS) <span style="color: #a020f0;">then</span>
|
|
<span style="color: #a020f0;">deallocate</span>(str_compiled)
|
|
trexio_read_$group_dset$ = rc
|
|
<span style="color: #a020f0;">else</span>
|
|
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">trexio_str2strarray</span>(str_compiled, $group_dset_dim$, max_str_len, dset)
|
|
<span style="color: #a020f0;">deallocate</span>(str_compiled)
|
|
trexio_read_$group_dset$ = TREXIO_SUCCESS
|
|
<span style="color: #a020f0;">endif</span>
|
|
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_read_$group_dset$</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_write_$group_dset$</span> (trex_file, dset, max_str_len)
|
|
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</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;"> max_str_len</span>
|
|
<span style="color: #228b22;">character</span>(len=*), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> dset(*)</span>
|
|
|
|
<span style="color: #228b22;">character</span>(len=:), <span style="color: #a020f0;">allocatable</span> ::<span style="color: #a0522d;"> str_compiled</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int64_t</span>) ::<span style="color: #a0522d;"> $group_dset_dim$</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) ::<span style="color: #a0522d;"> rc</span>
|
|
|
|
rc = trexio_read_$group_dset_dim$_64(trex_file, $group_dset_dim$)
|
|
<span style="color: #a020f0;">if</span> (rc /= TREXIO_SUCCESS) <span style="color: #a020f0;">then</span>
|
|
trexio_write_$group_dset$ = rc
|
|
<span style="color: #a020f0;">else</span>
|
|
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">trexio_strarray2str</span>(dset, $group_dset_dim$, str_compiled)
|
|
trexio_write_$group_dset$ = trexio_write_$group_dset$_low(trex_file, str_compiled, max_str_len)
|
|
<span style="color: #a020f0;">endif</span>
|
|
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_write_$group_dset$</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org8abff32" class="outline-4">
|
|
<h4 id="org8abff32"><span class="section-number-4">3.6.4</span> Python templates for front end</h4>
|
|
<div class="outline-text-4" id="text-3-6-4">
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">write_</span>$group_dset$(trexio_file, dset_w: <span style="color: #483d8b;">list</span>) -> <span style="color: #008b8b;">None</span>:
|
|
<span style="color: #8b2252;">"""Write the $group_dset$ array of strings in the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameters:</span>
|
|
|
|
<span style="color: #8b2252;"> trexio_file:</span>
|
|
<span style="color: #8b2252;"> TREXIO File object.</span>
|
|
|
|
<span style="color: #8b2252;"> dset_w: list</span>
|
|
<span style="color: #8b2252;"> Array of $group_dset$ strings to be written.</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a0522d;">max_str_length</span> = <span style="color: #483d8b;">len</span>(<span style="color: #483d8b;">max</span>(dset_w, key=<span style="color: #483d8b;">len</span>)) + 1
|
|
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_write_$group_dset$(trexio_file.pytrexio_s, dset_w, max_str_length)
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">read_</span>$group_dset$(trexio_file, dim = <span style="color: #008b8b;">None</span>) -> <span style="color: #483d8b;">list</span>:
|
|
<span style="color: #8b2252;">"""Read the $group_dset$ array of strings from the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameters:</span>
|
|
|
|
<span style="color: #8b2252;"> trexio_file:</span>
|
|
<span style="color: #8b2252;"> TREXIO File object.</span>
|
|
|
|
<span style="color: #8b2252;"> dim (Optional): int</span>
|
|
<span style="color: #8b2252;"> Size of the block to be read from the file (i.e. how many items of $group_dset$ will be returned)</span>
|
|
<span style="color: #8b2252;"> If None, the function will read all necessary array dimensions from the file.</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> ~dset_r~: list</span>
|
|
<span style="color: #8b2252;"> 1D list with ~dim~ elements corresponding to $group_dset$ strings read from the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
$group_dset_dim$ = read_$group_dset_dim$(trexio_file)
|
|
|
|
<span style="color: #a0522d;">dims_list</span> = [$group_dset_dim_list$]
|
|
<span style="color: #a0522d;">dim_real</span> = 1
|
|
<span style="color: #a020f0;">for</span> i <span style="color: #a020f0;">in</span> <span style="color: #483d8b;">range</span>($group_dset_rank$):
|
|
<span style="color: #a0522d;">dim_real</span> *= dims_list[i]
|
|
|
|
<span style="color: #a020f0;">if</span> dim:
|
|
<span style="color: #a020f0;">if</span> dim_real != dim:
|
|
<span style="color: #a020f0;">raise</span> Error(TREXIO_UNSAFE_ARRAY_DIM)
|
|
<span style="color: #a020f0;">else</span>:
|
|
<span style="color: #a0522d;">dim</span> = dim_real
|
|
|
|
<span style="color: #a0522d;">rc</span>, <span style="color: #a0522d;">dset_1d_r</span> = pytr.trexio_read_$group_dset$_low(trexio_file.pytrexio_s, PYTREXIO_MAX_STR_LENGTH)
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
|
|
|
|
<span style="color: #a0522d;">dset_full</span> = dset_1d_r.split(pytr.TREXIO_DELIM)
|
|
<span style="color: #a0522d;">dset_2d_r</span> = [dset_full[i] <span style="color: #a020f0;">for</span> i <span style="color: #a020f0;">in</span> <span style="color: #483d8b;">range</span>(dim) <span style="color: #a020f0;">if</span> dset_full[i]]
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">not</span> dset_2d_r:
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">ValueError</span>(f<span style="color: #8b2252;">"Output of {read_$group_dset$.__name__} function cannot be an empty list."</span>)
|
|
|
|
<span style="color: #a020f0;">return</span> dset_2d_r
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">has_</span>$group_dset$(trexio_file) -> <span style="color: #483d8b;">bool</span>:
|
|
<span style="color: #8b2252;">"""Check that $group_dset$ variable exists in the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function.</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> True if the variable exists, False otherwise</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - trexio.Error if TREXIO return code ~rc~ is TREXIO_FAILURE and prints the error message using string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_has_$group_dset$(trexio_file.pytrexio_s)
|
|
<span style="color: #a020f0;">if</span> rc == TREXIO_FAILURE:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
|
|
<span style="color: #a020f0;">return</span> rc == TREXIO_SUCCESS
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orgcb8af3e" class="outline-3">
|
|
<h3 id="orgcb8af3e"><span class="section-number-3">3.7</span> Templates for front end has/read/write a buffered vector</h3>
|
|
<div class="outline-text-3" id="text-3-7">
|
|
<p>
|
|
This corresponds to the <code>buffer</code> data type and is particularly useful for incremental additiona of values like
|
|
it was done for <code>sparse</code> data but without the need to supply tuples of indices.
|
|
</p>
|
|
|
|
|
|
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
|
|
|
|
|
|
<colgroup>
|
|
<col class="org-left" />
|
|
|
|
<col class="org-left" />
|
|
|
|
<col class="org-left" />
|
|
</colgroup>
|
|
<thead>
|
|
<tr>
|
|
<th scope="col" class="org-left">Function name</th>
|
|
<th scope="col" class="org-left">Description</th>
|
|
<th scope="col" class="org-left">Precision</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="org-left"><code>trexio_has_$group_dset$</code></td>
|
|
<td class="org-left">Check if a buffered dset is present in a file</td>
|
|
<td class="org-left">---</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_read_$group_dset$</code></td>
|
|
<td class="org-left">Read values of a vector in buffers</td>
|
|
<td class="org-left">Double</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_read_$group_dset$_size</code></td>
|
|
<td class="org-left">Read the number of elements stored in the file</td>
|
|
<td class="org-left">Double</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_write_$group_dset$</code></td>
|
|
<td class="org-left">Write values of a vector in buffers</td>
|
|
<td class="org-left">Double</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_read_safe_$group_dset$</code></td>
|
|
<td class="org-left">Safe (bounded) read (for Python API)</td>
|
|
<td class="org-left">Double</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_write_safe_$group_dset$</code></td>
|
|
<td class="org-left">Safe (bounded) write (for Python API)</td>
|
|
<td class="org-left">Double</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div id="outline-container-org79d57e1" class="outline-4">
|
|
<h4 id="org79d57e1"><span class="section-number-4">3.7.1</span> C source code</h4>
|
|
<div class="outline-text-4" id="text-3-7-1">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_read_$group_dset$</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">offset_file</span>, <span style="color: #228b22;">int64_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">buffer_size_read</span>, <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">dset</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (dset == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> TREXIO_DSET_MISSING;
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span>;
|
|
|
|
<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">rank</span> = 1;
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">det_size</span> = (<span style="color: #228b22;">uint64_t</span>) (*buffer_size_read);
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dims</span>[1] = {det_size};
|
|
|
|
// <span style="color: #b22222;">introduce a new variable which will be modified with the number of integrals being read if EOF is encountered</span>
|
|
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">eof_read_size</span> = 0L;
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
rc = trexio_text_read_$group_dset$(file, offset_file, rank, dims, &eof_read_size, dset);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
rc = trexio_hdf5_read_$group_dset$(file, offset_file, rank, dims, &eof_read_size, dset);
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
rc = TREXIO_BACK_END_MISSING;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> return trexio_json_read_$group_dset$(...);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
<span style="color: #a020f0;">default</span>:
|
|
rc = TREXIO_FAILURE; /* <span style="color: #b22222;">Impossible case</span> */
|
|
<span style="color: #a020f0;">break</span>;
|
|
}
|
|
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS && rc != TREXIO_END) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
<span style="color: #a020f0;">if</span> (rc == TREXIO_END) *buffer_size_read = eof_read_size;
|
|
|
|
<span style="color: #a020f0;">return</span> rc;
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_read_$group_dset$_size</span>(<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #228b22;">int64_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">size_max</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (size_max == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> TREXIO_DSET_MISSING;
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
<span style="color: #a020f0;">return</span> trexio_text_read_$group_dset$_size(file, size_max);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
<span style="color: #a020f0;">return</span> trexio_hdf5_read_$group_dset$_size(file, size_max);
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">return</span> TREXIO_BACK_END_MISSING;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> return trexio_json_read_</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
<span style="color: #a020f0;">default</span>:
|
|
<span style="color: #a020f0;">return</span> TREXIO_FAILURE; /* <span style="color: #b22222;">Impossible case</span> */
|
|
}
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_read_safe_$group_dset$</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">offset_file</span>, <span style="color: #228b22;">int64_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">buffer_size_read</span>, <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">dset_out</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">dim_out</span>)
|
|
{
|
|
<span style="color: #a020f0;">return</span> trexio_read_$group_dset$(file, offset_file, buffer_size_read, dset_out);
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_write_$group_dset$</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">offset_file</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">buffer_size</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span>* <span style="color: #a0522d;">dset</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (dset == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
|
|
<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">rank</span> = 1;
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dims</span>[1] = {buffer_size};
|
|
|
|
assert(file->back_end < TREXIO_INVALID_BACK_END);
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
<span style="color: #a020f0;">return</span> trexio_text_write_$group_dset$(file, offset_file, rank, dims, dset);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
<span style="color: #a020f0;">return</span> trexio_hdf5_write_$group_dset$(file, offset_file, rank, dims, dset);
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">return</span> TREXIO_BACK_END_MISSING;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> rc = trexio_json_read_</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_FAILURE;
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_write_safe_$group_dset$</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">offset_file</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">buffer_size</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span>* <span style="color: #a0522d;">dset_in</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">dim_in</span>)
|
|
{
|
|
<span style="color: #a020f0;">return</span> trexio_write_$group_dset$(file, offset_file, buffer_size, dset_in);
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_has_$group_dset$</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
|
|
assert(file->back_end < TREXIO_INVALID_BACK_END);
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
<span style="color: #a020f0;">return</span> trexio_text_has_$group_dset$(file);
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
<span style="color: #a020f0;">return</span> trexio_hdf5_has_$group_dset$(file);
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">return</span> TREXIO_BACK_END_MISSING;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> return trexio_json_has_</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_FAILURE;
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org67c1b95" class="outline-4">
|
|
<h4 id="org67c1b95"><span class="section-number-4">3.7.2</span> Fortran interface</h4>
|
|
<div class="outline-text-4" id="text-3-7-2">
|
|
<p>
|
|
The <code>Fortran</code> templates that provide an access to the <code>C</code> API calls from Fortran.
|
|
These templates are based on the use of <code>iso_c_binding</code>. Pointers have to be passed by value.
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code)<span style="color: #a0522d;"> function trexio_write_$group_dset$(trex_file, </span><span style="color: #a020f0;">&</span>
|
|
offset_file, buffer_size, dset) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</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;"> offset_file</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;"> buffer_size</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> dset(*)</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_write_$group_dset$</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
|
|
<span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code)<span style="color: #a0522d;"> function trexio_write_safe_$group_dset$ (trex_file, </span><span style="color: #a020f0;">&</span>
|
|
offset_file, buffer_size, <span style="color: #a020f0;">&</span>
|
|
dset, dset_size) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</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;"> offset_file</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;"> buffer_size</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> dset(*)</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;"> dset_size</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_write_safe_$group_dset$</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code)<span style="color: #a0522d;"> function trexio_read_safe_$group_dset$ (trex_file, </span><span style="color: #a020f0;">&</span>
|
|
offset_file, buffer_size, <span style="color: #a020f0;">&</span>
|
|
dset, dset_size) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</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;"> offset_file</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(inout) ::<span style="color: #a0522d;"> buffer_size</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> dset(*)</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;"> dset_size</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_read_safe_$group_dset$</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
|
|
<span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code)<span style="color: #a0522d;"> function trexio_read_$group_dset$(trex_file, </span><span style="color: #a020f0;">&</span>
|
|
offset_file, buffer_size, dset) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</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;"> offset_file</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(inout) ::<span style="color: #a0522d;"> buffer_size</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> dset(*)</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_read_$group_dset$</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
|
|
<span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code)<span style="color: #a0522d;"> function trexio_read_$group_dset$_size (trex_file, </span><span style="color: #a020f0;">&</span>
|
|
size_max) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> size_max</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_read_$group_dset$_size</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_has_$group_dset$</span> (trex_file) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_has_$group_dset$</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orgb45e5aa" class="outline-4">
|
|
<h4 id="orgb45e5aa"><span class="section-number-4">3.7.3</span> Python interface</h4>
|
|
<div class="outline-text-4" id="text-3-7-3">
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">write_</span>$group_dset$(trexio_file: File, offset_file: <span style="color: #483d8b;">int</span>, buffer_size: <span style="color: #483d8b;">int</span>, dset) -> <span style="color: #008b8b;">None</span>:
|
|
<span style="color: #8b2252;">"""Write the $group_dset$ in the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameters:</span>
|
|
|
|
<span style="color: #8b2252;"> trexio_file:</span>
|
|
<span style="color: #8b2252;"> TREXIO File object.</span>
|
|
|
|
<span style="color: #8b2252;"> offset_file: int</span>
|
|
<span style="color: #8b2252;"> The number of values to be skipped in the file when writing.</span>
|
|
|
|
<span style="color: #8b2252;"> buffer_size: int</span>
|
|
<span style="color: #8b2252;"> The number of values to write in the file.</span>
|
|
|
|
<span style="color: #8b2252;"> dset: list OR numpy.ndarray</span>
|
|
<span style="color: #8b2252;"> Array of $group_dset$ to be written. If array data type does not correspond to int64, the conversion is performed.</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - trexio.Error if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">not</span> <span style="color: #483d8b;">isinstance</span>(offset_file, <span style="color: #483d8b;">int</span>):
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">TypeError</span>(<span style="color: #8b2252;">"offset_file argument has to be an integer."</span>)
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">not</span> <span style="color: #483d8b;">isinstance</span>(buffer_size, <span style="color: #483d8b;">int</span>):
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">TypeError</span>(<span style="color: #8b2252;">"buffer_size argument has to be an integer."</span>)
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">not</span> <span style="color: #483d8b;">isinstance</span>(dset, (<span style="color: #483d8b;">list</span>, <span style="color: #483d8b;">tuple</span>, np.ndarray)):
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">TypeError</span>(<span style="color: #8b2252;">"dset argument has to be an array (list, tuple or NumPy ndarray)."</span>)
|
|
|
|
<span style="color: #a020f0;">if</span> <span style="color: #483d8b;">isinstance</span>(dset, np.ndarray) <span style="color: #a020f0;">and</span> <span style="color: #a020f0;">not</span> dset.dtype==np.float64:
|
|
# <span style="color: #b22222;">convert to float64 if input is in a different precision</span>
|
|
<span style="color: #a0522d;">dset_64</span> = np.float64(dset)
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_write_safe_$group_dset$(trexio_file.pytrexio_s, offset_file, buffer_size, dset_64)
|
|
<span style="color: #a020f0;">else</span>:
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_write_safe_$group_dset$(trexio_file.pytrexio_s, offset_file, buffer_size, dset)
|
|
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">read_</span>$group_dset$(trexio_file: File, offset_file: <span style="color: #483d8b;">int</span>, buffer_size: <span style="color: #483d8b;">int</span>) -> <span style="color: #483d8b;">tuple</span>:
|
|
<span style="color: #8b2252;">"""Read $group_dset$ from the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameters:</span>
|
|
|
|
<span style="color: #8b2252;"> trexio_file:</span>
|
|
<span style="color: #8b2252;"> TREXIO File object.</span>
|
|
|
|
<span style="color: #8b2252;"> offset_file: int</span>
|
|
<span style="color: #8b2252;"> The number of values to be skipped in the file when reading.</span>
|
|
|
|
<span style="color: #8b2252;"> buffer_size: int</span>
|
|
<span style="color: #8b2252;"> The number of values to read from the file.</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> (dset, n_int_read, eof_flag) tuple where</span>
|
|
<span style="color: #8b2252;"> - dset is the NumPy array [numpy.ndarray] with the default int64 precision;</span>
|
|
<span style="color: #8b2252;"> - n_int_read [int] is the number of coefficients read from the trexio_file</span>
|
|
<span style="color: #8b2252;"> (either strictly equal to buffer_size or less than buffer_size if EOF has been reached);</span>
|
|
<span style="color: #8b2252;"> - eof_flag [bool] is True when EOF has been reached (i.e. when call to low-level pytrexio API returns TREXIO_END)</span>
|
|
<span style="color: #8b2252;"> False otherwise.</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - trexio.Error if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">not</span> <span style="color: #483d8b;">isinstance</span>(offset_file, <span style="color: #483d8b;">int</span>):
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">TypeError</span>(<span style="color: #8b2252;">"offset_file argument has to be an integer."</span>)
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">not</span> <span style="color: #483d8b;">isinstance</span>(buffer_size, <span style="color: #483d8b;">int</span>):
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">TypeError</span>(<span style="color: #8b2252;">"buffer_size argument has to be an integer."</span>)
|
|
|
|
|
|
# <span style="color: #b22222;">read the number of values already in the file</span>
|
|
<span style="color: #a0522d;">det_num</span> = read_$group_dset$_size(trexio_file)
|
|
|
|
# <span style="color: #b22222;">additional modification needed to avoid allocating more memory than needed if EOF will be reached during read</span>
|
|
<span style="color: #a0522d;">overflow</span> = offset_file + buffer_size - det_num
|
|
<span style="color: #a0522d;">eof_flag</span> = <span style="color: #008b8b;">False</span>
|
|
<span style="color: #a020f0;">if</span> overflow > 0:
|
|
<span style="color: #a0522d;">verified_size</span> = buffer_size - overflow
|
|
<span style="color: #a0522d;">eof_flag</span> = <span style="color: #008b8b;">True</span>
|
|
<span style="color: #a020f0;">else</span>:
|
|
<span style="color: #a0522d;">verified_size</span> = buffer_size
|
|
|
|
# <span style="color: #b22222;">main call to the low-level (SWIG-wrapped) trexio_read function, which also requires the sizes of the output to be provided</span>
|
|
# <span style="color: #b22222;">read_buf_size contains the number of elements being read from the file, useful when EOF has been reached</span>
|
|
<span style="color: #a0522d;">rc</span>, <span style="color: #a0522d;">n_int_read</span>, <span style="color: #a0522d;">dset</span> = pytr.trexio_read_safe_$group_dset$(trexio_file.pytrexio_s, offset_file, verified_size, verified_size)
|
|
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
<span style="color: #a020f0;">if</span> n_int_read == 0:
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">ValueError</span>(<span style="color: #8b2252;">"No integrals have been read from the file."</span>)
|
|
<span style="color: #a020f0;">if</span> dset <span style="color: #a020f0;">is</span> <span style="color: #008b8b;">None</span>:
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">ValueError</span>(<span style="color: #8b2252;">"Returned NULL array from the low-level pytrexio API."</span>)
|
|
|
|
<span style="color: #a020f0;">return</span> (dset, n_int_read, eof_flag)
|
|
|
|
|
|
<span style="color: #a020f0;">def</span> <span style="color: #0000ff;">read_</span>$group_dset$_size(trexio_file) -> <span style="color: #483d8b;">int</span>:
|
|
<span style="color: #8b2252;">"""Read the number of elements stored in the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function.</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> ~num~: int</span>
|
|
<span style="color: #8b2252;"> Integer value of corresponding to the size of the $group_dset$ array from ~trexio_file~.</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a0522d;">rc</span>, <span style="color: #a0522d;">num</span> = pytr.trexio_read_$group_dset$_size(trexio_file.pytrexio_s)
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
|
|
<span style="color: #a020f0;">return</span> num
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">has_</span>$group_dset$(trexio_file) -> <span style="color: #483d8b;">bool</span>:
|
|
<span style="color: #8b2252;">"""Check that $group_dset$ exists in the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function.</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> True if the variable exists, False otherwise</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - trexio.Error if TREXIO return code ~rc~ is TREXIO_FAILURE and prints the error message using string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_has_$group_dset$(trexio_file.pytrexio_s)
|
|
<span style="color: #a020f0;">if</span> rc == TREXIO_FAILURE:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
|
|
<span style="color: #a020f0;">return</span> rc == TREXIO_SUCCESS
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org34592b0" class="outline-3">
|
|
<h3 id="org34592b0"><span class="section-number-3">3.8</span> Templates for front end has/read/write a single string attribute</h3>
|
|
<div class="outline-text-3" id="text-3-8">
|
|
</div>
|
|
<div id="outline-container-org6271871" class="outline-4">
|
|
<h4 id="org6271871"><span class="section-number-4">3.8.1</span> Introduction</h4>
|
|
<div class="outline-text-4" id="text-3-8-1">
|
|
<p>
|
|
This section concerns API calls related to string attributes.
|
|
</p>
|
|
|
|
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
|
|
|
|
|
|
<colgroup>
|
|
<col class="org-left" />
|
|
|
|
<col class="org-left" />
|
|
</colgroup>
|
|
<thead>
|
|
<tr>
|
|
<th scope="col" class="org-left">Function name</th>
|
|
<th scope="col" class="org-left">Description</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="org-left"><code>trexio_has_$group_str$</code></td>
|
|
<td class="org-left">Check if a string attribute exists in a file</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_read_$group_str$</code></td>
|
|
<td class="org-left">Read a string attribute</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_write_$group_str$</code></td>
|
|
<td class="org-left">Write a string attribute</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orgedc74b8" class="outline-4">
|
|
<h4 id="orgedc74b8"><span class="section-number-4">3.8.2</span> C templates for front end</h4>
|
|
<div class="outline-text-4" id="text-3-8-2">
|
|
</div>
|
|
<div id="outline-container-org33fe29c" class="outline-5">
|
|
<h5 id="org33fe29c"><span class="section-number-5">3.8.2.1</span> Function declarations</h5>
|
|
</div>
|
|
|
|
<div id="outline-container-orgfe93ff7" class="outline-5">
|
|
<h5 id="orgfe93ff7"><span class="section-number-5">3.8.2.2</span> Source code for default functions</h5>
|
|
<div class="outline-text-5" id="text-3-8-2-2">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_read_$group_str$</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #228b22;">char</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">str_out</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">max_str_len</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (str_out == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (max_str_len <= 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_3;
|
|
<span style="color: #a020f0;">if</span> (trexio_has_$group_str$(file) != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> TREXIO_ATTR_MISSING;
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
<span style="color: #a020f0;">return</span> trexio_text_read_$group_str$(file, str_out, (<span style="color: #228b22;">uint32_t</span>) max_str_len);
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
<span style="color: #a020f0;">return</span> trexio_hdf5_read_$group_str$(file, str_out, (<span style="color: #228b22;">uint32_t</span>) max_str_len);
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">return</span> TREXIO_BACK_END_MISSING;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> return trexio_json_read_$group_str$(file, str);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_FAILURE;
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_write_$group_str$</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">char</span>* <span style="color: #a0522d;">str</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">max_str_len</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (str == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (max_str_len <= 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_3;
|
|
<span style="color: #a020f0;">if</span> (trexio_has_$group_str$(file) == TREXIO_SUCCESS && file->mode != <span style="color: #8b2252;">'u'</span>) <span style="color: #a020f0;">return</span> TREXIO_ATTR_ALREADY_EXISTS;
|
|
|
|
<span style="color: #228b22;">size_t</span> <span style="color: #a0522d;">len_write</span> = strlen(str);
|
|
<span style="color: #a020f0;">if</span> ((<span style="color: #228b22;">size_t</span>) max_str_len < len_write) <span style="color: #a020f0;">return</span> TREXIO_INVALID_STR_LEN;
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
<span style="color: #a020f0;">return</span> trexio_text_write_$group_str$(file, str);
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
<span style="color: #a020f0;">return</span> trexio_hdf5_write_$group_str$(file, str);
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">return</span> TREXIO_BACK_END_MISSING;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> return trexio_json_write_$group_str$(file, str);</span>
|
|
*/
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_FAILURE;
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_has_$group_str$</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
|
|
assert(file->back_end < TREXIO_INVALID_BACK_END);
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
<span style="color: #a020f0;">return</span> trexio_text_has_$group_str$(file);
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
<span style="color: #a020f0;">return</span> trexio_hdf5_has_$group_str$(file);
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">return</span> TREXIO_BACK_END_MISSING;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> return trexio_json_has_$group_str$(file);</span>
|
|
*/
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_FAILURE;
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org863cc63" class="outline-4">
|
|
<h4 id="org863cc63"><span class="section-number-4">3.8.3</span> Fortran templates for front end</h4>
|
|
<div class="outline-text-4" id="text-3-8-3">
|
|
<p>
|
|
The <code>Fortran</code> templates that provide an access to the <code>C</code> API calls from Fortran.
|
|
These templates are based on the use of <code>iso_c_binding</code>. Pointers have to be passed by value.
|
|
</p>
|
|
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_write_$group_str$_c</span> (trex_file, str, max_str_len)<span style="color: #a0522d;"> </span><span style="color: #a020f0;">&</span>
|
|
<span style="color: #a020f0;">bind</span>(C, name=<span style="color: #8b2252;">"trexio_write_$group_str$"</span>)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
<span style="color: #228b22;">character</span>(kind=<span style="color: #008b8b;">c_char</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> str(*)</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;"> max_str_len</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_write_$group_str$_c</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_read_$group_str$_c</span> (trex_file, str, max_str_len)<span style="color: #a0522d;"> </span><span style="color: #a020f0;">&</span>
|
|
<span style="color: #a020f0;">bind</span>(C, name=<span style="color: #8b2252;">"trexio_read_$group_str$"</span>)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
<span style="color: #228b22;">character</span>(kind=<span style="color: #008b8b;">c_char</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> str(*)</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;"> max_str_len</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_read_$group_str$_c</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_has_$group_str$</span> (trex_file) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_has_$group_str$</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_read_$group_str$</span> (trex_file, str, max_str_len)
|
|
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</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;"> max_str_len</span>
|
|
<span style="color: #228b22;">character</span>, <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> str(*)</span>
|
|
|
|
trexio_read_$group_str$ = trexio_read_$group_str$_c(trex_file, str, max_str_len)
|
|
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_read_$group_str$</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_write_$group_str$</span> (trex_file, str, max_str_len)
|
|
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</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;"> max_str_len</span>
|
|
<span style="color: #228b22;">character</span>(len=*), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> str</span>
|
|
|
|
<span style="color: #228b22;">character</span>(len=<span style="color: #a020f0;">len_trim</span>(str)+1) ::<span style="color: #a0522d;"> str_c</span>
|
|
|
|
str_c = <span style="color: #a020f0;">trim</span>(str) // <span style="color: #008b8b;">c_null_char</span>
|
|
|
|
trexio_write_$group_str$ = trexio_write_$group_str$_c(trex_file, str_c, max_str_len)
|
|
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_write_$group_str$</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org6cf7c9f" class="outline-4">
|
|
<h4 id="org6cf7c9f"><span class="section-number-4">3.8.4</span> Python templates for front end</h4>
|
|
<div class="outline-text-4" id="text-3-8-4">
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">write_</span>$group_str$(trexio_file, str_w: <span style="color: #483d8b;">str</span>) -> <span style="color: #008b8b;">None</span>:
|
|
<span style="color: #8b2252;">"""Write the $group_str$ variable in the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameters:</span>
|
|
|
|
<span style="color: #8b2252;"> trexio_file:</span>
|
|
<span style="color: #8b2252;"> TREXIO File object.</span>
|
|
|
|
<span style="color: #8b2252;"> str_w: str</span>
|
|
<span style="color: #8b2252;"> String corresponding to the $group_str$ variable to be written.</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a0522d;">max_str_length</span> = <span style="color: #483d8b;">len</span>(str_w) + 1
|
|
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_write_$group_str$(trexio_file.pytrexio_s, str_w, max_str_length)
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">read_</span>$group_str$(trexio_file) -> <span style="color: #483d8b;">str</span>:
|
|
<span style="color: #8b2252;">"""Read the $group_str$ variable from the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function.</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> ~str_r~: str</span>
|
|
<span style="color: #8b2252;"> String corresponding to the $group_str$ variable read from ~trexio_file~.</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a0522d;">rc</span>, <span style="color: #a0522d;">str_r</span> = pytr.trexio_read_$group_str$(trexio_file.pytrexio_s, PYTREXIO_MAX_STR_LENGTH)
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
|
|
<span style="color: #a020f0;">return</span> str_r
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">has_</span>$group_str$(trexio_file) -> <span style="color: #483d8b;">bool</span>:
|
|
<span style="color: #8b2252;">"""Check that $group_str$ variable exists in the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function.</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> True if the variable exists, False otherwise</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - trexio.Error if TREXIO return code ~rc~ is TREXIO_FAILURE and prints the error message using string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_has_$group_str$(trexio_file.pytrexio_s)
|
|
<span style="color: #a020f0;">if</span> rc == TREXIO_FAILURE:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
|
|
<span style="color: #a020f0;">return</span> rc == TREXIO_SUCCESS
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org87fce9e" class="outline-3">
|
|
<h3 id="org87fce9e"><span class="section-number-3">3.9</span> Templates for front end delete an entire group (UNSAFE MODE)</h3>
|
|
<div class="outline-text-3" id="text-3-9">
|
|
</div>
|
|
<div id="outline-container-org6a7f139" class="outline-4">
|
|
<h4 id="org6a7f139"><span class="section-number-4">3.9.1</span> Introduction</h4>
|
|
<div class="outline-text-4" id="text-3-9-1">
|
|
<p>
|
|
This section concerns API calls related to string attributes.
|
|
</p>
|
|
|
|
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
|
|
|
|
|
|
<colgroup>
|
|
<col class="org-left" />
|
|
|
|
<col class="org-left" />
|
|
</colgroup>
|
|
<thead>
|
|
<tr>
|
|
<th scope="col" class="org-left">Function name</th>
|
|
<th scope="col" class="org-left">Description</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="org-left"><code>trexio_delete_$group$</code></td>
|
|
<td class="org-left">Delete a given group from the TREXIO file</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org7958c2a" class="outline-4">
|
|
<h4 id="org7958c2a"><span class="section-number-4">3.9.2</span> C templates for front end</h4>
|
|
<div class="outline-text-4" id="text-3-9-2">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_delete_$group$</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (file->mode != <span style="color: #8b2252;">'u'</span>) <span style="color: #a020f0;">return</span> TREXIO_SAFE_MODE;
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
<span style="color: #a020f0;">return</span> trexio_text_delete_$group$(file);
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
<span style="color: #a020f0;">return</span> trexio_hdf5_delete_$group$(file);
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">return</span> TREXIO_BACK_END_MISSING;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> return trexio_json_delete_$group$(file);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_FAILURE;
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orga1014f8" class="outline-4">
|
|
<h4 id="orga1014f8"><span class="section-number-4">3.9.3</span> Fortran templates for front end</h4>
|
|
<div class="outline-text-4" id="text-3-9-3">
|
|
<p>
|
|
The <code>Fortran</code> templates that provide an access to the <code>C</code> API calls from Fortran.
|
|
These templates are based on the use of <code>iso_c_binding</code>. Pointers have to be passed by value.
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_delete_$group$</span> (trex_file) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_delete_$group$</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orgcd08ae9" class="outline-4">
|
|
<h4 id="orgcd08ae9"><span class="section-number-4">3.9.4</span> Python templates for front end</h4>
|
|
<div class="outline-text-4" id="text-3-9-4">
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">delete_</span>$group$(trexio_file) -> <span style="color: #008b8b;">None</span>:
|
|
<span style="color: #8b2252;">"""Delete the entire $group$ group from the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameters:</span>
|
|
|
|
<span style="color: #8b2252;"> trexio_file:</span>
|
|
<span style="color: #8b2252;"> TREXIO File object.</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_delete_$group$(trexio_file.pytrexio_s)
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orgf4b6a01" class="outline-2">
|
|
<h2 id="orgf4b6a01"><span class="section-number-2">4</span> Source code for the determinant part</h2>
|
|
<div class="outline-text-2" id="text-4">
|
|
<p>
|
|
Storage of the determinants is a particular case,
|
|
which requires special treatment, but has to be coded only once
|
|
(since there is only one group that corresponds to it).
|
|
Thus, there is no need to auto-generate this part via templates.
|
|
</p>
|
|
|
|
<p>
|
|
This section concerns API calls related to Slater determinants.
|
|
</p>
|
|
|
|
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
|
|
|
|
|
|
<colgroup>
|
|
<col class="org-left" />
|
|
|
|
<col class="org-left" />
|
|
</colgroup>
|
|
<thead>
|
|
<tr>
|
|
<th scope="col" class="org-left">Function name</th>
|
|
<th scope="col" class="org-left">Description</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="org-left"><code>trexio_has_determinant_list</code></td>
|
|
<td class="org-left">Check if an attribute exists in a file</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_write_determinant_list</code></td>
|
|
<td class="org-left">Write an attribute</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_read_determinant_list</code></td>
|
|
<td class="org-left">Read an attribute</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td class="org-left"><code>trexio_get_int64_num</code></td>
|
|
<td class="org-left">Get the number of int64 bit fields per determinant</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div id="outline-container-orge2b3d27" class="outline-4">
|
|
<h4 id="orge2b3d27"><span class="section-number-4">4.0.1</span> C source code</h4>
|
|
<div class="outline-text-4" id="text-4-0-1">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_get_int64_num</span>(<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">num</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (num == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
|
|
/* <span style="color: #b22222;">Read the number of mos</span> */
|
|
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">mo_num</span> = 0L;
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span> = trexio_read_mo_num_64(file, &mo_num);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
<span style="color: #a020f0;">if</span> (mo_num == 0L) <span style="color: #a020f0;">return</span> TREXIO_INVALID_NUM;
|
|
|
|
/* <span style="color: #b22222;">Compute how many integer numbers is needed to represent a determinant</span> */
|
|
<span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">int_num</span> = 0;
|
|
int_num = (mo_num - 1L)/64 + 1;
|
|
|
|
*num = int_num;
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_read_determinant_list</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">offset_file</span>, <span style="color: #228b22;">int64_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">buffer_size_read</span>, <span style="color: #228b22;">int64_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">dset</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (dset == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (trexio_has_determinant_list(file) != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> TREXIO_DSET_MISSING;
|
|
|
|
/* <span style="color: #b22222;">Get the number of int bit fields per determinant</span> */
|
|
<span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">int_num</span> = 0;
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span> = trexio_get_int64_num(file, &int_num);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">rank</span> = 2;
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">det_size</span> = (<span style="color: #228b22;">uint64_t</span>) (*buffer_size_read);
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dims</span>[2] = {det_size, int_num*2UL};
|
|
|
|
// <span style="color: #b22222;">introduce a new variable which will be modified with the number of integrals being read if EOF is encountered</span>
|
|
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">eof_read_size</span> = 0L;
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
rc = trexio_text_read_determinant_list(file, offset_file, rank, dims, &eof_read_size, dset);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
rc = trexio_hdf5_read_determinant_list(file, offset_file, rank, dims, &eof_read_size, dset);
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
rc = TREXIO_BACK_END_MISSING;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> return trexio_json_read_$group_dset$(...);</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
<span style="color: #a020f0;">default</span>:
|
|
rc = TREXIO_FAILURE; /* <span style="color: #b22222;">Impossible case</span> */
|
|
<span style="color: #a020f0;">break</span>;
|
|
}
|
|
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS && rc != TREXIO_END) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
<span style="color: #a020f0;">if</span> (rc == TREXIO_END) *buffer_size_read = eof_read_size;
|
|
|
|
<span style="color: #a020f0;">return</span> rc;
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_read_safe_determinant_list</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">offset_file</span>, <span style="color: #228b22;">int64_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">buffer_size_read</span>, <span style="color: #228b22;">int64_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">dset_out</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">dim_out</span>)
|
|
{
|
|
<span style="color: #a020f0;">return</span> trexio_read_determinant_list(file, offset_file, buffer_size_read, dset_out);
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_write_determinant_list</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">offset_file</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">buffer_size</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span>* <span style="color: #a0522d;">dset</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (dset == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
|
|
/* <span style="color: #b22222;">Get the number of int bit fields per determinant</span> */
|
|
<span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">int_num</span> = 0;
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span> = trexio_get_int64_num(file, &int_num);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">rank</span> = 2;
|
|
<span style="color: #228b22;">uint64_t</span> <span style="color: #a0522d;">dims</span>[2] = {buffer_size, int_num*2UL};
|
|
|
|
assert(file->back_end < TREXIO_INVALID_BACK_END);
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
rc = trexio_text_write_determinant_list(file, offset_file, rank, dims, dset);
|
|
<span style="color: #a020f0;">break</span>;
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
rc = trexio_hdf5_write_determinant_list(file, offset_file, rank, dims, dset);
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">return</span> TREXIO_BACK_END_MISSING;
|
|
<span style="color: #a020f0;">break</span>;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> rc = trexio_json_read_</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
// <span style="color: #b22222;">Update the determinant_num value with the number of determinants written</span>
|
|
<span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">det_num</span> = 0L;
|
|
// <span style="color: #b22222;">Read the determinant_num if it exists already</span>
|
|
<span style="color: #a020f0;">if</span> (trexio_has_determinant_num(file) == TREXIO_SUCCESS) {
|
|
rc = trexio_read_determinant_num_64(file, &det_num);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
}
|
|
// <span style="color: #b22222;">Check for the INT64 overflow before writing an updated value</span>
|
|
<span style="color: #a020f0;">if</span> (INT64_MAX - det_num > buffer_size) {
|
|
det_num += buffer_size;
|
|
} <span style="color: #a020f0;">else</span> {
|
|
<span style="color: #a020f0;">return</span> TREXIO_INT_SIZE_OVERFLOW;
|
|
}
|
|
// <span style="color: #b22222;">Overwrite previous value. Here we have to temporarily set the file->mode to 'u' to trick the API</span>
|
|
// <span style="color: #b22222;">in order to overwrite existing determinant_num. Otherwise the API returns TREXIO_NUM_ALREADY_EXISTS.</span>
|
|
<span style="color: #228b22;">char</span> <span style="color: #a0522d;">mode_tmp</span> = file->mode;
|
|
file->mode = <span style="color: #8b2252;">'u'</span>;
|
|
rc = trexio_write_determinant_num_64(file, det_num);
|
|
file->mode = mode_tmp;
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_write_safe_determinant_list</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">offset_file</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">buffer_size</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span>* <span style="color: #a0522d;">dset_in</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">dim_in</span>)
|
|
{
|
|
<span style="color: #a020f0;">return</span> trexio_write_determinant_list(file, offset_file, buffer_size, dset_in);
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_has_determinant_list</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
|
|
assert(file->back_end < TREXIO_INVALID_BACK_END);
|
|
|
|
<span style="color: #a020f0;">switch</span> (file->back_end) {
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_TEXT:
|
|
<span style="color: #a020f0;">return</span> trexio_text_has_determinant_list(file);
|
|
|
|
<span style="color: #a020f0;">case</span> TREXIO_HDF5:
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
<span style="color: #a020f0;">return</span> trexio_hdf5_has_determinant_list(file);
|
|
<span style="color: #483d8b;">#else</span>
|
|
<span style="color: #a020f0;">return</span> TREXIO_BACK_END_MISSING;
|
|
<span style="color: #483d8b;">#endif</span>
|
|
/*
|
|
<span style="color: #b22222;"> case TREXIO_JSON:</span>
|
|
<span style="color: #b22222;"> return trexio_json_has_</span>
|
|
<span style="color: #b22222;"> break;</span>
|
|
*/
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_FAILURE;
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org464b9fd" class="outline-4">
|
|
<h4 id="org464b9fd"><span class="section-number-4">4.0.2</span> Fortran interface</h4>
|
|
<div class="outline-text-4" id="text-4-0-2">
|
|
<p>
|
|
The <code>Fortran</code> templates that provide an access to the <code>C</code> API calls from Fortran.
|
|
These templates are based on the use of <code>iso_c_binding</code>. Pointers have to be passed by value.
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code)<span style="color: #a0522d;"> function trexio_write_determinant_list (trex_file, </span><span style="color: #a020f0;">&</span>
|
|
offset_file, buffer_size, list) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</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;"> offset_file</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;"> buffer_size</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;"> list(*)</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_write_determinant_list</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
|
|
<span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code)<span style="color: #a0522d;"> function trexio_write_safe_determinant_list (trex_file, </span><span style="color: #a020f0;">&</span>
|
|
offset_file, buffer_size, <span style="color: #a020f0;">&</span>
|
|
list, list_size) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</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;"> offset_file</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;"> buffer_size</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;"> list(*)</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;"> list_size</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_write_safe_determinant_list</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code)<span style="color: #a0522d;"> function trexio_read_determinant_list(trex_file, </span><span style="color: #a020f0;">&</span>
|
|
offset_file, buffer_size, list) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</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;"> offset_file</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(inout) ::<span style="color: #a0522d;"> buffer_size</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> list(*)</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_read_determinant_list</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
|
|
<span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code)<span style="color: #a0522d;"> function trexio_read_safe_determinant_list (trex_file, </span><span style="color: #a020f0;">&</span>
|
|
offset_file, buffer_size, <span style="color: #a020f0;">&</span>
|
|
list, list_size) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</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;"> offset_file</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(inout) ::<span style="color: #a0522d;"> buffer_size</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> list(*)</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;"> list_size</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_read_safe_determinant_list</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_has_determinant_list</span> (trex_file) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_has_determinant_list</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
|
|
<span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_get_int64_num</span> (trex_file, num) <span style="color: #a020f0;">bind</span>(C)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trex_file</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> num</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_get_int64_num</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-org4b51a49" class="outline-4">
|
|
<h4 id="org4b51a49"><span class="section-number-4">4.0.3</span> Python interface</h4>
|
|
<div class="outline-text-4" id="text-4-0-3">
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">write_determinant_list</span>(trexio_file: File, offset_file: <span style="color: #483d8b;">int</span>, buffer_size: <span style="color: #483d8b;">int</span>, determinants: <span style="color: #483d8b;">list</span>) -> <span style="color: #008b8b;">None</span>:
|
|
<span style="color: #8b2252;">"""Write the determinant list in the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameters:</span>
|
|
|
|
<span style="color: #8b2252;"> trexio_file:</span>
|
|
<span style="color: #8b2252;"> TREXIO File object.</span>
|
|
|
|
<span style="color: #8b2252;"> offset_file: int</span>
|
|
<span style="color: #8b2252;"> The number of determinants to be skipped in the file when writing.</span>
|
|
|
|
<span style="color: #8b2252;"> buffer_size: int</span>
|
|
<span style="color: #8b2252;"> The number of determinants to write in the file.</span>
|
|
|
|
<span style="color: #8b2252;"> determinants: list OR numpy.ndarray</span>
|
|
<span style="color: #8b2252;"> Array of determinant_list to be written. If array data type does not correspond to int64, the conversion is performed.</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - trexio.Error if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">not</span> <span style="color: #483d8b;">isinstance</span>(offset_file, <span style="color: #483d8b;">int</span>):
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">TypeError</span>(<span style="color: #8b2252;">"offset_file argument has to be an integer."</span>)
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">not</span> <span style="color: #483d8b;">isinstance</span>(buffer_size, <span style="color: #483d8b;">int</span>):
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">TypeError</span>(<span style="color: #8b2252;">"buffer_size argument has to be an integer."</span>)
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">not</span> <span style="color: #483d8b;">isinstance</span>(determinants, (<span style="color: #483d8b;">list</span>, <span style="color: #483d8b;">tuple</span>, np.ndarray)):
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">TypeError</span>(<span style="color: #8b2252;">"determinants argument has to be an array (list, tuple or NumPy ndarray)."</span>)
|
|
|
|
<span style="color: #a0522d;">convert</span> = <span style="color: #008b8b;">False</span>
|
|
<span style="color: #a0522d;">flatten</span> = <span style="color: #008b8b;">False</span>
|
|
<span style="color: #a020f0;">if</span> <span style="color: #483d8b;">isinstance</span>(determinants, np.ndarray):
|
|
# <span style="color: #b22222;">convert to int64 if input determinants are in a different precision</span>
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">not</span> determinants.dtype==np.int64:
|
|
<span style="color: #a0522d;">convert</span>= <span style="color: #008b8b;">True</span>
|
|
|
|
<span style="color: #a020f0;">if</span> <span style="color: #483d8b;">len</span>(determinants.shape) > 1:
|
|
<span style="color: #a0522d;">flatten</span> = <span style="color: #008b8b;">True</span>
|
|
<span style="color: #a020f0;">if</span> convert:
|
|
<span style="color: #a0522d;">dets_64</span> = np.int64(determinants).flatten()
|
|
<span style="color: #a020f0;">else</span>:
|
|
<span style="color: #a0522d;">dets_64</span> = np.array(determinants, dtype=np.int64).flatten()
|
|
<span style="color: #a020f0;">else</span>:
|
|
<span style="color: #a020f0;">if</span> convert:
|
|
<span style="color: #a0522d;">dets_64</span> = np.int64(determinants)
|
|
<span style="color: #a020f0;">else</span>:
|
|
# <span style="color: #b22222;">if input array is a multidimensional list or tuple, we have to convert it</span>
|
|
<span style="color: #a020f0;">try</span>:
|
|
# <span style="color: #b22222;">if list is flat - the attempt to compute len() will raise a TypeError</span>
|
|
<span style="color: #a0522d;">_</span> = <span style="color: #483d8b;">len</span>(determinants[0])
|
|
<span style="color: #a0522d;">dets_64</span> = np.array(determinants, dtype=np.int64).flatten()
|
|
<span style="color: #a0522d;">flatten</span> = <span style="color: #008b8b;">True</span>
|
|
<span style="color: #a020f0;">except</span> <span style="color: #228b22;">TypeError</span>:
|
|
<span style="color: #a020f0;">pass</span>
|
|
|
|
<span style="color: #a020f0;">if</span> flatten <span style="color: #a020f0;">or</span> convert:
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_write_safe_determinant_list(trexio_file.pytrexio_s, offset_file, buffer_size, dets_64)
|
|
<span style="color: #a020f0;">else</span>:
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_write_safe_determinant_list(trexio_file.pytrexio_s, offset_file, buffer_size, determinants)
|
|
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">read_determinant_list</span>(trexio_file: File, offset_file: <span style="color: #483d8b;">int</span>, buffer_size: <span style="color: #483d8b;">int</span>) -> <span style="color: #483d8b;">tuple</span>:
|
|
<span style="color: #8b2252;">"""Read determinant_list from the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameters:</span>
|
|
|
|
<span style="color: #8b2252;"> trexio_file:</span>
|
|
<span style="color: #8b2252;"> TREXIO File object.</span>
|
|
|
|
<span style="color: #8b2252;"> offset_file: int</span>
|
|
<span style="color: #8b2252;"> The number of determinants to be skipped in the file when reading.</span>
|
|
|
|
<span style="color: #8b2252;"> buffer_size: int</span>
|
|
<span style="color: #8b2252;"> The number of determinants to read from the file.</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> (determinants, n_int_read, eof_flag) tuple where</span>
|
|
<span style="color: #8b2252;"> - determinants are NumPy arrays [numpy.ndarray] with the default int64 precision;</span>
|
|
<span style="color: #8b2252;"> - n_int_read [int] is the number of determinants read from the trexio_file</span>
|
|
<span style="color: #8b2252;"> (either strictly equal to buffer_size or less than buffer_size if EOF has been reached);</span>
|
|
<span style="color: #8b2252;"> - eof_flag [bool] is True when EOF has been reached (i.e. when call to low-level pytrexio API returns TREXIO_END)</span>
|
|
<span style="color: #8b2252;"> False otherwise.</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - trexio.Error if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">not</span> <span style="color: #483d8b;">isinstance</span>(offset_file, <span style="color: #483d8b;">int</span>):
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">TypeError</span>(<span style="color: #8b2252;">"offset_file argument has to be an integer."</span>)
|
|
<span style="color: #a020f0;">if</span> <span style="color: #a020f0;">not</span> <span style="color: #483d8b;">isinstance</span>(buffer_size, <span style="color: #483d8b;">int</span>):
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">TypeError</span>(<span style="color: #8b2252;">"buffer_size argument has to be an integer."</span>)
|
|
|
|
|
|
# <span style="color: #b22222;">read the number of determinants already in the file</span>
|
|
<span style="color: #a0522d;">det_num</span> = read_determinant_num(trexio_file)
|
|
# <span style="color: #b22222;">calculate the int_num (number of int bit fields per determinant)</span>
|
|
<span style="color: #a0522d;">int_num</span> = 2 * get_int64_num(trexio_file)
|
|
|
|
# <span style="color: #b22222;">additional modification needed to avoid allocating more memory than needed if EOF will be reached during read</span>
|
|
<span style="color: #a0522d;">overflow</span> = offset_file + buffer_size - det_num
|
|
<span style="color: #a0522d;">eof_flag</span> = <span style="color: #008b8b;">False</span>
|
|
<span style="color: #a020f0;">if</span> overflow > 0:
|
|
<span style="color: #a0522d;">verified_size</span> = buffer_size - overflow
|
|
<span style="color: #a0522d;">eof_flag</span> = <span style="color: #008b8b;">True</span>
|
|
<span style="color: #a020f0;">else</span>:
|
|
<span style="color: #a0522d;">verified_size</span> = buffer_size
|
|
|
|
# <span style="color: #b22222;">main call to the low-level (SWIG-wrapped) trexio_read function, which also requires the sizes of the output to be provided</span>
|
|
# <span style="color: #b22222;">read_buf_size contains the number of elements being read from the file, useful when EOF has been reached</span>
|
|
<span style="color: #a0522d;">rc</span>, <span style="color: #a0522d;">n_int_read</span>, <span style="color: #a0522d;">determinants</span> = pytr.trexio_read_safe_determinant_list(trexio_file.pytrexio_s,
|
|
offset_file,
|
|
verified_size,
|
|
verified_size * int_num)
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
<span style="color: #a020f0;">if</span> n_int_read == 0:
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">ValueError</span>(<span style="color: #8b2252;">"No integrals have been read from the file."</span>)
|
|
<span style="color: #a020f0;">if</span> determinants <span style="color: #a020f0;">is</span> <span style="color: #008b8b;">None</span>:
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">ValueError</span>(<span style="color: #8b2252;">"Returned NULL array from the low-level pytrexio API."</span>)
|
|
|
|
# <span style="color: #b22222;">conversion to custom types can be performed on the user side, here we only reshape the returned flat array according to int_num</span>
|
|
<span style="color: #a0522d;">dets_reshaped</span> = np.reshape(determinants, (verified_size, int_num), order=<span style="color: #8b2252;">'C'</span>)
|
|
|
|
<span style="color: #a020f0;">return</span> (dets_reshaped, n_int_read, eof_flag)
|
|
|
|
|
|
<span style="color: #a020f0;">def</span> <span style="color: #0000ff;">get_int64_num</span>(trexio_file) -> <span style="color: #483d8b;">int</span>:
|
|
<span style="color: #8b2252;">"""Compute the number of int64 bit fields corresponding to the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function.</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> ~num~: int</span>
|
|
<span style="color: #8b2252;"> Number of int64 bit fields per determinant.</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a0522d;">rc</span>, <span style="color: #a0522d;">num</span> = pytr.trexio_get_int64_num(trexio_file.pytrexio_s)
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
|
|
<span style="color: #a020f0;">return</span> num
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">has_determinant_list</span>(trexio_file) -> <span style="color: #483d8b;">bool</span>:
|
|
<span style="color: #8b2252;">"""Check that determinant_list exists in the TREXIO file.</span>
|
|
|
|
<span style="color: #8b2252;"> Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function.</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> True if the variable exists, False otherwise</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - trexio.Error if TREXIO return code ~rc~ is TREXIO_FAILURE and prints the error message using string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_has_determinant_list(trexio_file.pytrexio_s)
|
|
<span style="color: #a020f0;">if</span> rc == TREXIO_FAILURE:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
|
|
<span style="color: #a020f0;">return</span> rc == TREXIO_SUCCESS
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orge298f0c" class="outline-2">
|
|
<h2 id="orge298f0c"><span class="section-number-2">5</span> General helper functions</h2>
|
|
<div class="outline-text-2" id="text-5">
|
|
<p>
|
|
This section contains general helper functions like <code>trexio_info</code>.
|
|
</p>
|
|
|
|
<p>
|
|
<code>trexio_info</code> prints information about the TREXIO configuration (see <code>config.h</code> file).
|
|
In particular:
|
|
</p>
|
|
|
|
<ol class="org-ol">
|
|
<li><code>TREXIO_PACKAGE_VERSION</code> [string]</li>
|
|
<li><code>HAVE_HDF5</code> [bool]</li>
|
|
<li><code>HDF5_VERSION</code> [string] (optional, only if <code>HAVE_HDF5</code> is <code>true</code>)</li>
|
|
<li><code>TREXIO_GIT_HASH</code> [string]</li>
|
|
</ol>
|
|
|
|
<p>
|
|
<code>trexio_mark_safety</code> checks if the file has been open in UNSAFE mode.
|
|
If it was, the <code>metadata_unsafe</code> attribute can be overwritten with the value provided in a second argument of the function.
|
|
Since <code>metadata_unsafe</code> is set to <code>1</code> (<code>true</code>) upon the first opening of the file in UNSAFE mode, this value is immutable.
|
|
However, if the user validated that the file is correct (e.g. using <code>trexio-tools</code>),
|
|
then value of the <code>metadata_unsafe</code> attribute can be changed using the aforementioned function.
|
|
</p>
|
|
|
|
<p>
|
|
<code>trexio_to_orbital_list</code> function converts the list of integer bit fields of a
|
|
given determinant into a list of indices of the occupied orbitals (for one spin component).
|
|
<code>trexio_to_orbital_list_up_dn</code> function does the same but for both up- and down-spin components
|
|
of the determinant and returns two list of orbitals each corresponding to a different component.
|
|
</p>
|
|
|
|
<p>
|
|
<code>trexio_to_bitfield_list</code> function converts the list of occupied orbitals (up- or down-spin) into the corresponding <code>int64_t</code>
|
|
bitfield representation of the determinant. If the creation of the bitfield requires a change of sign, the return code is
|
|
<code>TREXIO_PHASE_CHANGE</code>.
|
|
</p>
|
|
|
|
<p>
|
|
<code>trexio_convert_nao_radius</code> functions convert a radius from the center of an NAO to its logarithmic interpolation grid.
|
|
</p>
|
|
|
|
<p>
|
|
<code>trexio_evaluate_nao_radial</code> function evaluates the radial function of an NAO for a given distance from the center.
|
|
</p>
|
|
|
|
<p>
|
|
<code>trexio_evaluate_nao_radial_all</code> evaluates all radial functions at a given position in space.
|
|
</p>
|
|
</div>
|
|
|
|
<div id="outline-container-org0c731ce" class="outline-3">
|
|
<h3 id="org0c731ce"><span class="section-number-3">5.1</span> C</h3>
|
|
<div class="outline-text-3" id="text-5-1">
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span> <span style="color: #0000ff;">trexio_info</span>(<span style="color: #228b22;">void</span>);
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #0000ff;">trexio_mark_safety</span>(<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">safety_flag</span>);
|
|
|
|
<span style="color: #a020f0;">typedef</span> <span style="color: #228b22;">int64_t</span> <span style="color: #228b22;">bitfield_t</span>;
|
|
|
|
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">TREXIO_ORBITAL_SHIFT</span> 1
|
|
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">TREXIO_INT_SIZE</span> 64
|
|
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">TREXIO_NORB_PER_INT</span> ( 8*<span style="color: #a020f0;">sizeof</span>(bitfield_t) )
|
|
<span style="color: #483d8b;">#define</span> <span style="color: #a0522d;">TREXIO_NORB_PER_INT_SHIFT</span> ( trailz( TREXIO_NORB_PER_INT ) )
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #0000ff;">trexio_to_orbital_list</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">N_int</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">bitfield_t</span>* <span style="color: #a0522d;">d1</span>, <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">list</span>, <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">occupied_num</span>);
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #0000ff;">trexio_to_orbital_list_up_dn</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">N_int</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">bitfield_t</span>* <span style="color: #a0522d;">d1</span>, <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">list_up</span>, <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">list_dn</span>, <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">occ_num_up</span>, <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">occ_num_dn</span>);
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #0000ff;">trexio_safe_to_orbital_list</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">N_int</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">bitfield_t</span>* <span style="color: #a0522d;">dset_in</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">dim_in</span>, <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">dset_out</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">dim_out</span>, <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">num</span>);
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #0000ff;">trexio_safe_to_orbital_list_up_dn</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">N_int</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">bitfield_t</span>* <span style="color: #a0522d;">dset_in</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">dim_in</span>, <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">dset_up_out</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">dim_up_out</span>, <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">dset_dn_out</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">dim_dn_out</span>, <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">num_up</span>, <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">num_dn</span>);
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #0000ff;">trexio_to_bitfield_list</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span>* <span style="color: #a0522d;">orb_list</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">occupied_num</span>, <span style="color: #228b22;">bitfield_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">bit_list</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">N_int</span>);
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #0000ff;">trexio_convert_nao_radius_32</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">float</span> <span style="color: #a0522d;">r</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">float</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">grid_r</span>, <span style="color: #228b22;">float</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">log_r_out</span>);
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #0000ff;">trexio_convert_nao_radius_64</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">r</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">grid_r</span>, <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">log_r_out</span>);
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #0000ff;">trexio_convert_nao_radius_py</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">r</span>,
|
|
<span style="color: #228b22;">double</span>* <span style="color: #a0522d;">grid_r</span>, <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">n_grid_r</span>, <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">log_r_out</span>);
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #0000ff;">trexio_evaluate_nao_radial</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">shell_index</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">r</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">grid_start</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">grid_size</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">grid_r</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">interpolator</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">normalization</span>, <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">amplitude</span>);
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #0000ff;">trexio_evaluate_nao_radial_all</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">shell_num</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">nucleus_index</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">nucleus_coords</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">grid_start</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">grid_size</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">grid_r</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">interpolator</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">normalization</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">rx</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">ry</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">rz</span>, <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">amplitude</span>);
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #0000ff;">trexio_evaluate_nao_radial_py</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int</span> <span style="color: #a0522d;">shell_index</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">r</span>, <span style="color: #228b22;">int64_t</span>* <span style="color: #a0522d;">grid_start</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_grid_st</span>, <span style="color: #228b22;">int64_t</span>* <span style="color: #a0522d;">grid_size</span>,
|
|
<span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_grid_si</span>, <span style="color: #228b22;">double</span>* <span style="color: #a0522d;">grid_r</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_grid_r</span>, <span style="color: #228b22;">double</span>* <span style="color: #a0522d;">interpolator</span>,
|
|
<span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_interp</span>, <span style="color: #228b22;">double</span>* <span style="color: #a0522d;">normalization</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_norm</span>, <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">amplitude</span>);
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #0000ff;">trexio_evaluate_nao_radial_all_py</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">shell_num</span>,
|
|
<span style="color: #228b22;">int64_t</span>* <span style="color: #a0522d;">nucleus_index</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_nuc_id</span>, <span style="color: #228b22;">double</span>* <span style="color: #a0522d;">nucleus_coords</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_nuc_co</span>,
|
|
<span style="color: #228b22;">int64_t</span>* <span style="color: #a0522d;">grid_start</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_grid_st</span>, <span style="color: #228b22;">int64_t</span>* <span style="color: #a0522d;">grid_size</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_grid_si</span>,
|
|
<span style="color: #228b22;">double</span>* <span style="color: #a0522d;">grid_r</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_grid_r</span>, <span style="color: #228b22;">double</span>* <span style="color: #a0522d;">interpolator</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_interp</span>, <span style="color: #228b22;">double</span>* <span style="color: #a0522d;">normalization</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_norm</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">rx</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">ry</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">rz</span>, <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">amplitudes</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">amplitude_cnt</span>);
|
|
|
|
</pre>
|
|
</div>
|
|
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span> <span style="color: #0000ff;">trexio_to_bitfield_list</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span>* <span style="color: #a0522d;">orb_list</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">occupied_num</span>,
|
|
<span style="color: #228b22;">bitfield_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">bit_list</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">N_int</span>)
|
|
{
|
|
<span style="color: #a020f0;">if</span> (orb_list == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (occupied_num <= 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (bit_list == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_3;
|
|
<span style="color: #a020f0;">if</span> (N_int <= 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_4;
|
|
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">j</span> = 0 ; j < N_int ; j++) {
|
|
bit_list[j] = (<span style="color: #228b22;">bitfield_t</span>) 0;
|
|
}
|
|
|
|
<span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">nswaps</span> = 0;
|
|
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">pos</span> = 0 ; pos < occupied_num ; pos++) {
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">iorb</span> = ((<span style="color: #228b22;">uint32_t</span>) (orb_list[pos] + 1)) - TREXIO_ORBITAL_SHIFT;
|
|
|
|
// <span style="color: #b22222;">Set the bit of to one</span>
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">i</span> = (<span style="color: #228b22;">uint32_t</span>) (iorb >> TREXIO_NORB_PER_INT_SHIFT);
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">uint32_t</span> <span style="color: #a0522d;">k</span> = (<span style="color: #228b22;">uint32_t</span>) (iorb & (TREXIO_NORB_PER_INT - 1) );
|
|
<span style="color: #228b22;">bitfield_t</span> <span style="color: #a0522d;">mask</span> = ((<span style="color: #228b22;">bitfield_t</span>) 1) << k;
|
|
bit_list[i] |= mask;
|
|
|
|
// <span style="color: #b22222;">Check for phase changes</span>
|
|
mask = ~(mask - (<span style="color: #228b22;">bitfield_t</span>) 1);
|
|
nswaps += popcnt(mask & bit_list[i]) - 1;
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">int</span> <span style="color: #a0522d;">j</span>=i+1 ; j < N_int ; ++j) {
|
|
<span style="color: #a020f0;">if</span> (bit_list[j] != (<span style="color: #228b22;">bitfield_t</span>) 0)
|
|
nswaps += popcnt(bit_list[j]);
|
|
}
|
|
}
|
|
|
|
<span style="color: #a020f0;">if</span> ( (nswaps & 1) == 0)
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
<span style="color: #a020f0;">else</span>
|
|
<span style="color: #a020f0;">return</span> TREXIO_PHASE_CHANGE;
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span> <span style="color: #0000ff;">trexio_to_orbital_list</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">N_int</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">bitfield_t</span>* <span style="color: #a0522d;">d1</span>,
|
|
<span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">list</span>,
|
|
<span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">occupied_num</span>)
|
|
{
|
|
<span style="color: #a020f0;">if</span> (N_int <= 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (d1 == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (list == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_3;
|
|
<span style="color: #a020f0;">if</span> (occupied_num == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_4;
|
|
|
|
<span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">k</span> = 0;
|
|
<span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">shift</span> = TREXIO_ORBITAL_SHIFT;
|
|
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">i</span>=0 ; i<N_int ; i++)
|
|
{
|
|
<span style="color: #228b22;">bitfield_t</span> <span style="color: #a0522d;">tmp</span> = d1[i];
|
|
|
|
<span style="color: #a020f0;">while</span> (tmp != (<span style="color: #228b22;">bitfield_t</span>) 0)
|
|
{
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">pos</span> = trailz(tmp);
|
|
<span style="color: #a020f0;">if</span> (pos < 0) <span style="color: #a020f0;">return</span> TREXIO_FAILURE;
|
|
|
|
list[k] = ( (<span style="color: #228b22;">int32_t</span>) pos) + shift - 1;
|
|
tmp ^= ( ((<span style="color: #228b22;">bitfield_t</span>) 1) << pos);
|
|
k++;
|
|
}
|
|
shift += TREXIO_NORB_PER_INT;
|
|
}
|
|
|
|
*occupied_num = (<span style="color: #228b22;">int32_t</span>) k;
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span> <span style="color: #0000ff;">trexio_to_orbital_list_up_dn</span>(<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">N_int</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">bitfield_t</span>* <span style="color: #a0522d;">d1</span>,
|
|
<span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">list_up</span>,
|
|
<span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">list_dn</span>,
|
|
<span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">occ_num_up</span>,
|
|
<span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">occ_num_dn</span>)
|
|
{
|
|
<span style="color: #a020f0;">if</span> (N_int <= 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (d1 == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (list_up == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_3;
|
|
<span style="color: #a020f0;">if</span> (list_dn == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_4;
|
|
<span style="color: #a020f0;">if</span> (occ_num_up == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_5;
|
|
<span style="color: #a020f0;">if</span> (occ_num_dn == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_6;
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span>;
|
|
|
|
/* <span style="color: #b22222;">First process up-spin electrons</span> */
|
|
rc = trexio_to_orbital_list(N_int, &d1[0], list_up, occ_num_up);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
/* <span style="color: #b22222;">Now process down-spin electrons</span> */
|
|
rc = trexio_to_orbital_list(N_int, &d1[N_int], list_dn, occ_num_dn);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS) <span style="color: #a020f0;">return</span> rc;
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_safe_to_orbital_list</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">N_int</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">bitfield_t</span>* <span style="color: #a0522d;">dset_in</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">dim_in</span>,
|
|
<span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">dset_out</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">dim_out</span>,
|
|
<span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">num</span>)
|
|
{
|
|
<span style="color: #a020f0;">return</span> trexio_to_orbital_list(N_int, dset_in, dset_out, num);
|
|
}
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_safe_to_orbital_list_up_dn</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">N_int</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">bitfield_t</span>* <span style="color: #a0522d;">dset_in</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">dim_in</span>,
|
|
<span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">dset_up_out</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">dim_up_out</span>,
|
|
<span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">dset_dn_out</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int64_t</span> <span style="color: #a0522d;">dim_dn_out</span>,
|
|
<span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">num_up</span>,
|
|
<span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">num_dn</span>)
|
|
{
|
|
<span style="color: #a020f0;">return</span> trexio_to_orbital_list_up_dn(N_int, dset_in, dset_up_out, dset_dn_out, num_up, num_dn);
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_convert_nao_radius_32</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">float</span> <span style="color: #a0522d;">r</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">float</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">grid_r</span>, <span style="color: #228b22;">float</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">log_r_out</span>)
|
|
{
|
|
<span style="color: #a020f0;">if</span> (r < 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (grid_r == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (log_r_out == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_3;
|
|
|
|
*log_r_out = log(r / grid_r[0]) / log(grid_r[1] / grid_r[0]);
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
}
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_convert_nao_radius_64</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">r</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">grid_r</span>, <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">log_r_out</span>)
|
|
{
|
|
<span style="color: #a020f0;">if</span> (r < 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (grid_r == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (log_r_out == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_3;
|
|
|
|
*log_r_out = log(r / grid_r[0]) / log(grid_r[1] / grid_r[0]);
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
}
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_convert_nao_radius_py</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">r</span>, <span style="color: #228b22;">double</span>* <span style="color: #a0522d;">grid_r</span>, <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">n_grid</span>, <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">log_r_out</span>)
|
|
{
|
|
<span style="color: #a020f0;">if</span> (r < 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (grid_r == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (log_r_out == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_3;
|
|
|
|
*log_r_out = log(r / grid_r[0]) / log(grid_r[1] / grid_r[0]);
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
}
|
|
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_evaluate_nao_radial</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">shell_index</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">r</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">grid_start</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">grid_size</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">grid_r</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">interpolator</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">normalization</span>, <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">amplitude</span>)
|
|
{
|
|
<span style="color: #a020f0;">if</span> (shell_index < 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (r < 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (grid_start == 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_3;
|
|
<span style="color: #a020f0;">if</span> (grid_size == 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_4;
|
|
<span style="color: #a020f0;">if</span> (grid_r == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_5;
|
|
<span style="color: #a020f0;">if</span> (interpolator == 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_6;
|
|
<span style="color: #a020f0;">if</span> (normalization == 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_7;
|
|
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">i0</span> = 4*grid_start[shell_index];
|
|
|
|
// <span style="color: #b22222;">Convert radius to logarithmic units </span>
|
|
<span style="color: #228b22;">double</span> <span style="color: #a0522d;">r_log</span> = 0.0;
|
|
trexio_convert_nao_radius_64 (r, grid_r + grid_start[shell_index], &r_log);
|
|
<span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">i_log</span> = (<span style="color: #228b22;">int32_t</span>) r_log;
|
|
<span style="color: #a020f0;">if</span> (i_log < 0)
|
|
i_log = 0;
|
|
<span style="color: #a020f0;">else</span> <span style="color: #a020f0;">if</span> (i_log >= grid_size[shell_index])
|
|
<span style="color: #a020f0;">return</span> 0; // <span style="color: #b22222;">NAOs vanish at the boundary by definition</span>
|
|
|
|
<span style="color: #228b22;">double</span> <span style="color: #a0522d;">t</span> = r_log - (<span style="color: #228b22;">double</span>) i_log;
|
|
<span style="color: #228b22;">double</span> <span style="color: #a0522d;">val_spline</span> = interpolator[i0 + 4*i_log + 0];
|
|
val_spline += t * interpolator[i0 + 4*i_log + 1];
|
|
val_spline += t * t * interpolator[i0 + 4*i_log + 2];
|
|
val_spline += t * t * t * interpolator[i0 + 4*i_log + 3];
|
|
|
|
*amplitude = val_spline * normalization[shell_index] / r;
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
}
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_evaluate_nao_radial_all</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">shell_num</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">nucleus_index</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">nucleus_coords</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">grid_start</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">grid_size</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">grid_r</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">interpolator</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">normalization</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">rx</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">ry</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">rz</span>, <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">amplitude</span>)
|
|
{
|
|
<span style="color: #a020f0;">if</span> (shell_num < 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (nucleus_index == 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (nucleus_coords == 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_3;
|
|
<span style="color: #a020f0;">if</span> (grid_start == 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_4;
|
|
<span style="color: #a020f0;">if</span> (grid_size == 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_5;
|
|
<span style="color: #a020f0;">if</span> (grid_r == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_6;
|
|
<span style="color: #a020f0;">if</span> (interpolator == 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_7;
|
|
<span style="color: #a020f0;">if</span> (normalization == 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_8;
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span>;
|
|
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">int</span> <span style="color: #a0522d;">shell_index</span> = 0; shell_index < shell_num; shell_index++) {
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">nuc_index</span> = nucleus_index[shell_index];
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">dx</span> = nucleus_coords[3*nuc_index + 0] - rx;
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">dy</span> = nucleus_coords[3*nuc_index + 1] - ry;
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">dz</span> = nucleus_coords[3*nuc_index + 2] - rz;
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">r</span> = sqrt(dx*dx + dy*dy + dz*dz);
|
|
|
|
// <span style="color: #b22222;">All possibly reported errors have been caught above</span>
|
|
rc = trexio_evaluate_nao_radial(shell_index, r, grid_start,
|
|
grid_size, grid_r, interpolator, normalization, &amplitude[shell_index]);
|
|
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS)
|
|
<span style="color: #a020f0;">return</span> rc;
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
}
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #0000ff;">trexio_evaluate_nao_radial_py</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int</span> <span style="color: #a0522d;">shell_index</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">r</span>, <span style="color: #228b22;">int64_t</span>* <span style="color: #a0522d;">grid_start</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_grid_st</span>,
|
|
<span style="color: #228b22;">int64_t</span>* <span style="color: #a0522d;">grid_size</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_grid_si</span>, <span style="color: #228b22;">double</span>* <span style="color: #a0522d;">grid_r</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_grid_r</span>,
|
|
<span style="color: #228b22;">double</span>* <span style="color: #a0522d;">interpolator</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_interp</span>, <span style="color: #228b22;">double</span>* <span style="color: #a0522d;">normalization</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_norm</span>, <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">amplitude</span>)
|
|
{
|
|
// <span style="color: #b22222;">Code needs to be copied because of the use of int64_t mandated by Python</span>
|
|
// <span style="color: #b22222;">If a 64-bit version is implemented, this can be avoided</span>
|
|
<span style="color: #a020f0;">if</span> (shell_index < 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (r < 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (grid_start == 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_3;
|
|
<span style="color: #a020f0;">if</span> (grid_size == 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_4;
|
|
<span style="color: #a020f0;">if</span> (grid_r == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_5;
|
|
<span style="color: #a020f0;">if</span> (interpolator == 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_6;
|
|
<span style="color: #a020f0;">if</span> (normalization == 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_7;
|
|
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">i0</span> = 4*grid_start[shell_index];
|
|
|
|
// <span style="color: #b22222;">Convert radius to logarithmic units </span>
|
|
<span style="color: #228b22;">double</span> <span style="color: #a0522d;">r_log</span> = 0.0;
|
|
trexio_convert_nao_radius_64 (r, grid_r + grid_start[shell_index], &r_log);
|
|
<span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">i_log</span> = (<span style="color: #228b22;">int32_t</span>) r_log;
|
|
<span style="color: #a020f0;">if</span> (i_log < 0) {
|
|
*amplitude = interpolator[i0] * normalization[shell_index] / r;
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
} <span style="color: #a020f0;">else</span> <span style="color: #a020f0;">if</span> (i_log >= grid_size[shell_index]) {
|
|
*amplitude = 0.0;
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS; // <span style="color: #b22222;">NAOs vanish at the boundary by definition</span>
|
|
}
|
|
|
|
<span style="color: #228b22;">double</span> <span style="color: #a0522d;">t</span> = r_log - (<span style="color: #228b22;">double</span>) i_log;
|
|
<span style="color: #228b22;">double</span> <span style="color: #a0522d;">val_spline</span> = interpolator[i0 + 4*i_log + 0];
|
|
val_spline += t * interpolator[i0 + 4*i_log + 1];
|
|
val_spline += t * t * interpolator[i0 + 4*i_log + 2];
|
|
val_spline += t * t * t * interpolator[i0 + 4*i_log + 3];
|
|
|
|
*amplitude = val_spline * normalization[shell_index] / r;
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
}
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #0000ff;">trexio_evaluate_nao_radial_all_py</span> (<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">shell_num</span>,
|
|
<span style="color: #228b22;">int64_t</span>* <span style="color: #a0522d;">nucleus_index</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_nuc_id</span>, <span style="color: #228b22;">double</span>* <span style="color: #a0522d;">nucleus_coords</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_nuc_co</span>,
|
|
<span style="color: #228b22;">int64_t</span>* <span style="color: #a0522d;">grid_start</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_grid_st</span>, <span style="color: #228b22;">int64_t</span>* <span style="color: #a0522d;">grid_size</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_grid_si</span>,
|
|
<span style="color: #228b22;">double</span>* <span style="color: #a0522d;">grid_r</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_grid_r</span>, <span style="color: #228b22;">double</span>* <span style="color: #a0522d;">interpolator</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_interp</span>,
|
|
<span style="color: #228b22;">double</span>* <span style="color: #a0522d;">normalization</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">n_norm</span>,
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">rx</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">ry</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">rz</span>, <span style="color: #228b22;">double</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">amplitudes</span>, <span style="color: #228b22;">int</span> <span style="color: #a0522d;">amplitude_cnt</span>)
|
|
{
|
|
<span style="color: #a020f0;">if</span> (shell_num < 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
<span style="color: #a020f0;">if</span> (nucleus_index == 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
<span style="color: #a020f0;">if</span> (nucleus_coords == 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_3;
|
|
<span style="color: #a020f0;">if</span> (grid_start == 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_4;
|
|
<span style="color: #a020f0;">if</span> (grid_size == 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_5;
|
|
<span style="color: #a020f0;">if</span> (grid_r == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_6;
|
|
<span style="color: #a020f0;">if</span> (interpolator == 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_7;
|
|
<span style="color: #a020f0;">if</span> (normalization == 0) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_8;
|
|
|
|
<span style="color: #228b22;">trexio_exit_code</span> <span style="color: #a0522d;">rc</span>;
|
|
|
|
<span style="color: #a020f0;">for</span> (<span style="color: #228b22;">int</span> <span style="color: #a0522d;">shell_index</span> = 0; shell_index < shell_num; shell_index++) {
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">nuc_index</span> = nucleus_index[shell_index];
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">dx</span> = nucleus_coords[3*nuc_index + 0] - rx;
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">dy</span> = nucleus_coords[3*nuc_index + 1] - ry;
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">dz</span> = nucleus_coords[3*nuc_index + 2] - rz;
|
|
<span style="color: #a020f0;">const</span> <span style="color: #228b22;">double</span> <span style="color: #a0522d;">r</span> = sqrt(dx*dx + dy*dy + dz*dz);
|
|
|
|
// <span style="color: #b22222;">All possibly reported errors have been caught above</span>
|
|
rc = trexio_evaluate_nao_radial_py(shell_index, r, grid_start, n_grid_st,
|
|
grid_size, n_grid_si, grid_r, n_grid_r, interpolator, n_interp, normalization, n_norm, &amplitudes[shell_index]);
|
|
<span style="color: #a020f0;">if</span> (rc != TREXIO_SUCCESS)
|
|
<span style="color: #a020f0;">return</span> rc;
|
|
}
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c">/* <span style="color: #b22222;">Popcount and trailz</span> */
|
|
<span style="color: #483d8b;">#if</span> TREXIO_INT_SIZE == 64
|
|
|
|
<span style="color: #a020f0;">extern</span> <span style="color: #228b22;">int</span> <span style="color: #0000ff;">__builtin_popcountll</span> (<span style="color: #228b22;">unsigned</span> <span style="color: #228b22;">long</span> <span style="color: #228b22;">long</span> <span style="color: #a0522d;">x_0</span>);
|
|
<span style="color: #483d8b;"> #define</span> <span style="color: #0000ff;">popcnt</span>(<span style="color: #a0522d;">X</span>) __builtin_popcountll((<span style="color: #228b22;">unsigned</span> <span style="color: #228b22;">long</span> <span style="color: #228b22;">long</span>) X)
|
|
|
|
<span style="color: #a020f0;">extern</span> <span style="color: #228b22;">int</span> <span style="color: #0000ff;">__builtin_ctzll</span> (<span style="color: #228b22;">unsigned</span> <span style="color: #228b22;">long</span> <span style="color: #228b22;">long</span> <span style="color: #a0522d;">x_0</span>);
|
|
<span style="color: #483d8b;"> #define</span> <span style="color: #0000ff;">trailz</span>(<span style="color: #a0522d;">X</span>) __builtin_ctzll((<span style="color: #228b22;">unsigned</span> <span style="color: #228b22;">long</span> <span style="color: #228b22;">long</span>) X)
|
|
|
|
<span style="color: #483d8b;">#elif</span> TREXIO_INT_SIZE == 32
|
|
|
|
<span style="color: #a020f0;">extern</span> <span style="color: #228b22;">int</span> <span style="color: #0000ff;">__builtin_popcountl</span> (<span style="color: #228b22;">unsigned</span> <span style="color: #228b22;">long</span> <span style="color: #a0522d;">x_0</span>);
|
|
<span style="color: #483d8b;"> #define</span> <span style="color: #0000ff;">popcnt</span>(<span style="color: #a0522d;">X</span>) __builtin_popcountl((<span style="color: #228b22;">unsigned</span> <span style="color: #228b22;">long</span>) X)
|
|
|
|
<span style="color: #a020f0;">extern</span> <span style="color: #228b22;">int</span> <span style="color: #0000ff;">__builtin_ctzl</span>(<span style="color: #228b22;">unsigned</span> <span style="color: #228b22;">long</span> <span style="color: #a0522d;">x_0</span>);
|
|
<span style="color: #483d8b;"> #define</span> <span style="color: #0000ff;">trailz</span>(<span style="color: #a0522d;">X</span>) __builtin_ctzl((<span style="color: #228b22;">unsigned</span> <span style="color: #228b22;">long</span>) X)
|
|
|
|
<span style="color: #483d8b;">#elif</span> TREXIO_INT_SIZE == 16
|
|
|
|
<span style="color: #a020f0;">extern</span> <span style="color: #228b22;">int</span> <span style="color: #0000ff;">__builtin_popcount</span> (<span style="color: #228b22;">unsigned</span> <span style="color: #228b22;">int</span> <span style="color: #a0522d;">x_0</span>);
|
|
<span style="color: #483d8b;"> #define</span> <span style="color: #0000ff;">popcnt</span>(<span style="color: #a0522d;">X</span>) __builtin_popcount((<span style="color: #228b22;">unsigned</span> <span style="color: #228b22;">int</span>) X)
|
|
|
|
<span style="color: #a020f0;">extern</span> <span style="color: #228b22;">int</span> <span style="color: #0000ff;">__builtin_ctz</span> (<span style="color: #228b22;">unsigned</span> <span style="color: #228b22;">int</span> <span style="color: #a0522d;">x_0</span>);
|
|
<span style="color: #483d8b;"> #define</span> <span style="color: #0000ff;">trailz</span>(<span style="color: #a0522d;">X</span>) __builtin_ctz((<span style="color: #228b22;">unsigned</span> <span style="color: #228b22;">int</span>) X)
|
|
|
|
<span style="color: #483d8b;">#else</span>
|
|
|
|
<span style="color: #483d8b;"> #error</span>(<span style="color: #8b2252;">"Invalid TREXIO_INT_SIZE"</span>)
|
|
|
|
<span style="color: #483d8b;">#endif</span>
|
|
</pre>
|
|
</div>
|
|
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_info</span> (<span style="color: #228b22;">void</span>)
|
|
{
|
|
printf(<span style="color: #8b2252;">"TREXIO_PACKAGE_VERSION : %s\n"</span>, TREXIO_PACKAGE_VERSION);
|
|
|
|
<span style="color: #483d8b;">#ifdef</span> TREXIO_GIT_HASH
|
|
printf(<span style="color: #8b2252;">"TREXIO_GIT_HASH : %s\n"</span>, TREXIO_GIT_HASH);
|
|
<span style="color: #483d8b;">#else</span>
|
|
printf(<span style="color: #8b2252;">"GIT_HASH is stored in the config.h file, which is missing."</span>);
|
|
<span style="color: #483d8b;">#endif</span>
|
|
|
|
<span style="color: #483d8b;">#ifdef</span> HAVE_HDF5
|
|
printf(<span style="color: #8b2252;">"HAVE_HDF5 : true\n"</span>);
|
|
printf(<span style="color: #8b2252;">"%s\n"</span>, H5_VERS_INFO);
|
|
<span style="color: #483d8b;">#else</span>
|
|
printf(<span style="color: #8b2252;">"HAVE_HDF5 : false\n"</span>);
|
|
printf(<span style="color: #8b2252;">"TREXIO configured without the HDF5 library\n"</span>);
|
|
<span style="color: #483d8b;">#endif</span>
|
|
|
|
<span style="color: #a020f0;">return</span> TREXIO_SUCCESS;
|
|
}
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-c"><span style="color: #228b22;">trexio_exit_code</span>
|
|
<span style="color: #0000ff;">trexio_mark_safety</span> (<span style="color: #228b22;">trexio_t</span>* <span style="color: #a020f0;">const</span> <span style="color: #a0522d;">file</span>, <span style="color: #a020f0;">const</span> <span style="color: #228b22;">int32_t</span> <span style="color: #a0522d;">safety_flag</span>)
|
|
{
|
|
|
|
<span style="color: #a020f0;">if</span> (file == <span style="color: #008b8b;">NULL</span>) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_1;
|
|
/* <span style="color: #b22222;">1 for true ; 0 for false</span> */
|
|
<span style="color: #a020f0;">if</span> (safety_flag != 0 && safety_flag != 1) <span style="color: #a020f0;">return</span> TREXIO_INVALID_ARG_2;
|
|
/* <span style="color: #b22222;">Cannot mark the file in safe mode</span> */
|
|
<span style="color: #a020f0;">if</span> (file->mode != <span style="color: #8b2252;">'u'</span>) <span style="color: #a020f0;">return</span> TREXIO_FAILURE;
|
|
|
|
<span style="color: #a020f0;">return</span> trexio_write_metadata_unsafe(file, safety_flag);
|
|
}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orgfc8ba1e" class="outline-3">
|
|
<h3 id="orgfc8ba1e"><span class="section-number-3">5.2</span> Fortran</h3>
|
|
<div class="outline-text-3" id="text-5-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: #a020f0;">function</span> <span style="color: #0000ff;">trexio_info_c</span> () <span style="color: #a020f0;">bind</span>(C, name=<span style="color: #8b2252;">"trexio_info"</span>)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_info_c</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_to_bitfield_list_c</span>(list, occupied_num, det_list, N_int)<span style="color: #a0522d;"> </span><span style="color: #a020f0;">&</span>
|
|
<span style="color: #a020f0;">bind</span>(C, name=<span style="color: #8b2252;">"trexio_to_bitfield_list"</span>)
|
|
<span style="color: #a020f0;">import</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;"> list(*)</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;"> occupied_num</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(inout) ::<span style="color: #a0522d;"> det_list(*)</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;"> N_int</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_to_bitfield_list_c</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_to_orbital_list_c</span>(N_int, d1, list, occupied_num)<span style="color: #a0522d;"> </span><span style="color: #a020f0;">&</span>
|
|
<span style="color: #a020f0;">bind</span>(C, name=<span style="color: #8b2252;">"trexio_to_orbital_list"</span>)
|
|
<span style="color: #a020f0;">import</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;"> N_int</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;"> d1(*)</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(inout) ::<span style="color: #a0522d;"> list(*)</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(inout) ::<span style="color: #a0522d;"> occupied_num</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_to_orbital_list_c</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_to_orbital_list_up_dn_c</span>(N_int, d1, list_up, list_dn, occ_num_up, occ_num_dn)<span style="color: #a0522d;"> </span><span style="color: #a020f0;">&</span>
|
|
<span style="color: #a020f0;">bind</span>(C, name=<span style="color: #8b2252;">"trexio_to_orbital_list_up_dn"</span>)
|
|
<span style="color: #a020f0;">import</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;"> N_int</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;"> d1(*)</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(inout) ::<span style="color: #a0522d;"> list_up(*)</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(inout) ::<span style="color: #a0522d;"> list_dn(*)</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(inout) ::<span style="color: #a0522d;"> occ_num_up</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(inout) ::<span style="color: #a0522d;"> occ_num_dn</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_to_orbital_list_up_dn_c</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_convert_nao_radius_32</span>(r, grid_r, log_r_out)<span style="color: #a0522d;"> </span><span style="color: #a020f0;">&</span>
|
|
<span style="color: #a020f0;">bind</span>(C, name=<span style="color: #8b2252;">"trexio_convert_nao_radius_32"</span>)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_float</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> r</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_float</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> grid_r(*)</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_float</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> log_r_out</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_convert_nao_radius_32</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_convert_nao_radius_64</span>(r, grid_r, log_r_out)<span style="color: #a0522d;"> </span><span style="color: #a020f0;">&</span>
|
|
<span style="color: #a020f0;">bind</span>(C, name=<span style="color: #8b2252;">"trexio_convert_nao_radius_64"</span>)
|
|
<span style="color: #a020f0;">import</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> r</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> grid_r(*)</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> log_r_out</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_convert_nao_radius_64</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code)<span style="color: #a0522d;"> function trexio_evaluate_nao_radial (shell_index, r, </span><span style="color: #a020f0;">&</span>
|
|
grid_start, grid_size, grid_r, interpolator, normalization, amplitude) <span style="color: #a020f0;">&</span>
|
|
<span style="color: #a020f0;">bind</span>(C, name=<span style="color: #8b2252;">"trexio_evaluate_nao_radial"</span>)
|
|
<span style="color: #a020f0;">import</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;"> shell_index</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> r</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;"> grid_start(*)</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;"> grid_size(*)</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> grid_r(*)</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> interpolator(*)</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> normalization(*)</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> amplitude</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_evaluate_nao_radial</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">interface</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code)<span style="color: #a0522d;"> function trexio_evaluate_nao_radial_all (shell_num, </span><span style="color: #a020f0;">&</span>
|
|
nucleus_index, nucleus_coords, <span style="color: #a020f0;">&</span>
|
|
grid_start, grid_size, grid_r, interpolator, <span style="color: #a020f0;">&</span>
|
|
normalization, rx, ry, rz, amplitudes) <span style="color: #a020f0;">&</span>
|
|
<span style="color: #a020f0;">bind</span>(C, name=<span style="color: #8b2252;">"trexio_evaluate_nao_radial_all"</span>)
|
|
<span style="color: #a020f0;">import</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;"> 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;"> nucleus_index(*)</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> nucleus_coords(*)</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;"> grid_start(*)</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;"> grid_size(*)</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> grid_r(*)</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> interpolator(*)</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> normalization(*)</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> rx</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> ry</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> rz</span>
|
|
<span style="color: #228b22;">real</span>(<span style="color: #008b8b;">c_double</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> amplitudes(*)</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_evaluate_nao_radial_all</span>
|
|
<span style="color: #a020f0;">end interface</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orgeeeacd3" class="outline-3">
|
|
<h3 id="orgeeeacd3"><span class="section-number-3">5.3</span> Python</h3>
|
|
<div class="outline-text-3" id="text-5-3">
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">info</span>():
|
|
<span style="color: #8b2252;">"""Print the info about the installed TREXIO library."""</span>
|
|
|
|
<span style="color: #a0522d;">rc</span> = pytr.trexio_info()
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
</pre>
|
|
</div>
|
|
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">to_bitfield_list</span>(n_int: <span style="color: #483d8b;">int</span>, orbitals: <span style="color: #483d8b;">list</span>) -> <span style="color: #483d8b;">list</span>:
|
|
<span style="color: #8b2252;">"""Convert a list of occupied orbitals into a bitfield determinant.</span>
|
|
|
|
<span style="color: #8b2252;"> Input:</span>
|
|
<span style="color: #8b2252;"> ~orbitals~ - list of occupied orbital indices fields (integers)</span>
|
|
<span style="color: #8b2252;"> ~n_int~ - number of bitfields per determinant of a given spin</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> ~bitfield_list~: list</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
|
|
<span style="color: #a0522d;">rc</span>, <span style="color: #a0522d;">bitfield_list</span> = pytr.trexio_to_bitfield_list(orbitals, n_int)
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
<span style="color: #a020f0;">if</span> <span style="color: #483d8b;">len</span>(bitfield_list) != n_int:
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">Exception</span>(<span style="color: #8b2252;">"Inconsistent size of the bitfield_list."</span>)
|
|
|
|
<span style="color: #a020f0;">return</span> bitfield_list
|
|
</pre>
|
|
</div>
|
|
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">to_orbital_list</span>(n_int: <span style="color: #483d8b;">int</span>, determinant: <span style="color: #483d8b;">list</span>) -> <span style="color: #483d8b;">list</span>:
|
|
<span style="color: #8b2252;">"""Convert a given determinant into a list of occupied orbitals.</span>
|
|
|
|
<span style="color: #8b2252;"> Input:</span>
|
|
<span style="color: #8b2252;"> ~determinant~ - list of bit fields (integers)</span>
|
|
<span style="color: #8b2252;"> ~n_int~ - number of bit fields per determinant of a given spin</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> ~orbital_list~: list</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
# <span style="color: #b22222;">max possible size of the orbital list per spin component (upper limit on the number of MOs)</span>
|
|
<span style="color: #a0522d;">size_max</span> = n_int * 64
|
|
|
|
<span style="color: #a0522d;">rc</span>, <span style="color: #a0522d;">orbital_list</span>, <span style="color: #a0522d;">occ_num</span> = pytr.trexio_safe_to_orbital_list(n_int, determinant, size_max)
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
<span style="color: #a020f0;">if</span> <span style="color: #483d8b;">len</span>(orbital_list) < occ_num:
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">Exception</span>(<span style="color: #8b2252;">"Inconsistent size of the orbital_list."</span>)
|
|
|
|
<span style="color: #a020f0;">return</span> orbital_list[0:occ_num]
|
|
</pre>
|
|
</div>
|
|
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">to_orbital_list_up_dn</span>(n_int: <span style="color: #483d8b;">int</span>, determinant: <span style="color: #483d8b;">list</span>) -> <span style="color: #483d8b;">tuple</span>:
|
|
<span style="color: #8b2252;">"""Convert a given determinant into two lists of occupied orbitals.</span>
|
|
|
|
<span style="color: #8b2252;"> Input:</span>
|
|
<span style="color: #8b2252;"> ~determinant~ - list of bit fields (integers)</span>
|
|
<span style="color: #8b2252;"> ~n_int~ - number of bit fields per determinant of a given spin</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> result: tuple with the following items:</span>
|
|
<span style="color: #8b2252;"> ~orbital_list_up~: list of orbitals occupied by up-spin electrons</span>
|
|
<span style="color: #8b2252;"> ~orbital_list_dn~: list of orbitals occupied by down-spin electrons</span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
# <span style="color: #b22222;">max possible size of the orbital list per spin component (upper limit on the number of MOs)</span>
|
|
<span style="color: #a0522d;">size_max</span> = n_int * 64
|
|
|
|
<span style="color: #a0522d;">rc</span>, <span style="color: #a0522d;">orbital_list_up</span>, <span style="color: #a0522d;">orbital_list_dn</span>, <span style="color: #a0522d;">occ_num_up</span>, <span style="color: #a0522d;">occ_num_dn</span> = pytr.trexio_safe_to_orbital_list_up_dn(n_int, determinant, size_max, size_max)
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
<span style="color: #a020f0;">if</span> <span style="color: #483d8b;">len</span>(orbital_list_up) < occ_num_up:
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">Exception</span>(<span style="color: #8b2252;">"Inconsistent size of the orbital_list for up-spin electrons."</span>)
|
|
<span style="color: #a020f0;">if</span> <span style="color: #483d8b;">len</span>(orbital_list_dn) < occ_num_dn:
|
|
<span style="color: #a020f0;">raise</span> <span style="color: #228b22;">Exception</span>(<span style="color: #8b2252;">"Inconsistent size of the orbital_list for down-spin electrons."</span>)
|
|
|
|
<span style="color: #a020f0;">return</span> (orbital_list_up[0:occ_num_up], orbital_list_dn[0:occ_num_dn])
|
|
</pre>
|
|
</div>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-python"><span style="color: #a020f0;">def</span> <span style="color: #0000ff;">convert_nao_radius</span>(r: <span style="color: #483d8b;">float</span>, grid_r) -> <span style="color: #483d8b;">float</span>:
|
|
<span style="color: #8b2252;">"""Converts the radius r as a distance from a nucleus to the shell</span>
|
|
<span style="color: #8b2252;"> s logarithmic grid.</span>
|
|
|
|
<span style="color: #8b2252;"> Input:</span>
|
|
<span style="color: #8b2252;"> ~r~ - the radius to be converted</span>
|
|
<span style="color: #8b2252;"> ~grid_r~ - The radial grid of the shell. Note that this is only the</span>
|
|
<span style="color: #8b2252;"> grid of the shell of interest, not the array of all shells.</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> Float that gives the radius in the shell's logarithmic units </span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Exception from some other error (e.g. RuntimeError).</span>
|
|
|
|
<span style="color: #8b2252;"> """</span>
|
|
|
|
<span style="color: #a0522d;">rc</span>, <span style="color: #a0522d;">r_log</span> = pytr.trexio_convert_nao_radius_py(r, grid_r)
|
|
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
|
|
<span style="color: #a020f0;">return</span> r_log
|
|
|
|
<span style="color: #a020f0;">def</span> <span style="color: #0000ff;">evaluate_nao_radial</span>(shell_index, r, grid_start, grid_size, grid_r, interpolator, normalization) -> <span style="color: #483d8b;">float</span>:
|
|
<span style="color: #8b2252;">"""Evaluates the radial function of a given NAO shell at a distance from its center.</span>
|
|
|
|
<span style="color: #8b2252;"> Input:</span>
|
|
<span style="color: #8b2252;"> ~shell_index~ - index of the shell of interest</span>
|
|
<span style="color: #8b2252;"> ~r~ - distance from the shell center</span>
|
|
<span style="color: #8b2252;"> ~grid_start~ - array of starting points of the individual splines</span>
|
|
<span style="color: #8b2252;"> ~grid_size~ - array of number of data points per spline</span>
|
|
<span style="color: #8b2252;"> ~grid_r~ - The radial grid of the shell. Note that this is only the</span>
|
|
<span style="color: #8b2252;"> grid of the shell of interest, not the array of all shells.</span>
|
|
<span style="color: #8b2252;"> ~interpolator~ - Interpolator of the spline. It is assumed to contain a cubic spline.</span>
|
|
<span style="color: #8b2252;"> An interpolator for a kinetic energy spline can also be passed.</span>
|
|
<span style="color: #8b2252;"> ~normalization~ - array of radial function normalization constants.</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> Value of the spline at the given radius </span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - Error from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Error from some other error (e.g. RuntimeError).</span>
|
|
|
|
<span style="color: #8b2252;"> """</span>
|
|
<span style="color: #a0522d;">rc</span>, <span style="color: #a0522d;">amplitude</span> = pytr.trexio_evaluate_nao_radial_py(shell_index, r, grid_start, grid_size, grid_r, interpolator.flatten(), normalization)
|
|
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
|
|
<span style="color: #a020f0;">return</span> amplitude
|
|
|
|
<span style="color: #a020f0;">def</span> <span style="color: #0000ff;">evaluate_nao_radial_all</span>(nucleus_index, nucleus_coords, grid_start,
|
|
grid_size, grid_r, interpolator, normalization, r) -> <span style="color: #483d8b;">float</span>:
|
|
<span style="color: #8b2252;">"""Evaluates the radial functions of all NAO shells at a given position in space.</span>
|
|
|
|
<span style="color: #8b2252;"> Input:</span>
|
|
<span style="color: #8b2252;"> ~nucleus_index~ - array giving the centers of the NAO</span>
|
|
<span style="color: #8b2252;"> ~nucleus_coords~ - array giving the coordinates of the NAO centers</span>
|
|
<span style="color: #8b2252;"> ~grid_start~ - array of starting points of the individual splines</span>
|
|
<span style="color: #8b2252;"> ~grid_size~ - array of number of data points per spline</span>
|
|
<span style="color: #8b2252;"> ~grid_r~ - The radial grid of the shell. Note that this is only the</span>
|
|
<span style="color: #8b2252;"> grid of the shell of interest, not the array of all shells.</span>
|
|
<span style="color: #8b2252;"> ~interpolator~ - Interpolator of the spline. It is assumed to contain a cubic spline.</span>
|
|
<span style="color: #8b2252;"> An interpolator for a kinetic energy spline can also be passed.</span>
|
|
<span style="color: #8b2252;"> ~normalization~ - array of radial function normalization constants.</span>
|
|
<span style="color: #8b2252;"> ~r~ - the position in space at which the functions are evaluated</span>
|
|
|
|
<span style="color: #8b2252;"> Returns:</span>
|
|
<span style="color: #8b2252;"> Array of spline values at ~r~ </span>
|
|
|
|
<span style="color: #8b2252;"> Raises:</span>
|
|
<span style="color: #8b2252;"> - Error if ~r~ is not three dimensional</span>
|
|
<span style="color: #8b2252;"> - Error from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.</span>
|
|
<span style="color: #8b2252;"> - Error from some other error (e.g. RuntimeError).</span>
|
|
|
|
<span style="color: #8b2252;"> """</span>
|
|
<span style="color: #a020f0;">if</span> <span style="color: #483d8b;">len</span>(r) != 3:
|
|
<span style="color: #a020f0;">raise</span> Error(TREXIO_INVALID_ARG7)
|
|
<span style="color: #a0522d;">shell_cnt</span> = <span style="color: #483d8b;">len</span>(nucleus_index)
|
|
<span style="color: #a0522d;">rc</span>, <span style="color: #a0522d;">amplitudes</span> = pytr.trexio_evaluate_nao_radial_all_py(shell_cnt, \
|
|
nucleus_index, nucleus_coords.flatten(), grid_start, grid_size, grid_r, \
|
|
interpolator.flatten(), normalization, r[0], r[1], r[2], shell_cnt)
|
|
|
|
<span style="color: #a020f0;">if</span> rc != TREXIO_SUCCESS:
|
|
<span style="color: #a020f0;">raise</span> Error(rc)
|
|
|
|
<span style="color: #a020f0;">return</span> amplitudes
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="outline-container-orge3876be" class="outline-2">
|
|
<h2 id="orge3876be"><span class="section-number-2">6</span> Fortran helper/wrapper functions</h2>
|
|
<div class="outline-text-2" id="text-6">
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">contains</span>
|
|
<span style="color: #228b22;">integer </span><span style="color: #a020f0;">function</span><span style="color: #a0522d;"> </span><span style="color: #0000ff;">trexio_info</span><span style="color: #a0522d;"> </span><span style="color: #000000; background-color: #ffffff;">()</span>
|
|
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span>
|
|
trexio_info = trexio_info_c()
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_info</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<p>
|
|
The function below adapts the original C-based <code>trexio_open</code> for Fortran.
|
|
This is needed due to the fact that strings in C are terminated by <code>NULL</code> character <code>\0</code>
|
|
unlike strings in Fortran.
|
|
Note, that Fortran interface calls the main <code>TREXIO</code> API, which is written in C.
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #228b22;">integer</span>(trexio_t) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_open</span> (filename, mode, back_end, rc_open)
|
|
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span>
|
|
<span style="color: #228b22;">character</span>(len=*), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> filename</span>
|
|
<span style="color: #228b22;">character</span>, <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> mode</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_back_end_t), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> back_end</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> rc_open</span>
|
|
<span style="color: #228b22;">character</span>(len=<span style="color: #a020f0;">len_trim</span>(filename)+1) ::<span style="color: #a0522d;"> filename_c</span>
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) ::<span style="color: #a0522d;"> rc</span>
|
|
|
|
filename_c = <span style="color: #a020f0;">trim</span>(filename) // <span style="color: #008b8b;">c_null_char</span>
|
|
trexio_open = trexio_open_c(filename_c, mode, back_end, rc_open)
|
|
<span style="color: #a020f0;">if</span> (trexio_open == 0_8 <span style="color: #a020f0;">.or.</span> rc_open /= TREXIO_SUCCESS) <span style="color: #a020f0;">then</span>
|
|
<span style="color: #a020f0;">return</span>
|
|
<span style="color: #a020f0;">endif</span>
|
|
rc = trexio_set_one_based(trexio_open)
|
|
<span style="color: #a020f0;">if</span> (rc /= TREXIO_SUCCESS) <span style="color: #a020f0;">then</span>
|
|
rc = trexio_close(trexio_open)
|
|
trexio_open = 0_8
|
|
<span style="color: #a020f0;">endif</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_open</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<p>
|
|
The function below adapts the original C-based <code>trexio_inquire</code> for Fortran.
|
|
This is needed due to the same reasons as for <code>trexio_open</code> function.
|
|
Note, that Fortran interface calls the main <code>TREXIO</code> API, which is written in C.
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_inquire</span> (filename)
|
|
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span>
|
|
<span style="color: #228b22;">character</span>(len=*), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> filename</span>
|
|
<span style="color: #228b22;">character</span>(len=<span style="color: #a020f0;">len_trim</span>(filename)+1) ::<span style="color: #a0522d;"> filename_c</span>
|
|
|
|
filename_c = <span style="color: #a020f0;">trim</span>(filename) // <span style="color: #008b8b;">c_null_char</span>
|
|
trexio_inquire = trexio_inquire_c(filename_c)
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_inquire</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<p>
|
|
Similarly, the following function adapts <code>trexio_cp</code>.
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_cp</span> (source, destination)
|
|
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span>
|
|
<span style="color: #228b22;">character</span>(len=*), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> source</span>
|
|
<span style="color: #228b22;">character</span>(len=*), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> destination</span>
|
|
<span style="color: #228b22;">character</span>(len=<span style="color: #a020f0;">len_trim</span>(source)+1) ::<span style="color: #a0522d;"> source_c</span>
|
|
<span style="color: #228b22;">character</span>(len=<span style="color: #a020f0;">len_trim</span>(destination)+1) ::<span style="color: #a0522d;"> destination_c</span>
|
|
|
|
source_c = <span style="color: #a020f0;">trim</span>(source) // <span style="color: #008b8b;">c_null_char</span>
|
|
destination_c = <span style="color: #a020f0;">trim</span>(destination) // <span style="color: #008b8b;">c_null_char</span>
|
|
trexio_cp = trexio_cp_c(source_c, destination_c)
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_cp</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<p>
|
|
The subroutines below wrap the <code>to_orbital_list</code> functions to shift the MO indices
|
|
by 1 since in Fortran arrays are 1-based and C/Python they are 0-based.
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_to_bitfield_list</span>(list, occupied_num, det_list, N_int)
|
|
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</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;"> list(*)</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;"> occupied_num</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int64_t</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> det_list(*)</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;"> N_int</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int32_t</span>) ::<span style="color: #a0522d;"> list_0based(occupied_num)</span>
|
|
|
|
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> i</span>
|
|
<span style="color: #a020f0;">do</span> i = 1,occupied_num
|
|
list_0based(i) = list(i) - 1
|
|
<span style="color: #a020f0;">enddo</span>
|
|
|
|
trexio_to_bitfield_list = trexio_to_bitfield_list_c(list_0based, occupied_num, det_list, N_int)
|
|
<span style="color: #a020f0;">if</span> (trexio_to_bitfield_list /= TREXIO_SUCCESS) <span style="color: #a020f0;">then</span>
|
|
<span style="color: #a020f0;">return</span>
|
|
<span style="color: #a020f0;">endif</span>
|
|
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_to_bitfield_list</span>
|
|
|
|
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_to_orbital_list</span>(N_int, d1, list, occupied_num)
|
|
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</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;"> N_int</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;"> d1(*)</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> list(*)</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> occupied_num</span>
|
|
|
|
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> i</span>
|
|
|
|
trexio_to_orbital_list = trexio_to_orbital_list_c(N_int, d1, list, occupied_num)
|
|
<span style="color: #a020f0;">if</span> (trexio_to_orbital_list /= TREXIO_SUCCESS) <span style="color: #a020f0;">then</span>
|
|
<span style="color: #a020f0;">return</span>
|
|
<span style="color: #a020f0;">endif</span>
|
|
|
|
<span style="color: #a020f0;">do</span> i = 1,occupied_num
|
|
list(i) = list(i) + 1
|
|
<span style="color: #a020f0;">enddo</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_to_orbital_list</span>
|
|
|
|
|
|
<span style="color: #228b22;">integer</span>(trexio_exit_code) <span style="color: #a020f0;">function</span> <span style="color: #0000ff;">trexio_to_orbital_list_up_dn</span>(N_int, d1, list_up, list_dn, occ_num_up, occ_num_dn)
|
|
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</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;"> N_int</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;"> d1(*)</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> list_up(*)</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> list_dn(*)</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> occ_num_up</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int32_t</span>), <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> occ_num_dn</span>
|
|
|
|
<span style="color: #228b22;">integer</span> ::<span style="color: #a0522d;"> i</span>
|
|
|
|
trexio_to_orbital_list_up_dn = trexio_to_orbital_list_up_dn_c(N_int, d1, list_up, list_dn, occ_num_up, occ_num_dn)
|
|
<span style="color: #a020f0;">if</span> (trexio_to_orbital_list_up_dn /= TREXIO_SUCCESS) <span style="color: #a020f0;">then</span>
|
|
<span style="color: #a020f0;">return</span>
|
|
<span style="color: #a020f0;">endif</span>
|
|
|
|
<span style="color: #a020f0;">do</span> i = 1,occ_num_up
|
|
list_up(i) = list_up(i) + 1
|
|
<span style="color: #a020f0;">enddo</span>
|
|
<span style="color: #a020f0;">do</span> i = 1,occ_num_dn
|
|
list_dn(i) = list_dn(i) + 1
|
|
<span style="color: #a020f0;">enddo</span>
|
|
<span style="color: #a020f0;">end function</span> <span style="color: #0000ff;">trexio_to_orbital_list_up_dn</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<p>
|
|
The subroutine below transforms an array of Fortran strings into one big string using <code>TREXIO_DELIM</code> symbol
|
|
as a delimeter and adds <code>NULL</code> character in the end in order to properly pass the desired string to
|
|
C API. This is needed due to the fact that strings in C are terminated by <code>NULL</code> character <code>\0</code>.
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">subroutine</span> <span style="color: #0000ff;">trexio_strarray2str</span>(str_array, max_num_str, str_res)
|
|
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</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;"> max_num_str </span>! <span style="color: #b22222;">number of elements in string array</span>
|
|
<span style="color: #228b22;">character</span>(len=*), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> str_array(*)</span>
|
|
<span style="color: #228b22;">character</span>(len=:), <span style="color: #a020f0;">allocatable</span>, <span style="color: #a020f0;">intent</span>(out) ::<span style="color: #a0522d;"> str_res</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int64_t</span>) ::<span style="color: #a0522d;"> i</span>
|
|
|
|
str_res = <span style="color: #8b2252;">''</span>
|
|
<span style="color: #a020f0;">do</span> i = 1, max_num_str
|
|
str_res = str_res // <span style="color: #a020f0;">trim</span>(str_array(i)) // TREXIO_DELIM
|
|
<span style="color: #a020f0;">enddo</span>
|
|
str_res = str_res // <span style="color: #008b8b;">c_null_char</span>
|
|
|
|
<span style="color: #a020f0;">end subroutine</span> <span style="color: #0000ff;">trexio_strarray2str</span>
|
|
</pre>
|
|
</div>
|
|
|
|
<p>
|
|
The subroutine below does the reverse tranformation from one big string with delimeters into an array of Fortran strings.
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">subroutine</span> <span style="color: #0000ff;">trexio_str2strarray</span>(str_flat, max_num_str, max_len_str, str_array)
|
|
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</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;"> max_num_str </span>! <span style="color: #b22222;">number of elements in strign array</span>
|
|
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> max_len_str </span>! <span style="color: #b22222;">maximum length of a string in an array</span>
|
|
<span style="color: #228b22;">character</span>(kind=<span style="color: #008b8b;">c_char</span>), <span style="color: #a020f0;">intent</span>(in) ::<span style="color: #a0522d;"> str_flat(*)</span>
|
|
<span style="color: #228b22;">character</span>(len=*), <span style="color: #a020f0;">intent</span>(inout) ::<span style="color: #a0522d;"> str_array(*)</span>
|
|
|
|
<span style="color: #228b22;">character</span>(len=max_len_str) ::<span style="color: #a0522d;"> tmp_str</span>
|
|
<span style="color: #228b22;">integer</span>(<span style="color: #008b8b;">c_int64_t</span>) ::<span style="color: #a0522d;"> i, j, k, ind, len_flat</span>
|
|
|
|
len_flat = (max_len_str+1)*max_num_str + 1
|
|
|
|
ind=1
|
|
<span style="color: #a020f0;">do</span> i=1,max_num_str
|
|
k = 1
|
|
tmp_str=<span style="color: #8b2252;">''</span>
|
|
<span style="color: #a020f0;">do</span> j=ind,len_flat
|
|
<span style="color: #a020f0;">if</span> (str_flat(j) == TREXIO_DELIM) <span style="color: #a020f0;">then</span>
|
|
ind=j+1
|
|
<span style="color: #a020f0;">exit</span>
|
|
<span style="color: #a020f0;">endif</span>
|
|
tmp_str(k:k) = str_flat(j)
|
|
k = k + 1
|
|
<span style="color: #a020f0;">enddo</span>
|
|
str_array(i)=tmp_str
|
|
<span style="color: #a020f0;">enddo</span>
|
|
|
|
<span style="color: #a020f0;">end subroutine</span> <span style="color: #0000ff;">trexio_str2strarray</span>
|
|
</pre>
|
|
</div>
|
|
|
|
|
|
<p>
|
|
The subroutine is a Fortran analogue of <code>assert</code> in C. It check that the the return code of the
|
|
TREXIO API call is equal to a given return code. It can optionally print a success message if the
|
|
two code are identical, i.e. if the <code>assert</code> statement pass.
|
|
</p>
|
|
|
|
<div class="org-src-container">
|
|
<pre class="src src-f90"><span style="color: #a020f0;">subroutine</span> <span style="color: #0000ff;">trexio_assert</span>(trexio_rc, check_rc, success_message)
|
|
<span style="color: #a020f0;">implicit</span> <span style="color: #228b22;">none</span>
|
|
|
|
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> trexio_rc</span>
|
|
<span style="color: #228b22;">integer</span>, <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">value</span> ::<span style="color: #a0522d;"> check_rc</span>
|
|
<span style="color: #228b22;">character</span>(len=*), <span style="color: #a020f0;">intent</span>(in), <span style="color: #a020f0;">optional</span> ::<span style="color: #a0522d;"> success_message</span>
|
|
|
|
<span style="color: #228b22;">character</span>*(128) ::<span style="color: #a0522d;"> str</span>
|
|
|
|
<span style="color: #a020f0;">if</span> (trexio_rc == check_rc) <span style="color: #a020f0;">then</span>
|
|
<span style="color: #a020f0;">if</span> (<span style="color: #a020f0;">present</span>(success_message)) <span style="color: #a020f0;">write</span>(*,*) success_message
|
|
<span style="color: #a020f0;">else</span>
|
|
<span style="color: #a020f0;">call</span> <span style="color: #0000ff;">trexio_string_of_error</span>(trexio_rc, str)
|
|
<span style="color: #a020f0;">print</span> *, <span style="color: #a020f0;">trim</span>(str)
|
|
<span style="color: #a020f0;">stop</span> 1
|
|
<span style="color: #a020f0;">endif</span>
|
|
|
|
<span style="color: #a020f0;">end subroutine</span> <span style="color: #0000ff;">trexio_assert</span>
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div id="postamble" class="status">
|
|
<p class="author">Author: TREX-CoE</p>
|
|
<p class="date">Created: 2024-05-23 Thu 15:59</p>
|
|
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
|
</div>
|
|
</body>
|
|
</html>
|