!   TITLE:  arc_info.mac (CALCULATION)
!
!
!   OBJECTIVE:
!
!   Determine radius and other information for one or more arcs and store
!   it in an array.
!
!
!   COMMAND SYNTAX:
!
!                     (1)     (2)   (3)    (4)    (5)        (11)
!        arc_info, ArrayName, KPC, arc#1, arc#2, arc#3, ..., arc#9
!
!   ARGUMENTS:
!
!       (1) ArrayName =  The name of the array to write the arc information
!                        to.  The array will be created or overwritten if it
!                        already exists.  The format will be as specified
!                        below.  The default name, if left blank, will be
!                        'arc_info'.
!
!       (2) KPC       =  0 - Do not create a KP at arc center (default)
!                        1 - Create KP at arc center
!
!       (3) arc#1     =  Line number of arc.  Can be zero or blank to get
!                        info on the currently selected set of arcs.
!
!       (4) arc#2,... =  Additional arc numbers. Ignored if arg3 is
!                        zero or blank.
!
!
!   DESCRIPTION:
!
!   This macro will gather arc information for a specific arc or for the
!   currently selected set of arcs and store it in an array.  The 
!   information for each arc will be stored in its own column with
!   the following format:
!
!       (i,1)   Line # of the arc
!       (i,2)   KP # at arc end 1
!       (i,3)   KP # at arc end 2
!       (i,4)   KP # of new KP at center (0 if arg 2 = 0 or straight line)
!       (i,5)   Radius of arc (0 for a straight line)
!       (i,6)   X coordinate of arc center relative to active CS
!       (i,7)   Y coordinate of arc center relative to active CS
!       (i,8)   Z coordinate of arc center relative to active CS
!       (i,9)   Arc length
!       (i,10)  Sector angle in degrees
!
!   For splines the center will be based on an arc through each endpoint
!   and the midpoint.
!
!   NOTE: init_entity_num is called if KPC = 1
!
!

*get,prkey_,active,0,prkey
/nopr

aname_=arg1
kpc_=arg2
arc1_=arg3

NCOL_=10                            ! Number of columns in matrix

! Set defaults
*get,typAnam_,parm,aname_,type
*if,typAnam_,ne,3,then              ! 3 = char scalar
    aname_='arc_info'
*endif

*get,typAnam_,parm,%aname_%,type
*if,typAnam_,ne,-1,then             ! -1 = undefined parameter
    *set,%aname_%
*endif

*if,arc1_,eq,0,then
    entity_array,'l',aname_,,,,NCOL_,1
*else

    ecount=1

    *do,i_,4,11
        *if,arg%i_%,eq,0,then
            *exit
        *else
            ecount=ecount+1
        *endif
    *enddo

    *dim,%aname_%,array,ecount,NCOL_

    *do,i_,1,ecount
        %aname_%(i_,1)=arg%i_+2%
    *enddo
*endif

! Get the max KP in the model
cm,kcur_,kp
alls,all,kp
*get,km_,kp,,num,max
cmsel,s,kcur_

kpi_=1                  ! Index offset from km

*do,i_,1,ecount

    ! Current line #
    lnum_=%aname_%(i_,1)

    *get,knum1_,line,lnum_,kp,1
    %aname_%(i_,2)=knum1_

    *get,knum2_,line,lnum_,kp,2
    %aname_%(i_,3)=knum2_

    *get,len_,line,lnum_,leng

    %aname_%(i_,9)=len_

    *if,len_,eq,distkp(knum1_,knum2_),then
        ! Straight line
        %aname_%(i_,4)=0
        %aname_%(i_,5)=0
    *else
        ! KCENTER, Type, VAL1, VAL2, VAL3, VAL4, KPNEW
        kcenter,line,lnum_,,,,km_+kpi_

        %aname_%(i_,5)= distkp(knum1_,km_+kpi_)

        %aname_%(i_,6)=kx(km_+kpi_)
        %aname_%(i_,7)=ky(km_+kpi_)
        %aname_%(i_,8)=kz(km_+kpi_)

        %aname_%(i_,10)=len_/%aname_%(i_,5)*dconv

        *if,kpc_,eq,0,then
            %aname_%(i_,4)=0
            kdele,km_+kpi_
        *else
            %aname_%(i_,4)=km_+kpi_
            kpi_=kpi_+1
        *endif
    *endif
*enddo

*if,kpc_,ne,0,then
    init_entity_num
*endif

lplot

!
!
*set,arc1_
*set,aname_
*set,kpc_
*set,NCOL_
*set,typAnam_
*set,kcur_
*set,km_
*set,lnum_
*set,knum1_
*set,knum2_
*set,len_
*set,i_
*set,kpi_

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