PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 17 Apr 2017 11:20 AM by  Mari Minari
colsort.pro
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

Jade Williams



New Member


Posts:
New Member


--
13 Apr 2017 11:32 AM
    On your blog page http://www.harrisgeospatial.com/Com...utine.aspx you reference a column sort routine, and give a link to download it at: ftp://download.exelisvis.com/groups/esg/blog/colsort.pro I am unable to access the site. Help please!

    Mari Minari



    Veteran Member


    Posts:1842
    Veteran Member


    --
    17 Apr 2017 11:20 AM
    It looks like that blog link is broken since it is from 2013. However, I was able to track down the code. You will need to copy and paste this into IDL: and name it colsort.pro:

    ========================================================
    ; docformat = 'rst'
    ;+
    ; :description:
    ; Applies SORT (ascending order) to a selected column of a two-dimensional
    ; array, then applies this sort to all the columns of the array. (It's like
    ; doing a column sort in Excel.)
    ;
    ; :params:
    ; array: in, required, type=numeric
    ; A two-dimensional numeric array.
    ; column_index: in, required, type=integer
    ; The column index over which sorting is performed.
    ;
    ; :keywords:
    ; reverse_sort: in, optional, type=boolean
    ; Set this keyword to do a reverse sort (descending order) on the
    ; elements of the selected column.
    ;
    ; :author:
    ; Mark Piper, ITT VIS, 2009
    ;
    ; :version:
    ; $Id: colsort.pro 182 2009-11-03 21:44:28Z mpiper $
    ;-
    function colsort, array, column_index, reverse_sort=rsort
    compile_opt idl2
    on_error, 2

    info = size(array, /structure)

    ; Test dimensions of input array.
    if info.n_dimensions ne 2 then $
    message, 'Input array must have two dimensions.'

    ; Ensure the sorting index is within a valid range.
    if n_elements(column_index) eq 0 then $
    message, 'Must pass a column index for sorting.'
    n_columns = info.dimensions[0]
    _column_index = (column_index > 0) < (n_columns-1)

    ; Sort the desired column.
    col_sort_index = sort(array[_column_index,*])
    if keyword_set(rsort) then $
    col_sort_index = reverse(col_sort_index)

    ; Apply the sort to each column of the array.
    sorted_array = array
    for i=0, n_columns-1 do $
    sorted_array[i,*] = (array[i,*])[col_sort_index]

    return, sorted_array
    end


    ;+
    ; Example main. Examine the results in the Console.
    ;-
    a = round(randomu(123, 5, 6) * 20.0)
    sort_index = 1
    b = colsort(a, sort_index, /reverse_sort)
    print, 'Original array:'
    print, a
    print
    print, 'Column index to sort on: ', sort_index
    print
    print, 'Sorted (reverse) array:'
    print, b
    end
    You are not authorized to post a reply.


    MOST RECENT

    GISCafe Interviews Stuart Blundell at GEOINT

    7/21/2017

    GISCafe – July 21, 2017 – GISCafe interviews Harris' Stuart Blundell, Director of Strategy and... more »

    SAR Imagery for Critical Decision Making

    7/20/2017

    Our ability to assist emergency services and national security decision makers by extracting meaningful... more »

    SIGN UP & STAY INFORMED

    Sign up to receive the latest news, events, technologies and special offers.

    SIGN ME UP