(vars, global_params={})
| 2445 | |
| 2446 | |
| 2447 | def get_parameters(vars, global_params={}): |
| 2448 | params = copy.copy(global_params) |
| 2449 | g_params = copy.copy(global_params) |
| 2450 | for name, func in [('kind', _kind_func), |
| 2451 | ('selected_int_kind', _selected_int_kind_func), |
| 2452 | ('selected_real_kind', _selected_real_kind_func), ]: |
| 2453 | if name not in g_params: |
| 2454 | g_params[name] = func |
| 2455 | param_names = [] |
| 2456 | for n in get_sorted_names(vars): |
| 2457 | if 'attrspec' in vars[n] and 'parameter' in vars[n]['attrspec']: |
| 2458 | param_names.append(n) |
| 2459 | kind_re = re.compile(r'\bkind\s*\(\s*(?P<value>.*)\s*\)', re.I) |
| 2460 | selected_int_kind_re = re.compile( |
| 2461 | r'\bselected_int_kind\s*\(\s*(?P<value>.*)\s*\)', re.I) |
| 2462 | selected_kind_re = re.compile( |
| 2463 | r'\bselected_(int|real)_kind\s*\(\s*(?P<value>.*)\s*\)', re.I) |
| 2464 | for n in param_names: |
| 2465 | if '=' in vars[n]: |
| 2466 | v = vars[n]['='] |
| 2467 | if islogical(vars[n]): |
| 2468 | v = v.lower() |
| 2469 | for repl in [ |
| 2470 | ('.false.', 'False'), |
| 2471 | ('.true.', 'True'), |
| 2472 | # TODO: test .eq., .neq., etc replacements. |
| 2473 | ]: |
| 2474 | v = v.replace(*repl) |
| 2475 | |
| 2476 | v = kind_re.sub(r'kind("\1")', v) |
| 2477 | v = selected_int_kind_re.sub(r'selected_int_kind(\1)', v) |
| 2478 | |
| 2479 | # We need to act according to the data. |
| 2480 | # The easy case is if the data has a kind-specifier, |
| 2481 | # then we may easily remove those specifiers. |
| 2482 | # However, it may be that the user uses other specifiers...(!) |
| 2483 | is_replaced = False |
| 2484 | |
| 2485 | if 'kindselector' in vars[n]: |
| 2486 | # Remove kind specifier (including those defined |
| 2487 | # by parameters) |
| 2488 | if 'kind' in vars[n]['kindselector']: |
| 2489 | orig_v_len = len(v) |
| 2490 | v = v.replace('_' + vars[n]['kindselector']['kind'], '') |
| 2491 | # Again, this will be true if even a single specifier |
| 2492 | # has been replaced, see comment above. |
| 2493 | is_replaced = len(v) < orig_v_len |
| 2494 | |
| 2495 | if not is_replaced: |
| 2496 | if not selected_kind_re.match(v): |
| 2497 | v_ = v.split('_') |
| 2498 | # In case there are additive parameters |
| 2499 | if len(v_) > 1: |
| 2500 | v = ''.join(v_[:-1]).lower().replace(v_[-1].lower(), '') |
| 2501 | |
| 2502 | # Currently this will not work for complex numbers. |
| 2503 | # There is missing code for extracting a complex number, |
| 2504 | # which may be defined in either of these: |
no test coverage detected
searching dependent graphs…