FUNCTION_BLOCK FB95
CONST
NUM_DATA_PTS := 12;
END_CONST
VAR_INPUT
X : REAL;
END_VAR
VAR_OUTPUT
Y : REAL;
END_VAR
VAR
TableData : STRUCT
XData : ARRAY [0..NUM_DATA_PTS - 1] OF REAL := 800, 900, 1000, 1100, 1150, 1200,
1250, 1300, 1350, 1400, 1450, 1500;
YData : ARRAY [0..NUM_DATA_PTS - 1] OF REAL := 0.553, 0.681, 0.786, 0.868, 0.901, 0.930,
0.953, 0.971, 0.986, 0.996, 1.000, 1.000;
END_STRUCT;
XIndex : INT;
END_VAR
BEGIN
IF X < TableData.XData[0] THEN
Y := TableData.YData[0];
ELSE
IF X > TableData.XData[NUM_DATA_PTS - 1] THEN
Y := TableData.YData[NUM_DATA_PTS - 1];
ELSE
XIndex := 1;
WHILE (XIndex < NUM_DATA_PTS) AND (X >= TableData.XData[XIndex]) DO
XIndex := XIndex + 1;
END_WHILE;
Y := ((X - TableData.XData[XIndex - 1]) *
(TableData.YData[XIndex] - TableData.YData[XIndex - 1]) /
(TableData.XData[XIndex] - TableData.XData[XIndex - 1]) +
TableData.YData[XIndex - 1]);
END_IF;
END_IF;
END_FUNCTION_BLOCK