!   TITLE:  mod_assemb_prep.mac (MANAGEMENT)
!
!
!   This sub-macro prepares a model for possible assembly with other
!   components.  Its execution is based on the decision variable
!   'assemble', where:
!
!       assemble = 0    clears the database and builds an individual part.
!                       If assemble = 0 (or left blank) for all succesive
!                       parts of an assembly, it will have no effect on the
!                       parameter 'assemble'.
!
!       assemble = 1    records all existing solid and FEA model entities
!                       into groups and maintains them unselected. If used
!                       in a part after a sub-assembly is initialized, then
!                       this part will be the first separate part that is
!                       not part of the previous sub-assembly.
!
!       assemble = 2    Initiates the creation of a sub-assembly. Bypasses
!                       use of MOD_ASSEMB_PREP. This allows a series of part
!                       macros to be run in order, allowing them to act as
!                       one part macro; i.e., a sub-assembly.
!
!   It initializes and maintains entity maximum values, coordinate system
!   numbers, entity count parameters, model count, coordinate system position
!   stack-ups, previous maximum values and numerical constants. Also, it un-
!   selects the previously created model entities and initializes the toolbar
!   abbreviations.
!
!   The following instructions apply to the use of the arguments:
!
!           assemble = argument which determines whether an assembly is
!                      to be performed (create multiple models in the
!                      database):
!
!                           0 (or blank) = do not perform assembly
!
!                           1 = perform assembly
!
!                           2 = do not execute MOD_ASSEMB_PREP
!
!           frst_mdl = argument determines the first model to calculate
!                      coordinate system stack-ups from:
!
!                           0 (or blank) = does not initiate c.s. stack-up
!                                          calculations
!
!                           1 = initiate c.s. stack-up calculations
!
!           f_mesh = mesh flag parameter.  This parameter determines whether
!                    models are to be meshed, whether individually or in an
!                    assembly:
!
!                           0 (or blank) = do not mesh solid models
!
!                           1 = mesh solid models
!
!                    This parameter can only be set in the 1st model of an
!                    assembly.
!
!
!   ***** CONDITIONS FOR USE OF ARGUMENTS:
!
!       a.) Creation of the first model in the database (modl_num = 1):
!
!           1.) If ASSEMBLE = 0 (or blank), then 'frst_mdl' is irrelevant,
!               since there will be no other models created to measure
!               stack-ups to.
!
!           2.) If ASSEMBLE = 1, then frst_mdl = 1 always, which is auto-
!               matically set by the algorithm.  Therefore, frst_mdl is left
!               blank.
!
!           3.) If ASSEMBLE = 2, the algorithm will skip execution of
!               MOD_ASSEMB_PREP.  This will allow the building of that current
!               macro without unselecting the previous model entities.  This
!               is essentially running all part macros (with ASSEMBLE = 2) as
!               one continuous macro; i.e., as if they were all in the same
!               part macro.  The only difference is that FINALIZE_MODEL_DATA
!               is executed, thereby storing/clearing the parameters.  Therefore,
!               the parameter files will still need to use PARAMETER_VALUE
!               where necessary.
!
!   `       When the first model in the database is created, only specify
!           'assemble', and leave 'frst_mdl' blank. In either case, 1 or 2,
!           frst_mdl = 1 for all first models in the database. Therefore,
!           coordinate system stack-up calculations are always initiated from
!           the first model in the database.
!
!       b.) Creation of successive models in the database (modl_num = 2 or more):
!
!           If modl_num = 2 or more, then 'assemble' is already set to 1,
!           and need not be specified in any remaining models. Therefore,
!           'assemble' is left blank in all models after the first.
!
!           1.) If FRST_MDL = 0 (or blank), then the algorithm will not
!               initiate stack-up calculations from this model. The ongoing
!               stack-up calculations initiated frorm the first model in the
!               database (modl_num = 1) will be continued without interuption.
!
!           2.) If FRST_MDL = 1, then the algorithm will initiate stack-up
!               calculations from this model onward, until 'frst_mdl' is
!               initiated again.
!
!   In summary, if you are creating a stand-alone model (not an assembly),
!   then simply call this macro with no arguments:
!
!                   EXAMPLE:    mod_assemb_prep
!
!   If you are performing an assembly, then the first model macro calling
!   this sub-macro must have a 1 in the first argument (assemble) of this
!   macro call, with no argument for 'frst_mdl':
!
!                   EXAMPLE:    mod_assemb_prep,1
!
!   For any successive model in an assembly (modl_num = 2 or more), and no
!   stack-up calculations from any or all of these particular models, simply
!   use this macro with no arguments:
!
!                   EXAMPLE:    mod_assemb_prep
!
!   For any successive model in an assembly (modl_num = 2 or more), and it
!   is desired to perform stack-up calculations from any of these
!   particular models, then simply place a 1 in the second argument only,
!   with no argument for 'assemble':
!
!                   EXAMPLE:    mod_assemb_prep,,1
!
!   Lastly, when ASSEMBLE = 2, then this part is the first part of a sub-assembly.
!   All successive parts with the first argument left blank will be part of that
!   sub-assembly.  The first part that is not part of this sub-assembly must have
!   a 1 in the first argument.
!
!           EXAMPLE:    mod_assemb_prep,2   <--- 1st part of sub-assembly
!
!                       mod_assemb_prep     <--- 2nd part of sub-assembly
!
!                       mod_assemb_prep     <--- 3rd part of sub-assembly
!                              .                            .
!                              .                            .
!                              .                            .
!                       mod_assemb_prep     <--- nth part of sub-assembly
!
!                       mod_assemb_prep,1   <--- 1st part of next assembly
!
!
!
! MOD_ASSEMB_PREP, assemble, frst_mdl
!

*get,prkey_,active,0,prkey
/nopr
!
*if,subassm_,eq,1,then
    *if,arg1,eq,1,then
        subassm_=0
    *elseif,arg1,eq,2,then
        subassm_=0
    *endif
*endif
!
*if,subassm_,ne,1,then          ! If assemble = 2, then, do not perform
    !
    finish
    !
    *if,assemble,eq,0,then
        clear_start_new,vidtog_
        selv='s'                ! selection type variable
    *else
        selv='r'
    *endif
    !
    /prep7                      ! activate preprocessor mode
*endif
!
    modl_num=1
    !
    *if,arg1,eq,1,then
        assemble=1
    *elseif,arg1,eq,2,then
        assemble=1
    *else
        assemble=0
    *endif
    !
    frst_mdl=modl_num
    !
    *dim,model,char,modl_num
    *dim,mdlbuff,char,modl_num+1
    !
    *dim,par_file,char,modl_num
    *dim,parfbuff,char,modl_num+1
    !
    *dim,parfmxi,array,modl_num
    *dim,pfmxibuf,array,modl_num+1
*else
    frst_mdl=arg2
    modl_num=modl_num+1
*endif
!
    km_prev=0
    lm_prev=0
    am_prev=0
    vm_prev=0
    em_prev=0
    nm_prev=0
*else
    km_prev=km
    lm_prev=lm
    am_prev=am
    vm_prev=vm
    em_prev=em
    nm_prev=nm
*endif
!
    *if,frst_mdl,eq,1,then
        xstack=0
        ystack=0
        zstack=0
    *endif
*endif
!
!
*if,subassm_,ne,1,then          ! If assemble = 2, then, do not perform
    !
    map_run_=1                  ! mod_assemb_prep IS RUN
    !
    allsel,all
    !
    !
    km=kmu                  ! store current maximum entity numbers
    numstr,kp,kmu           ! initialize entity numbers from current max values
    !
    *get,lmu,line,,num,max
    lm=lmu
    numstr,line,lmu
    !
    *get,amu,area,,num,max
    am=amu
    numstr,area,amu
    !
    *get,vmu,volu,,num,max
    vm=vmu
    numstr,volu,vmu
    !
    *get,emu,elem,,num,max
    em=emu
    numstr,elem,emu
    !
    *get,nmu,node,,num,max
    nm=nmu
    numstr,node,nmu
    !
    !
    *get,kp_pssof,kp,,count     ! entity count #'s to pass-off to INIT_ENTITY_NUM
    *get,ar_pssof,area,,count
    *get,vl_pssof,volu,,count
    *get,el_pssof,elem,,count
    *get,nd_pssof,node,,count
    !
    !
    *if,kp_pssof,gt,0,then
        ksel,s,kp,,1,kmu,1
        cm,_kset_,kp
        ksel,u,kp,,_kset_
    *endif
    !
    *if,ln_pssof,gt,0,then
        lsel,s,line,,1,lmu,1
        cm,_lset_,line
        lsel,u,line,,_lset_
    *endif
    !
    *if,ar_pssof,gt,0,then
        asel,s,area,,1,amu,1
        cm,_aset_,area
        asel,u,area,,_aset_
    *endif
    !
    *if,vl_pssof,gt,0,then
        vsel,s,volu,,1,vmu,1
        cm,_vset_,volu
        vsel,u,volu,,_vset_
    *endif
    !
    *if,el_pssof,gt,0,then
        esel,s,elem,,1,emu,1
        cm,_eset_,elem
        esel,u,elem,,_eset_
    *endif
    !
    *if,nd_pssof,gt,0,then
        nsel,s,node,,1,nmu,1
        cm,_ndset_,node
        nsel,u,node,,_ndset_
    *endif
*else
    map_run_=0                  ! mod_assemb_prep IS NOT RUN
*endif                          ! END arg1=2
!
!
!
*if,csn,eq,0,then
*endif
!
    subassm_=1
*else
    *if,modl_num,eq,1,then
        subassm_=0
    *endif
*endif
!
    !
    *get,zzzparmx,parm,,max     ! get count of user defined parameters
    *get,zzzzsclp,parm,,basic   ! get count of scalar parameters
    !
    zzzzsclp=zzzzsclp-1
    !
    *dim,zzzzparm,char,zzzzsclp+1   ! create array for storing parameters
    !
    zzzparof=0                  ! initialize parameter offset variable
    !
    *do,zzzzzzz1,1,zzzparmx-2,1
        !
        *if,zzzparof,eq,0,then
            zzzzzzz2=zzzzzzz1   ! If parameter offset is 0, leave as is.
        *else
            zzzzzzz2=zzzzzzz1-zzzparof  ! If parameter offset ~0, subtract it.
        *endif
        !
        *get,zzzzpar,parm,,loc,zzzzzzz1     ! retrieve parameter location
        *get,zzpartyp,parm,%zzzzpar%,type   ! retrieve parameter type
        !
        *if,zzzzzzz1,eq,zzzparmx-2,then     ! If ...zz1 = # scalar parameters,
            *if,zzpartyp,ne,0,then          ! If parameter type is not scalar,
                *exit                       ! then exit DO loop.
            *else                           ! If parameter type is scalar, then
                zzzzparm(zzzzzzz2,1)=zzzzpar    ! store in array position '..zz2'.
            *endif
        *else                               ! If zz1 ~= # scalar parameters,
            zzzzparm(zzzzzzz2,1)=zzzzpar    ! store in array position '...zz2'.
        *endif
        !
        *if,zzpartyp,ne,0,then          ! If parameter type not a scalar, then
            zzzparof=zzzparof+1         ! add 1 to parameter offset.
        *endif
        !
    *enddo
    !
    zzzzparm(zzzzsclp+1,1)='ASSMPMXI'   ! Store ASSMPMXI in last position
    assmpmxi=zzzzsclp+1                 ! Store the DIM of array in ASSMPMXI
    !
    *dim,assm_par,char,zzzzsclp+1       ! Store the contents of array in an
    !                                   ! array named ASSM_PAR.
    *do,zzzzijkl,1,zzzzsclp+1,1
        assm_par(zzzzijkl,1)=zzzzparm(zzzzijkl,1)
    *enddo
    !
    *set,zzzzijkl,
    *set,zzzzparm(1),
    *set,zzzzsclp,
    *set,zzzzpar,
    *set,zzzparmx,
    *set,zzzparof,
    *set,zzpartyp,
    *set,zzzzzzz1,
    *set,zzzzzzz2,
*endif
!
!
!
!
*GET,os_,Active,,SYNAME
!
*if,os_,eq,'SOLARIS',then
    /dev,font,1,charter,bold,r,20       ! Solaris 6 - Ultra Sparc 10
*elseif,os_,eq,'SOLARIS6',then
    /dev,font,1,charter,bold,r,20       ! Solaris 1 - Sparc 1
*else
    /dev,font,1,Arial,400,0,-16,0,0,,,  ! win95, NT, etc.
*endif
!
view,'iso'
!

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