1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2025-01-11 05:28:33 +01:00

fix for dset_dtype calloc and fscanf/fprintf

This commit is contained in:
q-posev 2021-03-17 15:49:43 +01:00
parent 6e7b9a370d
commit 8a02ea07e2
2 changed files with 20 additions and 7 deletions

View File

@ -15,8 +15,8 @@ del config0['metadata']
config = {}
for k,v in config0.items():
#if k == 'nucleus' or k == 'ecp':
if k == 'nucleus':
if k == 'nucleus' or k == 'ecp':
#if k == 'nucleus':
config[k] = v
#print(config)
@ -146,6 +146,18 @@ for fname in files_funcs_groups:
templine1 = loop_body.replace('$group_dset$', dset)
templine2 = templine1.replace('$group$', grname)
templine1 = templine2.replace('$group_dset_dtype$', params['dtype'])
templine2 = templine1
if params['dtype'] == 'double':
std_dtype = 'lf'
elif params['dtype'] == 'int64_t':
std_dtype = 'ld'
templine1 = templine2.replace('$group_dset_std_dtype$', std_dtype)
templine2 = templine1
f_out.write(templine2)
elif do_num:
#for dim in dim_variables.keys():
@ -269,6 +281,7 @@ for fname in files_funcs_dsets:
templine1 = templine2.replace('$group_dset_h5_dtype$', h5_dtype)
templine2 = templine1.replace('$group_dset_h5_dtype$'.upper(), h5_dtype.upper())
templine1 = templine2.replace('$group_dset_rank$', str(params['rank']))
templine2 = templine1

View File

@ -370,7 +370,7 @@ DEBUG
// START REPEAT GROUP_DSET
/* Allocate arrays */
$group$->$group_dset$ = (double*) calloc(size_$group_dset$, sizeof(double));
$group$->$group_dset$ = ($group_dset_dtype$*) calloc(size_$group_dset$, sizeof($group_dset_dtype$));
assert (!($group$->$group_dset$ == NULL));
if ($group$->$group_dset$ == NULL) {
FREE(buffer);
@ -393,7 +393,7 @@ DEBUG
}
for (uint64_t i=0 ; i<size_$group_dset$ ; i++) {
rc = fscanf(f, "%lf", &($group$->$group_dset$[i]));
rc = fscanf(f, "%$group_dset_std_dtype$", &($group$->$group_dset$[i]));
assert(!(rc != 1));
if (rc != 1) {
FREE(buffer);
@ -479,7 +479,7 @@ trexio_exit_code trexio_text_flush_$group$(const trexio_text_t* file) {
fprintf(f, "$group_dset$\n");
for (uint64_t i=0 ; i<size_$group_dset$ ; i++) {
fprintf(f, "%lf\n", $group$->$group_dset$[i]);
fprintf(f, "%$group_dset_std_dtype$\n", $group$->$group_dset$[i]);
}
// END REPEAT GROUP_DSET
@ -627,7 +627,7 @@ trexio_exit_code trexio_text_write_$group_dset$(const trexio_t* file, const $gro
dim_size *= dims[i];
}
$group$->$group_dset$ = (double*) calloc(dim_size, sizeof(double));
$group$->$group_dset$ = ($group_dset_dtype$*) calloc(dim_size, sizeof($group_dset_dtype$));
for (uint64_t i=0 ; i<dim_size ; i++) {
$group$->$group_dset$[i] = $group_dset$[i];