SortSpa (Sort Array Elements)

The SortSpa function is used to sort the elements of an array in ascending order.

Syntax

SortSpa ( Dest, Swath, Source, [ Dimension ] (optional) )

Remarks

The results from SortSpa can be stored in the same variable or a different variable. If the results are stored in a different variable, the array is copied from Source and stored into Dest prior to sorting. If the Source and Dest variables are the same, then the sorting is done in place. ClosedNAN Not a number. A data word indicating a measurement or processing error. Voltage overrange, SDI-12 sensor error, and undefined mathematical results can produce NAN.s and ±ClosedINF A data word indicating the result of a function is infinite or undefined.s are sorted to the top of the array (that is, the most minimum value).

The variables for Dest and Source must be declared as the same type (ClosedFP2 Two-byte floating-point data type. Default datalogger data type for stored data. While IEEE four-byte floating point is used for variables and internal calculations, FP2 is adequate for most stored data. FP2 provides three or four significant digits of resolution, and requires half the memory as IEEE4., ClosedIEEE Four-byte, floating-point data type. IEEE Standard 754. Same format as Float., or ClosedLong Data type used when declaring a variable as an integer.).

Parameters

Dest (Destination)

A variable in which to store the results of the function. Dest must be dimensioned to the size of the swath.

Type: Variable

Swath

The number of elements in the array to include in the values to be sorted.

Type: Constant

Source

The first variable in the array for which the sort should be performed.

When using the optional dimension parameter with a two- or three-dimensional array, Source also determines the row, column, or plane to sort on. For example, in a two-dimensional array Source(1,2) will sort on the second column of the array, keeping the rows intact. For example:

Public Result (3,2), Source(3,2)

SortSpa (Result(1,1),3,Source(1,2),2) 'sort 3 rows of 2-D array by 2nd column

For a three-dimensional array, the example below demonstrates sorting the planes of the array and then using a For/Next loop to sort the rows of each plane:

Public Result(5,4,3), Source(5,4,3)

SortSpa(Result(1,1,1),5,Source(1,1,1),3) 'sort the planes

Dim I

For i = 1 To 5

 SortSpa (Result6(i,1,1),4,Result5(i,1,1),2) 'sort the rows of each plane

Next i

Type: Variable

Optional Parameter

Dimension

An optional parameter that is used to specify the dimension to perform the sort on, in a multi-dimensional array. Valid options are:

Type: Constant