<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi Abhik,<br>
<br>
you can use NCLs function <i>dim_pqsort </i>to sort the array by
the first column.<br>
<br>
<font color="#3333ff"><tt>begin</tt><tt><br>
</tt><tt> Ain = (/ (/2,1,3/), (/6,2,4/), (/3,1,5/), (/1,7,4/) /)</tt><tt><br>
</tt><tt><br>
</tt><tt>;-- criteria is to sort the array Ain by increasing of
the first column</tt><tt><br>
</tt><tt> cols_0 = Ain(:,0) ;-- get first
columns of each row</tt><tt><br>
</tt><tt> i0 = dim_pqsort(cols_0,2) ;-- sorting
by increasing and overwrite cols_0</tt><tt> return sorted
indices i0</tt><tt><br>
</tt><tt><br>
;-- resort Ain</tt><tt><br>
</tt><tt> Aout = Ain(i0,:) ;-- use
sorted indices of first column to sort the complete array</tt><tt><br>
</tt><tt><br>
</tt><tt>;-- print the new array in a nicer way</tt><tt><br>
</tt><tt> opt = True</tt><tt><br>
</tt><tt> opt@title = "Sort array by first column of each row"</tt><tt><br>
</tt><tt> write_matrix(Aout,"3I4",opt)</tt><tt><br>
</tt><tt><br>
</tt><tt>end</tt></font><br>
<br>
This will print Aout<br>
<br>
<font color="#3333ff"><tt> Sort array by first column of each row</tt><tt><br>
</tt><tt> </tt><tt><br>
</tt><tt> 1 7 4</tt><tt><br>
</tt><tt> 2 1 3</tt><tt><br>
</tt><tt> 3 1 5</tt><tt><br>
</tt><tt> 6 2 4</tt></font><br>
<br>
Bye,<br>
Karin<br>
<br>
<div class="moz-cite-prefix">Am 06.12.16 um 06:59 schrieb Abhik
Santra:<br>
</div>
<blockquote
cite="mid:332769254.214242.1481003991324.JavaMail.root@mail.tropmet.res.in"
type="cite">
<pre wrap="">
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
<a class="moz-txt-link-abbreviated" href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a>
List instructions, subscriber options, unsubscribe:
<a class="moz-txt-link-freetext" href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a>
</pre>
</blockquote>
<br>
</body>
</html>