1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-12-23 04:43:57 +01:00
This commit is contained in:
Anthony Scemama 2021-03-28 22:38:32 +02:00
parent 4e68a808a0
commit 56389752de
3 changed files with 99 additions and 65 deletions

View File

@ -44,17 +44,17 @@ export CC CFLAGS FC FFLAGS LIBS
.PHONY: clean .PHONY: clean
cppcheck.out: $(HEADER_FILES) $(SOURCE_FILES)
cppcheck --addon=cert -q --error-exitcode=0 \
--enable=style,warning,unusedFunction,performance,portability,missingInclude \
--language=c -rp --std=c99 -v $(SOURCE_FILES) 2>$@
libtrexio.so: $(OBJECT_FILES) $(HEADER_FILES) cppcheck.out libtrexio.so: $(OBJECT_FILES) $(HEADER_FILES) cppcheck.out
$(CC) -shared $(OBJECT_FILES) -o libtrexio.so $(CC) -shared $(OBJECT_FILES) -o libtrexio.so
fortran: libtrexio.so trexio_f.f90 fortran: libtrexio.so trexio_f.f90
$(FC) $(FFLAGS) -c trexio_f.f90 -o trexio_f.o $(FC) $(FFLAGS) -c trexio_f.f90 -o trexio_f.o
cppcheck.out: $(HEADER_FILES) $(SOURCE_FILES)
cppcheck --addon=cert -q --error-exitcode=0 \
--enable=style,warning,unusedFunction,performance,portability,missingInclude \
--language=c -rp --std=c99 -v $(SOURCE_FILES) 2>$@
test_c: libtrexio.so test.c test_c: libtrexio.so test.c
$(CC) $(CFLAGS) $(INCLUDE) -Wl,-rpath,$(PWD) -L. test.c -ltrexio $(LIBS) -o test_c $(CC) $(CFLAGS) $(INCLUDE) -Wl,-rpath,$(PWD) -L. test.c -ltrexio $(LIBS) -o test_c

View File

