function WMSORT, array ;+ ;NAME: ; WMSORT ; ;PURPOSE: ; To create a increasing-order sorted array. This ; function works the same way as Matlab's SORT. ; ;CATEGORY: ; Math. ; ;CALLING SEQUENCE: ; Result = WMSORT(Array) ; ;INPUTS: ; Array: The data array. Array may be any type except string. ; ;OUTPUTS: ; WMSORT returns an increasing-order sorted array from the ; input data array. ; ;PROCEDURE: ; WMSORT = REVERSE(SORT(SORT(array))) ; ;EXAMPLE: ; >a=[[1,3,2],[6,3,4],[9,1,0]] ; >print, a ; 1 3 2 ; 6 3 4 ; 9 1 0 ; print, WMSORT(a) ; 1 1 0 ; 6 3 2 ; 9 3 4 ;MODIFICATION HISTORY: ; Amara Graps, BAER, December 1994. ; copyright (c) Amara Graps 1995, 1996. ;- t = SIZE(array) IF t(0) eq 1 THEN BEGIN ;1D array sorted = array(SORT(array)) ENDIF ELSE BEGIN ;Matrix numcol = t(1) ;number of columns numrow=t(2) ;number of rows ;Set up array corresponding to type CASE t(3) OF ;column vector containing all elements 1: sorted=BYTARR(numcol, numrow) ;byte 2: sorted=INTARR(numcol, numrow) ;integer 3: sorted=LONARR(numcol, numrow) ;long integer 4: sorted=FLTARR(numcol, numrow) ;float 5: sorted=DBLARR(numcol, numrow) ;double float ELSE: print, 'Do not know datatype in WMSORT.pro!' ENDCASE ;Step through the cols, and sort the columns (the way ;Matlab does it) FOR i = 0, numcol-1 DO BEGIN ;And sort in ascending order tt = array(i,*) sorted(i, 0) = TRANSPOSE(tt(SORT(tt))) END ;i ENDELSE RETURN, sorted END