! ******************************
! $Revision: 145002 $
! $Date: 2009-11-13 11:20:27 -0500 (Fri, 13 Nov 2009) $
! ******************************
! macro MTenvadd (_keepkey)

! *** primary function: add a new environment

! *** Notice - This file contains ANSYS Confidential information ***

!  input arguments:
!   _keepkey   (arg1)    (int,sc)       =0, clear existing BC (new env)
!                                       =1, keep existing BC (copy env)
!   _MTNAME    (global)  (char*8,ar(4)) the name of the new environment

!  modified parameters:
!   xxxx            (array)

/nopr
_SUCCESS=1

*if,_DEBUG,gt,0,then
!{
   /gopr
   *vwrite,arg1
   (' === MTenvadd:   keepkey =',f3.0)
   *if,_DEBUG,lt,3,then
   !{
      /nopr
   !}
   *endif
!}
*endif

_keepkey=arg1
*if,_keepkey,lt,0,then
   *msg,error
   MTenvadd error: The keepkey is less than 0
   _SUCCESS=0
*elseif,_keepkey,gt,1,then
   *msg,error
   MTenvadd error: The keepkey is greater than 1
   _SUCCESS=0
*endif
*if,_MTNAME(1),eq,'        ',then
   *msg,error
   MTenvadd error: The environment name is blank
   _SUCCESS=0
*endif

*if,_SUCCESS,gt,0,then
!{

_ENVNAM(_NXTENV,1) = _MTNAME(1)
_ENVNAM(_NXTENV,2) = _MTNAME(2)
_ENVNAM(_NXTENV,3) = _MTNAME(3)
_ENVNAM(_NXTENV,4) = _MTNAME(4)

_ENVDP(_NXTENV) = 1           ! set to show but not solved

_ACTENV = '_ENV%_NXTENV%'
*dim,%_ACTENV%,array,_MAXENT,30,4
*do,_i,1,3
  ! fill first column with entity numbers
  *vfill,%_actenv%(1,1,_i),ramp,1,1
  ! set all the disp/rot/temps to -999 unrestrained
  *VFILL,%_actenv%(1,2,_i),RAMP,_FREE,0,
  *VFILL,%_actenv%(1,3,_i),RAMP,_FREE,0,
  *VFILL,%_actenv%(1,4,_i),RAMP,_FREE,0,
  *VFILL,%_actenv%(1,21,_i),RAMP,_FREE,0,
  *VFILL,%_actenv%(1,22,_i),RAMP,_FREE,0,
  *VFILL,%_actenv%(1,23,_i),RAMP,_FREE,0,
  *VFILL,%_actenv%(1,15,_i),RAMP,_FREE,0,
*enddo   
*del,_i

! set the global picked location
_CURENV = _NXTENV

! update the counters
_NXTENV = _NXTENV + 1
_NUMENV = _NUMENV + 1

! clear the display of all BCs
*if,_keepkey,eq,0,then
   immed,0     ! turn off immediate display (too slow and we replot anyway!)
   lsclear,solid
   lsclear,fe
   lsclear,iner
   immed,1
*endif

*if,_DEBUG,gt,1,then
!{
   /gopr
   /com, === leave MTenvadd:
   _n = _NXTENV - 1
   _name1 = _ENVNAM(_n,1)
   _name2 = _ENVNAM(_n,2)
   _name3 = _ENVNAM(_n,3)
   _name4 = _ENVNAM(_n,4)
   _flag = _ENVDP(_n)
   *vwrite,_n,_name1,_name2,_name3,_name4
   ('   location=',f3.0,'    name=',4a)
   *vwrite,_ACTENV,_flag
   ('   ACTENV=',a,'   show flag=',f3.0)
   *if,debug,eq,5,then
      !{
      mtdumpenv                       ! dump out the entire data structure
      !}
   *endif
   *del,_n
   *del,_flag
   *del,_name1
   *del,_name2
   *del,_name3
   *del,_name4
!}
*endif

!}
*endif

*del,_keepkey
