1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-07-22 10:47:43 +02:00

org-mode to html conversion for the documentation website (#41)

* working static html doc website generated from org-mode files

* fix build_doc script

* add gitignore

* add gitignore

* clean html garbage

* documented hdf5

* documented text back end
This commit is contained in:
Evgeny Posenitskiy 2021-04-09 16:45:44 +02:00 committed by GitHub
parent 7e55933fea
commit 8defdaa0c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 1615 additions and 207 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "docs/org-html-themes"]
path = docs/org-html-themes
url = https://github.com:fniessen/org-html-themes.git

1
docs/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.html

1
docs/org-html-themes Submodule

@ -0,0 +1 @@
Subproject commit 39a8ce24babbf55667e3f4be21e37c619f55f257

15
docs/theme.setup Normal file
View File

@ -0,0 +1,15 @@
# -*- mode: org; -*-
#+HTML_LINK_HOME: index.html
#+OPTIONS: H:4 num:t toc:t \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t d:(HIDE)
# SETUPFILE: ../docs/org-html-themes/org/theme-readtheorg.setup
#+INFOJS_OPT: toc:t mouse:underline path:org-info.js
#+HTML_HEAD: <link rel="stylesheet" title="Standard" href="trexio.css" type="text/css" />
#+STARTUP: align fold nodlcheck hidestars oddeven lognotestate
#+AUTHOR: TREX-CoE
#+LANGUAGE: en

972
docs/trexio.css Normal file
View File

