From 8a02ea07e284862d25a0b8b6302e360045c5880e Mon Sep 17 00:00:00 2001 From: q-posev Date: Wed, 17 Mar 2021 15:49:43 +0100 Subject: [PATCH] fix for dset_dtype calloc and fscanf/fprintf --- src/generator.py | 19 ++++++++++++++++--- src/templates_text/templator_text.org | 8 ++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/generator.py b/src/generator.py index a5bb859..926da15 100644 --- a/src/generator.py +++ b/src/generator.py @@ -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) @@ -145,7 +145,19 @@ for fname in files_funcs_groups: continue templine1 = loop_body.replace('$group_dset$', dset) - templine2 = templine1.replace('$group$', grname) + 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 diff --git a/src/templates_text/templator_text.org b/src/templates_text/templator_text.org index ea21fab..2b934e4 100644 --- a/src/templates_text/templator_text.org +++ b/src/templates_text/templator_text.org @@ -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$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$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$group_dset$[i] = $group_dset$[i];