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

adapt the templates in back ends

This commit is contained in:
q-posev 2021-09-20 15:51:36 +02:00
parent 261e7c8b84
commit 4b9827048f
2 changed files with 33 additions and 66 deletions

View File

@ -156,14 +156,14 @@ trexio_hdf5_deinit (trexio_t* const file)
#+begin_src c :tangle hrw_num_hdf5.h :exports none
trexio_exit_code trexio_hdf5_has_$group_num$ (trexio_t* const file);
trexio_exit_code trexio_hdf5_read_$group_num$ (trexio_t* const file, uint64_t* const num);
trexio_exit_code trexio_hdf5_write_$group_num$(trexio_t* const file, const uint64_t num);
trexio_exit_code trexio_hdf5_read_$group_num$ (trexio_t* const file, $group_num_dtype_double$ * const num);
trexio_exit_code trexio_hdf5_write_$group_num$(trexio_t* const file, const $group_num_dtype_double$ num);
#+end_src
#+begin_src c :tangle read_num_hdf5.c
trexio_exit_code
trexio_hdf5_read_$group_num$ (trexio_t* const file, uint64_t* const num)
trexio_hdf5_read_$group_num$ (trexio_t* const file, $group_num_dtype_double$ * const num)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
@ -177,7 +177,7 @@ trexio_hdf5_read_$group_num$ (trexio_t* const file, uint64_t* const num)
const hid_t num_id = H5Aopen(f->$group$_group, $GROUP_NUM$_NAME, H5P_DEFAULT);
if (num_id <= 0) return TREXIO_INVALID_ID;
const herr_t status = H5Aread(num_id, H5T_NATIVE_UINT64, num);
const herr_t status = H5Aread(num_id, H5T_$GROUP_NUM_H5_DTYPE$, num);
H5Aclose(num_id);
@ -191,7 +191,7 @@ trexio_hdf5_read_$group_num$ (trexio_t* const file, uint64_t* const num)
#+begin_src c :tangle write_num_hdf5.c
trexio_exit_code
trexio_hdf5_write_$group_num$ (trexio_t* const file, const uint64_t num)
trexio_hdf5_write_$group_num$ (trexio_t* const file, const $group_num_dtype_double$ num)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
@ -199,52 +199,31 @@ trexio_hdf5_write_$group_num$ (trexio_t* const file, const uint64_t num)
trexio_hdf5_t* const f = (trexio_hdf5_t*) file;
if (H5Aexists(f->$group$_group, $GROUP_NUM$_NAME) == 0) {
/* Write the dimensioning variables */
const hid_t dtype = H5Tcopy(H5T_NATIVE_UINT64);
const hid_t dspace = H5Screate(H5S_SCALAR);
const hid_t num_id = H5Acreate(f->$group$_group, $GROUP_NUM$_NAME, dtype, dspace,
H5P_DEFAULT, H5P_DEFAULT);
if (num_id <= 0) {
H5Sclose(dspace);
H5Tclose(dtype);
return TREXIO_INVALID_ID;
}
const herr_t status = H5Awrite(num_id, dtype, &(num));
if (status < 0) {
H5Aclose(num_id);
H5Sclose(dspace);
H5Tclose(dtype);
return TREXIO_FAILURE;
}
/* Write the dimensioning variables */
const hid_t dtype = H5Tcopy(H5T_$GROUP_NUM_H5_DTYPE$);
const hid_t dspace = H5Screate(H5S_SCALAR);
const hid_t num_id = H5Acreate(f->$group$_group, $GROUP_NUM$_NAME,
dtype, dspace, H5P_DEFAULT, H5P_DEFAULT);
if (num_id <= 0) {
H5Sclose(dspace);
H5Aclose(num_id);
H5Tclose(dtype);
return TREXIO_SUCCESS;
} else {
uint64_t infile_num;
trexio_exit_code rc = trexio_hdf5_read_$group_num$(file, &(infile_num));
if (rc != TREXIO_SUCCESS) return rc;
const hid_t dtype = H5Tcopy(H5T_NATIVE_UINT64);
const hid_t num_id = H5Aopen(f->$group$_group, $GROUP_NUM$_NAME, H5P_DEFAULT);
if (num_id <= 0) return TREXIO_INVALID_ID;
const herr_t status = H5Awrite(num_id, dtype, &(num));
if (status < 0) return TREXIO_FAILURE;
H5Aclose(num_id);
H5Tclose(dtype);
return TREXIO_SUCCESS;
return TREXIO_INVALID_ID;
}
const herr_t status = H5Awrite(num_id, dtype, &(num));
if (status < 0) {
H5Aclose(num_id);
H5Sclose(dspace);
H5Tclose(dtype);
return TREXIO_FAILURE;
}
H5Sclose(dspace);
H5Aclose(num_id);
H5Tclose(dtype);
return TREXIO_SUCCESS;
}
#+end_src
@ -341,12 +320,6 @@ trexio_hdf5_write_$group_dset$ (trexio_t* const file, const $group_dset_dtype$*
if (file == NULL) return TREXIO_INVALID_ARG_1;
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
trexio_exit_code rc;
uint64_t $group_dset_dim$;
// error handling for rc is added by the generator
rc = trexio_hdf5_read_$group_dset_dim$(file, &($group_dset_dim$));
if ($group_dset_dim$ == 0L) return TREXIO_INVALID_NUM;
trexio_hdf5_t* f = (trexio_hdf5_t*) file;
if ( H5LTfind_dataset(f->$group$_group, $GROUP_DSET$_NAME) != 1 ) {
@ -523,12 +496,6 @@ trexio_hdf5_write_$group_dset$ (trexio_t* const file, const char** $group_dset$,
if (file == NULL) return TREXIO_INVALID_ARG_1;
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
trexio_exit_code rc;
uint64_t $group_dset_dim$;
// error handling for rc is added by the generator
rc = trexio_hdf5_read_$group_dset_dim$(file, &($group_dset_dim$));
if ($group_dset_dim$ == 0L) return TREXIO_INVALID_NUM;
trexio_hdf5_t* f = (trexio_hdf5_t*) file;
herr_t status;

View File

@ -78,7 +78,7 @@
#+begin_src c :tangle struct_text_group_dset.h
typedef struct $group$_s {
uint64_t $group_num$;
$group_num_dtype_double$ $group_num$;
$group_dset_dtype$* $group_dset$;
uint32_t rank_$group_dset$;
uint32_t to_flush;
@ -357,7 +357,7 @@ trexio_text_read_$group$ (trexio_text_t* const file)
return NULL;
}
rc = fscanf(f, "%" SCNu64 "", &($group$->$group_num$));
rc = fscanf(f, "%$group_num_std_dtype_in$", &($group$->$group_num$));
assert(!(rc != 1));
if (rc != 1) {
FREE(buffer);
@ -555,7 +555,7 @@ trexio_text_flush_$group$ (trexio_text_t* const file)
// END REPEAT GROUP_DSET_ALL
// START REPEAT GROUP_NUM
fprintf(f, "$group_num$ %" PRIu64 "\n", $group$->$group_num$);
fprintf(f, "$group_num$ %$group_num_std_dtype_out$ \n", $group$->$group_num$);
// END REPEAT GROUP_NUM
// START REPEAT GROUP_ATTR_STR
@ -628,13 +628,13 @@ trexio_text_free_$group$ (trexio_text_t* const file)
#+begin_src c :tangle hrw_num_text.h :exports none
trexio_exit_code trexio_text_has_$group_num$ (trexio_t* const file);
trexio_exit_code trexio_text_read_$group_num$ (trexio_t* const file, uint64_t* const num);
trexio_exit_code trexio_text_write_$group_num$(trexio_t* const file, const uint64_t num);
trexio_exit_code trexio_text_read_$group_num$ (trexio_t* const file, $group_num_dtype_double$ * const num);
trexio_exit_code trexio_text_write_$group_num$(trexio_t* const file, const $group_num_dtype_double$ num);
#+end_src
#+begin_src c :tangle read_num_text.c
trexio_exit_code
trexio_text_read_$group_num$ (trexio_t* const file, uint64_t* const num)
trexio_text_read_$group_num$ (trexio_t* const file, $group_num_dtype_double$ * const num)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
@ -652,7 +652,7 @@ trexio_text_read_$group_num$ (trexio_t* const file, uint64_t* const num)
#+begin_src c :tangle write_num_text.c
trexio_exit_code
trexio_text_write_$group_num$ (trexio_t* const file, const uint64_t num)
trexio_text_write_$group_num$ (trexio_t* const file, const $group_num_dtype_double$ num)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;