CXML

gen_sortx 


FORMAT

  GEN_SORTX

  ( order, status, type, size, n, x, incx, index )

Arguments

  order               character*1
                      On entry, order specifies the operation to be performed
                      as follows:

                      If order = 'A' or 'a', x is sorted in ascending
                      sequence

                      If order = 'D' or 'd', x is sorted in descending
                      sequence
                      On exit, order is unchanged.

  status              character*1
                      On entry, status specifies the operation to be
                      performed as follows:

                      If status = 'N' or 'n', the index vector is new (empty)
                      on input. Elements of data vector x are initially
                      accessed in sequential order.

                      If stat = 'O' or 'o', the index vector is old (full) on
                      input. Elements of data vector x are initially accessed
                      in the order specified by the index vector.
                      On exit, status is unchanged.

  type                character*1
                      On entry, type specifies the data type of data vector
                      x.  The following types are valid:

                      If type = 'B' or 'b', binary (unsigned integer)

                      If type = 'C' or 'c', character string

                      If type = 'I' or 'i', integer (signed)

                      If type = 'L' or 'l', logical - Fortran .TRUE. or
                      .FALSE.

                      If type = 'R' or 'r', IEEE floating point

                      If type = 'V' or 'v', VAXG floating point
                      On exit, type is unchanged.

  size                integer*4
                      On entry, size specifies the size, in bytes, of each
                      element of data vector x. Valid combinations of type
                      and size are shown below:

                      If type = 'B' or 'b' - size = { 1,2,4,8 }

                      If type = 'C' or 'c' - size = { 0 < size < 65536 }

                      If type = 'I' or 'i' - size = { 1,2,4,8 }

                      If type = 'L' or 'l' - size = { 1,2,4,8 }

                      If type = 'R' or 'r' - size = { 4,8,16 }

                      If type = 'V' or 'v' - size = { 4,8 }
                      On exit, size is unchanged.

  n                   integer*4
                      On entry, the length of the x vector.
                      On exit, n is unchanged.

  x                   data vector
                      On entry, a length n vector of data to be sorted.  Each
                      element of vector x is of type and size specified.
                      On exit, x is unchanged.

  incx                integer*4
                      On entry, incx specifies the distance between elements
                      of vector x. incx must be positive.
                      On exit, incx is unchanged.

  index               integer*4
                      On entry, vector index is ignored if status is 'N' or
                      'n', and used as an index vector for data vector x if
                      status is 'O' or 'o'.
                      On exit, vector index is overwritten by a permuted
                      vector of indices that may be used to access data
                      vector x in the sorted order specified by order.

Description

  GEN_SORTX is a general purpose, in memory, indexed sort routine. GEN_SORTX
  accepts the following FORTRAN data types:

          INTEGER*1, INTEGER*2, INTEGER*4, INTEGER*8

          LOGICAL*1, LOGICAL*2, LOGICAL*4, LOGICAL*8

          REAL*4, REAL*8, REAL*16

          CHARACTER*(*)

  GEN_SORTX also accepts unsigned "binary" integers of 1, 2, 4, or 8 byte
  sizes.

  An indexed radix algorithm is employed to sort the data. For all data types
  except REAL*16 and CHARACTER*(*), an N*16 byte work space is acquired from
  heap storage. For REAL*16 data, a work space of N*24 bytes is taken from
  heap storage. Heap work space required for CHARACTER data is of size
  N*((SIZE-1)/8+3)*8 bytes.

  GEN_SORTX does not return a sorted vector. Instead, it returns an index
  vector index, which may be used to access data in the collating sequence
  specified by order.

  GEN_SORTX is stable and may be used to perform multi-key record sorts.

Example

  REAL    DATA( 100 )
  INTEGER INDEX( 100 )
  N = 100
  CALL GEN_SORTX( 'Descend','New','Real',SIZEOF(DATA(1)),N,DATA,1,INDEX )
  DO I=1,N
     PRINT *,DATA(I),DATA( INDEX(I) )
  ENDDO

  This FORTRAN code sorts a 100 element single precision real vector by
  index, leaving the data unchanged. Unsorted and sorted data are printed in
  adjacent columns.

CXML Home Page

Index of CXML Routines