!   TITLE:  tv_profile_lines.mac (CALCULATION)
!
!
!   OBJECTIVE:
!
!   This macro creates a continuous line profile from a set of selected lines.
!
!
!   ARGUMENTS:
!
!       (1) strt_pt = the first or starting keypoint in the line profile.
!
!       (2) fin_pt = the last or finish keypoint in the line profile.
!
!
!   DESCRIPTION:
!
!   A set of independent, overlapping lines with no intersection points is
!   transformed into a connected chain profile.  The lines should not form
!   ANY closed path, and must overlap other lines at only 1 point for each
!   overlapping line.
!
!   The desired profile is determined from a start keypoint in the chain, and
!   terminate at a finish keypoint.  After execution, the resulting path is
!   a set of lines that share common keypoints, and form a continuous path
!   from the specified start and finish keypoints.  The extraneous line seg-
!   ments resulting from the line overlap operation (LOVLAP) are 'cleaned'
!   from the new path.
!
!
!
!
*get,prkey_,active,0,prkey
/nopr

multipro,'start',2
    *cset,1,3,skp_,'Enter Start Keypoint #',1
    *cset,4,6,fkp_,'Enter Finish Keypoint #',2
    *cset,61,62,'Creates a continuous line',' profile from a selected set'
    *cset,63,64,'of unconnected lines. Enter',' the end keypoint numbers.'
multipro,'end'
!
!
*get,origtyp_,comp,origlns_,type
!
*if,origtyp_,eq,7,then
    cmsel,u,origlns_
*endif
!
*get,numlns_,line,,count
!
lovlap,all
init_entity_num
!
isolate_lines
!
*if,origtyp_,eq,7,then
    cmsel,u,origlns_
*endif
!
lplot
!
!
*do,aaa_,1,numlns_,1
    ksel,s,kp,,skp_
    !
    lslk,s,0
    !
    *if,aaa_,eq,1,then
        get_max_entity
        prfln_=lm
    *else
        lsel,u,line,,prfln_
        get_max_entity
        prfln_=lm
    *endif
    !
    *get,kp11_,line,prfln_,kp,1
    *get,kp12_,line,prfln_,kp,2
    !
    *if,skp_,eq,kp11_,then
        juncpt_=kp12_
    *else
        juncpt_=kp11_
    *endif
    !
    *if,juncpt_,eq,fkp_,then
        *exit
    *else
        ksel,s,kp,,juncpt_
        !
        lslk,s,0
        lsel,u,line,,prfln_
        !
        *get,ptyp__,parm,lnset_,type
        !
        *if,ptyp__,ne,-1,then
            *set,lnset_(1),
        *endif
        !
        entity_array,'l','lnset_','array'
        nchkln_=ecount
        !
        *if,nchkln_,gt,0,then
            !
            *set,drlns_,
            !
            *do,bbb_,1,nchkln_,1
                *if,drlns_,eq,0,then
                    lsel,s,line,,lnset_(bbb_,1)
                    !
                    *get,kpls1_,line,lnset_(bbb_,1),kp,1
                    *get,kpls2_,line,lnset_(bbb_,1),kp,2
                    !
                    *if,kpls1_,eq,juncpt_,then
                        juncpt2_=kpls2_
                    *else
                        juncpt2_=kpls1_
                    *endif
                    !
                    ksel,s,kp,,juncpt2_
                    !
                    lslk,s,0
                    lsel,u,line,,lnset_(bbb_,1)
                    !
                    *get,numcl_,line,,count
                    !
                    *if,juncpt2_,ne,fkp_,then
                        *if,numcl_,eq,0,then
                            lsel,s,line,,lnset_(bbb_,1)
                            ldele,all,,,1
                        *else
                            drlns_=1
                        *endif
                    *else
                        drlns_=1
                    *endif
                *else
                    lsel,s,line,,lnset_(bbb_,1)
                    ldele,all,,,1
                *endif
            *enddo
        *else
            *exit
        *endif
    *endif
    !
    skp_=juncpt_
    !
    *set,juncpt_
    *set,juncpt2_
    !
    init_entity_num
    !
    lplot
*enddo
!
init_entity_num
!
lplot
!
!
!
*set,skp_,
*set,fkp_,
*set,lnset_(1),
*set,prfln_,
*set,drlns_,
*set,numcl_,
*set,juncpt_,
*set,juncpt2_,
*set,bbb_,
*set,aaa_,
*set,kp11_,
*set,kp12_,
*set,kpls1_,
*set,kpls2_,
*set,origtyp_,
cmdele,origlns_
cmdele,conln_

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