1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-08-24 22:21:43 +02:00

working has_ functions [all]

This commit is contained in:
q-posev 2021-03-30 11:50:02 +02:00
parent 679c462d63
commit 068beacb07
5 changed files with 138 additions and 54 deletions

View File

@ -94,11 +94,11 @@ files_front = [f for f in listdir(templ_path_front) if isfile(join(templ_path_fr
files = files_text + files_hdf5 + files_front
files_funcs = [f for f in files if 'read_' in f or 'write_' in f or 'flush_' in f or 'free_' in f or 'rw_' in f ]
files_funcs = [f for f in files if 'read_' in f or 'write_' in f or 'flush_' in f or 'free_' in f or 'hrw_' in f or 'has_' in f]
files_funcs_dsets = [f for f in files_funcs if 'dset' in f]
files_funcs_nums = [f for f in files_funcs if 'num' in f]
files_funcs_groups = [f for f in files_funcs if 'group' in f]
files_auxil = [f for f in files if not ('read_' in f or 'write_' in f or 'rw_' in f)]
files_auxil = [f for f in files if not ('read_' in f or 'write_' in f or 'hrw_' in f or 'has_' in f)]
files_funcs_groups.append('struct_text_group_dset.h')

View File

@ -12,7 +12,6 @@
#+end_src
#+begin_src fortran :tangle prefix_fortran.f90 :noweb yes
module trexio
use, intrinsic :: iso_c_binding
@ -36,6 +35,7 @@ module trexio
integer, parameter :: TREXIO_INVALID_ID = 20
integer, parameter :: TREXIO_ALLOCATION_FAILED = 21
integer, parameter :: TREXIO_INVALID_NUM = 22
integer, parameter :: TREXIO_HAS_NOT = 30
#+end_src
@ -128,6 +128,7 @@ typedef int32_t trexio_exit_code;
#define TREXIO_INVALID_ID ( (trexio_exit_code) 20 )
#define TREXIO_ALLOCATION_FAILED ( (trexio_exit_code) 21 )
#define TREXIO_INVALID_NUM ( (trexio_exit_code) 22 )
#define TREXIO_HAS_NOT ( (trexio_exit_code) 30 )
#+end_src
@ -401,15 +402,16 @@ end interface
#+end_src
* Templates for front end
** Template for frontend read/write a number
** Template for frontend has/read/write a number
#+begin_src c :tangle rw_num_front.h
#+begin_src c :tangle hrw_num_front.h
trexio_exit_code trexio_has_$group_num$(trexio_t* const file);
trexio_exit_code trexio_read_$group_num$(trexio_t* const file, int64_t* const num);
trexio_exit_code trexio_write_$group_num$(trexio_t* const file, const int64_t num);
#+end_src
#+begin_src c :tangle read_num_front.c
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) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
uint64_t u_num = 0;
@ -433,13 +435,12 @@ trexio_exit_code trexio_read_$group_num$(trexio_t* file, int64_t* num) {
if (rc != TREXIO_SUCCESS) return rc;
/**/ *num = (int64_t) u_num;
*num = (int64_t) u_num;
return TREXIO_SUCCESS;
}
#+end_src
#+begin_src c :tangle write_num_front.c
trexio_exit_code trexio_write_$group_num$(trexio_t* const file, const int64_t num) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (num < 0 ) return TREXIO_INVALID_ARG_2;
@ -467,9 +468,32 @@ trexio_exit_code trexio_write_$group_num$(trexio_t* const file, const int64_t nu
}
#+end_src
#+begin_src c :tangle has_num_front.c
trexio_exit_code trexio_has_$group_num$(trexio_t* const file) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
switch (file->back_end) {
case TREXIO_TEXT:
return trexio_text_has_$group_num$(file);
break;
case TREXIO_HDF5:
return trexio_hdf5_has_$group_num$(file);
break;
/*
case TREXIO_JSON:
return trexio_json_has_$group_num$(file);
break;
,*/
default:
return TREXIO_FAILURE; /* Impossible case */
}
}
#+end_src
#+begin_src fortran :tangle write_num_front_fortran.f90
interface
integer function trexio_write_$group_num$ (trex_file, num) bind(C)
use, intrinsic :: iso_c_binding
@ -477,12 +501,9 @@ interface
integer(8), intent(in), value :: num
end function trexio_write_$group_num$
end interface
#+end_src
#+begin_src fortran :tangle read_num_front_fortran.f90
interface
integer function trexio_read_$group_num$ (trex_file, num) bind(C)
use, intrinsic :: iso_c_binding
@ -490,13 +511,21 @@ interface
integer(8), intent(out) :: num
end function trexio_read_$group_num$
end interface
#+end_src
#+begin_src fortran :tangle has_num_front_fortran.f90
interface
integer function trexio_has_$group_num$ (trex_file) bind(C)
use, intrinsic :: iso_c_binding
integer(8), intent(in), value :: trex_file
end function trexio_has_$group_num$
end interface
#+end_src
** Template for frontend read/write a dataset
** Template for frontend has/read/write a dataset
#+begin_src c :tangle rw_dset_front.h
#+begin_src c :tangle hrw_dset_front.h
trexio_exit_code trexio_has_$group$_$group_dset$(trexio_t* const file);
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* const file, const $group_dset_dtype$* $group_dset$);
#+end_src
@ -553,7 +582,6 @@ trexio_exit_code trexio_read_$group$_$group_dset$(trexio_t* const file, $group_d
#+end_src
#+begin_src c :tangle write_dset_front.c
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 ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
@ -602,8 +630,32 @@ trexio_exit_code trexio_write_$group$_$group_dset$(trexio_t* const file, const $
}
#+end_src
#+begin_src fortran :tangle write_dset_front_fortran.f90
#+begin_src c :tangle has_dset_front.c
trexio_exit_code trexio_has_$group$_$group_dset$(trexio_t* const file) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
switch (file->back_end) {
case TREXIO_TEXT:
return trexio_text_has_$group$_$group_dset$(file);
break;
case TREXIO_HDF5:
return trexio_hdf5_has_$group$_$group_dset$(file);
break;
/*
case TREXIO_JSON:
return trexio_json_has_$group$_$group_dset$(file);
break;
,*/
default:
return TREXIO_FAILURE; /* Impossible case */
}
}
#+end_src
#+begin_src fortran :tangle write_dset_front_fortran.f90
interface
integer function trexio_write_$group$_$group_dset$ (trex_file, dset) bind(C)
use, intrinsic :: iso_c_binding
@ -611,11 +663,9 @@ interface
$group_dset_f_dtype$, intent(in) :: dset(*)
end function trexio_write_$group$_$group_dset$
end interface
#+end_src
#+begin_src fortran :tangle read_dset_front_fortran.f90
interface
integer function trexio_read_$group$_$group_dset$ (trex_file, dset) bind(C)
use, intrinsic :: iso_c_binding
@ -623,7 +673,15 @@ interface
$group_dset_f_dtype$, intent(out) :: dset(*)
end function trexio_read_$group$_$group_dset$
end interface
#+end_src
#+begin_src fortran :tangle has_dset_front_fortran.f90
interface
integer function trexio_has_$group$_$group_dset$ (trex_file) bind(C)
use, intrinsic :: iso_c_binding
integer(8), intent(in), value :: trex_file
end function trexio_has_$group$_$group_dset$
end interface
#+end_src
* Back ends