@ -390,8 +390,8 @@ end interface
** Template for frontend read/write a number ** Template for frontend read/write a number
#+begin_src c :tangle rw_num_front.h #+begin_src c :tangle rw_num_front.h
trexio_exit_code trexio_read_$group_num$(trexio_t* file, int64_t* num); trexio_exit_code trexio_read_$group_num$(trexio_t* const file, int64_t* const num);
trexio_exit_code trexio_write_$group_num$(trexio_t* file, const int64_t num); trexio_exit_code trexio_write_$group_num$(trexio_t* const file, const int64_t num);
#+end_src #+end_src
#+begin_src c :tangle read_num_front.c #+begin_src c :tangle read_num_front.c
@ -426,7 +426,7 @@ trexio_exit_code trexio_read_$group_num$(trexio_t* file, int64_t* num) {
#+begin_src c :tangle write_num_front.c #+begin_src c :tangle write_num_front.c
trexio_exit_code trexio_write_$group_num$(trexio_t* file, const int64_t num) { trexio_exit_code trexio_write_$group_num$(trexio_t* const file, const int64_t num) {
if (file == NULL) return TREXIO_INVALID_ARG_1; if (file == NULL) return TREXIO_INVALID_ARG_1;
if (num < 0 ) return TREXIO_INVALID_ARG_2; if (num < 0 ) return TREXIO_INVALID_ARG_2;
@ -483,12 +483,12 @@ end interface
** Template for frontend read/write a dataset ** Template for frontend read/write a dataset
#+begin_src c :tangle rw_dset_front.h #+begin_src c :tangle rw_dset_front.h
trexio_exit_code trexio_read_$group$_$group_dset$(trexio_t* file, $group_dset_dtype$* $group_dset$); trexio_exit_code trexio_read_$group$_$group_dset$(trexio_t* const file, $group_dset_dtype$* const $group_dset$);
trexio_exit_code trexio_write_$group$_$group_dset$(trexio_t* file, const $group_dset_dtype$* $group_dset$); trexio_exit_code trexio_write_$group$_$group_dset$(trexio_t* const file, const $group_dset_dtype$* $group_dset$);
#+end_src #+end_src
#+begin_src c :tangle read_dset_front.c #+begin_src c :tangle read_dset_front.c
trexio_exit_code trexio_read_$group$_$group_dset$(trexio_t* file, $group_dset_dtype$* $group_dset$) { trexio_exit_code trexio_read_$group$_$group_dset$(trexio_t* const file, $group_dset_dtype$* const $group_dset$) {
if (file == NULL) return TREXIO_INVALID_ARG_1; if (file == NULL) return TREXIO_INVALID_ARG_1;
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2; if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
@ -540,7 +540,7 @@ trexio_exit_code trexio_read_$group$_$group_dset$(trexio_t* file, $group_dset_dt
#+begin_src c :tangle write_dset_front.c #+begin_src c :tangle write_dset_front.c
trexio_exit_code trexio_write_$group$_$group_dset$(trexio_t* file, const $group_dset_dtype$* $group_dset$) { trexio_exit_code trexio_write_$group$_$group_dset$(trexio_t* const file, const $group_dset_dtype$* $group_dset$) {
if (file == NULL) return TREXIO_INVALID_ARG_1; if (file == NULL) return TREXIO_INVALID_ARG_1;
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2; if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;

View File

@ -113,14 +113,14 @@ typedef struct trexio_text_s {
*** Init/deinit functions (constant part) *** Init/deinit functions (constant part)
#+begin_src c :tangle basic_text.h #+begin_src c :tangle basic_text.h
trexio_exit_code trexio_text_init(trexio_t* file); trexio_exit_code trexio_text_init(trexio_t* const file);
#+end_src #+end_src
#+begin_src c :tangle basic_text.c #+begin_src c :tangle basic_text.c
trexio_exit_code trexio_text_init(trexio_t* file) { trexio_exit_code trexio_text_init(trexio_t* const file) {
if (file == NULL) return TREXIO_INVALID_ARG_1; if (file == NULL) return TREXIO_INVALID_ARG_1;
trexio_text_t* f = (trexio_text_t*) file; trexio_text_t* const f = (trexio_text_t*) file;
/* Put all pointers to NULL but leave parent untouched */ /* Put all pointers to NULL but leave parent untouched */
memset(&(f->parent)+1,0,sizeof(trexio_text_t)-sizeof(trexio_t)); memset(&(f->parent)+1,0,sizeof(trexio_text_t)-sizeof(trexio_t));
@ -163,14 +163,14 @@ trexio_exit_code trexio_text_init(trexio_t* file) {
#+end_src #+end_src
#+begin_src c :tangle basic_text.h #+begin_src c :tangle basic_text.h
trexio_exit_code trexio_text_lock(trexio_t* file); trexio_exit_code trexio_text_lock(trexio_t* const file);
#+end_src #+end_src
#+begin_src c :tangle basic_text.c #+begin_src c :tangle basic_text.c
trexio_exit_code trexio_text_lock(trexio_t* file) { trexio_exit_code trexio_text_lock(trexio_t* const file) {
if (file == NULL) return TREXIO_INVALID_ARG_1; if (file == NULL) return TREXIO_INVALID_ARG_1;
trexio_text_t* f = (trexio_text_t*) file; trexio_text_t* const f = (trexio_text_t*) file;
struct flock fl; struct flock fl;
@ -189,18 +189,18 @@ trexio_exit_code trexio_text_lock(trexio_t* file) {
#+begin_src c :tangle basic_text.h #+begin_src c :tangle basic_text.h
trexio_exit_code trexio_text_finalize(trexio_t* file); trexio_exit_code trexio_text_finalize(trexio_t* const file);
#+end_src #+end_src
#+begin_src c :tangle basic_text.h #+begin_src c :tangle basic_text.h
trexio_exit_code trexio_text_unlock(trexio_t* file); trexio_exit_code trexio_text_unlock(trexio_t* const file);
#+end_src #+end_src
#+begin_src c :tangle basic_text.c #+begin_src c :tangle basic_text.c
trexio_exit_code trexio_text_unlock(trexio_t* file) { trexio_exit_code trexio_text_unlock(trexio_t* const file) {
if (file == NULL) return TREXIO_INVALID_ARG_1; if (file == NULL) return TREXIO_INVALID_ARG_1;
trexio_text_t* f = (trexio_text_t*) file; trexio_text_t* const f = (trexio_text_t*) file;
struct flock fl; struct flock fl;
@ -220,7 +220,7 @@ trexio_exit_code trexio_text_unlock(trexio_t* file) {
*** Init/deinit functions (templated part) *** Init/deinit functions (templated part)
#+begin_src c :tangle basic_text_group.c #+begin_src c :tangle basic_text_group.c
trexio_exit_code trexio_text_finalize(trexio_t* file) { trexio_exit_code trexio_text_finalize(trexio_t* const file) {
if (file == NULL) return TREXIO_INVALID_ARG_1; if (file == NULL) return TREXIO_INVALID_ARG_1;
trexio_exit_code rc; trexio_exit_code rc;
@ -239,12 +239,11 @@ trexio_exit_code trexio_text_finalize(trexio_t* file) {
*** Template for text read struct *** Template for text read struct
#+begin_src c :tangle read_group_text.h #+begin_src c :tangle read_group_text.h
$group$_t* trexio_text_read_$group$(trexio_text_t* file); $group$_t* trexio_text_read_$group$(trexio_text_t* const file);
#+end_src #+end_src
#+begin_src c :tangle read_group_text.c #+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* file) {
if (file == NULL) return NULL; if (file == NULL) return NULL;
/* If the data structure exists, return it */ /* If the data structure exists, return it */
@ -438,11 +437,11 @@ $group$_t* trexio_text_read_$group$(trexio_text_t* file) {
*** Template for text flush struct *** Template for text flush struct
#+begin_src c :tangle flush_group_text.h #+begin_src c :tangle flush_group_text.h
trexio_exit_code trexio_text_flush_$group$(const trexio_text_t* file); trexio_exit_code trexio_text_flush_$group$(trexio_text_t* const file);
#+end_src #+end_src
#+begin_src c :tangle flush_group_text.c #+begin_src c :tangle flush_group_text.c
trexio_exit_code trexio_text_flush_$group$(const trexio_text_t* file) { trexio_exit_code trexio_text_flush_$group$(trexio_text_t* const file) {
if (file == NULL) return TREXIO_INVALID_ARG_1; if (file == NULL) return TREXIO_INVALID_ARG_1;
if (file->parent.mode == 'r') return TREXIO_READONLY; if (file->parent.mode == 'r') return TREXIO_READONLY;
@ -502,11 +501,11 @@ trexio_exit_code trexio_text_flush_$group$(const trexio_text_t* file) {
Memory is allocated when reading. The following function frees memory. 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
trexio_exit_code trexio_text_free_$group$(trexio_text_t* file); trexio_exit_code trexio_text_free_$group$(trexio_text_t* const file);
#+end_src #+end_src
#+begin_src c :tangle free_group_text.c #+begin_src c :tangle free_group_text.c
trexio_exit_code trexio_text_free_$group$(trexio_text_t* file) { trexio_exit_code trexio_text_free_$group$(trexio_text_t* const file) {
if (file == NULL) return TREXIO_INVALID_ARG_1; if (file == NULL) return TREXIO_INVALID_ARG_1;
if (file->parent.mode != 'r') { if (file->parent.mode != 'r') {
@ -538,12 +537,12 @@ trexio_exit_code trexio_text_free_$group$(trexio_text_t* file) {
*** Template for read/write the $group_num$ attribute *** Template for read/write the $group_num$ attribute
#+begin_src c :tangle rw_num_text.h #+begin_src c :tangle rw_num_text.h
trexio_exit_code trexio_text_read_$group_num$(const trexio_t* file, uint64_t* num); trexio_exit_code trexio_text_read_$group_num$ (trexio_t* const file, uint64_t* const num);
trexio_exit_code trexio_text_write_$group_num$(const trexio_t* file, const uint64_t num); trexio_exit_code trexio_text_write_$group_num$(trexio_t* const file, const uint64_t num);
#+end_src #+end_src
#+begin_src c :tangle read_num_text.c #+begin_src c :tangle read_num_text.c
trexio_exit_code trexio_text_read_$group_num$(const trexio_t* file, uint64_t* 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 (file == NULL) return TREXIO_INVALID_ARG_1;
if (num == NULL) return TREXIO_INVALID_ARG_2; if (num == NULL) return TREXIO_INVALID_ARG_2;
@ -551,7 +550,7 @@ trexio_exit_code trexio_text_read_$group_num$(const trexio_t* file, uint64_t* nu
$group$_t* $group$ = trexio_text_read_$group$((trexio_text_t*) file); $group$_t* $group$ = trexio_text_read_$group$((trexio_text_t*) file);
if ($group$ == NULL) return TREXIO_FAILURE; if ($group$ == NULL) return TREXIO_FAILURE;
/**/ *num = $group$->$group_num$; *num = $group$->$group_num$;
return TREXIO_SUCCESS; return TREXIO_SUCCESS;
} }
@ -559,7 +558,7 @@ trexio_exit_code trexio_text_read_$group_num$(const trexio_t* file, uint64_t* nu
#+begin_src c :tangle write_num_text.c #+begin_src c :tangle write_num_text.c
trexio_exit_code trexio_text_write_$group_num$(const trexio_t* 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 == NULL) return TREXIO_INVALID_ARG_1;
@ -580,17 +579,17 @@ trexio_exit_code trexio_text_write_$group_num$(const trexio_t* file, const uint6
The ~dset~ array is assumed allocated with the appropriate size. The ~dset~ array is assumed allocated with the appropriate size.
#+begin_src c :tangle rw_dset_text.h #+begin_src c :tangle rw_dset_text.h
trexio_exit_code trexio_text_read_$group_dset$(const trexio_t* file, $group_dset_dtype$* $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);
trexio_exit_code trexio_text_write_$group_dset$(const trexio_t* 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);
#+end_src #+end_src
#+begin_src c :tangle read_dset_text.c #+begin_src c :tangle read_dset_text.c
trexio_exit_code trexio_text_read_$group_dset$(const trexio_t* file, $group_dset_dtype$* $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 (file == NULL) return TREXIO_INVALID_ARG_1;
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2; if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
$group$_t* $group$ = trexio_text_read_$group$((trexio_text_t*) file); $group$_t* const $group$ = trexio_text_read_$group$((trexio_text_t*) file);
if ($group$ == NULL) return TREXIO_FAILURE; if ($group$ == NULL) return TREXIO_FAILURE;
if (rank != $group$->rank_$group_dset$) return TREXIO_INVALID_ARG_3; if (rank != $group$->rank_$group_dset$) return TREXIO_INVALID_ARG_3;
@ -610,14 +609,13 @@ trexio_exit_code trexio_text_read_$group_dset$(const trexio_t* file, $group_dset
#+end_src #+end_src
#+begin_src c :tangle write_dset_text.c #+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$(const trexio_t* file, const $group_dset_dtype$* $group_dset$, const uint32_t rank, const uint64_t* dims) {
if (file == NULL) return TREXIO_INVALID_ARG_1; if (file == NULL) return TREXIO_INVALID_ARG_1;
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2; if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
if (file->mode == 'r') return TREXIO_READONLY; if (file->mode == 'r') return TREXIO_READONLY;
$group$_t* $group$ = trexio_text_read_$group$((trexio_text_t*) file); $group$_t* const $group$ = trexio_text_read_$group$((trexio_text_t*) file);
if ($group$ == NULL) return TREXIO_FAILURE; if ($group$ == NULL) return TREXIO_FAILURE;
if ($group$->$group_dset$ != NULL) { if ($group$->$group_dset$ != NULL) {
@ -648,17 +646,17 @@ trexio_exit_code trexio_text_write_$group_dset$(const trexio_t* file, const $gro
**** Read the complete struct **** Read the complete struct
#+begin_src c :tangle rdm_text.h #+begin_src c :tangle rdm_text.h
rdm_t* trexio_text_read_rdm(trexio_text_t* file); rdm_t* trexio_text_read_rdm(trexio_text_t* const file);
#+end_src #+end_src
#+begin_src c :tangle rdm_text.c #+begin_src c :tangle rdm_text.c
rdm_t* trexio_text_read_rdm(trexio_text_t* file) { rdm_t* trexio_text_read_rdm(trexio_text_t* const file) {
if (file == NULL) return NULL; if (file == NULL) return NULL;
if (file->rdm != NULL) return file->rdm; if (file->rdm != NULL) return file->rdm;
/* Allocate the data structure */ /* Allocate the data structure */
rdm_t* rdm = MALLOC(rdm_t); rdm_t* const rdm = MALLOC(rdm_t);
assert (rdm != NULL); assert (rdm != NULL);
rdm->one_e = NULL; rdm->one_e = NULL;
@ -738,16 +736,16 @@ rdm_t* trexio_text_read_rdm(trexio_text_t* file) {
**** Flush the complete struct **** Flush the complete struct
#+begin_src c :tangle rdm_text.h #+begin_src c :tangle rdm_text.h
trexio_exit_code trexio_text_flush_rdm(const trexio_text_t* file); trexio_exit_code trexio_text_flush_rdm(trexio_text_t* const file);
#+end_src #+end_src
#+begin_src c :tangle rdm_text.c #+begin_src c :tangle rdm_text.c
trexio_exit_code trexio_text_flush_rdm(const trexio_text_t* file) { trexio_exit_code trexio_text_flush_rdm(trexio_text_t* const file) {
if (file == NULL) return TREXIO_INVALID_ARG_1; if (file == NULL) return TREXIO_INVALID_ARG_1;
if (file->parent.mode == 'r') return TREXIO_READONLY; if (file->parent.mode == 'r') return TREXIO_READONLY;
rdm_t* rdm = file->rdm; rdm_t* const rdm = file->rdm;
if (rdm == NULL) return TREXIO_SUCCESS; if (rdm == NULL) return TREXIO_SUCCESS;
if (rdm->to_flush == 0) return TREXIO_SUCCESS; if (rdm->to_flush == 0) return TREXIO_SUCCESS;
@ -779,11 +777,11 @@ trexio_exit_code trexio_text_flush_rdm(const trexio_text_t* file) {
Memory is allocated when reading. The followig function frees memory. Memory is allocated when reading. The followig function frees memory.
#+begin_src c :tangle rdm_text.h #+begin_src c :tangle rdm_text.h
trexio_exit_code trexio_text_free_rdm(trexio_text_t* file); trexio_exit_code trexio_text_free_rdm(trexio_text_t* const file);
#+end_src #+end_src
#+begin_src c :tangle rdm_text.c #+begin_src c :tangle rdm_text.c
trexio_exit_code trexio_text_free_rdm(trexio_text_t* file) { trexio_exit_code trexio_text_free_rdm(trexio_text_t* const file) {
if (file == NULL) return TREXIO_INVALID_ARG_1; if (file == NULL) return TREXIO_INVALID_ARG_1;
if (file->parent.mode != 'r') { if (file->parent.mode != 'r') {
@ -791,7 +789,7 @@ trexio_exit_code trexio_text_free_rdm(trexio_text_t* file) {
if (rc != TREXIO_SUCCESS) return TREXIO_FAILURE; if (rc != TREXIO_SUCCESS) return TREXIO_FAILURE;
} }
rdm_t* rdm = file->rdm; rdm_t* const rdm = file->rdm;
if (rdm == NULL) return TREXIO_SUCCESS; if (rdm == NULL) return TREXIO_SUCCESS;
if (rdm->file != NULL) { if (rdm->file != NULL) {
@ -818,17 +816,27 @@ trexio_exit_code trexio_text_free_rdm(trexio_text_t* file) {
The ~one_e~ array is assumed allocated with the appropriate size. The ~one_e~ array is assumed allocated with the appropriate size.
#+begin_src c :tangle rdm_text.h #+begin_src c :tangle rdm_text.h
trexio_exit_code trexio_text_read_rdm_one_e(const trexio_t* file, double* one_e, const uint64_t dim_one_e); trexio_exit_code
trexio_exit_code trexio_text_write_rdm_one_e(const trexio_t* file, const double* one_e, const uint64_t dim_one_e); trexio_text_read_rdm_one_e(trexio_t* const file,
double* const one_e,
const uint64_t dim_one_e);
trexio_exit_code
trexio_text_write_rdm_one_e(trexio_t* const file,
const double* one_e,
const uint64_t dim_one_e);
#+end_src #+end_src
#+begin_src c :tangle rdm_text.c #+begin_src c :tangle rdm_text.c
trexio_exit_code trexio_text_read_rdm_one_e(const trexio_t* file, double* one_e, const uint64_t dim_one_e) { trexio_exit_code
trexio_text_read_rdm_one_e(trexio_t* const file,
double* const one_e,
const uint64_t dim_one_e)
{
if (file == NULL) return TREXIO_INVALID_ARG_1; if (file == NULL) return TREXIO_INVALID_ARG_1;
if (one_e == NULL) return TREXIO_INVALID_ARG_2; if (one_e == NULL) return TREXIO_INVALID_ARG_2;
rdm_t* rdm = trexio_text_read_rdm((trexio_text_t*) file); rdm_t* const rdm = trexio_text_read_rdm((trexio_text_t*) file);
if (rdm == NULL) return TREXIO_FAILURE; if (rdm == NULL) return TREXIO_FAILURE;
if (dim_one_e != rdm->dim_one_e) return TREXIO_INVALID_ARG_3; if (dim_one_e != rdm->dim_one_e) return TREXIO_INVALID_ARG_3;
@ -841,12 +849,16 @@ trexio_exit_code trexio_text_read_rdm_one_e(const trexio_t* file, double* one_e,
} }
trexio_exit_code trexio_text_write_rdm_one_e(const trexio_t* file, const double* one_e, const uint64_t dim_one_e) { trexio_exit_code
trexio_text_write_rdm_one_e(trexio_t* const file,
const double* one_e,
const uint64_t dim_one_e)
{
if (file == NULL) return TREXIO_INVALID_ARG_1; if (file == NULL) return TREXIO_INVALID_ARG_1;
if (one_e == NULL) return TREXIO_INVALID_ARG_2; if (one_e == NULL) return TREXIO_INVALID_ARG_2;
if (file->mode != 'r') return TREXIO_READONLY; if (file->mode != 'r') return TREXIO_READONLY;
rdm_t* rdm = trexio_text_read_rdm((trexio_text_t*) file); rdm_t* const rdm = trexio_text_read_rdm((trexio_text_t*) file);
if (rdm == NULL) return TREXIO_FAILURE; if (rdm == NULL) return TREXIO_FAILURE;
rdm->dim_one_e = dim_one_e; rdm->dim_one_e = dim_one_e;
@ -868,18 +880,34 @@ trexio_exit_code trexio_text_write_rdm_one_e(const trexio_t* file, const double*
file for each sparse float structure. file for each sparse float structure.
#+begin_src c :tangle rdm_text.h #+begin_src c :tangle rdm_text.h
trexio_exit_code trexio_text_buffered_read_rdm_two_e(const trexio_t* file, const uint64_t offset, const uint64_t size, int64_t* index, double* value); trexio_exit_code
trexio_exit_code trexio_text_buffered_write_rdm_two_e(const trexio_t* file, const uint64_t offset, const uint64_t size, const int64_t* index, const double* value); trexio_text_buffered_read_rdm_two_e(trexio_t* const file,
const uint64_t offset,
const uint64_t size,
int64_t* const index,
double* const value);
trexio_exit_code
trexio_text_buffered_write_rdm_two_e(trexio_t* const file,
const uint64_t offset,
const uint64_t size,
const int64_t* index,
const double* value);
#+end_src #+end_src
#+begin_src c :tangle rdm_text.c #+begin_src c :tangle rdm_text.c
trexio_exit_code trexio_text_buffered_read_rdm_two_e(const trexio_t* file, const uint64_t offset, const uint64_t size, int64_t* index, double* value) { trexio_exit_code
trexio_text_buffered_read_rdm_two_e(trexio_t* const file,
const uint64_t offset,
const uint64_t size,
int64_t* const index,
double* const value)
{
if (file == NULL) return TREXIO_INVALID_ARG_1; if (file == NULL) return TREXIO_INVALID_ARG_1;
if (index == NULL) return TREXIO_INVALID_ARG_4; if (index == NULL) return TREXIO_INVALID_ARG_4;
if (value == NULL) return TREXIO_INVALID_ARG_5; if (value == NULL) return TREXIO_INVALID_ARG_5;
rdm_t* rdm = trexio_text_read_rdm((trexio_text_t*) file); rdm_t* const rdm = trexio_text_read_rdm((trexio_text_t*) file);
if (rdm == NULL) return TREXIO_FAILURE; if (rdm == NULL) return TREXIO_FAILURE;
FILE* f = fopen(rdm->two_e_file_name, "r"); FILE* f = fopen(rdm->two_e_file_name, "r");
@ -906,13 +934,19 @@ trexio_exit_code trexio_text_buffered_read_rdm_two_e(const trexio_t* file, const
} }
trexio_exit_code trexio_text_buffered_write_rdm_two_e(const trexio_t* file, const uint64_t offset, const uint64_t size, const int64_t* index, const double* value) { trexio_exit_code
trexio_text_buffered_write_rdm_two_e(trexio_t* const file,
const uint64_t offset,
const uint64_t size,
const int64_t* index,
const double* value)
{
if (file == NULL) return TREXIO_INVALID_ARG_1; if (file == NULL) return TREXIO_INVALID_ARG_1;
if (index == NULL) return TREXIO_INVALID_ARG_4; if (index == NULL) return TREXIO_INVALID_ARG_4;
if (value == NULL) return TREXIO_INVALID_ARG_5; if (value == NULL) return TREXIO_INVALID_ARG_5;
if (file->mode != 'r') return TREXIO_READONLY; if (file->mode != 'r') return TREXIO_READONLY;
rdm_t* rdm = trexio_text_read_rdm((trexio_text_t*) file); rdm_t* const rdm = trexio_text_read_rdm((trexio_text_t*) file);
if (rdm == NULL) return TREXIO_FAILURE; if (rdm == NULL) return TREXIO_FAILURE;
FILE* f = fopen(rdm->two_e_file_name, "w"); FILE* f = fopen(rdm->two_e_file_name, "w");