-------------------------------------
SORTING in AMIGADOS: Order from Chaos
By Elisa Artois, Rochester NY
-----------------------------
     Beginners, don't tune out. I'm going to show you how to
sort computer data alphabetically and numerically. Experts,
stick around if you haven't learned how to use AMigaDOS for
sorting. But first this important message:
     Sorting puts different items in order. While it seems
this order may be alphabetical or numerical, the items are
being ASCII-ized. ASCII stands for American Standard Code for
Information Interchange. Every character on the keyboard and
some not on it have different ASCII numbers. A sort works
by sifting through a list of items and reordering the items
according to the ASCII values found.
     In Amiga Basic you can see the different ASCII values
of the main characters used by doing the following in the
immediate mode (at left of screen):
     Type
     WIDTH 60
     and press Return.
     Then type
FOR X=48 to 122: PRINT X;CHR$(X)" ";: NEXT
     and press Return. You will see a screen display of each
ASCII number and its character, running from 48 to 122. It
is possible to write an Amiga Basic, C, or other programming
languages that sort data. JUMPDISK's editors inform me
such programs are upcoming. However, AmigaDOS already
contains a sorting function which even a beginner can use to
learn fundamentals which will be useful when he or she
progresses to a higher level. And even seasoned programmers
can use the AmigaDODS sort to create batch files to automate
the sorting of a large set of files. I'll go far enough with
my explanation (I hope) to leave the beginner wanting to
pursue this method.
     I'm going to suggest making this a one-drive affair. So
the first thing to do is make a copy of the Workbench disk,
and it is that copy which will hold all the needed files --
both programming and data files. When the copy is made,
do not copy-protect it. Leave the tab on the disk in its
unprotected state so material can be saved to it.
     Please don't proceed without using a Workbench disk
copy. All coming references to Workbench mean the Copy of
Workbench disk you have created.
     If you already know how to get into the CLI (Command
Line Interfact), skip forward past the dashed line. If not,
keep reading here.
     The Workbench disk comes with the CLI closed. To open
it:
     -- Insert the Workbench disk and quickly click the left
mouse button twice on its icon. This opens the Workbench
window.
     -- In the Workbench window, click twice on the
Preferences icon. This opens the Preferences window.
     -- On the Preferences screen, at lower left, you will
see the words CLI ON OFF. Click the word ON so it turns
orange. At right of screen, click the word SAVE so this
action is made a permanent part of the Workbench disk. This
action also returns you to the Workbench screen.
     Now, whenever you open this disk's Workbench window,
you would open the CLI in this way:
     -- In the Workbench window, click the SYSTEM icon.
     -- When the SYSTEM window opens, click the CLI icon.
This opens the CLI window, and you are ready to do some
sorting.

-----------------------------------------------------------
     In the CLI window you will see the prompt
1>
followed by an orange block cursor. From here you can get
into the AmigaDOS editing function. Type
ED LIST
and press Return.
     This will create an editable file named LIST.
(EDITOR'S NOTE: For a fuller explanation of this
method, which offers a good word processing system, see
JUMPDISK #1 for the article ED: THE WORD PROCESSOR IN YOUR
AMIGA.)
     A screen opens, and on it you may type just as you
would in a regular word processing program. You can move
the orange cursor with the arrow keys. You end a line by
pressing Return. And you delete mis-strikes by putting the
cursor over the offending character and tapping the DEL key.
     As an experiment, you're going to type the following
three names, just as they're given below:
Azevedo*Tom
Aardvark*Allen
Allison*Evelyn
     At the end of each name, press Return. When the work is
complete, press the ESC key, which causes an asterisk (*) to
appear at the bottom of the screen. Type X and press Return.
This saves the file on the disk as a file named LIST and
exits back to the CLI window.
     Now you will enter a few commands in the CLI window,
pressing Return after each. Here they are:

SORT LIST TO NEWLIST
DELETE LIST
RENAME NEWLIST TO LIST

     And that's all there is to it. Here's an explanation:
