suppose we have
region1   date   number
region2   date   number
etc

where region labels vary, many of each, and dates are a set of dates
that also have duplicates.

Suppose dates are julian dates, region labels just text.

Want sheet with rows by region, columns by date, sum of numbers

do it in a script. 
1. find start, end of input 1st column.
   get start of output area, add region, date label
2. save region, date. We assume monotonic increase.
3. loop over column.
   if region==save_region and date==save_date
     add number to output location
      (use the *U DBCMPFRM function or, within a command file, FILCMPFRM to
       compare text values of formulae. Note the W accumulator gets used as
       the output location of this function's comparison.)
4. If date changed, save new save_date, put number in next col
   of output area
5. if region changed re-init save_date, chnge save_region, goto 3
   after setup of output area. Want to go back to first date
   value when region changes.
6. go to next input row and if not at bottom of input go to 3

There is a compare formula function that will tell if region changed
and give 0 if same. Date compare can be an IF [ function. Test date
first, skip save to output area if different, then test region, if diffeent
update pointers.
A global input pointer can keep current row # on input.

A test that region is not blank could end loop also, so we need not depend
too strongly on getting end cell info. Need to be sure that blank value or
just P#0#0 default formula both count as null.

Output can also save each number in a 1 dim array and other functions
like sum[, avg[, std[, etc. can be used to report if sum of "number"
is not what we want. Compute result when save_date changes and save, including 
when region changes.

There can be a variety of such scripts to handle different input areas.
Since comparing formulae is built in, this kind of summary can be
computed at will. Good idea however to do an example. This kind of
thing is called pivot table in other spreadsheets. Because Analyrim
treats formulae and values as distinct, this kind of looping is harder
to do than it might otherwise be, but because there are functions
to compare or test formulae strings and return results as numeric,
this kind of loop can be done.

Still more weird data collection can be done in analogous ways. Computing
functions like sum[ where there are constraints on which input areas
may be used, for example, can be done by explicit tests within a loop.
Note too that the DS commands to sort display can sometimes be useful.

A loop that goes over a copy of a region and deletes rows not of interest
could be useful at times, as another case. Driving the comand thru short command
files allows a lot of flexibility.

Analyrim does not have any explicit "pivot" function separately though.
This is due to my lack of familiarity with it in general. The program
probably could use some more general "if" type functions in addition to
the ones that loop to beginning or go to somewhere if % is positive. However
multiple parts of a formula can be combined to gain some additional
functions. The fact that the "IF [" function calls the full-general
evaluation routine (except for IF) gives a fair bit of power you might
not expect.

In going over the manual I can see that AnalyRIM can fairly be described
as having one of the most powerful and disorganized feature sets around.
Its construction by accretion of new functions shows somewhat...things
were added in ways they could be parsed, and I never went over the
whole thing from scratch to try to get everything into some single
command paradigm. Remember it dates from 1982 and most of the "extra"
functions were novel to spreadsheets then, and I didn't want to
redo all the old functions that worked when adding others.

I will point out that unix and linux flavors of AnalyRIM are the most
recent, and were worked up from the Amiga version. Historic versions
were" pdp11 (rsx11m+), vms, msdos, amigados, sunos, linux in that order.
I hope I never gain have to devise an overlay tree such as was needed
for rsx11m (I initially used rsx11m+ with supervisor mode FCS, I/D space
separation, and thus needed little overlay work.) Fitting everything into
a 64k byte address space was hideously complex. That the rsx11m taskbuilder
allowed it to be done at all, and have a working program, was amazing but
maintaining it all was tough. The MSDOS versions had overlay problems too,
and a much less powerful linker, but the address space was a bit larger.

The Linux version, decades later, is much easier as even home computers
these days tend to have gigabytes of RAM and 64 bit address space,
so there is no need to work at squeezing everything into 256K bytes any more.
It can finally be compiled with really large matrices which get paged
in as needed.
Glenn Everhart
gce@gce.name  2018

Addendum, 2/18/2019
It occurred to me that postprocessing a saved spreadsheet would give access to
all formulae and values (if it was saved with both, using PPX). While it is
perhaps feasible to add a selector to functions like AVG[, SUM[, STD[ and so on,
so that only certain cells will be selected, this gets complex and would not
cover all one wants in a pivot function.
Something that reads a saved sheet and sorts labels, condensing information,
would work better.

Still better though would be a function (call it PIVOT) which would just
read info in the spreadsheet and generate an output area.
For example let's suppose a function PIVOT looks like

QPIV lbl1col,lbl2col,lbl3col;numcolleft:numcolright,ulcornercell,lengthdown,outareastartcell

where lnlncol are nnn (column nnn, Formula or Value)
numcol is Nstart-column:end-column, (just numbers)
ulcorner cell is upper left corner of area being pivoted (we will treat as collection
	of rows), lengthdown is number of rows in region being pivoted, and
	outareastartcell is upper left corner of area where results will go.

The function will look at rows starting at ulcornercell and down for lengthdown.
	For each row it will form a string of whatever is in lbl1col,lbl2col,...
	with some punctuation between, and see if this string exists in the
	output area. 
		If not, it will store the string in the output area and store the
	values in numcol (copy values for all the columns in the row being
	examioned) so the output area gets all these values. It will also initialize
	a cell in the output area beyond the numcol areas with 1, to hold a count
	of the rows in there.
		If so, it will increment the count cell value, and add the values
	in the numcol columns to columns found.

	This proceeds until lengthdown count is reached. That terminates it.

Result will be that outarea will have a bunch of labels for unique combinations of
	formulae or values (might put them in separate cells in output area - easier
	to use), with sum of values associated with the original rows that were
	being selected. Since the count is stored too, the average is easily computed
	for use.

While this does not handle computing standard deviation, skewness, or the like, it
gives some possibly useful summary capabilities. The formulae in cells will just be
P#0#0 so the values will not be altered by recalculation. Column labels can thus be
condensed and used together.

I might add that the RIM database might be a useful thing to consider for this kind
of data summary too, since it can select records in a database and constrain what
entries are selected. 

This gets implemented with command QPIV since parsing of P takes you to saving spreadsheet
command which is not so useful here. Also command should be

QPIV lbl1,lbl2,lbl3;numleft:numright,upperleftcorner,lengthdown,outareaupperleft

e.g

QPIV 2,3;4:4,b3,14,b16
if our data is in an area starting at b3, columns 2,3=user, quarter, col 4 is amoiunt
 

