<?xml version="1.0" encoding="UTF-8"?>

<UserFunctionMgr>
   <UserFunction
       Expression="//Equivalent of a Scale with Parameters PLC Block. Input is scaled linearly using the input min and max and the output min and max. &#13;&#10;// Example: a 4-20mA transducer representing 0-5000 PSI&#13;&#10;// The call to this function would be that myPSI := SCP(my_mA, 4,20,0,5000)&#13;&#10;&#13;&#10;FUNCTION SCP : REAL&#10;&#10;&#9;VAR_INPUT&#13;&#10;&#9;&#9;InVal : REAL;&#13;&#10;&#9;&#9;IN_MIN : REAL;&#13;&#10;&#9;&#9;IN_MAX : REAL;&#13;&#10;&#9;&#9;OUT_MIN : REAL;&#13;&#10;&#9;&#9;OUT_MAX : REAL;&#13;&#10;&#9;END_VAR&#13;&#10;&#10;&#9;VAR&#13;&#10;&#9;&#9;RISE : REAL;&#13;&#10;&#9;&#9;RUN : REAL;&#13;&#10;&#9;&#9;SLOPE : REAL;&#13;&#10;&#9;&#9;INTERCEPT :REAL;&#13;&#10;&#9;END_VAR&#13;&#10;&#13;&#10;&#9;RISE := OUT_MAX - OUT_MIN;&#9;&#13;&#10;&#9;RUN:= IN_MAX - IN_MIN;&#13;&#10;&#9;SLOPE := RISE / RUN;&#13;&#10;&#9;INTERCEPT := OUT_MAX - (SLOPE * IN_MAX);&#13;&#10;&#13;&#10;&#9;SCP := (SLOPE * InVal) + INTERCEPT;&#13;&#10;&#9;&#13;&#10;&#9;//Same results using only VAR_INPUT values, not requireing the local user function defined variables&#13;&#10;&#9;//SCP := (InVal * ((OUT_MAX - OUT_MIN) / ( IN_MAX - IN_MIN))) &#32;&#32;+ &#32;&#32;&#32;( OUT_MAX - ((OUT_MAX - OUT_MIN) / ( IN_MAX - IN_MIN)) * IN_MAX);&#10;&#10;END_FUNCTION"/>
</UserFunctionMgr>
