2021-04-12 14:32:08 +02:00
<?xml version="1.0" encoding="utf-8"?>
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
< html xmlns = "http://www.w3.org/1999/xhtml" lang = "en" xml:lang = "en" >
< head >
2021-09-16 16:47:50 +02:00
<!-- 2021 - 09 - 16 Thu 14:47 -->
2021-04-12 14:32:08 +02:00
< meta http-equiv = "Content-Type" content = "text/html;charset=utf-8" / >
< meta name = "viewport" content = "width=device-width, initial-scale=1" / >
2021-05-07 00:03:17 +02:00
< title > Front end API< / title >
2021-04-12 14:32:08 +02:00
< meta name = "generator" content = "Org mode" / >
< meta name = "author" content = "TREX-CoE" / >
< style type = "text/css" >
<!-- /* --> <![CDATA[/*> <!-- */
.title { text-align: center;
margin-bottom: .2em; }
.subtitle { text-align: center;
font-size: medium;
font-weight: bold;
margin-top:0; }
.todo { font-family: monospace; color: red; }
.done { font-family: monospace; color: green; }
.priority { font-family: monospace; color: orange; }
.tag { background-color: #eee; font-family: monospace;
padding: 2px; font-size: 80%; font-weight: normal; }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
.org-right { margin-left: auto; margin-right: 0px; text-align: right; }
.org-left { margin-left: 0px; margin-right: auto; text-align: left; }
.org-center { margin-left: auto; margin-right: auto; text-align: center; }
.underline { text-decoration: underline; }
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
p.verse { margin-left: 3%; }
pre {
border: 1px solid #ccc;
box-shadow: 3px 3px 3px #eee;
padding: 8pt;
font-family: monospace;
overflow: auto;
margin: 1.2em;
}
pre.src {
position: relative;
overflow: visible;
padding-top: 1.2em;
}
pre.src:before {
display: none;
position: absolute;
background-color: white;
top: -10px;
right: 10px;
padding: 3px;
border: 1px solid black;
}
pre.src:hover:before { display: inline;}
/* Languages per Org manual */
pre.src-asymptote:before { content: 'Asymptote'; }
pre.src-awk:before { content: 'Awk'; }
pre.src-C:before { content: 'C'; }
/* pre.src-C++ doesn't work in CSS */
pre.src-clojure:before { content: 'Clojure'; }
pre.src-css:before { content: 'CSS'; }
pre.src-D:before { content: 'D'; }
pre.src-ditaa:before { content: 'ditaa'; }
pre.src-dot:before { content: 'Graphviz'; }
pre.src-calc:before { content: 'Emacs Calc'; }
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
pre.src-fortran:before { content: 'Fortran'; }
pre.src-gnuplot:before { content: 'gnuplot'; }
pre.src-haskell:before { content: 'Haskell'; }
pre.src-hledger:before { content: 'hledger'; }
pre.src-java:before { content: 'Java'; }
pre.src-js:before { content: 'Javascript'; }
pre.src-latex:before { content: 'LaTeX'; }
pre.src-ledger:before { content: 'Ledger'; }
pre.src-lisp:before { content: 'Lisp'; }
pre.src-lilypond:before { content: 'Lilypond'; }
pre.src-lua:before { content: 'Lua'; }
pre.src-matlab:before { content: 'MATLAB'; }
pre.src-mscgen:before { content: 'Mscgen'; }
pre.src-ocaml:before { content: 'Objective Caml'; }
pre.src-octave:before { content: 'Octave'; }
pre.src-org:before { content: 'Org mode'; }
pre.src-oz:before { content: 'OZ'; }
pre.src-plantuml:before { content: 'Plantuml'; }
pre.src-processing:before { content: 'Processing.js'; }
pre.src-python:before { content: 'Python'; }
pre.src-R:before { content: 'R'; }
pre.src-ruby:before { content: 'Ruby'; }
pre.src-sass:before { content: 'Sass'; }
pre.src-scheme:before { content: 'Scheme'; }
pre.src-screen:before { content: 'Gnu Screen'; }
pre.src-sed:before { content: 'Sed'; }
pre.src-sh:before { content: 'shell'; }
pre.src-sql:before { content: 'SQL'; }
pre.src-sqlite:before { content: 'SQLite'; }
/* additional languages in org.el's org-babel-load-languages alist */
pre.src-forth:before { content: 'Forth'; }
pre.src-io:before { content: 'IO'; }
pre.src-J:before { content: 'J'; }
pre.src-makefile:before { content: 'Makefile'; }
pre.src-maxima:before { content: 'Maxima'; }
pre.src-perl:before { content: 'Perl'; }
pre.src-picolisp:before { content: 'Pico Lisp'; }
pre.src-scala:before { content: 'Scala'; }
pre.src-shell:before { content: 'Shell Script'; }
pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
/* additional language identifiers per "defun org-babel-execute"
in ob-*.el */
pre.src-cpp:before { content: 'C++'; }
pre.src-abc:before { content: 'ABC'; }
pre.src-coq:before { content: 'Coq'; }
pre.src-groovy:before { content: 'Groovy'; }
/* additional language identifiers from org-babel-shell-names in
ob-shell.el: ob-shell is the only babel language using a lambda to put
the execution function name together. */
pre.src-bash:before { content: 'bash'; }
pre.src-csh:before { content: 'csh'; }
pre.src-ash:before { content: 'ash'; }
pre.src-dash:before { content: 'dash'; }
pre.src-ksh:before { content: 'ksh'; }
pre.src-mksh:before { content: 'mksh'; }
pre.src-posh:before { content: 'posh'; }
/* Additional Emacs modes also supported by the LaTeX listings package */
pre.src-ada:before { content: 'Ada'; }
pre.src-asm:before { content: 'Assembler'; }
pre.src-caml:before { content: 'Caml'; }
pre.src-delphi:before { content: 'Delphi'; }
pre.src-html:before { content: 'HTML'; }
pre.src-idl:before { content: 'IDL'; }
pre.src-mercury:before { content: 'Mercury'; }
pre.src-metapost:before { content: 'MetaPost'; }
pre.src-modula-2:before { content: 'Modula-2'; }
pre.src-pascal:before { content: 'Pascal'; }
pre.src-ps:before { content: 'PostScript'; }
pre.src-prolog:before { content: 'Prolog'; }
pre.src-simula:before { content: 'Simula'; }
pre.src-tcl:before { content: 'tcl'; }
pre.src-tex:before { content: 'TeX'; }
pre.src-plain-tex:before { content: 'Plain TeX'; }
pre.src-verilog:before { content: 'Verilog'; }
pre.src-vhdl:before { content: 'VHDL'; }
pre.src-xml:before { content: 'XML'; }
pre.src-nxml:before { content: 'XML'; }
/* add a generic configuration mode; LaTeX export needs an additional
(add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
pre.src-conf:before { content: 'Configuration File'; }
table { border-collapse:collapse; }
caption.t-above { caption-side: top; }
caption.t-bottom { caption-side: bottom; }
td, th { vertical-align:top; }
th.org-right { text-align: center; }
th.org-left { text-align: center; }
th.org-center { text-align: center; }
td.org-right { text-align: right; }
td.org-left { text-align: left; }
td.org-center { text-align: center; }
dt { font-weight: bold; }
.footpara { display: inline; }
.footdef { margin-bottom: 1em; }
.figure { padding: 1em; }
.figure p { text-align: center; }
.inlinetask {
padding: 10px;
border: 2px solid gray;
margin: 10px;
background: #ffffcc;
}
#org-div-home-and-up
{ text-align: right; font-size: 70%; white-space: nowrap; }
textarea { overflow-x: auto; }
.linenr { font-size: smaller }
.code-highlighted { background-color: #ffff00; }
.org-info-js_info-navigation { border-style: none; }
#org-info-js_console-label
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
.org-info-js_search-highlight
{ background-color: #ffff00; color: #000000; font-weight: bold; }
.org-svg { width: 90%; }
/*]]>*/-->
< / style >
< link rel = "stylesheet" title = "Standard" href = "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-2019 Free Software Foundation, Inc.
*
*
* The JavaScript code in this tag is free software: you can
* redistribute it and/or modify it under the terms of the GNU
* General Public License (GNU GPL) as published by the Free Software
* Foundation, either version 3 of the License, or (at your option)
* any later version. The code is distributed WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
*
* As additional permission under GNU GPL version 3 section 7, you
* may distribute non-source (e.g., minimized or compacted) forms of
* that code without the copy of the GNU GPL normally required by
* section 4, provided you include this license notice and a URL
* through which recipients can access the Corresponding Source.
*
* @licend The above is the entire license notice
* for the JavaScript code in org-info.js.
*
*/
< / script >
< script type = "text/javascript" >
/*
@licstart The following is the entire license notice for the
JavaScript code in this tag.
Copyright (C) 2012-2019 Free Software Foundation, Inc.
The JavaScript code in this tag is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
@licend The above is the entire license notice
for the JavaScript code in this tag.
*/
<!-- /* --> <![CDATA[/*> <!-- */
org_html_manager.set("TOC_DEPTH", "4");
org_html_manager.set("LINK_HOME", "index.html");
org_html_manager.set("LINK_UP", "");
org_html_manager.set("LOCAL_TOC", "1");
org_html_manager.set("VIEW_BUTTONS", "0");
org_html_manager.set("MOUSE_HINT", "underline");
org_html_manager.set("FIXED_TOC", "0");
org_html_manager.set("TOC", "1");
org_html_manager.set("VIEW", "info");
org_html_manager.setup(); // activate after the parameters are set
/*]]>*///-->
< / script >
< script type = "text/javascript" >
/*
@licstart The following is the entire license notice for the
JavaScript code in this tag.
Copyright (C) 2012-2019 Free Software Foundation, Inc.
The JavaScript code in this tag is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
@licend The above is the entire license notice
for the JavaScript code in this tag.
*/
<!-- /* --> <![CDATA[/*> <!-- */
function CodeHighlightOn(elem, id)
{
var target = document.getElementById(id);
if(null != target) {
elem.cacheClassElem = elem.className;
elem.cacheClassTarget = target.className;
target.className = "code-highlighted";
elem.className = "code-highlighted";
}
}
function CodeHighlightOff(elem, id)
{
var target = document.getElementById(id);
if(elem.cacheClassElem)
elem.className = elem.cacheClassElem;
if(elem.cacheClassTarget)
target.className = elem.cacheClassTarget;
}
/*]]>*///-->
< / script >
2021-06-04 14:15:51 +02:00
< 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 >
2021-04-12 14:32:08 +02:00
< / 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" >
2021-05-07 00:03:17 +02:00
< h1 class = "title" > Front end API< / h1 >
2021-04-12 14:32:08 +02:00
< div id = "table-of-contents" >
< h2 > Table of Contents< / h2 >
< div id = "text-table-of-contents" >
< ul >
2021-09-16 16:47:50 +02:00
< li > < a href = "#orgac91e51" > 1. Coding conventions< / a >
2021-04-12 14:32:08 +02:00
< ul >
2021-09-16 16:47:50 +02:00
< li > < a href = "#org7303f5d" > 1.1. Memory allocation< / a > < / li >
2021-04-12 14:32:08 +02:00
< / ul >
< / li >
2021-09-16 16:47:50 +02:00
< li > < a href = "#org0ed731c" > 2. Front end< / a >
2021-04-12 14:32:08 +02:00
< ul >
2021-09-16 16:47:50 +02:00
< li > < a href = "#orgad4bf32" > 2.1. Error handling< / a >
2021-09-14 11:40:10 +02:00
< ul >
2021-09-16 16:47:50 +02:00
< li > < a href = "#org0c590e0" > 2.1.1. Decoding errors< / a >
2021-09-14 11:40:10 +02:00
< ul >
2021-09-16 16:47:50 +02:00
< li > < a href = "#orgfb3cc49" > 2.1.1.1. C source code< / a > < / li >
< li > < a href = "#org9a5bddc" > 2.1.1.2. Fortran interface< / a > < / li >
< li > < a href = "#orgb5b685d" > 2.1.1.3. Python interface< / a > < / li >
2021-09-14 11:40:10 +02:00
< / ul >
< / li >
< / ul >
< / li >
2021-09-16 16:47:50 +02:00
< li > < a href = "#org010ba58" > 2.2. Back ends< / a >
2021-09-14 11:40:10 +02:00
< ul >
2021-09-16 16:47:50 +02:00
< li > < a href = "#orgceba57c" > 2.2.1. C< / a > < / li >
< li > < a href = "#org6672d17" > 2.2.2. Fortran< / a > < / li >
< li > < a href = "#org040bab1" > 2.2.3. Python< / a > < / li >
2021-09-14 11:40:10 +02:00
< / ul >
< / li >
2021-09-16 16:47:50 +02:00
< li > < a href = "#orgf8ad563" > 2.3. Read/write behavior< / a > < / li >
< li > < a href = "#org940788e" > 2.4. TREXIO file type< / a >
2021-09-14 11:40:10 +02:00
< ul >
2021-09-16 16:47:50 +02:00
< li > < a href = "#orga619b31" > 2.4.1. TREXIO< sub > File< / sub > Python class< / a > < / li >
2021-09-14 11:40:10 +02:00
< / ul >
< / li >
2021-09-16 16:47:50 +02:00
< li > < a href = "#orga7947c3" > 2.5. Polymorphism of the file handle< / a > < / li >
< li > < a href = "#org95af478" > 2.6. File opening< / a >
2021-09-14 11:40:10 +02:00
< ul >
2021-09-16 16:47:50 +02:00
< li > < a href = "#org69ff763" > 2.6.1. C< / a > < / li >
< li > < a href = "#orgb66bef1" > 2.6.2. Fortran< / a > < / li >
< li > < a href = "#orgdac714f" > 2.6.3. Python< / a > < / li >
< li > < a href = "#org723d54b" > 2.6.4. Zero-based versus one-based arrays of indices< / a > < / li >
2021-04-12 14:32:08 +02:00
< / ul >
< / li >
2021-09-16 16:47:50 +02:00
< li > < a href = "#org2c095ce" > 2.7. File closing< / a >
2021-04-12 14:32:08 +02:00
< ul >
2021-09-16 16:47:50 +02:00
< li > < a href = "#orga522a7a" > 2.7.1. C< / a > < / li >
< li > < a href = "#org8df0c7d" > 2.7.2. Fortran< / a > < / li >
< li > < a href = "#orge504b2b" > 2.7.3. Python< / a > < / li >
2021-09-14 11:40:10 +02:00
< / ul >
< / li >
< / ul >
< / li >
2021-09-16 16:47:50 +02:00
< li > < a href = "#orgdaf108d" > 3. Templates for front end< / a >
2021-04-12 14:32:08 +02:00
< ul >
2021-09-16 16:47:50 +02:00
< li > < a href = "#org22d4aa1" > 3.1. Description< / a > < / li >
< li > < a href = "#orgd284f46" > 3.2. Templates for front end has/read/write a single dimensioning variable< / a >
2021-09-14 11:40:10 +02:00
< ul >
2021-09-16 16:47:50 +02:00
< li > < a href = "#org2b27120" > 3.2.1. C templates for front end< / a > < / li >
< li > < a href = "#org0ee88e6" > 3.2.2. Fortran templates for front end< / a > < / li >
< li > < a href = "#orge0091a8" > 3.2.3. Python templates for front end< / a > < / li >
2021-04-12 14:32:08 +02:00
< / ul >
< / li >
2021-09-16 16:47:50 +02:00
< li > < a href = "#org16b99a8" > 3.3. Templates for front end has/read/write a dataset of numerical data< / a >
2021-09-14 11:40:10 +02:00
< ul >
2021-09-16 16:47:50 +02:00
< li > < a href = "#org5e03693" > 3.3.1. C templates for front end< / a >
2021-04-12 14:32:08 +02:00
< ul >
2021-09-16 16:47:50 +02:00
< li > < a href = "#org08b5207" > 3.3.1.1. Function declarations< / a > < / li >
< li > < a href = "#org18b002f" > 3.3.1.2. Source code for double precision functions< / a > < / li >
< li > < a href = "#orgf1d90ef" > 3.3.1.3. Source code for single precision functions< / a > < / li >
< li > < a href = "#org50d0cb1" > 3.3.1.4. Source code for memory-safe functions< / a > < / li >
< li > < a href = "#org3ee523b" > 3.3.1.5. Source code for default functions< / a > < / li >
2021-04-12 14:32:08 +02:00
< / ul >
< / li >
2021-09-16 16:47:50 +02:00
< li > < a href = "#org6e6b777" > 3.3.2. Fortran templates for front end< / a > < / li >
< li > < a href = "#orgebb89b1" > 3.3.3. Python templates for front end< / a > < / li >
2021-09-14 11:40:10 +02:00
< / ul >
< / li >
2021-09-16 16:47:50 +02:00
< li > < a href = "#orgee32a13" > 3.4. Sparse data structures< / a > < / li >
< li > < a href = "#org513c03a" > 3.5. Templates for front end has/read/write a dataset of strings< / a >
2021-06-15 12:12:15 +02:00
< ul >
2021-09-16 16:47:50 +02:00
< li > < a href = "#orgdf1d0d1" > 3.5.1. Introduction< / a > < / li >
< li > < a href = "#org35ba109" > 3.5.2. C templates for front end< / a > < / li >
< li > < a href = "#org1e652ee" > 3.5.3. Fortran templates for front end< / a > < / li >
< li > < a href = "#orgd6a6924" > 3.5.4. Python templates for front end< / a > < / li >
2021-06-15 12:12:15 +02:00
< / ul >
< / li >
2021-09-16 16:47:50 +02:00
< li > < a href = "#org5deaed0" > 3.6. Templates for front end has/read/write a single string attribute< / a >
2021-06-15 12:12:15 +02:00
< ul >
2021-09-16 16:47:50 +02:00
< li > < a href = "#org414340f" > 3.6.1. Introduction< / a > < / li >
< li > < a href = "#orgc82d373" > 3.6.2. C templates for front end< / a > < / li >
< li > < a href = "#orgbb17101" > 3.6.3. Fortran templates for front end< / a > < / li >
< li > < a href = "#orgb00c204" > 3.6.4. Python templates for front end< / a > < / li >
2021-04-12 14:32:08 +02:00
< / ul >
< / li >
2021-06-15 12:12:15 +02:00
< / ul >
< / li >
2021-09-16 16:47:50 +02:00
< li > < a href = "#org7bba65f" > 4. Fortran helper/wrapper functions< / a > < / li >
2021-04-12 14:32:08 +02:00
< / ul >
< / div >
< / div >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-orgac91e51" class = "outline-2" >
< h2 id = "orgac91e51" > < span class = "section-number-2" > 1< / span > Coding conventions< / h2 >
2021-04-12 14:32:08 +02:00
< 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 >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org7303f5d" class = "outline-3" >
< h3 id = "org7303f5d" > < span class = "section-number-3" > 1.1< / span > Memory allocation< / h3 >
2021-04-12 14:32:08 +02:00
< div class = "outline-text-3" id = "text-1-1" >
< p >
Memory allocation of structures can be facilitated by using the
following macro, which ensures that the size of the allocated
object is the same as the size of the data type pointed by the pointer.
< / p >
< div class = "org-src-container" >
2021-05-04 10:04:57 +02:00
< 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) , < span style = "color: #a020f0;" > sizeof< / span > (T) )
2021-04-12 14:32:08 +02:00
< / 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 >
2021-05-04 10:04:57 +02:00
< 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 >
2021-04-12 14:32:08 +02:00
< / div >
< / div >
< / div >
2021-05-04 10:04:57 +02:00
< / div >
2021-05-07 00:03:17 +02:00
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org0ed731c" class = "outline-2" >
< h2 id = "org0ed731c" > < span class = "section-number-2" > 2< / span > Front end< / h2 >
2021-04-12 14:32:08 +02:00
< div class = "outline-text-2" id = "text-2" >
< p >
All calls to TREXIO are thread-safe.
2021-05-06 18:26:46 +02:00
TREXIO front end is modular, which simplifies implementation of new back ends.
2021-04-12 14:32:08 +02:00
< / p >
< / div >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-orgad4bf32" class = "outline-3" >
< h3 id = "orgad4bf32" > < span class = "section-number-3" > 2.1< / span > Error handling< / h3 >
2021-04-12 14:32:08 +02:00
< div class = "outline-text-3" id = "text-2-1" >
2021-09-16 16:47:50 +02:00
< table id = "org1606e6d" border = "2" cellspacing = "0" cellpadding = "6" rules = "groups" frame = "hsides" >
2021-04-12 14:32:08 +02:00
< 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 >
2021-05-06 19:57:56 +02:00
< td class = "org-left" > 'Invalid dimensions'< / td >
2021-04-12 14:32:08 +02:00
< / tr >
2021-05-06 18:09:34 +02:00
< tr >
2021-06-22 22:32:47 +02:00
< td class = "org-left" > < code > TREXIO_ATTR_ALREADY_EXISTS< / code > < / td >
2021-05-06 18:09:34 +02:00
< td class = "org-right" > 13< / td >
2021-09-14 11:40:10 +02:00
< td class = "org-left" > 'Attribute already exists'< / td >
2021-05-06 18:09:34 +02:00
< / tr >
2021-05-06 18:26:46 +02:00
< tr >
2021-06-04 14:15:51 +02:00
< td class = "org-left" > < code > TREXIO_DSET_ALREADY_EXISTS< / code > < / td >
2021-05-06 18:26:46 +02:00
< td class = "org-right" > 14< / td >
2021-06-04 14:15:51 +02:00
< 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 >
2021-05-06 18:26:46 +02:00
< td class = "org-left" > 'Error opening file'< / td >
< / tr >
< tr >
< td class = "org-left" > < code > TREXIO_LOCK_ERROR< / code > < / td >
2021-06-04 14:15:51 +02:00
< td class = "org-right" > 16< / td >
2021-05-06 18:26:46 +02:00
< td class = "org-left" > 'Error locking file'< / td >
< / tr >
< tr >
< td class = "org-left" > < code > TREXIO_UNLOCK_ERROR< / code > < / td >
2021-06-04 14:15:51 +02:00
< td class = "org-right" > 17< / td >
2021-05-06 18:26:46 +02:00
< td class = "org-left" > 'Error unlocking file'< / td >
< / tr >
< tr >
< td class = "org-left" > < code > TREXIO_FILE_ERROR< / code > < / td >
2021-06-04 14:15:51 +02:00
< td class = "org-right" > 18< / td >
2021-05-06 18:26:46 +02:00
< td class = "org-left" > 'Invalid file handle'< / td >
< / tr >
< tr >
< td class = "org-left" > < code > TREXIO_GROUP_READ_ERROR< / code > < / td >
2021-06-04 14:15:51 +02:00
< td class = "org-right" > 19< / td >
2021-05-06 18:26:46 +02:00
< td class = "org-left" > 'Error reading group'< / td >
< / tr >
< tr >
< td class = "org-left" > < code > TREXIO_GROUP_WRITE_ERROR< / code > < / td >
2021-06-04 14:15:51 +02:00
< td class = "org-right" > 20< / td >
2021-05-06 18:26:46 +02:00
< td class = "org-left" > 'Error writing group'< / td >
< / tr >
< tr >
< td class = "org-left" > < code > TREXIO_ELEM_READ_ERROR< / code > < / td >
2021-06-04 14:15:51 +02:00
< td class = "org-right" > 21< / td >
2021-05-06 18:26:46 +02:00
< td class = "org-left" > 'Error reading element'< / td >
< / tr >
< tr >
< td class = "org-left" > < code > TREXIO_ELEM_WRITE_ERROR< / code > < / td >
2021-06-04 14:15:51 +02:00
< td class = "org-right" > 22< / td >
2021-05-06 18:26:46 +02:00
< td class = "org-left" > 'Error writing element'< / td >
< / tr >
2021-06-15 12:12:15 +02:00
2021-09-14 11:40:10 +02:00
< 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 >
2021-06-15 12:12:15 +02:00
< 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 >
2021-04-12 14:32:08 +02:00
< / tbody >
< / table >
2021-09-14 11:40:10 +02:00
< 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 >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org0c590e0" class = "outline-4" >
< h4 id = "org0c590e0" > < span class = "section-number-4" > 2.1.1< / span > Decoding errors< / h4 >
2021-09-14 11:40:10 +02:00
< div class = "outline-text-4" id = "text-2-1-1" >
2021-04-12 14:32:08 +02:00
< 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 >
The text strings are extracted from the previous table.
< / p >
2021-09-14 11:40:10 +02:00
< / div >
2021-04-12 14:32:08 +02:00
2021-09-16 16:47:50 +02:00
< div id = "outline-container-orgfb3cc49" class = "outline-5" >
< h5 id = "orgfb3cc49" > < span class = "section-number-5" > 2.1.1.1< / span > C source code< / h5 >
2021-09-14 11:40:10 +02:00
< div class = "outline-text-5" id = "text-2-1-1-1" >
2021-04-12 14:32:08 +02:00
< 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:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #8b2252;" > "Unknown failure"< / span > ;
< span style = "color: #a020f0;" > break< / span > ;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_SUCCESS:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #8b2252;" > "Success"< / span > ;
< span style = "color: #a020f0;" > break< / span > ;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_INVALID_ARG_1:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #8b2252;" > "Invalid argument 1"< / span > ;
< span style = "color: #a020f0;" > break< / span > ;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_INVALID_ARG_2:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #8b2252;" > "Invalid argument 2"< / span > ;
< span style = "color: #a020f0;" > break< / span > ;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_INVALID_ARG_3:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #8b2252;" > "Invalid argument 3"< / span > ;
< span style = "color: #a020f0;" > break< / span > ;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_INVALID_ARG_4:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #8b2252;" > "Invalid argument 4"< / span > ;
< span style = "color: #a020f0;" > break< / span > ;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_INVALID_ARG_5:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #8b2252;" > "Invalid argument 5"< / span > ;
< span style = "color: #a020f0;" > break< / span > ;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_END:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #8b2252;" > "End of file"< / span > ;
< span style = "color: #a020f0;" > break< / span > ;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_READONLY:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #8b2252;" > "Read-only file"< / span > ;
< span style = "color: #a020f0;" > break< / span > ;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_ERRNO:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > strerror(errno);
< span style = "color: #a020f0;" > break< / span > ;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_INVALID_ID:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #8b2252;" > "Invalid ID"< / span > ;
< span style = "color: #a020f0;" > break< / span > ;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_ALLOCATION_FAILED:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #8b2252;" > "Allocation failed"< / span > ;
< span style = "color: #a020f0;" > break< / span > ;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_HAS_NOT:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #8b2252;" > "Element absent"< / span > ;
< span style = "color: #a020f0;" > break< / span > ;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_INVALID_NUM:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #8b2252;" > "Invalid dimensions"< / span > ;
< span style = "color: #a020f0;" > break< / span > ;
2021-06-22 22:32:47 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_ATTR_ALREADY_EXISTS:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #8b2252;" > "Attribute already exists"< / span > ;
< span style = "color: #a020f0;" > break< / span > ;
2021-06-04 14:15:51 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_DSET_ALREADY_EXISTS:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #8b2252;" > "Dataset already exists"< / span > ;
< span style = "color: #a020f0;" > break< / span > ;
2021-05-06 18:26:46 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_OPEN_ERROR:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #8b2252;" > "Error opening file"< / span > ;
< span style = "color: #a020f0;" > break< / span > ;
2021-05-06 18:26:46 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_LOCK_ERROR:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #8b2252;" > "Error locking file"< / span > ;
< span style = "color: #a020f0;" > break< / span > ;
2021-05-06 18:26:46 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_UNLOCK_ERROR:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #8b2252;" > "Error unlocking file"< / span > ;
< span style = "color: #a020f0;" > break< / span > ;
2021-05-06 18:26:46 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_FILE_ERROR:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #8b2252;" > "Invalid file handle"< / span > ;
< span style = "color: #a020f0;" > break< / span > ;
2021-05-06 18:26:46 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_GROUP_READ_ERROR:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #8b2252;" > "Error reading group"< / span > ;
< span style = "color: #a020f0;" > break< / span > ;
2021-05-06 18:26:46 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_GROUP_WRITE_ERROR:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #8b2252;" > "Error writing group"< / span > ;
< span style = "color: #a020f0;" > break< / span > ;
2021-05-06 18:26:46 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_ELEM_READ_ERROR:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #8b2252;" > "Error reading element"< / span > ;
< span style = "color: #a020f0;" > break< / span > ;
2021-05-06 18:26:46 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_ELEM_WRITE_ERROR:
2021-09-14 11:40:10 +02:00
< 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 > ;
2021-06-15 12:12:15 +02:00
< span style = "color: #a020f0;" > case< / span > TREXIO_INVALID_STR_LEN:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #8b2252;" > "Invalid max_str_len"< / span > ;
< span style = "color: #a020f0;" > break< / span > ;
2021-04-12 14:32:08 +02:00
}
< 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 >
2021-09-14 11:40:10 +02:00
< / div >
< / div >
2021-04-12 14:32:08 +02:00
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org9a5bddc" class = "outline-5" >
< h5 id = "org9a5bddc" > < span class = "section-number-5" > 2.1.1.2< / span > Fortran interface< / h5 >
2021-09-14 11:40:10 +02:00
< div class = "outline-text-5" id = "text-2-1-1-2" >
2021-04-12 14:32:08 +02:00
< 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;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / 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 > , < 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 >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-orgb5b685d" class = "outline-5" >
< h5 id = "orgb5b685d" > < span class = "section-number-5" > 2.1.1.3< / span > Python interface< / h5 >
2021-09-14 11:40:10 +02:00
< 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 string that contains description of TREXIO ~return_code~.< / span >
< span style = "color: #8b2252;" > """< / span >
< span style = "color: #a020f0;" > try< / span > :
< span style = "color: #a0522d;" > error_str< / span > = pytr.trexio_string_of_error(return_code)
< span style = "color: #a020f0;" > except< / span > :
< span style = "color: #a020f0;" > raise< / span >
< span style = "color: #a020f0;" > return< / span > error_str
< / pre >
< / div >
< / div >
< / div >
< / div >
< / div >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org010ba58" class = "outline-3" >
< h3 id = "org010ba58" > < span class = "section-number-3" > 2.2< / span > Back ends< / h3 >
2021-04-12 14:32:08 +02:00
< 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 >
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 >
2021-09-14 11:40:10 +02:00
< p >
< span class = "underline" > Note< / span > : It is important to increment the value of TREXIO< sub > INVALID< / sub > < sub > BACK< / sub > < sub > END< / sub > when a new back end is added. Otherwise, it will not be available.
< / p >
< / div >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-orgceba57c" class = "outline-4" >
< h4 id = "orgceba57c" > < span class = "section-number-4" > 2.2.1< / span > C< / h4 >
2021-09-14 11:40:10 +02:00
< div class = "outline-text-4" id = "text-2-2-1" >
2021-04-12 14:32:08 +02:00
< 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: #b22222;" > #define TREXIO_JSON ( (back_end_t) 2 )< / span > */
< span style = "color: #483d8b;" > #define< / span > < span style = "color: #a0522d;" > TREXIO_INVALID_BACK_END< / span > ( (< span style = "color: #228b22;" > back_end_t< / span > ) 2 )
2021-06-15 12:12:15 +02:00
< span style = "color: #483d8b;" > #define< / span > < span style = "color: #a0522d;" > TREXIO_DELIM< / span > < span style = "color: #8b2252;" > "\n"< / span >
2021-04-12 14:32:08 +02:00
< / pre >
< / div >
< / div >
< / div >
2021-09-14 11:40:10 +02:00
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org6672d17" class = "outline-4" >
< h4 id = "org6672d17" > < span class = "section-number-4" > 2.2.2< / span > Fortran< / h4 >
2021-09-14 11:40:10 +02:00
< 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_backend), < span style = "color: #a020f0;" > parameter< / span > ::< span style = "color: #a0522d;" > TREXIO_HDF5 = 0< / span >
< span style = "color: #228b22;" > integer< / span > (trexio_backend), < span style = "color: #a020f0;" > parameter< / span > ::< span style = "color: #a0522d;" > TREXIO_TEXT = 1< / span >
! < span style = "color: #b22222;" > integer(trexio_backend), parameter :: TREXIO_JSON = 2< / span >
< span style = "color: #228b22;" > integer< / span > (trexio_backend), < span style = "color: #a020f0;" > parameter< / span > ::< span style = "color: #a0522d;" > TREXIO_INVALID_BACK_END = 2< / span >
< / pre >
< / div >
< / div >
< / div >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org040bab1" class = "outline-4" >
< h4 id = "org040bab1" > < span class = "section-number-4" > 2.2.3< / span > Python< / h4 >
2021-09-14 11:40:10 +02:00
< 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
< / pre >
< / div >
< / div >
< / div >
< / div >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-orgf8ad563" class = "outline-3" >
< h3 id = "orgf8ad563" > < span class = "section-number-3" > 2.3< / span > Read/write behavior< / h3 >
2021-04-12 14:32:08 +02:00
< 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) in a per-group fashion. 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 >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org940788e" class = "outline-3" >
< h3 id = "org940788e" > < span class = "section-number-3" > 2.4< / span > TREXIO file type< / h3 >
2021-04-12 14:32:08 +02:00
< 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 > {
2021-06-14 09:35:37 +02:00
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > file_name< / span > [TREXIO_MAX_FILENAME_LENGTH];
2021-07-23 16:28:04 +02:00
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > version< / span > [16];
2021-04-12 14:32:08 +02:00
< 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 > ;
2021-06-14 09:35:37 +02:00
< span style = "color: #228b22;" > bool< / span > < span style = "color: #a0522d;" > one_based< / span > ;
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > padding< / span > [6]; /* < span style = "color: #b22222;" > Ensures the proper alignment of back ends < / span > */
2021-04-12 14:32:08 +02:00
};
< / pre >
< / div >
< / div >
2021-09-14 11:40:10 +02:00
2021-09-16 16:47:50 +02:00
< div id = "outline-container-orga619b31" class = "outline-4" >
< h4 id = "orga619b31" > < span class = "section-number-4" > 2.4.1< / span > TREXIO< sub > File< / sub > Python class< / h4 >
2021-09-14 11:40:10 +02:00
< div class = "outline-text-4" id = "text-2-4-1" >
< 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 object.< / 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;" > 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;" > """This is a TREXIO File constructor."""< / span >
< span style = "color: #a020f0;" > self< / span > .filename = filename
< span style = "color: #a020f0;" > self< / span > .mode = mode
< span style = "color: #a020f0;" > self< / span > .back_end = back_end
< span style = "color: #a020f0;" > self< / span > .isOpen = < 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 = < span style = "color: #483d8b;" > open< / span > (filename, mode, back_end)
< span style = "color: #a020f0;" > self< / span > .isOpen = < 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 > .info = info
< 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;" > __del__< / span > (< span style = "color: #a020f0;" > self< / span > ):
< span style = "color: #8b2252;" > """This is a TREXIO File 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 >
2021-04-12 14:32:08 +02:00
< / div >
2021-09-14 11:40:10 +02:00
2021-09-16 16:47:50 +02:00
< div id = "outline-container-orga7947c3" class = "outline-3" >
< h3 id = "orga7947c3" > < span class = "section-number-3" > 2.5< / span > Polymorphism of the file handle< / h3 >
2021-04-12 14:32:08 +02:00
< div class = "outline-text-3" id = "text-2-5" >
< p >
Polymorphism of the < code > trexio_t< / code > type is handled by ensuring that the
corresponding types for all back ends can be safely casted to
< code > trexio_t< / code > . This is done by making the back-end structs start with
< code > struct trexio_s< / code > :
< / p >
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #a020f0;" > struct< / span > < span style = "color: #228b22;" > trexio_back_end_s< / span > {
< span style = "color: #228b22;" > trexio_t< / span > < span style = "color: #a0522d;" > parent< / span > ;
/* < span style = "color: #b22222;" > add below specific back-end data < / span > */
}
< / pre >
< / div >
< / div >
< / div >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org95af478" class = "outline-3" >
< h3 id = "org95af478" > < span class = "section-number-3" > 2.6< / span > File opening< / h3 >
2021-04-12 14:32:08 +02:00
< div class = "outline-text-3" id = "text-2-6" >
< p >
< code > trexio_open< / code > creates a new TREXIO file or opens existing one.
< / p >
< p >
input parameters:
< / 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 (overwrite existing file)< / li >
< li > < code > 'r'< / code > - (read) opens existing file as READONLY< / 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 >
< / ul > < / li >
< / ol >
< p >
output:
< code > trexio_t< / code > file handle
< / p >
< p >
2021-06-14 09:35:37 +02:00
Note: 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.
2021-04-12 14:32:08 +02:00
< / p >
2021-09-14 11:40:10 +02:00
< / div >
2021-04-12 14:32:08 +02:00
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org69ff763" class = "outline-4" >
< h4 id = "org69ff763" > < span class = "section-number-4" > 2.6.1< / span > C< / h4 >
2021-09-14 11:40:10 +02:00
< div class = "outline-text-4" id = "text-2-6-1" >
2021-04-12 14:32:08 +02:00
< 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: #a020f0;" > if< / span > (file_name == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
< span style = "color: #a020f0;" > if< / span > (file_name[0] == < span style = "color: #8b2252;" > '\0'< / span > ) < span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
2021-05-04 10:04:57 +02:00
/* < span style = "color: #b22222;" > Check overflow in file_name < / span > */
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > if< / span > (back_end < 0) < span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
< span style = "color: #a020f0;" > if< / span > (back_end > = TREXIO_INVALID_BACK_END) < span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
2021-06-04 14:15:51 +02:00
< span style = "color: #a020f0;" > if< / span > (mode != < span style = "color: #8b2252;" > 'r'< / span > & & mode != < span style = "color: #8b2252;" > 'w'< / span > ) < span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
2021-04-12 14:32:08 +02:00
< span style = "color: #228b22;" > trexio_t< / span > * < span style = "color: #a0522d;" > result< / span > = < span style = "color: #008b8b;" > NULL< / span > ;
2021-05-19 22:03:41 +02:00
< span style = "color: #228b22;" > void< / span > * < span style = "color: #a0522d;" > result_tmp< / span > = < span style = "color: #008b8b;" > NULL< / span > ;
2021-04-12 14:32:08 +02:00
/* < span style = "color: #b22222;" > Allocate data structures < / span > */
< span style = "color: #a020f0;" > switch< / span > (back_end) {
< span style = "color: #a020f0;" > case< / span > TREXIO_TEXT:
2021-05-19 22:03:41 +02:00
result_tmp = malloc(< span style = "color: #a020f0;" > sizeof< / span > (trexio_text_t));
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > break< / span > ;
< span style = "color: #a020f0;" > case< / span > TREXIO_HDF5:
2021-05-19 22:03:41 +02:00
result_tmp = malloc(< span style = "color: #a020f0;" > sizeof< / span > (trexio_hdf5_t));
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > break< / 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 >
*/
}
2021-05-19 22:03:41 +02:00
result = (< span style = "color: #228b22;" > trexio_t< / span > *) result_tmp;
2021-04-12 14:32:08 +02:00
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 > */
2021-05-04 10:04:57 +02:00
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 > ) {
free(result);
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
}
2021-07-23 16:28:04 +02:00
strncpy(result-> version, PACKAGE_VERSION, 16);
< span style = "color: #a020f0;" > if< / span > (result-> version[15] != < span style = "color: #8b2252;" > '\0'< / span > ) {
free(result);
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
}
2021-04-12 14:32:08 +02:00
result-> back_end = back_end;
result-> mode = mode;
2021-06-14 09:35:37 +02:00
result-> one_based = < span style = "color: #008b8b;" > false< / span > ; // < span style = "color: #b22222;" > Need to be flipped in Fortran interface< / span >
2021-04-12 14:32:08 +02:00
< span style = "color: #228b22;" > int< / span > < span style = "color: #a0522d;" > irc< / span > = pthread_mutex_init ( & (result-> thread_lock), < span style = "color: #008b8b;" > NULL< / span > );
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > if< / span > (irc != 0) {
free(result);
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
}
2021-04-12 14:32:08 +02:00
assert (irc == 0);
< span style = "color: #228b22;" > trexio_exit_code< / span > < span style = "color: #a0522d;" > rc< / span > ;
/* < span style = "color: #b22222;" > Back end initialization < / span > */
2021-05-06 18:26:46 +02:00
rc = TREXIO_OPEN_ERROR;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > switch< / span > (back_end) {
< 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:
rc = trexio_hdf5_init(result);
< span style = "color: #a020f0;" > break< / 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) {
free(result);
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
}
2021-07-23 16:28:04 +02:00
rc = trexio_has_metadata_package_version(result);
< span style = "color: #a020f0;" > if< / span > (rc == TREXIO_FAILURE) {
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: #a020f0;" > switch< / span > (back_end) {
< span style = "color: #a020f0;" > case< / span > TREXIO_TEXT:
rc = trexio_text_write_metadata_package_version(result, PACKAGE_VERSION);
< span style = "color: #a020f0;" > break< / span > ;
< span style = "color: #a020f0;" > case< / span > TREXIO_HDF5:
rc = trexio_hdf5_write_metadata_package_version(result, PACKAGE_VERSION);
< span style = "color: #a020f0;" > break< / span > ;
/*
< span style = "color: #b22222;" > case TREXIO_JSON:< / span >
< span style = "color: #b22222;" > rc = trexio_json_write_metadata_package_version(result, PACKAGE_VERSION);< / span >
< span style = "color: #b22222;" > break;< / span >
*/
}
}
< span style = "color: #a020f0;" > if< / span > (rc != TREXIO_SUCCESS) {
free(result);
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
}
2021-04-12 14:32:08 +02:00
/* < span style = "color: #b22222;" > File locking < / span > */
2021-05-06 18:26:46 +02:00
rc = TREXIO_LOCK_ERROR;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > switch< / span > (back_end) {
< 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:
rc = TREXIO_SUCCESS;
< span style = "color: #a020f0;" > break< / 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) {
free(result);
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
}
< span style = "color: #a020f0;" > return< / span > result;
}
< / pre >
< / div >
2021-09-14 11:40:10 +02:00
< / div >
< / div >
2021-04-12 14:32:08 +02:00
2021-09-16 16:47:50 +02:00
< div id = "outline-container-orgb66bef1" class = "outline-4" >
< h4 id = "orgb66bef1" > < span class = "section-number-4" > 2.6.2< / span > Fortran< / h4 >
2021-09-14 11:40:10 +02:00
< div class = "outline-text-4" id = "text-2-6-2" >
2021-04-12 14:32:08 +02:00
< div class = "org-src-container" >
< pre class = "src src-f90" > < span style = "color: #a020f0;" > interface< / span >
< span style = "color: #228b22;" > integer< / span > (8) < span style = "color: #a020f0;" > function< / span > < span style = "color: #0000ff;" > trexio_open_c< / span > (filename, mode, backend) < span style = "color: #a020f0;" > bind< / span > (C, name=< span style = "color: #8b2252;" > "trexio_open"< / span > )
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span >
2021-06-04 18:16:31 +02:00
< 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 > , < 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_backend), < span style = "color: #a020f0;" > intent< / span > (in), < span style = "color: #a020f0;" > value< / span > ::< span style = "color: #a0522d;" > backend< / span >
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > end function< / span > < span style = "color: #0000ff;" > trexio_open_c< / span >
< span style = "color: #a020f0;" > end interface< / span >
< / pre >
< / div >
2021-09-14 11:40:10 +02:00
< / div >
< / div >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-orgdac714f" class = "outline-4" >
< h4 id = "orgdac714f" > < span class = "section-number-4" > 2.6.3< / span > Python< / h4 >
2021-09-14 11:40:10 +02:00
< 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;" > 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: #a020f0;" > try< / span > :
< span style = "color: #a0522d;" > trexio_file< / span > = pytr.trexio_open(file_name, mode, back_end)
< 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. Please make sure that there are no typos in the file name."< / span > )
< span style = "color: #a020f0;" > return< / span > trexio_file
< / pre >
< / div >
< / div >
< / div >
2021-06-14 09:35:37 +02:00
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org723d54b" class = "outline-4" >
< h4 id = "org723d54b" > < span class = "section-number-4" > 2.6.4< / span > Zero-based versus one-based arrays of indices< / h4 >
2021-09-14 11:40:10 +02:00
< div class = "outline-text-4" id = "text-2-6-4" >
2021-06-14 09:35:37 +02:00
< 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 > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_set_one_based< / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file) bind(C)< / span >
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span >
< span style = "color: #228b22;" > integer< / span > (8), < 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 >
2021-04-12 14:32:08 +02:00
< / div >
< / div >
2021-09-14 11:40:10 +02:00
< / div >
2021-04-12 14:32:08 +02:00
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org2c095ce" class = "outline-3" >
< h3 id = "org2c095ce" > < span class = "section-number-3" > 2.7< / span > File closing< / h3 >
2021-04-12 14:32:08 +02:00
< div class = "outline-text-3" id = "text-2-7" >
< 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 >
2021-09-14 11:40:10 +02:00
< / div >
2021-04-12 14:32:08 +02:00
2021-09-16 16:47:50 +02:00
< div id = "outline-container-orga522a7a" class = "outline-4" >
< h4 id = "orga522a7a" > < span class = "section-number-4" > 2.7.1< / span > C< / h4 >
2021-09-14 11:40:10 +02:00
< div class = "outline-text-4" id = "text-2-7-1" >
2021-04-12 14:32:08 +02:00
< 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 > )
{
2021-05-06 18:26:46 +02:00
< span style = "color: #a020f0;" > if< / span > (file == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FILE_ERROR;
2021-04-12 14:32:08 +02:00
2021-05-19 22:03:41 +02:00
< span style = "color: #228b22;" > trexio_exit_code< / span > < span style = "color: #a0522d;" > rc< / span > = TREXIO_FAILURE;
assert(file-> back_end < TREXIO_INVALID_BACK_END);
2021-04-12 14:32:08 +02:00
/* < 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:
rc = trexio_hdf5_deinit(file);
< span style = "color: #a020f0;" > break< / 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) {
2021-05-04 10:04:57 +02:00
FREE(file);
2021-05-06 18:26:46 +02:00
< span style = "color: #a020f0;" > return< / span > rc;
2021-04-12 14:32:08 +02:00
}
/* < span style = "color: #b22222;" > File unlocking < / span > */
2021-05-06 18:26:46 +02:00
rc = TREXIO_UNLOCK_ERROR;
2021-04-12 14:32:08 +02:00
< 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:
rc = TREXIO_SUCCESS;
< span style = "color: #a020f0;" > break< / 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;
2021-05-06 18:26:46 +02:00
< span style = "color: #a020f0;" > if< / span > (rc != TREXIO_SUCCESS) < span style = "color: #a020f0;" > return< / span > rc;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
}
< / pre >
< / div >
2021-09-14 11:40:10 +02:00
< / div >
< / div >
2021-04-12 14:32:08 +02:00
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org8df0c7d" class = "outline-4" >
< h4 id = "org8df0c7d" > < span class = "section-number-4" > 2.7.2< / span > Fortran< / h4 >
2021-09-14 11:40:10 +02:00
< div class = "outline-text-4" id = "text-2-7-2" >
2021-04-12 14:32:08 +02:00
< 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: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_close< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file) bind(C)< / span >
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span >
< span style = "color: #228b22;" > integer< / span > (8), < 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 >
2021-09-14 11:40:10 +02:00
2021-09-16 16:47:50 +02:00
< div id = "outline-container-orge504b2b" class = "outline-4" >
< h4 id = "orge504b2b" > < span class = "section-number-4" > 2.7.3< / span > Python< / h4 >
2021-09-14 11:40:10 +02:00
< 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;" > 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: #a020f0;" > try< / 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)
< span style = "color: #a020f0;" > except< / span > :
< span style = "color: #a020f0;" > raise< / span >
< / pre >
< / div >
< / div >
< / div >
< / div >
2021-04-12 14:32:08 +02:00
< / div >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-orgdaf108d" class = "outline-2" >
< h2 id = "orgdaf108d" > < span class = "section-number-2" > 3< / span > Templates for front end< / h2 >
2021-04-12 14:32:08 +02:00
< div class = "outline-text-2" id = "text-3" >
2021-06-15 12:12:15 +02:00
< / div >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org22d4aa1" class = "outline-3" >
< h3 id = "org22d4aa1" > < span class = "section-number-3" > 3.1< / span > Description< / h3 >
2021-06-15 12:12:15 +02:00
< div class = "outline-text-3" id = "text-3-1" >
2021-04-12 14:32:08 +02:00
< 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 > ] ]
2021-06-04 14:15:51 +02:00
, < span style = "color: #8b2252;" > "label"< / span > : [ < span style = "color: #8b2252;" > "str"< / span > , [ < span style = "color: #8b2252;" > "nucleus.num"< / span > ] ]
2021-04-12 14:32:08 +02:00
}
}
< / pre >
< / div >
< p >
2021-05-07 00:03:17 +02:00
< 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.
2021-04-12 14:32:08 +02:00
< / p >
< p >
2021-05-07 00:03:17 +02:00
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:
2021-04-12 14:32:08 +02:00
< / 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 >
2021-05-07 00:03:17 +02:00
< td class = "org-left" > Name of the group< / td >
2021-04-12 14:32:08 +02:00
< td class = "org-left" > < code > nucleus< / code > < / td >
< / tr >
< tr >
< td class = "org-left" > < code > $group_num$< / code > < / td >
2021-05-07 00:03:17 +02:00
< td class = "org-left" > Name of the dimensioning variable (scalar)< / td >
2021-04-12 14:32:08 +02:00
< td class = "org-left" > < code > nucleus_num< / code > < / td >
< / tr >
< tr >
< td class = "org-left" > < code > $group_dset$< / code > < / td >
2021-05-07 00:03:17 +02:00
< td class = "org-left" > Name of the dataset (vector/matrix/tensor)< / td >
2021-04-12 14:32:08 +02:00
< td class = "org-left" > < code > nucleus_coord< / code > < / td >
< / tr >
< tr >
< td class = "org-left" > < code > $group_dset_rank$< / code > < / td >
2021-05-07 00:03:17 +02:00
< td class = "org-left" > Rank of the dataset< / td >
2021-04-12 14:32:08 +02:00
< td class = "org-left" > < code > 2< / code > < / td >
< / tr >
< tr >
< td class = "org-left" > < code > $group_dset_dim$< / code > < / td >
2021-05-07 00:03:17 +02:00
< td class = "org-left" > Selected dimension of the dataset< / td >
2021-04-12 14:32:08 +02:00
< td class = "org-left" > < code > nucleus_num< / code > < / td >
< / tr >
< tr >
< td class = "org-left" > < code > $group_dset_dim_list$< / code > < / td >
2021-05-07 00:03:17 +02:00
< td class = "org-left" > All dimensions of the dataset< / td >
2021-04-12 14:32:08 +02:00
< td class = "org-left" > < code > {nucleus_num, 3}< / code > < / td >
< / tr >
< tr >
< td class = "org-left" > < code > $group_dset_dtype$< / code > < / td >
2021-05-07 00:03:17 +02:00
< td class = "org-left" > Basic type of the dataset (int/float/char)< / td >
2021-04-12 14:32:08 +02:00
< td class = "org-left" > < code > float< / code > < / td >
< / tr >
< tr >
< td class = "org-left" > < code > $group_dset_h5_dtype$< / code > < / td >
2021-05-07 00:03:17 +02:00
< td class = "org-left" > Type of the dataset in HDF5< / td >
2021-04-12 14:32:08 +02:00
< td class = "org-left" > < code > double< / code > < / td >
< / tr >
< tr >
< td class = "org-left" > < code > $group_dset_std_dtype_in$< / code > < / td >
2021-05-07 00:03:17 +02:00
< td class = "org-left" > Input type of the dataset in TEXT [fscanf]< / td >
2021-04-12 14:32:08 +02:00
< td class = "org-left" > < code > %lf< / code > < / td >
< / tr >
< tr >
< td class = "org-left" > < code > $group_dset_std_dtype_out$< / code > < / td >
2021-05-07 00:03:17 +02:00
< td class = "org-left" > Output type of the dataset in TEXT [fprintf]< / td >
2021-04-12 14:32:08 +02:00
< td class = "org-left" > < code > %24.16e< / code > < / td >
< / tr >
2021-05-18 12:16:43 +02:00
< 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 >
2021-04-12 14:32:08 +02:00
< tr >
< td class = "org-left" > < code > $group_dset_dtype_single$< / code > < / td >
2021-05-18 12:16:43 +02:00
< td class = "org-left" > Single precision datatype of the dataset [C]< / td >
< td class = "org-left" > < code > float/int32_t< / code > < / td >
2021-04-12 14:32:08 +02:00
< / tr >
< tr >
< td class = "org-left" > < code > $group_dset_dtype_double$< / code > < / td >
2021-05-18 12:16:43 +02:00
< 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 > $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 > $group_dset_f_dtype_default$< / code > < / td >
< td class = "org-left" > Default datatype of the dataset [Fortran]< / td >
< td class = "org-left" > < code > real(8)/integer(4)< / code > < / td >
2021-04-12 14:32:08 +02:00
< / tr >
< tr >
< td class = "org-left" > < code > $group_dset_f_dtype_single$< / code > < / td >
2021-05-18 12:16:43 +02:00
< td class = "org-left" > Single precision datatype of the dataset [Fortran]< / td >
< td class = "org-left" > < code > real(4)/integer(4)< / code > < / td >
2021-04-12 14:32:08 +02:00
< / tr >
< tr >
< td class = "org-left" > < code > $group_dset_f_dtype_double$< / code > < / td >
2021-05-18 12:16:43 +02:00
< td class = "org-left" > Double precision datatype of the dataset [Fortran]< / td >
< td class = "org-left" > < code > real(8)/integer(8)< / code > < / td >
2021-04-12 14:32:08 +02:00
< / tr >
2021-05-08 00:44:30 +02:00
< 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 >
2021-09-14 11:40:10 +02:00
< 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 >
2021-04-12 14:32:08 +02:00
< / tbody >
< / table >
2021-05-08 00:44:30 +02:00
2021-04-12 14:32:08 +02:00
< p >
2021-05-07 00:03:17 +02:00
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).
2021-04-12 14:32:08 +02:00
< / p >
< p >
2021-05-07 00:03:17 +02:00
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:
2021-04-12 14:32:08 +02:00
< / p >
< ol class = "org-ol" >
< li > Dimensioning variables (contain < code > num< / code > in their names). These are always scalar integers.< / li >
< li > Datasets. These can be vectors, matrices or tensors. The types are indicated in < code > trex.json< / code > .
2021-06-04 14:15:51 +02:00
Currently supported types: int, float and strings.< / li >
2021-04-12 14:32:08 +02:00
< / ol >
< p >
2021-05-07 00:03:17 +02:00
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.
2021-04-12 14:32:08 +02:00
< / p >
< / div >
2021-06-15 12:12:15 +02:00
< / div >
2021-04-12 14:32:08 +02:00
2021-09-16 16:47:50 +02:00
< div id = "outline-container-orgd284f46" class = "outline-3" >
< h3 id = "orgd284f46" > < span class = "section-number-3" > 3.2< / span > Templates for front end has/read/write a single dimensioning variable< / h3 >
2021-06-15 12:12:15 +02:00
< div class = "outline-text-3" id = "text-3-2" >
2021-04-12 14:32:08 +02:00
< p >
This section concerns API calls related to dimensioning variables.
< / 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 >
2021-05-07 00:03:17 +02:00
< td class = "org-left" > Check if a dimensioning variable exists in a file< / td >
2021-04-12 14:32:08 +02:00
< td class = "org-left" > ---< / td >
< / tr >
< tr >
< td class = "org-left" > < code > trexio_read_$group_num$< / code > < / td >
2021-05-07 00:03:17 +02:00
< td class = "org-left" > Read a dimensioning variable< / td >
2021-04-12 14:32:08 +02:00
< td class = "org-left" > Single< / td >
< / tr >
< tr >
< td class = "org-left" > < code > trexio_write_$group_num$< / code > < / td >
2021-05-07 00:03:17 +02:00
< td class = "org-left" > Write a dimensioning variable< / td >
2021-04-12 14:32:08 +02:00
< td class = "org-left" > Single< / td >
< / tr >
< tr >
< td class = "org-left" > < code > trexio_read_$group_num$_32< / code > < / td >
2021-05-07 00:03:17 +02:00
< td class = "org-left" > Read a dimensioning variable< / td >
2021-04-12 14:32:08 +02:00
< td class = "org-left" > Single< / td >
< / tr >
< tr >
< td class = "org-left" > < code > trexio_write_$group_num$_32< / code > < / td >
2021-05-07 00:03:17 +02:00
< td class = "org-left" > Write a dimensioning variable< / td >
2021-04-12 14:32:08 +02:00
< td class = "org-left" > Single< / td >
< / tr >
< tr >
< td class = "org-left" > < code > trexio_read_$group_num$_64< / code > < / td >
2021-05-07 00:03:17 +02:00
< td class = "org-left" > Read a dimensioning variable< / td >
2021-04-12 14:32:08 +02:00
< td class = "org-left" > Double< / td >
< / tr >
< tr >
< td class = "org-left" > < code > trexio_write_$group_num$_64< / code > < / td >
2021-05-07 00:03:17 +02:00
< td class = "org-left" > Write a dimensioning variable< / td >
2021-04-12 14:32:08 +02:00
< td class = "org-left" > Double< / td >
< / tr >
< / tbody >
< / table >
< / div >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org2b27120" class = "outline-4" >
< h4 id = "org2b27120" > < span class = "section-number-4" > 3.2.1< / span > C templates for front end< / h4 >
2021-06-15 12:12:15 +02:00
< div class = "outline-text-4" id = "text-3-2-1" >
2021-04-12 14:32:08 +02:00
< p >
2021-05-07 00:03:17 +02:00
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
2021-04-12 14:32:08 +02:00
to/from the < code > TREXIO< / code > file (except for < code > trexio_has_< / code > functions).
2021-05-07 00:03:17 +02:00
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 dimensioning variables deals with single
precision (see Table above).
2021-04-12 14:32:08 +02:00
< / p >
< 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 > , < span style = "color: #228b22;" > int64_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;
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > if< / span > (trexio_has_$group_num$(file) != TREXIO_SUCCESS) < span style = "color: #a020f0;" > return< / span > TREXIO_ATTR_MISSING;
2021-04-12 14:32:08 +02:00
< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > u_num< / span > = 0;
2021-05-06 18:26:46 +02:00
< span style = "color: #228b22;" > trexio_exit_code< / span > < span style = "color: #a0522d;" > rc< / span > = TREXIO_GROUP_READ_ERROR;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > switch< / span > (file-> back_end) {
< span style = "color: #a020f0;" > case< / span > TREXIO_TEXT:
rc = trexio_text_read_$group_num$(file, & u_num);
< span style = "color: #a020f0;" > break< / span > ;
< span style = "color: #a020f0;" > case< / span > TREXIO_HDF5:
rc = trexio_hdf5_read_$group_num$(file, & u_num);
< 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, & u_num);< / span >
< span style = "color: #b22222;" > break;< / span >
*/
}
< span style = "color: #a020f0;" > if< / span > (rc != TREXIO_SUCCESS) < span style = "color: #a020f0;" > return< / span > rc;
*num = (< span style = "color: #228b22;" > int64_t< / span > ) u_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_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 > < span style = "color: #228b22;" > int64_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: #a020f0;" > if< / span > (num < 0 ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_2;
2021-06-22 22:32:47 +02:00
< span style = "color: #a020f0;" > if< / span > (trexio_has_$group_num$(file) == TREXIO_SUCCESS) < span style = "color: #a020f0;" > return< / span > TREXIO_ATTR_ALREADY_EXISTS;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > switch< / span > (file-> back_end) {
< span style = "color: #a020f0;" > case< / span > TREXIO_TEXT:
2021-06-15 12:12:15 +02:00
< span style = "color: #a020f0;" > return< / span > trexio_text_write_$group_num$(file, (< span style = "color: #228b22;" > int64_t< / span > ) num);
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > break< / span > ;
< span style = "color: #a020f0;" > case< / span > TREXIO_HDF5:
2021-06-15 12:12:15 +02:00
< span style = "color: #a020f0;" > return< / span > trexio_hdf5_write_$group_num$(file, (< span style = "color: #228b22;" > int64_t< / span > ) num);
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > break< / span > ;
/*
< span style = "color: #b22222;" > case TREXIO_JSON:< / span >
2021-06-15 12:12:15 +02:00
< span style = "color: #b22222;" > return trexio_json_write_$group_num$(file, (int64_t) num);< / span >
2021-04-12 14:32:08 +02:00
< span style = "color: #b22222;" > break;< / span >
*/
}
2021-06-15 12:12:15 +02:00
< span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
2021-04-12 14:32:08 +02:00
}
< / 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_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: #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;
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > if< / span > (trexio_has_$group_num$(file) != TREXIO_SUCCESS) < span style = "color: #a020f0;" > return< / span > TREXIO_ATTR_MISSING;
2021-04-12 14:32:08 +02:00
< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > u_num< / span > = 0;
2021-05-06 18:26:46 +02:00
< span style = "color: #228b22;" > trexio_exit_code< / span > < span style = "color: #a0522d;" > rc< / span > = TREXIO_GROUP_READ_ERROR;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > switch< / span > (file-> back_end) {
< span style = "color: #a020f0;" > case< / span > TREXIO_TEXT:
rc = trexio_text_read_$group_num$(file, & u_num);
< span style = "color: #a020f0;" > break< / span > ;
< span style = "color: #a020f0;" > case< / span > TREXIO_HDF5:
rc = trexio_hdf5_read_$group_num$(file, & u_num);
< 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, & u_num);< / span >
< span style = "color: #b22222;" > break;< / span >
*/
}
< span style = "color: #a020f0;" > if< / span > (rc != TREXIO_SUCCESS) < span style = "color: #a020f0;" > return< / span > rc;
*num = (< span style = "color: #228b22;" > int32_t< / span > ) u_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_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 > < 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: #a020f0;" > if< / span > (num < 0 ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_2;
2021-06-22 22:32:47 +02:00
< span style = "color: #a020f0;" > if< / span > (trexio_has_$group_num$(file) == TREXIO_SUCCESS) < span style = "color: #a020f0;" > return< / span > TREXIO_ATTR_ALREADY_EXISTS;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > switch< / span > (file-> back_end) {
< span style = "color: #a020f0;" > case< / span > TREXIO_TEXT:
2021-06-15 12:12:15 +02:00
< span style = "color: #a020f0;" > return< / span > trexio_text_write_$group_num$(file, (< span style = "color: #228b22;" > int64_t< / span > ) num);
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > break< / span > ;
< span style = "color: #a020f0;" > case< / span > TREXIO_HDF5:
2021-06-15 12:12:15 +02:00
< span style = "color: #a020f0;" > return< / span > trexio_hdf5_write_$group_num$(file, (< span style = "color: #228b22;" > int64_t< / span > ) num);
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > break< / span > ;
/*
< span style = "color: #b22222;" > case TREXIO_JSON:< / span >
2021-06-15 12:12:15 +02:00
< span style = "color: #b22222;" > return trexio_json_write_$group_num$(file, (int64_t) num);< / span >
2021-04-12 14:32:08 +02:00
< span style = "color: #b22222;" > break;< / span >
*/
}
2021-06-15 12:12:15 +02:00
< span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
2021-04-12 14:32:08 +02:00
}
< / 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_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;" > return< / span > trexio_read_$group_num$_32(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 > < span style = "color: #228b22;" > int32_t< / span > < span style = "color: #a0522d;" > num< / span > )
{
< span style = "color: #a020f0;" > return< / span > trexio_write_$group_num$_32(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;
2021-05-26 19:12:38 +02:00
assert(file-> back_end < TREXIO_INVALID_BACK_END);
2021-05-19 22:03:41 +02:00
2021-04-12 14:32:08 +02:00
< 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;" > break< / span > ;
< span style = "color: #a020f0;" > case< / span > TREXIO_HDF5:
< span style = "color: #a020f0;" > return< / span > trexio_hdf5_has_$group_num$(file);
< span style = "color: #a020f0;" > break< / 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 >
*/
}
2021-06-15 12:12:15 +02:00
< span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
2021-04-12 14:32:08 +02:00
}
< / pre >
< / div >
< / div >
< / div >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org0ee88e6" class = "outline-4" >
< h4 id = "org0ee88e6" > < span class = "section-number-4" > 3.2.2< / span > Fortran templates for front end< / h4 >
2021-06-15 12:12:15 +02:00
< div class = "outline-text-4" id = "text-3-2-2" >
2021-04-12 14:32:08 +02:00
< 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 > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_write_$group_num$_64< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file, num) bind(C)< / span >
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span >
< span style = "color: #228b22;" > integer< / span > (8), < 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 > (8), < span style = "color: #a020f0;" > intent< / span > (in), < span style = "color: #a020f0;" > value< / span > ::< span style = "color: #a0522d;" > num< / span >
< 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 > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_read_$group_num$_64< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file, num) bind(C)< / span >
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span >
< span style = "color: #228b22;" > integer< / span > (8), < 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 > (8), < 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_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 > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_write_$group_num$_32< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file, num) bind(C)< / span >
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span >
< span style = "color: #228b22;" > integer< / span > (8), < 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 > (4), < span style = "color: #a020f0;" > intent< / span > (in), < span style = "color: #a020f0;" > value< / span > ::< span style = "color: #a0522d;" > num< / span >
< 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 > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_read_$group_num$_32< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file, num) bind(C)< / span >
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span >
< span style = "color: #228b22;" > integer< / span > (8), < 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 > (4), < 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_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 > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_write_$group_num$< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file, num) bind(C)< / span >
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span >
< span style = "color: #228b22;" > integer< / span > (8), < 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 > (4), < span style = "color: #a020f0;" > intent< / span > (in), < span style = "color: #a020f0;" > value< / span > ::< span style = "color: #a0522d;" > num< / span >
< 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 > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_read_$group_num$< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file, num) bind(C)< / span >
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span >
< span style = "color: #228b22;" > integer< / span > (8), < 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 > (4), < 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_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 > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_has_$group_num$< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file) bind(C)< / span >
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span >
< span style = "color: #228b22;" > integer< / span > (8), < 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 >
2021-09-14 11:40:10 +02:00
2021-09-16 16:47:50 +02:00
< div id = "outline-container-orge0091a8" class = "outline-4" >
< h4 id = "orge0091a8" > < span class = "section-number-4" > 3.2.3< / span > Python templates for front end< / h4 >
2021-09-14 11:40:10 +02:00
< div class = "outline-text-4" id = "text-3-2-3" >
< 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: < span style = "color: #483d8b;" > int< / span > ) -> < 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: #a020f0;" > try< / 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)
< span style = "color: #a020f0;" > except< / span > :
< span style = "color: #a020f0;" > raise< / span >
< / 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) -> < span style = "color: #483d8b;" > int< / span > :
< 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: #a020f0;" > try< / 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;" > except< / span > :
< span style = "color: #a020f0;" > raise< / span >
< 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;" > - Exception from trexio.Error class 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: #a020f0;" > try< / 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;" > except< / span > :
< span style = "color: #a020f0;" > raise< / span >
< 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;" > else< / span > :
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > False< / span >
< / pre >
< / div >
< / div >
< / div >
2021-04-12 14:32:08 +02:00
< / div >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org16b99a8" class = "outline-3" >
< h3 id = "org16b99a8" > < span class = "section-number-3" > 3.3< / span > Templates for front end has/read/write a dataset of numerical data< / h3 >
2021-06-15 12:12:15 +02:00
< div class = "outline-text-3" id = "text-3-3" >
2021-04-12 14:32:08 +02:00
< 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 >
2021-05-26 19:12:38 +02:00
< td class = "org-left" > < code > trexio_has_$group_dset$< / code > < / td >
2021-05-07 00:03:17 +02:00
< td class = "org-left" > Check if a dataset exists in a file< / td >
2021-04-12 14:32:08 +02:00
< td class = "org-left" > ---< / td >
< / tr >
< tr >
2021-05-26 19:12:38 +02:00
< td class = "org-left" > < code > trexio_read_$group_dset$< / code > < / td >
2021-09-14 11:40:10 +02:00
< td class = "org-left" > Read a dataset in default precision< / td >
< td class = "org-left" > Double/Single for float/int< / td >
2021-04-12 14:32:08 +02:00
< / tr >
< tr >
2021-05-26 19:12:38 +02:00
< td class = "org-left" > < code > trexio_write_$group_dset$< / code > < / td >
2021-09-14 11:40:10 +02:00
< 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 >
2021-04-12 14:32:08 +02:00
< td class = "org-left" > Double< / td >
< / tr >
< tr >
2021-05-26 19:12:38 +02:00
< td class = "org-left" > < code > trexio_read_$group_dset$_32< / code > < / td >
2021-09-14 11:40:10 +02:00
< td class = "org-left" > Read a dataset in single precision< / td >
2021-04-12 14:32:08 +02:00
< td class = "org-left" > Single< / td >
< / tr >
< tr >
2021-05-26 19:12:38 +02:00
< td class = "org-left" > < code > trexio_write_$group_dset$_32< / code > < / td >
2021-09-14 11:40:10 +02:00
< td class = "org-left" > Write a dataset in single precision< / td >
2021-04-12 14:32:08 +02:00
< td class = "org-left" > Single< / td >
< / tr >
< tr >
2021-05-26 19:12:38 +02:00
< td class = "org-left" > < code > trexio_read_$group_dset$_64< / code > < / td >
2021-09-14 11:40:10 +02:00
< td class = "org-left" > Read a dataset in double precision< / td >
2021-04-12 14:32:08 +02:00
< td class = "org-left" > Double< / td >
< / tr >
< tr >
2021-05-26 19:12:38 +02:00
< td class = "org-left" > < code > trexio_write_$group_dset$_64< / code > < / td >
2021-09-14 11:40:10 +02:00
< td class = "org-left" > Write a dataset in double precision< / td >
2021-04-12 14:32:08 +02:00
< td class = "org-left" > Double< / td >
< / tr >
< / tbody >
< / table >
< / div >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org5e03693" class = "outline-4" >
< h4 id = "org5e03693" > < span class = "section-number-4" > 3.3.1< / span > C templates for front end< / h4 >
2021-06-15 12:12:15 +02:00
< div class = "outline-text-4" id = "text-3-3-1" >
2021-04-12 14:32:08 +02:00
< 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 double precision (see Table above).
< / p >
2021-09-14 11:40:10 +02:00
< / div >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org08b5207" class = "outline-5" >
< h5 id = "org08b5207" > < span class = "section-number-5" > 3.3.1.1< / span > Function declarations< / h5 >
2021-09-14 11:40:10 +02:00
< / div >
2021-04-12 14:32:08 +02:00
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org18b002f" class = "outline-5" >
< h5 id = "org18b002f" > < span class = "section-number-5" > 3.3.1.2< / span > Source code for double precision functions< / h5 >
2021-09-14 11:40:10 +02:00
< div class = "outline-text-5" id = "text-3-3-1-2" >
2021-04-12 14:32:08 +02:00
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span >
2021-05-26 19:12:38 +02:00
< 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$)
2021-04-12 14:32:08 +02:00
{
< 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;
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > if< / span > (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) < span style = "color: #a020f0;" > return< / span > TREXIO_DSET_MISSING;
2021-04-12 14:32:08 +02:00
< 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$};
2021-05-26 19:12:38 +02:00
assert(file-> back_end < TREXIO_INVALID_BACK_END);
2021-05-19 22:03:41 +02:00
2021-06-14 09:35:37 +02:00
rc = TREXIO_FAILURE;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > switch< / span > (file-> back_end) {
< span style = "color: #a020f0;" > case< / span > TREXIO_TEXT:
2021-06-14 09:35:37 +02:00
rc = trexio_text_read_$group_dset$(file, $group_dset$, rank, dims);
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > break< / span > ;
< span style = "color: #a020f0;" > case< / span > TREXIO_HDF5:
2021-06-14 09:35:37 +02:00
rc = trexio_hdf5_read_$group_dset$(file, $group_dset$, rank, dims);
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > break< / span > ;
/*
< span style = "color: #b22222;" > case TREXIO_JSON:< / span >
2021-06-14 09:35:37 +02:00
< span style = "color: #b22222;" > rc = trexio_json_read_$group_dset$(file, $group_dset$, rank, dims);< / span >
2021-04-12 14:32:08 +02:00
< span style = "color: #b22222;" > break;< / span >
*/
}
2021-06-14 09:35:37 +02:00
< 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_single$) 1;
}
}
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
2021-04-12 14:32:08 +02:00
}
< / pre >
< / div >
2021-09-14 11:40:10 +02:00
2021-04-12 14:32:08 +02:00
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span >
2021-05-26 19:12:38 +02:00
< 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$)
2021-04-12 14:32:08 +02:00
{
< 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;
2021-06-04 14:15:51 +02:00
< span style = "color: #a020f0;" > if< / span > (trexio_has_$group_dset$(file) == TREXIO_SUCCESS) < span style = "color: #a020f0;" > return< / span > TREXIO_DSET_ALREADY_EXISTS;
2021-04-12 14:32:08 +02:00
< 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$};
2021-06-15 12:12:15 +02:00
$group_dset_dtype_double$* $group_dset$_p = ($group_dset_dtype_double$*) $group_dset$;
2021-06-14 09:35:37 +02:00
/* < 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];
}
$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$_p[i] - ($group_dset_dtype_single$) 1;
}
}
2021-05-26 19:12:38 +02:00
assert(file-> back_end < TREXIO_INVALID_BACK_END);
2021-05-19 22:03:41 +02:00
2021-06-14 09:35:37 +02:00
rc = TREXIO_FAILURE;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > switch< / span > (file-> back_end) {
< span style = "color: #a020f0;" > case< / span > TREXIO_TEXT:
2021-06-14 09:35:37 +02:00
rc = trexio_text_write_$group_dset$(file, $group_dset$_p, rank, dims);
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > break< / span > ;
< span style = "color: #a020f0;" > case< / span > TREXIO_HDF5:
2021-06-14 09:35:37 +02:00
rc = trexio_hdf5_write_$group_dset$(file, $group_dset$_p, rank, dims);
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > break< / span > ;
/*
< span style = "color: #b22222;" > case TREXIO_JSON:< / span >
2021-06-14 09:35:37 +02:00
< span style = "color: #b22222;" > rc = trexio_json_write_$group_dset$(file, $group_dset$_p, rank, dims);< / span >
2021-04-12 14:32:08 +02:00
< span style = "color: #b22222;" > break;< / span >
*/
}
2021-06-14 09:35:37 +02:00
/* < span style = "color: #b22222;" > Handle index type < / span > */
< span style = "color: #a020f0;" > if< / span > ($is_index$) {
FREE($group_dset$_p);
}
< span style = "color: #a020f0;" > return< / span > rc;
2021-04-12 14:32:08 +02:00
}
< / pre >
< / div >
2021-09-14 11:40:10 +02:00
< / div >
< / div >
2021-04-12 14:32:08 +02:00
2021-09-16 16:47:50 +02:00
< div id = "outline-container-orgf1d90ef" class = "outline-5" >
< h5 id = "orgf1d90ef" > < span class = "section-number-5" > 3.3.1.3< / span > Source code for single precision functions< / h5 >
2021-09-14 11:40:10 +02:00
< div class = "outline-text-5" id = "text-3-3-1-3" >
2021-04-12 14:32:08 +02:00
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span >
2021-05-26 19:12:38 +02:00
< 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$)
2021-04-12 14:32:08 +02:00
{
< 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;
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > if< / span > (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) < span style = "color: #a020f0;" > return< / span > TREXIO_DSET_MISSING;
2021-04-12 14:32:08 +02:00
< 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;
2021-06-14 09:35:37 +02:00
< span style = "color: #a020f0;" > for< / span > (< span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > i< / span > =0; i< rank; ++i){
2021-04-12 14:32:08 +02:00
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;
2021-05-19 22:03:41 +02:00
assert(file-> back_end < TREXIO_INVALID_BACK_END);
rc = TREXIO_FAILURE;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > switch< / span > (file-> back_end) {
< span style = "color: #a020f0;" > case< / span > TREXIO_TEXT:
2021-05-26 19:12:38 +02:00
rc = trexio_text_read_$group_dset$(file, $group_dset$_64, rank, dims);
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > break< / span > ;
< span style = "color: #a020f0;" > case< / span > TREXIO_HDF5:
2021-05-26 19:12:38 +02:00
rc = trexio_hdf5_read_$group_dset$(file, $group_dset$_64, rank, dims);
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > break< / span > ;
/*
< span style = "color: #b22222;" > case TREXIO_JSON:< / span >
2021-05-26 19:12:38 +02:00
< span style = "color: #b22222;" > rc = trexio_json_read_$group_dset$(file, $group_dset$_64, rank, dims);< / span >
2021-04-12 14:32:08 +02:00
< 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;
}
2021-06-14 09:35:37 +02:00
< 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] + ($group_dset_dtype_single$) 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];
}
2021-04-12 14:32:08 +02:00
}
FREE($group_dset$_64);
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
}
< / pre >
< / div >
2021-09-14 11:40:10 +02:00
2021-04-12 14:32:08 +02:00
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span >
2021-05-26 19:12:38 +02:00
< 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$)
2021-04-12 14:32:08 +02:00
{
< 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;
2021-06-04 14:15:51 +02:00
< span style = "color: #a020f0;" > if< / span > (trexio_has_$group_dset$(file) == TREXIO_SUCCESS) < span style = "color: #a020f0;" > return< / span > TREXIO_DSET_ALREADY_EXISTS;
2021-04-12 14:32:08 +02:00
< 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;
2021-06-14 09:35:37 +02:00
< span style = "color: #a020f0;" > for< / span > (< span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > i< / span > =0; i< rank; ++i){
2021-04-12 14:32:08 +02:00
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 reqired since back end only accepts 64-bit data < / span > */
2021-06-14 09:35:37 +02:00
< 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];
}
2021-04-12 14:32:08 +02:00
}
2021-05-19 22:03:41 +02:00
assert(file-> back_end < TREXIO_INVALID_BACK_END);
rc = TREXIO_FAILURE;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > switch< / span > (file-> back_end) {
< span style = "color: #a020f0;" > case< / span > TREXIO_TEXT:
2021-05-26 19:12:38 +02:00
rc = trexio_text_write_$group_dset$(file, $group_dset$_64, rank, dims);
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > break< / span > ;
< span style = "color: #a020f0;" > case< / span > TREXIO_HDF5:
2021-05-26 19:12:38 +02:00
rc = trexio_hdf5_write_$group_dset$(file, $group_dset$_64, rank, dims);
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > break< / span > ;
/*
< span style = "color: #b22222;" > case TREXIO_JSON:< / span >
2021-05-26 19:12:38 +02:00
< span style = "color: #b22222;" > rc = trexio_json_write_$group_dset$(file, $group_dset$_64, rank, dims);< / span >
2021-04-12 14:32:08 +02:00
< 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 >
2021-09-14 11:40:10 +02:00
< / div >
< / div >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org50d0cb1" class = "outline-5" >
< h5 id = "org50d0cb1" > < span class = "section-number-5" > 3.3.1.4< / span > Source code for memory-safe functions< / h5 >
2021-09-14 11:40:10 +02:00
< div class = "outline-text-5" id = "text-3-3-1-4" >
< div class = "org-src-container" >
2021-09-16 16:47:50 +02:00
< pre class = "src src-c" id = "org7f2c2e7" > < span style = "color: #228b22;" > trexio_exit_code< / span > < span style = "color: #a0522d;" > rc< / span > ;
2021-09-14 11:40:10 +02:00
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) < 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) < 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 >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org3ee523b" class = "outline-5" >
< h5 id = "org3ee523b" > < span class = "section-number-5" > 3.3.1.5< / span > Source code for default functions< / h5 >
2021-09-14 11:40:10 +02:00
< div class = "outline-text-5" id = "text-3-3-1-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 >
2021-04-12 14:32:08 +02:00
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span >
2021-05-26 19:12:38 +02:00
< 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$)
2021-04-12 14:32:08 +02:00
{
2021-05-26 19:12:38 +02:00
< span style = "color: #a020f0;" > return< / span > trexio_read_$group_dset$_$default_prec$(file, $group_dset$);
2021-04-12 14:32:08 +02:00
}
< / pre >
< / div >
2021-09-14 11:40:10 +02:00
2021-04-12 14:32:08 +02:00
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span >
2021-05-26 19:12:38 +02:00
< 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$)
2021-04-12 14:32:08 +02:00
{
2021-05-26 19:12:38 +02:00
< span style = "color: #a020f0;" > return< / span > trexio_write_$group_dset$_$default_prec$(file, $group_dset$);
2021-04-12 14:32:08 +02:00
}
< / pre >
< / div >
2021-09-14 11:40:10 +02:00
2021-04-12 14:32:08 +02:00
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span >
2021-05-26 19:12:38 +02:00
< 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 > )
2021-04-12 14:32:08 +02:00
{
< span style = "color: #a020f0;" > if< / span > (file == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_1;
2021-05-19 22:03:41 +02:00
assert(file-> back_end < TREXIO_INVALID_BACK_END);
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > switch< / span > (file-> back_end) {
< span style = "color: #a020f0;" > case< / span > TREXIO_TEXT:
2021-05-26 19:12:38 +02:00
< span style = "color: #a020f0;" > return< / span > trexio_text_has_$group_dset$(file);
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > break< / span > ;
< span style = "color: #a020f0;" > case< / span > TREXIO_HDF5:
2021-05-26 19:12:38 +02:00
< span style = "color: #a020f0;" > return< / span > trexio_hdf5_has_$group_dset$(file);
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > break< / span > ;
/*
< span style = "color: #b22222;" > case TREXIO_JSON:< / span >
2021-05-26 19:12:38 +02:00
< span style = "color: #b22222;" > return trexio_json_has_$group_dset$(file);< / span >
2021-04-12 14:32:08 +02:00
< span style = "color: #b22222;" > break;< / span >
*/
}
2021-05-19 22:03:41 +02:00
< span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
2021-04-12 14:32:08 +02:00
}
< / pre >
< / div >
< / div >
< / div >
2021-09-14 11:40:10 +02:00
< / div >
2021-04-12 14:32:08 +02:00
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org6e6b777" class = "outline-4" >
< h4 id = "org6e6b777" > < span class = "section-number-4" > 3.3.2< / span > Fortran templates for front end< / h4 >
2021-06-15 12:12:15 +02:00
< div class = "outline-text-4" id = "text-3-3-2" >
2021-04-12 14:32:08 +02:00
< 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 >
2021-05-26 19:12:38 +02:00
< span style = "color: #228b22;" > integer < / span > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_write_$group_dset$_64< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file, dset) bind(C)< / span >
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span >
< span style = "color: #228b22;" > integer< / span > (8), < span style = "color: #a020f0;" > intent< / span > (in), < span style = "color: #a020f0;" > value< / span > ::< span style = "color: #a0522d;" > trex_file< / span >
2021-05-08 00:44:30 +02:00
$group_dset_f_dtype_double$, < span style = "color: #a020f0;" > intent< / span > (in) :: dset$group_dset_f_dims$
2021-05-26 19:12:38 +02:00
< span style = "color: #a020f0;" > end function< / span > < span style = "color: #0000ff;" > trexio_write_$group_dset$_64< / span >
2021-04-12 14:32:08 +02:00
< 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 >
2021-05-26 19:12:38 +02:00
< span style = "color: #228b22;" > integer < / span > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_read_$group_dset$_64< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file, dset) bind(C)< / span >
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span >
< span style = "color: #228b22;" > integer< / span > (8), < span style = "color: #a020f0;" > intent< / span > (in), < span style = "color: #a020f0;" > value< / span > ::< span style = "color: #a0522d;" > trex_file< / span >
2021-05-08 00:44:30 +02:00
$group_dset_f_dtype_double$, < span style = "color: #a020f0;" > intent< / span > (out) :: dset$group_dset_f_dims$
2021-05-26 19:12:38 +02:00
< span style = "color: #a020f0;" > end function< / span > < span style = "color: #0000ff;" > trexio_read_$group_dset$_64< / span >
2021-04-12 14:32:08 +02:00
< 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 >
2021-05-26 19:12:38 +02:00
< span style = "color: #228b22;" > integer < / span > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_write_$group_dset$_32< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file, dset) bind(C)< / span >
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span >
< span style = "color: #228b22;" > integer< / span > (8), < span style = "color: #a020f0;" > intent< / span > (in), < span style = "color: #a020f0;" > value< / span > ::< span style = "color: #a0522d;" > trex_file< / span >
2021-05-08 00:44:30 +02:00
$group_dset_f_dtype_single$, < span style = "color: #a020f0;" > intent< / span > (in) :: dset$group_dset_f_dims$
2021-05-26 19:12:38 +02:00
< span style = "color: #a020f0;" > end function< / span > < span style = "color: #0000ff;" > trexio_write_$group_dset$_32< / span >
2021-04-12 14:32:08 +02:00
< 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 >
2021-05-26 19:12:38 +02:00
< span style = "color: #228b22;" > integer < / span > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_read_$group_dset$_32< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file, dset) bind(C)< / span >
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span >
< span style = "color: #228b22;" > integer< / span > (8), < span style = "color: #a020f0;" > intent< / span > (in), < span style = "color: #a020f0;" > value< / span > ::< span style = "color: #a0522d;" > trex_file< / span >
2021-05-08 00:44:30 +02:00
$group_dset_f_dtype_single$, < span style = "color: #a020f0;" > intent< / span > (out) :: dset$group_dset_f_dims$
2021-05-26 19:12:38 +02:00
< span style = "color: #a020f0;" > end function< / span > < span style = "color: #0000ff;" > trexio_read_$group_dset$_32< / span >
2021-04-12 14:32:08 +02:00
< 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 >
2021-05-26 19:12:38 +02:00
< span style = "color: #228b22;" > integer < / span > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_write_$group_dset$< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file, dset) bind(C)< / span >
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span >
< span style = "color: #228b22;" > integer< / span > (8), < span style = "color: #a020f0;" > intent< / span > (in), < span style = "color: #a020f0;" > value< / span > ::< span style = "color: #a0522d;" > trex_file< / span >
2021-05-18 12:16:43 +02:00
$group_dset_f_dtype_default$, < span style = "color: #a020f0;" > intent< / span > (in) :: dset$group_dset_f_dims$
2021-05-26 19:12:38 +02:00
< span style = "color: #a020f0;" > end function< / span > < span style = "color: #0000ff;" > trexio_write_$group_dset$< / span >
2021-04-12 14:32:08 +02:00
< 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 >
2021-05-26 19:12:38 +02:00
< span style = "color: #228b22;" > integer < / span > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_read_$group_dset$< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file, dset) bind(C)< / span >
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span >
< span style = "color: #228b22;" > integer< / span > (8), < span style = "color: #a020f0;" > intent< / span > (in), < span style = "color: #a020f0;" > value< / span > ::< span style = "color: #a0522d;" > trex_file< / span >
2021-05-18 12:16:43 +02:00
$group_dset_f_dtype_default$, < span style = "color: #a020f0;" > intent< / span > (out) :: dset$group_dset_f_dims$
2021-05-26 19:12:38 +02:00
< span style = "color: #a020f0;" > end function< / span > < span style = "color: #0000ff;" > trexio_read_$group_dset$< / span >
2021-04-12 14:32:08 +02:00
< 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 >
2021-05-26 19:12:38 +02:00
< span style = "color: #228b22;" > integer < / span > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_has_$group_dset$< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file) bind(C)< / span >
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span >
< span style = "color: #228b22;" > integer< / span > (8), < span style = "color: #a020f0;" > intent< / span > (in), < span style = "color: #a020f0;" > value< / span > ::< span style = "color: #a0522d;" > trex_file< / span >
2021-05-26 19:12:38 +02:00
< span style = "color: #a020f0;" > end function< / span > < span style = "color: #0000ff;" > trexio_has_$group_dset$< / span >
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > end interface< / span >
< / pre >
< / div >
< / div >
< / div >
2021-09-14 11:40:10 +02:00
2021-09-16 16:47:50 +02:00
< div id = "outline-container-orgebb89b1" class = "outline-4" >
< h4 id = "orgebb89b1" > < span class = "section-number-4" > 3.3.3< / span > Python templates for front end< / h4 >
2021-09-14 11:40:10 +02:00
< div class = "outline-text-4" id = "text-3-3-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, 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;" > - 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: #a020f0;" > try< / span > :
< span style = "color: #a020f0;" > import< / span > numpy < span style = "color: #a020f0;" > as< / span > np
< span style = "color: #a020f0;" > except< / span > < span style = "color: #228b22;" > ImportError< / span > :
< span style = "color: #a020f0;" > raise< / span > < span style = "color: #228b22;" > Exception< / span > (< span style = "color: #8b2252;" > "NumPy cannot be imported."< / 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;" > - 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: #a020f0;" > try< / span > :
< span style = "color: #a020f0;" > import< / span > numpy < span style = "color: #a020f0;" > as< / span > np
< span style = "color: #a020f0;" > except< / span > < span style = "color: #228b22;" > ImportError< / span > :
< span style = "color: #a020f0;" > raise< / span > < span style = "color: #228b22;" > Exception< / span > (< span style = "color: #8b2252;" > "NumPy cannot be imported."< / 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 > dim < span style = "color: #a020f0;" > is< / span > < span style = "color: #008b8b;" > None< / span > < span style = "color: #a020f0;" > or< / 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< / 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< / span > *= dims_list[i]
< 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: #a020f0;" > try< / 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: #a020f0;" > except< / span > :
< span style = "color: #a020f0;" > raise< / span >
< 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: #a020f0;" > try< / span > :
< span style = "color: #a0522d;" > dset_converted< / span > = np.array(dset_64, dtype=dtype)
< span style = "color: #a020f0;" > except< / span > :
< span style = "color: #a020f0;" > raise< / span >
< 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: #a020f0;" > try< / span > :
# < 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;" > except< / span > :
< span style = "color: #a020f0;" > raise< / 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 >
2021-04-12 14:32:08 +02:00
< / div >
2021-06-04 14:15:51 +02:00
2021-09-14 11:40:10 +02:00
< 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;" > - Exception from trexio.Error class 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: #a020f0;" > try< / 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;" > except< / span > :
< span style = "color: #a020f0;" > raise< / span >
< 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;" > else< / span > :
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > False< / span >
< / pre >
< / div >
< / div >
< / div >
< / div >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-orgee32a13" class = "outline-3" >
< h3 id = "orgee32a13" > < span class = "section-number-3" > 3.4< / span > Sparse data structures< / h3 >
2021-06-15 12:12:15 +02:00
< div class = "outline-text-3" id = "text-3-4" >
2021-06-04 14:15:51 +02:00
< 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_num"< / span > : [ < span style = "color: #8b2252;" > "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 \(\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< / code > : the index of the 1st integral we want to read. An
offset of zero implies to read the first integral.< / li >
< li > < code > num< / code > : the number of integrals to read.< / li >
< / ul >
< p >
We provide a function to read a chunk of indices, and a function to
read a chunk of values, because some users might want to read only
the values of the integrals, or only the indices.
< / p >
< p >
Here is an example for the 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_read_chunk_ao_2e_int_eri_index_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 > < span style = "color: #228b22;" > int64_t< / span > < span style = "color: #a0522d;" > offset< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > int64_t< / span > < span style = "color: #a0522d;" > num< / span > ,
< span style = "color: #228b22;" > int32_t< / span > * < span style = "color: #a0522d;" > buffer< / 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 < 0L) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_2;
< span style = "color: #a020f0;" > if< / span > (num < 0L) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_3;
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > rank< / span > = 4; // < span style = "color: #b22222;" > To be set by generator : number of indices< / span >
< span style = "color: #228b22;" > int64_t< / span > < span style = "color: #a0522d;" > nmax< / span > ; // < span style = "color: #b22222;" > Max number of integrals< / span >
< span style = "color: #228b22;" > trexio_exit_code< / span > < span style = "color: #a0522d;" > rc< / span > ;
rc = trexio_read_ao_2e_int_eri_num(< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > file< / span > , & nmax);
< span style = "color: #a020f0;" > if< / span > (rc != TREXIO_SUCCESS) < span style = "color: #a020f0;" > return< / span > rc;
< 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_chunk_ao_2e_int_eri_index(file, buffer, offset, num, rank, nmax);
< span style = "color: #a020f0;" > break< / span > ;
< span style = "color: #a020f0;" > case< / span > TREXIO_HDF5:
< span style = "color: #a020f0;" > return< / span > trexio_hdf5_read_chunk_ao_2e_int_eri_index(file, buffer, offset, num, rank, nmax);
< span style = "color: #a020f0;" > 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 >
< p >
For the values,
< / p >
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span >
< span style = "color: #0000ff;" > trexio_read_chunk_ao_2e_int_eri_value_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 > < span style = "color: #228b22;" > int64_t< / span > < span style = "color: #a0522d;" > offset< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > int64_t< / span > < span style = "color: #a0522d;" > num< / span > ,
< span style = "color: #228b22;" > double< / span > * < span style = "color: #a0522d;" > buffer< / 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 < 0L) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_2;
< span style = "color: #a020f0;" > if< / span > (num < 0L) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_3;
< span style = "color: #228b22;" > int64_t< / span > < span style = "color: #a0522d;" > nmax< / span > ; // < span style = "color: #b22222;" > Max number of integrals< / span >
< span style = "color: #228b22;" > trexio_exit_code< / span > < span style = "color: #a0522d;" > rc< / span > ;
rc = trexio_read_ao_2e_int_eri_num(< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > file< / span > , & nmax);
< span style = "color: #a020f0;" > if< / span > (rc != TREXIO_SUCCESS) < span style = "color: #a020f0;" > return< / span > rc;
< 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_chunk_ao_2e_int_eri_value(file, buffer, offset, num, nmax);
< span style = "color: #a020f0;" > break< / span > ;
< span style = "color: #a020f0;" > case< / span > TREXIO_HDF5:
< span style = "color: #a020f0;" > return< / span > trexio_hdf5_read_chunk_ao_2e_int_eri_index(file, buffer, offset, num, nmax);
< span style = "color: #a020f0;" > 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 >
< / div >
2021-06-15 12:12:15 +02:00
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org513c03a" class = "outline-3" >
< h3 id = "org513c03a" > < span class = "section-number-3" > 3.5< / span > Templates for front end has/read/write a dataset of strings< / h3 >
2021-06-15 12:12:15 +02:00
< div class = "outline-text-3" id = "text-3-5" >
< / div >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-orgdf1d0d1" class = "outline-4" >
< h4 id = "orgdf1d0d1" > < span class = "section-number-4" > 3.5.1< / span > Introduction< / h4 >
2021-06-15 12:12:15 +02:00
< div class = "outline-text-4" id = "text-3-5-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 >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org35ba109" class = "outline-4" >
< h4 id = "org35ba109" > < span class = "section-number-4" > 3.5.2< / span > C templates for front end< / h4 >
2021-06-15 12:12:15 +02:00
< div class = "outline-text-4" id = "text-3-5-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 class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span >
2021-09-14 11:40:10 +02:00
< 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 > )
2021-06-15 12:12:15 +02:00
{
< span style = "color: #a020f0;" > if< / span > (file == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_1;
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > if< / span > (dset_out == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_2;
2021-06-15 12:12:15 +02:00
< span style = "color: #a020f0;" > if< / span > (max_str_len < = 0) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_3;
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > if< / span > (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) < span style = "color: #a020f0;" > return< / span > TREXIO_DSET_MISSING;
2021-06-15 12:12:15 +02:00
< 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:
2021-09-14 11:40:10 +02:00
< 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);
2021-06-15 12:12:15 +02:00
< span style = "color: #a020f0;" > break< / span > ;
< span style = "color: #a020f0;" > case< / span > TREXIO_HDF5:
2021-09-14 11:40:10 +02:00
< 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);
2021-06-15 12:12:15 +02:00
< span style = "color: #a020f0;" > break< / span > ;
/*
< span style = "color: #b22222;" > case TREXIO_JSON:< / span >
2021-09-14 11:40:10 +02:00
< span style = "color: #b22222;" > rc = trexio_json_read_$group_dset$(file, dset_out, rank, dims);< / span >
2021-06-15 12:12:15 +02:00
< span style = "color: #b22222;" > break;< / span >
*/
}
2021-06-17 20:22:36 +02:00
< span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
2021-06-15 12:12:15 +02:00
}
< span style = "color: #228b22;" > trexio_exit_code< / span >
2021-09-14 11:40:10 +02:00
< 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 > )
2021-06-15 12:12:15 +02:00
{
< span style = "color: #a020f0;" > if< / span > (file == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_1;
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > if< / span > (dset_out == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_2;
2021-06-15 12:12:15 +02:00
< span style = "color: #a020f0;" > if< / span > (max_str_len < = 0) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_3;
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > if< / span > (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) < span style = "color: #a020f0;" > return< / span > TREXIO_DSET_MISSING;
2021-06-15 12:12:15 +02:00
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;
}
2021-09-14 11:40:10 +02:00
< 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++) {
2021-06-15 12:12:15 +02:00
2021-09-14 11:40:10 +02:00
< span style = "color: #228b22;" > char< / span > * < span style = "color: #a0522d;" > pch< / span > ;
2021-06-15 12:12:15 +02:00
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;
}
2021-09-14 11:40:10 +02:00
strcpy(dset_out[i], < span style = "color: #8b2252;" > ""< / span > );
strcat(dset_out[i], pch);
2021-06-15 12:12:15 +02:00
}
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 >
2021-09-14 11:40:10 +02:00
< 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: #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 > )
2021-06-15 12:12:15 +02:00
{
< span style = "color: #a020f0;" > if< / span > (file == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_1;
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > if< / span > (dset_in == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_2;
2021-06-15 12:12:15 +02:00
< 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_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 > *);
2021-09-14 11:40:10 +02:00
< 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;
}
2021-06-15 12:12:15 +02:00
/* < 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++) {
2021-09-14 11:40:10 +02:00
< span style = "color: #228b22;" > char< / span > * < span style = "color: #a0522d;" > pch< / span > ;
pch = i == 0 ? strtok( (< span style = "color: #228b22;" > char< / span > *) dset_in, TREXIO_DELIM) : strtok(< span style = "color: #008b8b;" > NULL< / span > , TREXIO_DELIM) ;
2021-06-15 12:12:15 +02:00
< 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;
}
2021-09-14 11:40:10 +02:00
< span style = "color: #228b22;" > size_t< / span > < span style = "color: #a0522d;" > pch_len< / span > = strlen(pch) + 1;
2021-06-15 12:12:15 +02:00
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > if< / span > (pch_len > (< span style = "color: #228b22;" > size_t< / span > ) max_str_len) {
2021-06-15 12:12:15 +02:00
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:
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: #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 >
2021-09-14 11:40:10 +02:00
< 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 > )
2021-06-15 12:12:15 +02:00
{
< span style = "color: #a020f0;" > if< / span > (file == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_1;
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > if< / span > (dset_in == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_2;
2021-06-15 12:12:15 +02:00
< 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_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 > );
2021-09-14 11:40:10 +02:00
< 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]);
2021-06-15 12:12:15 +02:00
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 >
2021-04-12 14:32:08 +02:00
< / div >
2021-06-15 12:12:15 +02:00
< 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;" > break< / span > ;
< span style = "color: #a020f0;" > case< / span > TREXIO_HDF5:
< span style = "color: #a020f0;" > return< / span > trexio_hdf5_has_$group_dset$(file);
< span style = "color: #a020f0;" > break< / 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 >
*/
}
2021-06-17 20:22:36 +02:00
2021-06-15 12:12:15 +02:00
< span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
}
< / pre >
< / div >
< / div >
< / div >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org1e652ee" class = "outline-4" >
< h4 id = "org1e652ee" > < span class = "section-number-4" > 3.5.3< / span > Fortran templates for front end< / h4 >
2021-06-15 12:12:15 +02:00
< 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 > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_write_$group_dset$_low< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file, dset, max_str_len) bind(C)< / span >
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span >
< span style = "color: #228b22;" > integer< / span > (8), < 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 > , < span style = "color: #a020f0;" > intent< / span > (in) ::< span style = "color: #a0522d;" > dset(*)< / span >
< span style = "color: #228b22;" > integer< / span > (4), < 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 > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_read_$group_dset$_low< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file, dset, max_str_len) bind(C)< / span >
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span >
< span style = "color: #228b22;" > integer< / span > (8), < 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 > , < span style = "color: #a020f0;" > intent< / span > (out) ::< span style = "color: #a0522d;" > dset(*)< / span >
< span style = "color: #228b22;" > integer< / span > (4), < 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 > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_has_$group_dset$< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file) bind(C)< / span >
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span >
< span style = "color: #228b22;" > integer< / span > (8), < 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 > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_read_$group_dset$< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file, dset, max_str_len)< / span >
< span style = "color: #a020f0;" > implicit< / span > < span style = "color: #228b22;" > none< / span >
< span style = "color: #228b22;" > integer< / span > (8), < 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 > (4), < 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 > (8) ::< span style = "color: #a0522d;" > $group_dset_dim$< / span >
< span style = "color: #228b22;" > integer< / span > ::< 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 > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_write_$group_dset$< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file, dset, max_str_len)< / span >
< span style = "color: #a020f0;" > implicit< / span > < span style = "color: #228b22;" > none< / span >
< span style = "color: #228b22;" > integer< / span > (8), < 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 > (4), < 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 > (8) ::< span style = "color: #a0522d;" > $group_dset_dim$< / span >
< span style = "color: #228b22;" > integer< / span > ::< 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$, max_str_len, 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 >
2021-09-14 11:40:10 +02:00
2021-09-16 16:47:50 +02:00
< div id = "outline-container-orgd6a6924" class = "outline-4" >
< h4 id = "orgd6a6924" > < span class = "section-number-4" > 3.5.4< / span > Python templates for front end< / h4 >
2021-09-14 11:40:10 +02:00
< 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, 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: #a020f0;" > try< / span > :
< 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)
< span style = "color: #a020f0;" > except< / span > :
< span style = "color: #a020f0;" > raise< / span >
< / pre >
2021-06-15 12:12:15 +02:00
< / div >
2021-09-14 11:40:10 +02:00
< 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 >
# < span style = "color: #b22222;" > if dim is not specified, read dimensions from the TREXIO file< / span >
< span style = "color: #a020f0;" > if< / span > dim < span style = "color: #a020f0;" > is< / span > < span style = "color: #008b8b;" > None< / 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< / 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< / span > *= dims_list[i]
< span style = "color: #a020f0;" > try< / span > :
< 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: #a020f0;" > except< / span > :
< span style = "color: #a020f0;" > raise< / span >
< span style = "color: #a020f0;" > try< / span > :
< 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;" > except< / span > :
< span style = "color: #a020f0;" > raise< / 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;" > - Exception from trexio.Error class 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: #a020f0;" > try< / 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;" > except< / span > :
< span style = "color: #a020f0;" > raise< / span >
< 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;" > else< / span > :
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > False< / span >
< / pre >
< / div >
< / div >
< / div >
< / div >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org5deaed0" class = "outline-3" >
< h3 id = "org5deaed0" > < span class = "section-number-3" > 3.6< / span > Templates for front end has/read/write a single string attribute< / h3 >
2021-06-15 12:12:15 +02:00
< div class = "outline-text-3" id = "text-3-6" >
< / div >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org414340f" class = "outline-4" >
< h4 id = "org414340f" > < span class = "section-number-4" > 3.6.1< / span > Introduction< / h4 >
2021-06-15 12:12:15 +02:00
< div class = "outline-text-4" id = "text-3-6-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 >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-orgc82d373" class = "outline-4" >
< h4 id = "orgc82d373" > < span class = "section-number-4" > 3.6.2< / span > C templates for front end< / h4 >
2021-06-15 12:12:15 +02:00
< div class = "outline-text-4" id = "text-3-6-2" >
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span >
2021-09-14 11:40:10 +02:00
< 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 > )
2021-06-15 12:12:15 +02:00
{
< span style = "color: #a020f0;" > if< / span > (file == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_1;
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > if< / span > (str_out == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_2;
2021-06-15 12:12:15 +02:00
< span style = "color: #a020f0;" > if< / span > (max_str_len < = 0) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_3;
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > if< / span > (trexio_has_$group_str$(file) != TREXIO_SUCCESS) < span style = "color: #a020f0;" > return< / span > TREXIO_ATTR_MISSING;
2021-06-15 12:12:15 +02:00
< span style = "color: #a020f0;" > switch< / span > (file-> back_end) {
< span style = "color: #a020f0;" > case< / span > TREXIO_TEXT:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > trexio_text_read_$group_str$(file, str_out, (< span style = "color: #228b22;" > uint32_t< / span > ) max_str_len);
2021-06-15 12:12:15 +02:00
< span style = "color: #a020f0;" > break< / span > ;
< span style = "color: #a020f0;" > case< / span > TREXIO_HDF5:
2021-09-14 11:40:10 +02:00
< span style = "color: #a020f0;" > return< / span > trexio_hdf5_read_$group_str$(file, str_out, (< span style = "color: #228b22;" > uint32_t< / span > ) max_str_len);
2021-06-15 12:12:15 +02:00
< span style = "color: #a020f0;" > break< / 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 >
*/
}
2021-06-17 20:22:36 +02:00
< span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
2021-06-15 12:12:15 +02:00
}
< / pre >
< / div >
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span >
2021-09-14 11:40:10 +02:00
< 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 > )
2021-06-15 12:12:15 +02:00
{
< 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;
2021-06-22 22:32:47 +02:00
< span style = "color: #a020f0;" > if< / span > (trexio_has_$group_str$(file) == TREXIO_SUCCESS) < span style = "color: #a020f0;" > return< / span > TREXIO_ATTR_ALREADY_EXISTS;
2021-06-15 12:12:15 +02:00
< span style = "color: #228b22;" > size_t< / span > < span style = "color: #a0522d;" > len_write< / span > = strlen(str);
2021-09-14 11:40:10 +02:00
< 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;
2021-06-15 12:12:15 +02:00
< 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;" > break< / span > ;
< span style = "color: #a020f0;" > case< / span > TREXIO_HDF5:
< span style = "color: #a020f0;" > return< / span > trexio_hdf5_write_$group_str$(file, str);
< span style = "color: #a020f0;" > break< / 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: #b22222;" > break;< / span >
*/
}
2021-06-17 20:22:36 +02:00
< span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
2021-06-15 12:12:15 +02:00
}
< / 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;" > break< / span > ;
< span style = "color: #a020f0;" > case< / span > TREXIO_HDF5:
< span style = "color: #a020f0;" > return< / span > trexio_hdf5_has_$group_str$(file);
< span style = "color: #a020f0;" > break< / span > ;
/*
< span style = "color: #b22222;" > case TREXIO_JSON:< / span >
< span style = "color: #b22222;" > return trexio_json_has_$group_str$(file);< / span >
< span style = "color: #b22222;" > break;< / span >
*/
}
< span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
}
< / pre >
< / div >
< / div >
< / div >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-orgbb17101" class = "outline-4" >
< h4 id = "orgbb17101" > < span class = "section-number-4" > 3.6.3< / span > Fortran templates for front end< / h4 >
2021-06-15 12:12:15 +02:00
< 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 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 > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_write_$group_str$_c< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file, str, max_str_len)< / span > < 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;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span >
< span style = "color: #228b22;" > integer< / span > (8), < 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 > , < span style = "color: #a020f0;" > intent< / span > (in) ::< span style = "color: #a0522d;" > str(*)< / span >
< span style = "color: #228b22;" > integer< / span > (4), < 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 > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_read_$group_str$_c< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file, str, max_str_len)< / span > < 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;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span >
< span style = "color: #228b22;" > integer< / span > (8), < 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 > , < span style = "color: #a020f0;" > intent< / span > (out) ::< span style = "color: #a0522d;" > str(*)< / span >
< span style = "color: #228b22;" > integer< / span > (4), < 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 > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_has_$group_str$< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file) bind(C)< / span >
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span >
< span style = "color: #228b22;" > integer< / span > (8), < 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 > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_read_$group_str$< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file, str, max_str_len)< / span >
< span style = "color: #a020f0;" > implicit< / span > < span style = "color: #228b22;" > none< / span >
< span style = "color: #228b22;" > integer< / span > (8), < 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 > (4), < 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 > < span style = "color: #a020f0;" > function< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #0000ff;" > trexio_write_$group_str$< / span > < span style = "color: #a0522d;" > < / span > < span style = "color: #000000; background-color: #ffffff;" > (trex_file, str, max_str_len)< / span >
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span > , < span style = "color: #a020f0;" > only< / span > : < span style = "color: #008b8b;" > c_null_char< / span >
< span style = "color: #a020f0;" > implicit< / span > < span style = "color: #228b22;" > none< / span >
< span style = "color: #228b22;" > integer< / span > (8), < 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 > (4), < 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 >
2021-09-14 11:40:10 +02:00
2021-09-16 16:47:50 +02:00
< div id = "outline-container-orgb00c204" class = "outline-4" >
< h4 id = "orgb00c204" > < span class = "section-number-4" > 3.6.4< / span > Python templates for front end< / h4 >
2021-09-14 11:40:10 +02:00
< 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_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: #a020f0;" > try< / span > :
< 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)
< span style = "color: #a020f0;" > except< / span > :
< span style = "color: #a020f0;" > raise< / span >
< / 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: #a020f0;" > try< / 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;" > except< / span > :
< span style = "color: #a020f0;" > raise< / span >
< 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;" > - Exception from trexio.Error class 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: #a020f0;" > try< / 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;" > except< / span > :
< span style = "color: #a020f0;" > raise< / span >
< 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;" > else< / span > :
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > False< / span >
< / pre >
< / div >
< / div >
< / div >
2021-06-15 12:12:15 +02:00
< / div >
< / div >
2021-09-16 16:47:50 +02:00
< div id = "outline-container-org7bba65f" class = "outline-2" >
< h2 id = "org7bba65f" > < span class = "section-number-2" > 4< / span > Fortran helper/wrapper functions< / h2 >
2021-04-12 14:32:08 +02:00
< div class = "outline-text-2" id = "text-4" >
< 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: #a020f0;" > contains< / span >
< span style = "color: #228b22;" > integer< / span > (8) < span style = "color: #a020f0;" > function< / span > < span style = "color: #0000ff;" > trexio_open< / span > (filename, mode, backend)
2021-06-15 12:12:15 +02:00
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span > , < span style = "color: #a020f0;" > only< / span > : < span style = "color: #008b8b;" > c_null_char< / span >
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > implicit< / span > < span style = "color: #228b22;" > none< / span >
2021-06-15 12:12:15 +02:00
< span style = "color: #228b22;" > character< / span > (len=*), < span style = "color: #a020f0;" > intent< / span > (in) ::< span style = "color: #a0522d;" > filename< / span >
2021-06-14 09:35:37 +02:00
< 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 >
2021-06-04 18:16:31 +02:00
< span style = "color: #228b22;" > integer< / span > (trexio_backend), < span style = "color: #a020f0;" > intent< / span > (in), < span style = "color: #a020f0;" > value< / span > ::< span style = "color: #a0522d;" > backend< / span >
2021-04-12 14:32:08 +02:00
< span style = "color: #228b22;" > character< / span > (len=< span style = "color: #a020f0;" > len_trim< / span > (filename)+1) ::< span style = "color: #a0522d;" > filename_c< / span >
2021-06-14 09:35:37 +02:00
< span style = "color: #228b22;" > integer< / span > ::< span style = "color: #a0522d;" > rc< / span >
2021-04-12 14:32:08 +02:00
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, backend)
2021-06-14 09:35:37 +02:00
< span style = "color: #a020f0;" > if< / span > (trexio_open == 0_8) < 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 >
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > end function< / span > < span style = "color: #0000ff;" > trexio_open< / span >
< / pre >
< / div >
2021-06-15 12:12:15 +02:00
< 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, max_len_str, str_res)
< span style = "color: #a020f0;" > use< / span > , < span style = "color: #a020f0;" > intrinsic< / span > :: < span style = "color: #0000ff;" > iso_c_binding< / span > , < span style = "color: #a020f0;" > only< / span > : < span style = "color: #008b8b;" > c_null_char< / span >
< span style = "color: #a020f0;" > implicit< / span > < span style = "color: #228b22;" > none< / span >
< span style = "color: #228b22;" > integer< / span > (8), < 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 > (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: #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 > (8), < 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 > , < 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: #a0522d;" > i, j, k, ind, offset< / span >
< span style = "color: #228b22;" > integer< / span > (8) ::< span style = "color: #a0522d;" > len_flat< / span >
len_flat = (max_len_str+1)*max_num_str + 1
ind=1
offset=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
offset=ind
< 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;" > call< / span > < span style = "color: #0000ff;" > exit< / span > (1)
< span style = "color: #a020f0;" > endif< / span >
< span style = "color: #a020f0;" > end subroutine< / span > < span style = "color: #0000ff;" > trexio_assert< / span >
< / pre >
< / div >
2021-04-12 14:32:08 +02:00
< / div >
< / div >
< / div >
< div id = "postamble" class = "status" >
< p class = "author" > Author: TREX-CoE< / p >
2021-09-16 16:47:50 +02:00
< p class = "date" > Created: 2021-09-16 Thu 14:47< / p >
2021-04-12 14:32:08 +02:00
< p class = "validation" > < a href = "http://validator.w3.org/check?uri=referer" > Validate< / a > < / p >
< / div >
< / body >
< / html >