@ -0,0 +1,972 @@
/* Adapted from worg.css */
@import url(https://fonts.googleapis.com/css?family=Droid+Sans|Droid+Sans+Mono|Droid+Serif);
@media all
{
html {
margin: 0;
font: .9em/1.6em "Droid Serif", Cambria, Georgia, "DejaVu Serif", serif;
background-image: url(/img/org-mode-unicorn-logo-worg.png);
background-attachment: fixed;
background-position: right bottom;
background-repeat: no-repeat;
background-color: white;
}
body {
font-size: 14pt;
line-height: 22pt;
color: black;
margin-top: 0;
}
body #content {
padding-top: 2em;
margin: auto;
max-width: 70%;
background-color: white;
}
body #support {
position: fixed;
top:0;
display:block;
font-size: 12pt;
right:0pt;
text-align: right;
padding: .2em 1em;
background: #EEE;
border-radius: 10px;
}
body .title {
margin-left: 0px;
font-size: 22pt;
}
#org-div-home-and-up{
position: fixed;
right: 0.5em;
margin-top: 70px;
font-family:sans-serif;
}
/* TOC inspired by http://jashkenas.github.com/coffee-script */
#table-of-contents {
margin-top: 105px;
font-size: 10pt;
font-family:sans-serif;
position: fixed;
right: 0em;
top: 0em;
background: white;
line-height: 12pt;
text-align: right;
box-shadow: 0 0 1em #777777;
-webkit-box-shadow: 0 0 1em #777777;
-moz-box-shadow: 0 0 1em #777777;
-webkit-border-bottom-left-radius: 5px;
-moz-border-radius-bottomleft: 5px;
/* ensure doesn't flow off the screen when expanded */
max-height: 80%;
overflow: auto; }
#table-of-contents h2 {
font-size: 13pt;
max-width: 9em;
border: 0;
font-weight: normal;
padding-left: 0.5em;
padding-right: 0.5em;
padding-top: 0.05em;
padding-bottom: 0.05em; }
#table-of-contents #text-table-of-contents {
display: none;
text-align: left; }
#table-of-contents:hover #text-table-of-contents {
display: block;
padding: 0.5em;
margin-top: -1.5em; }
#license {
background-color: #eeeeee;
}
h1 {
font-size:2.1em;
padding:0 0 30px 0;
margin-top: 10px;
margin-bottom: 10px;
margin-right: 7%;
color: grey;
}
h2 {
font-family:sans-serif;
font-size:1.45em;
padding:10px 0 10px 0;
color: black;
border-bottom: 1px solid #ddd;
padding-top: 1.5em;
}
.outline-text-2 {
margin-left: 0.1em
}
h3 {
font-family:sans-serif;
font-size:1.3em;
color: grey;
margin-left: 0.6em;
padding-top: 1.5em;
}
/* #A34D32;*/
.outline-text-3 {
margin-left: 0.9em;
}
h4 {
font-family:sans-serif;
font-size:1.2em;
margin-left: 1.2em;
color: #A5573E;
padding-top: 1.5em;
}
.outline-text-4 {
margin-left: 1.45em;
}
a {text-decoration: none; font-weight: 400;}
a:visited {text-decoration: none; font-weight: 400;}
a:hover {text-decoration: underline;}
.todo {
color: #CA0000;
}
.done {
color: #006666;
}
.timestamp-kwd {
color: #444;
}
.tag {
background-color: #ffff;
color: #ffff;
}
li {
margin: .4em;
}
table {
border: 1;
border-color: grey;
}
thead {
border: 0;
}
tbody {
border: 0;
}
tr {
border: 0;
}
td {
border-left: 0px;
border-right: 0px;
border-top: 0px;
border-bottom: 0px;
}
th {
border-left: 0px;
border-right: 0px;
border-top: 1px solid grey;
border-bottom: 1px solid grey;
}
code {
font-size: 100%;
color: black;
padding: 0px 0.2em;
}
img {
border: 0;
}
.share img {
opacity: .4;
-moz-opacity: .4;
filter: alpha(opacity=40);
}
.share img:hover {
opacity: 1;
-moz-opacity: 1;
filter: alpha(opacity=100);
}
pre {
font-family: Droid Sans Mono, Monaco, Consolas, "Lucida Console", monospace;
color: black;
font-size: 90%;
padding: 0.5em;
overflow: auto;
border: none;
background-color: #f2f2f2;
border-radius: 5px;
}
.org-info-box {
clear:both;
margin-left:auto;
margin-right:auto;
padding:0.7em;
}
.org-info-box img {
float:left;
margin:0em 0.5em 0em 0em;
}
.org-info-box p {
margin:0em;
padding:0em;
}
.builtin {
/* font-lock-builtin-face */
color: #f4a460;
}
.comment {
/* font-lock-comment-face */
color: #737373;
}
.comment-delimiter {
/* font-lock-comment-delimiter-face */
color: #666666;
}
.constant {
/* font-lock-constant-face */
color: #db7093;
}
.doc {
/* font-lock-doc-face */
color: #b3b3b3;
}
.function-name {
/* font-lock-function-name-face */
color: #5f9ea0;
}
.headline {
/* headline-face */
color: #ffffff;
background-color: #000000;
font-weight: bold;
}
.keyword {
/* font-lock-keyword-face */
color: #4682b4;
}
.negation-char {
}
.regexp-grouping-backslash {
}
.regexp-grouping-construct {
}
.string {
/* font-lock-string-face */
color: #ccc79a;
}
.todo-comment {
/* todo-comment-face */
color: #ffffff;
background-color: #000000;
font-weight: bold;
}
.variable-name {
/* font-lock-variable-name-face */
color: #ff6a6a;
}
.warning {
/* font-lock-warning-face */
color: #ffffff;
background-color: #cd5c5c;
font-weight: bold;
}
.important {
/* font-lock-warning-face */
background-color: #e3e3f7;
}
.exercise {
/* font-lock-warning-face */
background-color: #e3f7e3;
}
.note {
/* font-lock-warning-face */
background-color: #f7f7d9;
}
pre.a {
color: inherit;
background-color: inherit;
font: inherit;
text-decoration: inherit;
}
pre.a:hover {
text-decoration: underline;
}
/* Styles for org-info.js */
.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-info-js-window
{
border-bottom:1px solid black;
padding-bottom:10px;
margin-bottom:10px;
}
.org-info-search-highlight
{
background-color:#adefef; /* same color as emacs default */
color:#000000;
font-weight:bold;
}
.org-bbdb-company {
/* bbdb-company */
font-style: italic;
}
.org-bbdb-field-name {
}
.org-bbdb-field-value {
}
.org-bbdb-name {
/* bbdb-name */
text-decoration: underline;
}
.org-bold {
/* bold */
font-weight: bold;
}
.org-bold-italic {
/* bold-italic */
font-weight: bold;
font-style: italic;
}
.org-border {
/* border */
background-color: #000000;
}
.org-buffer-menu-buffer {
/* buffer-menu-buffer */
font-weight: bold;
}
.org-builtin {
/* font-lock-builtin-face */
color: #da70d6;
}
.org-button {
/* button */
text-decoration: underline;
}
.org-c-nonbreakable-space {
/* c-nonbreakable-space-face */
background-color: #ff0000;
font-weight: bold;
}
.org-calendar-today {
/* calendar-today */
text-decoration: underline;
}
.org-comment {
/* font-lock-comment-face */
color: #b22222;
}
.org-comment-delimiter {
/* font-lock-comment-delimiter-face */
color: #b22222;
}
.org-constant {
/* font-lock-constant-face */
color: #5f9ea0;
}
.org-cursor {
/* cursor */
background-color: #000000;
}
.org-default {
/* default */
color: #000000;
background-color: #ffffff;
}
.org-diary {
/* diary */
color: #ff0000;
}
.org-doc {
/* font-lock-doc-face */
color: #bc8f8f;
}
.org-escape-glyph {
/* escape-glyph */
color: #a52a2a;
}
.org-file-name-shadow {
/* file-name-shadow */
color: #7f7f7f;
}
.org-fixed-pitch {
}
.org-fringe {
/* fringe */
background-color: #f2f2f2;
}
.org-function-name {
/* font-lock-function-name-face */
color: #0000ff;
}
.org-header-line {
/* header-line */
color: #333333;
background-color: #e5e5e5;
}
.org-help-argument-name {
/* help-argument-name */
font-style: italic;
}
.org-highlight {
/* highlight */
background-color: #b4eeb4;
}
.org-holiday {
/* holiday */
background-color: #ffc0cb;
}
.org-info-header-node {
/* info-header-node */
color: #a52a2a;
font-weight: bold;
font-style: italic;
}
.org-info-header-xref {
/* info-header-xref */
color: #0000ff;
text-decoration: underline;
}
.org-info-menu-header {
/* info-menu-header */
font-weight: bold;
}
.org-info-menu-star {
/* info-menu-star */
color: #ff0000;
}
.org-info-node {
/* info-node */
color: #a52a2a;
font-weight: bold;
font-style: italic;
}
.org-info-title-1 {
/* info-title-1 */
font-size: 172%;
font-weight: bold;
}
.org-info-title-2 {
/* info-title-2 */
font-size: 144%;
font-weight: bold;
}
.org-info-title-3 {
/* info-title-3 */
font-size: 120%;
font-weight: bold;
}
.org-info-title-4 {
/* info-title-4 */
font-weight: bold;
}
.org-info-xref {
/* info-xref */
color: #0000ff;
text-decoration: underline;
}
.org-isearch {
/* isearch */
color: #b0e2ff;
background-color: #cd00cd;
}
.org-italic {
/* italic */
font-style: italic;
}
.org-keyword {
/* font-lock-keyword-face */
color: #a020f0;
}
.org-lazy-highlight {
/* lazy-highlight */
background-color: #afeeee;
}
.org-link {
/* link */
color: #0000ff;
text-decoration: underline;
}
.org-link-visited {
/* link-visited */
color: #8b008b;
text-decoration: underline;
}
.org-match {
/* match */
background-color: #ffff00;
}
.org-menu {
}
.org-message-cited-text {
/* message-cited-text */
color: #ff0000;
}
.org-message-header-cc {
/* message-header-cc */
color: #191970;
}
.org-message-header-name {
/* message-header-name */
color: #6495ed;
}
.org-message-header-newsgroups {
/* message-header-newsgroups */
color: #00008b;
font-weight: bold;
font-style: italic;
}
.org-message-header-other {
/* message-header-other */
color: #4682b4;
}
.org-message-header-subject {
/* message-header-subject */
color: #000080;
font-weight: bold;
}
.org-message-header-to {
/* message-header-to */
color: #191970;
font-weight: bold;
}
.org-message-header-xheader {
/* message-header-xheader */
color: #0000ff;
}
.org-message-mml {
/* message-mml */
color: #228b22;
}
.org-message-separator {
/* message-separator */
color: #a52a2a;
}
.org-minibuffer-prompt {
/* minibuffer-prompt */
color: #0000cd;
}
.org-mm-uu-extract {
/* mm-uu-extract */
color: #006400;
background-color: #ffffe0;
}
.org-mode-line {
/* mode-line */
color: #000000;
background-color: #bfbfbf;
}
.org-mode-line-buffer-id {
/* mode-line-buffer-id */
font-weight: bold;
}
.org-mode-line-highlight {
}
.org-mode-line-inactive {
/* mode-line-inactive */
color: #333333;
background-color: #e5e5e5;
}
.org-mouse {
/* mouse */
background-color: #000000;
}
.org-negation-char {
}
.org-next-error {
/* next-error */
background-color: #eedc82;
}
.org-nobreak-space {
/* nobreak-space */
color: #a52a2a;
text-decoration: underline;
}
.org-org-agenda-date {
/* org-agenda-date */
color: #0000ff;
}
.org-org-agenda-date-weekend {
/* org-agenda-date-weekend */
color: #0000ff;
font-weight: bold;
}
.org-org-agenda-restriction-lock {
/* org-agenda-restriction-lock */
background-color: #ffff00;
}
.org-org-agenda-structure {
/* org-agenda-structure */
color: #0000ff;
}
.org-org-archived {
/* org-archived */
color: #7f7f7f;
}
.org-org-code {
/* org-code */
color: #7f7f7f;
}
.org-org-column {
/* org-column */
background-color: #e5e5e5;
}
.org-org-column-title {
/* org-column-title */
background-color: #e5e5e5;
font-weight: bold;
text-decoration: underline;
}
.org-org-date {
/* org-date */
color: #a020f0;
text-decoration: underline;
}
.org-org-done {
/* org-done */
color: #228b22;
font-weight: bold;
}
.org-org-drawer {
/* org-drawer */
color: #0000ff;
}
.org-org-ellipsis {
/* org-ellipsis */
color: #b8860b;
text-decoration: underline;
}
.org-org-formula {
/* org-formula */
color: #b22222;
}
.org-org-headline-done {
/* org-headline-done */
color: #bc8f8f;
}
.org-org-hide {
/* org-hide */
color: #e5e5e5;
}
.org-org-latex-and-export-specials {
/* org-latex-and-export-specials */
color: #8b4513;
}
.org-org-level-1 {
/* org-level-1 */
color: #0000ff;
}
.org-org-level-2 {
/* org-level-2 */
color: #b8860b;
}
.org-org-level-3 {
/* org-level-3 */
color: #a020f0;
}
.org-org-level-4 {
/* org-level-4 */
color: #b22222;
}
.org-org-level-5 {
/* org-level-5 */
color: #228b22;
}
.org-org-level-6 {
/* org-level-6 */
color: #5f9ea0;
}
.org-org-level-7 {
/* org-level-7 */
color: #da70d6;
}
.org-org-level-8 {
/* org-level-8 */
color: #bc8f8f;
}
.org-org-link {
/* org-link */
color: #a020f0;
text-decoration: underline;
}
.org-org-property-value {
}
.org-org-scheduled-previously {
/* org-scheduled-previously */
color: #b22222;
}
.org-org-scheduled-today {
/* org-scheduled-today */
color: #006400;
}
.org-org-sexp-date {
/* org-sexp-date */
color: #a020f0;
}
.org-org-special-keyword {
/* org-special-keyword */
color: #bc8f8f;
}
.org-org-table {
/* org-table */
color: #0000ff;
}
.org-org-tag {
/* org-tag */
font-weight: bold;
}
.org-org-target {
/* org-target */
text-decoration: underline;
}
.org-org-time-grid {
/* org-time-grid */
color: #b8860b;
}
.org-org-todo {
/* org-todo */
color: #ff0000;
}
.org-org-upcoming-deadline {
/* org-upcoming-deadline */
color: #b22222;
}
.org-org-verbatim {
/* org-verbatim */
color: #7f7f7f;
text-decoration: underline;
}
.org-org-warning {
/* org-warning */
color: #ff0000;
font-weight: bold;
}
.org-outline-1 {
/* outline-1 */
color: #0000ff;
}
.org-outline-2 {
/* outline-2 */
color: #b8860b;
}
.org-outline-3 {
/* outline-3 */
color: #a020f0;
}
.org-outline-4 {
/* outline-4 */
color: #b22222;
}
.org-outline-5 {
/* outline-5 */
color: #228b22;
}
.org-outline-6 {
/* outline-6 */
color: #5f9ea0;
}
.org-outline-7 {
/* outline-7 */
color: #da70d6;
}
.org-outline-8 {
/* outline-8 */
color: #bc8f8f;
}
.outline-text-1, .outline-text-2, .outline-text-3, .outline-text-4, .outline-text-5, .outline-text-6 {
/* Add more spacing between section. Padding, so that folding with org-info.js works as expected. */
}
.org-preprocessor {
/* font-lock-preprocessor-face */
color: #da70d6;
}
.org-query-replace {
/* query-replace */
color: #b0e2ff;
background-color: #cd00cd;
}
.org-regexp-grouping-backslash {
/* font-lock-regexp-grouping-backslash */
font-weight: bold;
}
.org-regexp-grouping-construct {
/* font-lock-regexp-grouping-construct */
font-weight: bold;
}
.org-region {
/* region */
background-color: #eedc82;
}
.org-rmail-highlight {
}
.org-scroll-bar {
/* scroll-bar */
background-color: #bfbfbf;
}
.org-secondary-selection {
/* secondary-selection */
background-color: #ffff00;
}
.org-shadow {
/* shadow */
color: #7f7f7f;
}
.org-show-paren-match {
/* show-paren-match */
background-color: #40e0d0;
}
.org-show-paren-mismatch {
/* show-paren-mismatch */
color: #ffffff;
background-color: #a020f0;
}
.org-string {
/* font-lock-string-face */
color: #bc8f8f;
}
.org-texinfo-heading {
/* texinfo-heading */
color: #0000ff;
}
.org-tool-bar {
/* tool-bar */
color: #000000;
background-color: #bfbfbf;
}
.org-tooltip {
/* tooltip */
color: #000000;
background-color: #ffffe0;
}
.org-trailing-whitespace {
/* trailing-whitespace */
background-color: #ff0000;
}
.org-type {
/* font-lock-type-face */
color: #228b22;
}
.org-underline {
/* underline */
text-decoration: underline;
}
.org-variable-name {
/* font-lock-variable-name-face */
color: #b8860b;
}
.org-variable-pitch {
}
.org-vertical-border {
}
.org-warning {
/* font-lock-warning-face */
color: #ff0000;
font-weight: bold;
}
.rss_box {}
.rss_title, rss_title a {}
.rss_items {}
.rss_item a:link, .rss_item a:visited, .rss_item a:active {}
.rss_item a:hover {}
.rss_date {}
pre.src {
position: static;
overflow: visible;
padding-top: 1.2em;
}
label.org-src-name {
font-size: 80%;
font-style: italic;
}
#show_source {margin: 0; padding: 0;}
#postamble {
font-size: 75%;
min-width: 700px;
max-width: 80%;
line-height: 14pt;
margin-left: 20px;
margin-top: 10px;
padding: .2em;
background-color: #ffffff;
z-index: -1000;
}
} /* END OF @media all */
@media screen
{
#table-of-contents {
position: fixed;
margin-top: 105px;
float: right;
border: 1px solid #red;
max-width: 50%;
overflow: auto;
}
} /* END OF @media screen */

