(vars, global_params={})
| 2478 | |
| 2479 | |
| 2480 | def get_parameters(vars, global_params={}): |
| 2481 | params = copy.copy(global_params) |
| 2482 | g_params = copy.copy(global_params) |
| 2483 | for name, func in [('kind', _kind_func), |
| 2484 | ('selected_int_kind', _selected_int_kind_func), |
| 2485 | ('selected_real_kind', _selected_real_kind_func), ]: |
| 2486 | if name not in g_params: |
| 2487 | g_params[name] = func |
| 2488 | param_names = [] |
| 2489 | for n in get_sorted_names(vars): |
| 2490 | if 'attrspec' in vars[n] and 'parameter' in vars[n]['attrspec']: |
| 2491 | param_names.append(n) |
| 2492 | kind_re = re.compile(r'\bkind\s*\(\s*(?P<value>.*)\s*\)', re.I) |
| 2493 | selected_int_kind_re = re.compile( |
| 2494 | r'\bselected_int_kind\s*\(\s*(?P<value>.*)\s*\)', re.I) |
| 2495 | selected_kind_re = re.compile( |
| 2496 | r'\bselected_(int|real)_kind\s*\(\s*(?P<value>.*)\s*\)', re.I) |
| 2497 | for n in param_names: |
| 2498 | if '=' in vars[n]: |
| 2499 | v = vars[n]['='] |
| 2500 | if islogical(vars[n]): |
| 2501 | v = v.lower() |
| 2502 | for repl in [ |
| 2503 | ('.false.', 'False'), |
| 2504 | ('.true.', 'True'), |
| 2505 | # TODO: test .eq., .neq., etc replacements. |
| 2506 | ]: |
| 2507 | v = v.replace(*repl) |
| 2508 | |
| 2509 | v = kind_re.sub(r'kind("\1")', v) |
| 2510 | v = selected_int_kind_re.sub(r'selected_int_kind(\1)', v) |
| 2511 | |
| 2512 | # We need to act according to the data. |
| 2513 | # The easy case is if the data has a kind-specifier, |
| 2514 | # then we may easily remove those specifiers. |
| 2515 | # However, it may be that the user uses other specifiers...(!) |
| 2516 | is_replaced = False |
| 2517 | |
| 2518 | if 'kindselector' in vars[n]: |
| 2519 | # Remove kind specifier (including those defined |
| 2520 | # by parameters) |
| 2521 | if 'kind' in vars[n]['kindselector']: |
| 2522 | orig_v_len = len(v) |
| 2523 | v = v.replace('_' + vars[n]['kindselector']['kind'], '') |
| 2524 | # Again, this will be true if even a single specifier |
| 2525 | # has been replaced, see comment above. |
| 2526 | is_replaced = len(v) < orig_v_len |
| 2527 | |
| 2528 | if not is_replaced: |
| 2529 | if not selected_kind_re.match(v): |
| 2530 | v_ = v.split('_') |
| 2531 | # In case there are additive parameters |
| 2532 | if len(v_) > 1: |
| 2533 | v = ''.join(v_[:-1]).lower().replace(v_[-1].lower(), '') |
| 2534 | |
| 2535 | # Currently this will not work for complex numbers. |
| 2536 | # There is missing code for extracting a complex number, |
| 2537 | # which may be defined in either of these: |
no test coverage detected