!   TITLE:  profile_cut.mac (SM_TOOL)
!
!
!
!   This sub-macro is used to create a circular cut with a particular
!   profile into a volume, thereby partitioning a volume into 2 separate
!   special shaped volumes, one within the other. This will allow for tran-
!   sition meshing from an irregular volume to a map meshable volume. The
!   partitioning may be created at varying angles or at 90 degree intervals
!   if preferred. (See PROFILE_BORE.MAC)
!
!   Parameters needed to be passed to this macro are:
!
!       A selected volume set
!
!       output from (in order):
!
!               ANG_ARRAY.MAC
!               RADIUS.MAC
!               DEPTH.MAC
!
!       opt = input options: 1,2 or 3
!
!       p1 = c.s. origin keypoint
!       p2 = c.s. +x axis keypoint
!       p3 = c.s. +y axis keypoint
!
!       xcutc = x component of cut volume local c.s.
!       ycutc = y component of cut volume local c.s.
!       zcutc = z component of cut volume local c.s.
!       rotxyc = 1st orientation angle (+x to +y) of 'reccutcs' c.s.
!       rotyzc = 2nd orientation angle (+y to +z) of 'reccutcs' c.s. 
!       rotzxc = 3rd orientation angle (+z to +x) of 'reccutcs' c.s. 
!
!       acs1= pre-existing Active Coordinate System 
!
!   The position and orientation of the volume cut c.s. is measured in
!   relation to the active c.s. for option 1. From this c.s., the local
!   coordinate system building these areas is placed. Option 2 allows
!   construction of the cut areas from a c.s. defined by 3 KP's. Lastly,
!   option 3 allows construction from a pre-existing c.s., acs1.  acs1
!   must be a cylindrical c.s.
!
!   The 3 options of input data are summarized as follows:
!
!       1.  Create local c.s. by CLOCAL, input:
!               xcutc, ycutc, zcutc, rotxyc, rotyzc, rotzxc
!
!
!       2.  Create local c.s. by CSKP, input:
!               p1, p2, p3
!
!
!       3.  Use pre-existing c.s., input: acs1
!
!
!
! PROFILE_CUT,opt,xcutc,ycutc,zcutc,rotxyc,rotyzc,rotzxc
!
!
! PROFILE_CUT,opt,p1,p2,p3
!
!
! PROFILE_CUT,opt,acs1
!
!
*get,prkey_,active,0,prkey
/nopr

cm,v2bcut,volu      ! selected volume(s) to be (2b) cut
!
opt=arg1
!
!
*if,opt,eq,1,then
    xcutc=arg2
    ycutc=arg3
    zcutc=arg4
    !
    rotxyc=arg5
    rotyzc=arg6
    rotzxc=arg7
*endif
!
*if,opt,eq,2,then
    p1=arg2
    p2=arg3
    p3=arg4
*endif
!
*if,opt,eq,3,then
    acs1=arg2
*endif
!
!
*if,opt,eq,1,then
    csn=csn+1
    circutcs=csn
    clocal,circutcs,1,xcutc,ycutc,zcutc,rotxyc,rotyzc,rotzxc
*endif
!
*if,opt,eq,2,then
    csn=csn+1
    circutcs=csn
    cskp,circutcs,1,p1,p2,p3
*endif
!
*if,opt,eq,3,then
    csys,acs1
*endif
!
!
num_lns=num_pnt-1
!
*do,i,1,num_pnt,1
    k,,rad(i,1),ang(1,1),-z(i,1)
*enddo
!
init_entity_num
!
*do,i,1,num_lns,1
    lstr,km-(num_lns-(i-1)),km-(num_lns-i)
*enddo
!
init_entity_num
!
*do,i,1,num_ang,1
    !
    *if,i,ne,num_ang,then
        !
        lsel,selv,loc,y,ang(i,1)
        max_value,'rad',num_rad
        lsel,r,loc,x,0,radm
        cm,lset1,line
        !
        k,,rad(1,1),ang(i+1,1),0
        !
        init_entity_num
        !
        l,kp(rad(1,1),ang(i,1),0),km
        !
        init_entity_num
        !
        adrag,lset1,,,,,,lm
        !
        init_entity_num
    *else
        lsel,selv,loc,y,ang(i,1)
        max_value,'rad',num_rad
        lsel,r,loc,x,0,radm
        cm,lset1,line
        !
        l,kp(rad(1,1),ang(i,1),0),kp(rad(1,1),ang(1,1),0)
        !
        init_entity_num
        !
        adrag,lset1,,,,,,lm
        !
        init_entity_num
    *endif
*enddo
!
nummrg,kp
!
init_entity_num
!
asel,selv,area,,am-(num_ang*num_lns-1),am
cm,aset1,area
!
init_entity_num
!
vsba,v2bcut,aset1,,delete,delete
!
init_entity_num
!
lplot
!
*set,xcutc, ! undefine parameters
*set,ycutc,
*set,zcutc,
*set,opt,
*set,acs1,
*set,rotxyc,
*set,rotyzc,
*set,rotzxc,
*set,ang(1),
*set,d_angle,
*set,z(1),
*set,rad(1),
*set,xx,

*if,prkey_,eq,1,then
    /go
*endif