A formula is a special data set where the value is not fixed when stored, but is instead replaced by calculation operations that can calculate the value when required. You usually write these formulas in the script language FPScript. FlexPro offers you special analysis objects for common analyses so that you do not have to learn how to use FPScript.
Formulas are the main tools for automating the analysis. In the nested network of formulas for a project, the entire "knowledge" is saved so that you can repeat the analysis as often as you like, and the data to be analyzed can be assigned at the click of a button.
You can use formulas wherever data sets are also permitted, such as for a curve in a diagram.
FlexPro compiles the formula into binary code, which guarantees rapid processing. The FlexPro "Smart Update" technology ensures that unnecessary re-calculations are avoided. The result of the last calculation is stored temporarily and re-used for as long as possible.
Note With FlexPro View, the analysis options are limited to basic mathematical operations and simple, statistical evaluations.
Elements of FPScript Formulas
•Constants: These are constant expressions such as values in the various data types.
•Variables: You can use variables in a formula to save interim results. This allows you to save computing time by only performing a calculation once for terms that are used several times. You can also structure your formulas better by first assigning parameters to a variable and then continue on with the formula using the variable.
•Data sets: Data sets are used like variables. If a data set name is used in a formula, this name represents the data that is read when the formula is later calculated. This data can also be formulas. The formulas are then first evaluated to obtain the data. You cannot make assignments to formulas and data sets.
•Pre-defined constants: Some mathematical constants, such as PI or E, as well as constants, which are used as function parameters, are available as pre-defined constants. You cannot use these names for data set names and/or variables.
•Operators: You can use operators to calculate and modify data. FlexPro provides you with a variety of operators with which you can also calculate complete signals.
•Statements: Each formula consists of one or more statements, where one line is used for each statement. However, you can also write several statements in a single line, if you separate the statements from each other using a semi-colon ';'. You can also split a statement over several lines. For lines that are to be merged with the lines following, you have to enter a backslash '\' or an underscore character "_" as the final character. In FlexPro formulas you can use different loops and conditional statements, for example, to be able to perform a complex analysis for all of the data series in a signal series.
•Functions: FlexPro features a variety of functions that you can use to generate signals and carry out analyses. You can also define custom functions. These are formulas that you provide with arguments and that you can call like a function in other formulas.
•Object properties: The various objects in FlexPro provide special functions for accessing their attributes. For example, you can access the comments for a data set.
•Comments: These start with "//" and then extend to the end of the line.
•Python Functions und Constants You can use Python functions and constants directly in your FPScript formulas.
Examples of FPScript Formulas
The project database FPScript is located on your hard drive and contains various FPScript programming examples.
The project database path name is usually C:\Users\Public\Documents\Weisang\FlexPro\2023\Examples\FPScript.fpd or C:>Users>Public>Public Documents>Weisang>FlexPro>2023>Examples>FPScript.fpd.
Python Formula (FlexPro Professional, Developer Suite)
If you have licensed and activated the Python interface of FlexPro, you can also create Python formulas in addition to FPScript formulas. Python formulas are written in the open-source programming language Python and give you access to the extensive function libraries of this language directly in FlexPro. FlexPro uses the numerical data types of Python's NumPy library to exchange data between FlexPro and Python. NumPy is a library that must be imported into a Python program using the import command before it can be used.
In a Python formula, you can use the flexpro module to access data from other data sets or formulas, aggregate Python data into the composite data structures used in FlexPro and return the result of the Python formula to FlexPro.
Unlike FPScript, Python cannot calculate with physical values. However, it is possible to read in the units of data sets and assign units to the result of the Python formula.
Smart Update does not work automatically with Python, i.e. FlexPro cannot recognize whether a Python formula needs to be recalculated even if the data it is calculating has not changed. You do this by setting the Indeterministic option on the Result tab of the formula's Properties dialog box.
Important note In order for FlexPro to ensure the integrity of the object network, formulas in FlexPro must be programmed so that they only have their result as output. A formula must therefore not produce any "side effects". The range of functions and commands in FPScript ensures this for FPScript formulas. You can only have read access to other data sets and cannot perform operations, such as writing files. In Python, these restrictions do not exist and it is therefore up to the programmer's discipline to adhere to this basic rule.
Python Prolog Code
Libraries that you want to use in Python must first be imported using the import command. So that you do not have to do this in every Python formula, you can specify a prolog code under File > Project Database Properties > Python, which is always executed before the actual code of the formula. A typical prolog code looks like this, for example:
import flexpro
import numpy as np
You must always import the flexpro and numpy modules.
Using Further Python Modules
The numpy and flexpro modules are already pre-installed. If you want to use other modules, you must tell FlexPro where to find them. You can specify the hard disk folders in which FlexPro should search for Python modules under File > Options > Python > General settings.
Important note In contrast to FPScript, Python can be used to write programs that manipulate files and the operating system, provided your user permissions allow it. Therefore, only import modules that originate from trustworthy sources and only specify hard disk directories to which there is no unrestricted access! If in doubt, contact your company's IT security officer.
See Also
Custom FPScript Functions Tutorial
Working with Formulas
Inserting Code Elements into a Formula
Search and Replace in a Formula
Applying Formulas to Data Sets
Converting Formulas, Analysis Objects or Data Link Objects into Data Sets