!   TITLE:  min_enty_dim_2.mac (MANAGEMENT)
!
!
!   OBJECTIVE:
!
!   This sub-macro is used to retrieve the minimum value of the dimension
!   of a specified entity within a selected set along with the entity number.
!   (METHOD 2)
!
!   COMMAND SYNTAX:
!
!                         (1)
!       MIN_ENTY_DIM_2, ent_typ
!
!
!   ARGUMENTS:
!
!       (1) ent_typ = entity type with which to retrieve minimum dimension
!                     value within [entity type must be in single quotes]:
!
!               'l' = retrieves the minimum length of all selected lines
!
!               'a' = retrieves the minimum area of all selected areas
!
!               'v' = retrieves the minimum volume of all selected volumes
!
!
!   DESCRIPTION:
!
!   ---------------------------------------------------------------------------
!   This is the 2nd method of retrieving the minimum value of a set of entities.
!   This method is for a small number of entities (< 5000). For large models,
!   the use of 'MIN_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 minimum value of
!   its pertinent dimension, and the entity number with the minimum dimension,
!   is queried and returned in one of the corresponding sets of parameters,
!   respectively:
!
!                     DIMENSION      ENTITY NUMBER
!                    -----------     -------------
!               (1)   min_leng         min_lnum
!
!               (2)   min_area         min_anum
!
!               (3)   min_vol          min_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
*endif
!
*if,entity,ne,'l',then      ! If entity is not an 'l','a' or 'v',
   *if,entity,ne,'a',then       ! then assign ev to a dummy variable 'z'.
      *if,entity,ne,'v',then
         ev='z'
      *endif
   *endif
*endif
!
*if,ev,ne,'z',then        ! If ev is assigned 'z', then abort
    !
    *get,emax,ev,,num,max     ! retrieve MIN and MAX keypoint numbers
    *get,emin,ev,,num,min
    !
    *get,ecount,ev,,count     ! number of specified entities in the
    !             ! selected entity set
    *do,xyz_,1,ecount,1
        *if,xyz_,eq,1,then
            e%xyz_%=emin
        *else
            jkl_=%xyz_%-1
            *get,x,ev,e%jkl_%,nxth
            e%xyz_%=x
        *endif
    *enddo
*endif
!
*do,ikl_,1,ecount,1
    !
    *if,entity,eq,'l',then
        *get,ec%ikl_%,line,e%ikl_%,leng
    *elseif,entity,eq,'a',then
        *get,ec%ikl_%,area,e%ikl_%,area
    *elseif,entity,eq,'v',then
        *get,ec%ikl_%,volu,e%ikl_%,volu
    *endif
*enddo
!
*do,iii_,1,ecount,1
    *if,iii_,eq,1,then
        x=ec1
        y=e1
    *else
        *if,x,lt,ec%iii_%,then
            x=x
            y=y
        *else
            x=ec%iii_%
            y=e%iii_%
        *endif
    *endif
*enddo
!
*if,entity,eq,'l',then
    min_leng=x
    min_lnum=y
*elseif,entity,eq,'a',then
    min_area=x
    min_anum=y
*elseif,entity,eq,'v',then
    min_vol=x
    min_vnum=y
*endif
!
*do,ijk_,1,ecount,1
    *set,e%ijk_%,
    *set,ec%ijk_%
    *set,x,
    *set,y,
    *set,ev,
    *set,entity,
    *set,ecount,
    *set,emax,
    *set,emin,
*enddo
!
*set,xyz_,
*set,jkl_,
*set,ijk_,
*set,iii_,
*set,ikl_,
!
*if,prkey_,eq,1,then
    /go
*endif