FP_DATA_SORT

Sort data in data table

This FP instruction sorts values (with +/- sign) in a data table in ascending or descending order.

NOTE

This instruction sorts 1-dimensional arrays only. It does not work with 2-dimensional or 3-dimensional arrays.

Parameters

Input

s1_Start (INT, DINT, UINT, UDINT, REAL, LREAL)

Starting area of data table to be sorted

s2_End (INT, DINT, UINT, UDINT, REAL, LREAL)

Ending area of data table to be sorted

s3_Control (INT, DINT, UINT, UDINT, REAL, LREAL)

Specifies sorting order:

  • 0 = ascending

  • 1 = descending

Remarks

  • The data are sorted via bubble sort in the order specified according to the value entered at input s3_Control. Since the number of word comparisons increases in proportion to the square of the number of words, the sorting process can take some time when there is a large number of words. When the address of the variable at input s1_Start = s2_End, no sorting takes place.

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • if the area specified using the index modifier exceeds the limit.

  • if the address of the variable at input s1_Start > s2_End

  • if s1_Start and s2_End belong to different data areas.

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • if the area specified using the index modifier exceeds the limit.

  • if the address of the variable at input s1_Start > s2_End

  • if s1_Start and s2_End belong to different data areas.

Example

POU header

All input and output variables used for programming this function have been declared in the POU header.The same POU header is used for all programming languages.

	VAR
		bStart: BOOL:=FALSE;
			(*activates the function*)
		adiDataField: ARRAY [0..4] OF DINT:=[4,7,-32,13,5];
			(*result after a 0->1 leading
edge from start: [-32,4,5,7,13]*)
		iOrder: INT:=0;
			(*which way to sort:
0 means ascending order
1 means descending order*)
	END_VAR

POU body

When the variable bStart is set to TRUE, the function is carried out.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 7 ;
        NETWORK_BODY
B(B_F,FP_DATA_SORT!,,11,1,20,7,,?DEN?Ds1_Start?Ds2_End?Ds3_Control?AENO);
B(B_CONTACT,,bStart,5,2,7,4,);
B(B_VARIN,,adiDataField[0],9,3,11,5,);
B(B_VARIN,,adiDataField[4],9,4,11,6,);
B(B_VARIN,,iOrder,9,5,11,7,);
L(1,3,5,3);
L(7,3,11,3);
L(1,0,1,7);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

If (bStart) then
    FP_DATA_SORT(s1_Start := adiDataField[0], 
                 s2_End := adiDataField[4], 
                 s3_Control := iOrder);
End_if;

Modified on: 2024-03-01Feedback on this pagePanasonic hotline