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

! *** primary function: copy the picked environment

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

!  input arguments: 
!   _envloc    (arg1)    (int,sc)       the picked location in the env list
!   _MTNAME    (global)  (char*8,ar(4)) the name of the new shape

!  modified parameters:
!   xxxx            (array)

/nopr
_SUCCESS=1

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

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

*if,_MTNAME(1),eq,'        ',then
!{
   *msg,error
   MTshpadd error: The shape name is blank
   _SUCCESS=0
!}
*endif

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

! add the new environment (don't clear the copied BC!)
mtenvadd,1

! copy the data
*mfun,%_ACTENV%(1,1,1),copy,_ENV%_envloc%(1,1,1)
*mfun,%_ACTENV%(1,1,2),copy,_ENV%_envloc%(1,1,2)
*mfun,%_ACTENV%(1,1,3),copy,_ENV%_envloc%(1,1,3)
*mfun,%_ACTENV%(1,1,4),copy,_ENV%_envloc%(1,1,4) 
! thermal load file too
*do,_i,1,4
   _TEMPFIL(_CURENV,_i)=_TEMPFIL(_envloc,_i)
*enddo
*do,_i,1,10
   _TEMPRD(_CURENV,_i)=_TEMPRD(_envloc,_i)
*enddo

*if,_DEBUG,gt,1,then
!{
   /gopr
   /com, === leave MTenvcpy:
   _n=_NXTENV-1
   *vwrite,_envloc,_n
   ('   from location=',f3.0,' to=',f3.0)
   _name1 = _ENVNAM(_n,1)
   _name2 = _ENVNAM(_n,2)
   _name3 = _ENVNAM(_n,3)
   _name4 = _ENVNAM(_n,1)
   *vwrite,_name1,_name2,_name3,_name4
   ('   name=',4a)
   *if,debug,eq,5,then
      !{
      mtdumpenv                       ! dump out the entire data structure
      !}
   *endif
   *del,_type
   *del,_name1
   *del,_name2
   *del,_name3
   *del,_name4
   *del,_n
   *del,_i
!}
*endif

!}
*endif

! delete local variables
*del,_envloc
