1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-07-22 10:47:43 +02:00

dimension in write_dset populated properply + error handling

This commit is contained in:
q-posev 2021-03-10 11:48:43 +01:00
parent fba6c88973
commit ca234fb569
2 changed files with 19 additions and 20 deletions

View File

@ -63,24 +63,18 @@ for k,v in datasets.items():
elif v[0] == 'int':
datatype = 'int64_t'
tmp_dict['dtype'] = datatype
tmp_dict['dims'] = [dim.replace('.','_') for dim in v[1]]
tmp_dict['dims'] = [dim.replace('.','_') for dim in v[1]]
datasets_nostr[k] = tmp_dict
#print(datasets_nostr)
#print(numbers)
#print(attributes)
#print(groups)
#file_list = ['temp_trexio_hdf5.c']
file_list = []
temp_path = join(fileDir,'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_funcs_dsets = [f for f in files_funcs if 'dset' in f]
@ -120,6 +114,20 @@ for fname in files_funcs_dsets:
with open(f'{temp_path}/{fname_new}', 'a') as f_out :
for line in f_in :
if '$' in line:
if '$group_dset_dim$' in line:
rc_line = ' if (rc != TREXIO_SUCCESS) return rc;\n'
for dim in params['dims']:
if not dim.isdigit():
templine1 = line.replace('$group_dset_dim$', dim)
templine2 = templine1
if '_read' in templine2:
templine1 = rc_line
templine2 += templine1
f_out.write(templine2)
continue
templine1 = line.replace('$GROUP$_$GROUP_DSET$', dset.upper())
templine2 = templine1.replace('$group$_$group_dset$', dset)
@ -137,16 +145,6 @@ 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())
for dim in params['dims']:
if dim.isdigit():
continue
else:
print("TODO: this only populate 1 dim and not all !")
templine1 = templine2.replace('$group_dset_dim$', dim)
templine2 = templine1
f_out.write(templine2)
templine1 = templine2.replace('$group$', grname)
templine2 = templine1.replace('$GROUP$', grname.upper())

View File

@ -306,9 +306,10 @@ trexio_exit_code trexio_hdf5_write_$group$_$group_dset$(const trexio_t* file, co
assert (file != NULL);
assert ($group_dset$ != NULL);
trexio_exit_code rc;
uint64_t $group_dset_dim$;
trexio_exit_code rc = trexio_hdf5_read_$group_dset_dim$(file, &($group_dset_dim$));
if (rc != TREXIO_SUCCESS) return rc;
// error handling for rc is added by the generator
rc = trexio_hdf5_read_$group_dset_dim$(file, &($group_dset_dim$));
if ($group_dset_dim$ <= 0L) return TREXIO_INVALID_NUM;
trexio_hdf5_t* f = (trexio_hdf5_t*) file;