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 >
2022-07-28 13:50:07 +02:00
<!-- 2022 - 07 - 28 Thu 11:50 -->
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" / >
< title > TEXT back end< / title >
< meta name = "generator" content = "Org mode" / >
< meta name = "author" content = "TREX-CoE" / >
< style type = "text/css" >
<!-- /* --> <![CDATA[/*> <!-- */
.title { text-align: center;
margin-bottom: .2em; }
.subtitle { text-align: center;
font-size: medium;
font-weight: bold;
margin-top:0; }
.todo { font-family: monospace; color: red; }
.done { font-family: monospace; color: green; }
.priority { font-family: monospace; color: orange; }
.tag { background-color: #eee; font-family: monospace;
padding: 2px; font-size: 80%; font-weight: normal; }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
.org-right { margin-left: auto; margin-right: 0px; text-align: right; }
.org-left { margin-left: 0px; margin-right: auto; text-align: left; }
.org-center { margin-left: auto; margin-right: auto; text-align: center; }
.underline { text-decoration: underline; }
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
p.verse { margin-left: 3%; }
pre {
border: 1px solid #ccc;
box-shadow: 3px 3px 3px #eee;
padding: 8pt;
font-family: monospace;
overflow: auto;
margin: 1.2em;
}
pre.src {
position: relative;
overflow: visible;
padding-top: 1.2em;
}
pre.src:before {
display: none;
position: absolute;
background-color: white;
top: -10px;
right: 10px;
padding: 3px;
border: 1px solid black;
}
pre.src:hover:before { display: inline;}
/* Languages per Org manual */
pre.src-asymptote:before { content: 'Asymptote'; }
pre.src-awk:before { content: 'Awk'; }
pre.src-C:before { content: 'C'; }
/* pre.src-C++ doesn't work in CSS */
pre.src-clojure:before { content: 'Clojure'; }
pre.src-css:before { content: 'CSS'; }
pre.src-D:before { content: 'D'; }
pre.src-ditaa:before { content: 'ditaa'; }
pre.src-dot:before { content: 'Graphviz'; }
pre.src-calc:before { content: 'Emacs Calc'; }
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
pre.src-fortran:before { content: 'Fortran'; }
pre.src-gnuplot:before { content: 'gnuplot'; }
pre.src-haskell:before { content: 'Haskell'; }
pre.src-hledger:before { content: 'hledger'; }
pre.src-java:before { content: 'Java'; }
pre.src-js:before { content: 'Javascript'; }
pre.src-latex:before { content: 'LaTeX'; }
pre.src-ledger:before { content: 'Ledger'; }
pre.src-lisp:before { content: 'Lisp'; }
pre.src-lilypond:before { content: 'Lilypond'; }
pre.src-lua:before { content: 'Lua'; }
pre.src-matlab:before { content: 'MATLAB'; }
pre.src-mscgen:before { content: 'Mscgen'; }
pre.src-ocaml:before { content: 'Objective Caml'; }
pre.src-octave:before { content: 'Octave'; }
pre.src-org:before { content: 'Org mode'; }
pre.src-oz:before { content: 'OZ'; }
pre.src-plantuml:before { content: 'Plantuml'; }
pre.src-processing:before { content: 'Processing.js'; }
pre.src-python:before { content: 'Python'; }
pre.src-R:before { content: 'R'; }
pre.src-ruby:before { content: 'Ruby'; }
pre.src-sass:before { content: 'Sass'; }
pre.src-scheme:before { content: 'Scheme'; }
pre.src-screen:before { content: 'Gnu Screen'; }
pre.src-sed:before { content: 'Sed'; }
pre.src-sh:before { content: 'shell'; }
pre.src-sql:before { content: 'SQL'; }
pre.src-sqlite:before { content: 'SQLite'; }
/* additional languages in org.el's org-babel-load-languages alist */
pre.src-forth:before { content: 'Forth'; }
pre.src-io:before { content: 'IO'; }
pre.src-J:before { content: 'J'; }
pre.src-makefile:before { content: 'Makefile'; }
pre.src-maxima:before { content: 'Maxima'; }
pre.src-perl:before { content: 'Perl'; }
pre.src-picolisp:before { content: 'Pico Lisp'; }
pre.src-scala:before { content: 'Scala'; }
pre.src-shell:before { content: 'Shell Script'; }
pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
/* additional language identifiers per "defun org-babel-execute"
in ob-*.el */
pre.src-cpp:before { content: 'C++'; }
pre.src-abc:before { content: 'ABC'; }
pre.src-coq:before { content: 'Coq'; }
pre.src-groovy:before { content: 'Groovy'; }
/* additional language identifiers from org-babel-shell-names in
ob-shell.el: ob-shell is the only babel language using a lambda to put
the execution function name together. */
pre.src-bash:before { content: 'bash'; }
pre.src-csh:before { content: 'csh'; }
pre.src-ash:before { content: 'ash'; }
pre.src-dash:before { content: 'dash'; }
pre.src-ksh:before { content: 'ksh'; }
pre.src-mksh:before { content: 'mksh'; }
pre.src-posh:before { content: 'posh'; }
/* Additional Emacs modes also supported by the LaTeX listings package */
pre.src-ada:before { content: 'Ada'; }
pre.src-asm:before { content: 'Assembler'; }
pre.src-caml:before { content: 'Caml'; }
pre.src-delphi:before { content: 'Delphi'; }
pre.src-html:before { content: 'HTML'; }
pre.src-idl:before { content: 'IDL'; }
pre.src-mercury:before { content: 'Mercury'; }
pre.src-metapost:before { content: 'MetaPost'; }
pre.src-modula-2:before { content: 'Modula-2'; }
pre.src-pascal:before { content: 'Pascal'; }
pre.src-ps:before { content: 'PostScript'; }
pre.src-prolog:before { content: 'Prolog'; }
pre.src-simula:before { content: 'Simula'; }
pre.src-tcl:before { content: 'tcl'; }
pre.src-tex:before { content: 'TeX'; }
pre.src-plain-tex:before { content: 'Plain TeX'; }
pre.src-verilog:before { content: 'Verilog'; }
pre.src-vhdl:before { content: 'VHDL'; }
pre.src-xml:before { content: 'XML'; }
pre.src-nxml:before { content: 'XML'; }
/* add a generic configuration mode; LaTeX export needs an additional
(add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
pre.src-conf:before { content: 'Configuration File'; }
table { border-collapse:collapse; }
caption.t-above { caption-side: top; }
caption.t-bottom { caption-side: bottom; }
td, th { vertical-align:top; }
th.org-right { text-align: center; }
th.org-left { text-align: center; }
th.org-center { text-align: center; }
td.org-right { text-align: right; }
td.org-left { text-align: left; }
td.org-center { text-align: center; }
dt { font-weight: bold; }
.footpara { display: inline; }
.footdef { margin-bottom: 1em; }
.figure { padding: 1em; }
.figure p { text-align: center; }
.inlinetask {
padding: 10px;
border: 2px solid gray;
margin: 10px;
background: #ffffcc;
}
#org-div-home-and-up
{ text-align: right; font-size: 70%; white-space: nowrap; }
textarea { overflow-x: auto; }
.linenr { font-size: smaller }
.code-highlighted { background-color: #ffff00; }
.org-info-js_info-navigation { border-style: none; }
#org-info-js_console-label
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
.org-info-js_search-highlight
{ background-color: #ffff00; color: #000000; font-weight: bold; }
.org-svg { width: 90%; }
/*]]>*/-->
< / style >
< link rel = "stylesheet" title = "Standard" href = "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 >
< / head >
< body >
< div id = "org-div-home-and-up" >
< a accesskey = "h" href = "" > UP < / a >
|
< a accesskey = "H" href = "index.html" > HOME < / a >
< / div > < div id = "content" >
< h1 class = "title" > TEXT back end< / h1 >
< div id = "table-of-contents" >
< h2 > Table of Contents< / h2 >
< div id = "text-table-of-contents" >
< ul >
2022-07-28 13:50:07 +02:00
< li > < a href = "#org6f1b301" > 1. Template for group-related structures in text back end< / a > < / li >
< li > < a href = "#org483f360" > 2. Template for general structure in text back end< / a > < / li >
< li > < a href = "#org9e4f4cc" > 3. Initialize function (constant part)< / a > < / li >
< li > < a href = "#org3d9c5cd" > 4. Deinitialize function (templated part)< / a > < / li >
< li > < a href = "#org9a0027c" > 5. Template for text read a group< / a > < / li >
< li > < a href = "#org2d3bdcc" > 6. Template for text has a group< / a > < / li >
< li > < a href = "#org13fb100" > 7. Template for text flush a group< / a > < / li >
< li > < a href = "#orgc84ab8d" > 8. Template for text free memory< / a > < / li >
< li > < a href = "#orgdb5dede" > 9. Template for has/read/write a numerical attribute< / a > < / li >
< li > < a href = "#org8d367b7" > 10. Template for has/read/write a dataset of numerical data< / a > < / li >
< li > < a href = "#org2bfe1f8" > 11. Template for has/read/write a dataset of strings< / a > < / li >
< li > < a href = "#org28a7228" > 12. Template for has/read/write a string attribute< / a > < / li >
< li > < a href = "#orgc3668ab" > 13. Template for has/read/write the dataset of sparse data< / a > < / li >
< li > < a href = "#orga16bb1f" > 14. Template for text delete a group (UNSAFE mode)< / a > < / li >
< li > < a href = "#org2142971" > 15. Source code for the determinant part< / a > < / li >
2021-04-12 14:32:08 +02:00
< / ul >
< / div >
< / div >
< p >
The "file" produced by the text back end is a directory with one
file per group.
< / p >
< p >
When the file is open, it is locked by the current process. No other
process can read/write the same file. This guarantees that the
representation in memory is consistent with the file and avoid
re-reading the file before writing.
To lock the file, we lock the < code > .lock< / code > file which is present in the
directory.
< / p >
< p >
The file is written when closed, or when the flush function is called.
< / p >
2022-07-28 13:50:07 +02:00
< div id = "outline-container-org6f1b301" class = "outline-2" >
< h2 id = "org6f1b301" > < span class = "section-number-2" > 1< / span > Template for group-related structures in text back end< / h2 >
2022-04-23 19:25:51 +02:00
< div class = "outline-text-2" id = "text-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: #a020f0;" > struct< / span > $group$_s {
2021-09-22 13:34:44 +02:00
$group_num_dtype_double$ $group_num$;
2021-04-12 14:32:08 +02:00
$group_dset_dtype$* $group_dset$;
< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > dims_$group_dset$< / span > [16];
2021-06-15 12:12:15 +02:00
< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > len_$group_str$< / span > ;
2022-02-16 14:52:14 +01:00
< span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > rank_$group_dset$< / span > ;
< span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > to_flush< / span > ;
bool $group_num$_isSet;
2021-06-15 12:12:15 +02:00
< span style = "color: #228b22;" > char< / span > * $group_str$;
2021-05-06 19:41:32 +02:00
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > file_name< / span > [TREXIO_MAX_FILENAME_LENGTH];
2021-04-12 14:32:08 +02:00
} $group$_t;
< / pre >
< / div >
< / div >
< / div >
2022-07-28 13:50:07 +02:00
< div id = "outline-container-org483f360" class = "outline-2" >
< h2 id = "org483f360" > < span class = "section-number-2" > 2< / span > Template for general structure in text back end< / h2 >
2022-04-23 19:25:51 +02:00
< div class = "outline-text-2" id = "text-2" >
2022-05-19 17:24:20 +02:00
< 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 > trexio_t parent< / code > attribute:
< / p >
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: #a020f0;" > struct< / span > < span style = "color: #228b22;" > trexio_text_s< / span > {
< span style = "color: #228b22;" > trexio_t< / span > < span style = "color: #a0522d;" > parent< / span > ;
$group$_t* $group$;
< span style = "color: #228b22;" > int< / span > < span style = "color: #a0522d;" > lock_file< / span > ;
} < span style = "color: #228b22;" > trexio_text_t< / span > ;
< / pre >
< / div >
< / div >
< / div >
2022-07-28 13:50:07 +02:00
< div id = "outline-container-org9e4f4cc" class = "outline-2" >
< h2 id = "org9e4f4cc" > < span class = "section-number-2" > 3< / span > Initialize function (constant part)< / h2 >
2022-04-23 19:25:51 +02:00
< div class = "outline-text-2" id = "text-3" >
2022-07-04 13:02:49 +02:00
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > bool< / span >
< span style = "color: #0000ff;" > trexio_text_file_exists< / span > (< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > char< / span > * < span style = "color: #a0522d;" > file_name< / span > )
{
/* < span style = "color: #b22222;" > Check if the file with "file_name" exists < / span > */
< span style = "color: #a020f0;" > struct< / span > < span style = "color: #228b22;" > stat< / span > < span style = "color: #a0522d;" > st< / span > ;
< span style = "color: #228b22;" > int< / span > < span style = "color: #a0522d;" > rc< / span > = stat(file_name, & st);
< span style = "color: #228b22;" > bool< / span > < span style = "color: #a0522d;" > file_exists< / span > = rc == 0;
< span style = "color: #a020f0;" > return< / span > file_exists;
}
< / 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 >
2022-01-19 15:14:51 +01:00
< span style = "color: #0000ff;" > trexio_text_inquire< / span > (< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > char< / span > * < span style = "color: #a0522d;" > file_name< / span > )
2021-04-12 14:32:08 +02:00
{
2022-01-19 15:14:51 +01:00
/* < span style = "color: #b22222;" > Check if the file with "file_name" exists and that it is a directory < / span > */
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > struct< / span > < span style = "color: #228b22;" > stat< / span > < span style = "color: #a0522d;" > st< / span > ;
2022-01-19 15:14:51 +01:00
< span style = "color: #228b22;" > int< / span > < span style = "color: #a0522d;" > rc< / span > = stat(file_name, & st);
2021-10-13 17:44:31 +02:00
< span style = "color: #228b22;" > bool< / span > < span style = "color: #a0522d;" > file_exists< / span > = rc == 0;
< span style = "color: #a020f0;" > if< / span > (file_exists) {
2022-07-11 16:38:25 +02:00
< span style = "color: #228b22;" > bool< / span > < span style = "color: #a0522d;" > is_a_directory< / span > = < span style = "color: #008b8b;" > false< / span > ;
< span style = "color: #483d8b;" > #ifdef< / span > S_IFDIR
is_a_directory = st.st_mode & S_IFDIR;
< span style = "color: #483d8b;" > #elif< / span > S_ISDIR
is_a_directory = S_ISDIR(s.st_mode);
< span style = "color: #483d8b;" > #else< / span >
printf(< span style = "color: #8b2252;" > "Some important macros are missing for directory handling.\n"< / span > );
< span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
< span style = "color: #483d8b;" > #endif< / span >
2022-01-19 15:14:51 +01:00
< span style = "color: #a020f0;" > if< / span > (!is_a_directory) < span style = "color: #a020f0;" > return< / span > TREXIO_FILE_ERROR;
2021-10-13 17:44:31 +02:00
2022-01-19 15:14:51 +01:00
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
2021-04-12 14:32:08 +02:00
} < span style = "color: #a020f0;" > else< / span > {
2022-01-19 15:14:51 +01:00
< span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
}
}
< / pre >
< / div >
2021-04-12 14:32:08 +02:00
2022-01-19 15:14:51 +01:00
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span >
< span style = "color: #0000ff;" > trexio_text_init< / span > (< span style = "color: #228b22;" > trexio_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > file< / span > )
{
< span style = "color: #a020f0;" > if< / span > (file == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_1;
< span style = "color: #228b22;" > trexio_text_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > f< / span > = (< span style = "color: #228b22;" > trexio_text_t< / span > *) file;
/* < span style = "color: #b22222;" > Put all pointers to NULL but leave parent untouched < / span > */
memset(& (f-> parent)+1,0,< span style = "color: #a020f0;" > sizeof< / span > (trexio_text_t)-< span style = "color: #a020f0;" > sizeof< / span > (trexio_t));
/* < span style = "color: #b22222;" > Check if directory exists < / span > */
< span style = "color: #228b22;" > trexio_exit_code< / span > < span style = "color: #a0522d;" > rc< / span > ;
rc = trexio_text_inquire(file-> file_name);
/* < span style = "color: #b22222;" > TREXIO file exists but is not a directory < / span > */
< span style = "color: #a020f0;" > if< / span > (rc == TREXIO_FILE_ERROR) < span style = "color: #a020f0;" > return< / span > rc;
/* < span style = "color: #b22222;" > If directory does not exist - create it in write mode < / span > */
< span style = "color: #a020f0;" > if< / span > (rc == TREXIO_FAILURE) {
< span style = "color: #a020f0;" > if< / span > (file-> mode == < span style = "color: #8b2252;" > 'r'< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_READONLY;
< span style = "color: #228b22;" > int< / span > < span style = "color: #a0522d;" > rc_dir< / span > = mkdir(file-> file_name, 0777);
< span style = "color: #a020f0;" > if< / span > (rc_dir != 0) < span style = "color: #a020f0;" > return< / span > TREXIO_ERRNO;
2021-10-13 17:44:31 +02:00
2021-04-12 14:32:08 +02:00
}
/* < span style = "color: #b22222;" > Create the lock file in the directory < / span > */
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > char< / span > * < span style = "color: #a0522d;" > lock_file_name< / span > = < span style = "color: #8b2252;" > "/.lock"< / span > ;
2021-05-06 19:41:32 +02:00
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > file_name< / span > [TREXIO_MAX_FILENAME_LENGTH];
2021-04-12 14:32:08 +02:00
2021-05-04 10:04:57 +02:00
strncpy (file_name, file-> file_name, TREXIO_MAX_FILENAME_LENGTH);
strncat (file_name, lock_file_name, TREXIO_MAX_FILENAME_LENGTH-strlen(lock_file_name));
< span style = "color: #a020f0;" > if< / span > (file_name[TREXIO_MAX_FILENAME_LENGTH-1] != < span style = "color: #8b2252;" > '\0'< / span > ) {
2021-05-06 19:41:32 +02:00
< span style = "color: #a020f0;" > return< / span > TREXIO_LOCK_ERROR;
2021-05-04 10:04:57 +02:00
}
2021-04-12 14:32:08 +02:00
f-> lock_file = open(file_name,O_WRONLY|O_CREAT|O_TRUNC, 0644);
< span style = "color: #a020f0;" > if< / span > (f-> lock_file < = 0) {
2021-10-13 17:44:31 +02:00
< span style = "color: #a020f0;" > if< / span > (file-> mode != < span style = "color: #8b2252;" > 'r'< / span > ) {
< span style = "color: #a020f0;" > return< / span > TREXIO_ERRNO;
} < span style = "color: #a020f0;" > else< / span > {
< span style = "color: #a020f0;" > if< / span > (errno == EACCES) {
/* < span style = "color: #b22222;" > The directory is read-only and the lock file can't be written.< / span >
< span style = "color: #b22222;" > Create a dummy temporary file for dummy locking.< / span >
< span style = "color: #b22222;" > < / span > */
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > dirname< / span > [TREXIO_MAX_FILENAME_LENGTH] = < span style = "color: #8b2252;" > "/tmp/trexio.XXXXXX"< / span > ;
2021-10-14 10:54:31 +02:00
< span style = "color: #a020f0;" > if< / span > (mkdtemp(dirname) == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_ERRNO;
2021-10-13 17:44:31 +02:00
strncpy (file_name, dirname, TREXIO_MAX_FILENAME_LENGTH);
strncat (file_name, lock_file_name, TREXIO_MAX_FILENAME_LENGTH-strlen(lock_file_name));
f-> lock_file = open(file_name,O_WRONLY|O_CREAT|O_TRUNC, 0644);
remove(file_name);
rmdir(dirname);
} < span style = "color: #a020f0;" > else< / span > {
< span style = "color: #a020f0;" > return< / span > TREXIO_ERRNO;
}
}
2021-04-12 14:32:08 +02:00
}
< 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_text_lock< / span > (< span style = "color: #228b22;" > trexio_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > file< / span > ) {
< span style = "color: #a020f0;" > if< / span > (file == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_1;
< span style = "color: #228b22;" > trexio_text_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > f< / span > = (< span style = "color: #228b22;" > trexio_text_t< / span > *) file;
< span style = "color: #a020f0;" > struct< / span > < span style = "color: #228b22;" > flock< / span > < span style = "color: #a0522d;" > fl< / span > ;
fl.l_type = F_WRLCK;
fl.l_whence = SEEK_SET;
fl.l_start = 0;
fl.l_len = 0;
fl.l_pid = getpid();
< span style = "color: #228b22;" > int< / span > < span style = "color: #a0522d;" > rc< / span > = fcntl(f-> lock_file, F_SETLKW, & fl);
< span style = "color: #a020f0;" > if< / span > (rc == -1) < span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
< 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_text_unlock< / span > (< span style = "color: #228b22;" > trexio_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > file< / span > )
{
< span style = "color: #a020f0;" > if< / span > (file == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_1;
< span style = "color: #228b22;" > trexio_text_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > f< / span > = (< span style = "color: #228b22;" > trexio_text_t< / span > *) file;
< span style = "color: #a020f0;" > struct< / span > < span style = "color: #228b22;" > flock< / span > < span style = "color: #a0522d;" > fl< / span > ;
fl.l_type = F_UNLCK;
fl.l_whence = SEEK_SET;
fl.l_start = 0;
fl.l_len = 0;
fl.l_pid = getpid();
fcntl(f-> lock_file, F_SETLK, & fl);
close(f-> lock_file);
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
}
< / pre >
< / div >
< / div >
< / div >
2022-07-28 13:50:07 +02:00
< div id = "outline-container-org3d9c5cd" class = "outline-2" >
< h2 id = "org3d9c5cd" > < span class = "section-number-2" > 4< / span > Deinitialize function (templated part)< / h2 >
2022-04-23 19:25:51 +02:00
< div class = "outline-text-2" id = "text-4" >
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_text_deinit< / span > (< span style = "color: #228b22;" > trexio_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > file< / span > )
{
< span style = "color: #a020f0;" > if< / span > (file == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_1;
< span style = "color: #228b22;" > trexio_exit_code< / span > < span style = "color: #a0522d;" > rc< / span > ;
2021-05-19 15:05:19 +02:00
/* < span style = "color: #b22222;" > Error handling for this call is added by the generator < / span > */
rc = trexio_text_free_$group$( (< span style = "color: #228b22;" > trexio_text_t< / span > *) file);
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
}
< / pre >
< / div >
< / div >
< / div >
2022-07-28 13:50:07 +02:00
< div id = "outline-container-org9a0027c" class = "outline-2" >
< h2 id = "org9a0027c" > < span class = "section-number-2" > 5< / span > Template for text read a group< / h2 >
2022-04-23 19:25:51 +02:00
< div class = "outline-text-2" id = "text-5" >
2021-04-12 14:32:08 +02:00
< div class = "org-src-container" >
< pre class = "src src-c" > $group$_t*
trexio_text_read_$group$ (< span style = "color: #228b22;" > trexio_text_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 > < span style = "color: #008b8b;" > NULL< / span > ;
/* < span style = "color: #b22222;" > If the data structure exists, return it < / span > */
< span style = "color: #a020f0;" > if< / span > (file-> $group$ != < span style = "color: #008b8b;" > NULL< / span > ) {
< span style = "color: #a020f0;" > return< / span > file-> $group$;
}
/* < span style = "color: #b22222;" > Allocate the data structure < / span > */
$group$_t* $group$ = MALLOC($group$_t);
< span style = "color: #a020f0;" > if< / span > ($group$ == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
memset($group$,0,< span style = "color: #a020f0;" > sizeof< / span > ($group$_t));
/* < span style = "color: #b22222;" > Build the file name < / span > */
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > char< / span > * $group$_file_name = < span style = "color: #8b2252;" > "/$group$.txt"< / span > ;
2021-05-06 19:41:32 +02:00
strncpy ($group$-> file_name, file-> parent.file_name, TREXIO_MAX_FILENAME_LENGTH);
strncat ($group$-> file_name, $group$_file_name,
2021-05-04 10:04:57 +02:00
TREXIO_MAX_FILENAME_LENGTH-strlen($group$_file_name));
2021-05-06 19:41:32 +02:00
< span style = "color: #a020f0;" > if< / span > ($group$-> file_name[TREXIO_MAX_FILENAME_LENGTH-1] != < span style = "color: #8b2252;" > '\0'< / span > ) {
2021-05-04 10:04:57 +02:00
FREE($group$);
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
}
2021-04-12 14:32:08 +02:00
/* < span style = "color: #b22222;" > If the file exists, read it < / span > */
2021-05-06 19:41:32 +02:00
< span style = "color: #228b22;" > FILE< / span > * < span style = "color: #a0522d;" > f< / span > = fopen($group$-> file_name,< span style = "color: #8b2252;" > "r"< / span > );
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > if< / span > (f != < span style = "color: #008b8b;" > NULL< / span > ) {
/* < span style = "color: #b22222;" > Find size of file to allocate the max size of the string buffer < / span > */
fseek(f, 0L, SEEK_END);
< span style = "color: #228b22;" > size_t< / span > < span style = "color: #a0522d;" > sz< / span > = ftell(f);
fseek(f, 0L, SEEK_SET);
sz = (sz < 1024) ? (1024) : (sz);
< span style = "color: #228b22;" > char< / span > * < span style = "color: #a0522d;" > buffer< / span > = CALLOC(sz, < span style = "color: #228b22;" > char< / span > );
< span style = "color: #a020f0;" > if< / span > (buffer == < span style = "color: #008b8b;" > NULL< / span > ) {
fclose(f);
FREE($group$);
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
}
2022-01-07 11:04:45 +01:00
< span style = "color: #228b22;" > int< / span > < span style = "color: #a0522d;" > rc< / span > = 0;
2022-02-16 14:52:14 +01:00
< span style = "color: #228b22;" > trexio_exit_code< / span > < span style = "color: #a0522d;" > rc_free< / span > = TREXIO_FAILURE;
2021-04-12 14:32:08 +02:00
/* < span style = "color: #b22222;" > workaround for the case of missing blocks in the file < / span > */
2022-02-16 14:52:14 +01:00
// < span style = "color: #b22222;" > START REPEAT GROUP_DSET_ALL< / span >
2021-04-12 14:32:08 +02:00
< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > size_$group_dset$< / span > = 0;
2021-06-15 12:12:15 +02:00
// < span style = "color: #b22222;" > END REPEAT GROUP_DSET_ALL< / span >
2021-04-12 14:32:08 +02:00
2022-02-16 14:52:14 +01:00
< span style = "color: #a020f0;" > while< / span > (fscanf(f, < span style = "color: #8b2252;" > "%1023s"< / span > , buffer) != EOF) {
2021-09-22 13:34:44 +02:00
2022-02-16 14:52:14 +01:00
< span style = "color: #a020f0;" > if< / span > (strcmp(buffer, < span style = "color: #8b2252;" > "EXIT"< / span > ) == 0) {
< span style = "color: #a020f0;" > break< / span > ;
// < span style = "color: #b22222;" > START REPEAT GROUP_DSET_ALL< / span >
} < span style = "color: #a020f0;" > else< / span > < span style = "color: #a020f0;" > if< / span > (strcmp(buffer, < span style = "color: #8b2252;" > "rank_$group_dset$"< / span > ) == 0) {
2021-09-22 13:34:44 +02:00
2022-02-16 14:52:14 +01:00
rc = fscanf(f, < span style = "color: #8b2252;" > "%u"< / span > , & ($group$-> rank_$group_dset$));
< span style = "color: #a020f0;" > if< / span > (rc != 1) {
2022-05-19 17:24:20 +02:00
trexio_text_free_read_$group$(buffer, f, file, $group$);
2022-02-16 14:52:14 +01:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
}
2021-06-15 12:12:15 +02:00
2022-02-16 14:52:14 +01:00
< span style = "color: #a020f0;" > if< / span > ($group$-> rank_$group_dset$ != 0) size_$group_dset$ = 1UL;
< span style = "color: #a020f0;" > for< / span > (< span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > i< / span > =0; i< $group$-> rank_$group_dset$; ++i){
< span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > j< / span > =0;
rc = fscanf(f, < span style = "color: #8b2252;" > "%1023s %u"< / span > , buffer, & j);
< span style = "color: #a020f0;" > if< / span > ((rc != 2) || (strcmp(buffer, < span style = "color: #8b2252;" > "dims_$group_dset$"< / span > ) != 0) || (j!=i)) {
2022-05-19 17:24:20 +02:00
trexio_text_free_read_$group$(buffer, f, file, $group$);
2022-02-16 14:52:14 +01:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
}
rc = fscanf(f, < span style = "color: #8b2252;" > "%"< / span > SCNu64 < span style = "color: #8b2252;" > "\n"< / span > , & ($group$-> dims_$group_dset$[i]));
assert(!(rc != 1));
< span style = "color: #a020f0;" > if< / span > (rc != 1) {
2022-05-19 17:24:20 +02:00
trexio_text_free_read_$group$(buffer, f, file, $group$);
2022-02-16 14:52:14 +01:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
}
size_$group_dset$ *= $group$-> dims_$group_dset$[i];
}
// < span style = "color: #b22222;" > END REPEAT GROUP_DSET_ALL< / span >
// < span style = "color: #b22222;" > START REPEAT GROUP_DSET_NUM< / span >
} < span style = "color: #a020f0;" > else< / span > < span style = "color: #a020f0;" > if< / span > (strcmp(buffer, < span style = "color: #8b2252;" > "$group_dset$"< / span > ) == 0) {
2021-06-15 12:12:15 +02:00
2022-02-16 14:52:14 +01:00
/* < span style = "color: #b22222;" > Allocate arrays < / span > */
$group$-> $group_dset$ = CALLOC(size_$group_dset$, $group_dset_dtype$);
< span style = "color: #a020f0;" > if< / span > ($group$-> $group_dset$ == < span style = "color: #008b8b;" > NULL< / span > ) {
2022-05-19 17:24:20 +02:00
trexio_text_free_read_$group$(buffer, f, file, $group$);
2022-02-16 14:52:14 +01:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
}
2021-06-15 12:12:15 +02:00
2022-02-16 14:52:14 +01:00
< span style = "color: #a020f0;" > for< / span > (< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > i< / span > =0 ; i< size_$group_dset$ ; ++i) {
rc = fscanf(f, < span style = "color: #8b2252;" > "%$group_dset_format_scanf$"< / span > , & ($group$-> $group_dset$[i]));
< span style = "color: #a020f0;" > if< / span > (rc != 1) {
2022-05-19 17:24:20 +02:00
trexio_text_free_read_$group$(buffer, f, file, $group$);
2022-02-16 14:52:14 +01:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
}
}
2021-06-15 12:12:15 +02:00
2022-02-16 14:52:14 +01:00
// < span style = "color: #b22222;" > END REPEAT GROUP_DSET_NUM< / span >
// < span style = "color: #b22222;" > START REPEAT GROUP_DSET_STR< / span >
} < span style = "color: #a020f0;" > else< / span > < span style = "color: #a020f0;" > if< / span > (strcmp(buffer, < span style = "color: #8b2252;" > "$group_dset$"< / span > ) == 0) {
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > (size_$group_dset$ != 0) {
2022-02-16 14:52:14 +01:00
/* < span style = "color: #b22222;" > Allocate arrays < / span > */
$group$-> $group_dset$ = CALLOC(size_$group_dset$, $group_dset_dtype$);
< span style = "color: #a020f0;" > if< / span > ($group$-> $group_dset$ == < span style = "color: #008b8b;" > NULL< / span > ) {
2022-05-19 17:24:20 +02:00
trexio_text_free_read_$group$(buffer, f, file, $group$);
2022-02-16 14:52:14 +01:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
}
/* < span style = "color: #b22222;" > WARNING: this tmp array allows to avoid allocation of space for each element of array of string< / span >
2022-05-19 17:24:20 +02:00
< span style = "color: #b22222;" > * BUT it's size has to be number_of_str*max_len_str where max_len_str is somewhat arbitrary, e.g. 32.< / span >
2022-02-16 14:52:14 +01:00
< span style = "color: #b22222;" > < / span > */
< span style = "color: #228b22;" > char< / span > * < span style = "color: #a0522d;" > tmp_$group_dset$< / span > ;
tmp_$group_dset$ = CALLOC(size_$group_dset$*32, < span style = "color: #228b22;" > char< / span > );
< span style = "color: #a020f0;" > for< / span > (< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > i< / span > =0 ; i< size_$group_dset$ ; ++i) {
$group$-> $group_dset$[i] = tmp_$group_dset$;
/* < span style = "color: #b22222;" > conventional fcanf with "%s" only return the string before the first space character< / span >
< span style = "color: #b22222;" > * to read string with spaces use "%[^\n]" possible with space before or after, i.e. " %[^\n]"< / span >
2022-05-19 17:24:20 +02:00
< span style = "color: #b22222;" > < / span > */
2022-07-08 12:28:27 +02:00
rc = fscanf(f, < span style = "color: #8b2252;" > " %1023[^\n]"< / span > , buffer);
2022-02-16 14:52:14 +01:00
< span style = "color: #a020f0;" > if< / span > (rc != 1) {
2022-05-19 17:24:20 +02:00
trexio_text_free_read_$group$(buffer, f, file, $group$);
2022-02-16 14:52:14 +01:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
}
2022-07-08 12:28:27 +02:00
< span style = "color: #228b22;" > size_t< / span > < span style = "color: #a0522d;" > tmp_$group_dset$_len< / span > = strlen(buffer);
2022-07-11 16:38:25 +02:00
strncpy(tmp_$group_dset$, buffer, 32);
2022-02-16 14:52:14 +01:00
tmp_$group_dset$ += tmp_$group_dset$_len + 1;
}
}
2021-04-12 14:32:08 +02:00
2022-02-16 14:52:14 +01:00
// < span style = "color: #b22222;" > END REPEAT GROUP_DSET_STR< / span >
// < span style = "color: #b22222;" > START REPEAT GROUP_NUM< / span >
} < span style = "color: #a020f0;" > else< / span > < span style = "color: #a020f0;" > if< / span > (strcmp(buffer, < span style = "color: #8b2252;" > "$group_num$_isSet"< / span > ) == 0) {
2021-04-12 14:32:08 +02:00
2022-02-16 14:52:14 +01:00
< span style = "color: #228b22;" > unsigned< / span > < span style = "color: #228b22;" > int< / span > $group_num$_isSet;
/* < span style = "color: #b22222;" > additional parameter $group_num$_isSet is needed to suppress warning when fscanf into bool variable using %u or %d < / span > */
rc = fscanf(f, < span style = "color: #8b2252;" > "%u"< / span > , & ($group_num$_isSet));
$group$-> $group_num$_isSet = (bool) $group_num$_isSet;
< span style = "color: #a020f0;" > if< / span > (rc != 1) {
2022-05-19 17:24:20 +02:00
trexio_text_free_read_$group$(buffer, f, file, $group$);
2022-02-16 14:52:14 +01:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
}
2021-06-15 12:12:15 +02:00
2022-02-16 14:52:14 +01:00
< span style = "color: #a020f0;" > if< / span > ($group$-> $group_num$_isSet == < span style = "color: #008b8b;" > true< / span > ) {
2022-05-19 17:24:20 +02:00
2022-02-16 14:52:14 +01:00
rc = fscanf(f, < span style = "color: #8b2252;" > "%1023s"< / span > , buffer);
< span style = "color: #a020f0;" > if< / span > ((rc != 1) || (strcmp(buffer, < span style = "color: #8b2252;" > "$group_num$"< / span > ) != 0)) {
2022-05-19 17:24:20 +02:00
trexio_text_free_read_$group$(buffer, f, file, $group$);
2022-02-16 14:52:14 +01:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
}
rc = fscanf(f, < span style = "color: #8b2252;" > "%$group_num_format_scanf$"< / span > , & ($group$-> $group_num$));
< span style = "color: #a020f0;" > if< / span > (rc != 1) {
2022-05-19 17:24:20 +02:00
trexio_text_free_read_$group$(buffer, f, file, $group$);
2022-02-16 14:52:14 +01:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
}
2022-05-19 17:24:20 +02:00
2022-02-16 14:52:14 +01:00
}
2021-12-23 18:22:30 +01:00
2022-02-16 14:52:14 +01:00
// < span style = "color: #b22222;" > END REPEAT GROUP_NUM< / span >
// < span style = "color: #b22222;" > START REPEAT GROUP_ATTR_STR< / span >
} < span style = "color: #a020f0;" > else< / span > < span style = "color: #a020f0;" > if< / span > (strcmp(buffer, < span style = "color: #8b2252;" > "len_$group_str$"< / span > ) == 0) {
2021-09-14 11:40:10 +02:00
2022-02-16 14:52:14 +01:00
rc = fscanf(f, < span style = "color: #8b2252;" > "%"< / span > SCNu64 < span style = "color: #8b2252;" > ""< / span > , & ($group$-> len_$group_str$));
2021-09-22 13:34:44 +02:00
< span style = "color: #a020f0;" > if< / span > (rc != 1) {
2022-05-19 17:24:20 +02:00
trexio_text_free_read_$group$(buffer, f, file, $group$);
2021-09-22 13:34:44 +02:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
}
2022-02-16 14:52:14 +01:00
rc = fscanf(f, < span style = "color: #8b2252;" > "%1023s"< / span > , buffer);
< span style = "color: #a020f0;" > if< / span > ((rc != 1) || (strcmp(buffer, < span style = "color: #8b2252;" > "$group_str$"< / span > ) != 0)) {
2022-05-19 17:24:20 +02:00
trexio_text_free_read_$group$(buffer, f, file, $group$);
2022-02-16 14:52:14 +01:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
}
< span style = "color: #a020f0;" > if< / span > ($group$-> len_$group_str$ != 0) {
$group$-> $group_str$ = CALLOC($group$-> len_$group_str$, < span style = "color: #228b22;" > char< / span > );
< span style = "color: #a020f0;" > if< / span > ($group$-> $group_str$ == < span style = "color: #008b8b;" > NULL< / span > ) {
2022-05-19 17:24:20 +02:00
trexio_text_free_read_$group$(buffer, f, file, $group$);
2022-02-16 14:52:14 +01:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
}
2022-07-08 12:28:27 +02:00
rc = fscanf(f, < span style = "color: #8b2252;" > " %1023[^\n]"< / span > , buffer);
2022-02-16 14:52:14 +01:00
< span style = "color: #a020f0;" > if< / span > (rc != 1) {
2022-05-19 17:24:20 +02:00
trexio_text_free_read_$group$(buffer, f, file, $group$);
2022-02-16 14:52:14 +01:00
< span style = "color: #a020f0;" > return< / span > < span style = "color: #008b8b;" > NULL< / span > ;
}
2022-07-08 12:28:27 +02:00
/* < span style = "color: #b22222;" > Safer string conversion to avoid buffer overflow in fscanf < / span > */
strncpy($group$-> $group_str$, buffer, $group$-> len_$group_str$);
2022-02-16 14:52:14 +01:00
}
// < span style = "color: #b22222;" > END REPEAT GROUP_ATTR_STR< / span >
} < span style = "color: #a020f0;" > else< / span > {
< span style = "color: #a020f0;" > continue< / span > ;
2021-09-22 13:34:44 +02:00
}
2022-02-16 14:52:14 +01:00
2021-06-15 12:12:15 +02:00
}
2021-04-12 14:32:08 +02:00
FREE(buffer);
fclose(f);
f = < span style = "color: #008b8b;" > NULL< / span > ;
}
file-> $group$ = $group$;
< span style = "color: #a020f0;" > return< / span > $group$;
}
< / pre >
< / div >
< / div >
< / div >
2022-07-28 13:50:07 +02:00
< div id = "outline-container-org2d3bdcc" class = "outline-2" >
< h2 id = "org2d3bdcc" > < span class = "section-number-2" > 6< / span > Template for text has a group< / h2 >
2022-04-23 19:25:51 +02:00
< div class = "outline-text-2" id = "text-6" >
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 >
2022-07-04 13:02:49 +02:00
< span style = "color: #0000ff;" > trexio_text_has_$group$< / span > (< span style = "color: #228b22;" > trexio_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > file< / span > )
{
< span style = "color: #a020f0;" > if< / span > (file == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_1;
/* < span style = "color: #b22222;" > Flush the group to make sure the group.txt file is created < / span > */
< span style = "color: #a020f0;" > if< / span > (file-> mode != < span style = "color: #8b2252;" > 'r'< / span > ) {
< span style = "color: #228b22;" > trexio_exit_code< / span > < span style = "color: #a0522d;" > rc< / span > = trexio_text_flush_$group$((< span style = "color: #228b22;" > trexio_text_t< / span > *) file);
< span style = "color: #a020f0;" > if< / span > (rc != TREXIO_SUCCESS) < span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
}
/* < span style = "color: #b22222;" > Build the file name < / span > */
< span style = "color: #228b22;" > char< / span > $group$_full_path[TREXIO_MAX_FILENAME_LENGTH];
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > char< / span > * $group$_file_name = < span style = "color: #8b2252;" > "/$group$.txt"< / span > ;
strncpy ($group$_full_path, file-> file_name, TREXIO_MAX_FILENAME_LENGTH);
strncat ($group$_full_path, $group$_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen($group$_file_name));
< span style = "color: #a020f0;" > if< / span > ($group$_full_path[TREXIO_MAX_FILENAME_LENGTH-1] != < span style = "color: #8b2252;" > '\0'< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
< span style = "color: #228b22;" > bool< / span > < span style = "color: #a0522d;" > file_exists< / span > ;
file_exists = trexio_text_file_exists($group$_full_path);
< span style = "color: #a020f0;" > if< / span > (file_exists) {
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
} < span style = "color: #a020f0;" > else< / span > {
< span style = "color: #a020f0;" > return< / span > TREXIO_HAS_NOT;
}
}
< / pre >
< / div >
< / div >
< / div >
2022-07-28 13:50:07 +02:00
< div id = "outline-container-org13fb100" class = "outline-2" >
< h2 id = "org13fb100" > < span class = "section-number-2" > 7< / span > Template for text flush a group< / h2 >
2022-07-04 13:02:49 +02:00
< div class = "outline-text-2" id = "text-7" >
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span >
2021-04-12 14:32:08 +02:00
< span style = "color: #0000ff;" > trexio_text_flush_$group$< / span > (< span style = "color: #228b22;" > trexio_text_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > file< / span > )
{
< span style = "color: #a020f0;" > if< / span > (file == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_1;
< span style = "color: #a020f0;" > if< / span > (file-> parent.mode == < span style = "color: #8b2252;" > 'r'< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_READONLY;
$group$_t* $group$ = file-> $group$;
< span style = "color: #a020f0;" > if< / span > ($group$ == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
< span style = "color: #a020f0;" > if< / span > ($group$-> to_flush == 0) < span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
2022-01-25 16:19:26 +01:00
assert (file-> parent.mode == < span style = "color: #8b2252;" > 'w'< / span > || file-> parent.mode == < span style = "color: #8b2252;" > 'u'< / span > );
2021-05-06 19:41:32 +02:00
< span style = "color: #228b22;" > FILE< / span > * < span style = "color: #a0522d;" > f< / span > = fopen($group$-> file_name, < span style = "color: #8b2252;" > "w"< / span > );
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > if< / span > (f == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_1;
/* < span style = "color: #b22222;" > Write the dimensioning variables < / span > */
2021-06-15 12:12:15 +02:00
// < span style = "color: #b22222;" > START REPEAT GROUP_DSET_ALL< / span >
2021-04-12 14:32:08 +02:00
fprintf(f, < span style = "color: #8b2252;" > "rank_$group_dset$ %u\n"< / span > , $group$-> rank_$group_dset$);
// < span style = "color: #b22222;" > workaround for the case of missing blocks in the file< / span >
< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > size_$group_dset$< / span > = 0;
< span style = "color: #a020f0;" > if< / span > ($group$-> rank_$group_dset$ != 0) size_$group_dset$ = 1;
< span style = "color: #a020f0;" > for< / span > (< span style = "color: #228b22;" > unsigned< / span > < span style = "color: #228b22;" > int< / span > < span style = "color: #a0522d;" > i< / span > =0; i< $group$-> rank_$group_dset$; ++i){
2021-05-06 18:09:34 +02:00
fprintf(f, < span style = "color: #8b2252;" > "dims_$group_dset$ %u %"< / span > PRIu64 < span style = "color: #8b2252;" > "\n"< / span > , i, $group$-> dims_$group_dset$[i]);
2021-04-12 14:32:08 +02:00
size_$group_dset$ *= $group$-> dims_$group_dset$[i];
}
2021-06-15 12:12:15 +02:00
// < span style = "color: #b22222;" > END REPEAT GROUP_DSET_ALL< / span >
2021-04-12 14:32:08 +02:00
// < span style = "color: #b22222;" > START REPEAT GROUP_NUM< / span >
2021-09-22 13:34:44 +02:00
fprintf(f, < span style = "color: #8b2252;" > "$group_num$_isSet %u \n"< / span > , $group$-> $group_num$_isSet);
2021-12-17 17:14:30 +01:00
< span style = "color: #a020f0;" > if< / span > ($group$-> $group_num$_isSet == < span style = "color: #008b8b;" > true< / span > ) fprintf(f, < span style = "color: #8b2252;" > "$group_num$ %$group_num_format_printf$ \n"< / span > , $group$-> $group_num$);
2021-04-12 14:32:08 +02:00
// < span style = "color: #b22222;" > END REPEAT GROUP_NUM< / span >
2021-06-15 12:12:15 +02:00
// < span style = "color: #b22222;" > START REPEAT GROUP_ATTR_STR< / span >
fprintf(f, < span style = "color: #8b2252;" > "len_$group_str$ %"< / span > PRIu64 < span style = "color: #8b2252;" > "\n"< / span > , $group$-> len_$group_str$);
fprintf(f, < span style = "color: #8b2252;" > "$group_str$\n"< / span > );
< span style = "color: #a020f0;" > if< / span > ($group$-> len_$group_str$ != 0) fprintf(f, < span style = "color: #8b2252;" > "%s\n"< / span > , $group$-> $group_str$);
// < span style = "color: #b22222;" > END REPEAT GROUP_ATTR_STR< / span >
2021-04-12 14:32:08 +02:00
/* < span style = "color: #b22222;" > Write arrays < / span > */
2021-06-15 12:12:15 +02:00
// < span style = "color: #b22222;" > START REPEAT GROUP_DSET_ALL< / span >
2021-04-12 14:32:08 +02:00
fprintf(f, < span style = "color: #8b2252;" > "$group_dset$\n"< / span > );
< span style = "color: #a020f0;" > for< / span > (< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > i< / span > =0 ; i< size_$group_dset$ ; ++i) {
2021-12-17 17:14:30 +01:00
fprintf(f, < span style = "color: #8b2252;" > "%$group_dset_format_printf$\n"< / span > , $group$-> $group_dset$[i]);
2021-04-12 14:32:08 +02:00
}
2021-06-15 12:12:15 +02:00
// < span style = "color: #b22222;" > END REPEAT GROUP_DSET_ALL< / span >
2021-04-12 14:32:08 +02:00
2021-05-06 19:41:32 +02:00
fclose(f);
2021-04-12 14:32:08 +02:00
$group$-> to_flush = 0;
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
}
< / pre >
< / div >
< / div >
< / div >
2022-07-28 13:50:07 +02:00
< div id = "outline-container-orgc84ab8d" class = "outline-2" >
< h2 id = "orgc84ab8d" > < span class = "section-number-2" > 8< / span > Template for text free memory< / h2 >
2022-07-04 13:02:49 +02:00
< div class = "outline-text-2" id = "text-8" >
2021-04-12 14:32:08 +02:00
< p >
Memory is allocated when reading. The following function frees memory.
< / p >
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span >
< span style = "color: #0000ff;" > trexio_text_free_$group$< / span > (< span style = "color: #228b22;" > trexio_text_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > file< / span > )
{
< span style = "color: #a020f0;" > if< / span > (file == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_1;
< span style = "color: #a020f0;" > if< / span > (file-> parent.mode != < span style = "color: #8b2252;" > 'r'< / span > ) {
< span style = "color: #228b22;" > trexio_exit_code< / span > < span style = "color: #a0522d;" > rc< / span > = trexio_text_flush_$group$(file);
< span style = "color: #a020f0;" > if< / span > (rc != TREXIO_SUCCESS) < span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
}
$group$_t* $group$ = file-> $group$;
< span style = "color: #a020f0;" > if< / span > ($group$ == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
2021-06-15 12:12:15 +02:00
// < span style = "color: #b22222;" > START REPEAT GROUP_DSET_NUM< / span >
< span style = "color: #a020f0;" > if< / span > ($group$-> $group_dset$ != < span style = "color: #008b8b;" > NULL< / span > ) FREE ($group$-> $group_dset$);
// < span style = "color: #b22222;" > END REPEAT GROUP_DSET_NUM< / span >
// < span style = "color: #b22222;" > START REPEAT GROUP_DSET_STR< / span >
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > if< / span > ($group$-> $group_dset$ != < span style = "color: #008b8b;" > NULL< / span > ) {
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > ($group$-> rank_$group_dset$ != 0) FREE ($group$-> $group_dset$[0]);
2021-04-12 14:32:08 +02:00
FREE ($group$-> $group_dset$);
}
2021-06-15 12:12:15 +02:00
// < span style = "color: #b22222;" > END REPEAT GROUP_DSET_STR< / span >
// < span style = "color: #b22222;" > START REPEAT GROUP_ATTR_STR< / span >
< span style = "color: #a020f0;" > if< / span > ($group$-> $group_str$ != < span style = "color: #008b8b;" > NULL< / span > ) FREE ($group$-> $group_str$);
// < span style = "color: #b22222;" > END REPEAT GROUP_ATTR_STR< / span >
2021-04-12 14:32:08 +02:00
FREE ($group$);
2022-01-25 16:19:26 +01:00
file-> $group$ = < span style = "color: #008b8b;" > NULL< / span > ;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
}
< / pre >
< / div >
2022-05-19 17:24:20 +02:00
< p >
This function is called upon the non-successful exit from the < code > trexio_text_read_group< / code > function.
< / p >
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span >
< span style = "color: #0000ff;" > trexio_text_free_read_$group$< / span > (< span style = "color: #228b22;" > char< / span > * < span style = "color: #a0522d;" > buffer< / span > , < span style = "color: #228b22;" > FILE< / span > * < span style = "color: #a0522d;" > txt_file< / span > , < span style = "color: #228b22;" > trexio_text_t< / span > * < span style = "color: #a0522d;" > trexio_file< / span > , $group$_t* $group$)
{
< span style = "color: #228b22;" > trexio_exit_code< / span > < span style = "color: #a0522d;" > rc_free< / span > ;
FREE(buffer);
fclose(txt_file);
/* < span style = "color: #b22222;" > Set pointer to the struct so that the garbage collector can do the job on file handle < / span > */
trexio_file-> $group$ = $group$;
rc_free = trexio_text_free_$group$(trexio_file);
assert(rc_free == TREXIO_SUCCESS);
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
}
< / pre >
< / div >
2021-04-12 14:32:08 +02:00
< / div >
< / div >
2022-07-28 13:50:07 +02:00
< div id = "outline-container-orgdb5dede" class = "outline-2" >
< h2 id = "orgdb5dede" > < span class = "section-number-2" > 9< / span > Template for has/read/write a numerical attribute< / h2 >
2022-07-04 13:02:49 +02:00
< div class = "outline-text-2" id = "text-9" >
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-09-22 13:34:44 +02:00
< span style = "color: #0000ff;" > trexio_text_read_$group_num$< / span > (< span style = "color: #228b22;" > trexio_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > file< / span > , $group_num_dtype_double$* < span style = "color: #a020f0;" > const< / span > num)
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 > (num == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_2;
$group$_t* $group$ = trexio_text_read_$group$((< span style = "color: #228b22;" > trexio_text_t< / span > *) file);
< span style = "color: #a020f0;" > if< / span > ($group$ == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
*num = $group$-> $group_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 >
2021-09-22 13:34:44 +02:00
< span style = "color: #0000ff;" > trexio_text_write_$group_num$< / span > (< span style = "color: #228b22;" > trexio_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > file< / span > , < span style = "color: #a020f0;" > const< / span > $group_num_dtype_double$ num)
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 > (file-> mode == < span style = "color: #8b2252;" > 'r'< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_READONLY;
$group$_t* $group$ = trexio_text_read_$group$((< span style = "color: #228b22;" > trexio_text_t< / span > *) file);
< span style = "color: #a020f0;" > if< / span > ($group$ == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
$group$-> $group_num$ = num;
2021-09-22 13:34:44 +02:00
$group$-> $group_num$_isSet = < span style = "color: #008b8b;" > true< / span > ;
2021-04-12 14:32:08 +02:00
$group$-> to_flush = 1;
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
}
< / pre >
< / div >
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span >
< span style = "color: #0000ff;" > trexio_text_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;
$group$_t* $group$ = trexio_text_read_$group$((< span style = "color: #228b22;" > trexio_text_t< / span > *) file);
< span style = "color: #a020f0;" > if< / span > ($group$ == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
2021-09-22 13:34:44 +02:00
< span style = "color: #a020f0;" > if< / span > ($group$-> $group_num$_isSet == < span style = "color: #008b8b;" > true< / span > ){
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
} < span style = "color: #a020f0;" > else< / span > {
< span style = "color: #a020f0;" > return< / span > TREXIO_HAS_NOT;
}
}
< / pre >
< / div >
< / div >
< / div >
2022-07-28 13:50:07 +02:00
< div id = "outline-container-org8d367b7" class = "outline-2" >
< h2 id = "org8d367b7" > < span class = "section-number-2" > 10< / span > Template for has/read/write a dataset of numerical data< / h2 >
2022-07-04 13:02:49 +02:00
< div class = "outline-text-2" id = "text-10" >
2021-04-12 14:32:08 +02:00
< p >
The < code > group_dset< / code > array is assumed allocated with the appropriate size.
< / p >
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span >
< span style = "color: #0000ff;" > trexio_text_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$* < span style = "color: #a020f0;" > const< / span > $group_dset$,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > rank< / span > , < span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > uint64_t< / span > * < span style = "color: #a0522d;" > dims< / 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 > ($group_dset$ == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_2;
$group$_t* < span style = "color: #a020f0;" > const< / span > $group$ = trexio_text_read_$group$((< span style = "color: #228b22;" > trexio_text_t< / span > *) file);
< span style = "color: #a020f0;" > if< / span > ($group$ == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
< span style = "color: #a020f0;" > if< / span > (rank != $group$-> rank_$group_dset$) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_3;
< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > dim_size< / span > = 1;
2021-06-15 12:12:15 +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
< span style = "color: #a020f0;" > if< / span > (dims[i] != $group$-> dims_$group_dset$[i]) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_4;
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$-> $group_dset$[i];
}
< 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_text_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$* $group_dset$,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > rank< / span > , < span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > uint64_t< / span > * < span style = "color: #a0522d;" > dims< / 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 > ($group_dset$ == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_2;
< span style = "color: #a020f0;" > if< / span > (file-> mode == < span style = "color: #8b2252;" > 'r'< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_READONLY;
$group$_t* < span style = "color: #a020f0;" > const< / span > $group$ = trexio_text_read_$group$((< span style = "color: #228b22;" > trexio_text_t< / span > *) file);
< span style = "color: #a020f0;" > if< / span > ($group$ == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
< span style = "color: #a020f0;" > if< / span > ($group$-> $group_dset$ != < span style = "color: #008b8b;" > NULL< / span > ) {
FREE($group$-> $group_dset$);
}
$group$-> rank_$group_dset$ = rank;
< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > dim_size< / span > = 1;
2021-06-15 12:12:15 +02:00
< span style = "color: #a020f0;" > for< / span > (< span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > i< / span > =0; i< $group$-> rank_$group_dset$; ++i){
2021-04-12 14:32:08 +02:00
$group$-> dims_$group_dset$[i] = dims[i];
dim_size *= dims[i];
}
$group$-> $group_dset$ = CALLOC(dim_size, $group_dset_dtype$);
< 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$-> $group_dset$[i] = $group_dset$[i];
}
$group$-> to_flush = 1;
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
}
< / pre >
< / div >
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span >
< span style = "color: #0000ff;" > trexio_text_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;
$group$_t* < span style = "color: #a020f0;" > const< / span > $group$ = trexio_text_read_$group$((< span style = "color: #228b22;" > trexio_text_t< / span > *) file);
< span style = "color: #a020f0;" > if< / span > ($group$ == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
< span style = "color: #a020f0;" > if< / span > ($group$-> rank_$group_dset$ > 0){
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
} < span style = "color: #a020f0;" > else< / span > {
< span style = "color: #a020f0;" > return< / span > TREXIO_HAS_NOT;
}
}
< / pre >
< / div >
< / div >
< / div >
2022-07-28 13:50:07 +02:00
< div id = "outline-container-org2bfe1f8" class = "outline-2" >
< h2 id = "org2bfe1f8" > < span class = "section-number-2" > 11< / span > Template for has/read/write a dataset of strings< / h2 >
2022-07-04 13:02:49 +02:00
< div class = "outline-text-2" id = "text-11" >
2021-06-15 12:12:15 +02:00
< p >
The < code > group_dset< / code > array is assumed allocated with the appropriate size.
< / p >
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span >
< span style = "color: #0000ff;" > trexio_text_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: #a020f0;" > const< / span > < span style = "color: #a0522d;" > dset< / span > , < span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > rank< / span > , < span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > uint64_t< / span > * < span style = "color: #a0522d;" > dims< / span > , < span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > max_str_len< / span > )
{
< span style = "color: #a020f0;" > if< / span > (file == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_1;
< span style = "color: #a020f0;" > if< / span > (dset == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_2;
$group$_t* < span style = "color: #a020f0;" > const< / span > $group$ = trexio_text_read_$group$((< span style = "color: #228b22;" > trexio_text_t< / span > *) file);
< span style = "color: #a020f0;" > if< / span > ($group$ == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
< span style = "color: #a020f0;" > if< / span > (rank != $group$-> rank_$group_dset$) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_3;
< span style = "color: #a020f0;" > for< / span > (< span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > i< / span > =0 ; i< rank ; ++i) {
< span style = "color: #a020f0;" > if< / span > (dims[i] != $group$-> dims_$group_dset$[i]) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_4;
}
strcpy(dset, < span style = "color: #8b2252;" > ""< / span > );
< span style = "color: #a020f0;" > for< / span > (< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > i< / span > =0 ; i< dims[0] ; ++i) {
strncat(dset, $group$-> $group_dset$[i], max_str_len);
strcat(dset, TREXIO_DELIM);
}
< 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_text_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< / span > , < span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > rank< / span > , < span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > uint64_t< / span > * < span style = "color: #a0522d;" > dims< / span > )
{
< span style = "color: #a020f0;" > if< / span > (file == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_1;
< span style = "color: #a020f0;" > if< / span > (dset == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_2;
< span style = "color: #a020f0;" > if< / span > (file-> mode == < span style = "color: #8b2252;" > 'r'< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_READONLY;
$group$_t* < span style = "color: #a020f0;" > const< / span > $group$ = trexio_text_read_$group$((< span style = "color: #228b22;" > trexio_text_t< / span > *) file);
< span style = "color: #a020f0;" > if< / span > ($group$ == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
< span style = "color: #a020f0;" > if< / span > ($group$-> $group_dset$ != < span style = "color: #008b8b;" > NULL< / span > ) {
< span style = "color: #a020f0;" > if< / span > ($group$-> rank_$group_dset$ != 0) FREE($group$-> $group_dset$[0]);
FREE($group$-> $group_dset$);
}
$group$-> rank_$group_dset$ = rank;
< span style = "color: #a020f0;" > for< / span > (< span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > i< / span > =0; i< $group$-> rank_$group_dset$; ++i){
$group$-> dims_$group_dset$[i] = dims[i];
}
$group$-> $group_dset$ = CALLOC(dims[0], < span style = "color: #228b22;" > char< / span > *);
< span style = "color: #a020f0;" > if< / span > ($group$-> $group_dset$ == < 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;" > tmp_str< / span > = CALLOC(dims[0]*32 + 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: #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;" > size_t< / span > < span style = "color: #a0522d;" > tmp_len< / span > = strlen(dset[i]);
2021-06-15 12:12:15 +02:00
$group$-> $group_dset$[i] = tmp_str;
strncpy(tmp_str, dset[i], tmp_len);
2021-10-13 17:44:31 +02:00
tmp_str += tmp_len + 1;
2021-06-15 12:12:15 +02:00
}
$group$-> to_flush = 1;
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
}
< / pre >
< / div >
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span >
< span style = "color: #0000ff;" > trexio_text_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;
$group$_t* < span style = "color: #a020f0;" > const< / span > $group$ = trexio_text_read_$group$((< span style = "color: #228b22;" > trexio_text_t< / span > *) file);
< span style = "color: #a020f0;" > if< / span > ($group$ == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
< span style = "color: #a020f0;" > if< / span > ($group$-> rank_$group_dset$ > 0){
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
} < span style = "color: #a020f0;" > else< / span > {
< span style = "color: #a020f0;" > return< / span > TREXIO_HAS_NOT;
}
}
< / pre >
< / div >
< / div >
< / div >
2022-07-28 13:50:07 +02:00
< div id = "outline-container-org28a7228" class = "outline-2" >
< h2 id = "org28a7228" > < span class = "section-number-2" > 12< / span > Template for has/read/write a string attribute< / h2 >
2022-07-04 13:02:49 +02:00
< div class = "outline-text-2" id = "text-12" >
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_text_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< / span > , < span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > max_str_len< / span > )
{
< span style = "color: #a020f0;" > if< / span > (file == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_1;
< span style = "color: #a020f0;" > if< / span > (str == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_2;
$group$_t* < span style = "color: #a020f0;" > const< / span > $group$ = trexio_text_read_$group$((< span style = "color: #228b22;" > trexio_text_t< / span > *) file);
< span style = "color: #a020f0;" > if< / span > ($group$ == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
strncpy(str, $group$-> $group_str$, max_str_len);
< 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_text_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;" > 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 > (file-> mode == < span style = "color: #8b2252;" > 'r'< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_READONLY;
$group$_t* < span style = "color: #a020f0;" > const< / span > $group$ = trexio_text_read_$group$((< span style = "color: #228b22;" > trexio_text_t< / span > *) file);
< span style = "color: #a020f0;" > if< / span > ($group$ == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
< span style = "color: #a020f0;" > if< / span > ($group$-> $group_str$ != < span style = "color: #008b8b;" > NULL< / span > ) FREE($group$-> $group_str$);
< span style = "color: #228b22;" > size_t< / span > < span style = "color: #a0522d;" > tmp_len< / span > = strlen(str);
$group$-> $group_str$ = CALLOC(tmp_len + 1, < span style = "color: #228b22;" > char< / span > );
< span style = "color: #a020f0;" > if< / span > ($group$-> $group_str$ == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_ALLOCATION_FAILED;
$group$-> len_$group_str$ = tmp_len + 1;
strncpy($group$-> $group_str$, str, tmp_len + 1);
$group$-> to_flush = 1;
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
}
< / pre >
< / div >
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span >
< span style = "color: #0000ff;" > trexio_text_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;
$group$_t* < span style = "color: #a020f0;" > const< / span > $group$ = trexio_text_read_$group$((< span style = "color: #228b22;" > trexio_text_t< / span > *) file);
< span style = "color: #a020f0;" > if< / span > ($group$ == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
< span style = "color: #a020f0;" > if< / span > ($group$-> len_$group_str$ > 0){
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
} < span style = "color: #a020f0;" > else< / span > {
< span style = "color: #a020f0;" > return< / span > TREXIO_HAS_NOT;
}
}
< / pre >
< / div >
< / div >
< / div >
2022-07-28 13:50:07 +02:00
< div id = "outline-container-orgc3668ab" class = "outline-2" >
< h2 id = "orgc3668ab" > < span class = "section-number-2" > 13< / span > Template for has/read/write the dataset of sparse data< / h2 >
2022-07-04 13:02:49 +02:00
< div class = "outline-text-2" id = "text-13" >
2021-12-17 17:14:30 +01:00
< p >
Each sparse array is stored in a separate < code > .txt< / code > file due to the fact that sparse I/O has to be decoupled
from conventional write/read/flush behaviour of the TEXT back end. Chunks are used to read/write sparse data
to prevent memory overflow. Chunks have a given < code > int64_t size< / code >
(size specifies the number of sparse data items, e.g. integrals).
< / p >
2021-04-12 14:32:08 +02:00
2021-12-17 17:14:30 +01:00
< p >
User provides indices and values of the sparse array as two separate variables.
< / p >
2021-04-12 14:32:08 +02:00
2021-05-04 10:04:57 +02:00
2021-12-17 17:14:30 +01:00
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span > < span style = "color: #0000ff;" > trexio_text_write_$group_dset$< / span > (< span style = "color: #228b22;" > trexio_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > file< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > int64_t< / span > < span style = "color: #a0522d;" > offset_file< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > int64_t< / span > < span style = "color: #a0522d;" > size< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > int64_t< / span > < span style = "color: #a0522d;" > size_max< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > int64_t< / span > < span style = "color: #a0522d;" > size_start< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > int32_t< / span > * < span style = "color: #a0522d;" > index_sparse< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > double< / span > * < span style = "color: #a0522d;" > value_sparse< / span > )
{
< span style = "color: #a020f0;" > if< / span > (file == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_1;
2021-04-12 14:32:08 +02:00
2021-12-17 17:14:30 +01:00
/* < span style = "color: #b22222;" > Build the name of the file with sparse data< / span > */
/* < span style = "color: #b22222;" > The $group_dset$.txt is limited to 256 symbols for the moment. What are the chances that it will exceed? < / span > */
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > char< / span > $group_dset$_file_name[256] = < span style = "color: #8b2252;" > "/$group_dset$.txt"< / span > ;
/* < span style = "color: #b22222;" > The full path to the destination TXT file with sparse data. This will include TREXIO directory name. < / span > */
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > file_full_path< / span > [TREXIO_MAX_FILENAME_LENGTH];
/* < span style = "color: #b22222;" > Copy directory name in file_full_path < / span > */
strncpy (file_full_path, file-> file_name, TREXIO_MAX_FILENAME_LENGTH);
/* < span style = "color: #b22222;" > Append name of the file with sparse data < / span > */
strncat (file_full_path, $group_dset$_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen($group_dset$_file_name));
/* < span style = "color: #b22222;" > Open the file in "a" (append) mode to guarantee that no truncation happens upon consecutive writes < / span > */
< span style = "color: #228b22;" > FILE< / span > * < span style = "color: #a0522d;" > f< / span > = fopen(file_full_path, < span style = "color: #8b2252;" > "a"< / span > );
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > (f == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FILE_ERROR;
2021-12-17 17:14:30 +01:00
/* < span style = "color: #b22222;" > Specify the line length in order to offset properly. For example, for 4-index quantities< / span >
< span style = "color: #b22222;" > the line_length is 69 because 10 per index + 4 spaces + 24 for floating point value + 1 for the new line char.< / span >
< span style = "color: #b22222;" > CURRENTLY NO OFFSET IS USED WHEN WRITING !< / span >
< span style = "color: #b22222;" > < / span > */
< span style = "color: #228b22;" > int64_t< / span > < span style = "color: #a0522d;" > line_length< / span > = 0L;
2022-01-07 11:04:45 +01:00
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > format_str< / span > [256];
2021-12-17 17:14:30 +01:00
/* < span style = "color: #b22222;" > Determine the optimal type for storing indices depending on the size_max (usually mo_num or ao_num) < / span > */
< span style = "color: #a020f0;" > if< / span > (size_max < UINT8_MAX) {
line_length = $sparse_line_length_8$; // < span style = "color: #b22222;" > 41 for 4 indices< / span >
strncpy(format_str, $sparse_format_printf_8$, 256);
} < span style = "color: #a020f0;" > else< / span > < span style = "color: #a020f0;" > if< / span > (size_max < UINT16_MAX) {
line_length = $sparse_line_length_16$; // < span style = "color: #b22222;" > 49 for 4 indices< / span >
strncpy(format_str, $sparse_format_printf_16$, 256);
} < span style = "color: #a020f0;" > else< / span > {
line_length = $sparse_line_length_32$; //< span style = "color: #b22222;" > 69 for 4 indices< / span >
strncpy(format_str, $sparse_format_printf_32$, 256);
2021-05-04 10:04:57 +02:00
}
2021-12-17 17:14:30 +01:00
strncat(format_str, < span style = "color: #8b2252;" > "\n"< / span > , 2);
/* < span style = "color: #b22222;" > Get the starting position of the IO stream to be written in the .size file.< / span >
< span style = "color: #b22222;" > This is error-prone due to the fact that for large files (> 2 GB) in 32-bit systems ftell will fail.< / span >
< span style = "color: #b22222;" > One can use ftello function which is adapted for large files.< / span >
< span style = "color: #b22222;" > For now, we can use front-end-provided size_start, which has been checked for INT64_MAX overflow.< / span >
< span style = "color: #b22222;" > < / span > */
< span style = "color: #228b22;" > int64_t< / span > < span style = "color: #a0522d;" > io_start_pos< / span > = size_start * line_length;
/* < span style = "color: #b22222;" > Write the data in the file and check the return code of fprintf to verify that > 0 bytes have been written < / span > */
< span style = "color: #228b22;" > int< / span > < span style = "color: #a0522d;" > rc< / span > ;
2022-01-07 11:04:45 +01:00
< span style = "color: #a020f0;" > for< / span > (< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > i< / span > =0UL; i < (< span style = "color: #228b22;" > uint64_t< / span > ) size; ++i) {
2021-12-17 17:14:30 +01:00
rc = fprintf(f, format_str,
$group_dset_sparse_indices_printf$,
*(value_sparse + i));
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > (rc < = 0) {
2021-05-04 10:04:57 +02:00
fclose(f);
2021-12-17 17:14:30 +01:00
< span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
2021-05-04 10:04:57 +02:00
}
2021-04-12 14:32:08 +02:00
}
2021-12-17 17:14:30 +01:00
/* < span style = "color: #b22222;" > Close the TXT file < / span > */
rc = fclose(f);
< span style = "color: #a020f0;" > if< / span > (rc != 0) < span style = "color: #a020f0;" > return< / span > TREXIO_FILE_ERROR;
2021-04-12 14:32:08 +02:00
2021-12-17 17:14:30 +01:00
/* < span style = "color: #b22222;" > Append .size to the file_full_path in order to write additional info about the written buffer of data < / span > */
strncat(file_full_path, < span style = "color: #8b2252;" > ".size"< / span > , 6);
2021-04-12 14:32:08 +02:00
2021-12-17 17:14:30 +01:00
/* < span style = "color: #b22222;" > Open the new file in "a" (append) mode to append info about the buffer that has been just written < / span > */
< span style = "color: #228b22;" > FILE< / span > *< span style = "color: #a0522d;" > f_wSize< / span > = fopen(file_full_path, < span style = "color: #8b2252;" > "a"< / span > );
< span style = "color: #a020f0;" > if< / span > (f_wSize == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FILE_ERROR;
2021-04-12 14:32:08 +02:00
2021-12-17 17:14:30 +01:00
/* < span style = "color: #b22222;" > Write the buffer_size < / span > */
rc = fprintf(f_wSize, < span style = "color: #8b2252;" > "%"< / span > PRId64 < span style = "color: #8b2252;" > " %"< / span > PRId64 < span style = "color: #8b2252;" > "\n"< / span > , size, io_start_pos);
< span style = "color: #a020f0;" > if< / span > (rc < = 0) {
fclose(f_wSize);
< span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
2021-04-12 14:32:08 +02:00
}
2021-12-17 17:14:30 +01:00
/* < span style = "color: #b22222;" > Close the TXT file < / span > */
rc = fclose(f_wSize);
< span style = "color: #a020f0;" > if< / span > (rc != 0) < span style = "color: #a020f0;" > return< / span > TREXIO_FILE_ERROR;
2021-04-12 14:32:08 +02:00
2022-07-04 13:02:49 +02:00
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > char< / span > $group$_file_name[256] = < span style = "color: #8b2252;" > "/$group$.txt"< / span > ;
memset (file_full_path, 0, TREXIO_MAX_FILENAME_LENGTH);
/* < span style = "color: #b22222;" > Copy directory name in file_full_path < / span > */
strncpy (file_full_path, file-> file_name, TREXIO_MAX_FILENAME_LENGTH);
/* < span style = "color: #b22222;" > Append name of the file with sparse data < / span > */
strncat (file_full_path, $group$_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen($group$_file_name));
< span style = "color: #228b22;" > bool< / span > < span style = "color: #a0522d;" > file_exists< / span > = trexio_text_file_exists(file_full_path);
/* < span style = "color: #b22222;" > Create an empty file for the trexio_text_has_group to work < / span > */
< span style = "color: #a020f0;" > if< / span > (!file_exists) {
< span style = "color: #228b22;" > FILE< / span > *< span style = "color: #a0522d;" > fp< / span > = fopen(file_full_path, < span style = "color: #8b2252;" > "ab+"< / span > );
fclose(fp);
}
2021-12-17 17:14:30 +01:00
/* < span style = "color: #b22222;" > Exit upon success < / span > */
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
}
< / pre >
< / div >
< div class = "org-src-container" >
2021-12-17 17:14:30 +01:00
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span > < span style = "color: #0000ff;" > trexio_text_read_$group_dset$< / span > (< span style = "color: #228b22;" > trexio_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > file< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > int64_t< / span > < span style = "color: #a0522d;" > offset_file< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > int64_t< / span > < span style = "color: #a0522d;" > size< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > int64_t< / span > < span style = "color: #a0522d;" > size_max< / span > ,
< span style = "color: #228b22;" > int64_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > eof_read_size< / span > ,
< span style = "color: #228b22;" > int32_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > index_sparse< / span > ,
< span style = "color: #228b22;" > double< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > value_sparse< / span > )
{
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-12-17 17:14:30 +01:00
< span style = "color: #a020f0;" > if< / span > (eof_read_size == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_5;
/* < span style = "color: #b22222;" > Build the name of the file with sparse data.< / span >
< span style = "color: #b22222;" > The $group_dset$.txt is limited to 256 symbols for the moment. What are the chances that it will exceed?< / span >
< span style = "color: #b22222;" > < / span > */
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > char< / span > $group_dset$_file_name[256] = < span style = "color: #8b2252;" > "/$group_dset$.txt"< / span > ;
/* < span style = "color: #b22222;" > The full path to the destination TXT file with sparse data. This will include TREXIO directory name. < / span > */
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > file_full_path< / span > [TREXIO_MAX_FILENAME_LENGTH];
/* < span style = "color: #b22222;" > Copy directory name in file_full_path < / span > */
strncpy (file_full_path, file-> file_name, TREXIO_MAX_FILENAME_LENGTH);
/* < span style = "color: #b22222;" > Append name of the file with sparse data < / span > */
strncat (file_full_path, $group_dset$_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen($group_dset$_file_name));
/* < span style = "color: #b22222;" > Open the file in "r" (read) mode to guarantee that no truncation happens upon consecutive reads < / span > */
< span style = "color: #228b22;" > FILE< / span > * < span style = "color: #a0522d;" > f< / span > = fopen(file_full_path, < span style = "color: #8b2252;" > "r"< / span > );
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > (f == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FILE_ERROR;
2021-12-17 17:14:30 +01:00
/* < span style = "color: #b22222;" > Specify the line length in order to offset properly. For example, for 4-index quantities< / span >
< span style = "color: #b22222;" > the line_length is 69 because 10 per index + 4 spaces + 24 for floating point value + 1 for the new line char< / span >
< span style = "color: #b22222;" > < / span > */
< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > line_length< / span > = 0UL;
/* < span style = "color: #b22222;" > Determine the line length depending on the size_max (usually mo_num or ao_num) < / span > */
< span style = "color: #a020f0;" > if< / span > (size_max < UINT8_MAX) {
line_length = $sparse_line_length_8$; // < span style = "color: #b22222;" > 41 for 4 indices< / span >
} < span style = "color: #a020f0;" > else< / span > < span style = "color: #a020f0;" > if< / span > (size_max < UINT16_MAX) {
line_length = $sparse_line_length_16$; // < span style = "color: #b22222;" > 49 for 4 indices< / span >
} < span style = "color: #a020f0;" > else< / span > {
line_length = $sparse_line_length_32$; //< span style = "color: #b22222;" > 69 for 4 indices< / span >
2021-04-12 14:32:08 +02:00
}
2021-12-17 17:14:30 +01:00
/* < span style = "color: #b22222;" > Offset in the file according to the provided value of offset_file and optimal line_length < / span > */
fseek(f, (< span style = "color: #228b22;" > long< / span > ) < span style = "color: #228b22;" > offset_file< / span > * < span style = "color: #a0522d;" > line_length< / span > , < span style = "color: #a0522d;" > SEEK_SET< / span > );
2021-04-12 14:32:08 +02:00
2021-12-17 17:14:30 +01:00
/* < span style = "color: #b22222;" > Read the data from the file and check the return code of fprintf to verify that > 0 bytes have been read or reached EOF < / span > */
< span style = "color: #228b22;" > int< / span > < span style = "color: #a0522d;" > rc< / span > ;
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > buffer< / span > [1024];
< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > count< / span > = 0UL;
2022-01-07 11:04:45 +01:00
< span style = "color: #a020f0;" > for< / span > (< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > i< / span > =0UL; i < (< span style = "color: #228b22;" > uint64_t< / span > ) size; ++i) {
2021-04-12 14:32:08 +02:00
2022-01-07 11:04:45 +01:00
memset(buffer, 0, < span style = "color: #a020f0;" > sizeof< / span > (buffer));
2021-04-12 14:32:08 +02:00
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > (fgets(buffer, 1023, f) == < span style = "color: #008b8b;" > NULL< / span > ){
2021-04-12 14:32:08 +02:00
2021-12-17 17:14:30 +01:00
fclose(f);
*eof_read_size = count;
< span style = "color: #a020f0;" > return< / span > TREXIO_END;
2021-04-12 14:32:08 +02:00
2021-12-17 17:14:30 +01:00
} < span style = "color: #a020f0;" > else< / span > {
2021-04-12 14:32:08 +02:00
2021-12-17 17:14:30 +01:00
rc = sscanf(buffer, < span style = "color: #8b2252;" > "$group_dset_format_scanf$"< / span > ,
$group_dset_sparse_indices_scanf$,
value_sparse + i);
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > (rc < = 0) {
2021-12-17 17:14:30 +01:00
fclose(f);
< span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
}
count += 1UL;
2021-04-12 14:32:08 +02:00
2021-12-17 17:14:30 +01:00
}
2021-04-12 14:32:08 +02:00
}
2021-12-17 17:14:30 +01:00
/* < span style = "color: #b22222;" > Close the TXT file < / span > */
rc = fclose(f);
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > (rc != 0) < span style = "color: #a020f0;" > return< / span > TREXIO_FILE_ERROR;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
}
< / pre >
< / div >
< div class = "org-src-container" >
2021-12-17 17:14:30 +01:00
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span > < span style = "color: #0000ff;" > trexio_text_read_$group_dset$_size< / span > (< span style = "color: #228b22;" > trexio_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > file< / span > , < span style = "color: #228b22;" > int64_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > size_max< / span > )
2021-04-12 14:32:08 +02:00
{
2021-12-17 17:14:30 +01: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: #b22222;" > Build the name of the file with sparse data.< / span >
< span style = "color: #b22222;" > The $group_dset$.txt is limited to 256 symbols for the moment. What are the chances that it will exceed?< / span >
< span style = "color: #b22222;" > < / span > */
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > char< / span > $group_dset$_file_name[256] = < span style = "color: #8b2252;" > "/$group_dset$.txt.size"< / span > ;
/* < span style = "color: #b22222;" > The full path to the destination TXT file with sparse data. This will include TREXIO directory name. < / span > */
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > file_full_path< / span > [TREXIO_MAX_FILENAME_LENGTH];
/* < span style = "color: #b22222;" > Copy directory name in file_full_path < / span > */
strncpy (file_full_path, file-> file_name, TREXIO_MAX_FILENAME_LENGTH);
/* < span style = "color: #b22222;" > Append name of the file with sparse data < / span > */
strncat (file_full_path, $group_dset$_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen($group_dset$_file_name));
/* < span style = "color: #b22222;" > Open the file in "r" (read) mode to guarantee that no truncation happens upon consecutive reads < / span > */
< span style = "color: #228b22;" > FILE< / span > * < span style = "color: #a0522d;" > f< / span > = fopen(file_full_path, < span style = "color: #8b2252;" > "r"< / span > );
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > (f == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FILE_ERROR;
2021-12-17 17:14:30 +01:00
/* < span style = "color: #b22222;" > Read the data from the file and check the return code of fprintf to verify that > 0 bytes have been read or reached EOF < / span > */
< span style = "color: #228b22;" > int< / span > < span style = "color: #a0522d;" > rc< / span > ;
< span style = "color: #228b22;" > int64_t< / span > < span style = "color: #a0522d;" > size_item< / span > , < span style = "color: #a0522d;" > offset_item< / span > , < span style = "color: #a0522d;" > size_accum< / span > =0L;
/* < span style = "color: #b22222;" > Read the values from the file. BEWARE OF POSSIBLE MAX_INT64 OVERFLOW ! < / span > */
< span style = "color: #a020f0;" > while< / span > (fscanf(f, < span style = "color: #8b2252;" > "%"< / span > SCNd64 < span style = "color: #8b2252;" > " %"< / span > SCNd64 < span style = "color: #8b2252;" > ""< / span > , & size_item, & offset_item) != EOF) {
/* < span style = "color: #b22222;" > Check that summation will not overflow the int64_t value < / span > */
< span style = "color: #a020f0;" > if< / span > (INT64_MAX - size_accum > size_item) {
size_accum += size_item;
} < span style = "color: #a020f0;" > else< / span > {
fclose(f);
*size_max = -1L;
< span style = "color: #a020f0;" > return< / span > TREXIO_INT_SIZE_OVERFLOW;
2021-04-12 14:32:08 +02:00
}
}
2021-12-17 17:14:30 +01:00
/* < span style = "color: #b22222;" > Close the TXT file < / span > */
rc = fclose(f);
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > (rc != 0) < span style = "color: #a020f0;" > return< / span > TREXIO_FILE_ERROR;
2021-12-17 17:14:30 +01:00
/* < span style = "color: #b22222;" > Overwrite the value at the input address and return TREXIO_SUCCESS < / span > */
*size_max = size_accum;
2021-04-12 14:32:08 +02:00
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
2021-12-17 17:14:30 +01:00
}
< / pre >
< / div >
2021-04-12 14:32:08 +02:00
2021-12-17 17:14:30 +01:00
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span > < span style = "color: #0000ff;" > trexio_text_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
{
2021-12-17 17:14:30 +01: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-04-12 14:32:08 +02:00
2021-12-17 17:14:30 +01:00
/* < span style = "color: #b22222;" > Build the name of the file with sparse data.< / span >
< span style = "color: #b22222;" > The $group_dset$.txt is limited to 256 symbols for the moment. What are the chances that it will exceed?< / span >
< span style = "color: #b22222;" > < / span > */
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > char< / span > $group_dset$_file_name[256] = < span style = "color: #8b2252;" > "/$group_dset$.txt"< / span > ;
/* < span style = "color: #b22222;" > The full path to the destination TXT file with sparse data. This will include TREXIO directory name. < / span > */
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > file_full_path< / span > [TREXIO_MAX_FILENAME_LENGTH];
/* < span style = "color: #b22222;" > Copy directory name in file_full_path < / span > */
strncpy (file_full_path, file-> file_name, TREXIO_MAX_FILENAME_LENGTH);
/* < span style = "color: #b22222;" > Append name of the file with sparse data < / span > */
strncat (file_full_path, $group_dset$_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen($group_dset$_file_name));
/* < span style = "color: #b22222;" > Check the return code of access function to determine whether the file with sparse data exists or not < / span > */
< span style = "color: #a020f0;" > if< / span > (access(file_full_path, F_OK) == 0){
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
} < span style = "color: #a020f0;" > else< / span > {
< span style = "color: #a020f0;" > return< / span > TREXIO_HAS_NOT;
}
2021-04-12 14:32:08 +02:00
}
< / pre >
< / div >
< / div >
< / div >
2022-01-25 16:19:26 +01:00
2022-07-28 13:50:07 +02:00
< div id = "outline-container-orga16bb1f" class = "outline-2" >
< h2 id = "orga16bb1f" > < span class = "section-number-2" > 14< / span > Template for text delete a group (UNSAFE mode)< / h2 >
2022-07-04 13:02:49 +02:00
< div class = "outline-text-2" id = "text-14" >
2022-01-25 16:19:26 +01:00
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span >
< span style = "color: #0000ff;" > trexio_text_delete_$group$< / span > (< span style = "color: #228b22;" > trexio_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > file< / span > )
{
< span style = "color: #a020f0;" > if< / span > (file == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_1;
< span style = "color: #228b22;" > trexio_text_t< / span > * < span style = "color: #a0522d;" > f< / span > = (< span style = "color: #228b22;" > trexio_text_t< / span > *) file;
$group$_t* $group$ = trexio_text_read_$group$(f);
< span style = "color: #a020f0;" > if< / span > ($group$ == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
< span style = "color: #228b22;" > int< / span > < span style = "color: #a0522d;" > rc< / span > = remove($group$-> file_name);
< span style = "color: #a020f0;" > if< / span > (rc == -1) < span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
$group$-> to_flush = 0;
< span style = "color: #228b22;" > trexio_exit_code< / span > < span style = "color: #a0522d;" > rc_free< / span > = trexio_text_free_$group$(f);
< span style = "color: #a020f0;" > if< / span > (rc_free != TREXIO_SUCCESS) < span style = "color: #a020f0;" > return< / span > rc_free;
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
}
< / pre >
< / div >
< / div >
< / div >
2022-04-23 19:25:51 +02:00
2022-07-28 13:50:07 +02:00
< div id = "outline-container-org2142971" class = "outline-2" >
< h2 id = "org2142971" > < span class = "section-number-2" > 15< / span > Source code for the determinant part< / h2 >
2022-07-04 13:02:49 +02:00
< div class = "outline-text-2" id = "text-15" >
2022-04-23 19:25:51 +02:00
< p >
Each array is stored in a separate < code > .txt< / code > file due to the fact that determinant I/O has to be decoupled
from conventional write/read/flush behaviour of the TEXT back end. Chunks are used to read/write the data
to prevent memory overflow. Chunks have a given < code > int64_t size< / code > .
Size specifies the number of data items, e.g. determinants.
< / p >
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span > < span style = "color: #0000ff;" > trexio_text_read_determinant_list< / span > (< span style = "color: #228b22;" > trexio_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > file< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > int64_t< / span > < span style = "color: #a0522d;" > offset_file< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > rank< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > uint64_t< / span > * < span style = "color: #a0522d;" > dims< / span > ,
< span style = "color: #228b22;" > int64_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > eof_read_size< / span > ,
< span style = "color: #228b22;" > int64_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > list< / 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 > (eof_read_size == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_5;
< span style = "color: #a020f0;" > if< / span > (list == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_6;
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > determinant_list_file_name< / span > [256] = < span style = "color: #8b2252;" > "/determinant_list.txt"< / span > ;
/* < span style = "color: #b22222;" > The full path to the destination TXT file with sparse data. This will include TREXIO directory name. < / span > */
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > file_full_path< / span > [TREXIO_MAX_FILENAME_LENGTH];
/* < span style = "color: #b22222;" > Copy directory name in file_full_path < / span > */
strncpy (file_full_path, file-> file_name, TREXIO_MAX_FILENAME_LENGTH);
/* < span style = "color: #b22222;" > Append name of the file with sparse data < / span > */
strncat (file_full_path, determinant_list_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen(determinant_list_file_name));
/* < span style = "color: #b22222;" > Open the file in "r" (read) mode to guarantee that no truncation happens upon consecutive reads < / span > */
< span style = "color: #228b22;" > FILE< / span > * < span style = "color: #a0522d;" > f< / span > = fopen(file_full_path, < span style = "color: #8b2252;" > "r"< / span > );
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > (f == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FILE_ERROR;
2022-04-23 19:25:51 +02:00
/* < span style = "color: #b22222;" > Specify the line length in order to offset properly.< / span >
< span style = "color: #b22222;" > Each 64-bit integer takes at most 10 slots and requires one space,< / span >
< span style = "color: #b22222;" > we have int_num integers per up-spin determinant,< / span >
< span style = "color: #b22222;" > then this number is doubled because we have the same number for down-spin electrons,< / span >
< span style = "color: #b22222;" > and then one newline char.< / span >
< span style = "color: #b22222;" > < / span > */
< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > line_length< / span > = dims[1]*11UL + 1UL; // < span style = "color: #b22222;" > 10 digits per int64_t bitfield + 1 space = 11 spots + 1 newline char< / span >
/* < span style = "color: #b22222;" > Offset in the file according to the provided value of offset_file and optimal line_length < / span > */
fseek(f, (< span style = "color: #228b22;" > long< / span > ) < span style = "color: #228b22;" > offset_file< / span > * < span style = "color: #a0522d;" > line_length< / span > , < span style = "color: #a0522d;" > SEEK_SET< / span > );
/* < span style = "color: #b22222;" > Read the data from the file and check the return code of fprintf to verify that > 0 bytes have been read or reached EOF < / span > */
< span style = "color: #228b22;" > int< / span > < span style = "color: #a0522d;" > rc< / span > ;
/* < span style = "color: #b22222;" > Declare fixed buffer which will be used to read the determinant string < a1 a2 ... a/\ b1 b2 ... b\/> < / span > */
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > buffer< / span > [1024];
< span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > buf_size< / span > = < span style = "color: #a020f0;" > sizeof< / span > (buffer);
/* < span style = "color: #b22222;" > Parameters to post-process the buffer and to get bit fields integers < / span > */
< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > accum< / span > = 0UL;
< span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > shift_int64< / span > = 11U;
/* < span style = "color: #b22222;" > Counter for number of elements beind processed < / span > */
< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > count< / span > = 0UL;
< span style = "color: #a020f0;" > for< / span > (< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > i< / span > =0UL; i < dims[0]; ++i) {
accum = 0UL;
memset(buffer, 0, buf_size);
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > (fgets(buffer, buf_size-1, f) == < span style = "color: #008b8b;" > NULL< / span > ){
2022-04-23 19:25:51 +02:00
fclose(f);
*eof_read_size = count;
< span style = "color: #a020f0;" > return< / span > TREXIO_END;
} < span style = "color: #a020f0;" > else< / span > {
/* < span style = "color: #b22222;" > The format string is not anymore static but rather dynamic (the number of ints depend on the mo_num)< / span >
< span style = "color: #b22222;" > Thus, we parse the buffer string int_num*2 times to get the bit field determinants.< / span >
< span style = "color: #b22222;" > < / span > */
< span style = "color: #a020f0;" > for< / span > (< span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > j< / span > =0; j < (< span style = "color: #228b22;" > uint32_t< / span > ) dims[1]; ++j) {
rc = sscanf(buffer+accum, < span style = "color: #8b2252;" > "%10"< / span > SCNd64, list + dims[1]*i + j);
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > (rc < = 0) {
2022-04-23 19:25:51 +02:00
fclose(f);
< span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
}
accum += shift_int64;
}
count += 1UL;
}
}
/* < span style = "color: #b22222;" > Close the TXT file < / span > */
rc = fclose(f);
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > (rc != 0) < span style = "color: #a020f0;" > return< / span > TREXIO_FILE_ERROR;
2022-04-23 19:25:51 +02:00
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
}
< span style = "color: #228b22;" > trexio_exit_code< / span > < span style = "color: #0000ff;" > trexio_text_read_determinant_coefficient< / span > (< span style = "color: #228b22;" > trexio_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > file< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > int64_t< / span > < span style = "color: #a0522d;" > offset_file< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > rank< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > uint64_t< / span > * < span style = "color: #a0522d;" > dims< / span > ,
< span style = "color: #228b22;" > int64_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > eof_read_size< / span > ,
< span style = "color: #228b22;" > double< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > coeff< / 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 > (eof_read_size == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_5;
< span style = "color: #a020f0;" > if< / span > (coeff == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_6;
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > coeff_file_name< / span > [256];
memset(coeff_file_name, 0, < span style = "color: #a020f0;" > sizeof< / span > (coeff_file_name));
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > int32_t< / span > < span style = "color: #a0522d;" > trexio_state< / span > = file-> state;
< span style = "color: #a020f0;" > if< / span > (trexio_state != 0) {
sprintf(coeff_file_name, < span style = "color: #8b2252;" > "/determinant_coefficient_state_%"< / span > PRId32 < span style = "color: #8b2252;" > ".txt"< / span > , trexio_state);
} < span style = "color: #a020f0;" > else< / span > {
strncpy(coeff_file_name, < span style = "color: #8b2252;" > "/determinant_coefficient.txt"< / span > , 32);
}
/* < span style = "color: #b22222;" > The full path to the destination TXT file with sparse data. This will include TREXIO directory name. < / span > */
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > file_full_path< / span > [TREXIO_MAX_FILENAME_LENGTH];
/* < span style = "color: #b22222;" > Copy directory name in file_full_path < / span > */
strncpy (file_full_path, file-> file_name, TREXIO_MAX_FILENAME_LENGTH);
/* < span style = "color: #b22222;" > Append name of the file with sparse data < / span > */
strncat (file_full_path, coeff_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen(coeff_file_name));
/* < span style = "color: #b22222;" > Open the file in "r" (read) mode to guarantee that no truncation happens upon consecutive reads < / span > */
< span style = "color: #228b22;" > FILE< / span > * < span style = "color: #a0522d;" > f< / span > = fopen(file_full_path, < span style = "color: #8b2252;" > "r"< / span > );
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > (f == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FILE_ERROR;
2022-04-23 19:25:51 +02:00
/* < span style = "color: #b22222;" > Specify the line length in order to offset properly.< / span >
< span style = "color: #b22222;" > Each double value 24 elements + one newline char.< / span >
< span style = "color: #b22222;" > < / span > */
< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > line_length< / span > = 25UL;
/* < span style = "color: #b22222;" > Offset in the file according to the provided value of offset_file and optimal line_length < / span > */
fseek(f, (< span style = "color: #228b22;" > long< / span > ) < span style = "color: #228b22;" > offset_file< / span > * < span style = "color: #a0522d;" > line_length< / span > , < span style = "color: #a0522d;" > SEEK_SET< / span > );
/* < span style = "color: #b22222;" > Read the data from the file and check the return code of fprintf to verify that > 0 bytes have been read or reached EOF < / span > */
< span style = "color: #228b22;" > int< / span > < span style = "color: #a0522d;" > rc< / span > ;
/* < span style = "color: #b22222;" > Declare fixed buffer which will be used to read the determinant string < a1 a2 ... a/\ b1 b2 ... b\/> < / span > */
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > buffer< / span > [64];
< span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > buf_size< / span > = < span style = "color: #a020f0;" > sizeof< / span > (buffer);
/* < span style = "color: #b22222;" > Counter for number of elements beind processed < / span > */
< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > count< / span > = 0UL;
< span style = "color: #a020f0;" > for< / span > (< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > i< / span > =0UL; i < dims[0]; ++i) {
memset(buffer, 0, buf_size);
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > (fgets(buffer, buf_size-1, f) == < span style = "color: #008b8b;" > NULL< / span > ){
2022-04-23 19:25:51 +02:00
fclose(f);
*eof_read_size = count;
< span style = "color: #a020f0;" > return< / span > TREXIO_END;
} < span style = "color: #a020f0;" > else< / span > {
rc = sscanf(buffer, < span style = "color: #8b2252;" > "%lf"< / span > , coeff + i);
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > (rc < = 0) {
2022-04-23 19:25:51 +02:00
fclose(f);
< span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
}
count += 1UL;
}
}
/* < span style = "color: #b22222;" > Close the TXT file < / span > */
rc = fclose(f);
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > (rc != 0) < span style = "color: #a020f0;" > return< / span > TREXIO_FILE_ERROR;
2022-04-23 19:25:51 +02:00
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
}
< span style = "color: #228b22;" > trexio_exit_code< / span >
< span style = "color: #0000ff;" > trexio_text_read_determinant_coefficient_size< / span > (< span style = "color: #228b22;" > trexio_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > file< / span > , < span style = "color: #228b22;" > int64_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > size_max< / span > )
{
< span style = "color: #a020f0;" > if< / span > (file == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_1;
< span style = "color: #a020f0;" > if< / span > (size_max == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_2;
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > coeff_file_name< / span > [256];
memset(coeff_file_name, 0, < span style = "color: #a020f0;" > sizeof< / span > (coeff_file_name));
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > int32_t< / span > < span style = "color: #a0522d;" > trexio_state< / span > = file-> state;
< span style = "color: #a020f0;" > if< / span > (trexio_state != 0) {
sprintf(coeff_file_name, < span style = "color: #8b2252;" > "/determinant_coefficient_state_%"< / span > PRId32 < span style = "color: #8b2252;" > ".txt.size"< / span > , trexio_state);
} < span style = "color: #a020f0;" > else< / span > {
strncpy(coeff_file_name, < span style = "color: #8b2252;" > "/determinant_coefficient.txt.size"< / span > , 64);
}
/* < span style = "color: #b22222;" > The full path to the destination TXT file with sparse data. This will include TREXIO directory name. < / span > */
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > file_full_path< / span > [TREXIO_MAX_FILENAME_LENGTH];
/* < span style = "color: #b22222;" > Copy directory name in file_full_path < / span > */
strncpy (file_full_path, file-> file_name, TREXIO_MAX_FILENAME_LENGTH);
/* < span style = "color: #b22222;" > Append name of the file with sparse data < / span > */
strncat (file_full_path, coeff_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen(coeff_file_name));
/* < span style = "color: #b22222;" > Open the file in "r" (read) mode to guarantee that no truncation happens upon consecutive reads < / span > */
< span style = "color: #228b22;" > FILE< / span > * < span style = "color: #a0522d;" > f< / span > = fopen(file_full_path, < span style = "color: #8b2252;" > "r"< / span > );
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > (f == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FILE_ERROR;
2022-04-23 19:25:51 +02:00
/* < span style = "color: #b22222;" > Read the data from the file and check the return code of fprintf to verify that > 0 bytes have been read or reached EOF < / span > */
< span style = "color: #228b22;" > int< / span > < span style = "color: #a0522d;" > rc< / span > ;
< span style = "color: #228b22;" > int64_t< / span > < span style = "color: #a0522d;" > size_item< / span > , < span style = "color: #a0522d;" > size_accum< / span > =0L;
/* < span style = "color: #b22222;" > Read the values from the file. BEWARE OF POSSIBLE MAX_INT64 OVERFLOW ! < / span > */
< span style = "color: #a020f0;" > while< / span > (fscanf(f, < span style = "color: #8b2252;" > "%"< / span > SCNd64, & size_item) != EOF) {
/* < span style = "color: #b22222;" > Check that summation will not overflow the int64_t value < / span > */
< span style = "color: #a020f0;" > if< / span > (INT64_MAX - size_accum > size_item) {
size_accum += size_item;
} < span style = "color: #a020f0;" > else< / span > {
fclose(f);
*size_max = -1L;
< span style = "color: #a020f0;" > return< / span > TREXIO_INT_SIZE_OVERFLOW;
}
}
/* < span style = "color: #b22222;" > Close the TXT file < / span > */
rc = fclose(f);
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > (rc != 0) < span style = "color: #a020f0;" > return< / span > TREXIO_FILE_ERROR;
2022-04-23 19:25:51 +02:00
/* < span style = "color: #b22222;" > Overwrite the value at the input address and return TREXIO_SUCCESS < / span > */
*size_max = size_accum;
< 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_text_write_determinant_list< / span > (< span style = "color: #228b22;" > trexio_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > file< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > int64_t< / span > < span style = "color: #a0522d;" > offset_file< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > rank< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > uint64_t< / span > * < span style = "color: #a0522d;" > dims< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > int64_t< / span > * < span style = "color: #a0522d;" > list< / 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 > (list == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_5;
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > determinant_list_file_name< / span > [256] = < span style = "color: #8b2252;" > "/determinant_list.txt"< / span > ;
/* < span style = "color: #b22222;" > The full path to the destination TXT file with sparse data. This will include TREXIO directory name. < / span > */
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > file_full_path< / span > [TREXIO_MAX_FILENAME_LENGTH];
/* < span style = "color: #b22222;" > Copy directory name in file_full_path < / span > */
strncpy (file_full_path, file-> file_name, TREXIO_MAX_FILENAME_LENGTH);
/* < span style = "color: #b22222;" > Append name of the file with sparse data < / span > */
strncat (file_full_path, determinant_list_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen(determinant_list_file_name));
/* < span style = "color: #b22222;" > Open the file in "a" (append) mode to guarantee that no truncation happens upon consecutive writes < / span > */
< span style = "color: #228b22;" > FILE< / span > * < span style = "color: #a0522d;" > f< / span > = fopen(file_full_path, < span style = "color: #8b2252;" > "a"< / span > );
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > (f == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FILE_ERROR;
2022-04-23 19:25:51 +02:00
/* < span style = "color: #b22222;" > Write the data in the file and check the return code of fprintf to verify that > 0 bytes have been written < / span > */
< span style = "color: #228b22;" > int< / span > < span style = "color: #a0522d;" > rc< / span > ;
< span style = "color: #a020f0;" > for< / span > (< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > i< / span > =0UL; i < dims[0]; ++i) {
/* < span style = "color: #b22222;" > The loop below is needed to write a line with int bit fields for alpha and beta electrons < / span > */
< span style = "color: #a020f0;" > for< / span > (< span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > j< / span > =0; j < (< span style = "color: #228b22;" > uint32_t< / span > ) dims[1]; ++j) {
rc = fprintf(f, < span style = "color: #8b2252;" > "%10"< / span > PRId64 < span style = "color: #8b2252;" > " "< / span > , *(list + i*dims[1] + j));
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > (rc < = 0) {
2022-04-23 19:25:51 +02:00
fclose(f);
< span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
}
}
fprintf(f, < span style = "color: #8b2252;" > "%s"< / span > , < span style = "color: #8b2252;" > "\n"< / span > );
}
/* < span style = "color: #b22222;" > Close the TXT file < / span > */
rc = fclose(f);
< span style = "color: #a020f0;" > if< / span > (rc != 0) < span style = "color: #a020f0;" > return< / span > TREXIO_FILE_ERROR;
2022-07-04 13:02:49 +02:00
/* < span style = "color: #b22222;" > Additional part for the trexio_text_has_group to work < / span > */
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > det_file_name< / span > [256] = < span style = "color: #8b2252;" > "/determinant.txt"< / span > ;
memset (file_full_path, 0, TREXIO_MAX_FILENAME_LENGTH);
/* < span style = "color: #b22222;" > Copy directory name in file_full_path < / span > */
strncpy (file_full_path, file-> file_name, TREXIO_MAX_FILENAME_LENGTH);
/* < span style = "color: #b22222;" > Append name of the file with sparse data < / span > */
strncat (file_full_path, det_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen(det_file_name));
< span style = "color: #228b22;" > bool< / span > < span style = "color: #a0522d;" > file_exists< / span > = trexio_text_file_exists(file_full_path);
/* < span style = "color: #b22222;" > Create an empty file for the trexio_text_has_group to work < / span > */
< span style = "color: #a020f0;" > if< / span > (!file_exists) {
< span style = "color: #228b22;" > FILE< / span > *< span style = "color: #a0522d;" > fp< / span > = fopen(file_full_path, < span style = "color: #8b2252;" > "ab+"< / span > );
fclose(fp);
}
2022-04-23 19:25:51 +02:00
/* < span style = "color: #b22222;" > Exit upon success < / span > */
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
}
< span style = "color: #228b22;" > trexio_exit_code< / span > < span style = "color: #0000ff;" > trexio_text_write_determinant_coefficient< / span > (< span style = "color: #228b22;" > trexio_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > file< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > int64_t< / span > < span style = "color: #a0522d;" > offset_file< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > uint32_t< / span > < span style = "color: #a0522d;" > rank< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > uint64_t< / span > * < span style = "color: #a0522d;" > dims< / span > ,
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > double< / span > * < span style = "color: #a0522d;" > coeff< / 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 > (coeff == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_5;
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > coeff_file_name< / span > [256];
memset(coeff_file_name, 0, < span style = "color: #a020f0;" > sizeof< / span > (coeff_file_name));
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > int32_t< / span > < span style = "color: #a0522d;" > trexio_state< / span > = file-> state;
< span style = "color: #a020f0;" > if< / span > (trexio_state != 0) {
sprintf(coeff_file_name, < span style = "color: #8b2252;" > "/determinant_coefficient_state_%"< / span > PRId32 < span style = "color: #8b2252;" > ".txt"< / span > , trexio_state);
} < span style = "color: #a020f0;" > else< / span > {
strncpy(coeff_file_name, < span style = "color: #8b2252;" > "/determinant_coefficient.txt"< / span > , 32);
}
/* < span style = "color: #b22222;" > The full path to the destination TXT file with sparse data. This will include TREXIO directory name. < / span > */
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > file_full_path< / span > [TREXIO_MAX_FILENAME_LENGTH];
/* < span style = "color: #b22222;" > Copy directory name in file_full_path < / span > */
strncpy (file_full_path, file-> file_name, TREXIO_MAX_FILENAME_LENGTH);
/* < span style = "color: #b22222;" > Append name of the file with sparse data < / span > */
strncat (file_full_path, coeff_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen(coeff_file_name));
/* < span style = "color: #b22222;" > Open the file in "a" (append) mode to guarantee that no truncation happens upon consecutive writes < / span > */
< span style = "color: #228b22;" > FILE< / span > * < span style = "color: #a0522d;" > f< / span > = fopen(file_full_path, < span style = "color: #8b2252;" > "a"< / span > );
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > (f == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FILE_ERROR;
2022-04-23 19:25:51 +02:00
/* < span style = "color: #b22222;" > Write the data in the file and check the return code of fprintf to verify that > 0 bytes have been written < / span > */
< span style = "color: #228b22;" > int< / span > < span style = "color: #a0522d;" > rc< / span > ;
< span style = "color: #a020f0;" > for< / span > (< span style = "color: #228b22;" > uint64_t< / span > < span style = "color: #a0522d;" > i< / span > =0UL; i < dims[0]; ++i) {
rc = fprintf(f, < span style = "color: #8b2252;" > "%24.16e\n"< / span > , *(coeff + i));
2022-05-19 17:24:20 +02:00
< span style = "color: #a020f0;" > if< / span > (rc < = 0) {
2022-04-23 19:25:51 +02:00
fclose(f);
< span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
}
}
/* < span style = "color: #b22222;" > Close the TXT file < / span > */
rc = fclose(f);
< span style = "color: #a020f0;" > if< / span > (rc != 0) < span style = "color: #a020f0;" > return< / span > TREXIO_FILE_ERROR;
/* < span style = "color: #b22222;" > Append .size to the file_full_path in order to write additional info about the written buffer of data < / span > */
strncat(file_full_path, < span style = "color: #8b2252;" > ".size"< / span > , 6);
/* < span style = "color: #b22222;" > Open the new file in "a" (append) mode to append info about the buffer that has been just written < / span > */
< span style = "color: #228b22;" > FILE< / span > *< span style = "color: #a0522d;" > f_wSize< / span > = fopen(file_full_path, < span style = "color: #8b2252;" > "a"< / span > );
< span style = "color: #a020f0;" > if< / span > (f_wSize == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_FILE_ERROR;
/* < span style = "color: #b22222;" > Write the buffer_size < / span > */
rc = fprintf(f_wSize, < span style = "color: #8b2252;" > "%"< / span > PRIu64 < span style = "color: #8b2252;" > "\n"< / span > , dims[0]);
< span style = "color: #a020f0;" > if< / span > (rc < = 0) {
fclose(f_wSize);
< span style = "color: #a020f0;" > return< / span > TREXIO_FAILURE;
}
/* < span style = "color: #b22222;" > Close the TXT file < / span > */
rc = fclose(f_wSize);
< span style = "color: #a020f0;" > if< / span > (rc != 0) < span style = "color: #a020f0;" > return< / span > TREXIO_FILE_ERROR;
2022-07-04 13:02:49 +02:00
/* < span style = "color: #b22222;" > Additional part for the trexio_text_has_group to work < / span > */
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > det_file_name< / span > [256] = < span style = "color: #8b2252;" > "/determinant.txt"< / span > ;
memset (file_full_path, 0, TREXIO_MAX_FILENAME_LENGTH);
/* < span style = "color: #b22222;" > Copy directory name in file_full_path < / span > */
strncpy (file_full_path, file-> file_name, TREXIO_MAX_FILENAME_LENGTH);
/* < span style = "color: #b22222;" > Append name of the file with sparse data < / span > */
strncat (file_full_path, det_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen(det_file_name));
< span style = "color: #228b22;" > bool< / span > < span style = "color: #a0522d;" > file_exists< / span > = trexio_text_file_exists(file_full_path);
/* < span style = "color: #b22222;" > Create an empty file for the trexio_text_has_group to work < / span > */
< span style = "color: #a020f0;" > if< / span > (!file_exists) {
< span style = "color: #228b22;" > FILE< / span > *< span style = "color: #a0522d;" > fp< / span > = fopen(file_full_path, < span style = "color: #8b2252;" > "ab+"< / span > );
fclose(fp);
}
2022-04-23 19:25:51 +02:00
/* < span style = "color: #b22222;" > Exit upon success < / span > */
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
}
< / pre >
< / div >
< div class = "org-src-container" >
< pre class = "src src-c" > < span style = "color: #228b22;" > trexio_exit_code< / span > < span style = "color: #0000ff;" > trexio_text_has_determinant_list< / span > (< span style = "color: #228b22;" > trexio_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > file< / span > )
{
< span style = "color: #a020f0;" > if< / span > (file == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_1;
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > determinant_list_file_name< / span > [256] = < span style = "color: #8b2252;" > "/determinant_list.txt"< / span > ;
/* < span style = "color: #b22222;" > The full path to the destination TXT file with sparse data. This will include TREXIO directory name. < / span > */
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > file_full_path< / span > [TREXIO_MAX_FILENAME_LENGTH];
/* < span style = "color: #b22222;" > Copy directory name in file_full_path < / span > */
strncpy (file_full_path, file-> file_name, TREXIO_MAX_FILENAME_LENGTH);
/* < span style = "color: #b22222;" > Append name of the file with sparse data < / span > */
strncat (file_full_path, determinant_list_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen(determinant_list_file_name));
/* < span style = "color: #b22222;" > Check the return code of access function to determine whether the file with data exists or not < / span > */
< span style = "color: #a020f0;" > if< / span > (access(file_full_path, F_OK) == 0){
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
} < span style = "color: #a020f0;" > else< / span > {
< span style = "color: #a020f0;" > return< / span > TREXIO_HAS_NOT;
}
}
< span style = "color: #228b22;" > trexio_exit_code< / span > < span style = "color: #0000ff;" > trexio_text_has_determinant_coefficient< / span > (< span style = "color: #228b22;" > trexio_t< / span > * < span style = "color: #a020f0;" > const< / span > < span style = "color: #a0522d;" > file< / span > )
{
< span style = "color: #a020f0;" > if< / span > (file == < span style = "color: #008b8b;" > NULL< / span > ) < span style = "color: #a020f0;" > return< / span > TREXIO_INVALID_ARG_1;
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > coeff_file_name< / span > [256];
memset(coeff_file_name, 0, < span style = "color: #a020f0;" > sizeof< / span > (coeff_file_name));
< span style = "color: #a020f0;" > const< / span > < span style = "color: #228b22;" > int32_t< / span > < span style = "color: #a0522d;" > trexio_state< / span > = file-> state;
< span style = "color: #a020f0;" > if< / span > (trexio_state != 0) {
sprintf(coeff_file_name, < span style = "color: #8b2252;" > "/determinant_coefficient_state_%"< / span > PRId32 < span style = "color: #8b2252;" > ".txt"< / span > , trexio_state);
} < span style = "color: #a020f0;" > else< / span > {
strncpy(coeff_file_name, < span style = "color: #8b2252;" > "/determinant_coefficient.txt"< / span > , 32);
}
/* < span style = "color: #b22222;" > The full path to the destination TXT file with sparse data. This will include TREXIO directory name. < / span > */
< span style = "color: #228b22;" > char< / span > < span style = "color: #a0522d;" > file_full_path< / span > [TREXIO_MAX_FILENAME_LENGTH];
/* < span style = "color: #b22222;" > Copy directory name in file_full_path < / span > */
strncpy (file_full_path, file-> file_name, TREXIO_MAX_FILENAME_LENGTH);
/* < span style = "color: #b22222;" > Append name of the file with sparse data < / span > */
strncat (file_full_path, coeff_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen(coeff_file_name));
/* < span style = "color: #b22222;" > Check the return code of access function to determine whether the file with data exists or not < / span > */
< span style = "color: #a020f0;" > if< / span > (access(file_full_path, F_OK) == 0){
< span style = "color: #a020f0;" > return< / span > TREXIO_SUCCESS;
} < span style = "color: #a020f0;" > else< / span > {
< span style = "color: #a020f0;" > return< / span > TREXIO_HAS_NOT;
}
}
< / pre >
< / div >
< / div >
2021-04-12 14:32:08 +02:00
< / div >
< / div >
< div id = "postamble" class = "status" >
< p class = "author" > Author: TREX-CoE< / p >
2022-07-28 13:50:07 +02:00
< p class = "date" > Created: 2022-07-28 Thu 11:50< / 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 >