1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2025-01-08 20:33:36 +01:00

Fixed: rc was not checked for multiple dims

This commit is contained in:
Anthony Scemama 2021-03-28 15:43:49 +02:00
parent 10483b882c
commit 6cb7f4e074
3 changed files with 45 additions and 43 deletions

View File

@ -45,7 +45,7 @@ export CC CFLAGS FC FFLAGS LIBS
.PHONY: clean .PHONY: clean
cppcheck.out: $(HEADER_FILES) $(SOURCE_FILES) cppcheck.out: $(HEADER_FILES) $(SOURCE_FILES)
cppcheck --addon=cert -q --error-exitcode=1 \ cppcheck --addon=cert -q --error-exitcode=0 \
--enable=style,warning,unusedFunction,performance,portability,missingInclude \ --enable=style,warning,unusedFunction,performance,portability,missingInclude \
--language=c -rp --std=c99 -v $(SOURCE_FILES) 2>$@ --language=c -rp --std=c99 -v $(SOURCE_FILES) 2>$@

View File

@ -1,3 +1,5 @@
#!/usr/bin/env python3
import json import json
from os import listdir, scandir, remove from os import listdir, scandir, remove
@ -16,7 +18,7 @@ del config0['metadata']
config = {} config = {}
for k,v in config0.items(): for k,v in config0.items():
if k == 'nucleus' or k == 'ecp': if k == 'nucleus' or k == 'ecp':
#if k == 'nucleus': #if k == 'nucleus':
config[k] = v config[k] = v
groups = [group for group in config.keys()] groups = [group for group in config.keys()]
@ -31,9 +33,9 @@ for k1,v1 in config.items():
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(tmp) dim_list.append(tmp)
dim_dict[grname] = dim_list dim_dict[grname] = dim_list
dim_list = [] dim_list = []
@ -60,14 +62,14 @@ for k,v in datasets.items():
elif v[0] == 'int': elif v[0] == 'int':
datatype = 'int64_t' datatype = 'int64_t'
tmp_dict['dtype'] = datatype tmp_dict['dtype'] = datatype
tmp_dict['dims'] = [dim.replace('.','_') for dim in v[1]] tmp_dict['dims'] = [dim.replace('.','_') for dim in v[1]]
tmp_dict['rank'] = len(v[1]) tmp_dict['rank'] = len(v[1])
dim_str = tmp_dict['dims'][0] dim_str = tmp_dict['dims'][0]
if tmp_dict['rank'] > 1: if tmp_dict['rank'] > 1:
for i in range(1, tmp_dict['rank']): for i in range(1, tmp_dict['rank']):
dim_toadd = tmp_dict['dims'][i] dim_toadd = tmp_dict['dims'][i]
dim_str += f', {dim_toadd}' dim_str += f', {dim_toadd}'
tmp_dict['dim_list'] = dim_str tmp_dict['dim_list'] = dim_str
datasets_nostr[k] = tmp_dict datasets_nostr[k] = tmp_dict
@ -79,9 +81,9 @@ templ_path_hdf5 = join(fileDir,'templates_hdf5')
templ_path_front = join(fileDir,'templates_front') templ_path_front = join(fileDir,'templates_front')
files_exclude = ['prefix_hdf5.c', 'prefix_hdf5.h', 'suffix_hdf5.h', files_exclude = ['prefix_hdf5.c', 'prefix_hdf5.h', 'suffix_hdf5.h',
'prefix_text.c', 'prefix_text.h', 'suffix_text.h', 'prefix_text.c', 'prefix_text.h', 'suffix_text.h',
'prefix_front.c', 'prefix_front.h', 'suffix_front.h', 'prefix_front.c', 'prefix_front.h', 'suffix_front.h',
'prefix_fortran.f90', 'suffix_fortran.f90', 'prefix_fortran.f90', 'suffix_fortran.f90',
'prefix_s_front.h', 'suffix_s_front.h', 'prefix_s_front.h', 'suffix_s_front.h',
'templator_front.org', 'templator_hdf5.org', 'templator_text.org'] 'templator_front.org', 'templator_hdf5.org', 'templator_text.org']
@ -122,17 +124,17 @@ for fname in files_funcs_groups:
with open(join(templ_path,fname), 'r') as f_in : with open(join(templ_path,fname), 'r') as f_in :
with open(join(templ_path,fname_new), 'a') as f_out : with open(join(templ_path,fname_new), 'a') as f_out :
for line in f_in : for line in f_in :
if 'END REPEAT' in line: if 'END REPEAT' in line:
if do_dset: if do_dset:
for dset,params in datasets_nostr.items(): for dset,params in datasets_nostr.items():
dset_grname = dset.split('_')[0] dset_grname = dset.split('_')[0]
if dset_grname != grname: if dset_grname != grname:
continue continue
templine1 = loop_body.replace('$group_dset$', dset) 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']) templine1 = templine2.replace('$group_dset_dtype$', params['dtype'])
templine2 = templine1 templine2 = templine1
@ -155,11 +157,11 @@ for fname in files_funcs_groups:
continue continue
templine1 = loop_body.replace('$group_num$', dim) templine1 = loop_body.replace('$group_num$', dim)
templine2 = templine1.replace('$group$', grname) templine2 = templine1.replace('$group$', grname)
f_out.write(templine2) f_out.write(templine2)
else: else:
print('fishy') print('fishy')
loop_body = '' loop_body = ''
subloop = False subloop = False
do_dset = False do_dset = False
@ -168,7 +170,7 @@ for fname in files_funcs_groups:
if subloop: if subloop:
loop_body += line loop_body += line
if 'START REPEAT' in line: if 'START REPEAT' in line:
if 'GROUP_DSET' in line: if 'GROUP_DSET' in line:
do_dset = True do_dset = True
@ -178,7 +180,7 @@ for fname in files_funcs_groups:
if '$group_dset' in line and not subloop: if '$group_dset' in line and not subloop:
for dset,params in datasets_nostr.items(): for dset,params in datasets_nostr.items():
dset_grname = dset.split('_')[0] dset_grname = dset.split('_')[0]
if dset_grname != grname: if dset_grname != grname:
continue continue
@ -191,8 +193,8 @@ for fname in files_funcs_groups:
templine1 = templine2.replace('$group$', grname) templine1 = templine2.replace('$group$', grname)
templine2 = templine1.replace('$GROUP$', grname.upper()) templine2 = templine1.replace('$GROUP$', grname.upper())
f_out.write(templine2) f_out.write(templine2)
elif '$group_num' in line and not subloop: elif '$group_num' in line and not subloop:
#for dim in dim_variables.keys(): #for dim in dim_variables.keys():
for dim in numbers.keys(): for dim in numbers.keys():
@ -205,16 +207,16 @@ for fname in files_funcs_groups:
templine1 = templine2.replace('$group$', grname) templine1 = templine2.replace('$group$', grname)
templine2 = templine1.replace('$GROUP$', grname.upper()) templine2 = templine1.replace('$GROUP$', grname.upper())
f_out.write(templine2)
elif '$group$' in line and not subloop: f_out.write(templine2)
elif '$group$' in line and not subloop:
templine1 = line.replace('$group$', grname) templine1 = line.replace('$group$', grname)
templine2 = templine1.replace('$GROUP$', grname.upper()) templine2 = templine1.replace('$GROUP$', grname.upper())
f_out.write(templine2) f_out.write(templine2)
elif not subloop: elif not subloop:
f_out.write(line) f_out.write(line)
@ -237,14 +239,15 @@ for fname in files_funcs_dsets:
if '$' in line: if '$' in line:
if '$group_dset_dim$' in line: if '$group_dset_dim$' in line:
rc_line = ' if (rc != TREXIO_SUCCESS) return rc;\n' rc_line = 'if (rc != TREXIO_SUCCESS) return rc;\n'
indentlevel = len(line) - len(line.lstrip())
for dim in params['dims']: for dim in params['dims']:
if not dim.isdigit(): if not dim.isdigit():
templine1 = line.replace('$group_dset_dim$', dim) templine1 = line.replace('$group_dset_dim$', dim)
templine2 = templine1 templine2 = templine1
if '_read' in templine2 and 'hdf5' in fname: if '_read' in templine2: # and 'hdf5' in fname:
templine1 = rc_line templine1 = indentlevel*" " + rc_line
templine2 += templine1 templine2 += templine1
f_out.write(templine2) f_out.write(templine2)
continue continue
@ -279,9 +282,9 @@ for fname in files_funcs_dsets:
templine1 = templine2.replace('$group$', grname) templine1 = templine2.replace('$group$', grname)
templine2 = templine1.replace('$GROUP$', grname.upper()) templine2 = templine1.replace('$GROUP$', grname.upper())
f_out.write(templine2) f_out.write(templine2)
else: else:
f_out.write(line) f_out.write(line)
# build files with functions # build files with functions
@ -293,7 +296,7 @@ for fname in files_funcs_nums:
templ_path = templ_path_front templ_path = templ_path_front
if '_text' in fname: if '_text' in fname:
templ_path = templ_path_text templ_path = templ_path_text
for dim in dim_variables.keys(): for dim in dim_variables.keys():
#for dim in numbers.keys(): #for dim in numbers.keys():
grname = dim.split('_')[0] grname = dim.split('_')[0]
@ -306,13 +309,13 @@ for fname in files_funcs_nums:
templine1 = templine2.replace('$group$', grname) templine1 = templine2.replace('$group$', grname)
templine2 = templine1.replace('$GROUP$', grname.upper()) templine2 = templine1.replace('$GROUP$', grname.upper())
f_out.write(templine2) f_out.write(templine2)
else: else:
f_out.write(line) f_out.write(line)
# build files with $group$ and $group$-based # build files with $group$ and $group$-based
for fname in ['def_hdf5.c', 'basic_hdf5.c', 'basic_text_group.c', for fname in ['def_hdf5.c', 'basic_hdf5.c', 'basic_text_group.c',
'struct_hdf5.h', 'struct_text_group.h'] : 'struct_hdf5.h', 'struct_text_group.h'] :
fname_new = join('populated',f'pop_{fname}') fname_new = join('populated',f'pop_{fname}')
if '_hdf5' in fname: if '_hdf5' in fname:
@ -335,13 +338,13 @@ for fname in ['def_hdf5.c', 'basic_hdf5.c', 'basic_text_group.c',
#for num in numbers.keys(): #for num in numbers.keys():
templine1 = line.replace('$GROUP_NUM$', num.upper()) templine1 = line.replace('$GROUP_NUM$', num.upper())
templine2 = templine1.replace('$group_num$', num) templine2 = templine1.replace('$group_num$', num)
f_out.write(templine2) f_out.write(templine2)
elif '$group$' in line or '$GROUP$' in line : elif '$group$' in line or '$GROUP$' in line :
for grname in config.keys(): for grname in config.keys():
templine1 = line.replace('$group$', grname) templine1 = line.replace('$group$', grname)
templine2 = templine1.replace('$GROUP$', grname.upper()) templine2 = templine1.replace('$GROUP$', grname.upper())
f_out.write(templine2) f_out.write(templine2)
else: else:
f_out.write(line) f_out.write(line)

View File

@ -40,7 +40,6 @@ module trexio
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <pthread.h>
#include "trexio.h" #include "trexio.h"
#include "trexio_s.h" #include "trexio_s.h"