From 2f876ef7cd6ae65661e3cb0286441b1ecddeeb71 Mon Sep 17 00:00:00 2001 From: q-posev Date: Fri, 23 Jul 2021 15:55:16 +0200 Subject: [PATCH] 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;