Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
smaller, simpler sorting for irregular number columns
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Larry  
View profile  
 More options Nov 18 2009, 3:11 pm
From: "Larry" <hayes_sm...@hotmail.com>
Date: Wed, 18 Nov 2009 14:11:25 -0600
Local: Wed, Nov 18 2009 3:11 pm
Subject: smaller, simpler sorting for irregular number columns

/***
This is the other part of the jagged column sorting macro set, this one
for number columns.
***/

// macro source starts here

// jigjagnumbsort.s - a simpler jaggedy number column sorter

<ctrlshift x><n> execmacro("jigjagnumbsort")

/***
Sometimes, simple is better.

This is a simpler, quicker version of the staggered column sorter of
earlier this year.

The macro sorts a column of numbers even if the columnis not
aligned. After the sort, the data in the column remains
in its original horizontal position on each line (not aligned).

The macro takes sort parameter on the command line, like so:

jigjagnumbsort (parameter)

like:

jigjagnumbsort -d

The default sort is ascending, but the -d parameter will sort
descending.

The command by itself defaults to ascending sort.

Assumptions:
1. column block is required;
2. sort decimals as well as whole numbers;
3. there should only be numbers, decimal points, and minus signs in the
column;
4. blank column lines will sort as normally to top or bottom depening on
   the sort order chosen.

If the macro happens to be used on a text column, the resulting sort
will as though right-aligned.

***/

proc main()

integer ob=0
integer tb=0

string p[2]=Lower(Query(MacroCmdLine))
string gt[255]=""

integer i=0
integer tl=0
integer dl=0
integer nt=0

// cmdline option or ask
if p==""
  p="-a"
  if ask("Sort Options: (-d)escending, (-a)scending, ESC=Quit",p)
     and length(p)
  else
    sound(40,40)
    warn("Cancelled.")
    goto ending
  endif
endif

// set sort option
if pos("d",p)
  p="-d"
else
  p="-a"
endif

// start work
if isblockmarked()==_column_
  gotoblockbegin()
  pushposition()
  ob=getbufferid()
  pushblock()
  // check for decimal
  if lfind(".","gl")
    // if one, use long method
    tb=createbuffer("numb"+rightstr(str(gettime()),4)+".jigjag")
    gotobufferid(tb)
    copyblock()
    unmarkblock()
    // get longest decimal length
    for i=1 to numlines()
      gotoline(i)
      // add one if not one
      if lfind(".","cg")==0
        endline()
        inserttext(".0")
        dl=1
      endif
      // get longest
      gt=trim(gettext(1,currlinelen()))
      nt=numtokens(gt,".")
      if gt<>""
        tl=length(gettoken(gt,".",nt))
        if tl>dl
          dl=tl
        endif
      endif
    endfor
    // make all decimals the same length
    for i=1 to numlines()
      gotoline(i)
      gt=trim(gettext(1,currlinelen()))
      nt=numtokens(gt,".")
      if gt<>""
        tl=length(gettoken(gt,".",nt))
        if tl<dl
          endline()
          inserttext(format("0":-(dl-tl):"0"))
        endif
      endif
    endfor
    begfile()
    markcolumn(1,1,numlines(),longestlineinbuffer())
    gotobufferid(ob)
  endif
  popposition()
  copyblock()
  if tb
    abandonfile(tb)
  endif

  // do the sort
  execmacro("adjust right")
  while lreplace(" -","- ","ngl") // put minus to left column in block
  endwhile
  execmacro("sort "+p)
  delblock()
  popblock()
else
  sound(40,40)
  warn("No Block. Ending.")
endif
sound(11000,30)
message("(jigjagnumbsort) Finished.")

goto ending
ending:

end
// macro source ends here

  jigjagnumbsort.mac
1K Download

  jigjagnumbsort.s
3K Download

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google