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

! *** primary function: delete the picked environment

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

!  input arguments: 
!   _envloc    (arg1)    (int,sc)      the picked location in the env list

!  modified parameters:
!   xxxx            (array)

_SUCCESS=1
/nopr

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

_envloc = ARG1
*if,_envloc,lt,1,then
!{
   *msg,error,_envloc
   MTenvdel error: The picked location in the list is %i
   _SUCCESS=0
!}
*elseif,_envloc,gt,_NUMENV,then
!{
   *msg,error,_envloc,_NUMENV
   MTenvdel error: The picked location in the list is %i which is greater &
   than NUMENV
   _SUCCESS=0
!}
*endif

! delete the environment
*if,_SUCCESS,gt,0,then
!{

_ENVDP(_envloc) = 0       ! deleted
*del,_ENV%_envloc%

*if,_NUMENV,eq,1,then
   ! deleting the first and only environment: just clear it
   _NXTENV = 1
   _NUMENV = 0
   _MTNAME(1) = 'Environm'
   _MTNAME(2) = 'ent 1   '
   _MTNAME(3) = '        '
   _MTNAME(4) = '        '
   mtenvadd
   ! set the global picked location
*elseif,_envloc,eq,_NUMENV,then
   ! deleting the last entry
   _ENVNAM(_envloc,1) = '        '
   _ENVNAM(_envloc,2) = '        '
   _ENVNAM(_envloc,3) = '        '
   _ENVNAM(_envloc,4) = '        '
   _NXTENV = _NXTENV - 1
   _NUMENV = _NUMENV - 1
*else
   ! deleting one in the middle: leave a carcass
   _ENVNAM(_envloc,1) = '-deleted'
   _ENVNAM(_envloc,2) = '-       '
   _ENVNAM(_envloc,3) = '        '
   _ENVNAM(_envloc,4) = '        '
*endif

! set CURENV to an active environment
_CURENV=0
*do,_i,_NUMENV,1,-1
   *if,_ENVDP(_i),gt,0,then
      _CURENV=_i
      *exit
   *endif
*enddo
*if,_CURENV,eq,0,then
   ! this env does not exist - create a new one
   _MTNAME(1) = 'Environm'
   _char=chrval(_NXTENV)
   _MTNAME(2) = strfill('ent ',_char,5)
   _MTNAME(3) = '        '
   _MTNAME(4) = '        '
   mtenvadd,1
*endif
*endif

! display the BCs of the active environment
immed,0     ! turn off immediate display (too slow and we replot anyway!)
lsclear,solid
lsclear,fe
lsclear,iner
immed,1
mttranbc,1

*if,_DEBUG,gt,1,then
!{
   /gopr
   /com, === leave MTenvdel:
   _type = _ENVDP(_envloc)
   *vwrite,_envloc,_type
   ('   location=',f3.0,' deleted   show flag=',f3.0)
   *if,debug,eq,5,then
      !{
      mtdumpenv                       ! dump out the entire data structure
      !}
   *endif
   *del,_type
!}
*endif

!}
*endif

! delete local variables
*del,_envloc
*del,_i