ProStructures Help

Calculator/Preprocessor

The Calculator/Preprocessor utility ("calculat.ma") is used to evaluate expressions in ProStructures key-ins. The syntax used is that of "C".

  • The calculator displays the result of an expression in the Status Bar. For example, if Calculator/Preprocessor is loaded, when you key in CALCULATOR 3*sin(90) the result, 3, is displayed in the Status Bar.
  • The preprocessor replaces an expression with the result and passes the key-in to ProStructures. For example, if Calculator/Preprocessor is loaded, when you key in AA={asin(1)} the active angle is set to the result, 90°.

C Expression Handling

Both the calculator and preprocessor handle standard C syntax for expressions.

The most significant difference between C expression handling and Calculator/Preprocessor expression handling is in integer division. With C expression handling, integer division produces an integer result. With Calculator/Preprocessor expression handling, integer division produces a floating point result. For example, in C the result of 1/4 is 0. With Calculator/Preprocessor, the result of 1/4 is 0.25.

The functions cos, acos, sin, asin, atan, atan2, tan, cosh, tanh, sinh, exp, ldexp, log, log10, pow, and sqrt are supported. These functions are the same as the standard C functions except that angles are expressed in degrees rather than radians.

Variables and functions can be declared for use with Calculator/Preprocessor. See Customizing Calculator/Preprocessor for more information.

Interaction Between the Preprocessor and the Product

The interaction between the preprocessor and ProStructures while Calculator/Preprocessor is loaded is described here.

The preprocessor examines all ProStructures key-ins and looks for text enclosed in designated delimiter characters. The default delimiters are braces {}.

When the preprocessor finds a delimited text string, it evaluates the string. If the string is a valid C expression, the preprocessor replaces the delimiters and the expression with the result and re-examines the entire key-in string. The preprocessor loops in this manner until it completes a pass without replacing any text. The key-in is then passed to ProStructures for processing as a normal key-in.

The preprocessor handles key-in strings resulting from custom menu selections or simulated by other applications (MDL applications) in addition to key-ins. The preprocessor expects the result of an expression to be an integer, floating point value, or character string.

Default values can be changed in the Preprocessor dialog.

Calculator and Preprocessor Output Format

The calculator and preprocessor each have a format string that controls integer result display and another that controls floating point result display. These format strings are standard C printf strings.

The calculator does not process character string results. If the calculator evaluates an expression that generates a character pointer result, the calculator displays an error message. If the preprocessor evaluates an expression that generates a character pointer result, the preprocessor replaces the expression with the string to which the result points.

Calculator Commands

While Calculator/Preprocessor is active, these calculator commands can be keyed-in the same way as ProStructures key-ins:

  • CALCULATOR [C_expression] — calculates the result of a C expression. The result of the expression is displayed in the Status Bar. CALCULATOR alone directs the calculator to interpret all key-ins as expressions. This mode remains active until another command is activated.
  • CALCULATOR DECLARE DOUBLE [variable_name] — declares a floating point variable for the calculator and preprocessor. The initial value for the variable is 0. The value's definition and value are saved between sessions in "uservrbl.dat."
  • CALCULATOR DECLARE INT [variable_name] — declares an integer variable for the calculator and preprocessor. The initial value for the variable is 0. The value's definition and value are saved between sessions in "uservrbl.dat."
  • CALCULATOR FORMAT DOUBLE [format_string] — specifies the format string used to display the result of floating point expressions. The default is %.16g.
  • CALCULATOR FORMAT INT [format_string] — specifies the format string used to display the result of integer expressions. The default is %d.

    For example, to calculate the hexadecimal value of decimal 100:, key in CALCULATOR FORMAT INT %#X and then key in CALCULATOR 100.

    For example, to calculate the decimal value of hexadecimal 100, key in CALCULATOR FORMAT INT %d and then key in CALCULATOR 0x100.

  • UCCALC [C_expression] — calculates the result of a C expression, but does not display the result.

Customizing Calculator/Preprocessor

You can customize Calculator/Preprocessor as follows:

  • Add variables through the "uservrbl.dat" file.
  • Add additional functions and variables from MDL programs.
  • Declare variables with CALCULATOR DECLARE commands.
  • Completely replace the preprocessor with another MDL program.

During its initialization, Calculator/Preprocessor reads "uservrbl.dat." It looks for the file in the directory assigned to the MS_DATA configuration variable. Each variable definition in the file has the following format :<type_name> <variable_name> <initial_value>

The possible values for type_name are double and int. The variable names defined in "uservrbl.dat" are restricted to a maximum of 16 characters. The initial value of the string begins with the first non-blank character after the variable name. It continues until the end of the line.

An example of a standard initialization file follows:

int baseValue 1
double baseUor 1.0

When Calculator/Preprocessor is being unloaded, it updates "uservrbl.dat." While updating, it records the types, names, and values of the variables defined in the "uservrbl.dat" file and those defined with CALCULATOR DECLARE commands. It does not save information about variables published from MDL programs.

MDL programs can add functions and variables to the calculator by publishing them with the mdlCExpression_symbolPublish function. Using a symbol set that has a VISIBILITY_CALCULATOR visibility makes the function or variable available to the calculator. This is the only way to add functions to the calculator.