!   TITLE:  ln_group.mac (MANAGEMENT)
!
!
!   OBJECTIVE:
!
!   This sub-macro selects a set of lines, from a currently selected set of
!   lines, that connect (form a continuous path between) 2 specified keypoints.
!
!
!   COMMAND SYNTAX:
!
!                   (1)   (2)   (3)
!        LN_GROUP,  skp,  dkp,  ekp
!
!
!   ARGUMENTS:
!
!       (1) skp = start keypoint (KP) in the line sequence
!
!       (2) dkp = direction keypoint. This is the next KP, in sequence, in the
!                 desired direction of travel towards the end KP (EKP).
!
!       (3) ekp = end keypoint in the line sequence
!
!
!   DESCRIPTION:
!
!   This macro may be used to select a series of lines that create a complex
!   geometric boundary, and therefore make it difficult to select by location
!   or by line number.
!
!   Starting from the start KP, the first line selected is the line terminated
!   by the start KP (skp) and the direction KP (dkp). The direction KP (2nd
!   argument) is the next keypoint in sequence in the desired direction towards
!   the end KP. This establishes the direction of selection and continually chain
!   selects lines until reaching the end keypoint.
!
!   The selected line set may form a closed loop or be an open loop. However,
!   the selected set of lines must contain no branching points, i.e., no key-
!   points that branch off into more than one line. Therefore, the selected
!   line set must form a continuous closed or open chain without any branching
!   points.
!
!
!
*get,prkey_,active,0,prkey
/nopr
!
skp_=arg1
dkp_=arg2
ekp_=arg3
!
cm,CL01_,line                           ! create selected line group
cm,CK01_,kp                             ! create selected KP group
*get,lcnt01_,line,,count                ! selected group line count
!
ksel,s,kp,,skp_
ksel,a,kp,,dkp_
lslk,r,1
cm,lngrp_,line                          ! create line group
get_max_entity
ljs2g_=lm                               ! (l)ine (j)ust (s)ent (2)to the (g)roup
!
*if,dkp_,eq,ekp_,then
    stpsel_=1                           ! stop selection routine
*else
    stpsel_=0                           ! do not stop selection routine
*endif
!
*if,stpsel_,eq,0,then
    *get,kp1l1_,line,ljs2g_,kp,1
    *get,kp2l1_,line,ljs2g_,kp,2
    !
    *if,kp1l1_,eq,dkp_,then             ! establish junction KP
        jkp_=kp1l1_
    *else
        jkp_=kp2l1_
    *endif
    !
    *do,z__,1,lcnt01_,1
        ksel,s,kp,,jkp_
        cmsel,s,CL01_
        lslk,r,0
        lsel,u,line,,ljs2g_
        get_max_entity
        ljs2g_=lm
        cmsel,s,lngrp_
        lsel,a,line,,ljs2g_
        cm,lngrp_,line
        !
        lsel,s,line,,ljs2g_
        ksll,s
        ksel,u,kp,,jkp_
        get_max_entity
        jkp_=km
        !
        *if,jkp_,eq,ekp_,then
            *exit
        *endif
    *enddo
*endif
!
init_entity_num
cmsel,s,lngrp_
cmsel,s,CK01_
!
lplot
!
*set,skp_,
*set,dkp_,
*set,ekp_,
*set,lcnt01_,
*set,stpsel_,
*set,jkp_,
*set,kp1l1_,
*set,kp2l1_,
*set,ljs2g_,
*set,z__,
cmdele,CL01_
cmdele,CK01_
!
*if,arg4,eq,0,then
    cmdele,lngrp_
*endif
!
*if,prkey_,eq,1,then
    /go
*endif