<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://pickwiki.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Matash</id>
	<title>Pickwiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://pickwiki.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Matash"/>
	<link rel="alternate" type="text/html" href="https://pickwiki.org/index.php/Special:Contributions/Matash"/>
	<updated>2026-04-28T23:38:06Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://pickwiki.org/index.php?title=ASORT&amp;diff=2609</id>
		<title>ASORT</title>
		<link rel="alternate" type="text/html" href="https://pickwiki.org/index.php?title=ASORT&amp;diff=2609"/>
		<updated>2017-01-29T08:40:27Z</updated>

		<summary type="html">&lt;p&gt;Matash: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Back to [[BasicSource]]&lt;br /&gt;
&lt;br /&gt;
This is a utility to reorganise associated multivalues by sorting one of them and changing the order of all the others to match.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;PRE&amp;gt;&lt;br /&gt;
     SUBROUTINE ASORT(back, give, what, mode)&lt;br /&gt;
* ASORT() subroutine&lt;br /&gt;
* Copyright (c) 2007, Keith Robert Johnson, All Rights Reserved&lt;br /&gt;
*&lt;br /&gt;
* This program is free software in the public domain; you can&lt;br /&gt;
* redistribute it and/or modify it in any way you wish.&lt;br /&gt;
*&lt;br /&gt;
* This program is distributed in the hope that it will be useful,&lt;br /&gt;
* but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.&lt;br /&gt;
*&lt;br /&gt;
* START-HISTORY:&lt;br /&gt;
* 28 Aug 07  Program written.&lt;br /&gt;
* 29 Jan 16  Modified syntax to compile on D3/WIN Namely:&lt;br /&gt;
*            1. Moved SUBROUTINE command to line 1&lt;br /&gt;
*            2. Changed upcase command to OCONV equivalent&lt;br /&gt;
* END-HISTORY&lt;br /&gt;
*&lt;br /&gt;
* START-DESCRIPTION:&lt;br /&gt;
*&lt;br /&gt;
* This subroutine will reorganise a set of associated&lt;br /&gt;
* attributes by sorting the values in one of them and&lt;br /&gt;
* aligning all the other attributes to match that one.&lt;br /&gt;
* &lt;br /&gt;
* CALL ASORT(back, give, what, mode)&lt;br /&gt;
*&lt;br /&gt;
* back = Sorted array&lt;br /&gt;
* give = Unsorted array of Associated Multivalues&lt;br /&gt;
* what = Sort Attribute : Default &#039;1&#039;&lt;br /&gt;
* mode = Sort mode      : Default &#039;AL&#039;&lt;br /&gt;
*        A or AL = ascending - left justified&lt;br /&gt;
*             AR = ascending - right justified&lt;br /&gt;
*        D or DL = descending - left justified&lt;br /&gt;
*             DR = descending - right justified&lt;br /&gt;
*&lt;br /&gt;
* END-DESCRIPTION&lt;br /&gt;
*&lt;br /&gt;
* START-CODE&lt;br /&gt;
&lt;br /&gt;
* Set a default empty returned item&lt;br /&gt;
     back = &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Get sort attribute (default is 1)&lt;br /&gt;
     attr = what&lt;br /&gt;
     if not(num(attr)) then attr = 1&lt;br /&gt;
     attr = int(abs(attr))&lt;br /&gt;
     acnt = dcount(give,@am)&lt;br /&gt;
     if attr lt 1 or attr gt acnt then attr = 1&lt;br /&gt;
&lt;br /&gt;
* Get sort mode (default is &#039;AL&#039;)&lt;br /&gt;
     rank = oconv(mode,&amp;quot;MCU&amp;quot;)&lt;br /&gt;
     if not(index(&#039;[[/A/AL/AR/D/DL/DR]]/&#039;,&#039;/&#039;:rank:&#039;/&#039;,1)) then rank = &#039;AL&#039;&lt;br /&gt;
&lt;br /&gt;
* Initialise - note that sorted attribute defines the value count&lt;br /&gt;
     this = &#039;&#039; ; that = &#039;&#039;&lt;br /&gt;
     line = give&amp;lt;attr&amp;gt;&lt;br /&gt;
     vcnt = dcount(line,@vm)&lt;br /&gt;
&lt;br /&gt;
* Backward pass to preserve existing order for equal sorting values&lt;br /&gt;
     for vnum = vcnt to 1 step -1&lt;br /&gt;
        valu = line&amp;lt;1,vnum&amp;gt;&lt;br /&gt;
        locate(valu,this;posn;rank) then null&lt;br /&gt;
        ins valu before this&amp;lt;posn&amp;gt;&lt;br /&gt;
        ins vnum before that&amp;lt;posn&amp;gt;&lt;br /&gt;
     next vnum&lt;br /&gt;
&lt;br /&gt;
* Put all the returned attributes in the correct order&lt;br /&gt;
     for anum = 1 to acnt&lt;br /&gt;
        line = give&amp;lt;anum&amp;gt;&lt;br /&gt;
        for vnum = 1 to vcnt&lt;br /&gt;
           iota = line&amp;lt;1,that&amp;lt;vnum&amp;gt;&amp;gt;&lt;br /&gt;
           if iota ne &#039;&#039; or anum eq attr then back&amp;lt;anum,vnum&amp;gt; = iota&lt;br /&gt;
        next vnum&lt;br /&gt;
     next anum&lt;br /&gt;
&lt;br /&gt;
     return&lt;br /&gt;
&amp;lt;/PRE&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Comments ==&lt;br /&gt;
&lt;br /&gt;
2007-08-27 by Rex Gozar&amp;lt;br&amp;gt;&lt;br /&gt;
Similar functionality can be achieved using [[Row2Col]] and [[QuickSort]].  The difference is more pronounced in larger (10,000 plus) datasets, where I found that LOCATE tends to slow down.&lt;/div&gt;</summary>
		<author><name>Matash</name></author>
	</entry>
</feed>