![]() |
Subroutines for equation parsing in case of an analytic trajectory or luminosity mode. More...
Functions/Subroutines | |
logical function, private | is_digit (str_in) |
Function to decide whether a character is a number or not (i.e., 0-9). More... | |
logical function, private | is_operator (str_in) |
Function to decide whether a character is a mathematical operator or not. Functions (as e.g., sin) are not defined here! More... | |
logical function, private | is_dot_operator (str_in) |
Function to decide whether a character is "*" or "/". More... | |
logical function, private | is_line_operator (str_in) |
Function to decide whether a character is a "+" or "-". More... | |
logical function, private | is_power_operator (str_in) |
Function to decide whether a character is a "^". More... | |
logical function, private | is_separator (str_in) |
Function to decide whether a character can be associated with a number. More... | |
real(r_kind) function, private | operation (number_1, number_2, str_in) |
Function to perform a simple mathematical operation. More... | |
real(r_kind) function, private | eval_function (number, str_in) |
Function to perform a function operations. More... | |
subroutine, private | make_pars_str_consistent |
Subroutine to check the parsing string for consistency and correct it. More... | |
real(r_kind) function, private | common_variables (inp_str) |
Function to define constants. More... | |
subroutine, private | store_digits_operator |
Store mathematical operators (+-*/) and numbers in arrays. More... | |
subroutine, private | get_simple_result |
Evaluate a simple string expression, without brackets and functions. More... | |
subroutine, private | evaluate |
Evaluate a complex string expression. More... | |
real(r_kind) function, public | parse_string (input_string, var_value) |
Takes a string and evaluates the expression. More... | |
subroutine, public | find_start_value (input_string, eq_value, initial_guess, converged, result) |
Finds a value of the variable for a given y-value. More... | |
Variables | |
character(max_fname_len), private | parsing_string |
Current substring to parse. More... | |
character(max_fname_len), private | complete_string |
Complete input string. More... | |
integer, private | operator_count |
integer, private | number_count |
character(1), dimension(:), allocatable, private | operators |
Array containing the operations of the equation as a character (e.g., ["*","+"]) More... | |
real(r_kind), dimension(:), allocatable, private | numbers |
Array containing the numbers of the equation (e.g., [1, 2, 3]) More... | |
real(r_kind), private | variable_value |
Input variable, set by parse_string. More... | |
character(1), parameter, private | variable_name ='x' |
Name of the variable that is replaced by parse_string. More... | |
Subroutines for equation parsing in case of an analytic trajectory or luminosity mode.
The subroutine can calculate equations from a string, e.g., "5.1+3d-2*(2-1)*sin(pi)/x". A variable name (in the upper example "x") can be given, which will be filled with a value. Everything in this function is private with the exception of the function "parse_string" which serves as a interface to parse the given string. The return value of this function is a real (i.e., not a string).
|
private |
Function to define constants.
This function translates names of constants to numbers (real). For example, "pi" is translated to 3.1415. Define new constants (names and values) in this function.
After this, will be 3.141592653589793
[in] | inp_str | Input character, defining the constant |
Definition at line 441 of file parser_module.f90.
|
private |
Function to perform a function operations.
Depending on the input it will calculate, e.g., the square root (sqrt) or the sinus (sin). To add a function to the functionality of the parser, add the translation in this function here.
b will be 2.
[in] | str_in | Name of the function |
[in] | number | input to the function |
Definition at line 314 of file parser_module.f90.
|
private |
Evaluate a complex string expression.
Evaluate expressions with brackets ( i.e., "(" and ")" ) and function names (i.e., "sin(5)" ).
After this, the array numbers will have -8 on its first entry.
Definition at line 713 of file parser_module.f90.
subroutine, public parser_module::find_start_value | ( | character(300), intent(in) | input_string, |
real(r_kind), intent(in) | eq_value, | ||
real(r_kind), intent(in) | initial_guess, | ||
logical, intent(out) | converged, | ||
real(r_kind), intent(out) | result | ||
) |
Finds a value of the variable for a given y-value.
This function solves an equation, i.e., finds the value of variable "x" for expressions as, for example, "3*x+2+x^2 = 10" returns 1.701562. This works with a newton raphson to find the root of f(x) - 10.
After this, result will be 1.701562 and converged will be .True.
[in] | input_string | String to parse |
[in] | eq_value | Value of the equation |
[in] | initial_guess | Initial guess for the variable |
[out] | converged | Flag that indicates a success |
[out] | result | Time at which the expression is equal to eq_value. |
Definition at line 855 of file parser_module.f90.
|
private |
Evaluate a simple string expression, without brackets and functions.
This subroutine is able to evaluate simply expressions without brackets or functions. Only +- * / and ^ is allowed here. In addition a variable name or constant names may be given. For example "2+3-1" will store the result (4) in the first entry of the "numbers" array.
After this, the array numbers will have -11 on its first entry.
Definition at line 594 of file parser_module.f90.
|
private |
Function to decide whether a character is a number or not (i.e., 0-9).
b will be .True. and c will be .False.
[in] | str_in | Input character |
Definition at line 73 of file parser_module.f90.
|
private |
Function to decide whether a character is "*" or "/".
b will be .False. and c will be .True.
[in] | str_in | Input character |
Definition at line 141 of file parser_module.f90.
|
private |
Function to decide whether a character is a "+" or "-".
b will be .True. and c will be .False.
[in] | str_in | Input character |
Definition at line 172 of file parser_module.f90.
|
private |
Function to decide whether a character is a mathematical operator or not. Functions (as e.g., sin) are not defined here!
b will be .True. and c will be .False.
[in] | str_in | Input character |
Definition at line 104 of file parser_module.f90.
|
private |
Function to decide whether a character is a "^".
b will be .True. and c will be .False.
[in] | str_in | Input character |
Definition at line 203 of file parser_module.f90.
|
private |
Function to decide whether a character can be associated with a number.
Allowed characters are ".", "d", and "e" (for scientific format of a number).
b will be .True. and c will be .False.
[in] | str_in | Input character |
Definition at line 235 of file parser_module.f90.
|
private |
Subroutine to check the parsing string for consistency and correct it.
This subroutine will convert all characters to lower case characters (e.g., 4E-1 -> 4e-1) and will add a leading "0" in case the string starts with a mathematical operator (i.e., + or -, e.g., "-3+5" -> "0-3+5"). Furthermore, it checks for "+-" (and "++", "--" and all combinations) and will correct it to "-". Additionally "**" is corrected to "^", in this way the power can be written by both (**, and ^).
After this, parsing_string will be "0-2-3^2"
Definition at line 372 of file parser_module.f90.
|
private |
Function to perform a simple mathematical operation.
Depending on the input character, the function performs "+". "-", "*", "/", or "^". In case of a different character, an error is raised.
b will be 13.
[in] | str_in | Input character (containing "+","-","*","/","^".) |
number_2 | Input numbers on which the operation is performed |
Definition at line 269 of file parser_module.f90.
real(r_kind) function, public parser_module::parse_string | ( | character(300), intent(in) | input_string, |
real(r_kind), intent(in) | var_value | ||
) |
Takes a string and evaluates the expression.
This function is accessible to the outside of the module. It serves as interface between other modules and this one. Also replaces variable_name with variable_value.
After this, b will be -15.
[in] | input_string | String to parse |
[in] | var_value | Value of the variable that will be stored in variable_value |
Definition at line 806 of file parser_module.f90.
|
private |
Store mathematical operators (+-*/) and numbers in arrays.
The result of this subroutine are two arrays, one containing all operators (e.g., for "3+2*2+1-1": ['+','*','+','-']) and one array containing all numbers (as real type, [3,2,2,1,1]).
After this, the array operators will contain ("-","-","^"), and the array numbers will contain (0, 2, 3, 2).
Definition at line 480 of file parser_module.f90.
|
private |
Complete input string.
Definition at line 29 of file parser_module.f90.
|
private |
Definition at line 32 of file parser_module.f90.
|
private |
Array containing the numbers of the equation (e.g., [1, 2, 3])
Definition at line 34 of file parser_module.f90.
|
private |
Definition at line 32 of file parser_module.f90.
|
private |
Array containing the operations of the equation as a character (e.g., ["*","+"])
Definition at line 33 of file parser_module.f90.
|
private |
Current substring to parse.
Definition at line 28 of file parser_module.f90.
|
private |
Name of the variable that is replaced by parse_string.
Definition at line 38 of file parser_module.f90.
|
private |
Input variable, set by parse_string.
Definition at line 37 of file parser_module.f90.