Reference Guide
Reference Guide
Reference Guide

Calculator/Preprocessor

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

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 information.

Preprocessor/MicroStation interaction

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.

To prevent preprocessing while Calculator/Preprocessor is active
  1. Use the backward quotation mark (`) as the first character in the key-in string or key in PREPROCESSOR OFF.
    If a backward quotation mark is the first character, MicroStation ignores the character when processing the key-in.

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 (%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.

Calculator commands

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

Preprocessor commands

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

Customizing Calculator/Preprocessor

You can customize Calculator/Preprocessor as follows:

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.

Preprocessor dialog box

The Preprocessor dialog box lets you disable and enable preprocessing and adjust the following preprocessor settings:

Preprocessor dialog box

  

Key-in: PREPROCESSOR