/*
@Node Header
@Next Macro

Code:       genregion.rexx
Author:     Russell Leighton
Revision:   16 Feb 1994

Comments:

Create  a  region  of  nodes  from  two  existing lines of nodes created by
'genline.rexx'.   The number of nodes generated between (and including) the
two  lines  can  be  set  with  the  variable 'jnodes'.  A gradient in node
spacing can be set with the variable 'jgrad'.  The four corner nodes should
be  selected  in  the  counterclockwise  direction starting with the lowest
numbered node.

@EndNode
@Node Macro
*/

options results

address ami2d

if ~show('l', "rexxmathlib.library") then do
    check = addlib('rexxmathlib.library',0,-30,0)
end

'save(t:temp.dat)'
do n=1 to 4
    'info(node)'
    fn = result
    parse var fn nd in junk
    if in = 0 then exit
    do m=1 to n-1
        if in < i.m then do
            do j=n-1 to m by -1
                j1 = j+1
                f.j1 = f.j
                i.j1 = i.j
            end
            leave
        end
    end
    f.m = fn
    i.m = in
end
parse var f.1 nd i1a x1a y1a
parse var f.2 nd i1b x1b y1b
parse var f.3 nd i2a x2a y2a
parse var f.4 nd i2b x2b y2b

in = i1b - i1a
jn = (i2a - i1a)/(in + 1)

ni = in
'get jnodes'
if length(result) > 0 then nj = result%1 - 1
else nj = jn
'set jnodes 'nj + 1
'get jgrad'
if length(result) > 0 then gj = result
else gj = 1

do i=0 to ni
    n1 = i1a + i
    n2 = i2a + i
    'info(node,'0 - n1')'
    parse var result nd id xa ya
    'info(node,'0 - n2')'
    parse var result nd id xb yb
    do j=1 to nj
        n = n1 + j*(ni + 1)
        xn = xa + (xb-xa)*pow(j/nj,gj)
        yn = ya + (yb-ya)*pow(j/nj,gj)
        'node('n','xn','yn')'
    end
end

exit
