[ncl-talk] Sorting an array depending on first column

Barry Lynn barry.h.lynn at gmail.com
Mon Dec 5 23:23:12 MST 2016


Hi:

If there is no standard NCL program, then...

One approach is to use WRAPIT and apply it to my_sort.f.

WRAPIT my_sort.f

This will create my_sort.so.

Place this before "begin."

external MY_SORT "./my_sort.so"


  begin

Then:

create three arrays

  r_list =new((/icnt/),float)
  i_list=new((/icnt/),integer)
  j_list=new((/icnt/),integer)

If you don't want a real value and two integers, then change my_sort.f to
the correct variable definitions, and modify your definitions above.

Within the program, call my_sort

MY_SORT::my_sort(i_cnt,r_list,i_list,j_list)

where i_cnt is the number of elements in each one dimensional array.

The first (r_list) will be sorted and the i_list, and j_list will tag along.

Barry Lynn

On Tue, Dec 6, 2016 at 7:59 AM, Abhik Santra <abhiksantra at tropmet.res.in>
wrote:

>
> Hi NCL users
>
> How can I sort an array based on its first column elements?
> For example, if
>
> Ain = (/ (/2,1,3/), (/6,2,4/), (/3,1,5/), (/1,7,4/) /)
>
> then how can I get
>
> Aout = (/ (/1,7,4/), (/2,1,3/), (/3,1,5/), (/6,2,4/) /) ?
>
> Any help would be greatly appreciated.
>
> Thanks,
> Abhik
>
> ****************************************
> Abhik Santra
> Postdoctoral Research Fellow
> Australian Bureau of Meteorology,
> Melbourne, Australia
> ****************************************
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>



-- 
Barry H. Lynn, Ph.D
Senior Lecturer,
The Institute of the Earth Science,
The Hebrew University of Jerusalem,
Givat Ram, Jerusalem 91904, Israel
Tel: 972 547 231 170
Fax: (972)-25662581

C.E.O, Weather It Is, LTD
Weather and Climate Focus
http://weather-it-is.com
Jerusalem, Israel
Local: 02 930 9525
Cell: 054 7 231 170
Int-IS: x972 2 930 9525
US 914 432 3108
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20161206/63f03687/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: my_sort.f
Type: application/octet-stream
Size: 2916 bytes
Desc: not available
Url : http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20161206/63f03687/attachment.obj 


More information about the ncl-talk mailing list