ganutenator
Lifetime Supporting Member
(* convert the inputs to floats *)
input_min:= raw_min_real;
input_max:= raw_max_real;
scaled_min:= eu_min_real;
scaled_max:= eu_max_real;
(*limit raw to 0 to 10,000*)
If raw_real < 0.0 then
input_real:= 0.0;
elsif raw_real > 10000.0 then
input_real:= 10000.0;
else
input_real:= raw_real;
end_if;
(* calculates the slope or rate; i.e. rise over the run *)
If ((input_max - input_min) <> 0.0) Then
rate:= (scaled_max - scaled_min) / (input_max - input_min);
Else
rate:= 0.0;
End_if;
(* calculates the offset *)
offset:= scaled_min - (input_min * rate);
(* performs the scaling calculation; i.e. y = mx+b *)
output_real:= (input_real * rate) + offset;
(* If the "Limit_En" flag is set then limit the output to within the scaling parameters *)
IF limit_overflow THEN
IF output_real > scaled_max THEN
output_real:= scaled_max;
fail:= true;
ELSIF output_real < scaled_min THEN
output_real:= scaled_min;
fail:= true;
else
fail:= false;
END_IF;
else
fail:= false;
END_IF;
If fail_hi & fail then
output_real:= scaled_max;
elsif fail then
output_real:= scaled_min;
end_if;
scaled_out:= output_real;
input_min:= raw_min_real;
input_max:= raw_max_real;
scaled_min:= eu_min_real;
scaled_max:= eu_max_real;
(*limit raw to 0 to 10,000*)
If raw_real < 0.0 then
input_real:= 0.0;
elsif raw_real > 10000.0 then
input_real:= 10000.0;
else
input_real:= raw_real;
end_if;
(* calculates the slope or rate; i.e. rise over the run *)
If ((input_max - input_min) <> 0.0) Then
rate:= (scaled_max - scaled_min) / (input_max - input_min);
Else
rate:= 0.0;
End_if;
(* calculates the offset *)
offset:= scaled_min - (input_min * rate);
(* performs the scaling calculation; i.e. y = mx+b *)
output_real:= (input_real * rate) + offset;
(* If the "Limit_En" flag is set then limit the output to within the scaling parameters *)
IF limit_overflow THEN
IF output_real > scaled_max THEN
output_real:= scaled_max;
fail:= true;
ELSIF output_real < scaled_min THEN
output_real:= scaled_min;
fail:= true;
else
fail:= false;
END_IF;
else
fail:= false;
END_IF;
If fail_hi & fail then
output_real:= scaled_max;
elsif fail then
output_real:= scaled_min;
end_if;
scaled_out:= output_real;