UtilsRPE
AutoRPE.UtilsRPE.ImplementRPE
- class AutoRPE.UtilsRPE.ImplementRPE.ImplementRPE(path_to_input_sources: str, path_to_output_sources: str, blacklist: list[str], extension='.f90')[source]
Bases:
objectA class to implement the Reduced Precision Emulator (RPE) for Fortran source code.
This class facilitates modifying Fortran source files to use reduced precision emulation, making necessary adjustments to variable declarations, function and subroutine calls, interfaces, and more. It also integrates a vault for managing metadata about the code, such as variables, subprograms, and modules.
- output_path
The directory where modified sources will be saved.
- Type:
str
- blacklist
List of filenames or modules to exclude from modification.
- Type:
list
- vault
A database-like object containing detailed information about the code structure and dependencies.
- Type:
Vault
- fix_derived_type_constructor(module: <module 'AutoRPE.UtilsRPE.Classes.Module' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Module.py'>)[source]
Adjusts calls to derived type constructors in the given module to be compatible with RPE.
This method ensures that arguments passed to derived type constructors match the expected type, performing conversions if necessary.
- Parameters:
module – The module object containing the lines of source code to modify.
- fix_interfaces()[source]
Fixes indistinguishable interfaces by resolving conflicts caused by substituting sp/dp real types with rpe_var.
This ensures that module procedures are properly updated to match the expected interfaces.
- fix_intrinsic_functions(module: <module 'AutoRPE.UtilsRPE.Classes.Module' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Module.py'>)[source]
Adjusts calls to intrinsic functions in the given module to handle RPE variables.
This involves identifying intrinsic function calls, determining whether their arguments are RPE variables, and applying the appropriate transformations to ensure compatibility.
- Parameters:
module (Module) – The module object containing the lines of source code to modify.
- fix_parameter_declaration(module: <module 'AutoRPE.UtilsRPE.Classes.Module' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Module.py'>)[source]
Adjusts parameter declarations in a module to comply with RPE requirements.
This includes converting parameter declarations with assignments to use the RPE constructor where necessary.
- Parameters:
module (Module) – The module object containing the lines of source code to modify.
- fix_pointer_assignations(module: <module 'AutoRPE.UtilsRPE.Classes.Module' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Module.py'>)[source]
Adjusts pointer assignments in the given module to be compatible with RPE variables.
This method ensures that assignments between pointers and targets of different types (e.g., rpe_var and standard types) are handled correctly.
- Parameters:
module (Module) – The module object containing the lines of source code to modify.
- fix_pure_functions(module: <module 'AutoRPE.UtilsRPE.Classes.Module' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Module.py'>)[source]
Removes the pure attribute from function declarations in a given module.
- Parameters:
module (Module) – The module object containing the lines of source code to modify.
- fix_read_and_write_calls(module: <module 'AutoRPE.UtilsRPE.Classes.Module' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Module.py'>)[source]
Adjusts read and write calls in a module to handle RPE variables correctly.
- Parameters:
module (Module) – The module object containing the lines of source code to modify.
- fix_sources()[source]
Applies a series of fixes to the source files to integrate RPE.
This includes adjusting parameter declarations, function and subroutine calls, read/write statements, interfaces, and pointer assignments to ensure compatibility with RPE.
- fix_subprogram_calls()[source]
Ensures consistency between subprogram calls and their arguments.
This includes adjusting arguments passed to subprograms based on their expected types and modifying the calls as needed.
- get_assignation_real_part(procedure: <module 'AutoRPE.UtilsRPE.Classes.Procedure' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Procedure.py'>, argument: str, type_of_exception: str)[source]
Extracts the real part of an RPE variable or expression during an assignment.
- Parameters:
procedure – The procedure containing the assignment.
argument – The argument being assigned.
line – The source code line containing the assignment.
type_of_exception – The type of special handling needed for the assignment (e.g., intrinsic, operation, etc.).
- Returns:
The modified assignment string with the real part extracted.
- Return type:
str
- get_intrinsic_real_part(string: str, procedure: <module 'AutoRPE.UtilsRPE.Classes.Procedure' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Procedure.py'>)[source]
Adjusts the arguments of intrinsic function calls to handle RPE variables.
This method ensures that RPE variables used as arguments in intrinsic functions have their real parts correctly referenced.
- Parameters:
string – The intrinsic function call as a string.
procedure – The procedure where the function call is defined.
- Returns:
The modified function call with the real parts of RPE variables substituted.
- Return type:
str
- get_operation_real_part(argument: str, procedure: <module 'AutoRPE.UtilsRPE.Classes.Procedure' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Procedure.py'>)[source]
Extracts the real parts of RPE variables involved in an operation.
This method processes operations containing RPE variables and ensures that their real parts are correctly referenced.
- Parameters:
argument (str) – The expression containing the operation.
procedure (Procedure) – The procedure where the operation is defined.
- Returns:
The operation with the real parts of RPE variables substituted.
- Return type:
str
- replace_real_with_RPE_declaration()[source]
Replaces declarations of real variables with RPE variables in the source files.
This method identifies real variable declarations and ensures they are converted to type(rpe_var) where applicable. It also propagates changes to dependent variables while considering constraints such as module blacklists and variable usage in external subprograms.
- AutoRPE.UtilsRPE.ImplementRPE.Implement_RPE(path_to_input_sources: str, path_to_output_sources: str, blacklist: list[str]) ImplementRPE.vault[source]
Implements the Reduced Precision Emulator (RPE) for the source code located in path_to_input_sources and stores the modified sources in path_to_output_sources. Additionally, a database (referred to as vault) is created to store detailed information about the source code, including functions, subroutines, modules, variables and their precisions, and all corresponding dependencies.
- Parameters:
path_to_input_sources – The directory of the original pre-processed sources.
path_to_output_sources – The directory where modified sources will be saved.
blacklist – list of files that should not be modified by the tool.
- Returns:
Database with all the information of the code.
- Return type:
Vault
AutoRPE.UtilsRPE.AttributeParser
- AutoRPE.UtilsRPE.AttributeParser.attribute_dimension(attributes: list[str], variable: str)[source]
Returns the dimension of the variable from a list of attributes.
- Parameters:
attributes (list[str]) – A list of attribute strings.
variable (str) – The variable string to analyze for dimensions.
- Returns:
The number of dimensions of the variable.
- Return type:
int
- AutoRPE.UtilsRPE.AttributeParser.attribute_intent(attributes: list[str])[source]
Returns the intent of a variable from its attributes. Defaults to ‘inout’.
- Parameters:
attributes (list[str]) – A list of attribute strings.
- Returns:
The intent of the variable (e.g., ‘in’, ‘out’, ‘inout’).
- Return type:
str
- AutoRPE.UtilsRPE.AttributeParser.attribute_is_allocatable(attributes: list[str])[source]
Returns whether a variable is allocatable in its attributes.
- Parameters:
attributes (list[str]) – A list of attribute strings.
- Returns:
True if the variable is allocatable, False otherwise.
- Return type:
bool
- AutoRPE.UtilsRPE.AttributeParser.attribute_is_optional(attributes: list[str])[source]
Returns whether a variable is marked as optional in its attributes.
- Parameters:
attributes (list[str]) – A list of attribute strings.
- Returns:
True if the variable is optional, False otherwise.
- Return type:
bool
- AutoRPE.UtilsRPE.AttributeParser.attribute_is_parameter(attributes: list[str])[source]
Returns whether a variable is a constant parameter in its attributes.
- Parameters:
attributes (list[str]) – A list of attribute strings.
- Returns:
True if the variable is a parameter, False otherwise.
- Return type:
bool
- AutoRPE.UtilsRPE.AttributeParser.attribute_is_pointer(attributes: list[str], variables: list[str])[source]
Checks if a variable is a pointer and returns the pointed object.
- Parameters:
attributes (list[str]) – A list of attribute strings.
variables (list[str]) – A list of variable declarations.
- Returns:
The pointed object name if the variable is a pointer, False otherwise.
- Return type:
str | bool
- AutoRPE.UtilsRPE.AttributeParser.attribute_type(attributes: list[str], variable: str = None)[source]
Determines the type of a variable from its attribute string.
- Parameters:
attributes (list) – A list of attributes.
variable (str, optional) – A variable object for additional context, default is None.
- Returns:
The variable type as a string, or None if the type cannot be determined.
- Return type:
str | None
- AutoRPE.UtilsRPE.AttributeParser.get_variable_name(string: str, original_file=False)[source]
Returns the variable name(s) from a declaration string, handling both single and multiple declarations.
- Parameters:
string (str) – The variable declaration string.
original_file (bool) – Flag indicating whether the file is parsed (default is False).
- Returns:
The variable name(s).
- Return type:
str | list[str]
- AutoRPE.UtilsRPE.AttributeParser.get_variable_name_parsed(string: str)[source]
Removes assignment or indexing from a variable declaration and returns the variable name.
- Parameters:
string (str) – The variable declaration string.
- Returns:
The parsed variable name.
- Return type:
str
- AutoRPE.UtilsRPE.AttributeParser.parse_attributes(attributes: str, variables: list)[source]
Parses a string of attributes to extract variable characteristics.
- Parameters:
attributes (str) – The attribute string to parse.
variables (list) – List of variables to use for parsing.
- Returns:
- A tuple containing the parsed variable type, dimension, intent, optionality, allocatable status,
pointer status, and parameter status.
- Return type:
tuple
- AutoRPE.UtilsRPE.AttributeParser.parse_dimension_attribute(dimension_attribute: str) int[source]
Parses a dimension attribute string and returns the number of dimensions.
- Parameters:
dimension_attribute (str) – The dimension attribute string to parse.
- Returns:
The number of dimensions, or 0 if invalid.
- Return type:
int
AutoRPE.UtilsRPE.BasicFunctions
- AutoRPE.UtilsRPE.BasicFunctions.clean_if_else_condition(line: str, function_name: str)[source]
Removes conditions from an if or else statement, returning the function call if present.
- Parameters:
line (str) – The input line of code.
function_name (str) – The name of the function to search for.
- Returns:
The function call if found, otherwise the remaining code.
- Return type:
str
- AutoRPE.UtilsRPE.BasicFunctions.close_brackets(string: str)[source]
Trims a string to include only the portion up to the closing bracket of a function or array call.
- Parameters:
string (str) – The input string.
- Returns:
The trimmed string ending at the first matched closing bracket.
- Return type:
str
- Raises:
ExceptionNotManaged – If the brackets are unbalanced in the input string.
- AutoRPE.UtilsRPE.BasicFunctions.combine_types(list_of_types: list[str])[source]
Combines a list of variable types into a single resulting type, based on a predefined dictionary.
- Parameters:
list_of_types (list) – A list of variable types to combine.
- Returns:
The resulting combined type.
- Return type:
str
- Raises:
ExceptionNotManaged – If the type combination is not defined in the dictionary.
- AutoRPE.UtilsRPE.BasicFunctions.contain_literals(string: str, string_dictionary: dict = None)[source]
Determines if a string contains literals (e.g., quotes, concatenation symbols, or masks).
- Parameters:
string (str) – The input string to check.
string_dictionary (dict, optional) – A dictionary of masked strings for additional checks.
- Returns:
True if the string contains literals or matches a masked string.
- Return type:
bool
- AutoRPE.UtilsRPE.BasicFunctions.count_initial_spaces(string: str)[source]
Counts the number of leading spaces in a string.
- Parameters:
string (str) – The input string.
- Returns:
The number of leading spaces.
- Return type:
int
- AutoRPE.UtilsRPE.BasicFunctions.create_type_combinations(case_types: list)[source]
Generates all possible combinations of casting real types for a list of variable types.
- Parameters:
case_types (list) – A list of variable types.
- Returns:
A list of all possible variations of the input variable types.
- Return type:
list
- Raises:
AssertionError – If the number of arguments exceeds 10, which can cause combinatorial issues.
- AutoRPE.UtilsRPE.BasicFunctions.find_next_end(lines: list[str], _index: int, end_statement: str)[source]
Finds the next occurrence of an end statement in a block of lines.
- Parameters:
lines (list[str]) – A list of source code lines.
_index (int) – The starting index to search from.
end_statement (str) – The end statement to search for (e.g., “end subroutine”).
- Returns:
The index of the next line containing the end statement.
- Return type:
int
- AutoRPE.UtilsRPE.BasicFunctions.hash_from_list(string_list: list[str])[source]
Computes a hash value from a list of strings.
- Parameters:
string_list (list[str]) – A list of strings.
- Returns:
The MD5 hash value of the concatenated strings.
- Return type:
str
- Raises:
ExceptionNotManaged – If the input is not a list of strings.
- AutoRPE.UtilsRPE.BasicFunctions.is_all_inside_parenthesis(string: str)[source]
Checks if the entire string is enclosed in parentheses.
- Parameters:
string (str) – The input string to check.
- Returns:
True if the string is fully enclosed in parentheses, False otherwise.
- Return type:
bool
- AutoRPE.UtilsRPE.BasicFunctions.load_intrinsics()[source]
Loads a dictionary of Fortran intrinsic functions and their corresponding types.
- Returns:
A dictionary where keys are intrinsic function names (lowercase) and values are their types.
- Return type:
dict
- AutoRPE.UtilsRPE.BasicFunctions.load_source_file(_filename: str, extension: str, no_strip: bool = False)[source]
Loads a Fortran source file and creates a SourceFile object.
- Parameters:
_filename (str) – The name of the source file to load.
extension (str) – The file extension (e.g., “.f90”).
no_strip (bool) – If True, preserves extra whitespace and comments while reading the file.
- Returns:
An object representing the source file, with its content loaded.
- Return type:
SourceFile
- AutoRPE.UtilsRPE.BasicFunctions.load_sources(input_path: str, extension: list[str] = ['.f90'])[source]
Recursively loads Fortran source files from the specified input path(s).
- Parameters:
input_path (str | list[str]) – A single directory path or a list of paths to scan for source files.
extension (list[str]) – A list of allowed file extensions to load (default is [“.f90”]).
- Returns:
A list of SourceFile objects representing the loaded files.
- Return type:
list
- Raises:
ValueError – If no files with the specified extensions are found in the input path.
- AutoRPE.UtilsRPE.BasicFunctions.merge_line_in_file(line_index: int, module: <module 'AutoRPE.UtilsRPE.Classes.Module' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Module.py'>)[source]
Merges a split statement into a single line within a source file. Removes empty lines.
- Parameters:
line_index (int) – The index of the line to merge.
module – The module object containing the lines of source code.
- AutoRPE.UtilsRPE.BasicFunctions.merge_line_range(lines: list[str], line_index: int)[source]
Merges a multi-line statement into a single line by resolving line continuations.
- Parameters:
lines (list[str]) – The list of lines in the source file.
line_index (int) – The starting index of the line to merge.
- Returns:
The merged line with all continuations resolved.
- Return type:
str
- AutoRPE.UtilsRPE.BasicFunctions.remove_comments(string: str, return_comment: bool = False)[source]
Removes comments from a string, preserving OpenMP directives.
- Parameters:
string (str) – The input string.
return_comment (bool) – If True, returns the removed comment as well.
- Returns:
The string without comments, and optionally the removed comment.
- Return type:
str | tuple[str, str]
- AutoRPE.UtilsRPE.BasicFunctions.remove_else_condition(line: str)[source]
Removes an else condition from a line, preserving the remaining content.
- Parameters:
line (str) – The input line.
- Returns:
The line without the else condition.
- Return type:
str
- AutoRPE.UtilsRPE.BasicFunctions.remove_hardcoded_array_assign(string: str)[source]
Removes hardcoded array assignments from a string.
- Parameters:
string (str) – The input string containing the assignment.
- Returns:
The string without hardcoded array assignments.
- Return type:
str
- AutoRPE.UtilsRPE.BasicFunctions.remove_if_condition(_line: str, return_if_condition: bool = False)[source]
Removes an if condition from a line, preserving the remaining content.
- Parameters:
_line (str) – The input line.
return_if_condition (bool) – If True, also returns the removed condition.
- Returns:
The line without the if condition, and optionally the removed condition.
- Return type:
str | tuple[str, str]
- AutoRPE.UtilsRPE.BasicFunctions.remove_indexing(content: str)[source]
Removes indexing (e.g., array brackets) from a variable or expression.
- Parameters:
content (str) – The input content string.
- Returns:
The string without indexing or array brackets.
- Return type:
str
- AutoRPE.UtilsRPE.BasicFunctions.remove_keywords(arguments: list[str])[source]
Removes keywords from a list of argument strings, returning only the values.
- Parameters:
arguments (list[str]) – A list of arguments, potentially containing keywords.
- Returns:
The list of arguments with keywords removed.
- Return type:
list[str]
- AutoRPE.UtilsRPE.BasicFunctions.remove_outer_brackets(string: str)[source]
Removes the outermost parentheses from a string, if present.
- Parameters:
string (str) – The input string.
- Returns:
The string without its outermost parentheses.
- Return type:
str
- AutoRPE.UtilsRPE.BasicFunctions.remove_spaces(string: str)[source]
Removes extra spaces from a string.
- Parameters:
string (str) – The input string.
- Returns:
The string with multiple spaces reduced to a single space.
- Return type:
str
- AutoRPE.UtilsRPE.BasicFunctions.remove_unary_operator(string: str)[source]
Removes unary operators (e.g., + or -) from a string, if present.
- Parameters:
string (str) – The input string.
- Returns:
The string with unary operators removed.
- Return type:
str
- AutoRPE.UtilsRPE.BasicFunctions.split_comparison(content: str) tuple[str, str][source]
Splits a string based on the first occurrence of a comparison operator.
- Parameters:
content (str) – The input string containing a comparison.
- Returns:
A tuple with the left-hand side and right-hand side of the comparison.
- Return type:
tuple[str, str]
AutoRPE.UtilsRPE.CallManager
- class AutoRPE.UtilsRPE.CallManager.SubprogramCall(name, subprogram, block)[source]
Bases:
objectRepresents a call to a subprogram (function or subroutine) in the source code.
- name
The name of the subprogram being called.
- Type:
str
- subprogram
The subprogram object representing the called subprogram.
- Type:
Subprogram
- is_external
Whether the subprogram is external.
- Type:
bool
- block
The block in which the call is made.
- arguments
The actual arguments passed to the subprogram.
- Type:
list
- dummy_arguments
The expected dummy arguments for the subprogram.
- Type:
list
- cast
The type cast applied to the arguments, if any.
- line_info
Information about the line in which the call occurs.
- index
The index of the call in the source line.
- Type:
int
- property call
Retrieves the string representation of the subprogram call.
- Returns:
The subprogram call as a string.
- Return type:
str
- Raises:
ExceptionNotManaged – If the line information is not filled or the call cannot be located.
- check_argument_consistency()[source]
Verifies the consistency between the arguments passed to the subprogram and the expected dummy arguments.
- fill_dummy_arg(call=None)[source]
Populates the list of dummy arguments for the subprogram call.
- Parameters:
call (str, optional) – The string representation of the call. If not provided, the existing call in the object is used.
- update_actual_arguments(vault, call=None)[source]
Updates the list of actual arguments for the subprogram call.
- Parameters:
vault – The vault object containing metadata about the code.
call (str, optional) – The string representation of the call. If not provided, the existing call in the object is used.
- AutoRPE.UtilsRPE.CallManager.create_SubprogramCall(call: str, subprogram: <module 'AutoRPE.UtilsRPE.Classes.Subprogram' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Subprogram.py'>, procedure: <module 'AutoRPE.UtilsRPE.Classes.Procedure' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Procedure.py'>, vault: <module 'AutoRPE.UtilsRPE.Classes.Vault' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Vault.py'>)[source]
Creates a SubprogramCall object for a given subprogram call.
- Parameters:
call (str) – The string representation of the subprogram call.
subprogram (Suborogram) – The subprogram being called.
procedure (Procedure) – The procedure where the call is made.
vault (Vault) – The database containing metadata about the code.
- Returns:
The created SubprogramCall object.
- Return type:
- AutoRPE.UtilsRPE.CallManager.find_call_arguments(string: str)[source]
Extracts the arguments of a function call from a given string.
- Parameters:
string (str) – The input string containing the function call.
- Returns:
A list of arguments as strings.
- Return type:
list[str]
- AutoRPE.UtilsRPE.CallManager.find_called_function(string: str)[source]
Identifies the name of a function being called in a given string.
- Parameters:
string (str) – The input string containing the function call.
- Returns:
The name of the called function.
- Return type:
str
- AutoRPE.UtilsRPE.CallManager.get_function(string: str, procedure: <module 'AutoRPE.UtilsRPE.Classes.Procedure' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Procedure.py'>, vault: <module 'AutoRPE.UtilsRPE.Classes.Vault' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Vault.py'>)[source]
Retrieves the function(s) being called in a given string.
- Parameters:
string (str) – The input string.
procedure (Procedure) – The procedure where the call is made.
vault (Vault) – The database containing metadata about the code.
- Returns:
A list of function objects being called.
- Return type:
list
- AutoRPE.UtilsRPE.CallManager.get_subroutine(string: str, procedure: <module 'AutoRPE.UtilsRPE.Classes.Procedure' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Procedure.py'>, vault: <module 'AutoRPE.UtilsRPE.Classes.Vault' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Vault.py'>)[source]
Retrieves the subroutine(s) being called in a given string.
- Parameters:
string (str) – The input string.
procedure (Procedure) – The procedure where the call is made.
vault (Vault) – The database containing metadata about the code.
- Returns:
A list of subroutine objects being called.
- Return type:
list
- AutoRPE.UtilsRPE.CallManager.is_call_to_function(contents: str, procedure: <module 'AutoRPE.UtilsRPE.Classes.Procedure' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Procedure.py'>, vault: <module 'AutoRPE.UtilsRPE.Classes.Vault' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Vault.py'>, called_function=[])[source]
Determines if a string represents a function call.
- Parameters:
contents (str) – The input string to check.
procedure (Procedure) – Procedure object where the call is made.
vault (Vault) – The database containing metadata about the code.
called_function (list, optional) – A list to store details about the called function.
- Returns:
True if the string represents a function call, False otherwise.
- Return type:
bool
AutoRPE.UtilsRPE.Error
- exception AutoRPE.UtilsRPE.Error.ClusterCantBeDivided[source]
Bases:
ErrorA job failed on a leaf, and can not be subdivided anymore.
- exception AutoRPE.UtilsRPE.Error.DimensionNotFound[source]
Bases:
ErrorThe dimension of the argument you were searching for in vault could not be found.
- exception AutoRPE.UtilsRPE.Error.DuplicatedObject[source]
Bases:
ErrorFound duplicated object, this should not happen. Check is needed.
- exception AutoRPE.UtilsRPE.Error.ExceptionNotManaged[source]
Bases:
ErrorFound duplicated object, this should not happen. Check is needed.
- exception AutoRPE.UtilsRPE.Error.ExternalTypeUsed[source]
Bases:
ErrorExternal Derived type is used.
- exception AutoRPE.UtilsRPE.Error.HardcodedRealWithoutPrecision[source]
Bases:
ErrorThe hardcoded real does not have precision specification.
- exception AutoRPE.UtilsRPE.Error.IntentOutError[source]
Bases:
ErrorA variable was declared with an intent, but is used with a different one. Fix is needed.
- exception AutoRPE.UtilsRPE.Error.InterfaceNotFound[source]
Bases:
ErrorThe Interface you were searching for in vault could not be found.
- exception AutoRPE.UtilsRPE.Error.LineNotFound[source]
Bases:
ErrorLine you were searching for in file could not be found.
- class AutoRPE.UtilsRPE.Error.PathType(exists=True, type='file', dash_ok=True)[source]
Bases:
objectValidates file, directory, or symlink paths based on existence, type, and special cases like “-” for stdin/stdout.
- exists
Path existence condition.
- Type:
bool or None
- type
Path type (‘file’, ‘dir’, ‘symlink’, or callable).
- Type:
str or callable
- dash_ok
Whether “-” is allowed for stdin/stdout.
- Type:
bool
- exception AutoRPE.UtilsRPE.Error.PointerTarged[source]
Bases:
ErrorPointer and corresponding target types do not coincide.
- exception AutoRPE.UtilsRPE.Error.ProcedureNotFound[source]
Bases:
ErrorThe procedure you were searching for in vault could not be found.
- exception AutoRPE.UtilsRPE.Error.SplitElementError[source]
Bases:
ErrorRaised when the split_element function does not split the element.
- exception AutoRPE.UtilsRPE.Error.SubprogramNotFound[source]
Bases:
ErrorA subprogram name have not been found, probably “end subroutine” without the name. Fix is needed.
- exception AutoRPE.UtilsRPE.Error.TypeOfContent[source]
Bases:
ErrorThe function find type of error failed.
- exception AutoRPE.UtilsRPE.Error.ValueTooLargeError[source]
Bases:
ErrorRaised when the input value is too large.
AutoRPE.UtilsRPE.Getter
- AutoRPE.UtilsRPE.Getter.get_dimension_of_contents(contents: str, block: Procedure, vault: Vault)[source]
Determines the dimensionality of a given variable or expression.
- Parameters:
contents (str) – The string representation of the variable or expression.
block (Procedure) – The procedure context to analyze.
vault (Vault) – The vault containing metadata about the code.
- Returns:
The dimensionality of the contents.
- Return type:
int
- AutoRPE.UtilsRPE.Getter.get_function_type(function_call, procedure: Procedure, vault: Vault)[source]
Determines the return type of a function call.
- Parameters:
function_call (str) – The string representation of the function call.
procedure (Procedure) – The procedure context to analyze.
vault (Vault) – The vault containing metadata about the code.
- Returns:
The return type of the function.
- Return type:
str
- AutoRPE.UtilsRPE.Getter.get_interface(arguments: ~typing.List[str], interface: <module 'AutoRPE.UtilsRPE.Classes.Interface' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Interface.py'>, block: ~AutoRPE.UtilsRPE.Classes.Procedure.Procedure, vault: Vault, uniform_intent=None)[source]
Determines the specific interface subroutine that matches the given arguments.
- Parameters:
arguments (list[str]) – A list of arguments passed to the interface.
interface (Interface) – The interface object to search within.
block (Procedure) – The procedure context to analyze.
vault (Vault) – The vault containing metadata about the code.
uniform_intent (str, optional) – An intent to filter by (e.g., ‘in’, ‘out’).
- Returns:
The subprogram within the interface that matches the arguments.
- Return type:
Subprogram
- Raises:
InterfaceNotFound – If no matching routine is found.
- AutoRPE.UtilsRPE.Getter.get_interface_from_mandatory_arguments(interface: <module 'AutoRPE.UtilsRPE.Classes.Interface' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Interface.py'>, argument_types: ~typing.List[str], argument_dimensions: ~typing.List[int], uniform_intent)[source]
Matches a specific subprogram in an interface based on mandatory arguments.
- Parameters:
interface (Interface) – The interface to analyze.
argument_types (list[str]) – The types of the mandatory arguments.
argument_dimensions (list[int]) – The dimensions of the mandatory arguments.
uniform_intent (str, optional) – An intent to filter by.
- Returns:
The matching subprogram.
- Return type:
Subprogram
- Raises:
InterfaceNotFound – If no matching subprogram is found.
- AutoRPE.UtilsRPE.Getter.get_intrinsic_type(function_call: str, procedure: Procedure, vault: Vault)[source]
Determines the type of an intrinsic function call.
- Parameters:
function_call (str) – The string representation of the intrinsic function call.
procedure (Procedure) – The procedure context to analyze.
vault (Vault) – The vault containing metadata about the code.
- Returns:
The type of the intrinsic function call.
- Return type:
str
- Raises:
ValueError – If the intrinsic function type is not defined in the metadata.
- AutoRPE.UtilsRPE.Getter.get_pointer_assignment(line: str, vault: Vault, procedure: Procedure, var_type={'dp': 'dp', 'hp': 'hp', 'sp': 'sp', 'wp': 'wp'})[source]
Finds pointer assignments in a line of code and retrieves the pointer variable and its target.
- Parameters:
line (str) – The line of code to analyze.
vault (Vault) – The vault containing metadata about the code.
procedure (Procedure) – The procedure context to search within.
var_type (dict) – A dictionary of valid types for the pointer.
- Returns:
A list containing the pointer and its target if found, or None.
- Return type:
list[list]
- AutoRPE.UtilsRPE.Getter.get_structure_member(contents: str, procedure: Procedure, vault: Vault)[source]
Retrieves the last member of a structure based on its string representation.
- Parameters:
contents (str) – The string representation of the structure.
procedure (Procedure) – The procedure context to search within.
vault (Vault) – The vault containing metadata about the code.
- Returns:
The variable object corresponding to the last member of the structure.
- Return type:
Variable
- Raises:
MemberNotFound – If the structure member is not found.
- AutoRPE.UtilsRPE.Getter.get_type_of_contents(contents: str, procedure: Procedure, vault: Vault)[source]
Determines the type of a given string of code.
- Parameters:
contents (str) – The string representation of the code.
procedure (Procedure) – The procedure context to analyze.
vault (Vault) – The vault containing metadata about the code.
- Returns:
The type of the contents.
- Return type:
str
- Raises:
TypeOfContent – If the type of the contents cannot be determined.
- AutoRPE.UtilsRPE.Getter.get_type_of_real_cast(string: str)[source]
Determines the type of a real cast operation based on its arguments.
- Parameters:
string (str) – The string representation of the cast operation.
- Returns:
The type of the real cast (e.g., ‘sp’, ‘dp’, etc.).
- Return type:
str
- AutoRPE.UtilsRPE.Getter.get_variable(contents: str, procedure: Procedure = None, vault: Vault = None, clean: bool = False)[source]
Retrieves a variable based on its string representation, considering context.
- Parameters:
contents (str) – The string representation of the variable.
procedure (Procedure, optional) – The procedure context to search within.
vault (Vault, optional) – The vault containing metadata about the code.
clean (bool) – Whether to clean the string of operations and intrinsics.
- Returns:
The variable object corresponding to the input string.
- Return type:
Variable
- Raises:
VariableNotFound – If the variable is not found or the string does not represent a valid variable.
AutoRPE.UtilsRPE.Inserter
- AutoRPE.UtilsRPE.Inserter.add_real_to_argument(argument: str, string: str, precision: str = 'wp')[source]
Adds ‘real’ type casting with specified precision to the argument in the string if not already cast.
- Parameters:
argument (str) – The argument to be cast.
string (str) – The string where the replacement occurs.
precision (str, optional) – The precision to apply. Defaults to VariablePrecision.real_id[“wp”].
- Returns:
The string with the real-cast argument.
- Return type:
str
- AutoRPE.UtilsRPE.Inserter.add_real_to_array_arguments(argument: str)[source]
Casts each element of the array argument to ‘real’ with ‘wp’ precision.
- Parameters:
argument (str) – The array argument to be cast.
- Returns:
The array argument with each element cast to ‘real(wp)’.
- Return type:
str
- AutoRPE.UtilsRPE.Inserter.add_rpe_real_member_to_argument(argument: str, string: str)[source]
Replaces occurrences of the argument with its ‘%val’ version in the string, handling hardcoded arrays.
- Parameters:
argument (str) – The argument to be replaced.
string (str) – The string where the replacement occurs.
- Returns:
The string with the replaced argument.
- Return type:
str
- AutoRPE.UtilsRPE.Inserter.add_rpe_to_argument(argument: str, string: str, is_pointer: bool = False)[source]
Adds an ‘rpe’ or ‘rpe_ptr’ cast to the argument in the string if not already cast.
- Parameters:
argument (str) – The argument to be cast.
string (str) – The string where the replacement occurs.
is_pointer (bool, optional) – Whether to use ‘rpe_ptr’ for pointer types. Defaults to False.
- Returns:
The string with the casted argument.
- Return type:
str
- AutoRPE.UtilsRPE.Inserter.add_rpe_to_array_arguments(argument: str)[source]
Casts each element of the array argument to ‘rpe_var( 52, … )’.
- Parameters:
argument (str) – The array argument to be cast.
- Returns:
The array argument with each element cast to ‘rpe_var( 52, … )’.
- Return type:
str
- AutoRPE.UtilsRPE.Inserter.add_rpe_type_constructor(argument: str, string: str)[source]
Adds an ‘rpe’ constructor to the argument in the string, handling reshapes and arrays.
- Parameters:
argument (str) – The argument to be cast.
string (str) – The string where the replacement occurs.
- Returns:
The string with the rpe constructor applied.
- Return type:
str
- AutoRPE.UtilsRPE.Inserter.add_sbits_to_rpe_variables(vault: Vault)[source]
Assigns significant bits to RPE variables, truncating them based on their attributes.
- Parameters:
vault (Vault) – The vault containing the variables to be processed and truncated.
- AutoRPE.UtilsRPE.Inserter.add_val_to_argument(argument: str, string: str)[source]
Replaces occurrences of the argument with its ‘%val’ version in the string.
- Parameters:
argument (str) – The argument to be replaced.
string (str) – The string where the replacement occurs.
- Returns:
The string with the replaced argument.
- Return type:
str
- AutoRPE.UtilsRPE.Inserter.create_read_precisions_module(path_to_sources: str, vault: Vault)[source]
Generates a Fortran module to read precision namelist and writes it to a file.
- Parameters:
path_to_sources (str) – The directory path where the module should be saved.
vault (Vault) – The vault containing the variables to be processed.
- AutoRPE.UtilsRPE.Inserter.find_first_use_of_member(variable: Variable, member: Variable)[source]
Finds the first use of a member variable in a subprogram, skipping declarations, implicit statements, and use statements.
Searches through the subprogram lines after the declaration to find the first occurrence of the member variable, considering loops and where statements to avoid incorrect matches.
- Parameters:
variable (Variable) – The parent variable whose member’s usage is being tracked.
member (Variable) – The member variable to search for.
- Returns:
The module and line index where the member is first used, along with any condition string if present.
- Return type:
tuple
- AutoRPE.UtilsRPE.Inserter.find_subprogram_lines(subprogram: <module 'AutoRPE.UtilsRPE.Classes.Subprogram' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Subprogram.py'>, module: Module = None)[source]
Finds the lines in a module corresponding to the start and end of a subprogram.
- Parameters:
subprogram (Subprogram) – The subprogram whose lines are to be found.
module (Module, optional) – The module to search in. Defaults to None, in which case the subprogram’s module is used.
- Returns:
A tuple containing the module and a list with the start and end line indices of the subprogram.
- Return type:
tuple
- Raises:
Error.ProcedureNotFound – If the subprogram is not found in the module or its header files.
- AutoRPE.UtilsRPE.Inserter.insert_use_rp_emulator_in_function(func_name: str, module: Module)[source]
Inserts a ‘USE rp_emulator’ statement after the function declaration in the module.
- Parameters:
func_name (str) – The name of the function to search for.
module (Module) – The module to modify.
- AutoRPE.UtilsRPE.Inserter.insert_use_statement(vault: Vault)[source]
Adds ‘USE rp_emulator’ and ‘USE read_precisions’ to all modules and abstract interfaces that contain a variable of type ‘rpe_var’.
- Parameters:
vault (Vault) – The vault containing the modules and interfaces to modify.
- AutoRPE.UtilsRPE.Inserter.insert_variable_precision_after_subroutine_call(vault: Vault)[source]
Inserts truncation statements after each subroutine call for variables with intent ‘out’.
- Parameters:
vault (Vault) – The vault containing the subprogram calls.
- Returns:
None
- AutoRPE.UtilsRPE.Inserter.insert_variable_precision_specification(variable: Variable, module_line: str, if_condition: str = '', member_name: str = None, apply_truncation: bool = False)[source]
Adds variable precision specification to a module line, with optional truncation and condition checks.
- Parameters:
variable (Variable) – The variable whose precision is to be specified.
module_line (str) – The module line to which the specification is added.
if_condition (str, optional) – A condition to be applied before the specification (default is “”).
member_name (str, optional) – The name of the member to use, if the variable is part of a structure (default is None).
apply_truncation (bool, optional) – Whether to apply truncation to the variable (default is False).
- Returns:
The updated module line with the precision specification.
- Return type:
str
- AutoRPE.UtilsRPE.Inserter.insert_variable_precision_specification_to_allocatable(variable: Variable)[source]
Searches for the allocation of a variable and applies truncation afterward.
- Parameters:
variable (Variable) – The allocatable variable for which precision specification is to be inserted.
- Returns:
None
- AutoRPE.UtilsRPE.Inserter.insert_variable_precision_specification_to_allocatable_member(variable: Variable, counter_object, vault: Vault)[source]
Searches for allocatable members of a variable’s type and applies precision truncation to them.
- Parameters:
variable (Variable) – The variable whose allocatable members will be processed.
counter_object – The counter for assigning unique IDs to members.
vault (Vault) – The vault containing the variables and modules.
- Returns:
None
- AutoRPE.UtilsRPE.Inserter.insert_variable_precision_specification_to_namelist_parameter(variable: Variable, vault: Vault)[source]
Inserts variable precision specification to a namelist parameter in the corresponding module.
- Parameters:
variable (Variable) – The variable to be processed.
vault (Vault) – The vault containing the modules and variables.
- Returns:
None
- AutoRPE.UtilsRPE.Inserter.insert_variable_precision_to_main_variable(in_main: list[Variable], vault: Vault)[source]
Inserts truncation for all global variables with no first use tracking.
For each module that contains global variables, it creates a subroutine to assign precision truncation and adds a call to this subroutine in the main program.
- Parameters:
in_main (list) – List of global variables in the main program.
vault (Vault) – The vault containing all modules and variables.
- Updates:
Modifies the lines of relevant modules to include truncation subroutines and appropriate calls to these subroutines in the main program.
Note
This function handles the insertion of the assign_sbits subroutine and ensures that necessary USE statements and CALL statements are added.
- AutoRPE.UtilsRPE.Inserter.insert_variable_precision_to_output_dummy(variable: Variable)[source]
Inserts truncation for dummy arguments in the output, searching for the first line of code after variable declarations. Adds truncation logic to the first line of code in the subprogram where no variables are declared, handling optional variables with a conditional check for their presence.
- Parameters:
variable (Variable) – The variable for which truncation is to be added.
- Returns:
None
- AutoRPE.UtilsRPE.Inserter.insert_variable_precision_to_output_dummy_with_rpe_member(variable, counter_object, vault)[source]
Inserts variable precision specification for an rpe member in the output dummy.
- Parameters:
variable (Variable) – The variable to be processed.
counter_object – The counter for assigning ids.
vault (Vault) – The vault containing the variables and modules.
- Returns:
None
- AutoRPE.UtilsRPE.Inserter.replace_variable_exact_match(piece_to_replace: str, replacement: str, string: str)[source]
Replaces exact occurrences of a variable in the string, ensuring no internal replacements occur.
- Parameters:
piece_to_replace (str) – The variable to be replaced.
replacement (str) – The replacement for the variable.
string (str) – The string where the substitution occurs.
- Returns:
The string with the exact replacement applied.
- Return type:
str
- AutoRPE.UtilsRPE.Inserter.split_by_appearance_in_namelist(variables: list[Variable])[source]
Splits the variables into two lists: one with variables that appear in a namelist and the other with those that do not.
- Parameters:
variables (list[Variable]) – List of variables to split.
- Returns:
Two lists, the first containing variables in a namelist, and the second containing those not in a namelist.
- Return type:
tuple
- AutoRPE.UtilsRPE.Inserter.split_vars_by_allocatable(variables: list[Variable])[source]
Splits the variables into two lists: one with allocatable or pointer variables, and the other with the remaining variables.
- Parameters:
variables (list[Variable]) – List of variables to split.
- Returns:
Two lists, the first containing allocatable or pointer variables, and the second containing the rest.
- Return type:
tuple
- AutoRPE.UtilsRPE.Inserter.split_vars_by_main(variables: list[Variable], vault: Vault)[source]
Splits variables based on whether they are in the ‘main’ procedure or not, and further categorizes non-main variables by their association with derived types that contain RPE members.
- Parameters:
variables (list[Variable]) – List of variables to split.
vault (Vault) – Object containing the global variables.
- Returns:
- Three lists, the first containing non-main variables with RPE members,
the second containing non-main variables without RPE members, and the third containing variables in the main procedure.
- Return type:
tuple
AutoRPE.UtilsRPE.MaskCreator
- AutoRPE.UtilsRPE.MaskCreator.find_keys(string: str, dictionary_of_replacements: dict = None)[source]
Finds all masked keys in the given string, including those with double masks.
- Parameters:
string (str) – The input string to search for masked keys.
dictionary_of_replacements (dict, optional) – A dictionary of replacements to filter the keys found.
- Returns:
A list of masked keys found in the string, filtered by the dictionary of replacements if provided.
- Return type:
list
- AutoRPE.UtilsRPE.MaskCreator.mask_arrays_and_structures(string: str, only_structures: bool = False, dictionary_of_replacements: dict = None)[source]
Masks arrays and structures within a string by replacing them with randomly generated strings or placeholders, and creates a dictionary of the substitutions.
- Parameters:
string (str) – The input string containing arrays and structures to be masked.
only_structures (bool, optional) – If True, only structure patterns are masked. Defaults to False.
dictionary_of_replacements (dict, optional) – A dictionary to store the replacements. If None, a temporary dictionary is used.
- Returns:
The modified string with arrays and structures masked.
- Return type:
str
- AutoRPE.UtilsRPE.MaskCreator.mask_exponential(string: str, dictionary_of_replacements: dict = None)[source]
Masks exponential notations within the given string and creates a dictionary with the substitutions.
- Parameters:
string (str) – The input string containing exponential notations to be masked.
dictionary_of_replacements (dict, optional) – A dictionary to store the replacements. If None, a new dictionary is created.
- Returns:
The modified string with exponential notations masked.
- Return type:
str
- AutoRPE.UtilsRPE.MaskCreator.mask_functions(string: str, dictionary_of_replacements: dict = None)[source]
Masks function calls within the given string. Identifies and replaces all function calls in the input string with a masked placeholder.
- Parameters:
string (str) – The input string containing function calls to be masked.
dictionary_of_replacements (dict, optional) – A dictionary to store the replacements. If None, a new dictionary is created.
- Returns:
The modified string with function calls masked.
- Return type:
str
- AutoRPE.UtilsRPE.MaskCreator.mask_intrinsics(string: str)[source]
Masks intrinsic function calls within the string by simplifying their arguments.
- Parameters:
string (str) – The input string containing intrinsic function calls to be masked.
- Returns:
The simplified arguments or the modified string after masking.
- Return type:
list
- AutoRPE.UtilsRPE.MaskCreator.mask_keyword(line: str, key: str, dictionary_of_substitutions: dict)[source]
Masks occurrences of a specific keyword in a line by replacing them with unique placeholders.
This function identifies occurrences of a keyword assignment (e.g., key = value) and substitutes the keyword with a placeholder, while updating a dictionary to store the original values.
- Parameters:
line (str) – The line of code in which to mask the keyword.
key (str) – The keyword to search for and mask.
dictionary_of_substitutions (dict) – A dictionary to store mappings between placeholders and the original values.
- Returns:
The line with the specified keyword occurrences masked.
- Return type:
str
- AutoRPE.UtilsRPE.MaskCreator.mask_literal(string, dict_of_substitutions=None)[source]
Looks for open and close of different apex and mask what is in between.
- Parameters:
string (str) – String to be masked.
dict_of_substitutions (dict) – Dictionary that contains the masked-unmasked strings to substitute.
- Returns:
Masked string.
- Return type:
str
- AutoRPE.UtilsRPE.MaskCreator.mask_string_for_check_operation(string: str, dictionary_of_replacements: dict = None)[source]
Masks various components of a string to prepare it for safe operation checks.
This function applies several masking steps to handle components like exponents, arrays, structures, and function calls. It replaces these components with placeholders, allowing for safe processing of operations without interference from complex structures.
- Parameters:
string (str) – The input string to be masked.
dictionary_of_replacements (dict, optional) – A dictionary to store mappings between placeholders and the original components. If not provided, a new dictionary will be created.
- Returns:
The masked string with brackets removed and placeholders for complex components.
- Return type:
str
- AutoRPE.UtilsRPE.MaskCreator.remove_literals(string: str, dict_of_literal_sub: dict = None)[source]
Removes literal values from a string, replacing them with spaces while maintaining the original string length.
This function masks literal values (e.g., strings in quotes) using mask_literal, then substitutes the masked literals with spaces while preserving the length of the original string.
- Parameters:
string (str) – The input string from which literals should be removed.
dict_of_literal_sub (dict, optional) – A dictionary to store mappings of masked literals and their original values. If not provided, a new dictionary will be created.
- Returns:
The modified string with literals replaced by spaces.
- Return type:
str
- AutoRPE.UtilsRPE.MaskCreator.remove_pow(string: str)[source]
Removes exponential notation (e.g., power operations) from a string.
This function searches for instances of exponentiation (using ‘**’ or raised powers) in the input string and removes them. It handles both simple power operations and exponentiation inside parentheses.
- Parameters:
string (str) – The input string from which exponential notations are to be removed.
- Returns:
The modified string with exponential notations removed.
- Return type:
str
- AutoRPE.UtilsRPE.MaskCreator.unmask_from_dict(string: str, dictionary_of_replacements: dict)[source]
Unmasks a string using a dictionary of replacements, processing double-masked keys first (strings that have been masked twice, containing two ‘@’).
- Parameters:
string (str or list) – The masked string (or list of strings) to be unmasked.
dictionary_of_replacements (dict) – A dictionary containing the masked keys and their replacements.
- Returns:
The unmasked string (or list of strings) after applying the dictionary replacements.
- Return type:
str | list
AutoRPE.UtilsRPE.NatureDeterminer
- AutoRPE.UtilsRPE.NatureDeterminer.has_intrinsics(string: str)[source]
Checks if the string contains any intrinsic function calls.
- Parameters:
string (str) – The string to check for intrinsic function calls.
- Returns:
The name of the intrinsic function if found, None otherwise.
- Return type:
str or None
- AutoRPE.UtilsRPE.NatureDeterminer.has_operations(string: str, operand=None)[source]
Checks if the string contains mathematical operations and optionally splits the operands.
- Parameters:
string (str) – The string to check for operations.
operand (list, optional) – If provided, the operands will be split and stored in the list.
- Returns:
True if the string contains mathematical operations, False otherwise.
- Return type:
bool
- AutoRPE.UtilsRPE.NatureDeterminer.is_a_number(string)[source]
Checks if a string is a valid number and return its type if applicable.
- Parameters:
string (str) – The string to be checked.
- Returns:
The type of the number (e.g., ‘integer’ or ‘real’), or False if it’s not a number.
- Return type:
str or bool
- Raises:
ValueError – If the string cannot be converted to a number and does not match valid formats.
- AutoRPE.UtilsRPE.NatureDeterminer.is_array(contents: str, check_sliced: bool = False)[source]
Checks if the contents represent an array, optionally checking for slicing.
- Parameters:
contents (str) – The contents to check if they represent an array.
check_sliced (bool, optional) – If True, the function checks if the array is sliced.
- Returns:
True if the contents represent an array, False otherwise.
- Return type:
bool
- AutoRPE.UtilsRPE.NatureDeterminer.is_end_function_statement(line: str)[source]
Checks if the line contains an ‘end function’ statement.
- Parameters:
line (str) – A line of source code to check for an ‘end function’ statement.
Returns: - bool: True if the line matches the syntax of an ‘end function’ statement, False otherwise.
- AutoRPE.UtilsRPE.NatureDeterminer.is_function_declaration_statement(line: str)[source]
Checks if the line contains a function declaration statement.
- Parameters:
line (str) – A line of source code to check for a function declaration.
- Returns:
True if the line matches the syntax of a function declaration, False otherwise.
- Return type:
bool
- AutoRPE.UtilsRPE.NatureDeterminer.is_hardcoded_array(string, array=None)[source]
Checks if the string represents a hardcoded array [form (/a, b/)] and optionally populate the array parameter.
- Parameters:
string (str) – The string to check if it represents a hardcoded array.
array (list, optional) – If provided, the array will be populated with the elements found in the array.
- Returns:
True if the string represents a hardcoded array, False otherwise.
- Return type:
bool
- AutoRPE.UtilsRPE.NatureDeterminer.is_keyword_argument(argument: str, key_arg=None)[source]
Checks if the argument is a keyword argument and optionally store the key-value pair.
- Parameters:
argument (str) – The argument string to check.
key_arg (list, optional) – If provided, the list will be populated with the key and argument value.
- Returns:
True if the argument is a keyword argument, False otherwise.
- Return type:
bool
- AutoRPE.UtilsRPE.NatureDeterminer.is_logical_comparison(string: str)[source]
Checks if the string contains a logical comparison operator.
- Parameters:
string (str) – The string to check for logical comparison operators.
- Returns:
True if the string contains a logical comparison operator, False otherwise.
- Return type:
bool
- AutoRPE.UtilsRPE.NatureDeterminer.is_pointer_assignment(string: str)[source]
Checks if the string represents a pointer assignment.
- Parameters:
string (str) – The string to check if it contains a pointer assignment.
- Returns:
True if the string represents a pointer assignment, False otherwise.
- Return type:
bool
- AutoRPE.UtilsRPE.NatureDeterminer.is_struct_element(contents: str) bool[source]
Checks if the contents represent a structure element (derived type).
- Parameters:
contents (str) – The contents to check for structure element notation (e.g., ‘struct%element’).
- Returns:
True if the contents represent a structure element, False otherwise.
- Return type:
bool
AutoRPE.UtilsRPE.ObtainSourceFileInfo
- AutoRPE.UtilsRPE.ObtainSourceFileInfo.add_external_subprogram(unknown_calls, vault: Vault)[source]
Adds external subprogram calls to the vault, marking variables used in external subprograms.
This function stores external subprogram calls in the vault’s block dictionary and marks variables used in these calls as involved in external subprograms.
- Parameters:
unknown_calls (UnknownCalls) – The object containing subprogram calls that are not yet recognized.
vault (Vault) – The vault object where subprogram call information and associated variables are stored.
- Returns:
None
- AutoRPE.UtilsRPE.ObtainSourceFileInfo.add_module_subprogram(vault: Vault)[source]
Adds subprograms and associated information to each module in the vault.
This function assigns subprograms (functions, subroutines, interfaces) to each module and stores information about accessible and indirectly accessible subprograms.
- Parameters:
vault (Vault) – The database containing modules and related information.
- AutoRPE.UtilsRPE.ObtainSourceFileInfo.add_struct_members(file, structure)[source]
Adds members of a structure to the main routine of the file. Given a structure, this method finds its members and adds them as variables to the ‘main’ routine of the provided file, if available.
- Parameters:
file (File) – The file object containing the structure and routines.
structure (Structure) – The structure object containing variables to be added to the main routine.
- Returns:
None
- Raises:
UnboundLocalError – If the ‘main’ routine is not found in the file.
- AutoRPE.UtilsRPE.ObtainSourceFileInfo.check_external_function(vault: Vault)[source]
Verifies that external subprograms are not mistakenly identified as internal due to misspelling, ensuring that variables used in external functions are properly analyzed.
- Parameters:
vault (Vault) – The vault object containing information about subprograms and interfaces.
- Returns:
None
- AutoRPE.UtilsRPE.ObtainSourceFileInfo.create_subprogram(module, header, routine_name, dummy_arguments, var_declarations, used_modules, subprogram_type)[source]
Creates a subprogram (function or subroutine) with its associated variables and attributes.
This function creates a subprogram object (function or subroutine) by processing its header, dummy arguments, variable declarations, and used modules. It determines the return value for functions and assigns appropriate attributes to the variables, including type, dimension, intent, and optional status.
- Parameters:
module (Module) – The module containing the subprogram.
header (str) – The header string of the subprogram.
routine_name (str) – The name of the subprogram.
dummy_arguments (list) – A list of dummy arguments for the subprogram.
var_declarations (list) – A list of variable declarations within the subprogram.
used_modules (list) – A list of modules used by the subprogram.
subprogram_type (Subprogram) – The type of the subprogram (Function or SubRoutine).
- Returns:
The created subprogram object with associated variables and attributes.
- Return type:
Subprogram
- Raises:
ValueError – If the subprogram type is not recognized (i.e., not a Function or SubRoutine).
- AutoRPE.UtilsRPE.ObtainSourceFileInfo.deduce_precision(fortran_kind: str) str[source]
Determines if the Fortran kind specifier corresponds to single or double precision.
- Parameters:
fortran_kind (str) – The Fortran kind specification as a string (e.g., ‘kind ( 1.0D+00 )’).
- Returns:
- ‘single’ if the specifier corresponds to single precision,
’double’ if it corresponds to double precision.
- Return type:
str
- Raises:
ValueError – If the input string does not contain a valid precision specifier.
- AutoRPE.UtilsRPE.ObtainSourceFileInfo.fill_alloc_info(vault: Vault)[source]
Identifies allocation and deallocation of allocatable variables and updates their metadata.
- Parameters:
vault (Vault) – The vault containing all modules, variables, and metadata.
- Returns:
A list of allocatable variables with their type, dimensions, name, allocation block, and module.
- Return type:
list
- AutoRPE.UtilsRPE.ObtainSourceFileInfo.fill_line_info_call(vault: Vault)[source]
Populates the line information in the vault by processing function and subroutine calls in each module’s line info.
Iterates through each module and its line information, identifying function and subroutine calls. If a call corresponds to an unknown subprogram, it adds the external subprogram to the vault. The information is stored in the vault’s dictionary of calls, with the key being the subprogram’s name (or module name for non-external calls).
- Parameters:
vault (Vault) – The vault object containing the modules and their associated data.
- Returns:
None
- AutoRPE.UtilsRPE.ObtainSourceFileInfo.find_function_type_from_header(header: str, var_declaration: list[str])[source]
Extracts the return type and name of a function from its header and variable declarations.
- Parameters:
header (str) – The function declaration line.
var_declaration (list) – A list of variable declarations within the function.
- Returns:
A pair containing the function’s return type and name.
- Return type:
tuple
- AutoRPE.UtilsRPE.ObtainSourceFileInfo.find_functions(module: <module 'AutoRPE.UtilsRPE.Classes.Module' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Module.py'>, vault: Vault)[source]
Extracts function declarations from a module, including their names, arguments, and attributes, and stores them in the vault.
- Parameters:
module (Module) – The module containing the function declarations.
vault (Vault) – The vault object where function metadata is stored.
- Returns:
None
- AutoRPE.UtilsRPE.ObtainSourceFileInfo.find_interfaces(vault: Vault)[source]
Extracts interface declarations from all modules in the vault, identifies their associated procedures, and stores them as interface objects.
- Parameters:
vault (Vault) – The vault containing modules and their metadata.
- Returns:
None
- AutoRPE.UtilsRPE.ObtainSourceFileInfo.find_module_variables(module: <module 'AutoRPE.UtilsRPE.Classes.Module' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Module.py'>)[source]
Extracts and processes variable declarations from a module, excluding variables within type and function declaration zones.
- Parameters:
module (Module) – The module to analyze for variable declarations.
- Returns:
None
- AutoRPE.UtilsRPE.ObtainSourceFileInfo.find_namelist_variable(module: <module 'AutoRPE.UtilsRPE.Classes.Module' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Module.py'>, vault: Vault)[source]
Identifies variables in a namelist declaration, associates them with the module and namelist, and updates their metadata.
- Parameters:
module (Module) – The module containing the namelist declarations.
vault (Vault) – The database storing variables and their associated metadata.
- Returns:
None
- AutoRPE.UtilsRPE.ObtainSourceFileInfo.find_subprogram_declaration(module: <module 'AutoRPE.UtilsRPE.Classes.Module' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Module.py'>, _subprogram_start: int, _subprogram_end: int, obj_to_find: str = '(.*)::(.*)')[source]
Finds and returns a list of variable declarations within a subprogram, given its start and end lines.
- Parameters:
module (Module) – The module containing the subprogram’s source code.
_subprogram_start (int) – The starting line number of the subprogram.
_subprogram_end (int) – The ending line number of the subprogram.
obj_to_find (Pattern) – A regular expression pattern for identifying variable declarations..
- Returns:
A list of strings containing variable declarations within the subprogram.
- Return type:
list
- AutoRPE.UtilsRPE.ObtainSourceFileInfo.find_subroutines(module, vault)[source]
Finds subroutine declarations within a module, extracts their attributes, and stores them in the vault.
This function scans the module’s source code for subroutine declarations, identifies their names, dummy arguments, variable declarations, and used modules. It creates subroutine objects with appropriate attributes and adds them to the vault. It also identifies any internal subroutines declared within the subroutine’s scope.
- Parameters:
module (Module) – The module containing the source code to scan for subroutine declarations.
vault (Vault) – The vault object where subroutines and their associated information are stored.
- Returns:
None
- Raises:
Error.SubprogramNotFound – If the corresponding end subroutine statement for a subroutine cannot be found.
- AutoRPE.UtilsRPE.ObtainSourceFileInfo.find_types(module: <module 'AutoRPE.UtilsRPE.Classes.Module' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Module.py'>, vault: Vault)[source]
Scans the module for type declarations and extracts information about derived types and their members.
This function looks for type declarations, including any type extensions, and parses the variables associated with each type. It then adds the derived types and their variables to the vault.
- Parameters:
module (Module) – The module containing lines of code to be analyzed for type declarations.
vault (Vault) – The database where derived types and their variables are stored.
- Returns:
None
- AutoRPE.UtilsRPE.ObtainSourceFileInfo.find_undefined_type_parameters(vault: Vault)[source]
Finds and assigns types to undefined kind parameters used in the code, based on the declaration.
- Parameters:
vault – The vault containing variables and their metadata.
- Returns:
None
- Raises:
NotImplementedError – If multiple potential types are found for the same kind parameter.
- AutoRPE.UtilsRPE.ObtainSourceFileInfo.find_used_modules(module: <module 'AutoRPE.UtilsRPE.Classes.Module' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Module.py'>, vault: Vault)[source]
Parses the ‘use’ statements in a module to identify dependencies and imports variables or subprograms into the module.
- Parameters:
module (Module) – The module to analyze.
vault (Vault) – The vault containing all module definitions and metadata.
- Returns:
None
- AutoRPE.UtilsRPE.ObtainSourceFileInfo.get_dummy_arguments(module: <module 'AutoRPE.UtilsRPE.Classes.Module' from '/home/docs/checkouts/readthedocs.org/user_builds/autorpe/checkouts/stable/AutoRPE/UtilsRPE/Classes/Module.py'>, index: int)[source]
Retrieves the subroutine name and its dummy arguments from a specific line in the module.
Given the line number in the module, this function extracts the subroutine name and any associated dummy arguments, handling special cases like function declarations with kind attributes.
- Parameters:
module (Module) – The module containing the source code.
index (int) – The line number to examine in the module.
- Returns:
- A tuple where the first element is the subroutine name (str) and the second element is
a list of dummy arguments (list of str).
- Return type:
tuple
- AutoRPE.UtilsRPE.ObtainSourceFileInfo.get_type_from_declaration(declaration: str) str[source]
Extracts and deduces the type from a variable declaration.
- Parameters:
declaration (str) – The variable declaration, e.g., ‘real :: var = kind_parameter’
- Returns:
The deduced type based on the declaration.
- Return type:
str
- AutoRPE.UtilsRPE.ObtainSourceFileInfo.handle_misspelled_variable(dummy_argument: str, variables: List[str])[source]
Checks if a dummy argument is in the variables list, case insensitively.
- Parameters:
dummy_argument (str) – The dummy argument to check.
variables (List[str]) – The list of variables to search.
- Returns:
The matching variable if found.
- Return type:
str
- Raises:
Error.VariableNotFound – If no matching variable is found.
- AutoRPE.UtilsRPE.ObtainSourceFileInfo.parse_sources(file_list: list, vault: Vault, extension: str)[source]
Parses a list of source files and extracts relevant information into a vault structure.
This function processes subprograms, variables, derived types, and more from the given source files. It identifies subroutines, functions, and module variables, then stores them in the vault.
- Parameters:
file_list (list) – List of source files to be parsed.
vault (Vault) – The database to store extracted information from the code.
extension (str) – The file extension to be used during parsing.
- Returns:
The updated vault containing parsed information.
- Return type:
Vault
AutoRPE.UtilsRPE.RegexPattern
- AutoRPE.UtilsRPE.RegexPattern.escape_deindexed_structures(string: str)[source]
Modifies the provided string to handle structures with indexed members (i.e., using “%”). The function adds the appropriate regular expression format for structures to ensure proper matching, including handling nested structures.
- Parameters:
string (str) – The string representing the structure to escape.
- Returns:
- The modified string suitable for use in regular expressions,
accounting for structure members and indexing.
- Return type:
str
- AutoRPE.UtilsRPE.RegexPattern.escape_string(string: str, strict: bool = True)[source]
Escapes a given string to make it compatible with regular expressions. The function ensures that special characters like “+”, “-”, “*”, and “.” are escaped, and that word boundaries are added where appropriate. Additionally, it can apply stricter conditions to avoid matching certain structures or patterns (like names followed by parentheses or arrays).
- Parameters:
string (str) – The string to escape.
strict (bool) – Whether to apply strict escaping (default is True).
- Returns:
The escaped string suitable for use in regular expressions.
- Return type:
str
AutoRPE.UtilsRPE.SourceManager
- AutoRPE.UtilsRPE.SourceManager.expand_sources(source_path: str)[source]
Recursively gets all source files with a Fortran extension (.f, .F, .f90, .F90) from the specified directory.
- Parameters:
source_path (str) – The directory to search for source files.
- Returns:
A sorted list of file paths matching the Fortran source file pattern.
- Return type:
list
- Raises:
OSError – If there is an issue accessing the directory.
- AutoRPE.UtilsRPE.SourceManager.load_intrinsics()[source]
Loads the list of Fortran intrinsics from a hardcoded file.
- Returns:
A dictionary mapping the lowercase name of each intrinsic to its corresponding name.
- Return type:
dict
- AutoRPE.UtilsRPE.SourceManager.load_list_of_files_to_keep_unmodified(filename: str = None)[source]
Loads a list of files to keep unmodified from a specified file (defaults to a hardcoded path). Returns a list of file paths, excluding comments.
- Parameters:
filename (str, optional) – The path to the file containing the list of files. Defaults to a hardcoded path.
- Returns:
A list of file paths to keep unmodified.
- Return type:
list
- AutoRPE.UtilsRPE.SourceManager.load_variable_list(filename: str, vault: Vault, is_used: bool = False, precision: bool = False)[source]
Loads and processes a list of banned variables from a file, with options to separate by usage or apply precision settings.
- Parameters:
filename (str) – The path to the file containing variable data.
vault (object) – The vault containing variable data to be matched.
is_used (bool) – If True, separates variables by whether they are used or not.
precision (bool) – If True, applies precision settings to variables.
- Returns:
A list of variables (or two lists if is_used is True).
- Return type:
list
- AutoRPE.UtilsRPE.SourceManager.match_module_and_filename(module: str, filenames: list[str])[source]
Returns a list of filenames matching the module name with a Fortran extension.
- Parameters:
module (str) – The module name to search for.
filenames (list[str]) – A list of filenames to search through.
- Returns:
A list of filenames that match the module name and Fortran extension.
- Return type:
list
AutoRPE.UtilsRPE.TrackDependency
- AutoRPE.UtilsRPE.TrackDependency.create_edges(argument: Variable, dummy: Variable, graph: networkx.Graph)[source]
Creates an edge in the graph between two variables based on their relationship.
- Parameters:
argument (Variable) – The first variable.
dummy (Variable) – The second variable.
graph (networkx.Graph) – The graph in which the edge will be created.
- AutoRPE.UtilsRPE.TrackDependency.create_graph(vault: Vault, graph_name: str, var_type: str)[source]
Creates a directed graph to represent dependencies, then converts it to an undirected graph.
- Parameters:
vault (Vault) – The vault containing variables and subprogram calls.
graph_name (str) – The name to save the graph to (optional).
var_type (str) – The type of variables to track in the graph.
- Returns:
The undirected graph representing dependencies.
- Return type:
networkx.Graph
- Raises:
FileNotFoundError – If saving the graph to disk fails due to an invalid path.
- AutoRPE.UtilsRPE.TrackDependency.create_nodes(variables: list[Variable], graph: networkx.Graph)[source]
Creates nodes in the graph for each variable in the given list.
- Parameters:
variables (list) – A list of variables to create nodes for.
graph (networkx.Graph) – The graph in which nodes will be created.
- Raises:
KeyError – If a variable’s hash_id is not found in the graph.
AttributeError – If the procedure.level attribute is missing for a variable.
- AutoRPE.UtilsRPE.TrackDependency.propagate_dependencies(vault: Vault, graph_name: str = None, var_type: dict = {'dp': 'dp', 'hp': 'hp', 'sp': 'sp', 'wp': 'wp'})[source]
Propagates dependencies by creating a graph and storing dependency information into the vault.
- Parameters:
vault (Vault) – The vault containing variables.
graph_name (str, optional) – The name of the graph file to save (defaults to None).
var_type (dict, optional) – The type of variables to track in the graph (defaults to VariablePrecision.real_id).
- Returns:
None
- Raises:
FileNotFoundError – If saving the graph to disk fails due to an invalid path.
- AutoRPE.UtilsRPE.TrackDependency.track_dependencies(vault: Vault, graph: networkx.Graph, var_type: str)[source]
Tracks dependencies between variables in the vault and updates the graph with nodes and edges.
- Parameters:
vault (Vault) – The vault containing variables and subprogram calls.
graph (networkx.Graph) – The graph to update with dependency information.
var_type (str) – The type of variables to track.
- Returns:
None
- Raises:
VariableNotFound – If a variable is not found in the vault while processing pointer assignments.
AutoRPE.UtilsRPE.VariablePrecision
- class AutoRPE.UtilsRPE.VariablePrecision.UndefinedPrecision(name)[source]
Bases:
objectA class to represent an undefined precision.
- name
The name of the undefined precision type.
- Type:
str
- AutoRPE.UtilsRPE.VariablePrecision.set_working_precision(working_precision: str)[source]
Set the value of the working precision.
- Parameters:
working_precision (str) – The precision type to set (e.g., ‘sp’, ‘dp’, ‘wp’).
- AutoRPE.UtilsRPE.VariablePrecision.type_are_equivalent(type1: str, type2: str, working_precision: str = None)[source]
Check if two types are equivalent, considering the working precision if needed.
- Parameters:
type1 (str) – The first type to compare.
type2 (str) – The second type to compare.
working_precision (str, optional) – The working precision to consider when one type is ‘wp’.
- Returns:
True if the types are equivalent, False otherwise.
- Return type:
bool