!   TITLE:  trim.mac (SM_TOOL)
!
!
!   OBJECTIVE:
!
!   This macro trims the length of a line.
!
!
!   COMMAND SYNTAX:
!
!                      (1)   (2)     (3)
!               TRIM, line#, kp#, trim_leng
!
!
!   ARGUMENTS:
!
!       (1) line# = number of the line to extend
!
!       (2) kp# = end keypoint number to extend from
!
!       (3) trim_leng = the amount of length to trim line
!
!
!   DESCRIPTION:
!
!   The line is trimmed (shortened) from the specified end keypoint side. The
!   original length of the line is shortened in length by the amount specified
!   in argument 3, 'trim_leng'.
!
!   If the end keypoint is attached to only 1 line, then the line number
!   need not be specified; only arguments 2 and 3. In this case, the line
!   is trimmed to make 1 shorter line. If the end keypoint is attached to more
!   than 1 line, then the line number to be extended must be specified.
!
!   The end keypoint may be attached to other lines, but the original line must
!   not be attached to any higher order entities (i.e., areas, volumes, etc.).
!   This command is valid only for straight lines.
!
!
!
!
*get,prkey_,active,0,prkey
/nopr

baseln_=arg1
endkp_=arg2
triml_=arg3
!
init_entity_num
!
ksel,s,kp,,endkp_
lslk,s,0
get_max_entity
lhold_=lm
*get,numlns_,line,,count
!
init_entity_num
!
*if,numlns_,eq,1,then
    baseln_=lhold_
*endif
!
*get,kp1_,line,baseln_,kp,1
*get,kp2_,line,baseln_,kp,2
!
*if,kp1_,eq,endkp_,then
    kxp_=kp2_
*else
    kxp_=kp1_
*endif
!
*get,acs1_,active,,csys
!
clocal,csn+5,1,kx(endkp_),ky(endkp_),kz(endkp_),0,0,0
kxpang_=ky(kxp_)
clocal,csn+6,0,0,0,0,kxpang_,0,0
!
k,,0,1,0
init_entity_num
kpln_=km
!
cskp,csn+7,0,endkp_,kxp_,kpln_
!
kdele,kpln_
init_entity_num
!
*if,triml_,gt,0,then
    k,,triml_,0,0
    !
    init_entity_num
    !
    lstr,endkp_,km
    !
    init_entity_num
    !
    lovlap,baseln_,lm
    !
    init_entity_num
    !
    ldele,lm-1,,,1
    !
    init_entity_num
*endif
!
csdele,csn+5,csn+7,1
csys,acs1_
!
lplot
!
*set,baseln_,
*set,endkp_,
*set,kpln_,
*set,kp1_,
*set,kp2_,
*set,acs1_,
*set,triml_,
*set,lhold_,
*set,numlns_,
*set,kxp_,
*set,kxpang_,

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