!   TITLE:  create_sphere.mac (SM_TOOL)
!
!
!   OBJECTIVE:
!
!   This sub-macro creates a solid spherical segment (or complete sphere).
!
!
!   COMMAND SYNTAX:
!
!                         (1)     (2)     (3)    (4)      (5)     (6)
!        CREATE_SPHERE, radius, ang_inc, n_arc, st_ang, revang, numseg
!
!
!   ARGUMENTS:
!
!
!       (1) radius = the radius of the circle
!
!       (2) ang_inc = angle subtended by arc(s). When specifying this
!                     parameter, the algorithm will create the circle
!                     with a series of arcs subtending an angle of
!                     'ANG_INC'. Therefore, the value of this parameter
!                     must be an integral divisor of 360; i.e., 3,4,5,6,
!                     8,9,10,12,....etc. When this parameter is desired,
!                     'N_ARC' must be left blank.
!
!       (3) n_arc = The number of equal arc increments that the circle
!                   is constructed from.  If this argument is specified,
!                   then 'ANG_INC' is over-ridden and the circle is
!                   created by this number of equal arcs.
!
!       (4) st_ang = The start angle of the first arc used in the
!                    construction of the circle.
!
!       (5) revang = total angle of revolution of half-circle (segment of
!                    a sphere).
!
!       (6) numseg = number of volume (spherical)segments in the revolve
!                    angle (revang).
!
!
!   DESCRIPTION:
!
!   This sub-macro creates a semi-circle area from a set of circular profile
!   lines using the CREATE_CIRC_AREA command argument structure. The circular
!   segment is created in the XY-plane along the +x-axis. The circle may be
!   created with various arc angle increments or number of arcs within given
!   start and finish angles. 
!
!   The semi-circle may be revolved into a spherical segment or a complete
!   sphere. the revolve is started from the XY plane +X-axis, and revolves
!   counterclockwise, as looking down the +Y-axis (the Y axis is the axis of
!   revolve).
!   
!   When arguments 2, 3, 4, 5 and 6 are left blank, the algorithm defaults to
!   a complete sphere of 4-90 degree volume segments.
!
!
!
*get,prkey_,active,0,prkey
/nopr
!
rad_=arg1
anginc_=arg2
narc_=arg3
stang_=arg4
revang_=arg5
numseg_=arg6
!
*get,ccs_,active,,csys
!
*get,ccstyp_,cdsy,ccs_,attr,kcs
!
*if,ccstyp_,ne,1,then
    clocal,csn+50,1,0,0,0,0,0,0
*endif
!
finang_=stang_+360
!
*if,narc_,eq,0,then
    *if,anginc_,eq,0,then
        anginc_=90
        narc_=4
    *else
        narc_=abs(finang_-stang_)/anginc_
    *endif
*else
    anginc_=abs(finang_-stang_)/narc_
*endif
!
*if,revang_,eq,0,then
    revang_=360
*endif
!
*if,numseg_,eq,0,then
    numseg_=4
*endif
!
*do,ii_,0,narc_-1,1
    ang_=stang_+(ii_*anginc_)
    k,,rad_,ang_,0
*enddo
!
create_lines,1
!
create_area-lines
!
k,,1.1*rad_,90,0
k,,1.1*rad_,270,0
!
create_lines
!
asbl,am,lm,,delete,delete
init_entity_num
!
isolate_areas
asel,r,loc,x,0,rad_
asel,r,loc,y,90,270
asel,r,loc,z,0,0
adele,all,,,1
!
isolate_areas
asel,r,loc,x,0,rad_
asel,r,loc,y,-90,90
asel,r,loc,z,0,0
!
clocal,csn+51,0,0,0,0,0,0,0
clocal,csn+52,1,0,0,0,0,-90,0
!
revolve_aset,csn+52,revang_,numseg_
!
*if,ccstyp_,ne,1,then
    csdele,csn+50
    csdele,csn+51
    csdele,csn+52
*endif
!
csys,ccs_
!
!
*set,ii_
*set,rad_
*set,stang_
*set,finang_
*set,anginc_
*set,narc_
*set,ccs_
*set,ccstyp_
*set,ang_
*set,revang_
*set,numseg_
!
*if,prkey_,eq,1,then
    /go
*endif