Computed Variables and Expressions

A computed variable is a variable of one of the types identified above. A computed variable value is dynamically computed by ASSET based on expressions that the user supplies which arithmetically combine other variable values. Computed variables are associated with the following ASSET functions:

General usage variables.

Test Scheduler

The mechanism which allows the user to define a computed variable’s value as a function of other variables is called an expression. An expression is a string the user specifies which is equated to the computed variable’s value.

Variables

Variables are referred to in expressions using the variable’s label. The units associated with a variable are automatically managed in the evaluation of the expression, ie., no units conversions are required in expressions.

Constants

A constant in an expression is a combination of a value and a units specification. The units are associated with the value using square brackets ([...]), as follows:

100[deg_f]
1200[rpm]

Arithmetic Operators

The following arithmetic operators are supported in expressions:

+ addition
- subtraction
/ division
* multiplication

Note that the + operator, when applied to strings, denotes concatenation. The other 3 arithmetic operators cannot be used with strings.

Logical Expressions

Logical expressions can be parsed using if, then, else constructs, as follows:

if (logical_variable_or_expression) then (value) else (value)

Complex if/then/else logical constructs may be used where the value above may itself be an if/then/else expression.

if a then ( if(x) then (y) else (z) ) else b

If the target variable of an expression is a logical variable, the if/then/else terms are unnecessary for the case where the result is either TRUE or FALSE.

if ( a > b ) then TRUE else FALSE

can be replaced by the expression alone

a > b

since the result of evaluating ( a > b ) will be either TRUE or FALSE.

Logical Operators

Logical operators may be used to combine logical values or expressions. Supported logical operators are:

&& AND

|| OR

! NOT

> greater than

< less than

>= greater than or equal to

== equal to

<= less than or equal to

Bitwise Operators

| bitwise OR

& bitwise AND

>> right shift

<< left shift

 

Functions

Functions may be called in expressions. Functions are called using an "at" sign (@) followed by the name of the function, for example:

@sin( crank_angle )





Table 5 - Functions Supported in Expressions

Function

Description

abs(X)

integer absolute value of X

ceil(X)

smallest integer not less than X

fabs(X)

floating point absolute value of X

floor(X)

largest integer not greater than X

fmod(dividend, divisor)

remainder of dividend divided by divisor

labs(X)

long absolute value of X

round(X)

rounds to nearest integer

exp(X)

Napier’s number (2.71828...) raised to the X power

log(X)

natural log of X

log10(X)

common log of X

log2(X)

log, base 2, of X

pow(base,exp)

base raised to the exp power

sqrt(x)

square root of X

acos(X)

arc cosine of X (-1<=X<=1)

acosh(X)

inverse hyberbolic cosine of X (X>1)

asin(X)

arc sine of X (-1<=X<=1)

asinh(X)

inverse hyperbolic sine of X

atan(X)

arc tangent of X (- /2 < X < /2) (2 quadrants)

atanh(X)

inverse hyperbolic arctangent of X

atan2(sin, cos)

arc tangent of sin/cos (4 quadrants)

cos(X)

cosine of X

cosh(X)

hyperbolic cosine of X

sin(X)

sine of X

sinh(X)

hyperbolic sine of X

tan(X)

tangent of X

tanh(X)

hyperbolic tangent of X

j0(X)

Bessel function first kind, zeroth order

j1(X)

Bessel function first kind, first order

y0(X)

Bessel function second kind, zeroth order

y1(X)

Bessel function second kind, first order

long_3d_comp(X_VAR, TABLE_NUM)

3D long interpolation

shrt_3d_comp(X_VAR, TABLE_NUM)

3D short interpolation

oil_pressr(RPM, OIL_TEMP)

oil pressure model (for L10 engine)

long second_of_minuteL()

returns current "seconds" of time as an interger

char* second_of_minute ()

returns current "seconds" of time as a string with leading zeroes

long minute_of_hourL()

returns current "minutes" of time as an integer

char* minute_of_hour()

returns current "minutes" of time as a string with leading zeroes

long day_of_month()

returns current "day" of month

long day_of_week()

returns current "day" of week