30
src/README.org Normal file
View File

@ -0,0 +1,30 @@
#+TITLE: TREXIO source code documentation
#+PROPERTY: comments org
#+SETUPFILE: ../docs/theme.setup
------------------
- [[./templator_front.html][Front end API]]
- [[./templator_hdf5.html][HDF5 back end]]
- [[./templator_text.html][TEXT back end]]
--------------------------------
The ultimate goal of the TREXIO library is to provide a high-performance
implementation of basic I/O functionality for users within and beyond
the TREX-CoE.
The source code of the library is available at
https://github.com/trex-coe/trexio
and bug reports should be submitted at
https://github.com/trex-coe/trexio/issues.
------------------
[[https://trex-coe.eu/sites/default/files/inline-images/euflag.jpg]] [[https://trex-coe.eu][TREX: Targeting Real Chemical Accuracy at the Exascale]] project has received funding from the European Unions Horizon 2020 - Research and Innovation program - under grant agreement no. 952165. The content of this document does not represent the opinion of the European Union, and the European Union is not responsible for any use that might be made of such content.
# -*- mode: org -*-

View File

@ -1,9 +1,12 @@
#+Title: Templator for front end
#+TITLE: Front end API
#+PROPERTY: comments org
#+SETUPFILE: ../../docs/theme.setup
# -*- mode: org -*-
* Constant file prefixes (not used by generator) :noexport:
Prefixes in C contain mainly `#include` as well as some
`#define` and `typedef` statements.
Prefixes in C contain mainly ~#include~ as well as some
~#define~ and ~typedef~ statements.
Prefixes in Fortran contain back-end definitions.
#+NAME:header
@ -133,22 +136,23 @@ typedef int32_t trexio_exit_code;
result = [ "#+begin_src c :tangle prefix_front.h :exports none" ]
for (text, code,_) in table:
text=text.replace("~","")
result += [ f"#define {text:30s} ((trexio_exit_code) {code:d})" ]
text=text.replace("~","")
result += [ f"#define {text:30s} ((trexio_exit_code) {code:d})" ]
result += [ "#+end_src" ]
result += [ "" ]
result += [ "#+begin_src f90 :tangle prefix_fortran.f90 :exports none" ]
for (text, code,_) in table:
text=text.replace("~","")
result += [ f" integer(trexio_exit_code), parameter :: {text:30s} = {code:d}" ]
text=text.replace("~","")
result += [ f" integer(trexio_exit_code), parameter :: {text:30s} = {code:d}" ]
result += [ "#+end_src" ]
return '\n'.join(result)
#+end_src
#+RESULTS:
:results:
#+begin_src c :tangle prefix_front.h :exports none
@ -200,9 +204,7 @@ return '\n'.join(result)
#+begin_src c :tangle prefix_front.h :exports none :noweb yes
const char* trexio_string_of_error(const trexio_exit_code error);
void trexio_string_of_error_f(const trexio_exit_code error,
char result[<<MAX_STRING_LENGTH()>>]);
void trexio_string_of_error_f(const trexio_exit_code error, char result[<<MAX_STRING_LENGTH()>>]);
#+end_src
The text strings are extracted from the previous table.
@ -215,11 +217,11 @@ void trexio_string_of_error_f(const trexio_exit_code error,
result = []
for (text, code, message) in table:
text = text.replace("~","")
message = message.replace("'",'"')
result += [ f"""case {text}:
return {message};
break;""" ]
text = text.replace("~","")
message = message.replace("'",'"')
result += [ f"""case {text}:
return {message};
break;""" ]
return '\n'.join(result)
#+end_src
@ -272,52 +274,46 @@ return '\n'.join(result)
# Source
#+begin_src c :tangle prefix_front.c :noweb yes
const char* trexio_string_of_error(const trexio_exit_code error) {
const char*
trexio_string_of_error (const trexio_exit_code error)
{
switch (error) {
<<cases()>>
}
return "Unknown error";
}
void trexio_string_of_error_f(const trexio_exit_code error, char result[<<MAX_STRING_LENGTH()>>]) {
void
trexio_string_of_error_f (const trexio_exit_code error, char result[<<MAX_STRING_LENGTH()>>])
{
strncpy(result, trexio_string_of_error(error), <<MAX_STRING_LENGTH()>>);
}
#+end_src
# Fortran interface
#+begin_src f90 :tangle prefix_fortran.f90 :noexport :noweb yes
interface
subroutine trexio_string_of_error (error, string) bind(C, name='trexio_string_of_error_f')
use, intrinsic :: iso_c_binding
import
integer (trexio_exit_code), intent(in), value :: error
character, intent(out) :: string(<<MAX_STRING_LENGTH()>>)
end subroutine trexio_string_of_error
end interface
interface
subroutine trexio_string_of_error (error, string) bind(C, name='trexio_string_of_error_f')
use, intrinsic :: iso_c_binding
import
integer (trexio_exit_code), intent(in), value :: error
character, intent(out) :: string(<<MAX_STRING_LENGTH()>>)
end subroutine trexio_string_of_error
end interface
#+end_src
** Back ends
TREXIO has several back ends:
1) `TREXIO_HDF5` relies on extensive use of the HDF5 library and the associated file format.
The HDF5 file is binary and tailored to high-performance I/O. This back end is the default one.
HDF5 can be compiled with MPI for parallel I/O.
Note, that HDF5 has to be downloaded and installed independently of TREXIO, which may cause
some obstacles, especially when the user is not allowed to install external software.
The produced files usually have `.h5` extension.
1) ~TREXIO_HDF5~ relies on extensive use of the HDF5 library and the associated file format. The HDF5 file is binary and tailored to high-performance I/O. This back end is the default one. HDF5 can be compiled with MPI for parallel I/O. Note, that HDF5 has to be downloaded and installed independently of TREXIO, which may cause some obstacles, especially when the user is not allowed to install external software. The produced files usually have ~.h5~ extension.
2) `TREXIO_TEXT` relies on basic file I/O in C, namely `fopen, fclose, fprintf, fscanf` etc.
from `stdio.h` library. This back end is not optimized for performance. It is supposed to be
used for debug purposes or, for example, when the user wants to modify some data manually within the file.
This back end is supposed to work "out-of-the-box" since there are no external dependencies, which might
be useful for users that do not have access to HDF5 library.
The produced files usually have `.txt` extension.
2) ~TREXIO_TEXT~ relies on basic file I/O in C, namely ~fopen, fclose, fprintf, fscanf~ etc. from ~stdio.h~ library. This back end is not optimized for performance. It is supposed to be used for debug purposes or, for example, when the user wants to modify some data manually within the file. This back end is supposed to work "out-of-the-box" since there are no external dependencies, which might be useful for users that do not have access to HDF5 library. The produced files usually have ~.txt~ extension.
Additional back ends can be implemented thanks to the modular nature of the front end.
This can be achieved by adding a new `case` (corresponding to the desired back end) in the front-end `switch`
Then the corresponding back-end `has/read/write_` functions has to be implemented. For example, see the commented
lines that correspond to the `TREXIO_JSON` back end (not implemented yet).
This can be achieved by adding a new ~case~ (corresponding to the desired back end) in the front-end ~switch~.
Then the corresponding back-end ~has/read/write~ functions has to be implemented. For example, see the commented
lines that correspond to the ~TREXIO_JSON~ back end (not implemented yet).
#+begin_src c :tangle prefix_front.h
typedef int32_t back_end_t;
@ -327,7 +323,6 @@ typedef int32_t back_end_t;
/*#define TREXIO_JSON ( (back_end_t) 2 )*/
#define TREXIO_INVALID_BACK_END ( (back_end_t) 2 )
#+end_src
** Read/write behavior
Every time a reading function is called, the data is read from the
@ -336,7 +331,7 @@ typedef int32_t back_end_t;
Writing to TREXIO files is done with transactions (all-or-nothing
effect) in a per-group fashion. File writes are attempted by
calling explicitly the write (`TREXIO_HDF5`) or flush (`TREXIO_TEXT`)
calling explicitly the write (~TREXIO_HDF5~) or flush (~TREXIO_TEXT~)
function, or when the TREXIO file is closed.
If writing is impossible because the data is not valid, no data is written.
@ -346,7 +341,6 @@ typedef int32_t back_end_t;
The TREXIO files are supposed to be opened by only one program at a
time: if the same TREXIO file is modified simultaneously by multiple
concurrent programs, the behavior is not specified.
** TREXIO file type
~trexio_s~ is the the main type for TREXIO files, visible to the users
@ -371,7 +365,6 @@ struct trexio_s {
char padding[7]; /* Ensures the proper alignment of back ends */
};
#+end_src
** Polymorphism of the file handle
Polymorphism of the ~trexio_t~ type is handled by ensuring that the
@ -388,33 +381,36 @@ struct trexio_back_end_s {
** File opening
`trexio_open` creates a new ~TREXIO~ file or opens existing one.
~trexio_open~ creates a new TREXIO file or opens existing one.
`trexio_open` input:
1) `file_name` - string containing file name
2) `mode` - character containing open mode (see below)
1. `'w'` - (write) creates a new file as READWRITE (overwrite existing file)
2. `'r'` - (read) opens existing file as READONLY
3. `'a'` - (append) either opens file in READWRITE mode if it already exists or creates a new one
3) `back_end` - integer number (or the corresponding global parameter) specifying the back end
1. `TREXIO_HDF5` - for HDF5 back end (integer alternative: 0)
2. `TREXIO_TEXT` - for TEXT back end (integer alternative: 1)
input parameters:
1) ~file_name~ - string containing file name
2) ~mode~ - character containing open mode (see below)
- ~'w'~ - (write) creates a new file as READWRITE (overwrite existing file)
- ~'r'~ - (read) opens existing file as READONLY
- ~'a'~ - (append) either opens file in READWRITE mode if it already exists or creates a new one
3) ~back_end~ - integer number (or the corresponding global parameter) specifying the back end
- ~TREXIO_HDF5~ - for HDF5 back end (integer alternative: 0)
- ~TREXIO_TEXT~ - for TEXT back end (integer alternative: 1)
`trexio_open` output:
`trexio_t` file handle
output:
~trexio_t~ file handle
_**Note: the `file_name` in TEXT back end actually corresponds to the name of the folder where `.txt`
data files are stored. The actual name of each `.txt.` file corresponds to the `group` name provided in
`trex.config` (e.g. `nucleus.txt` for nucleus-related data like atomic coordinates).
These names are populated by the `generator.py` (i.e. they are hard-coded), which is why the user
should tend to avoid renaming the `.txt` data files.**_
Note: the ~file_name~ in TEXT back end actually corresponds to the name of the folder where ~.txt~
data files are stored. The actual name of each ~.txt~ file corresponds to the group name provided in
~trex.config~ (e.g. ~nucleus.txt~ for nuclei-related data).
These names are populated by the generator.py (i.e. they are hard-coded), which is why the user
should tend to avoid renaming the ~.txt~ data files.
#+begin_src c :tangle prefix_front.h
trexio_t* trexio_open(const char* file_name, const char mode, const back_end_t back_end);
#+end_src
#+begin_src c :tangle prefix_front.c
trexio_t* trexio_open(const char* file_name, const char mode, const back_end_t back_end) {
trexio_t*
trexio_open(const char* file_name, const char mode,
const back_end_t back_end)
{
if (file_name == NULL) return NULL;
if (file_name[0] == '\0') return NULL;
@ -526,20 +522,22 @@ end interface
** File closing
`trexio_close` closes an existing `trexio_t` file.
~trexio_close~ closes an existing ~trexio_t~ file.
`trexio_close` input:
`file` - TREXIO file handle.
input parameters:
~file~ -- TREXIO file handle.
`trexio_close` output:
`trexio_exit_code` exit code.
output:
~trexio_exit_code~ exit code.
#+begin_src c :tangle prefix_front.h
#+begin_src c :tangle prefix_front.h
trexio_exit_code trexio_close(trexio_t* file);
#+end_src
#+end_src
#+begin_src c :tangle prefix_front.c
trexio_exit_code trexio_close(trexio_t* file) {
#+begin_src c :tangle prefix_front.c
trexio_exit_code
trexio_close (trexio_t* file)
{
if (file == NULL) return TREXIO_FAILURE;
@ -604,21 +602,23 @@ trexio_exit_code trexio_close(trexio_t* file) {
return TREXIO_SUCCESS;
}
#+end_src
#+end_src
#+begin_src f90 :tangle prefix_fortran.f90
#+begin_src f90 :tangle prefix_fortran.f90
interface
integer function trexio_close (trex_file) bind(C)
use, intrinsic :: iso_c_binding
integer(8), intent(in), value :: trex_file
end function trexio_close
end interface
#+end_src
#+end_src
* Templates for front end
Consider the following block of `trex.json`:
Consider the following block of ~trex.json~:
#+begin_src python
{
"nucleus": {
"num" : [ "int" , [ ] ]
@ -627,46 +627,47 @@ end interface
, "label" : [ "char" , [ "nucleus.num", "32" ] ]
}
}
#+end_src
~TREXIO~ is generated automatically by the `generator.py` Python script
based on the tree-like configuration provided in the `trex.json` file.
~TREXIO~ is generated automatically by the ~generator.py~ Python script
based on the tree-like configuration provided in the ~trex.json~ file.
Because of that, generalized templates can be implemented and re-used.
This approach minimizes the number of bugs as compared with manual copy-paste-modify scheme.
All templates presented below use the `$var$` notation to indicate the variable,
which will be replaced by the `generator.py`. Sometimes the upper case is used, i.e.
`$VAR$` (for example, in `#define` statements).
All templates presented below use the ~$var$~ notation to indicate the variable,
which will be replaced by the ~generator.py~. Sometimes the upper case is used, i.e.
~$VAR$~ (for example, in ~#define~ statements).
More detailed description of each variable can be found below:
| Template variable | Description | Example |
|-------------------------------+--------------------------------------------------+------------------|
| ~$group$~ | 'Name of the group' | nucleus |
| ~$group_num$~ | 'Name of the dimensioning variable (scalar)' | nucleus_num |
| ~$group_dset$~ | 'Name of the dataset (vector/matrix/tensor)' | nucleus_coord |
| ~$group_dset_rank$~ | 'Rank of the dataset' | 2 |
| ~$group_dset_dim$~ | 'Selected dimension of the dataset' | nucleus_num |
| ~$group_dset_dim_list$~ | 'All dimensions of the dataset' | {nucleus_num, 3} |
| ~$group_dset_dtype$~ | 'Basic type of the dataset (int/float/char)' | float |
| ~$group_dset_h5_dtype$~ | 'Type of the dataset in HDF5' | double |
| ~$group_dset_std_dtype_in$~ | 'Input type of the dataset in TEXT [fscanf] ' | %lf |
| ~$group_dset_std_dtype_out$~ | 'Output type of the dataset in TEXT [fprintf]' | %24.16e |
| ~$group_dset_dtype_single$~ | 'Single precision type of the dataset [C]' | float |
| ~$group_dset_dtype_double$~ | 'Double precision type of the dataset [C]' | double |
| ~$group_dset_f_dtype_single$~ | 'Single precision type of the dataset [Fortran]' | real(4) |
| ~$group_dset_f_dtype_double$~ | 'Double precision type of the dataset [Fortran]' | real(8) |
| Template variable | Description | Example |
|-------------------------------+--------------------------------------------------+--------------------|
| ~$group$~ | 'Name of the group' | ~nucleus~ |
| ~$group_num$~ | 'Name of the dimensioning variable (scalar)' | ~nucleus_num~ |
| ~$group_dset$~ | 'Name of the dataset (vector/matrix/tensor)' | ~nucleus_coord~ |
| ~$group_dset_rank$~ | 'Rank of the dataset' | ~2~ |
| ~$group_dset_dim$~ | 'Selected dimension of the dataset' | ~nucleus_num~ |
| ~$group_dset_dim_list$~ | 'All dimensions of the dataset' | ~{nucleus_num, 3}~ |
| ~$group_dset_dtype$~ | 'Basic type of the dataset (int/float/char)' | ~float~ |
| ~$group_dset_h5_dtype$~ | 'Type of the dataset in HDF5' | ~double~ |
| ~$group_dset_std_dtype_in$~ | 'Input type of the dataset in TEXT [fscanf] ' | ~%lf~ |
| ~$group_dset_std_dtype_out$~ | 'Output type of the dataset in TEXT [fprintf]' | ~%24.16e~ |
| ~$group_dset_dtype_single$~ | 'Single precision type of the dataset [C]' | ~float~ |
| ~$group_dset_dtype_double$~ | 'Double precision type of the dataset [C]' | ~double~ |
| ~$group_dset_f_dtype_single$~ | 'Single precision type of the dataset [Fortran]' | ~real(4)~ |
| ~$group_dset_f_dtype_double$~ | 'Double precision type of the dataset [Fortran]' | ~real(8)~ |
Note: parent group name is always added to the child objects upon consruction of TREXIO
(e.g. `num` of `nucleus` group becomes `nucleus_num` and should be accessed accordingly within TREXIO).
Note: parent group name is always added to the child objects upon construction of TREXIO
(e.g. ~num~ of ~nucleus~ group becomes ~nucleus_num~ and should be accessed accordingly within TREXIO).
TREXIO generator parses the `trex.json` file. TREXIO operates with names of variables
based on the 1-st (parent group) and 2-nd (child object) levels of `trex.json`.
The parsed configutation is divided in 2 parts:
TREXIO generator parses the ~trex.json~ file. TREXIO operates with names of variables
based on the 1-st (parent group) and 2-nd (child object) levels of ~trex.json~ .
The parsed data is divided in 2 parts:
1) Dimensioning variables (containing `num`). These are always scalar integers.
2) Datasets. These can be vectors, matrices or tensors. The types are indicated in `trex.json`.
1) Dimensioning variables (contain ~num~ in their names). These are always scalar integers.
2) Datasets. These can be vectors, matrices or tensors. The types are indicated in ~trex.json~.
Currently supported types: int, float. TODO: strings.
For each of the aforementioned objects, TREXIO provides `has`,`read` and `write` functionality.
For each of the aforementioned objects, TREXIO provides *has*, *read* and *write* functionality.
TREXIO supports I/O with single or double precision for integer and floating point numbers.
@ -674,26 +675,26 @@ end interface
This section concerns API calls related to dimensioning variables.
| Function name | Description | Precision |
|-------------------------------+----------------------------------------------------+-----------|
| ~trexio_has_$group_num$~ | 'Check if a dimensioning variable exists in a file | --- |
| ~trexio_read_$group_num$~ | 'Read a dimensioning variable ' | Single |
| ~trexio_write_$group_num$~ | 'Write a dimensioning variable' | Single |
| ~trexio_read_$group_num$_32~ | 'Read a dimensioning variable ' | Single |
| ~trexio_write_$group_num$_32~ | 'Write a dimensioning variable' | Single |
| ~trexio_read_$group_num$_64~ | 'Read a dimensioning variable ' | Double |
| ~trexio_write_$group_num$_64~ | 'Write a dimensioning variable' | Double |
| Function name | Description | Precision |
|-------------------------------+-----------------------------------------------------+-----------|
| ~trexio_has_$group_num$~ | 'Check if a dimensioning variable exists in a file' | --- |
| ~trexio_read_$group_num$~ | 'Read a dimensioning variable ' | Single |
| ~trexio_write_$group_num$~ | 'Write a dimensioning variable' | Single |
| ~trexio_read_$group_num$_32~ | 'Read a dimensioning variable ' | Single |
| ~trexio_write_$group_num$_32~ | 'Write a dimensioning variable' | Single |
| ~trexio_read_$group_num$_64~ | 'Read a dimensioning variable ' | Double |
| ~trexio_write_$group_num$_64~ | 'Write a dimensioning variable' | Double |
*** C templates for front end f
*** C templates for front end
The C templates that correspond to each of the abovementioned functions can be found below.
The ~C~ templates that correspond to each of the abovementioned functions can be found below.
First parameter is the ~TREXIO~ file handle. Second parameter is the variable to be written/read
to/from the ~TREXIO~ file (except for `trexio_has_` functions).
Suffixes `_32` and `_64` correspond to API calls dealing with single and double precision, respectively.
to/from the ~TREXIO~ file (except for ~trexio_has_~ functions).
Suffixes ~_32~ and ~_64~ correspond to API calls dealing with single and double precision, respectively.
The basic (non-suffixed) API call on dimensioning variables deals with single precision (see Table above).
#+begin_src c :tangle hrw_num_front.h
#+begin_src c :tangle hrw_num_front.h :exports none
trexio_exit_code trexio_has_$group_num$(trexio_t* const file);
trexio_exit_code trexio_read_$group_num$(trexio_t* const file, int32_t* const num);
trexio_exit_code trexio_write_$group_num$(trexio_t* const file, const int32_t num);
@ -704,7 +705,9 @@ trexio_exit_code trexio_write_$group_num$_64(trexio_t* const file, const int64_t
#+end_src
#+begin_src c :tangle read_num_64_front.c
trexio_exit_code trexio_read_$group_num$_64(trexio_t* const file, int64_t* const num) {
trexio_exit_code
trexio_read_$group_num$_64 (trexio_t* const file, int64_t* const num)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
uint64_t u_num = 0;
@ -734,7 +737,9 @@ trexio_exit_code trexio_read_$group_num$_64(trexio_t* const file, int64_t* const
#+end_src
#+begin_src c :tangle write_num_64_front.c
trexio_exit_code trexio_write_$group_num$_64(trexio_t* const file, const int64_t num) {
trexio_exit_code
trexio_write_$group_num$_64 (trexio_t* const file, const int64_t num)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (num < 0 ) return TREXIO_INVALID_ARG_2;
@ -762,7 +767,9 @@ trexio_exit_code trexio_write_$group_num$_64(trexio_t* const file, const int64_t
#+end_src
#+begin_src c :tangle read_num_32_front.c
trexio_exit_code trexio_read_$group_num$_32(trexio_t* const file, int32_t* const num) {
trexio_exit_code
trexio_read_$group_num$_32 (trexio_t* const file, int32_t* const num)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
uint64_t u_num = 0;
@ -792,7 +799,10 @@ trexio_exit_code trexio_read_$group_num$_32(trexio_t* const file, int32_t* const
#+end_src
#+begin_src c :tangle write_num_32_front.c
trexio_exit_code trexio_write_$group_num$_32(trexio_t* const file, const int32_t num) {
trexio_exit_code
trexio_write_$group_num$_32 (trexio_t* const file, const int32_t num)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (num < 0 ) return TREXIO_INVALID_ARG_2;
@ -820,19 +830,26 @@ trexio_exit_code trexio_write_$group_num$_32(trexio_t* const file, const int32_t
#+end_src
#+begin_src c :tangle read_num_def_front.c
trexio_exit_code trexio_read_$group_num$(trexio_t* const file, int32_t* const num) {
trexio_exit_code
trexio_read_$group_num$ (trexio_t* const file, int32_t* const num)
{
return trexio_read_$group_num$_32(file, num);
}
#+end_src
#+begin_src c :tangle write_num_def_front.c
trexio_exit_code trexio_write_$group_num$(trexio_t* const file, const int32_t num) {
trexio_exit_code
trexio_write_$group_num$ (trexio_t* const file, const int32_t num)
{
return trexio_write_$group_num$_32(file, num);
}
#+end_src
#+begin_src c :tangle has_num_front.c
trexio_exit_code trexio_has_$group_num$(trexio_t* const file) {
trexio_exit_code
trexio_has_$group_num$ (trexio_t* const file)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
switch (file->back_end) {
@ -858,8 +875,8 @@ trexio_exit_code trexio_has_$group_num$(trexio_t* const file) {
*** Fortran templates for front end
The Fortran templates that provide an access to the C API calls from Fortran.
These templates are based on the use of `iso_c_binding`. Pointers have to be passed by value.
The ~Fortran~ templates that provide an access to the ~C~ API calls from Fortran.
These templates are based on the use of ~iso_c_binding~. Pointers have to be passed by value.
#+begin_src f90 :tangle write_num_64_front_fortran.f90
interface
@ -929,30 +946,32 @@ interface
end function trexio_has_$group_num$
end interface
#+end_src
** Templates for front end has/read/write a dataset
This section concerns API calls related to datasets.
| Function name | Description | Precision |
|----------------------------------------+--------------------------------------+-----------|
| ~trexio_has_$group$_$group_dset$~ | 'Check if a dataset exists in a file | --- |
| ~trexio_read_$group$_$group_dset$~ | 'Read a dataset ' | Double |
| ~trexio_write_$group$_$group_dset$~ | 'Write a dataset' | Double |
| ~trexio_read_$group$_$group_dset$_32~ | 'Read a dataset' | Single |
| ~trexio_write_$group$_$group_dset$_32~ | 'Write a dataset' | Single |
| ~trexio_read_$group$_$group_dset$_64~ | 'Read a dataset' | Double |
| ~trexio_write_$group$_$group_dset$_64~ | 'Write a dataset' | Double |
| Function name | Description | Precision |
|----------------------------------------+---------------------------------------+-----------|
| ~trexio_has_$group$_$group_dset$~ | 'Check if a dataset exists in a file' | --- |
| ~trexio_read_$group$_$group_dset$~ | 'Read a dataset ' | Double |
| ~trexio_write_$group$_$group_dset$~ | 'Write a dataset' | Double |
| ~trexio_read_$group$_$group_dset$_32~ | 'Read a dataset' | Single |
| ~trexio_write_$group$_$group_dset$_32~ | 'Write a dataset' | Single |
| ~trexio_read_$group$_$group_dset$_64~ | 'Read a dataset' | Double |
| ~trexio_write_$group$_$group_dset$_64~ | 'Write a dataset' | Double |
*** C templates for front end
The C templates that correspond to each of the abovementioned functions can be found below.
First parameter is the ~TREXIO~ file handle. Second parameter is the variable to be written/read
to/from the ~TREXIO~ file (except for `trexio_has_` functions).
Suffixes `_32` and `_64` correspond to API calls dealing with single and double precision, respectively.
to/from the ~TREXIO~ file (except for ~trexio_has_~ functions).
Suffixes ~_32~ and ~_64~ correspond to API calls dealing with single and double precision, respectively.
The basic (non-suffixed) API call on datasets deals with double precision (see Table above).
#+begin_src c :tangle hrw_dset_front.h
#+begin_src c :tangle hrw_dset_front.h :exports none
trexio_exit_code trexio_has_$group$_$group_dset$(trexio_t* const file);
trexio_exit_code trexio_read_$group$_$group_dset$(trexio_t* const file, $group_dset_dtype_double$* const $group_dset$);
trexio_exit_code trexio_write_$group$_$group_dset$(trexio_t* const file, const $group_dset_dtype_double$* $group_dset$);
@ -963,7 +982,10 @@ trexio_exit_code trexio_write_$group$_$group_dset$_64(trexio_t* const file, cons
#+end_src
#+begin_src c :tangle read_dset_64_front.c
trexio_exit_code trexio_read_$group$_$group_dset$_64(trexio_t* const file, $group_dset_dtype_double$* const $group_dset$) {
trexio_exit_code
trexio_read_$group$_$group_dset$_64 (trexio_t* const file, $group_dset_dtype_double$* const $group_dset$)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
@ -999,7 +1021,10 @@ trexio_exit_code trexio_read_$group$_$group_dset$_64(trexio_t* const file, $grou
#+end_src
#+begin_src c :tangle write_dset_64_front.c
trexio_exit_code trexio_write_$group$_$group_dset$_64(trexio_t* const file, const $group_dset_dtype_double$* $group_dset$) {
trexio_exit_code
trexio_write_$group$_$group_dset$_64 (trexio_t* const file, const $group_dset_dtype_double$* $group_dset$)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
@ -1035,7 +1060,10 @@ trexio_exit_code trexio_write_$group$_$group_dset$_64(trexio_t* const file, cons
#+end_src
#+begin_src c :tangle read_dset_32_front.c
trexio_exit_code trexio_read_$group$_$group_dset$_32(trexio_t* const file, $group_dset_dtype_single$* const $group_dset$) {
trexio_exit_code
trexio_read_$group$_$group_dset$_32 (trexio_t* const file, $group_dset_dtype_single$* const $group_dset$)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
@ -1091,7 +1119,10 @@ trexio_exit_code trexio_read_$group$_$group_dset$_32(trexio_t* const file, $grou
#+end_src
#+begin_src c :tangle write_dset_32_front.c
trexio_exit_code trexio_write_$group$_$group_dset$_32(trexio_t* const file, const $group_dset_dtype_single$* $group_dset$) {
trexio_exit_code
trexio_write_$group$_$group_dset$_32 (trexio_t* const file, const $group_dset_dtype_single$* $group_dset$)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
@ -1146,19 +1177,26 @@ trexio_exit_code trexio_write_$group$_$group_dset$_32(trexio_t* const file, cons
#+end_src
#+begin_src c :tangle read_dset_def_front.c
trexio_exit_code trexio_read_$group$_$group_dset$(trexio_t* const file, $group_dset_dtype_double$* const $group_dset$) {
trexio_exit_code
trexio_read_$group$_$group_dset$ (trexio_t* const file, $group_dset_dtype_double$* const $group_dset$)
{
return trexio_read_$group$_$group_dset$_64(file, $group_dset$);
}
#+end_src
#+begin_src c :tangle write_dset_def_front.c
trexio_exit_code trexio_write_$group$_$group_dset$(trexio_t* const file, const $group_dset_dtype_double$* $group_dset$) {
trexio_exit_code
trexio_write_$group$_$group_dset$ (trexio_t* const file, const $group_dset_dtype_double$* $group_dset$)
{
return trexio_write_$group$_$group_dset$_64(file, $group_dset$);
}
#+end_src
#+begin_src c :tangle has_dset_front.c
trexio_exit_code trexio_has_$group$_$group_dset$(trexio_t* const file) {
trexio_exit_code
trexio_has_$group$_$group_dset$ (trexio_t* const file)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
switch (file->back_end) {
@ -1183,8 +1221,8 @@ trexio_exit_code trexio_has_$group$_$group_dset$(trexio_t* const file) {
*** Fortran templates for front end
The Fortran templates that provide an access to the C API calls from Fortran.
These templates are based on the use of `iso_c_binding`. Pointers have to be passed by value.
The ~Fortran~ templates that provide an access to the ~C~ API calls from ~Fortran~.
These templates are based on the use of ~iso_c_binding~. Pointers have to be passed by value.
#+begin_src f90 :tangle write_dset_64_front_fortran.f90
interface
@ -1257,8 +1295,8 @@ end interface
* Fortran helper/wrapper functions
The function below adapts the original C-based `trexio_open` for Fortran.
This is needed due to the fact that strings in C are terminated by NULL character `\0`
The function below adapts the original C-based ~trexio_open~ for Fortran.
This is needed due to the fact that strings in C are terminated by ~NULL~ character ~\0~
unlike strings in Fortran.
Note, that Fortran interface calls the main ~TREXIO~ API, which is written in C.

View File

@ -1,8 +1,18 @@
#+Title: Templator for HDF5 back end
#+TITLE: HDF5 back end
#+PROPERTY: comments org
#+SETUPFILE: ../../docs/theme.setup
# -*- mode: org -*-
* Constant file prefixes (not used by the generator) :noexport:
#+begin_src emacs-lisp
(setq-local org-babel-default-header-args:c '((:comments . "both")))
org-babel-default-header-args:c
#+end_src
#+RESULTS:
: ((:comments . both))
#+NAME:header
#+begin_src c
/* This file was generated from the org-mode file.
@ -12,6 +22,9 @@
#+end_src
DOCUMENT HDF5 BACK END HERE
#+begin_src c :tangle prefix_hdf5.h :noweb yes
<<header>>
#ifndef TREXIO_HDF5_H
@ -41,34 +54,35 @@
* HDF5 back end
** Template for HDF5 definitions
#+begin_src c :tangle def_hdf5.c
#define $GROUP$_GROUP_NAME "$group$"
#define $GROUP_NUM$_NAME "$group_num$"
#define $GROUP$_$GROUP_DSET$_NAME "$group_dset$"
#+end_src
#+begin_src c :tangle def_hdf5.c
#define $GROUP$_GROUP_NAME "$group$"
#define $GROUP_NUM$_NAME "$group_num$"
#define $GROUP$_$GROUP_DSET$_NAME "$group_dset$"
#+end_src
** Template for HDF5 structures
#+begin_src c :tangle struct_hdf5.h
typedef struct trexio_hdf5_s {
trexio_t parent ;
hid_t file_id;
hid_t $group$_group;
const char* file_name;
} trexio_hdf5_t;
#+end_src
#+begin_src c :tangle struct_hdf5.h :exports none
trexio_exit_code trexio_hdf5_init(trexio_t* const file);
trexio_exit_code trexio_hdf5_deinit(trexio_t* const file);
#+end_src
** Template for HDF5 init/deinit
#+begin_src c :tangle basic_hdf5.c
trexio_exit_code trexio_hdf5_init(trexio_t* const file) {
trexio_exit_code
trexio_hdf5_init (trexio_t* const file)
{
trexio_hdf5_t* const f = (trexio_hdf5_t*) file;
@ -126,7 +140,9 @@ trexio_exit_code trexio_hdf5_init(trexio_t* const file) {
return TREXIO_SUCCESS;
}
trexio_exit_code trexio_hdf5_deinit(trexio_t* const file) {
trexio_exit_code
trexio_hdf5_deinit (trexio_t* const file)
{
trexio_hdf5_t* f = (trexio_hdf5_t*) file;
@ -137,13 +153,13 @@ trexio_exit_code trexio_hdf5_deinit(trexio_t* const file) {
f->file_id = 0;
return TREXIO_SUCCESS;
}
}
#+end_src
** Template for HDF5 has/read/write a number
#+begin_src c :tangle hrw_num_hdf5.h
#+begin_src c :tangle hrw_num_hdf5.h :exports none
trexio_exit_code trexio_hdf5_has_$group_num$ (trexio_t* const file);
trexio_exit_code trexio_hdf5_read_$group_num$ (trexio_t* const file, uint64_t* const num);
trexio_exit_code trexio_hdf5_write_$group_num$(trexio_t* const file, const uint64_t num);
@ -151,7 +167,10 @@ trexio_exit_code trexio_hdf5_write_$group_num$(trexio_t* const file, const uint6
#+begin_src c :tangle read_num_hdf5.c
trexio_exit_code trexio_hdf5_read_$group_num$ (trexio_t* const file, uint64_t* const num) {
trexio_exit_code
trexio_hdf5_read_$group_num$ (trexio_t* const file, uint64_t* const num)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (num == NULL) return TREXIO_INVALID_ARG_2;
@ -167,12 +186,16 @@ trexio_exit_code trexio_hdf5_read_$group_num$ (trexio_t* const file, uint64_t* c
if (status < 0) return TREXIO_FAILURE;
return TREXIO_SUCCESS;
}
#+end_src
#+begin_src c :tangle write_num_hdf5.c
trexio_exit_code trexio_hdf5_write_$group_num$ (trexio_t* const file, const uint64_t num) {
trexio_exit_code
trexio_hdf5_write_$group_num$ (trexio_t* const file, const uint64_t num)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (num == 0L ) return TREXIO_INVALID_ARG_2;
@ -234,12 +257,14 @@ trexio_exit_code trexio_hdf5_write_$group_num$ (trexio_t* const file, const uint
return TREXIO_SUCCESS;
}
}
#+end_src
#+begin_src c :tangle has_num_hdf5.c
trexio_exit_code trexio_hdf5_has_$group_num$ (trexio_t* const file) {
trexio_exit_code
trexio_hdf5_has_$group_num$ (trexio_t* const file)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
const trexio_hdf5_t* f = (const trexio_hdf5_t*) file;
@ -253,19 +278,24 @@ trexio_exit_code trexio_hdf5_has_$group_num$ (trexio_t* const file) {
} else {
return TREXIO_FAILURE;
}
}
#+end_src
** Template for HDF5 has/read/write a dataset
#+begin_src c :tangle hrw_dset_hdf5.h
#+begin_src c :tangle hrw_dset_hdf5.h :exports none
trexio_exit_code trexio_hdf5_has_$group$_$group_dset$(trexio_t* const file);
trexio_exit_code trexio_hdf5_read_$group$_$group_dset$(trexio_t* const file, $group_dset_dtype$* const $group_dset$, const uint32_t rank, const uint64_t* dims);
trexio_exit_code trexio_hdf5_write_$group$_$group_dset$(trexio_t* const file, const $group_dset_dtype$* $group_dset$, const uint32_t rank, const uint64_t* dims);
#+end_src
#+begin_src c :tangle read_dset_hdf5.c
trexio_exit_code trexio_hdf5_read_$group$_$group_dset$(trexio_t* const file, $group_dset_dtype$* const $group_dset$, const uint32_t rank, const uint64_t* dims) {
trexio_exit_code
trexio_hdf5_read_$group$_$group_dset$ (trexio_t* const file, $group_dset_dtype$* const $group_dset$,
const uint32_t rank, const uint64_t* dims)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
@ -314,11 +344,14 @@ trexio_exit_code trexio_hdf5_read_$group$_$group_dset$(trexio_t* const file, $gr
return TREXIO_SUCCESS;
}
#+end_src
#+begin_src c :tangle write_dset_hdf5.c
trexio_exit_code trexio_hdf5_write_$group$_$group_dset$(trexio_t* const file, const $group_dset_dtype$* $group_dset$, const uint32_t rank, const uint64_t* dims) {
trexio_exit_code
trexio_hdf5_write_$group$_$group_dset$ (trexio_t* const file, const $group_dset_dtype$* $group_dset$,
const uint32_t rank, const uint64_t* dims)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
@ -352,11 +385,15 @@ trexio_exit_code trexio_hdf5_write_$group$_$group_dset$(trexio_t* const file, co
}
return TREXIO_SUCCESS;
}
#+end_src
#+begin_src c :tangle has_dset_hdf5.c
trexio_exit_code trexio_hdf5_has_$group$_$group_dset$(trexio_t* const file) {
trexio_exit_code
trexio_hdf5_has_$group$_$group_dset$ (trexio_t* const file)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
trexio_hdf5_t* f = (trexio_hdf5_t*) file;
@ -370,6 +407,7 @@ trexio_exit_code trexio_hdf5_has_$group$_$group_dset$(trexio_t* const file) {
} else {
return TREXIO_FAILURE;
}
}
#+end_src

View File

@ -1,5 +1,7 @@
#+Title: Templator for TEXT back end
#+TITLE: TEXT back end
#+PROPERTY: comments org
#+SETUPFILE: ../../docs/theme.setup
# -*- mode: org -*-
* Constant file prefixes (not used by the generator) :noexport:
@ -75,7 +77,6 @@
** Template for group-related structures in text back end
#+begin_src c :tangle struct_text_group_dset.h
typedef struct $group$_s {
uint64_t $group_num$;
FILE* file;
@ -84,13 +85,11 @@ typedef struct $group$_s {
uint32_t to_flush;
uint64_t dims_$group_dset$[16];
} $group$_t;
#+end_src
** Template for general structure in text back end
#+begin_src c :tangle struct_text_group.h
typedef struct rdm_s {
uint64_t dim_one_e;
uint32_t to_flush;
@ -99,24 +98,28 @@ typedef struct rdm_s {
FILE* file;
char* two_e_file_name;
} rdm_t;
#+end_src
#+begin_src c :tangle struct_text_group.h
typedef struct trexio_text_s {
trexio_t parent ;
$group$_t* $group$;
rdm_t* rdm;
int lock_file;
} trexio_text_t;
#+end_src
** Init/deinit functions (constant part)
** Initialize function (constant part)
#+begin_src c :tangle basic_text.h
#+begin_src c :tangle basic_text.h :exports none
trexio_exit_code trexio_text_init(trexio_t* const file);
#+end_src
#+begin_src c :tangle basic_text.c
trexio_exit_code trexio_text_init(trexio_t* const file) {
trexio_exit_code
trexio_text_init (trexio_t* const file)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
trexio_text_t* const f = (trexio_text_t*) file;
@ -161,7 +164,7 @@ trexio_exit_code trexio_text_init(trexio_t* const file) {
}
#+end_src
#+begin_src c :tangle basic_text.h
#+begin_src c :tangle basic_text.h :exports none
trexio_exit_code trexio_text_lock(trexio_t* const file);
#+end_src
@ -183,20 +186,24 @@ trexio_exit_code trexio_text_lock(trexio_t* const file) {
if (rc == -1) return TREXIO_FAILURE;
return TREXIO_SUCCESS;
}
#+end_src
#+begin_src c :tangle basic_text.h
#+begin_src c :tangle basic_text.h :exports none
trexio_exit_code trexio_text_deinit(trexio_t* const file);
#+end_src
#+begin_src c :tangle basic_text.h
#+begin_src c :tangle basic_text.h :exports none
trexio_exit_code trexio_text_unlock(trexio_t* const file);
#+end_src
#+begin_src c :tangle basic_text.c
trexio_exit_code trexio_text_unlock(trexio_t* const file) {
trexio_exit_code
trexio_text_unlock (trexio_t* const file)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
trexio_text_t* const f = (trexio_text_t*) file;
@ -212,13 +219,17 @@ trexio_exit_code trexio_text_unlock(trexio_t* const file) {
close(f->lock_file);
return TREXIO_SUCCESS;
}
#+end_src
** Init/deinit functions (templated part)
** Deinitialize function (templated part)
#+begin_src c :tangle basic_text_group.c
trexio_exit_code trexio_text_deinit(trexio_t* const file) {
trexio_exit_code
trexio_text_deinit (trexio_t* const file)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
trexio_exit_code rc;
@ -229,17 +240,21 @@ trexio_exit_code trexio_text_deinit(trexio_t* const file) {
assert (rc == TREXIO_SUCCESS);
return TREXIO_SUCCESS;
}
#+end_src
** Template for text read struct
#+begin_src c :tangle read_group_text.h
#+begin_src c :tangle read_group_text.h :exports none
$group$_t* trexio_text_read_$group$(trexio_text_t* const file);
#+end_src
#+begin_src c :tangle read_group_text.c
$group$_t* trexio_text_read_$group$(trexio_text_t* const file) {
$group$_t*
trexio_text_read_$group$ (trexio_text_t* const file)
{
if (file == NULL) return NULL;
/* If the data structure exists, return it */
@ -417,17 +432,21 @@ $group$_t* trexio_text_read_$group$(trexio_text_t* const file) {
fseek($group$->file, 0L, SEEK_SET);
file->$group$ = $group$;
return $group$;
}
#+end_src
** Template for text flush struct
#+begin_src c :tangle flush_group_text.h
#+begin_src c :tangle flush_group_text.h :exports none
trexio_exit_code trexio_text_flush_$group$(trexio_text_t* const file);
#+end_src
#+begin_src c :tangle flush_group_text.c
trexio_exit_code trexio_text_flush_$group$(trexio_text_t* const file) {
trexio_exit_code
trexio_text_flush_$group$ (trexio_text_t* const file)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (file->parent.mode == 'r') return TREXIO_READONLY;
@ -472,6 +491,7 @@ trexio_exit_code trexio_text_flush_$group$(trexio_text_t* const file) {
fflush(f);
$group$->to_flush = 0;
return TREXIO_SUCCESS;
}
#+end_src
@ -479,12 +499,15 @@ trexio_exit_code trexio_text_flush_$group$(trexio_text_t* const file) {
Memory is allocated when reading. The following function frees memory.
#+begin_src c :tangle free_group_text.h
#+begin_src c :tangle free_group_text.h :exports none
trexio_exit_code trexio_text_free_$group$(trexio_text_t* const file);
#+end_src
#+begin_src c :tangle free_group_text.c
trexio_exit_code trexio_text_free_$group$(trexio_text_t* const file) {
trexio_exit_code
trexio_text_free_$group$ (trexio_text_t* const file)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (file->parent.mode != 'r') {
@ -508,19 +531,23 @@ trexio_exit_code trexio_text_free_$group$(trexio_text_t* const file) {
FREE ($group$);
return TREXIO_SUCCESS;
}
#+end_src
** Template for has/read/write the $group_num$ attribute
** Template for has/read/write the ~$group_num$~ attribute
#+begin_src c :tangle hrw_num_text.h
#+begin_src c :tangle hrw_num_text.h :exports none
trexio_exit_code trexio_text_has_$group_num$ (trexio_t* const file);
trexio_exit_code trexio_text_read_$group_num$ (trexio_t* const file, uint64_t* const num);
trexio_exit_code trexio_text_write_$group_num$(trexio_t* const file, const uint64_t num);
#+end_src
#+begin_src c :tangle read_num_text.c
trexio_exit_code trexio_text_read_$group_num$(trexio_t* const file, uint64_t* const num) {
trexio_exit_code
trexio_text_read_$group_num$ (trexio_t* const file, uint64_t* const num)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (num == NULL) return TREXIO_INVALID_ARG_2;
@ -530,12 +557,15 @@ trexio_exit_code trexio_text_read_$group_num$(trexio_t* const file, uint64_t* co
*num = $group$->$group_num$;
return TREXIO_SUCCESS;
}
#+end_src
#+begin_src c :tangle write_num_text.c
trexio_exit_code
trexio_text_write_$group_num$ (trexio_t* const file, const uint64_t num)
{
trexio_exit_code trexio_text_write_$group_num$(trexio_t* const file, const uint64_t num) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (file->mode == 'r') return TREXIO_READONLY;
@ -546,11 +576,14 @@ trexio_exit_code trexio_text_write_$group_num$(trexio_t* const file, const uint6
$group$->to_flush = 1;
return TREXIO_SUCCESS;
}
#+end_src
#+begin_src c :tangle has_num_text.c
trexio_exit_code trexio_text_has_$group_num$(trexio_t* const file) {
trexio_exit_code
trexio_text_has_$group_num$ (trexio_t* const file)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
$group$_t* $group$ = trexio_text_read_$group$((trexio_text_t*) file);
@ -565,18 +598,21 @@ trexio_exit_code trexio_text_has_$group_num$(trexio_t* const file) {
}
#+end_src
** Template for has/read/write the $group_dset$ dataset
** Template for has/read/write the ~$group_dset$~ dataset
The ~dset~ array is assumed allocated with the appropriate size.
The ~group_dset~ array is assumed allocated with the appropriate size.
#+begin_src c :tangle hrw_dset_text.h
#+begin_src c :tangle hrw_dset_text.h :exports none
trexio_exit_code trexio_text_has_$group_dset$ (trexio_t* const file);
trexio_exit_code trexio_text_read_$group_dset$ (trexio_t* const file, $group_dset_dtype$* const $group_dset$, const uint32_t rank, const uint64_t* dims);
trexio_exit_code trexio_text_write_$group_dset$(trexio_t* const file, const $group_dset_dtype$* $group_dset$, const uint32_t rank, const uint64_t* dims);
#+end_src
#+begin_src c :tangle read_dset_text.c
trexio_exit_code trexio_text_read_$group_dset$(trexio_t* const file, $group_dset_dtype$* const $group_dset$, const uint32_t rank, const uint64_t* dims) {
trexio_exit_code
trexio_text_read_$group_dset$ (trexio_t* const file, $group_dset_dtype$* const $group_dset$,
const uint32_t rank, const uint64_t* dims)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
@ -597,11 +633,16 @@ trexio_exit_code trexio_text_read_$group_dset$(trexio_t* const file, $group_dset
}
return TREXIO_SUCCESS;
}
#+end_src
#+begin_src c :tangle write_dset_text.c
trexio_exit_code trexio_text_write_$group_dset$(trexio_t* const file, const $group_dset_dtype$* $group_dset$, const uint32_t rank, const uint64_t* dims) {
trexio_exit_code
trexio_text_write_$group_dset$ (trexio_t* const file, const $group_dset_dtype$* $group_dset$,
const uint32_t rank, const uint64_t* dims)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
@ -630,11 +671,15 @@ trexio_exit_code trexio_text_write_$group_dset$(trexio_t* const file, const $gro
$group$->to_flush = 1;
return TREXIO_SUCCESS;
}
#+end_src
#+begin_src c :tangle has_dset_text.c
trexio_exit_code trexio_text_has_$group_dset$(trexio_t* const file) {
trexio_exit_code
trexio_text_has_$group_dset$ (trexio_t* const file)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
$group$_t* const $group$ = trexio_text_read_$group$((trexio_text_t*) file);
@ -645,10 +690,11 @@ trexio_exit_code trexio_text_has_$group_dset$(trexio_t* const file) {
} else {
return TREXIO_HAS_NOT;
}
}
#+end_src
** RDM struct
** RDM struct (hard-coded)
*** Read the complete struct
#+begin_src c :tangle rdm_text.h

1
tools/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
emacs/htmlize.el

132
tools/build_doc.sh Executable file
View File

@ -0,0 +1,132 @@
#!/bin/bash
# Script to build the documentation
TREXIO_ROOT=$(dirname "${PWD}")
# First define readonly global variables.
readonly DOCS=${TREXIO_ROOT}/docs
readonly SRC=${TREXIO_ROOT}/src
readonly TOOLS=${TREXIO_ROOT}/tools
readonly ELDIR=${TREXIO_ROOT}/tools/emacs
readonly HTMLIZE=${ELDIR}/htmlize.el
readonly CONFIG_DOC=${ELDIR}/config_doc.el
readonly CONFIG_TANGLE=${ELDIR}/config_tangle.el
# Check that all the defined global variables correspond to files.
function check_preconditions()
{
if [[ -z ${TREXIO_ROOT} ]]
then
print "TREXIO_ROOT is not defined"
exit 1
fi
for dir in ${DOCS} ${SRC} ${TOOLS} ${ELDIR}
do
if [[ ! -d ${dir} ]]
then
print "${dir} not found"
exit 2
fi
done
for file in ${CONFIG_DOC} ${CONFIG_TANGLE}
do
if [[ ! -f ${file} ]]
then
print "${file} not found"
exit 3
fi
done
}
# Download the htmlize Emacs plugin if not present
function install_htmlize()
{
local url="https://github.com/hniksic/emacs-htmlize"
local repo="emacs-htmlize"
if [[ ! -f "${HTMLIZE}" ]]
then
cd ${TOOLS}
git clone ${url} \
&& cp ${repo}/htmlize.el ${HTMLIZE} \
&& rm -rf ${repo}
cd ..
fi
# Assert htmlize is installed
[[ -f ${HTMLIZE} ]] \
|| exit 1
}
# Compile org-mode file into html
function extract_doc()
{
local org=$1
local dir=$2
local local_html=${dir}/${org%.org}.html
local html=${DOCS}/${org%.org}.html
if [[ -f ${html} && ${org} -ot ${html} ]]
then
return
fi
emacs --batch \
--load ${HTMLIZE} \
--load ${CONFIG_DOC} \
${org} \
--load ${CONFIG_TANGLE} \
-f org-html-export-to-html
mv ${local_html} ${DOCS}
rm -f "${local_html}~"
}
# The main function of the script.
function main() {
# Check directories and files for existence
check_preconditions
# Install htmlize if needed
install_htmlize
# Create documentation
cd ${SRC}
for dir in ${SRC}/templates_*/
do
dir=${dir%*/}
echo ${dir}
cd ${dir}
for i in *.org
do
echo
echo "======= ${i} ======="
extract_doc ${i} ${dir}
done
cd ..
done
echo
echo "======= README.org ======="
extract_doc README.org ${SRC}
if [[ $? -eq 0 ]]
then
cd ${DOCS}
rm -f index.html
ln README.html index.html
exit 0
else
exit 3
fi
}
main

85
tools/emacs/config_doc.el Executable file
View File

@ -0,0 +1,85 @@
;; Thanks to Tobias's answer on Emacs Stack Exchange:
;; https://emacs.stackexchange.com/questions/38437/org-mode-batch-export-missing-syntax-highlighting
(package-initialize)
(require 'htmlize)
(require 'font-lock)
(setq org-confirm-babel-evaluate nil)
(global-font-lock-mode t)
(setq org-src-fontify-natively t)
;(require 'ox-latex)
;(setq org-latex-listings t)
;(add-to-list 'org-latex-packages-alist '("" "listings"))
;(add-to-list 'org-latex-packages-alist '("" "color"))
(require 'subr-x) ;; for `when-let'
(unless (boundp 'maximal-integer)
(defconst maximal-integer (lsh -1 -1)
"Maximal integer value representable natively in emacs lisp."))
(defun face-spec-default (spec)
"Get list containing at most the default entry of face SPEC.
Return nil if SPEC has no default entry."
(let* ((first (car-safe spec))
(display (car-safe first)))
(when (eq display 'default)
(list (car-safe spec)))))
(defun face-spec-min-color (display-atts)
"Get min-color entry of DISPLAY-ATTS pair from face spec."
(let* ((display (car-safe display-atts)))
(or (car-safe (cdr (assoc 'min-colors display)))
maximal-integer)))
(defun face-spec-highest-color (spec)
"Search face SPEC for highest color.
That means the DISPLAY entry of SPEC
with class 'color and highest min-color value."
(let ((color-list (cl-remove-if-not
(lambda (display-atts)
(when-let ((display (car-safe display-atts))
(class (and (listp display)
(assoc 'class display)))
(background (assoc 'background display)))
(and (member 'light (cdr background))
(member 'color (cdr class)))))
spec)))
(cl-reduce (lambda (display-atts1 display-atts2)
(if (> (face-spec-min-color display-atts1)
(face-spec-min-color display-atts2))
display-atts1
display-atts2))
(cdr color-list)
:initial-value (car color-list))))
(defun face-spec-t (spec)
"Search face SPEC for fall back."
(cl-find-if (lambda (display-atts)
(eq (car-safe display-atts) t))
spec))
(defun my-face-attribute (face attribute &optional frame inherit)
"Get FACE ATTRIBUTE from `face-user-default-spec' and not from `face-attribute'."
(let* ((face-spec (face-user-default-spec face))
(display-attr (or (face-spec-highest-color face-spec)
(face-spec-t face-spec)))
(attr (cdr display-attr))
(val (or (plist-get attr attribute) (car-safe (cdr (assoc attribute attr))))))
;; (message "attribute: %S" attribute) ;; for debugging
(when (and (null (eq attribute :inherit))
(null val))
(let ((inherited-face (my-face-attribute face :inherit)))
(when (and inherited-face
(null (eq inherited-face 'unspecified)))
(setq val (my-face-attribute inherited-face attribute)))))
;;(message "face: %S attribute: %S display-attr: %S, val: %S" face attribute display-attr val) ;; for debugging
(or val 'unspecified)))
(advice-add 'face-attribute :override #'my-face-attribute)

46
tools/emacs/config_tangle.el Executable file
View File

@ -0,0 +1,46 @@
;; Thanks to Tobias's answer on Emacs Stack Exchange:
;; https://emacs.stackexchange.com/questions/38437/org-mode-batch-export-missing-syntax-highlighting
(package-initialize)
(add-to-list 'package-archives
'("gnu" . "https://elpa.gnu.org/packages/"))
(add-to-list 'package-archives
'("melpa-stable" . "https://stable.melpa.org/packages/"))
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
(setq package-archive-priorities '(("melpa-stable" . 100)
("melpa" . 50)
("gnu" . 10)))
(require 'font-lock)
(setq org-confirm-babel-evaluate nil)
(global-font-lock-mode t)
(setq org-src-fontify-natively t)
(org-babel-do-load-languages
'org-babel-load-languages
'(
(emacs-lisp . t)
(shell . t)
(python . t)
(fortran . t)
(C . t)
(org . t)
(makefile . t)
))
; The following is required to compute the file names
(setq pwd (file-name-directory buffer-file-name))
(setq name (file-name-nondirectory (substring buffer-file-name 0 -4)))
(setq f (concat pwd name "_f.f90"))
(setq fh (concat pwd name "_fh.f90"))
(setq c (concat pwd name ".c"))
(setq h (concat name ".h"))
(setq h_private (concat name "_private.h"))
(setq c_test (concat pwd "test_" name ".c"))
(setq f_test (concat pwd "test_" name "_f.f90"))
(org-babel-lob-ingest "../tools/lib.org")