!   TITLE:  cs_dist_pt_calc.mac (CALCULATION)
!
!
!           Implemented graphical picking option.
!
!   TOOLBAR MACRO
!
!   OBJECTIVE:
!
!   This GUI command macro calculates the linear distances of a keypoint
!   relative to a coordinate system (C.S.).
!
!
!   ARGUMENTS:
!
!           1 prompt:   C.S. number & Keypoint number to measure distances
!                       between:
!
!                                   CS# and KP#
!
!           NOTE: If the input box for the keypoint number in the dialogue box
!                 is left to the default value of 0, then graphical picking is
!                 enabled. In this case, the user must select exactly 1 keypoint
!                 only.
!
!
!   DESCRIPTION:
!
!   This macro calculates the X, Y, Z and linear (absolute) distance between
!   a C.S. center and a keypoint, if the C.S. is cartesian. If the C.S. is not
!   cartesian, then the X,Y and Z coordinates are given, but not the distance.
!   The distances are the coordinates of the keypoint relative to that system.
!   Therefore, a cartesian system has coordinates X,Y and Z; a cylinindrical
!   system has coordinates R, Theta and Z; etc.
!
!   If the active C.S. is the desired C.S., then the first dialogue box may
!   be left unchanged (default), and the keypoint box only specified.
!
!   The output is to a screen dialog box.
!
!
!
*get,prkey_,active,0,prkey
/nopr
!
tol_=0.0001
prec_=4
!
cm,kset1__,kp
!
*get,acs1__,active,,csys
!
grphpic_=0
!
multipro,'start',2
    *cset,1,3,csnum__,'Enter C.S. #',acs1__
    *cset,4,6,kpt__,'Enter KP #',0
    *cset,7,9,prec_,'Enter Decimal Precision',4
    *cset,61,62,'Calculates the coordinate dist','ances of a keypoint relative'
    *cset,63,64,'to a specified C.S. Enter',' the C.S. and KP numbers.'
multipro,'end'
!
*if,kpt__,eq,0,then
    /ui,ksel
    get_max_entity
    !
    *get,kcount_,kp,,count
    !
    kpt__=km
    !
    grphpic_=1
*endif
!
*if,grphpic_,eq,0,then
    kp1_=ksel(kpt__)
    !
    *if,kp1_,eq,1,then
        kcount_=1
    *else
        kcount_=0
    *endif
*endif
!
*if,kcount_,eq,1,then
    *if,prec_,le,0,then
        prec_=4
    *endif
    !
    tol_=10**(-prec_-1)
    !
    csys,csnum__
    !
    dx__=kx(kpt__)
    !
    *if,abs(dx__),lt,tol_,then
        dx__=0
    *else
        *if,abs(dx__),ge,(10*tol_),then
            round_num,dx__,prec_
        *else
            round_num,dx__,prec_+1
        *endif
        !
        dx__=num_
    *endif
    !
    dy__=ky(kpt__)
    !
    *if,abs(dy__),lt,tol_,then
        dy__=0
    *else
        *if,abs(dy__),ge,(10*tol_),then
            round_num,dy__,prec_
        *else
            round_num,dy__,prec_+1
        *endif
        !
        dy__=num_
    *endif
    !
    dz__=kz(kpt__)
    !
    *if,abs(dz__),lt,tol_,then
        dz__=0
    *else
        *if,abs(dz__),ge,(10*tol_),then
            round_num,dz__,prec_
        *else
            round_num,dz__,prec_+1
        *endif
        !
        dz__=num_
    *endif
    !
    *get,csnumtyp,cdsy,csnum__,attr,kcs
    !
    *if,csnumtyp,eq,0,then
        dabs__=sqrt(((dx__**2))+((dy__**2))+((dz__**2)))
        !
        *if,abs(dabs__),lt,tol_,then
            dabs__=0
        *else
            *if,abs(dabs__),ge,(10*tol_),then
                round_num,dabs__,prec_
            *else
                round_num,dabs__,prec_+1
            *endif
            !
            dabs__=num_
        *endif
        !
*msg,ui,%csnum__%,%kpt__%,%dx__%,%dy__%,%dz__%,%dabs__%
Coordinates ( CS %i , KP %i ) : %/&
%/&
X = %g %/&
Y = %g %/&
Z = %g %/&
%/&
D = %g
        !
        *set,dabs__,
    *else
        *if,csnumtyp,eq,1,then
*msg,ui,%csnum__%,%kpt__%,%dx__%,%dy__%,%dz__%
Coordinates ( CS %i , KP %i ) : %/&
%/&
R = %g %/&
THETA = %g %/&
Z = %g %/&

        *elseif,csnumtyp,eq,2,then
*msg,ui,%csnum__%,%kpt__%,%dx__%,%dy__%,%dz__%
Coordinates ( CS %i , KP %i ) : %/&
%/&
R = %g %/&
THETA = %g %/&
PHI = %g %/&

        *else
*msg,ui,%csnum__%,%kpt__%,%dx__%,%dy__%,%dz__%
Coordinates ( CS %i , KP %i ) : %/&
%/&
X = %g %/&
Y = %g %/&
Z = %g %/&

        *endif
    *endif
*elseif,kcount_,gt,1,then
*msg,warn
Too Many KP's Picked. Must Select 1 KP Only.
*elseif,kcount_,lt,1,then
*msg,warn
No KP Selected. Must Select 1 KP Only.
*endif
!
init_entity_num
!
csys,acs1__
cmsel,s,kset1__
/replot
!
*set,csnum__,
*set,kpt__,
*set,dx__,
*set,dy__,
*set,dz__,
*set,csnumtyp,
*set,acs1__,
*set,tol_,
*set,prec_,
*set,kp1_,
*set,kcount_,
*set,grphpic_,
cmdele,kset1__
!
*if,prkey_,eq,1,then
    /go
*endif