long day_of_year()

returns current "day" of year

long hour_of_dayL()

returns current "hour" of day (24 hour clock) as an integer

char* hour_of_day()

returns current "hour" of day (24 hour clock) as a string with leading zeroes

long year_month_dayL()

returns an integer of format YYMMDD, e.g. 60621

long day_month_yearL()

returns an integer of format DDMMYY, e.g. 210606

char* year_month_day()

returns string of format YYMMDD with leading zeroes, e.g. “060621”

char* day_month_year()

returns string of format DDMMYY with leading zeroes, e.g. “210606”

long year4_month_dayL()

returns an integer of format YYYYMMDD, e.g. 20060621

char* year4_month_day()

returns string of format YYYYMMDD with leading zeroes, e.g. “20060621”

double rh_visc_rat( double temp, double rh )

determine viscosity ratio for air as a function of temperature and relative humidity (in %)

double kvisc( long code , double t )

compute the kinematic viscosity (stokes)of lube or fuel oil at a given temperature (t)

code type

1 #1 fuel oil

2 #2 fuel oil

3 15W40 lube oil

4 10W lube oil

5 30W lube oil

double dpt_to_vp( temp )

returns vapor pressure as function of dewpoint

Example:

@dpt_to_vp( outside_temp )

@dpt_to_vp( 68[deg_f] ) returns 2336 pascals

double cal_table( x-value, table_name )

returns interpolated value from a calibration table

Examples:

@cal_table( 100[mv], ‘cmp_in_p’ )

@cal_table( x_val, ‘cmp_in_p’ )

char ascii_time( time )

returns MM/DD/YY HH:MM:SS format from a double value of ANSI time – time may be a constant with units, the label of a variable with units of time, or a computed expression

Examples:

@ascii_time( 1150897824.87[sec] )

@ascii_time( time )

@ascii_time( “time – 1[hr]” )

unsigned int strlen( char *string )

length of a string

Examples:

var1 = “abcde”

@strlen( var1 )

The above returns 5

Or

@strlen( ‘abcde’ )

The above returns 5

int strcmp( char *s1, char *s2 )

compare strings

Example:

Var1 = “abc”

Var2 = “def”

@strcmp( Var1, Var2 )

The above returns -1

Var1 = “ghi”

Var2 = “ghi”

@strcmp( Var1, Var2 )

The above returns 0

Var1 = “jkl”

Var2 = “abc”

@strcmp( Var1, Var2 )

The above returns 1

strcpy( char *s1, char *s2 )

string copy

Examples:

Var1 = “111”

Var2 = “789”

@strcpy( Var1, Var2 )

The above results: Var1 = “789”

Var1 = “abc”

@strcpy( Var1, ‘8888’ )

The above results: Var1 = “8888”

char *strstr( char *s1, char *s2 )

string search

Examples:

Var1 = “0”

Var2 = “456”

@strstr( var1, var2 )

The above results: Var1 = “”

Var1 = “789”

Var2 = “8”

@strstr( var1, var2 )

The above results: Var1 = “89”

strncmp( char *s1, char *s2, int n )

string search

Examples:

Var1 = “ABCDEFGH”

Var2 = “ABCDEFHI”

@strncmp( Var1, Var2, 4[none])

The above returns: 0

@strncmp( Var1, Var2, 8[none])

The above returns: -1

@strncmp( Var1, ‘ab’, 2[none] )

The above returns: 0

strncpy( char *s1, char *s2, int n )

string copy

Examples:

Var1 = “55555555”

Var2 = “789”

@strncpy( Var1, Var2, 3[none] )

The above results: Var1 = “7895555”

Var1 = “TRUE”

@strncpy( Var1, ‘FALSE’, 2[none] )

The above results: Var1 = “FAUE”

char* strupr( char *s1 )

convert a string to upper case

Example:

Var1 = “abcdefgh”

@strupr( Var1 )

The above results: Var1 = “ABCDEFGH”

LOGICAL strcmp_lbl_lbl( char *label1, char *label2 )

compare the values of 2 string variables

Example:

@strcmp_lbl_lbl( my_s1, my_s2 ) returns TRUE if the contents of string variable s1 is the same as the contents of string variable s2

