1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-07-22 18:57:39 +02:00

Merge pull request #55 from TREX-CoE/add-metadata-info

Automatically add package version to the metadata; Close #53
This commit is contained in:
Anthony Scemama 2021-07-23 16:27:03 +02:00 committed by GitHub
commit 84e0d480c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 14 deletions

View File

@ -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
## ---------

View File

@ -3,6 +3,11 @@
# 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
echo "" >> trexio.h
cat prefix_s_front.h > trexio_s.h
cat prefix_fortran.f90 > trexio_f.f90

View File

@ -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;

View File

@ -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)