!   TITLE:  entity_array.mac (MANAGEMENT)
!
!               Allow argument 3 to be left blank and default to 'array'
!
!   OBJECTIVE:
!
!   This sub-macro retrieves a selected set of solid modeling entities
!   and stores them in an array of a user specified name.
!
!
!   COMMAND SYNTAX:
!
!                          (1)     (2)   (3)  (4)   (5)    (6)   (7)
!           ENTITY_ARRAY, entity, aname, typ, dir, #rows, #col, #pln
!
!
!   ARGUMENTS:
!
!       (1) entity = 'k' for keypoint entities
!                    'l' for line entities
!                    'a' for area entities
!                    'v' for volume entities
!                    'n' for node entities
!                    'e' for element entities
!
!       (2) aname = character name for array
!
!       (3) typ = array type:
!
!               'array' = normal (default) array
!               'table' = table array
!
!       (4) dir = the direction of placement of the entities in the array .  It
!                 is the indical direction in the index positions:
!
!                   (1,2,3)  ====>  (row, column, plane)
!
!               1 = [DEFAULT] store entities in each row (the (r,1,1) positions)
!
!               2 = store entities in each column (the (1,c,1) positions)
!
!               3 = store entities in each plane (the (1,1,p) positions)
!
!       (5) #rows = The number of rows in the array. If DIR = 1, then the number
!                   of rows is automatically determined by the number of entities
!                   to be stored, and this argument is ignored.
!
!       (6) #col = The number of columns in the array. If DIR = 2, then the
!                  number of columns is automatically determined by the number
!                  of entities to be stored, and this argument is ignored.
!
!       (7) #pln = The number of planes in the array. If DIR = 3, then the number
!                  of planes is automatically determined by the number of entities
!                  to be stored, and this argument is ignored.
!
!
!   DESCRIPTION:
!
!   The following choice of entities are:
!
!                       ENTITY
!                      --------
!                       keypoint
!                       line
!                       area
!                       volume
!                       node
!                       element
!
!   Output for this macro:
!
!           1.) An array of the user specified name
!
!           2.) ecount = the number of entities (elements) in
!                        the array
!
!   If only the entities are to be stored as elements of the array; i.e., if
!   only a one dimensional (column) array is desired, then arguments 4 thru
!   7 may be ignored.
!
!
!
!
*get,prkey_,active,0,prkey
/nopr

_entity=arg1
_aname=arg2
_typ=arg3
_dir=arg4
_nrow=arg5
_ncol=arg6
_npln=arg7
!
*if,_par_typ,ne,3,then        ! character scalar
    _typ='array'
*endif
!
*if,_nrow,eq,0,then
    _nrow=1
*endif
!
*if,_ncol,eq,0,then
    _ncol=1
*endif
!
*if,_npln,eq,0,then
    _npln=1
*endif
!
*if,_dir,eq,0,then
    _dir=1
*endif
!
!
*if,_entity,eq,'k',then     ! assignment of entity variable, '_ev'
    _ev='kp'
*elseif,_entity,eq,'l',then
    _ev='line'
*elseif,_entity,eq,'a',then
    _ev='area'
*elseif,_entity,eq,'v',then
    _ev='volu'
*elseif,_entity,eq,'n',then
    _ev='node'
*elseif,_entity,eq,'e',then
    _ev='elem'
*else
    _ev='z'
    *msg,warn,
    Invalid Entity Option. Use k, l, a, v, n or e
*endif
!
*if,_ev,ne,'z',then       ! If ev is assigned 'z', then abort
    !
    *get,_emin,_ev,,num,min   ! retrieve MIN keypoint numbers
    *get,ecount,_ev,,count    ! Retieve # of specified entities in the
    !                         ! selected entity set.
    !
    !
    !
    *if,_dir,eq,1,then
        !
        *dim,%_aname%,_typ,ecount,_ncol,_npln       ! dimension array
        !
        *do,_iii,1,ecount,1
            *if,_iii,eq,1,then
                %_aname%(_iii,1,1)=_emin
            *else
                _jjj=_iii-1
                *get,_xxx,_ev,%_aname%(_jjj,1,1),nxth
                %_aname%(_iii,1,1)=_xxx
            *endif
        *enddo
    *endif
    !
    !
    *if,_dir,eq,2,then
        !
        *dim,%_aname%,_typ,_nrow,ecount,_npln       ! dimension array
        !
        *do,_iii,1,ecount,1
            *if,_iii,eq,1,then
                %_aname%(1,_iii,1)=_emin
            *else
                _jjj=_iii-1
                *get,_xxx,_ev,%_aname%(1,_jjj,1),nxth
                %_aname%(1,_iii,1)=_xxx
            *endif
        *enddo
    *endif
    !
    !
    *if,_dir,eq,3,then
        !
        *dim,%_aname%,_typ,_nrow,_ncol,ecount       ! dimension array
        !
        *do,_iii,1,ecount,1
            *if,_iii,eq,1,then
                %_aname%(1,1,_iii)=_emin
            *else
                _jjj=_iii-1
                *get,_xxx,_ev,%_aname%(1,1,_jjj),nxth
                %_aname%(1,1,_iii)=_xxx
            *endif
        *enddo
    *endif
    !
    !
    !
*endif
!
*set,_xxx,
*set,_iii,
*set,_jjj,
*set,_entity,
*set,_emin,
*set,_typ,
*set,_par_typ
*set,_aname,
*set,_ev,
*set,_nrow,
*set,_ncol,
*set,_npln,
*set,_dir,

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