1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-07-22 18:57:39 +02:00

Merge pull request #46 from TREX-CoE/fix-int-dsets

Fix default precision of int datasets
This commit is contained in:
Evgeny Posenitskiy 2021-05-18 12:15:48 +02:00 committed by GitHub
commit f2c79827b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 35 deletions

View File

@ -707,23 +707,26 @@ end interface
example, in ~#define~ statements). More detailed description of
each variable can be found below:
| Template variable | Description | Example |
|-------------------------------+------------------------------------------------+--------------------|
| ~$group$~ | Name of the group | ~nucleus~ |
| ~$group_num$~ | Name of the dimensioning variable (scalar) | ~nucleus_num~ |
| ~$group_dset$~ | Name of the dataset (vector/matrix/tensor) | ~nucleus_coord~ |
| ~$group_dset_rank$~ | Rank of the dataset | ~2~ |
| ~$group_dset_dim$~ | Selected dimension of the dataset | ~nucleus_num~ |
| ~$group_dset_dim_list$~ | All dimensions of the dataset | ~{nucleus_num, 3}~ |
| ~$group_dset_dtype$~ | Basic type of the dataset (int/float/char) | ~float~ |
| ~$group_dset_h5_dtype$~ | Type of the dataset in HDF5 | ~double~ |
| ~$group_dset_std_dtype_in$~ | Input type of the dataset in TEXT [fscanf] | ~%lf~ |
| ~$group_dset_std_dtype_out$~ | Output type of the dataset in TEXT [fprintf] | ~%24.16e~ |
| ~$group_dset_dtype_single$~ | Single precision type of the dataset [C] | ~float~ |
| ~$group_dset_dtype_double$~ | Double precision type of the dataset [C] | ~double~ |
| ~$group_dset_f_dtype_single$~ | Single precision type of the dataset [Fortran] | ~real(4)~ |
| ~$group_dset_f_dtype_double$~ | Double precision type of the dataset [Fortran] | ~real(8)~ |
| ~$group_dset_f_dims$~ | Dimensions in Fortran | ~(:,:)~ |
| Template variable | Description | Example |
|--------------------------------+-----------------------------------------------------+----------------------|
| ~$group$~ | Name of the group | ~nucleus~ |
| ~$group_num$~ | Name of the dimensioning variable (scalar) | ~nucleus_num~ |
| ~$group_dset$~ | Name of the dataset (vector/matrix/tensor) | ~nucleus_coord~ |
| ~$group_dset_rank$~ | Rank of the dataset | ~2~ |
| ~$group_dset_dim$~ | Selected dimension of the dataset | ~nucleus_num~ |
| ~$group_dset_dim_list$~ | All dimensions of the dataset | ~{nucleus_num, 3}~ |
| ~$group_dset_dtype$~ | Basic type of the dataset (int/float/char) | ~float~ |
| ~$group_dset_h5_dtype$~ | Type of the dataset in HDF5 | ~double~ |
| ~$group_dset_std_dtype_in$~ | Input type of the dataset in TEXT [fscanf] | ~%lf~ |
| ~$group_dset_std_dtype_out$~ | Output type of the dataset in TEXT [fprintf] | ~%24.16e~ |
| ~$group_dset_dtype_default$~ | Default datatype of the dataset [C] | ~double/int32_t~ |
| ~$group_dset_dtype_single$~ | Single precision datatype of the dataset [C] | ~float/int32_t~ |
| ~$group_dset_dtype_double$~ | Double precision datatype of the dataset [C] | ~double/int64_t~ |
| ~$default_prec$~ | Default precision for read/write without suffix [C] | ~64/32~ |
| ~$group_dset_f_dtype_default$~ | Default datatype of the dataset [Fortran] | ~real(8)/integer(4)~ |
| ~$group_dset_f_dtype_single$~ | Single precision datatype of the dataset [Fortran] | ~real(4)/integer(4)~ |
| ~$group_dset_f_dtype_double$~ | Double precision datatype of the dataset [Fortran] | ~real(8)/integer(8)~ |
| ~$group_dset_f_dims$~ | Dimensions in Fortran | ~(:,:)~ |
Note: parent group name is always added to the child objects upon
@ -1047,8 +1050,8 @@ end interface
#+begin_src c :tangle hrw_dset_front.h :exports none
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_double$* const $group_dset$);
trexio_exit_code trexio_write_$group$_$group_dset$(trexio_t* const file, const $group_dset_dtype_double$* $group_dset$);
trexio_exit_code trexio_read_$group$_$group_dset$(trexio_t* const file, $group_dset_dtype_default$* const $group_dset$);
trexio_exit_code trexio_write_$group$_$group_dset$(trexio_t* const file, const $group_dset_dtype_default$* $group_dset$);
trexio_exit_code trexio_read_$group$_$group_dset$_32(trexio_t* const file, $group_dset_dtype_single$* const $group_dset$);
trexio_exit_code trexio_write_$group$_$group_dset$_32(trexio_t* const file, const $group_dset_dtype_single$* $group_dset$);
trexio_exit_code trexio_read_$group$_$group_dset$_64(trexio_t* const file, $group_dset_dtype_double$* const $group_dset$);
@ -1252,17 +1255,17 @@ trexio_write_$group$_$group_dset$_32 (trexio_t* const file, const $group_dset_dt
#+begin_src c :tangle read_dset_def_front.c
trexio_exit_code
trexio_read_$group$_$group_dset$ (trexio_t* const file, $group_dset_dtype_double$* const $group_dset$)
trexio_read_$group$_$group_dset$ (trexio_t* const file, $group_dset_dtype_default$* const $group_dset$)
{
return trexio_read_$group$_$group_dset$_64(file, $group_dset$);
return trexio_read_$group$_$group_dset$_$default_prec$(file, $group_dset$);
}
#+end_src
#+begin_src c :tangle write_dset_def_front.c
trexio_exit_code
trexio_write_$group$_$group_dset$ (trexio_t* const file, const $group_dset_dtype_double$* $group_dset$)
trexio_write_$group$_$group_dset$ (trexio_t* const file, const $group_dset_dtype_default$* $group_dset$)
{
return trexio_write_$group$_$group_dset$_64(file, $group_dset$);
return trexio_write_$group$_$group_dset$_$default_prec$(file, $group_dset$);
}
#+end_src
@ -1343,7 +1346,7 @@ interface
integer function trexio_write_$group$_$group_dset$ (trex_file, dset) bind(C)
use, intrinsic :: iso_c_binding
integer(8), intent(in), value :: trex_file
$group_dset_f_dtype_double$, intent(in) :: dset$group_dset_f_dims$
$group_dset_f_dtype_default$, intent(in) :: dset$group_dset_f_dims$
end function trexio_write_$group$_$group_dset$
end interface
#+end_src
@ -1353,7 +1356,7 @@ interface
integer function trexio_read_$group$_$group_dset$ (trex_file, dset) bind(C)
use, intrinsic :: iso_c_binding
integer(8), intent(in), value :: trex_file
$group_dset_f_dtype_double$, intent(out) :: dset$group_dset_f_dims$
$group_dset_f_dtype_default$, intent(out) :: dset$group_dset_f_dims$
end function trexio_read_$group$_$group_dset$
end interface
#+end_src

View File

@ -145,10 +145,6 @@ trexio_text_init (trexio_t* const file)
char file_name[TREXIO_MAX_FILENAME_LENGTH];
if (file_name == NULL) {
return TREXIO_ALLOCATION_FAILED;
}
strncpy (file_name, file->file_name, TREXIO_MAX_FILENAME_LENGTH);
strncat (file_name, lock_file_name, TREXIO_MAX_FILENAME_LENGTH-strlen(lock_file_name));
@ -273,11 +269,6 @@ trexio_text_read_$group$ (trexio_text_t* const file)
/* Build the file name */
const char* $group$_file_name = "/$group$.txt";
if ($group$->file_name == NULL) {
FREE($group$);
return NULL;
}
strncpy ($group$->file_name, file->parent.file_name, TREXIO_MAX_FILENAME_LENGTH);
strncat ($group$->file_name, $group$_file_name,
TREXIO_MAX_FILENAME_LENGTH-strlen($group$_file_name));

View File

@ -281,18 +281,24 @@ for fname in files_funcs_dsets:
templine2 = templine1
if params['dtype'] == 'double':
h5_dtype = 'double'
h5_dtype = 'double'
f_dtype_default= 'real(8)'
f_dtype_double = 'real(8)'
f_dtype_single = 'real(4)'
c_dtype_default= 'double'
c_dtype_double = 'double'
c_dtype_single = 'float'
default_prec = '64'
elif params['dtype'] == 'int64_t':
h5_dtype = 'int64'
f_dtype_default= 'integer(4)'
f_dtype_double = 'integer(8)'
f_dtype_single = 'integer(4)'
c_dtype_default= 'int32_t'
c_dtype_double = 'int64_t'
c_dtype_single = 'int32_t'
default_prec = '32'
templine1 = templine2.replace('$group_dset_dtype_double$', c_dtype_double)
templine2 = templine1.replace('$group_dset_dtype_single$', c_dtype_single)
@ -303,6 +309,12 @@ for fname in files_funcs_dsets:
templine1 = templine2.replace('$group_dset_f_dtype_double$', f_dtype_double)
templine2 = templine1.replace('$group_dset_f_dtype_single$', f_dtype_single)
templine1 = templine2.replace('$group_dset_f_dtype_default$', f_dtype_default)
templine2 = templine1.replace('$group_dset_dtype_default$', c_dtype_default)
templine1 = templine2.replace('$default_prec$', default_prec)
templine2 = templine1
templine1 = templine2.replace('$group_dset_rank$', str(params['rank']))
templine2 = templine1