View File

@ -7,12 +7,14 @@ cat populated/pop_def_hdf5.c >> trexio_hdf5.c
cat populated/pop_struct_hdf5.h >> trexio_hdf5.h
cat populated/pop_basic_hdf5.c >> trexio_hdf5.c
cat populated/pop_has_dset_hdf5.c >> trexio_hdf5.c
cat populated/pop_has_num_hdf5.c >> trexio_hdf5.c
cat populated/pop_read_dset_hdf5.c >> trexio_hdf5.c
cat populated/pop_read_num_hdf5.c >> trexio_hdf5.c
cat populated/pop_write_dset_hdf5.c >> trexio_hdf5.c
cat populated/pop_write_num_hdf5.c >> trexio_hdf5.c
cat populated/pop_rw_num_hdf5.h >> trexio_hdf5.h
cat populated/pop_rw_dset_hdf5.h >> trexio_hdf5.h
cat populated/pop_hrw_num_hdf5.h >> trexio_hdf5.h
cat populated/pop_hrw_dset_hdf5.h >> trexio_hdf5.h
cat suffix_hdf5.h >> trexio_hdf5.h

View File

@ -118,15 +118,12 @@ trexio_exit_code trexio_hdf5_init(trexio_t* const file) {
case 'r':
case 'a':
f->$group$_group = H5Gopen(f->file_id, $GROUP$_GROUP_NAME, H5P_DEFAULT);
//f->electron_group = H5Gopen(f->file_id, ELECTRON_GROUP_NAME, H5P_DEFAULT);
break;
case 'w':
f->$group$_group = H5Gcreate(f->file_id, $GROUP$_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
//f->electron_group = H5Gcreate(f->file_id, ELECTRON_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
break;
}
assert (f->$group$_group > 0L);
//assert (f->electron_group > 0L);
return TREXIO_SUCCESS;
}
@ -138,11 +135,6 @@ trexio_exit_code trexio_hdf5_finalize(trexio_t* const file) {
H5Gclose(f->$group$_group);
f->$group$_group = 0;
/*
H5Gclose(f->electron_group);
f->electron_group = 0;
*/
H5Fclose(f->file_id);
f->file_id = 0;
@ -152,10 +144,10 @@ trexio_exit_code trexio_hdf5_finalize(trexio_t* const file) {
#+end_src
** Template for HDF5 has/read/write a number
** Template for HDF5 read/write a number
#+begin_src c :tangle rw_num_hdf5.h
#+begin_src c :tangle hrw_num_hdf5.h
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);
#+end_src
@ -163,9 +155,8 @@ trexio_exit_code trexio_hdf5_write_$group_num$(trexio_t* const file, const uint6
#+begin_src c :tangle read_num_hdf5.c
trexio_exit_code trexio_hdf5_read_$group_num$ (trexio_t* const file, uint64_t* const num) {
assert (file != NULL);
assert (num != NULL);
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (num == NULL) return TREXIO_INVALID_ARG_2;
const trexio_hdf5_t* f = (const trexio_hdf5_t*) file;
/* Quit if the dimensioning attribute is missing in the file */
@ -185,9 +176,8 @@ trexio_exit_code trexio_hdf5_read_$group_num$ (trexio_t* const file, uint64_t* c
#+begin_src c :tangle write_num_hdf5.c
trexio_exit_code trexio_hdf5_write_$group_num$ (trexio_t* const file, const uint64_t num) {
assert (file != NULL);
assert (num > 0L);
if (file == NULL) return TREXIO_INVALID_ARG_1;
if (num == 0L ) return TREXIO_INVALID_ARG_2;
trexio_hdf5_t* const f = (trexio_hdf5_t*) file;
@ -251,20 +241,36 @@ trexio_exit_code trexio_hdf5_write_$group_num$ (trexio_t* const file, const uint
}
#+end_src
#+begin_src c :tangle has_num_hdf5.c
trexio_exit_code trexio_hdf5_has_$group_num$ (trexio_t* const file) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
** Template for HDF5 read/write a dataset
const trexio_hdf5_t* f = (const trexio_hdf5_t*) file;
htri_t status = H5Aexists(f->$group$_group, $GROUP_NUM$_NAME);
/* H5Aexists returns positive value if attribute exists, 0 if does not, negative if error */
if (status > 0){
return TREXIO_SUCCESS;
} else if (status == 0) {
return TREXIO_HAS_NOT;
} else {
return TREXIO_FAILURE;
}
}
#+end_src
#+begin_src c :tangle rw_dset_hdf5.h
** Template for HDF5 has/read/write a dataset
#+begin_src c :tangle hrw_dset_hdf5.h
trexio_exit_code trexio_hdf5_has_$group$_$group_dset$(trexio_t* const file);
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* const file, const $group_dset_dtype$* $group_dset$, const uint32_t rank, const uint64_t* dims);
#+end_src
#+begin_src c :tangle read_dset_hdf5.c
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 ($group_dset$ != NULL);
if (file == NULL) return TREXIO_INVALID_ARG_1;
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
const trexio_hdf5_t* f = (const trexio_hdf5_t*) file;
@ -316,9 +322,8 @@ trexio_exit_code trexio_hdf5_read_$group$_$group_dset$(trexio_t* const file, $gr
#+begin_src c :tangle write_dset_hdf5.c
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 ($group_dset$ != NULL);
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$;
@ -353,6 +358,23 @@ trexio_exit_code trexio_hdf5_write_$group$_$group_dset$(trexio_t* const file, co
}
#+end_src
#+begin_src c :tangle has_dset_hdf5.c
trexio_exit_code trexio_hdf5_has_$group$_$group_dset$(trexio_t* const file) {
if (file == NULL) return TREXIO_INVALID_ARG_1;
trexio_hdf5_t* f = (trexio_hdf5_t*) file;
herr_t status = H5LTfind_dataset(f->$group$_group, $GROUP$_$GROUP_DSET$_NAME);
/* H5LTfind_dataset returns 1 if dataset exists, 0 otherwise */
if (status == 1){
return TREXIO_SUCCESS;
} else if (status == 0) {
return TREXIO_HAS_NOT;
} else {
return TREXIO_FAILURE;
}
}
#+end_src
** Constant file suffixes (not used by generator) for HDF5 :noxport:

View File

@ -17,12 +17,14 @@ cat populated/pop_free_group_text.h >> trexio_text.h
cat populated/pop_read_group_text.h >> trexio_text.h
cat populated/pop_flush_group_text.h >> trexio_text.h
cat populated/pop_has_dset_text.c >> trexio_text.c
cat populated/pop_has_num_text.c >> trexio_text.c
cat populated/pop_read_dset_text.c >> trexio_text.c
cat populated/pop_read_num_text.c >> trexio_text.c
cat populated/pop_write_dset_text.c >> trexio_text.c
cat populated/pop_write_num_text.c >> trexio_text.c
cat populated/pop_rw_num_text.h >> trexio_text.h
cat populated/pop_rw_dset_text.h >> trexio_text.h
cat populated/pop_hrw_num_text.h >> trexio_text.h
cat populated/pop_hrw_dset_text.h >> trexio_text.h
cat rdm_text.c >> trexio_text.c
cat rdm_text.h >> trexio_text.h