LOGICAL strcmp_lbl_lit( char *label, char *s1 )

compare the value of a string variable with a string literal

Example:

@strcmp_lbl_lit( my_s, ‘ctl_spd’ ) returns TRUE if my_s contains “ctl_spd”

double str_lbl_value( char *label )

get the value of a variable whose label is contained in a string variable

Example:

@str_lbl_value( my_s ) where my_s contains the label ‘ctl_spd’, returns 1000.5

char *str_var_string( char *label, int format )

get the value of a variable whose label is contained in a string variable - return the value as string with "format" places to the right of decimal

Example:

@str_var_string( my_s, 2) where my_s contains the label ‘ctl_spd’, returns “1000.49”

double str_lbl_def_value( char *label )

return default (SI units) value of a variable

Example:

@str_lbl_def_value( ctl_spd )

short str_lbl_in_str_lbl_out( char *lable1, char *label2)

where label1 and label2 are string variables which contain the labels i_lbl_1 and i_lbl_2, move the value of i_lbl_1 to i_lbl_2 using appropriate units conversion – return TRUE if successful

Example:

@str_lbl_in_str_lbl_out( my_pres1, my_pres2 )

long strstrx( char *s1, char *s2 )

search s1 for the substring s2 and return the position in s1 where s2 starts

Example:

@strstrx( ‘a valuable lesson’, ‘val’ ) returns a 2

double cal_table_min( char *file )

return the minimum engineering units of a calibration table file

Example:

@cal_table_min( ‘air_mtr0_p’ ) returns the minimum value of file /cell/tables/air_mtr0_p.tbl

double cal_table_max( char *file )

return the maximum engineering units of a calibration table file

Example:

@cal_table_max( ‘air_mtr0_p’ ) returns the maximum value of file /cell/tables/air_mtr0_p.tbl

double variable_age( char *label )

return the time (in seconds) since a variable was updated

Example:

@variable_age( ctl_spd ) returns 1.00 if ctl_spd variable was update 1 sec ago

double variable_time( char *label )

return the time (time_t) when a variable was last updated

Example:

@variable_time( ctl_spd ) returns 1150897824.87

char* units_tag( char *label, char *tag )

return a tag with value and units for a variable

Example:

@units_tag( ‘ctl_spd’, ‘speed’ ) returns “speed=1000.5[rpm]”

char* value_units( char *label )

return a string which contains the value[units] of a variable

Example:

@value_units( ‘ctl_spd’ ) returns “1000.5[rpm]”

short ctrl_loop_mode( char *loop )

return the open/closed mode of a control loop – where 0 =closed loop, 1=open loop and loop is the label of the feedback variable

Example:

@ctrl_loop_mode( fuel_t )

short file_info( char *filename, char *type)

This function duplicates the C access() function. It determines the access permissions of a file.

type can be either ‘W_OK’ (for writing), ‘R_OK’ (for reading), or ‘X_OK’ (for execute). The return will be TRUE if the specified access mode is permitted.

Example:

@file_info( ‘/specs/PAM_datapoint’, ‘W_OK’ ) returns TRUE if the file is writeable







 Examples of Expressions:

A calculation of a speed 100 RPM over the engine’s idle speed:

IdleSpd + 100[rpm]

A calculation of a control loop target temperature as a function of whether an engine is running:

if(SpdGt400) then(100[deg_f]) else(130[deg_f])

A calculation of engine brake horse power:

RPM * TORQUE



Expressions without units conversion:

Calculations within an expression can be forced to occur without units conversion or to be done with specified units by enclosing the expression in { } braces. In this form, the constants are entered without units and adding units to a variable label is optional.

For example, assume that IdleSpd has units of RPM and a value of 1000[rpm]

“IdleSpd + 100[rpm]” will yield the equivalent of 1100[rpm] in default units of [rad/sec]



{IdleSpd + 100} will yield a value of 1100



As another example, using temperatures, assume my_temp has a value of 68[deg_f] and units of deg_f.

“my_temp” will yield 293 (Kelvin)

{my_temp} will yield 68