1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2025-01-09 12:44:11 +01:00

Undefined num_id in HDF5

This commit is contained in:
Anthony Scemama 2021-03-29 00:34:03 +02:00
parent 9edeb7825e
commit 3f2261ea9b
2 changed files with 42 additions and 31 deletions

View File

@ -52,8 +52,9 @@ fortran: libtrexio.so trexio_f.f90
cppcheck.out: $(HEADER_FILES) $(SOURCE_FILES) cppcheck.out: $(HEADER_FILES) $(SOURCE_FILES)
cppcheck --addon=cert -q --error-exitcode=0 \ cppcheck --addon=cert -q --error-exitcode=0 \
--enable=style,warning,unusedFunction,performance,portability,missingInclude \ --enable=warning,performance,portability,missingInclude,information \
--language=c -rp --std=c99 -v $(SOURCE_FILES) 2>$@ --language=c --std=c99 -rp --platform=unix64 \
$(INCLUDE) $(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

@ -60,8 +60,8 @@ typedef struct trexio_hdf5_s {
const char* file_name; const char* file_name;
} trexio_hdf5_t; } trexio_hdf5_t;
trexio_exit_code trexio_hdf5_init(trexio_t* file); trexio_exit_code trexio_hdf5_init(trexio_t* const file);
trexio_exit_code trexio_hdf5_finalize(trexio_t* file); trexio_exit_code trexio_hdf5_finalize(trexio_t* const file);
#+end_src #+end_src
@ -70,9 +70,9 @@ trexio_exit_code trexio_hdf5_finalize(trexio_t* file);
#+begin_src c :tangle basic_hdf5.c #+begin_src c :tangle basic_hdf5.c
trexio_exit_code trexio_hdf5_init(trexio_t* file) { trexio_exit_code trexio_hdf5_init(trexio_t* const file) {
trexio_hdf5_t* f = (trexio_hdf5_t*) file; trexio_hdf5_t* const f = (trexio_hdf5_t*) file;
/* If file doesn't exist, create it */ /* If file doesn't exist, create it */
int f_exists = 0; int f_exists = 0;
@ -131,7 +131,7 @@ trexio_exit_code trexio_hdf5_init(trexio_t* file) {
return TREXIO_SUCCESS; return TREXIO_SUCCESS;
} }
trexio_exit_code trexio_hdf5_finalize(trexio_t* file) { trexio_exit_code trexio_hdf5_finalize(trexio_t* const file) {
trexio_hdf5_t* f = (trexio_hdf5_t*) file; trexio_hdf5_t* f = (trexio_hdf5_t*) file;
@ -156,13 +156,13 @@ trexio_exit_code trexio_hdf5_finalize(trexio_t* file) {
** Template for HDF5 read/write a number ** Template for HDF5 read/write a number
#+begin_src c :tangle rw_num_hdf5.h #+begin_src c :tangle rw_num_hdf5.h
trexio_exit_code trexio_hdf5_read_$group_num$ (const trexio_t* file, uint64_t* num); 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* file, const uint64_t num); trexio_exit_code trexio_hdf5_write_$group_num$(trexio_t* const file, const uint64_t num);
#+end_src #+end_src
#+begin_src c :tangle read_num_hdf5.c #+begin_src c :tangle read_num_hdf5.c
trexio_exit_code trexio_hdf5_read_$group_num$ (const trexio_t* file, uint64_t* num) { trexio_exit_code trexio_hdf5_read_$group_num$ (trexio_t* const file, uint64_t* const num) {
assert (file != NULL); assert (file != NULL);
assert (num != NULL); assert (num != NULL);
@ -184,29 +184,39 @@ trexio_exit_code trexio_hdf5_read_$group_num$ (const trexio_t* file, uint64_t* n
#+begin_src c :tangle write_num_hdf5.c #+begin_src c :tangle write_num_hdf5.c
trexio_exit_code trexio_hdf5_write_$group_num$ (trexio_t* file, const uint64_t num) { trexio_exit_code trexio_hdf5_write_$group_num$ (trexio_t* const file, const uint64_t num) {
assert (file != NULL); assert (file != NULL);
assert (num > 0L); assert (num > 0L);
trexio_hdf5_t* f = (trexio_hdf5_t*) file; trexio_hdf5_t* const f = (trexio_hdf5_t*) file;
hid_t num_id;
herr_t status;
/* Write the dimensioning variables */
hid_t dtype = H5Tcopy(H5T_NATIVE_ULLONG);
if (H5Aexists(f->$group$_group, $GROUP_NUM$_NAME) == 0) { if (H5Aexists(f->$group$_group, $GROUP_NUM$_NAME) == 0) {
hid_t dspace = H5Screate(H5S_SCALAR); /* Write the dimensioning variables */
const hid_t dtype = H5Tcopy(H5T_NATIVE_ULLONG);
const hid_t dspace = H5Screate(H5S_SCALAR);
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) return TREXIO_INVALID_ID; if (num_id <= 0) {
H5Sclose(dspace);
H5Tclose(dtype);
return TREXIO_INVALID_ID;
}
status = H5Awrite(num_id, dtype, &(num)); const herr_t status = H5Awrite(num_id, dtype, &(num));
if (status < 0) return TREXIO_FAILURE; if (status < 0) {
H5Aclose(num_id);
H5Sclose(dspace);
H5Tclose(dtype);
return TREXIO_FAILURE;
}
H5Sclose(dspace); H5Sclose(dspace);
H5Aclose(num_id);
H5Tclose(dtype);
return TREXIO_SUCCESS;
} else { } else {
@ -219,24 +229,24 @@ trexio_exit_code trexio_hdf5_write_$group_num$ (trexio_t* file, const uint64_t n
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");
H5Tclose(dtype);
return TREXIO_FAILURE; return TREXIO_FAILURE;
} else { } else {
num_id = H5Aopen(f->$group$_group, $GROUP_NUM$_NAME, H5P_DEFAULT); const hid_t dtype = H5Tcopy(H5T_NATIVE_ULLONG);
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;
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);
H5Tclose(dtype);
} }
} }
return TREXIO_SUCCESS;
} }
H5Aclose(num_id);
H5Tclose(dtype);
return TREXIO_SUCCESS;
} }
#+end_src #+end_src
@ -246,12 +256,12 @@ trexio_exit_code trexio_hdf5_write_$group_num$ (trexio_t* file, const uint64_t n
#+begin_src c :tangle rw_dset_hdf5.h #+begin_src c :tangle rw_dset_hdf5.h
trexio_exit_code trexio_hdf5_read_$group$_$group_dset$(const trexio_t* file, $group_dset_dtype$* $group_dset$, const uint32_t rank, const uint64_t* dims); trexio_exit_code trexio_hdf5_read_$group$_$group_dset$(trexio_t* const file, $group_dset_dtype$* const $group_dset$, const uint32_t rank, const uint64_t* dims);
trexio_exit_code trexio_hdf5_write_$group$_$group_dset$(trexio_t* file, const $group_dset_dtype$* $group_dset$, const uint32_t rank, const uint64_t* dims); trexio_exit_code trexio_hdf5_write_$group$_$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_hdf5.c #+begin_src c :tangle read_dset_hdf5.c
trexio_exit_code trexio_hdf5_read_$group$_$group_dset$(const trexio_t* file, $group_dset_dtype$* $group_dset$, const uint32_t rank, const uint64_t* dims) { trexio_exit_code trexio_hdf5_read_$group$_$group_dset$(trexio_t* const file, $group_dset_dtype$* const $group_dset$, const uint32_t rank, const uint64_t* dims) {
assert (file != NULL); assert (file != NULL);
assert ($group_dset$ != NULL); assert ($group_dset$ != NULL);
@ -305,7 +315,7 @@ trexio_exit_code trexio_hdf5_read_$group$_$group_dset$(const trexio_t* file, $gr
#+end_src #+end_src
#+begin_src c :tangle write_dset_hdf5.c #+begin_src c :tangle write_dset_hdf5.c
trexio_exit_code trexio_hdf5_write_$group$_$group_dset$(trexio_t* file, const $group_dset_dtype$* $group_dset$, const uint32_t rank, const uint64_t* dims) { trexio_exit_code trexio_hdf5_write_$group$_$group_dset$(trexio_t* const file, const $group_dset_dtype$* $group_dset$, const uint32_t rank, const uint64_t* dims) {
assert (file != NULL); assert (file != NULL);
assert ($group_dset$ != NULL); assert ($group_dset$ != NULL);