!   TITLE:  create_mat_prop.mac (MANAGEMENT)
!
!
!   Added code to assign material attributes to volumes or areas.
!
!
!   OBJECTIVE:
!
!   This macro allows the user to create a new material and its properties;
!   or to define additional properties to an already existing material.
!
!
!   COMMAND SYNTAX:
!
!                            (1)   (2)    (3)   (4)    (5)   (6)    (7)
!           CREATE_MAT_PROP, mat, prop1, val1, prop2, val2, prop3, val3
!
!
!   ARGUMENTS:
!
!           (1) mat = material name
!
!       (2,4,6) propN = material property label
!
!       (3,5,7) valN = material property value of propN
!
!
!   DESCRIPTION:
!
!   If a material that is not previously defined in the material library
!   listing, or a generic user defined material, is to be created, then
!   a new material name may be input in argument 1, and up to 3 material
!   properties and their values in the remaining arguments.
!
!   A generic material that is to be defined will be added to the material
!   name array 'mat_name', along with its material properties.
!
!   If the name in argument 1 is an existing material in 'mat_name', then
!   the remaining arguments, that define the property values, will be input
!   into the respective property values for that material. If these values
!   are already defined, then these new values will over-write the existing
!   values.
!
!   If more than 3 properties are to be defined, then simply rerunning this
!   macro with the new additional properties will add these properties values
!   to the 'mat_prop' array.
!
!
!
!
*get,prkey_,active,0,prkey
/nopr
!
mat_=arg1
!
*get,nummat_,parm,mat_name,dim,y
!
*if,nummat_,gt,0,then
    arry_search,'mat_name','%mat_%'
    !
    *if,hits,eq,0,then
        !
        *dim,matbuff_,char,1,nummat_            ! add column to MAT_NAME
        !
        *do,abcd_,1,nummat_,1
            matbuff_(1,abcd_)=mat_name(1,abcd_)
        *enddo
        !
        *set,mat_name(1),
        !
        *dim,mat_name,char,1,nummat_+1
        !
        *do,abcd_,1,nummat_,1
            mat_name(1,abcd_)=matbuff_(1,abcd_)
        *enddo
        !
        mat_name(1,nummat_+1)=mat_
        !
        *set,matbuff_(1),
        !
        !
        *get,matpr_,parm,mat_prop,dim,x         ! add column to MAT_PROP
        *get,matpc_,parm,mat_prop,dim,y
        !
        *dim,matpbuf_,array,matpr_,matpc_
        !
        *do,bcde_,1,matpc_,1
            *do,cdef_,1,matpr_,1
                matpbuf_(cdef_,bcde_)=mat_prop(cdef_,bcde_)
            *enddo
        *enddo
        !
        *set,mat_prop(1),
        !
        *dim,mat_prop,array,matpr_,matpc_+1
        !
        *do,bcde_,1,matpc_,1
            *do,cdef_,1,matpr_,1
                mat_prop(cdef_,bcde_)=matpbuf_(cdef_,bcde_)
            *enddo
        *enddo
        !
        *get,matpc_,parm,mat_prop,dim,y
        mat_prop(1,matpc_)=matpc_
        col_=matpc_
        !
        *set,matpbuf_(1),
    *else
        col_=hit(1,2)
    *endif
    !
    *do,abcd_,2,6,2                 ! assign material property values
        prop_=arg%abcd_%
        !
        *get,ptyp_,parm,prop_,type
        !
        *if,ptyp_,ne,0,then
            prop_=upcase(prop_)
            val_=arg%abcd_+1%
            !
            arry_search,'prop_lab','%prop_%'
            row_=hit(1,1)
            !
            mat_prop(row_+1,col_)=val_
        *endif
    *enddo
    !
    *get,numprop_,parm,mat_prop,dim,x
    *get,nummat_,parm,mat_name,dim,y
    !
    *do,abcd_,1,nummat_,1               ! assign material numbers
        mat_prop(1,abcd_)=abcd_
        namhold_=mat_name(1,abcd_)
        %namhold_%=abcd_
    *enddo
    !
    *do,abcd_,1,nummat_,1               ! initialize material properties
        *do,bcde_,2,numprop_,1
            !
            mpval_=mat_prop(bcde_,abcd_)
            !
            *if,mpval_,ne,0,then
                prop_=prop_lab(bcde_-1,1)
                matnum_=mat_prop(1,abcd_)
                !
                mp,prop_,matnum_,mpval_
            *endif
        *enddo
    *enddo
*else
    mat_select,arg1
    create_mat_prop,arg1,arg2,arg3,arg4,arg5,arg6,arg7
*endif
!
attrmat_=%arg1%
!
*set,prop_,
*set,val_,
*set,row_,
*set,col_,
*set,numprop_,
*set,nummat_,
*set,mat_,
*set,hits,
*set,abcd_,
*set,bcde_,
*set,cdef_,
*set,matnum_,
*set,mpval_,
*set,numprop_,
*set,nummat_,
*set,matpc_,
*set,matpr_,
*set,namhold_,
!
*if,prkey_,eq,1,then
    /go
*endif