From c0b319a7513a8c213b95925f81d05d622141f81a Mon Sep 17 00:00:00 2001 From: q-posev Date: Wed, 10 Mar 2021 14:50:51 +0100 Subject: [PATCH] adapt generator for frontend --- src/generator.py | 57 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/src/generator.py b/src/generator.py index 9f50dfc..4255850 100644 --- a/src/generator.py +++ b/src/generator.py @@ -64,17 +64,30 @@ for k,v in datasets.items(): datatype = 'int64_t' tmp_dict['dtype'] = datatype tmp_dict['dims'] = [dim.replace('.','_') for dim in v[1]] - + tmp_dict['rank'] = len(v[1]) + dim_str = tmp_dict['dims'][0] + if tmp_dict['rank'] > 1: + for i in range(1, tmp_dict['rank']): + dim_toadd = tmp_dict['dims'][i] + dim_str += f', {dim_toadd}' + tmp_dict['dim_list'] = dim_str datasets_nostr[k] = tmp_dict -#print(datasets_nostr) +print(datasets_nostr['nucleus_coord']) #print(numbers) -temp_path = join(fileDir,'templates_hdf5') +templ_path_hdf5 = join(fileDir,'templates_hdf5') +templ_path_front = join(fileDir,'templates_front') -files_exclude = ['prefix_hdf5.c', 'prefix_hdf5.h', 'suffix_hdf5.h', 'templator_hdf5.org'] +files_exclude = ['prefix_hdf5.c', 'prefix_hdf5.h', 'suffix_hdf5.h', + 'prefix_front.c', 'prefix_front.h', 'suffix_front.h', + 'prefix_s_front.h', 'suffix_s_front.h', + 'templator_front.org', 'templator_hdf5.org'] -files = [f for f in listdir(temp_path) if isfile(join(temp_path, f)) and f not in files_exclude] +files_hdf5 = [f for f in listdir(templ_path_hdf5) if isfile(join(templ_path_hdf5, f)) and f not in files_exclude] +files_front = [f for f in listdir(templ_path_front) if isfile(join(templ_path_front, f)) and f not in files_exclude] + +files = files_hdf5 + files_front files_funcs = [f for f in files if 'read_' in f or 'write_' in f or 'rw_' in f ] files_funcs_dsets = [f for f in files_funcs if 'dset' in f] @@ -85,12 +98,16 @@ files_auxil = [f for f in files if not ('read_' in f or 'write_' in f or 'rw_' i # build files with functions for fname in files_funcs_nums: fname_new = join('populated',f'pop_{fname}') + if '_hdf5' in fname: + templ_path = templ_path_hdf5 + if '_front' in fname: + templ_path = templ_path_front + for dim in dim_variables.keys(): grname = dim.split('_')[0] - - with open(join(temp_path,fname), 'r') as f_in : - with open(join(temp_path,fname_new), 'a') as f_out : + with open(join(templ_path,fname), 'r') as f_in : + with open(join(templ_path,fname_new), 'a') as f_out : for line in f_in : if '$' in line: templine1 = line.replace('$GROUP_NUM$', dim.upper()) @@ -106,12 +123,15 @@ for fname in files_funcs_nums: # build files with functions for fname in files_funcs_dsets: fname_new = join('populated',f'pop_{fname}') + if '_hdf5' in fname: + templ_path = templ_path_hdf5 + if '_front' in fname: + templ_path = templ_path_front for dset,params in datasets_nostr.items(): grname = dset.split('_')[0] - - with open(join(temp_path,fname), 'r') as f_in : - with open(join(temp_path,fname_new), 'a') as f_out : + with open(join(templ_path,fname), 'r') as f_in : + with open(join(templ_path,fname_new), 'a') as f_out : for line in f_in : if '$' in line: @@ -145,6 +165,12 @@ 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 + + templine1 = templine2.replace('$group_dset_dim_list$', params['dim_list']) + templine2 = templine1 + templine1 = templine2.replace('$group$', grname) templine2 = templine1.replace('$GROUP$', grname.upper()) @@ -155,8 +181,13 @@ for fname in files_funcs_dsets: # build files with $group$ and $group$-based for fname in ['def_hdf5.c', 'basic_hdf5.c', 'struct_hdf5.h'] : fname_new = join('populated',f'pop_{fname}') - with open(join(temp_path,fname), 'r') as f_in : - with open(join(temp_path,fname_new), 'a') as f_out : + if '_hdf5' in fname: + templ_path = templ_path_hdf5 + if '_front' in fname: + templ_path = templ_path_front + + with open(join(templ_path,fname), 'r') as f_in : + with open(join(templ_path,fname_new), 'a') as f_out : for line in f_in : if '$group_dset$' in line or '$GROUP_DSET$' in line : for dset in datasets_nostr.keys():