!   TITLE:  arry_search.mac (MANAGEMENT)
!
!
!   OBJECTIVE:
!
!   This sub-macro searches an array for a user specified element and
!   returns the indices of that element.
!
!   COMMAND SYNTAX:
!
!                        (1)       (2)
!        ARRY_SEARCH, arry_nam, arry_elem
!
!   ARGUMENTS:
!
!           arry_nam = the name of the array to be searched.
!
!           arry_elem = the element wihtin the array to search for.
!
!   DESCRIPTION:
!
!   This macro searches a user specified array for an element, and returns
!   the index positions of that element in an array called 'hit'. This array
!   is an N x 3 array, where N is the number of occurences ("hits") of the
!   element, and 3 is the index positions returned for each hit. Therefore,
!   a row is a particular element, and the 1st, 2nd and 3rd columns contain
!   the row, column and plane indices for that element, respectively.
!
!   If more than 1 element is found (and therefore, the 'hit' array has more
!   than 1 row), then each row is a particular element, with each column
!   containing an index. Therefore, 'hit' has the following form:
!
!                                        COLUMNS
!                       ROW     |   1   |   2   |   3   |
!                   -------------------------------------
!       1st hit -->     1       |   i1  |   j1  |   k1  |
!       2nd hit -->     2       |   i2  |   j2  |   k2  |
!       3rd hit -->     3       |   i3  |   j3  |   k3  |
!           .           .       |   .   |   .   |   .   |
!           .           .       |   .   |   .   |   .   |
!           .           .       |   .   |   .   |   .   |
!       Nth hit -->     N       |   iN  |   jN  |   kN  |
!
!   where, the iN, jN, and kN are the row, column and plane index positions
!   of the Nth element found in the array to be searched.
!
!   Additionally, the parameter 'hits' is the number of occurences (=N) of
!   a particular element in the array which is output by this macro.
!
!
!
!
*get,prkey_,active,0,prkey
/nopr

arrynam_=arg1
arryelm_=arg2
!
!
*get,hittyp_,parm,hit,type
!
*if,hittyp_,ne,-1,then
    *set,hit(1),
*endif
!
*get,rnum_,parm,%arrynam_%,dim,x
*get,colnum_,parm,%arrynam_%,dim,y
*get,plnnum_,parm,%arrynam_%,dim,z
!
rowhit_=0
!
*do,klm_,1,plnnum_,1
    *do,mno_,1,colnum_,1
        *do,nop_,1,rnum_,1
            *if,%arrynam_%(nop_,mno_,klm_),eq,arryelm_,then
                *if,rowhit_,eq,0,then
                    *dim,hit,array,1,3
                    !
                    hit(1,1)=nop_
                    hit(1,2)=mno_
                    hit(1,3)=klm_
                    !
                    *get,rowhit_,parm,hit,dim,x
                *else
                    *dim,buffer_,array,rowhit_+1,3
                    !
                    *do,abc_,1,rowhit_,1
                        buffer_(abc_,1)=hit(abc_,1)
                        buffer_(abc_,2)=hit(abc_,2)
                        buffer_(abc_,3)=hit(abc_,3)
                    *enddo
                    !
                    *set,hit(1),
                    !
                    *dim,hit,array,rowhit_+1,3
                    !
                    *do,abc_,1,rowhit_,1
                        hit(abc_,1)=buffer_(abc_,1)
                        hit(abc_,2)=buffer_(abc_,2)
                        hit(abc_,3)=buffer_(abc_,3)
                    *enddo
                    !
                    hit(rowhit_+1,1)=nop_
                    hit(rowhit_+1,2)=mno_
                    hit(rowhit_+1,3)=klm_
                    !
                    *get,rowhit_,parm,hit,dim,x
                    !
                    *set,buffer_(1),
                *endif
            *endif
        *enddo
    *enddo
*enddo
!
hits=rowhit_
!
*set,nop_,
*set,mno_,
*set,klm_,
*set,abc_,
*set,rowhit_,
*set,arrynam_,
*set,arryelm_,
*set,hittyp_,
*set,rnum_,
*set,colnum_,
*set,plnnum_,

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