/out,pldcstr,out
/com, pldcstr.mac  3/23/01
!  This macro plots specifed phases.  Volumes are generated to represent
!  the phases.  The dimensions for the volumes
!  are taken from the elements/nodes comprising the slot. The length of 
!  the stack is corresponds to the input stack length. All dimensions are in
!  meters.  The displayed thickness of the stack can be factored by the 
!  parameter FAC_STK which defaults to .5.
!
! Attributes for the volumes generated for the phases
!  Real number      =  phase number from the winding file
!  Material number  =  slot number
!  Type number      =  UP/DOWN
!                          = 1  , IN  (-) slot in winding file for the coil
!                          = 2  , OUT (+) slot in winding file for the coil
!  ESYS number      =  coil in the winding file (1= the first winding in the winding file)
!
!   All volumes for the phases are contained the volume component Vphase
!     
!   Input arguements:
!
!   arg1=starting phase number , defaults to 1
!   arg2=ending phase number   , defaults to all phases
!   arg3=increment phase number, defaults to 1
!
_err=0
*if,arg1,le,0,then
  arg1=1
*endif

_mx_ph=0
*vscfun,_mx_ph,max,wnd_(1,4)
*if,_mx_ph,le,0,then
   /out
   /nerr
   /nopr
   *msg,error
   The data (WND_) generated for the specified winding file name does not&
   have all the correct data. Winding data should be regenerated.  No action
   /out,pldcstr,out,,append
   _err=1
   /gopr
*endif


*if,arg2,le,0,then
 arg2=_mx_ph
*endif

*if,arg3,le,0,then
 arg3=1
*endif

*if,_n_slot*_nteeth,eq,0,then
   /out
   /nerr
   /nopr
   *msg,error
   The data generated for the specified winding file name does not&
   have all the correct data. Winding data should be regenerated.  No action
   /out,pldcstr,out,,append
   _err=1
   /gopr
*endif

*get,_typc10,parm,cwnd_,type
*if,_typc10,ne,4,then
   /out
   /nerr
   /nopr
   *msg,error
   It does not appear that the Winding data has been generated or it has been&
   been deleted. The winding needs to be regenerated. No action
   /out,pldcstr,out,,append
   _err=1
   /gopr
*endif

*if,_typc10,eq,4,then
  *get,_zc1000,comp,%cwnd_(1)%,type
  *if,_zc1000,ne,2,then
   /out
   /nerr
   /nopr
   *msg,error
   It appears that the winding was at one time generated, but the element&
   component definitions which were generated by <WIND_2D> have been deleted.&
   This could have resulted due to regeneration of the stator.  The winding needs&
   to be regenerated. No action
   /out,pldcstr,out,,append
   _err=1
  *endif
*endif

*if,_err,eq,1,:end
/anno,dele
/ANUM,     1,     1,-0.67249    , 0.90918
/TSPE, 15, 1.000,   1,   0,   0
/TLAB,-0.970, 0.909,Type=1 => IN SLOT
/ANUM,     2,     1,-0.63757    , 0.85913
/TLAB,-0.970, 0.859,Type=2 => OUT SLOT
/ANUM,     3,     1,-0.62000    , 0.80920
/TLAB,-0.970, 0.809,Real = phase number
/ANUM ,0,     1,-0.62009    , 0.75326
/TLAB,-0.970, 0.753,Material=Coil number in file

/title,%mname% phase plot
*if,fac_stk,le,0,then
  fac_stk=.5
*endif

*set,get_s
*dim,get_s,,_n_slot

n_i2=0
*do,_i1,arg1,arg2,arg3
 n_i2=n_i2+1
 get_s(n_i2)=_i1
*enddo

*get,_rout,active,,rout
*if,_rout,ne,17,then
 fini
 /prep7
*endif

vsel,none
cmsel,,vphase
*get,ncvnt,volu,,count
*if,ncvnt,gt,0,then
 aslv
 lsla
 ksll
 vdel,all,,,1
*endif

vsel,none
cm,vphase,elem

csys,1
/num,1
*do,_i1,1,n_i2      !  the phase
 _w1=get_s(_i1)
 esel,none
 *do,_w2,1,_n_slot  !  the number of slots
  /gopr
  *if,wnd_(_w2,4),eq,_w1,then     ! this coil is in this phase
  /com, the out  (+)
  *msg,info,_w1,_w2
  _w1,_w2:  %i %i
  !c_ptwnd=pt_wnd(_w1,_w2)
  !c_rld=rsc_ud(c_ptwnd,1)
  !esel,,real,,c_rld 
  /com, the in
  cmsel,,%cwnd_(_w2,1)%
  nsle
  *get,_thmx,node,,mxloc,y
  *get,_thmn,node,,mnloc,y
  *if,_thmx*_thmn,lt,0,then
    /com, splits the coil
    *if,_thmx-_thmn,gt,90,then
      /com, split on the -X axis 
      local,20,1
      cscir,20,1
      *get,_thmx,node,,mxloc,y
      *get,_thmn,node,,mnloc,y
      csys,1
     *endif
  *endif
  *get,_rmax,node,,mxloc,x
  *get,_rmin,node,,mnloc,x
  _zstk=stkthk*ggeom/2*fac_stk
  vsel,none
  cylinder,_rmin,_rmax,-_zstk,_zstk,_thmn,_thmx
  _m_in=wnd_(_w2,1)
  vatt,_w2,_w1,1
  cmsel,a,vphase
  cm,vphase,volu

  /com, the out
  cmsel,,%cwnd_(_w2,2)%
  !c_rld=rsc_ud(c_ptwnd,2)
  !esel,,real,,c_rld 
  nsle
  *get,_thmx,node,,mxloc,y
  *get,_thmn,node,,mnloc,y
  *if,_thmx*_thmn,lt,0,then
    /com, splits the coil (the out)
    *if,_thmx-_thmn,gt,90,then
      /com, split on the -X axis 
      local,20,1
      cscir,20,1
      *get,_thmx,node,,mxloc,y
      *get,_thmn,node,,mnloc,y
      csys,1
     *endif
  *endif
  *get,_rmax,node,,mxloc,x
  *get,_rmin,node,,mnloc,x
  vsel,none
  cylinder,_rmin,_rmax,-_zstk,_zstk,_thmn,_thmx,
  _m_out=wnd_(_w2,2)
  vatt,_w2,_w1,2
  cmsel,a,vphase
  cm,vphase,volu
  *msg,info
  **********************************************
  *endif

 *enddo
*enddo
cmsel,,vphase
aslv
lsla
ksll
/auto
/pnum,real,1
/pnum,kp
/pnum,line
/pnum,area
/pnum,volu
/num
vplo

/anno,dele
/ANUM,     1,     1,-0.67249    , 0.90918
/TSPE, 15, 1.000,   1,   0,   0
/TLAB,-0.970, 0.909,Type=1 => OUT SLOT
/ANUM,     2,     1,-0.63757    , 0.85913
/TLAB,-0.970, 0.859,Type=2 => IN SLOT
/ANUM,     3,     1,-0.62000    , 0.80920
/TLAB,-0.970, 0.809,Real = phase number
/ANUM ,0,     1,-0.62009    , 0.75326
/TLAB,-0.970, 0.753,Material=coil number in file

/title,%mname% phase plot
cmsel,,vphase
/auto
/pnum,real,1
/num
/type,,2
vplo
!emod,all,esys,0
*if,_rout,eq,21,then
 fini
 /solu
*endif
*if,_rout,eq,31,then
 fini
 /post1
*endif
!/anno,dele
/eras


:end
/nerr,0,1e5
/out