Reference Guide
Reference Guide
Reference Guide
|
The Calculator/Preprocessor utility (“calculat.ma”) is used to evaluate expressions in MicroStation 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 MicroStation. For example, if Calculator/Preprocessor is loaded, when you key in AA={asin(1)} the active angle is set to the result, 90°.
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 information.
The interaction between the preprocessor and MicroStation while Calculator/Preprocessor is loaded is described here.
The preprocessor examines all MicroStation 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 MicroStation 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 and user commands) in addition to key-ins. The preprocessor expects the result of an expression to be an integer, floating point value, or character string.
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 (%w for working units format is valid as well).
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.
While Calculator/Preprocessor is active, these calculator commands can be keyed-in the same way as MicroStation 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 MicroStation 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 MicroStation 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 %.10f.
For example, to calculate the value of 9000.10 in working units format, key in CALCULATOR FORMAT DOUBLE %w and then key in CALCULATOR 9000.10.
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 CALCULATE 0x100.
UCCALC [C_expression] — calculates
the result of a C expression, but does not display the result. This command
is intended for use in key-in strings generated in user commands with KEY
statements.
While Calculator/Preprocessor is active, these preprocessor commands can be keyed in the same way as MicroStation key-ins:
PREPROCESSOR [OFF|ON|TOGGLE] — used to disable and enable preprocessing. PREPROCESSOR alone opens the Preprocessor dialog box.
PREPROCESSOR FORMAT DOUBLE [format_string] — specifies the format string used to substitute for floating point expressions. The default is %.10f.
PREPROCESSOR FORMAT INT [format_string] — specifies the format string used to substitute for integer expressions. The default is %d.
PREPROCESSOR START [start_character] — used to specify the character used to delimit the start of key-in strings for preprocessing. The default start delimiter is “{.”
PREPROCESSOR END [end_character] — used to specify the character used to delimit the end of key-in strings for preprocessing. The default end delimiter is “}.”
PREPROCESSOR STATUS — displays the current status of the preprocessor in the Status Bar.
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.
The Preprocessor dialog box lets you disable and enable preprocessing and adjust the following preprocessor settings:
Expression delimiters
Output format strings
Preprocessor dialog box | |
Key-in: PREPROCESSOR