1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2025-01-05 19:08:59 +01:00

consistent naming init/deinit instead init/finalize in back ends

This commit is contained in:
q-posev 2021-04-08 11:31:51 +02:00
parent b8c9bfa2df
commit b656917323
3 changed files with 210 additions and 210 deletions

View File

@ -549,19 +549,19 @@ trexio_exit_code trexio_close(trexio_t* file) {
switch (file->back_end) { switch (file->back_end) {
case TREXIO_TEXT: case TREXIO_TEXT:
rc = trexio_text_finalize(file); rc = trexio_text_deinit(file);
break; break;
case TREXIO_HDF5: case TREXIO_HDF5:
rc = trexio_hdf5_finalize(file); rc = trexio_hdf5_deinit(file);
break; break;
/* /*
case TREXIO_JSON: case TREXIO_JSON:
rc = trexio_json_finalize(file); rc = trexio_json_deinit(file);
break; break;
,*/ ,*/
default: default:
assert (1 == 0); /* Impossible case */ rc = TREXIO_FAILURE; /* Impossible case */
} }
if (rc != TREXIO_SUCCESS) { if (rc != TREXIO_SUCCESS) {

View File

@ -61,7 +61,7 @@ typedef struct trexio_hdf5_s {
} trexio_hdf5_t; } trexio_hdf5_t;
trexio_exit_code trexio_hdf5_init(trexio_t* const file); trexio_exit_code trexio_hdf5_init(trexio_t* const file);
trexio_exit_code trexio_hdf5_finalize(trexio_t* const file); trexio_exit_code trexio_hdf5_deinit(trexio_t* const file);
#+end_src #+end_src
@ -128,7 +128,7 @@ trexio_exit_code trexio_hdf5_init(trexio_t* const file) {
return TREXIO_SUCCESS; return TREXIO_SUCCESS;
} }
trexio_exit_code trexio_hdf5_finalize(trexio_t* const file) { trexio_exit_code trexio_hdf5_deinit(trexio_t* const file) {
trexio_hdf5_t* f = (trexio_hdf5_t*) file; trexio_hdf5_t* f = (trexio_hdf5_t*) file;
@ -188,7 +188,7 @@ trexio_exit_code trexio_hdf5_write_$group_num$ (trexio_t* const file, const uint
const hid_t dspace = H5Screate(H5S_SCALAR); const hid_t dspace = H5Screate(H5S_SCALAR);
const hid_t num_id = H5Acreate(f->$group$_group, $GROUP_NUM$_NAME, dtype, dspace, const hid_t num_id = H5Acreate(f->$group$_group, $GROUP_NUM$_NAME, dtype, dspace,
H5P_DEFAULT, H5P_DEFAULT); H5P_DEFAULT, H5P_DEFAULT);
if (num_id <= 0) { if (num_id <= 0) {
H5Sclose(dspace); H5Sclose(dspace);
H5Tclose(dtype); H5Tclose(dtype);
@ -217,21 +217,21 @@ trexio_exit_code trexio_hdf5_write_$group_num$ (trexio_t* const file, const uint
if (infile_num != num) { if (infile_num != num) {
if (infile_num != 0) { if (infile_num != 0) {
printf("%lu -> %lu %s \n", num, infile_num, printf("%lu -> %lu %s \n", num, infile_num,
"This variable already exists. Overwriting it is not supported"); "This variable already exists. Overwriting it is not supported");
return TREXIO_FAILURE; return TREXIO_FAILURE;
} else { } else {
const hid_t dtype = H5Tcopy(H5T_NATIVE_ULLONG); const hid_t dtype = H5Tcopy(H5T_NATIVE_ULLONG);
const hid_t num_id = H5Aopen(f->$group$_group, $GROUP_NUM$_NAME, H5P_DEFAULT); const hid_t num_id = H5Aopen(f->$group$_group, $GROUP_NUM$_NAME, H5P_DEFAULT);
if (num_id <= 0) return TREXIO_INVALID_ID; if (num_id <= 0) return TREXIO_INVALID_ID;
const herr_t status = H5Awrite(num_id, dtype, &(num)); const herr_t status = H5Awrite(num_id, dtype, &(num));
if (status < 0) return TREXIO_FAILURE; if (status < 0) return TREXIO_FAILURE;
H5Aclose(num_id); H5Aclose(num_id);
H5Tclose(dtype); H5Tclose(dtype);
} }
} }
return TREXIO_SUCCESS; return TREXIO_SUCCESS;
@ -278,7 +278,7 @@ trexio_exit_code trexio_hdf5_read_$group$_$group_dset$(trexio_t* const file, $gr
int rrank; int rrank;
// get the rank of the dataset in a file // get the rank of the dataset in a file
status = H5LTget_dataset_ndims (f->$group$_group, $GROUP$_$GROUP_DSET$_NAME, status = H5LTget_dataset_ndims (f->$group$_group, $GROUP$_$GROUP_DSET$_NAME,
&rrank); &rrank);
if (status < 0) return TREXIO_FAILURE; if (status < 0) return TREXIO_FAILURE;
@ -311,8 +311,8 @@ trexio_exit_code trexio_hdf5_read_$group$_$group_dset$(trexio_t* const file, $gr
/* High-level H5LT API. No need to deal with dataspaces and datatypes */ /* High-level H5LT API. No need to deal with dataspaces and datatypes */
status = H5LTread_dataset_$group_dset_h5_dtype$(f->$group$_group, status = H5LTread_dataset_$group_dset_h5_dtype$(f->$group$_group,
$GROUP$_$GROUP_DSET$_NAME, $GROUP$_$GROUP_DSET$_NAME,
$group_dset$); $group_dset$);
if (status < 0) return TREXIO_FAILURE; if (status < 0) return TREXIO_FAILURE;
return TREXIO_SUCCESS; return TREXIO_SUCCESS;
@ -337,7 +337,7 @@ trexio_exit_code trexio_hdf5_write_$group$_$group_dset$(trexio_t* const file, co
const herr_t status = const herr_t status =
H5LTmake_dataset_$group_dset_h5_dtype$ (f->$group$_group, $GROUP$_$GROUP_DSET$_NAME, H5LTmake_dataset_$group_dset_h5_dtype$ (f->$group$_group, $GROUP$_$GROUP_DSET$_NAME,
(int) rank, (const hsize_t*) dims, $group_dset$); (int) rank, (const hsize_t*) dims, $group_dset$);
if (status < 0) return TREXIO_FAILURE; if (status < 0) return TREXIO_FAILURE;
} else { } else {
@ -347,7 +347,7 @@ trexio_exit_code trexio_hdf5_write_$group$_$group_dset$(trexio_t* const file, co
const herr_t status = const herr_t status =
H5Dwrite(dset_id, H5T_NATIVE_$GROUP_DSET_H5_DTYPE$, H5S_ALL, H5S_ALL, H5Dwrite(dset_id, H5T_NATIVE_$GROUP_DSET_H5_DTYPE$, H5S_ALL, H5S_ALL,
H5P_DEFAULT, $group_dset$); H5P_DEFAULT, $group_dset$);
H5Dclose(dset_id); H5Dclose(dset_id);
if (status < 0) return TREXIO_FAILURE; if (status < 0) return TREXIO_FAILURE;

View File

@ -189,7 +189,7 @@ trexio_exit_code trexio_text_lock(trexio_t* const file) {
#+begin_src c :tangle basic_text.h #+begin_src c :tangle basic_text.h
trexio_exit_code trexio_text_finalize(trexio_t* const file); trexio_exit_code trexio_text_deinit(trexio_t* const file);
#+end_src #+end_src
#+begin_src c :tangle basic_text.h #+begin_src c :tangle basic_text.h
@ -220,7 +220,7 @@ trexio_exit_code trexio_text_unlock(trexio_t* const 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* const file) { trexio_exit_code trexio_text_deinit(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;
@ -317,21 +317,21 @@ $group$_t* trexio_text_read_$group$(trexio_text_t* const file) {
rc = fscanf(f, "%1023s %u", buffer, &j); rc = fscanf(f, "%1023s %u", buffer, &j);
if ((rc != 2) || (strcmp(buffer, "dims_$group_dset$") != 0) || (j!=i)) { if ((rc != 2) || (strcmp(buffer, "dims_$group_dset$") != 0) || (j!=i)) {
FREE(buffer); FREE(buffer);
FREE(file_name); FREE(file_name);
fclose(f); fclose(f);
FREE($group$); FREE($group$);
return NULL; return NULL;
} }
rc = fscanf(f, "%lu\n", &($group$->dims_$group_dset$[i])); rc = fscanf(f, "%lu\n", &($group$->dims_$group_dset$[i]));
assert(!(rc != 1)); assert(!(rc != 1));
if (rc != 1) { if (rc != 1) {
FREE(buffer); FREE(buffer);
FREE(file_name); FREE(file_name);
fclose(f); fclose(f);
FREE($group$); FREE($group$);
return NULL; return NULL;
} }
size_$group_dset$ *= $group$->dims_$group_dset$[i]; size_$group_dset$ *= $group$->dims_$group_dset$[i];
@ -376,24 +376,24 @@ $group$_t* trexio_text_read_$group$(trexio_text_t* const file) {
rc = fscanf(f, "%1023s", buffer); rc = fscanf(f, "%1023s", buffer);
assert(!((rc != 1) || (strcmp(buffer, "$group_dset$") != 0))); assert(!((rc != 1) || (strcmp(buffer, "$group_dset$") != 0)));
if ((rc != 1) || (strcmp(buffer, "$group_dset$") != 0)) { if ((rc != 1) || (strcmp(buffer, "$group_dset$") != 0)) {
FREE(buffer); FREE(buffer);
FREE(file_name); FREE(file_name);
fclose(f); fclose(f);
FREE($group$->$group_dset$); FREE($group$->$group_dset$);
FREE($group$); FREE($group$);
return NULL; return NULL;
} }
for (uint64_t i=0 ; i<size_$group_dset$ ; ++i) { for (uint64_t i=0 ; i<size_$group_dset$ ; ++i) {
rc = fscanf(f, "%$group_dset_std_dtype_in$", &($group$->$group_dset$[i])); rc = fscanf(f, "%$group_dset_std_dtype_in$", &($group$->$group_dset$[i]));
assert(!(rc != 1)); assert(!(rc != 1));
if (rc != 1) { if (rc != 1) {
FREE(buffer); FREE(buffer);
FREE(file_name); FREE(file_name);
fclose(f); fclose(f);
FREE($group$->$group_dset$); FREE($group$->$group_dset$);
FREE($group$); FREE($group$);
return NULL; return NULL;
} }
} }
// END REPEAT GROUP_DSET // END REPEAT GROUP_DSET
@ -827,20 +827,20 @@ trexio_exit_code trexio_text_free_rdm(trexio_text_t* const file) {
#+begin_src c :tangle rdm_text.h #+begin_src c :tangle rdm_text.h
trexio_exit_code trexio_exit_code
trexio_text_read_rdm_one_e(trexio_t* const file, trexio_text_read_rdm_one_e(trexio_t* const file,
double* const one_e, double* const one_e,
const uint64_t dim_one_e); const uint64_t dim_one_e);
trexio_exit_code trexio_exit_code
trexio_text_write_rdm_one_e(trexio_t* const file, trexio_text_write_rdm_one_e(trexio_t* const file,
const double* one_e, const double* one_e,
const uint64_t dim_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_exit_code
trexio_text_read_rdm_one_e(trexio_t* const file, trexio_text_read_rdm_one_e(trexio_t* const file,
double* const one_e, double* const one_e,
const uint64_t dim_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;
@ -860,8 +860,8 @@ trexio_text_read_rdm_one_e(trexio_t* const file,
trexio_exit_code trexio_exit_code
trexio_text_write_rdm_one_e(trexio_t* const file, trexio_text_write_rdm_one_e(trexio_t* const file,
const double* one_e, const double* one_e,
const uint64_t dim_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;
@ -891,26 +891,26 @@ trexio_text_write_rdm_one_e(trexio_t* const file,
#+begin_src c :tangle rdm_text.h #+begin_src c :tangle rdm_text.h
trexio_exit_code trexio_exit_code
trexio_text_buffered_read_rdm_two_e(trexio_t* const file, trexio_text_buffered_read_rdm_two_e(trexio_t* const file,
const uint64_t offset, const uint64_t offset,
const uint64_t size, const uint64_t size,
int64_t* const index, int64_t* const index,
double* const value); double* const value);
trexio_exit_code trexio_exit_code
trexio_text_buffered_write_rdm_two_e(trexio_t* const file, trexio_text_buffered_write_rdm_two_e(trexio_t* const file,
const uint64_t offset, const uint64_t offset,
const uint64_t size, const uint64_t size,
const int64_t* index, const int64_t* index,
const double* value); 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_exit_code
trexio_text_buffered_read_rdm_two_e(trexio_t* const file, trexio_text_buffered_read_rdm_two_e(trexio_t* const file,
const uint64_t offset, const uint64_t offset,
const uint64_t size, const uint64_t size,
int64_t* const index, int64_t* const index,
double* const value) 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;
@ -927,11 +927,11 @@ trexio_text_buffered_read_rdm_two_e(trexio_t* const file,
for (uint64_t i=0 ; i<size ; ++i) { for (uint64_t i=0 ; i<size ; ++i) {
int rc = fscanf(f, "%9ld %9ld %9ld %9ld %24le\n", int rc = fscanf(f, "%9ld %9ld %9ld %9ld %24le\n",
&index[4*i], &index[4*i],
&index[4*i+1], &index[4*i+1],
&index[4*i+2], &index[4*i+2],
&index[4*i+3], &index[4*i+3],
&value[i]); &value[i]);
if (rc == 5) { if (rc == 5) {
/* Do nothing */ /* Do nothing */
} else if (rc == EOF) { } else if (rc == EOF) {
@ -945,10 +945,10 @@ trexio_text_buffered_read_rdm_two_e(trexio_t* const file,
trexio_exit_code trexio_exit_code
trexio_text_buffered_write_rdm_two_e(trexio_t* const file, trexio_text_buffered_write_rdm_two_e(trexio_t* const file,
const uint64_t offset, const uint64_t offset,
const uint64_t size, const uint64_t size,
const int64_t* index, const int64_t* index,
const double* value) 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;
@ -966,11 +966,11 @@ trexio_text_buffered_write_rdm_two_e(trexio_t* const file,
for (uint64_t i=0 ; i<size ; ++i) { for (uint64_t i=0 ; i<size ; ++i) {
int rc = fprintf(f, "%9ld %9ld %9ld %9ld %24le\n", int rc = fprintf(f, "%9ld %9ld %9ld %9ld %24le\n",
index[4*i], index[4*i],
index[4*i+1], index[4*i+1],
index[4*i+2], index[4*i+2],
index[4*i+3], index[4*i+3],
value[i]); value[i]);
if (rc != 5) return TREXIO_FAILURE; if (rc != 5) return TREXIO_FAILURE;
} }
@ -978,7 +978,7 @@ trexio_text_buffered_write_rdm_two_e(trexio_t* const file,
} }
#+end_src #+end_src
:noexport: :noexport:
* Constant file suffixes :noxport: * Constant file suffixes :noxport: