1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-11-03 20:54:07 +01:00

Add functions to force flushing of data buffers

This commit is contained in:
q-posev 2022-09-13 11:29:59 +02:00
parent bbb9bcb085
commit 7fc4465d33
4 changed files with 118 additions and 0 deletions

View File

@ -1424,6 +1424,84 @@ def _close(trexio_file):
raise Error(rc)
#+end_src
** File flushing
~trexio_flush~ flushes all buffers into the ~trexio_t~ file.
input parameters:
~file~ -- TREXIO file handle.
output:
~trexio_exit_code~ exit code.
*** C
#+begin_src c :tangle prefix_front.h :exports none
trexio_exit_code trexio_flush(trexio_t* file);
#+end_src
#+begin_src c :tangle prefix_front.c
trexio_exit_code
trexio_flush (trexio_t* file)
{
if (file == NULL) return TREXIO_FILE_ERROR;
trexio_exit_code rc = TREXIO_FAILURE;
assert(file->back_end < TREXIO_INVALID_BACK_END);
/* Terminate the back end */
switch (file->back_end) {
case TREXIO_TEXT:
rc = trexio_text_flush(file);
break;
case TREXIO_HDF5:
#ifdef HAVE_HDF5
rc = trexio_hdf5_flush(file);
break;
#else
return TREXIO_BACK_END_MISSING;
#endif
/*
case TREXIO_JSON:
rc = trexio_json_flush(file);
break;
,*/
}
return rc;
}
#+end_src
*** Fortran
#+begin_src f90 :tangle prefix_fortran.f90
interface
integer(trexio_exit_code) function trexio_flush (trex_file) bind(C)
use, intrinsic :: iso_c_binding
import
integer(c_int64_t), intent(in), value :: trex_file
end function trexio_flush
end interface
#+end_src
*** Python
#+begin_src python :tangle basic_python.py
def flush(trexio_file):
"""Flush buffers into the TREXIO file.
Parameter is a ~trexio_file~ object that has been created by a call to ~open~ function.
"""
rc = pytr.trexio_flush(trexio_file)
if rc != TREXIO_SUCCESS:
raise Error(rc)
#+end_src
** File existence
~trexio_inquire~ check whether TREXIO file exists.

View File

@ -79,6 +79,21 @@ typedef struct trexio_hdf5_s {
trexio_exit_code trexio_hdf5_init(trexio_t* const file);
trexio_exit_code trexio_hdf5_deinit(trexio_t* const file);
trexio_exit_code trexio_hdf5_inquire(const char* file_name);
trexio_exit_code trexio_hdf5_flush(trexio_t* const file);
#+end_src
#+begin_src c :tangle basic_hdf5.c
trexio_exit_code
trexio_hdf5_flush(trexio_t* const file)
{
trexio_hdf5_t* f = (trexio_hdf5_t*) file;
herr_t rc = H5Fflush(f->file_id, H5F_SCOPE_GLOBAL);
if (rc < 0) return TREXIO_FAILURE;
return TREXIO_SUCCESS;
}
#+end_src
#+begin_src c :tangle basic_hdf5.c

View File

@ -112,6 +112,7 @@ trexio_exit_code trexio_text_inquire(const char* file_name);
trexio_exit_code trexio_text_deinit(trexio_t* const file);
trexio_exit_code trexio_text_lock(trexio_t* const file);
trexio_exit_code trexio_text_unlock(trexio_t* const file);
trexio_exit_code trexio_text_flush(trexio_t* const file);
bool trexio_text_file_exists(const char* file_name);
#+end_src
@ -292,6 +293,26 @@ trexio_text_deinit (trexio_t* const file)
}
#+end_src
* Flush function (templated part)
#+begin_src c :tangle basic_text_group.c
trexio_exit_code
trexio_text_flush (trexio_t* const file)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
trexio_exit_code rc;
trexio_text_t* f = (trexio_text_t*) file;
/* Error handling for this call is added by the generator */
rc = trexio_text_flush_$group$(f);
return TREXIO_SUCCESS;
}
#+end_src
* Template for text read a group
#+begin_src c :tangle read_group_text.h :exports none

View File

@ -94,6 +94,10 @@ int test_write(const char* file_name, const back_end_t backend) {
rc = trexio_write_nucleus_coord(file,coord);
assert (rc == TREXIO_SUCCESS);
// check the force flushing
rc = trexio_flush(file);
assert (rc == TREXIO_SUCCESS);
rc = trexio_write_nucleus_label(file, label, 32);
assert (rc == TREXIO_SUCCESS);
rc = trexio_write_nucleus_point_group(file, sym, 32);