SORT LIST TO NEWLIST - Puts the names in LIST in order and
saves the new version to a disk file named NEWLIST.
DELETE LIST - Kills the original version of the file.
RENAME NEWLIST TO LIST - Puts the new list in a file with
the same name it had at the start.
     You can see the alphabetized version by again typing
ED LIST
and pressing Return. Note that the new version may have
added blank line at the top. If so, it can be deleted by
putting the cursor anywhere in the blank line and pressing
the CTRL and B keys together. To exit the file, again type
ESC and answer the asterisk prompt with an X and a press of
Return.
     This is a simple way to sort lists of names. In the
format I offered, the asterisk between the two names isn't
necessary. It simply delineates. And in Amiga Basic programs
it can be an important character used to reverse last and
first names in printing.
     Were you to attempt to sort a list of items beginning
with numbers, you should remember that a computer sort works
by ASCII-izing, and because of this you must enter numbers
differently than you would names. For example, let's say
that for a month you add items to an ED file for checks that
have come back from the bank. Each item is begun with the
number of the check. You must leave what is called a
"trailing blank" for these numbers. Here are examples of
right and wrong list methods:

Right    Wrong
-----    ----
   1     1
 234     234
  10     10
   5     5
1020     1020

     The ASCII sort compares characters from left to right.
Wherever it finds a difference, it assigns sort weights
accordingly.
     Another important thing to remember is that the sort
depends on the STACK in its work. If the stack is set too
low (default is 4000) and a sort file contains too much,
the system will crash. You can safely sort up to about 200
names without resetting the STACK.
     Resetting the STACK is a matter of guesswork. It's a
command typed at the CLI prompt. Try
STACK 8000
for larger files and see what happens. Save all files to
disk first, and don't call me if it doesn't work.
     So far I've covered simple sorting. I'm told Matthew
Leeds has written something on batch files (ED: Right, it's
in this issue.), so I won't steal his thunder. However, I
will tell you how to set up a simple batch file that will
sort multiple files.
     To start, let's assume you're setting up a series of
files holding addresses. For an alphabetical file, each
address would be put in a separate file according to the
first letter of the addressee's last name. For reasons I
won't go into, all the material for each address has to be
in one line, as in:
Azevedo*Tom*124 Elm*Stonewell AZ 82010
Suffice to say, separating these elements by asterisks will
be helpful in a Basic program for rearranging and printing
various elements of the string. Here, it's just given as an
example.
     In turn, as example, from the CLI I want you to create
or work on two files, an A file and a B file.
     Type
ED A
and type a few brief names beginning with A. Exit by
pressing the ESC key and typing X to answer the asterisk
prompt.
     Then type
ED B
and do the same with some names beginning with B.
     Back in the CLI, you will create a simple batch file
for sorting multiple files. To start type,
ED S/ORDER
and press Return.  When the screen for S/ORDER appears, type
the following, pressing Return after each line:
SORT A TO NEWA
DELETE A
RENAME NEWA TO A
SORT B TO NEWB
DELETE B
RENAME NEWB TO B

     When you are finished, save the file and exit to the
CLI by pressing the ESC key and answering the asterisk
prompt with an X.
     Back in the CLI, type
EXECUTE S/ORDER
and press return.
     Nothing shows, but the batch file S/ORDER is doing in
turn to the A and B files what you did manually from the CLI
before.
     Now, without any more hand-holding from me, you can
create a batch file which sorts 26 files, from A to Z.
     More realistically and more work is to create a file
system with three-character codes, in order to more
accurately reflect alphabetical spread of names. Something
like AAA ABA ALA . . . ZZZ.
     It would be simpler for an Amiga Basic programmer to
set up a Basic entry system of names, which assigns the name
to a file according to whether its ASCII value is equal to
or more than one file name and less than the next. This is
getting beyond beginners, so this is where I'll stop, secure
in the knowledge I've done my job and perhaps suggested
possibilities for more experienced programmers.

END OF TEXT




