1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-12-23 04:43:57 +01:00

dummy generator for auxiliary files

This commit is contained in:
q-posev 2021-03-09 11:58:47 +01:00
parent 9b54f71f4a
commit ebc7aa5d40
2 changed files with 73 additions and 25 deletions

View File

@ -1,6 +1,9 @@
import json 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) config0 = json.load(f)
print('Metadata I/O currently not supported') print('Metadata I/O currently not supported')
@ -9,23 +12,31 @@ del config0['metadata']
config = {} config = {}
for k,v in config0.items(): for k,v in config0.items():
if k == 'nucleus' or k == 'electron': if k == 'nucleus' or k == 'ecp':
config[k] = v config[k] = v
print(config) #print(config)
groups = [group for group in config.keys()] groups = [group for group in config.keys()]
dim_variables = {} dim_variables = {}
dim_list = [] dim_list = []
dim_dict = {}
for k1,v1 in config.items(): for k1,v1 in config.items():
grname = k1
for v2 in v1.values(): for v2 in v1.values():
for dim in v2[1]: for dim in v2[1]:
if not dim.isdigit(): if not dim.isdigit():
tmp = dim.replace('.','_') tmp = dim.replace('.','_')
dim_variables[tmp] = 0 dim_variables[tmp] = 0
if dim not in dim_list: 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 = {} datasets = {}
numbers = {} numbers = {}
@ -46,30 +57,65 @@ for k,v in datasets.items():
datasets_nostr[k] = v datasets_nostr[k] = v
#print(datasets_nostr) #print(datasets_nostr)
print(numbers) #print(numbers)
#print(attributes) #print(attributes)
#print(groups) #print(groups)
file_list = ['temp_trexio_hdf5.c'] #file_list = ['temp_trexio_hdf5.c']
path = 'src/templates' file_list = []
for fname in file_list:
fname_new = fname.replace('temp_','') temp_path = 'templates_hdf5'
with open(f'{path}/{fname}', 'r') as f_in:
with open(f'{path}/{fname_new}', 'w') as f_out: files_exclude = ['prefix_hdf5.c', 'prefix_hdf5.h', 'suffix_hdf5.h', 'templator_hdf5.org']
isfunc = False
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: 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: if '$group$' in line or '$GROUP$' in line:
for group_name in config.keys(): for grname in config.keys():
templine = line.replace('$group$', f'{group_name}') templine1 = line.replace('$group$', grname)
newline = templine.replace('$GROUP$', f'{group_name.upper()}') 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: else:
f_out.write(line) f_out.write(line)

View File

@ -157,7 +157,7 @@ trexio_exit_code trexio_hdf5_write_$group_num$(const trexio_t* file, const uint6
#+end_src #+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) { trexio_exit_code trexio_hdf5_read_$group_num$const trexio_t* file, uint64_t* num) {
assert (file != NULL); 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; 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) { trexio_exit_code trexio_hdf5_write_$group_num$(const trexio_t* file, const uint64_t num) {
assert (file != NULL); 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); 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 #+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) { 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); assert (file != NULL);
@ -296,7 +298,9 @@ trexio_exit_code trexio_hdf5_read_$group$_$group_dset$(const trexio_t* file, $gr
return TREXIO_SUCCESS; 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) { 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); assert (file != NULL);
@ -330,8 +334,6 @@ trexio_exit_code trexio_hdf5_write_$group$_$group_dset$(const trexio_t* file, co
return TREXIO_SUCCESS; return TREXIO_SUCCESS;
} }
#+end_src
#+end_src #+end_src