!   TITLE:  entity_array.mac (MANAGEMENT)
!
!               Allow argument 3 to be left blank and default to 'array'
!               Removed *if block from *do loops for a 3 times speed increase
!
!   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
!
! Set defaults
!
*get,_par_typ,parm,_typ,type
!
    _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
!
! Assignment of entity variable, '_ev'
!
*if,_entity,eq,'k',then
    _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
    *msg,error
    entity_array: Invalid argument <entity>.  Use k, l, a, v, n or e
    return,,1
*endif
!
*get,_emin,_ev,,num,min   ! retrieve MIN keypoint number
*get,ecount,_ev,,count    ! Retieve # of specified entities in the
!                         ! selected entity set.
!
!
*if,_dir,eq,2,then      ! If _dir ~= 2 or 3, then assume = 1
    *dim,%_aname%,_typ,_nrow,ecount,_npln
    %_aname%(1,1,1)=_emin
    !
    *if,ecount,gt,1,then
        *do,_iii,2,ecount
            *get,%_aname%(1,_iii,1),_ev,%_aname%(1,_iii-1,1),nxth
        *enddo
    *endif
*elseif,_dir,eq,3,then
    *dim,%_aname%,_typ,_nrow,_ncol,ecount
    %_aname%(1,1,1)=_emin
    !
    *if,ecount,gt,1,then
        *do,_iii,2,ecount,1
            *get,%_aname%(1,1,_iii),_ev,%_aname%(1,1,_iii-1),nxth
        *enddo
    *endif
*else
    *dim,%_aname%,_typ,ecount,_ncol,_npln   ! Default: _dir = 1
    %_aname%(1,1,1)=_emin
    !
    *if,ecount,gt,1,then
        *do,_iii,2,ecount
            *get,%_aname%(_iii,1,1),_ev,%_aname%(_iii-1,1,1),nxth
        *enddo
    *endif
*endif
!
*set,_iii
*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