!   TITLE:  parm_val.mac (MANAGEMENT)
!
!
!               Modified code to check if a model is built.  If it exists
!               it retrieves the parameter value; if not it aborts. Also
!               added default assignment parameter.
!
!               Modified code to use the default value if a parameter
!               array is found but the parameter is not defined.
!
!   OBJECTIVE:
!
!   This sub-macro initializes/retrieves a parameter value from a previously
!   stored array of parameter values.
!
!
!   COMMAND SYNTAX:
!
!                   (1)      (2)     (3)       (4)
!       PARM_VAL, mod_name, param, new_parm, def_val
!
!
!   ARGUMENTS:
!
!       (1) mod_name = model name using the parameter file which has
!                      the desired user value.  This may be retrieved
!                      from the array 'MODEL'.
!
!       (2) param = desired parameter within the parameter file to be
!                   queried.
!
!       (3) new_parm = new parameter character name to assign the value to
!
!       (4) def_val = parameter assignment default value.  If ALL of the
!                     following conditions are met:
!
!                   a.) the parameter array for a model does not exist
!
!                   b.) the parameter NEW_PARM is not previously defined
!
!                   c.) DEF_VAL is not equal to 0
!
!               then DEF_VAL is assigned to the new specified parameter.
!
!           In the event that a given model, and therefore the parameter
!           array, does not exist for retrieval, these conditions will insure
!           that a previously defined value for a parameter holding the name
!           of NEW_PARM is not overwritten when this macro is executed. Also,
!           if the parameter NEW_PARM is not previously defined, it will not
!           be initialized with a value of 0 when DEF_VAL is left blank.
!
!
!   DESCRIPTION:
!
!   These parameter values may be used to link separate models together whose
!   surfaces may interface. This will keep the surfaces contingent by using the
!   same dimensional values to interface the parts (e.g., outer diameter of one
!   part mating with the inner diameter of a second part, therefore same diame-
!   ter value must be used for the two mating surfaces from a given axis of rot-
!   ation). This prevents the user from searching for a specific parameter value
!   manually, and keeps the parts linked if a specific paramter value is changed.
!
!
!
*get,prkey_,active,0,prkey
/nopr
!
mod_name=arg1
param_=arg2
newparm_=arg3
defval_=arg4
!
!
param_=upcase(param_)
!
*get,parftyp_,parm,par_file,type
!
*if,parftyp_,eq,4,then
    !
    *get,modlim_,parm,par_file,dim,x
    !
    *do,iiii_,1,modlim_,1
        *if,mod_name,eq,model(iiii_,1),then
            mod_indx=iiii_
            abrtget_=0
            *exit
        *else
            *if,iiii_,eq,modlim_,then
                abrtget_=1
            *endif
        *endif
    *enddo
    !
    *if,abrtget_,eq,0,then
        parm_arr=par_file(mod_indx,1)
        !
        max_indx=parfmxi(mod_indx,1)
        !
        *do,iiii_,1,max_indx,1
            *if,param_,eq,%parm_arr%(iiii_,1),then
                %newparm_%=%parm_arr%v(iiii_,1)
                *exit
            *else
                *if,iiii_,eq,max_indx,then
                    *get,ptyp_,parm,%newparm_%,type
                    !
                    *if,ptyp_,eq,-1,then
                        *if,defval_,ne,0,then
                            %newparm_%=defval_
                        *endif
                    *endif
                *endif
            *endif
        *enddo
    *else
        *get,ptyp_,parm,%newparm_%,type
        !
        *if,ptyp_,eq,-1,then
            *if,defval_,ne,0,then
                %newparm_%=defval_
            *endif
        *endif
    *endif
*else
    *get,ptyp_,parm,%newparm_%,type
    !
    *if,ptyp_,eq,-1,then
        *if,defval_,ne,0,then
            %newparm_%=defval_
        *endif
    *endif
*endif
!
*set,mod_name,
*set,param_,
*set,newparm_,
*set,defval_,
*set,iiii_,
*set,max_indx,
*set,mod_indx,
*set,parm_arr,
*set,abrtget_,
*set,ptyp_,
*set,parftyp_,
*set,modlim_,

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