def convpar(p):
if '<STR_LIT>' not in p:<EOL><INDENT>return p<EOL><DEDENT>els = p['<STR_LIT>']<EOL>nel = len(els)<EOL>q = { }<EOL>for name, values in p.items():<EOL><INDENT>if isinstance(values, dict):<EOL><INDENT>m = <NUM_LIT:0><EOL>for itype, value in values:<EOL><INDENT>if itype[<NUM_LIT:0>] == '<STR_LIT:_>':<EOL><INDENT>continue<EOL><DEDENT>syms = string2symbols(itype)<EOL>nums = [ els.index(sym) for sym in syms ]<EOL>m = max(m, nums)<EOL><DEDENT>default = <NUM_LIT:0.0><EOL>if '<STR_LIT>' in values:<EOL><INDENT>default = values['<STR_LIT>']<EOL><DEDENT>if m == <NUM_LIT:2>:<EOL><INDENT>new_values = [ default ]*pair_index(nel,nel,nel)<EOL><DEDENT>elif m == <NUM_LIT:3>:<EOL><INDENT>new_values = [ default ]*triplet_index(nel,nel,nel,nel)<EOL><DEDENT>else:<EOL><INDENT>raise RuntimeError("<STR_LIT>""<STR_LIT>""<STR_LIT>" % ( name, nel ))<EOL><DEDENT>for itype, value in values:<EOL><INDENT>if itype[<NUM_LIT:0>] == '<STR_LIT:_>':<EOL><INDENT>continue<EOL><DEDENT>syms = string2symbols(itype)<EOL>nums = [ els.index(sym) for sym in syms ]<EOL>if len(nums) == m:<EOL><INDENT>if m == <NUM_LIT:2>:<EOL><INDENT>i,j = nums<EOL>new_values[pair_index(i,j,nel)] = value<EOL><DEDENT>elif m == <NUM_LIT:3>:<EOL><INDENT>i,j,k = nums<EOL>new_values[triple_index(i,j,k,nel)] = value<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if m == <NUM_LIT:3> and len(nums) == <NUM_LIT:1>:<EOL><INDENT>[k] = nums<EOL>for i in range(nel):<EOL><INDENT>for j in range(nel):<EOL><INDENT>new_values[triple_index(i,j,k,nel)] = value<EOL>new_values[triple_index(i,k,j,nel)] = value<EOL>new_values[triple_index(k,j,i,nel)] = value<EOL>new_values[triple_index(j,k,i,nel)] = value<EOL>new_values[triple_index(k,i,j,nel)] = value<EOL>new_values[triple_index(i,j,k,nel)] = value<EOL><DEDENT><DEDENT><DEDENT>elif m == <NUM_LIT:3> and len(nums) == <NUM_LIT:2>:<EOL><INDENT>[i,j] = nums<EOL>for k in range(nel):<EOL><INDENT>new_values[triple_index(i,j,k,nel)] = value<EOL>new_values[triple_index(i,k,j,nel)] = value<EOL>new_values[triple_index(k,j,i,nel)] = value<EOL>new_values[triple_index(j,k,i,nel)] = value<EOL>new_values[triple_index(k,i,j,nel)] = value<EOL>new_values[triple_index(i,j,k,nel)] = value<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise RuntimeError("<STR_LIT>""<STR_LIT>""<STR_LIT>""<STR_LIT>"% ( name, nel, len(nums) ))<EOL><DEDENT><DEDENT><DEDENT>values = new_values<EOL><DEDENT>q[name] = values<EOL><DEDENT>return q<EOL>
Convert a parameter set from convenient Python dictionary to the format
expected by the Fortran kernels.