From 56df1c8549c081219964d13e45bef26898fc8a8b Mon Sep 17 00:00:00 2001 From: q-posev Date: Fri, 23 Jul 2021 15:48:45 +0200 Subject: [PATCH 1/5] propagate local user name from $USER to config.h --- configure.ac | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/configure.ac b/configure.ac index 3b2904e..5c1233a 100644 --- a/configure.ac +++ b/configure.ac @@ -21,6 +21,11 @@ AC_SUBST([VERSION_MAJOR]) AC_SUBST([VERSION_MINOR]) AC_SUBST([VERSION_PATCH]) +## Save system information, e.g. user name + +UNAME=`echo ${USER}` +AC_DEFINE_UNQUOTED(TREXIO_USER_NAME, ["${UNAME}"], [user name]) +AC_SUBST([UNAME]) ## ------------------- ## Checks for programs @@ -49,6 +54,7 @@ PKG_CFLAGS="" AC_PROG_INSTALL AC_PROG_LIBTOOL AC_PROG_LN_S +AC_PROG_GREP ## --------- From 856412f06a953f0ecfead4863df45684e67d3cec Mon Sep 17 00:00:00 2001 From: q-posev Date: Fri, 23 Jul 2021 15:49:42 +0200 Subject: [PATCH 2/5] propagate package version and user name to trexio.h --- src/templates_front/build.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/templates_front/build.sh b/src/templates_front/build.sh index 25d2261..1a15d92 100644 --- a/src/templates_front/build.sh +++ b/src/templates_front/build.sh @@ -3,6 +3,12 @@ # prefixes cat prefix_front.c > trexio.c cat prefix_front.h > trexio.h +# grep some usefull constants from the config.h +echo "" >> trexio.h +grep "_VERSION" ../../include/config.h >> trexio.h +grep "_USER_NAME" ../../include/config.h >> trexio.h +echo "" >> trexio.h + cat prefix_s_front.h > trexio_s.h cat prefix_fortran.f90 > trexio_f.f90 From ba45479a8a6e4a968a603810a4a03428abe7c01b Mon Sep 17 00:00:00 2001 From: q-posev Date: Fri, 23 Jul 2021 15:50:31 +0200 Subject: [PATCH 3/5] add package_version attribute to metadata group --- trex.org | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/trex.org b/trex.org index 829ade4..80d146f 100644 --- a/trex.org +++ b/trex.org @@ -33,27 +33,29 @@ arrays are 0-based. Hence, we introduce the ~index~ type which is an authors of the file, and a textual description. #+NAME: metadata - | Variable | Type | Dimensions (for arrays) | Description | - |---------------+-------+-------------------------+------------------------------------------| - | ~code_num~ | ~int~ | | Number of codes used to produce the file | - | ~code~ | ~str~ | ~(metadata.code_num)~ | Names of the codes used | - | ~author_num~ | ~int~ | | Number of authors of the file | - | ~author~ | ~str~ | ~(metadata.author_num)~ | Names of the authors of the file | - | ~description~ | ~str~ | | Text describing the content of file | + | Variable | Type | Dimensions (for arrays) | Description | + |-------------------+-------+-------------------------+------------------------------------------| + | ~code_num~ | ~int~ | | Number of codes used to produce the file | + | ~code~ | ~str~ | ~(metadata.code_num)~ | Names of the codes used | + | ~author_num~ | ~int~ | | Number of authors of the file | + | ~author~ | ~str~ | ~(metadata.author_num)~ | Names of the authors of the file | + | ~package_version~ | ~str~ | | TREXIO version used to produce the file | + | ~description~ | ~str~ | | Text describing the content of file | #+CALL: json(data=metadata, title="metadata") #+RESULTS: - :results: + :RESULTS: #+begin_src python :tangle trex.json "metadata": { - "code_num" : [ "int", [] ] - , "code" : [ "str", [ "metadata.code_num" ] ] - , "author_num" : [ "int", [] ] - , "author" : [ "str", [ "metadata.author_num" ] ] - , "description" : [ "str", [] ] + "code_num" : [ "int", [] ] + , "code" : [ "str", [ "metadata.code_num" ] ] + , "author_num" : [ "int", [] ] + , "author" : [ "str", [ "metadata.author_num" ] ] + , "package_version" : [ "str", [] ] + , "description" : [ "str", [] ] } , #+end_src - :end: + :END: * Electron (electron group) From 2f876ef7cd6ae65661e3cb0286441b1ecddeeb71 Mon Sep 17 00:00:00 2001 From: q-posev Date: Fri, 23 Jul 2021 15:55:16 +0200 Subject: [PATCH 4/5] write TREXIO version in the file if not done yet --- src/templates_front/templator_front.org | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index d619fb6..7434ed9 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -432,6 +432,7 @@ typedef struct trexio_s trexio_t; #+begin_src c :tangle prefix_s_front.h struct trexio_s { char file_name[TREXIO_MAX_FILENAME_LENGTH]; + char version[16]; pthread_mutex_t thread_lock; back_end_t back_end; char mode; @@ -528,6 +529,12 @@ trexio_open(const char* file_name, const char mode, return NULL; } + strncpy(result->version, PACKAGE_VERSION, 16); + if (result->version[15] != '\0') { + free(result); + return NULL; + } + result->back_end = back_end; result->mode = mode; result->one_based = false; // Need to be flipped in Fortran interface @@ -561,6 +568,36 @@ trexio_open(const char* file_name, const char mode, return NULL; } + rc = trexio_has_metadata_package_version(result); + if (rc == TREXIO_FAILURE) { + free(result); + return NULL; + } + + if (rc == TREXIO_HAS_NOT) { + switch (back_end) { + + case TREXIO_TEXT: + rc = trexio_text_write_metadata_package_version(result, PACKAGE_VERSION); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_write_metadata_package_version(result, PACKAGE_VERSION); + break; +/* + case TREXIO_JSON: + rc = trexio_json_write_metadata_package_version(result, PACKAGE_VERSION); + break; +,*/ + } + } + + if (rc != TREXIO_SUCCESS) { + free(result); + return NULL; + } + + /* File locking */ rc = TREXIO_LOCK_ERROR; From 578819afe78ea3c22ff72adfe40173521dae094a Mon Sep 17 00:00:00 2001 From: q-posev Date: Fri, 23 Jul 2021 16:19:15 +0200 Subject: [PATCH 5/5] do not propagate the local user name from config.h to trexio.h --- src/templates_front/build.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/src/templates_front/build.sh b/src/templates_front/build.sh index 1a15d92..61cde7b 100644 --- a/src/templates_front/build.sh +++ b/src/templates_front/build.sh @@ -6,7 +6,6 @@ cat prefix_front.h > trexio.h # grep some usefull constants from the config.h echo "" >> trexio.h grep "_VERSION" ../../include/config.h >> trexio.h -grep "_USER_NAME" ../../include/config.h >> trexio.h echo "" >> trexio.h cat prefix_s_front.h > trexio_s.h