From ebc7aa5d40c7de5d419a0d3472b42db2512bc130 Mon Sep 17 00:00:00 2001 From: q-posev Date: Tue, 9 Mar 2021 11:58:47 +0100 Subject: [PATCH] dummy generator for auxiliary files --- src/generator.py | 88 ++++++++++++++++++++------- src/templates_hdf5/templator_hdf5.org | 10 +-- 2 files changed, 73 insertions(+), 25 deletions(-) diff --git a/src/generator.py b/src/generator.py index 1016b90..17f99c2 100644 --- a/src/generator.py +++ b/src/generator.py @@ -1,6 +1,9 @@ import json -with open('trex.json', 'r') as f: +from os import listdir +from os.path import isfile, join + +with open('../trex.json', 'r') as f: config0 = json.load(f) print('Metadata I/O currently not supported') @@ -9,23 +12,31 @@ del config0['metadata'] config = {} for k,v in config0.items(): - if k == 'nucleus' or k == 'electron': + if k == 'nucleus' or k == 'ecp': config[k] = v -print(config) +#print(config) groups = [group for group in config.keys()] dim_variables = {} dim_list = [] +dim_dict = {} for k1,v1 in config.items(): + grname = k1 for v2 in v1.values(): for dim in v2[1]: if not dim.isdigit(): tmp = dim.replace('.','_') dim_variables[tmp] = 0 if dim not in dim_list: - dim_list.append(dim) + dim_list.append(tmp) + + dim_dict[grname] = dim_list + dim_list = [] + +print(dim_variables) +#print(dim_dict) datasets = {} numbers = {} @@ -46,30 +57,65 @@ for k,v in datasets.items(): datasets_nostr[k] = v #print(datasets_nostr) -print(numbers) +#print(numbers) #print(attributes) #print(groups) -file_list = ['temp_trexio_hdf5.c'] -path = 'src/templates' -for fname in file_list: - fname_new = fname.replace('temp_','') - with open(f'{path}/{fname}', 'r') as f_in: - with open(f'{path}/{fname_new}', 'w') as f_out: - isfunc = False +#file_list = ['temp_trexio_hdf5.c'] +file_list = [] + +temp_path = 'templates_hdf5' + +files_exclude = ['prefix_hdf5.c', 'prefix_hdf5.h', 'suffix_hdf5.h', 'templator_hdf5.org'] + +files = [f for f in listdir(temp_path) if isfile(join(temp_path, f)) and f not in files_exclude] +#print(files) + +files_funcs = [f for f in files if '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 'rw_' in f)] +print(files_auxil) + +# build files with $group$ only +for fname in ['basic_hdf5.c', 'struct_hdf5.h']: + fname_new = 'populated/pop_' + fname + with open(f'{temp_path}/{fname}', 'r') as f_in: + with open(f'{temp_path}/{fname_new}', 'w') as f_out: for line in f_in: - if '$group$' in line and 'hdf5' in line: - # probably a good function criterion - isfunc = True - - if '$group$' in line or '$GROUP$' in line: - for group_name in config.keys(): - templine = line.replace('$group$', f'{group_name}') - newline = templine.replace('$GROUP$', f'{group_name.upper()}') + for grname in config.keys(): + templine1 = line.replace('$group$', grname) + templine2 = templine1.replace('$GROUP$', grname.upper()) + #templine1 = templine2.replace('$GROUP_NUM$', dim.upper()) + #templine2 = templine1.replace('$group_num$', dim) + #templine1 = templine2.replace('$GROUP_DSET$', '') + #templine2 = templine1.replace('$group_dset$', '') - f_out.write(newline) + f_out.write(templine2) + else: + f_out.write(line) + +# build files with $group$ and $group$-based +for fname in ['def_hdf5.c'] : + fname_new = 'populated/pop_' + fname + with open(f'{temp_path}/{fname}', 'r') as f_in : + with open(f'{temp_path}/{fname_new}', 'w') as f_out : + for line in f_in : + if '$group_dset$' in line or '$GROUP_DSET$' in line : + for dset in datasets_nostr.keys(): + templine1 = line.replace('$GROUP$_$GROUP_DSET$', dset.upper()) + templine2 = templine1.replace('$group_dset$', dset) + f_out.write(templine2) + elif '$group_num$' in line or '$GROUP_NUM$' in line : + for num in dim_variables.keys(): + templine1 = line.replace('$GROUP_NUM$', num.upper()) + templine2 = templine1.replace('$group_num$', num) + f_out.write(templine2) + elif '$group$' in line or '$GROUP$' in line : + for grname in config.keys(): + templine1 = line.replace('$group$', grname) + templine2 = templine1.replace('$GROUP$', grname.upper()) + f_out.write(templine2) else: f_out.write(line) diff --git a/src/templates_hdf5/templator_hdf5.org b/src/templates_hdf5/templator_hdf5.org index 6ee1e15..1b28668 100644 --- a/src/templates_hdf5/templator_hdf5.org +++ b/src/templates_hdf5/templator_hdf5.org @@ -157,7 +157,7 @@ trexio_exit_code trexio_hdf5_write_$group_num$(const trexio_t* file, const uint6 #+end_src - #+begin_src c :tangle rw_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) { assert (file != NULL); @@ -176,8 +176,10 @@ trexio_exit_code trexio_hdf5_read_$group_num$const trexio_t* file, uint64_t* num return TREXIO_SUCCESS; } + #+end_src + #+begin_src c :tangle write_num_hdf5.c trexio_exit_code trexio_hdf5_write_$group_num$(const trexio_t* file, const uint64_t num) { assert (file != NULL); @@ -244,7 +246,7 @@ trexio_exit_code trexio_hdf5_read_$group$_$group_dset$(const trexio_t* file, dou trexio_exit_code trexio_hdf5_write_$group$_$group_dset$(const trexio_t* file, const double* $group_dset$, const uint32_t rank, const uint64_t* dims); #+end_src - #+begin_src c :tangle rw_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) { assert (file != NULL); @@ -296,7 +298,9 @@ trexio_exit_code trexio_hdf5_read_$group$_$group_dset$(const trexio_t* file, $gr return TREXIO_SUCCESS; } + #+end_src + #+begin_src c :tangle write_dset_hdf5.c trexio_exit_code trexio_hdf5_write_$group$_$group_dset$(const trexio_t* file, const $group_dset_dtype$* $group_dset$, const uint32_t rank, const uint64_t* dims) { assert (file != NULL); @@ -330,8 +334,6 @@ trexio_exit_code trexio_hdf5_write_$group$_$group_dset$(const trexio_t* file, co return TREXIO_SUCCESS; } - - #+end_src #+end_src