!   TITLE:  ns_fillet_test.mac (MANAGEMENT)
!
!---------------------------------------------------------------------------
!   Rev -     RELEASED      01/30/2006      J. Rinaldi
!---------------------------------------------------------------------------
!
!   OBJECTIVE:
!
!   This sub-macro tests whether a fillet is standard or non-standard at the
!   junction of a pair of lines.
!
!
!   COMMAND SYNTAX:
!
!                         (1)     (2)    (3)     (4)
!       NS_FILLET_TEST, rad_fil, ln_#1, ln_#2, d_trans
!
!
!   ARGUMENTS:
!
!       (1) rad_fil = intended fillet radius
!
!       (2) ln_#1 = the 1st line
!
!       (3) ln_#2 = the 2nd line
!
!       (4) d_trans = boolean operator to transfer line numbers, lengths,
!                     angle, connecting (junction) KP and KP's at the endpoint
!                     of each line as data to parameters for future use:
!
!                       0 (or blank) = do not transfer data
!                       1 = transfer data
!
!
!   DESCRIPTION:
!
!   A NON-STANDARD FILLET is a fillet that is created at the junction between
!   2 lines where the resulting fillet is not tangent to one, or both, lines.
!   In this case, it passes through the endpoint of one, or both, lines, but
!   is not tangent at those points.
!
!   A STANDARD FILLET is at the junction of 2 lines such that the resulting
!   fillet is tangent to both lines at any point along the line lengths.
!
!   The algorithm determines if a standard fillet may be executed (use the
!   LFILLT command within the command macro LN_FILLET), or if the fillet has
!   to be constructed manually (non-standard).
!
!   The output is a boolean value (NON_STND) that states whether the fillet
!   is standard or non-standard:
!
!           non_stnd = 0, if the fillet is standard.
!
!           non_stnd = 1, if the fillet is non-standard.
!
!   Additionally, this macro is capable of assigning the line numbers, their
!   lengths, the angle between them and the KP's to a set of predefined
!   parameters. If the line transfer parameter (argument 4) is 0 (or blank),
!   the only output of this function is 'non_stnd'. If it is assigned 1, then
!   the line numbers and lengths are transferred to the following parameters:
!
!       a.) ln_long = longer line number between LN_#1 and LN_#2
!       b.) lng_long = longer line length between LN_#1 and LN_#2
!       c.) kp_long = KP number at the non-junction end of the longer line
!       d.) kplong_1 = KP number at the 1st end of the longer line
!       e.) kplong_2 = KP number at the 2nd end of the longer line
!       f.) dir_lng = longer line direction relative to the junction KP
!   
!       g.) ln_shrt = shorter line number between LN_#1 and LN_#2
!       h.) lng_shrt = shorter line length between LN_#1 and LN_#2
!       i.) kp_shrt = KP number at the non-junction end of the shorter line
!       j.) kpshrt_1 = KP number at the 1st end of the shorter line
!       k.) kpshrt_2 = KP number at the 2nd end of the shorter line
!       l.) dir_sht = shorter line direction relative to the junction KP
!   
!       m.) ang_lns = angle between lines
!       n.) jkp = KP number at the junction of the 2 lines
!
!
!---------------------------------------------------------------------------
!
*get,prkey_,active,0,prkey
/nopr
!
irad_=arg1
ln1_=arg2
ln2_=arg3
dtrans_=arg4
!
kp_intersect,ln1_,ln2_
!
lsel,s,line,,ln1_
lsel,a,line,,ln2_
ksll,s
ksel,u,kp,,ikp_
!
get_min_entity
get_max_entity
k1_=k_min
k2_=km
!
ksel,a,kp,,ikp_
angln_=(anglek(ikp_,k1_,k2_))*dconv
!
l_chk_=irad_/(tan((angln_/2)*rconv))
!
*get,lng_ln1_,line,ln1_,leng
*get,lng_ln2_,line,ln2_,leng
!
*if,dtrans_,eq,1,then
    *if,lng_ln1_,ge,lng_ln2_,then
        ln_long=ln1_
        lng_long=lng_ln1_
        ln_shrt=ln2_
        lng_shrt=lng_ln2_
    *elseif,lng_ln1_,lt,lng_ln2_,then
        ln_long=ln2_
        lng_long=lng_ln2_
        ln_shrt=ln1_
        lng_shrt=lng_ln1_
    *endif
    !
    ang_lns=angln_
    jkp=ikp_
    !
    lsel,s,line,,ln_long
    lsel,a,line,,ln_shrt
    ksel,s,kp,,k1_
    lslk,r,0
    !
    get_max_entity
    !
    *if,ln_long,eq,lm,then
        kp_long=k1_
        kp_shrt=k2_
    *elseif,ln_shrt,eq,lm,then
        kp_long=k2_
        kp_shrt=k1_
    *endif
    !
    *get,kplong_1,line,ln_long,kp,1
    *get,kplong_2,line,ln_long,kp,2
    !
    *get,kpshrt_1,line,ln_shrt,kp,1
    *get,kpshrt_2,line,ln_shrt,kp,2
    !
    *if,kplong_1,eq,kpshrt_1,then
        dir_lng=1
        dir_sht=1
    *elseif,kplong_1,eq,kpshrt_2,then
        dir_lng=1
        dir_sht=-1
    *elseif,kplong_2,eq,kpshrt_1,then
        dir_lng=-1
        dir_sht=1
    *elseif,kplong_2,eq,kpshrt_2,then
        dir_lng=-1
        dir_sht=-1
    *endif
*endif
!
*if,l_chk_,gt,lng_ln1_,or,l_chk_,gt,lng_ln2_,then
    non_stnd=1
*else
    non_stnd=0
*endif
!
init_entity_num
!
*set,irad_,
*set,ln1_,
*set,ln2_,
*set,ikp_,
*set,l_min,
*set,l_chk_,
*set,angln_,
*set,lng_ln1_,
*set,lng_ln2_,
*set,dtrans_,
*set,k1_,
*set,k2_,
!
*if,prkey_,eq,1,then
    /go
*endif