!   TITLE:  vol_cg.mac (CALCULATION)
!
!
!   OBJECTIVE:
!
!   This macro records the position of the centroid and the volume of each
!   volume in a selected set of volumes.
!
!
!   COMMAND SYNTAX:
!
!                    (1)
!           VOL_CG, vol_#
!
!
!   ARGUMENTS:
!
!       (1) vol_# = volume number
!
!             a.) 0 (or blank) = the current selected set of volumes.
!
!             b.) N (where N > 0) = the volume number N.
!
!             c.) 'comp_name' = component group character name containing
!                               the volumes. [ MUST BE IN SINGLE QUOTES ]
!
!
!   DESCRIPTION:
!
!   The selected/specified volume(s) are stored in an array named: VCG_DATA.
!   The array contains 5 pieces of data for each volume:
!
!       1.) volume number
!       2.) volume
!       3.) X-coordinate of volume centroid (relative to csys = 0)
!       4.) Y-coordinate of volume centroid (relative to csys = 0)
!       5.) Z-coordinate of volume centroid (relative to csys = 0)
!
!   Each piece of data is stored in each column, with each row a volume. The
!   array, VCG_DATA, takes the following form:
!
!                                   COLUMNS
!             ROW   |   1    |  2   |   3   |   4   |   5   |
!          --------------------------------------------------
!              1    | vol_#1 |  V1  |  Xc1  |  Yc1  |  Zc1  |
!              2    | vol_#2 |  V2  |  Xc2  |  Yc2  |  Zc2  |
!              3    | vol_#3 |  V3  |  Xc3  |  Yc3  |  Xc3  |
!              .    |   .    |  .   |   .   |   .   |   .   |
!              .    |   .    |  .   |   .   |   .   |   .   |
!              N    | vol_#N |  VN  |  XcN  |  YcN  |  ZcN  |
!
!   The number of volumes (and therefore the number of rows in VCG_DATA) are
!   output in the parameter:
!                                   NUM_VOLS
!
!   Each succesive run of this macro erases the array data from the previous
!   run. If the data is to be retained from any run, the use of ARRY_TRANSFER
!   may be used to replicate the data into a new array of a different name.
!
!
!
*get,prkey_,active,0,prkey
/nopr
!
volnum__=arg1
!
configuration,0
!
*set,vcg_data(1),
!
! Parameter type: 0=scalar, 1=array, 2=table, 3=character scalar,
!                 4=character array, -1=undefined
!
*get,argtyp_,parm,volnum__,type
!
*if,argtyp_,eq,0,then
    *if,volnum__,eq,0,then
        volnum__='cmpvset_'
        cm,%volnum__%,volu
    *elseif,volnum__,gt,0,then
        vsel,s,volu,,volnum__
        volnum__='cmpvset_'
        cm,%volnum__%,volu
    *endif
*elseif,argtyp_,eq,3,then
    cmsel,s,%volnum__%
*endif
!
cmsel,s,%volnum__%
!
entity_array,'v','vcg_data','array',,,5
vcnt__=ecount
!
csys,0
!
*do,abc_,1,vcnt__,1
    vsel,s,volu,,vcg_data(abc_,1)
    vsum
    !
    *get,vcg_data(abc_,2),volu,,volu
    !
    *get,vcg_data(abc_,3),volu,,cent,x
    *get,vcg_data(abc_,4),volu,,cent,y
    *get,vcg_data(abc_,5),volu,,cent,z
*enddo
!
num_vols=vcnt__
!
configuration,1
!
cmdele,%volnum__%
*set,volnum__,
*set,vcnt__,
*set,ecount,
*set,argtyp_,
*set,parmtyp_,
*set,abc_,
!
*if,prkey_,eq,1,then
    /go
*endif