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

Jade Williams

New Member

New Member

13 Apr 2017 11:32 AM
    On your blog page you reference a column sort routine, and give a link to download it at: I am unable to access the site. Help please!

    Mari Minari

    Veteran Member

    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

    ; 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: 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

    ; 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, 'Column index to sort on: ', sort_index
    print, 'Sorted (reverse) array:'
    print, b
    You are not authorized to post a reply.


    UAV Expo – A Growing Industry That’s Growing Up!


    This year’s UAV Expo had a strong agenda featuring a mix of sessions and speakers representing... more »

    What is a KMZ file?


    What is a KMZ file? A KMZ file is a placemark file used in Google Earth and Google Earth Pro. Since KMZ... more »


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