Lookup Table Implementation

Lookup Table Implementation

 

The MicroC Style Guide implementation of the Rational Statemate Language has been extended to include Lookup Tables.

The language supports non-linear “Y=F(X)” functions that are so common in the world of micros. Typically, these non-linear functions are used to represent characteristic curves of valves in a table structure. Such a table may consist of a list of pairs of digitizing points, Xi, and its corresponding value, Fi. The data might be imported from any ASCII data file. A choice is given whether to perform (linear) interpolation between points, or to use a histogram like mode. In addition, saturation values might be defined, for the upper and lower range bounds, as well as a search order to support performance sensitive scenarios.

For example, consider the following definition and implementation of such a function with return value defined to be “Real” and input defined to be “Integer”:

In “Interpolation,” High to Low mode, Lower Bound=0, Upper Bound =4 The following code will be generated.

 
Note: Define default mapping between Real and either “double” or “float” and Integer vs.
int8/16/32.
double LOOKUP1(int IN1)
{
/*
Interpolation Function:
if(In < X2 && In >= X1)
Out = (Y2-Y1)/(X2-X1)*(In-X1)+Y1
*/
double LOOKUP1_retval;
if(IN1 < 1)
LOOKUP1_retval = (0);
else if(IN1 >= 1000)
LOOKUP1_retval = (4);
else if(IN1 >= 100)
LOOKUP1_retval = (4 - 3)/((double)1000 - 100)*(IN1 -
100) + 3;
else if(IN1 >= 10)
LOOKUP1_retval = (3 - 2)/((double)100 - 10)*(IN1 -
10) + 2;
else if(IN1 >= 1)
LOOKUP1_retval = (2 - 1)/((double)10 - 1)*(IN1 - 1)
+ 1;
return(LOOKUP1_retval);
}