!   TITLE:  norm_kp.mac (CALCULATION)
!
!
!   OBJECTIVE:
!
!   This macro creates a normal (perpendicular) line to a specified line
!   through a specified keypoint.
!
!
!   COMMAND SYNTAX:
!
!                         (1)   (2)   (3)
!               NORM_KP, line#, kp#, kp_use
!
!
!   ARGUMENTS:
!
!       line# = line number to create a normal line relative to
!
!       kp# = keypoint number which the normal line must pass through.
!             This argument has 2 options:
!
!               a.) If the KP number is proceeded by a '+' sign (or blank),
!                   then the normal line will be constructed on the same
!                   side as the KP, passing through it. (DEFAULT)
!
!               b.) If the KP number is proceeded by a '-' sign, then the
!                   normal line will be constructed on the opposite side
!                   as the KP.
!
!       kp_use = use the keypoint as one of the normal line's endpoints:
!
!               0 (or blank) = do not use keypoint (constuct line such
!                              that it passes through the KP) (DEFAULT)
!
!               1 = use keypoint as one endpoint to the normal line.
!
!
!   DESCRIPTION:
!
!   The line is constructed such that it is perpendicular to the specified
!   line, and passes through a keypoint not colinear with the specified line.
!   The line is constucted such that it passes through the keypoint a distance
!   15% of the distance between the keypoint and the user specified line.
!
!   If it is desired to construct the line on the same side as the keypoint,
!   then simply enter the keypoint number in the 2nd argument. If it is
!   desired to construct the line on the opposite side as the keypoint, then
!   enter the keypoint number as a negative number. In either case, the line
!   will cross the specified line.
!
!   If it is desired to use the keypoint as one endpoint of the normal line,
!   then specify the 3rd argument, 'kp_use', as a 1. Whether the line is
!   constructed on either side, if 'kp_use' is 1, the line sill use the
!   specified keypoint as one of its endpoints.
!
!
!
!
*get,prkey_,active,0,prkey
/nopr

baseln_=arg1
basekp_=arg2
usekp_=arg3
!
init_entity_num
!
*get,kp1st_,line,baseln_,kp,1
*get,kp2nd_,line,baseln_,kp,2
!
*get,acs1_,active,,csys
!
cskp,csn+5,0,kp1st_,kp2nd_,abs(basekp_)
!
*if,basekp_,gt,0,then
    *if,usekp_,eq,0,then
        k,,kx(abs(basekp_)),1.1*ky(abs(basekp_)),0
        k,,kx(abs(basekp_)),-0.15*ky(abs(basekp_)),0
    *elseif,usekp_,eq,1,then
        k,,kx(abs(basekp_)),-0.15*ky(abs(basekp_)),0
    *endif
*elseif,basekp_,lt,0,then
    *if,usekp_,eq,0,then
        k,,kx(abs(basekp_)),-1.1*ky(abs(basekp_)),0
        k,,kx(abs(basekp_)),0.15*ky(abs(basekp_)),0
    *elseif,usekp_,eq,1,then
        k,,kx(abs(basekp_)),-1.1*ky(abs(basekp_)),0
    *endif
*endif
!
*if,usekp_,eq,0,then
    create_lines,,1
*elseif,usekp_,eq,1,then
    init_entity_num
    lstr,abs(basekp_),km
    init_entity_num
*endif
!
csdele,csn+5
csys,acs1_
!
lplot
!
*set,baseln_,
*set,basekp_,
*set,kp1st_,
*set,kp2nd_,
*set,acs1_,
*set,usekp_,

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