!   TITLE:  involute_curve.mac (SM_TOOL)
!
!
!   OBJECTIVE:
!
!   This sub-macro creates an involute curve, or set of curves, eminating
!   from a specified point, or set of points, on a base circle.
!
!
!   COMMAND SYNTAX:
!
!                        (1)   (2)    (3)    (4)    (5)     (6)    (7)    (8)
!        INVOLUTE_CURVE, cs, d_base, d_out, n_pts, a_init, a_fin, a_inc, zpos
!
!
!   ARGUMENTS:
!
!       (1) cs = coordinate system to build curve(s) relative to.
!
!       (2) d_base = diameter of the base circle (1st point of the/each curve).
!
!       (3) d_out = outer diameter of curve endpoint(s).
!
!       (4) n_pts = number of points forming the/each curve.
!
!       (5) a_init = initial angle of curve set. This is the angle of the
!                    1st point of the 1st involute curve of the set.
!
!       (6) a_fin = final angle of curve set. This is the angle of the
!                   1st point of the last involute curve of the set.
!
!       (7) a_inc = incremental angle between each involute curve in the set.
!
!       (8) zpos = position along Z axis of the plane of the curve.
!
!
!   DESCRIPTION:
!
!   A single involute curve may be created, or a set of curves may be created.
!   If more than one curve is created, then the curves will be angularly spaced
!   the number of degrees as specified in argument 7 (a_inc), within a total
!   angular range between argument 5 (a_init) and argument 6 (a_fin). The ang-
!   ular spacing is the angular distance between the initial (1st) point of
!   each curve (the points lying on the base circle).
!
!   If a single curve at a specified angle is desired, then specify the desired
!   angle of the curve in argument 5 (a_init) and in argument 6 (a_fin), and
!   set argument 7 (a_inc) to 0 (or blank).
!
!   The curve enpoints are created at an inner diameter (d_base), with the
!   outer endpoint at the outer diameter (d_out). The curve is created using
!   a B-spline (BSPLIN command) curve fit to a set of keypoints. The number
!   of points that the curve is fit to is specified in argument 4 (n_pts).
!   This is the number of equally spaced radii between the inner diameter
!   (d_base) and outer diamater (d_out). This allows the user to control the
!   resolution of the curve-fit.
!
!   The curve(s) are created relative to a specified coordinate system. The
!   radii of the curve points are measured from the Z axis, with the curve(s)
!   lying in a plane parallel to the XY plane of the coordinate system. The
!   coordinate system specified in argument 1 (cs) can be of any type, i.e.,
!   cartesian, cylindrical, spherical or toroidal.
!
!
!
iccs_=arg1
dbc_=arg2
dout_=arg3
npts_=arg4
ainit_=arg5
afin_=arg6
ainc_=arg7
z_=arg8
!
*get,acs_,active,,csys
!
csys,iccs_
!
*get,iccstyp_,cdsy,iccs_,attr,kcs
!
*if,iccstyp_,ne,1,then
    clocal,csn+50,1,0,0,0,0,0,0
    iccs_=csn+50
*endif
!
*if,afin_,ne,360,then
    afin_=afin_
*elseif,afin_,eq,360,then
    afin_=afin_-ainc_
*endif
!
*do,jj_,ainit_,afin_,ainc_
    r0_=dbc_/2
    ro_=dout_/2
    !
    r_inc=(ro_-r0_)/npts_
    r_=r0_
    !
    strtang_=jj_
    !
    *do,kk_,1,npts_+2,1
        phi_=sqrt((r_/r0_)**2-1)
        beta_=((strtang_*rconv)-phi_+atan(phi_))*dconv
        !
        k,,r_,beta_,z_
        r_=r_+r_inc
    *enddo
    !
    init_entity_num
    ksll,u
    bsplin,all,,,,,,0,-1
    init_entity_num
    kdele,km-npts_,km-1,1
    init_entity_num
*enddo
!
csys,acs_
!
*if,iccstyp_,ne,1,then
    csdele,iccs_
*endif
!
lplot
!
*set,iccs_,
*set,iccstyp_,
*set,acs_,
*set,dbc_,
*set,dout_,
*set,npts_,
*set,ainit_,
*set,afin_,
*set,ainc_,
*set,z_,
*set,jj_,
*set,kk_,
*set,strtang_,
*set,phi_,
*set,beta_,
*set,r_,
*set,r_inc,
*set,r0_,
*set,ro_,