!   TITLE:  mat_select.mac (MANAGEMENT)
!
!
!   OBJECTIVE:
!
!   This macro assigns material properties and numbers used in part macros.
!
!
!   COMMAND SYNTAX:
!
!           MAT_SELECT, mat_1, mat_2, mat_3, mat_4, mat_5
!
!
!   ARGUMENTS:
!
!           mat_N = selected material.  This is the character name of the
!                   material to be initiated into the part macro.
!
!
!   DESCRIPTION:
!
!   This macro calls the defined properties from the material library for
!   that material, as defined by its character name.  This character name
!   is assigned the material number and may be used as the parameter for
!   that material number. Once defined, any reoccurence of this material
!   in macro assemblies is ignored, and the pre-existing material number
!   already assigned is used. This will alleviate any overlap or redundant
!   material assignments.
!
!   Up to five material properties may be defined by this macro on 1 line.
!   If more than five materials are needed to be defined, then simply rerunning
!   this macro with the additional materials will add to the material list.
!   The material numbers are assigned to each material in the order in which
!   they occur.
!
!   Refer to mat_list.mac for a complete list of defined material names.
!
!
!
*get,prkey_,active,0,prkey
/nopr
!
/prep7
!
*get,matmax_,parm,mat_name,dim,y    ! determine whether MATMAX_ exists
!
*if,matmax_,eq,0,then               ! If MATMAX_ does not exist, then
    matnum_=0                       ! initialize material numbers
    mati_=1
*else
    matnum_=matmax_                 ! else, pick up at the last maximum
    mati_=matmax_+1                 ! material number
*endif
!
locmax_=0
!
*do,k_,1,5,1                        ! assign material numbers
    parhold_=arg%k_%
    *get,_ptyp,parm,parhold_,type
    !
    *if,_ptyp,eq,0,then
        *exit
    *else
        locmax_=locmax_+1
        matnum_=matnum_+1
    *endif
*enddo
!
matmax_=matnum_                         ! assign maximum material number
!
*get,ptyp_,parm,mat_name,type
!
*do,k_,mati_,matmax_,1                  ! assign material name
    *if,ptyp_,eq,4,then
        namhold_=arg%k_-(mati_-1)%
        arry_search,'mat_name','%namhold_%'
        !
        *if,hits,eq,0,then
            *get,nummat_,parm,mat_name,dim,y
            *dim,matbuff_,char,1,nummat_+1
            !
            *do,abc_,1,nummat_,1
                matbuff_(1,abc_)=mat_name(1,abc_)
            *enddo
            !
            *set,mat_name(1),
            !
            *dim,mat_name,char,1,nummat_+1
            !
            *do,abc_,1,nummat_,1
                mat_name(1,abc_)=matbuff_(1,abc_)
            *enddo
            !
            mat_name(1,nummat_+1)=arg%k_-(mati_-1)%
            !
            *get,nummat_,parm,mat_name,dim,y
            !
            *set,matbuff_(1),
            !
            namhold_=mat_name(1,nummat_)
            mat_library,'%namhold_%'
        *endif
    *else
        *if,k_,eq,1,then
            *dim,mat_name,char,1,1
            !
            mat_name(1,k_)=arg%k_-(mati_-1)%
            !
            *get,nummat_,parm,mat_name,dim,y
        *else
            *get,nummat_,parm,mat_name,dim,y
            *dim,matbuff_,char,1,nummat_+1
            !
            *do,abc_,1,nummat_,1
                matbuff_(1,abc_)=mat_name(1,abc_)
            *enddo
            !
            *set,mat_name(1),
            !
            *dim,mat_name,char,1,nummat_+1
            !
            *do,abc_,1,nummat_,1
                mat_name(1,abc_)=matbuff_(1,abc_)
            *enddo
            !
            mat_name(1,nummat_+1)=arg%k_-(mati_-1)%
            !
            *get,nummat_,parm,mat_name,dim,y
            !
            *set,matbuff_(1),
        *endif
        !
        namhold_=mat_name(1,nummat_)
        mat_library,'%namhold_%'
    *endif
*enddo
!
*get,numprop_,parm,mat_prop,dim,x
*get,nummat_,parm,mat_name,dim,y
!
*do,abc_,1,nummat_,1                ! assign material numbers
    mat_prop(1,abc_)=abc_
    namhold_=mat_name(1,abc_)
    %namhold_%=abc_
*enddo
!
*do,abc_,1,nummat_,1                ! initialize material properties
    *do,bcd_,2,numprop_,1
        !
        mpval_=mat_prop(bcd_,abc_)
        !
        *if,mpval_,ne,0,then
            prop_=prop_lab(bcd_-1,1)
            matnum_=mat_prop(1,abc_)
            !
            mp,prop_,matnum_,mpval_
        *endif
    *enddo
*enddo
!
*if,locmax_,eq,1,then
    attrmat_=%arg1%
*else
    attrmat_=0
*endif
!
*set,abc_,
*set,bcd_,
*set,prop_,
*set,matnum_,
*set,mpval_,
*set,numprop_,
*set,nummat_,
*set,namhold_,
*set,parhold_,
*set,matmax_,
*set,mati_,
*set,ptyp_,
*set,k_,
*set,locmax_,
!
*if,prkey_,eq,1,then
    /go
*endif