!   TITLE:  create_cs.mac (MANAGEMENT)
!
!
!   OBJECTIVE:
!
!   This sub-macro creates a coordinate system that is automatically numbered
!   and tracked by the assembly algorithms.
!
!
!   COMMAND SYNTAX:
!
!       * METHOD = 0 (CLOCAL command):
!
!                       (1)    (2)    (3)    (4) (5) (6)  (7)    (8)    
!           CREATE_CS, mthd, cs_nam, cs_typ, xc, yc, zc, rotxy, rotyz, 
!
!                      rotzx, ratyx, ratzx
!                       (9)    (10)   (11)
!       --------------------------------------------------------------
!       * METHOD = 1 (CSKP command):
!
!                       (1)    (2)    (3)    (4)   (5)   (6)    (7)    (8)
!           CREATE_CS, mthd, cs_nam, cs_typ, kp_1, kp_2, kp_3, ratyx, ratzx
!       --------------------------------------------------------------
!       * METHOD = 2 (LOCAL command)::
!
!                       (1)    (2)    (3)    (4) (5) (6)  (7)    (8)    
!           CREATE_CS, mthd, cs_nam, cs_typ, xc, yc, zc, rotxy, rotyz,
!
!                      rotzx, ratyx, ratzx
!                       (9)    (10)   (11)
!       --------------------------------------------------------------
!       * METHOD = 3 (CS command)::
!
!                       (1)    (2)    (3)    (4)   (5)   (6)    (7)    (8)
!           CREATE_CS, mthd, cs_nam, cs_typ, nd_1, nd_2, nd_3, ratyx, ratzx
!
!
!   ARGUMENTS:
!
!       (1) mthd = the method used to create the coordinate system.
!                  Options for this argument are:
!
!                   0 (or blank) = use the command CLOCAL; create c.s. at a
!                                  relative position and orientation to the
!                                  active c.s.
!
!                   1 = use the command CSKP; create c.s. by 3 keypoints.
!
!                   2 = use the command LOCAL; create c.s. relative to
!                       global cartesian c.s.
!
!                   3 = use the command CS; create c.s. by 3 nodes.
!
!       (2) cs_nam = character parameter name of c.s., which is assigned
!                    the value of CSN, the coordinate system number.
!
!       (3) cs_typ = coordinate system type:
!
!                   0 = cartesian
!                   1 = cylindrical
!                   2 = spherical
!                   3 = toroidal
!
!       (7, 10) ratyx = scaling ratio of y-axis radius to x-axis radius
!
!       (8, 11) ratzx = scaling ratio of z-axis radius to x-axis radius
!
!   Arguments particular to the various options:
!
!   METHOD = 0 & 2:
!
!           (4) xc = x coordinate of c.s. center
!
!           (5) yc = x coordinate of c.s. center
!
!           (6) zc = x coordinate of c.s. center
!
!           (7) rotxy = 1st rotation angle (+x to +y)
!
!           (8) rotyz = 2nd rotation angle (+y to +z)
!
!           (9) rotzx = 3rd rotation angle (+z to +x)
!
!   METHOD = 1:
!
!           (4) kp_1 = c.s. origin keypoint
!
!           (5) kp_2 = keypoint defining +x axis direction
!
!           (6) kp_3 = keypoint defining +y axis direction (+xy plane)
!
!   METHOD = 3:
!
!           (4) nd_1 = c.s. origin node
!
!           (5) nd_2 = node defining +x axis direction
!
!           (6) nd_3 = node defining +y axis direction (+xy plane)
!
!
!   DESCRIPTION:
!
!   The coordinate systems (c.s.) are created by the 4 methods available in
!   ANSYS: CLOCAL, CSKP, LOCAL or CS. It updates the coordinate system
!   tracking parameter, CSN, and names the coordinate system by the user
!   specified name in argument 2. This name must be 8 characters or less,
!   and must be placed in single quotes (e.g., 'CSname'). The number assigned
!   to this coordinate system is then stored in the parameter of the user
!   specified name (e.g., c.s. 17 is stored in the parameter name,
!   CSname=17).
!
!
*get,prkey_,active,0,prkey
/nopr
!
mthd=arg1
cs_nam=arg2
cs_typ=arg3
!
csn=csn+1
!
*get,par_typ,parm,cs_nam,type
!
*if,par_typ,eq,0,then
    cs_nam=csn
    abrtfile=1              ! abort filing process parameter (1=abort filing)
*elseif,par_typ,eq,3,then
    %cs_nam%=csn
    abrtfile=0              ! abort filing process parameter (0=file)
*endif
!
*if,mthd,eq,0,then
    xc=arg4
    yc=arg5
    zc=arg6
    rotxy=arg7
    rotyz=arg8
    rotzx=arg9
    ratyx=ar10
    ratzx=ar11
    !
    clocal,%cs_nam%,cs_typ,xc,yc,zc,rotxy,rotyz,rotzx,ratyx,ratzx
    !
    *set,xc,
    *set,yc,
    *set,zc,
    *set,rotxy,
    *set,rotyz,
    *set,rotzx,
*endif
!
!
*if,mthd,eq,1,then
    kp_1=arg4
    kp_2=arg5
    kp_3=arg6
    ratyx=arg7
    ratzx=arg8
    !
    cskp,%cs_nam%,cs_typ,kp_1,kp_2,kp_3,ratyx,ratzx
    !
    *set,kp_1,
    *set,kp_2,
    *set,kp_3,
*endif
!
!
*if,mthd,eq,2,then
    xc=arg4
    yc=arg5
    zc=arg6
    rotxy=arg7
    rotyz=arg8
    rotzx=arg9
    ratyx=ar10
    ratzx=ar11
    !
    local,%cs_nam%,cs_typ,xc,yc,zc,rotxy,rotyz,rotzx,ratyx,ratzx
    !
    *set,xc,
    *set,yc,
    *set,zc,
    *set,rotxy,
    *set,rotyz,
    *set,rotzx,
*endif
!
!
*if,mthd,eq,3,then
    nd_1=arg4
    nd_2=arg5
    nd_3=arg6
    ratyx=arg7
    ratzx=arg8
    !
    cs,%cs_nam%,cs_typ,nd_1,nd_2,nd_3,ratyx,ratzx
    !
    *set,nd_1,
    *set,nd_2,
    *set,nd_3,
*endif
!
*get,_parchk,parm,cs_arry,type
!
*if,abrtfile,eq,0,then
    *if,_parchk,eq,4,then
        cs_file
    *endif
*else
    csn=csn-1
*endif
!
*set,abrtfile,
*set,cs_nam,
*set,cs_typ,
*set,par_typ,
*set,ratyx,
*set,ratzx,
*set,mthd,
*set,_parchk,
!
*if,prkey_,eq,1,then
    /go
*endif