!   TITLE:  max_enty_dim_2.mac (MANAGEMENT)
!
!
!   OBJECTIVE:
!
!   This sub-macro is used to retrieve the maximum value of the dimension
!   of a specified entity within a selected set along with the entity number.
!   (METHOD 2)
!
!   COMMAND SYNTAX:
!
!                         (1)
!       MAX_ENTY_DIM_2, ent_typ
!
!
!   ARGUMENTS:
!
!       (1) ent_typ = entity type with which to retrieve maximum dimension
!                     value within [entity type must be in single quotes]:
!
!               'l' = retrieves the maximum length of all selected lines
!
!               'a' = retrieves the maximum area of all selected areas
!
!               'v' = retrieves the maximum volume of all selected volumes
!
!
!   DESCRIPTION:
!
!   ---------------------------------------------------------------------------
!   This is the 2nd method of retrieving the maximum value of a set of entities.
!   This method is for a small number of entities (< 5000). For large models,
!   the use of 'MAX_ENTY_DIM' is recommended. This method does not use the
!   macro 'ENTITY_ARRAY', and is therefore more efficient.
!   ---------------------------------------------------------------------------
!
!   The entity types that may be queried are:
!
!                       ENTITY      DIMENSION
!                      --------    -----------
!               (1)     line        line length
!               (2)     area        surface area
!               (3)     volume      volume
!
!   From within the selected set of any given entity, the maximum value of
!   its pertinent dimension, and the entity number with the maximum dimension,
!   is queried and returned in one of the corresponding sets of parameters,
!   respectively:
!
!                     DIMENSION      ENTITY NUMBER
!                    -----------     -------------
!               (1)   max_leng         max_lnum
!
!               (2)   max_area         max_anum
!
!               (3)   max_vol          max_vnum
!
!
!
*get,prkey_,active,0,prkey
/nopr
!
entity=arg1
!
*if,entity,eq,'l',then          ! assignment of entity variable, 'ev'
    ev='line'
*elseif,entity,eq,'a',then
    ev='area'
    asum
*elseif,entity,eq,'v',then
    ev='volu'
    vsum
*else
    ev='z'
*endif
!
*if,ev,ne,'z',then              ! If ev is assigned 'z', then abort
    !
    *get,emax,ev,,num,max       ! retrieve MIN and MAX entity numbers
    *get,emin,ev,,num,min
    !
    *get,ecount,ev,,count       ! number of specified entities in the
    !                           ! selected entity set
    *do,jkl_,1,ecount,1
        *if,jkl_,eq,1,then
            e%jkl_%=emin
        *else
            jj_=jkl_-1
            *get,xx,ev,e%jj_%,nxth
            e%jkl_%=xx
        *endif
    *enddo
*endif
!
*do,ii_,1,ecount,1
    !
    *if,entity,eq,'l',then
        *get,ec%ii_%,line,e%ii_%,leng
    *elseif,entity,eq,'a',then
        *get,ec%ii_%,area,e%ii_%,area
    *elseif,entity,eq,'v',then
        *get,ec%ii_%,volu,e%ii_%,volu
    *endif
*enddo
!
*do,ii_,1,ecount,1
    *if,ii_,eq,1,then
        xx=ec1
        yy=e1
    *else
        *if,xx,gt,ec%ii_%,then
            xx=xx
            yy=yy
        *else
            xx=ec%ii_%
            yy=e%ii_%
        *endif
    *endif
*enddo
!
*if,entity,eq,'l',then
    max_leng=xx
    max_lnum=yy
*elseif,entity,eq,'a',then
    max_area=xx
    max_anum=yy
*elseif,entity,eq,'v',then
    max_vol=xx
    max_vnum=yy
*endif
!
*do,ijk_,1,ecount,1
    *set,e%ijk_%,
    *set,ec%ijk_%
    *set,xx,
    *set,yy,
    *set,ev,
    *set,entity,
    *set,emax,
    *set,emin,
*enddo
!
*set,ijk_,
*set,ii_,
*set,jj_,
*set,jkl_,

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