/com,   ckslot.mac  10/07/01    add rotor winding option
!    
!   Checks currents in a series of slots in which the
!   real set numbers are in a pattern.
!   All elements are in a component "s_coil" !!
!
!    arg1 = starting real number (defaults to the min real number
!            in the component given in arg4)
!    arg2 = ending real number (defaults to the max real number
!            in the component given in arg4)
!    arg3 = increment in the real number (defaults to 1)
!    arg4 = name of the elements comprising the elements in the coil region
!           defaults to 's_coil' which are the elements in the coil region
!           for the stator
!
/gopr
/out,ckslot,out
cmsel,,s_coil
*set,ckcur
*if,arg3,eq,0,then
   arg3=1
*endif
*get,_rout,active,,rout

*if,_rout,ne,31,then
   fini
   /post1
*endif
_arg4=arg4

_err=0
*get,_targ4,parm,_arg4,type
*if,_targ4,ne,3,then
  *get,_twind,parm,windloc,type
  *if,_twind,eq,3,then
     arg4='r_coil'
  *else
    arg4='s_coil'
  *endif
*endif
cm,ce,elem
esel,none
cmsel,,%arg4%
*get,_ec_4,elem,,count
cmsel,,ce
*if,_ec_4,le,0,then
  _err=1
  /nerr
  /out
  *msg,error,arg4
  The specified component for the coil region ( %c ) does not&
  have any elements
 /out,ckslot,out,,append
 /nerr,0,1e5
*endif
*if,_err,eq,1,:end


esel,all
*get,_elmx,elem,,num,max
cmsel,,%arg4%
*set,_mskv
*dim,_mskv,,_elmx
*set,_rele
*dim,_rele,,_elmx
*vget,_mskv(1),elem,1,esel
*voper,_mskv(1),_mskv(1),gt,0
*vmask,_mskv(1)
*vget,_rele(1),elem,1,attr,real
*vmask,_mskv(1)
*vscfun,_rlmn,min,_rele(1)
*vmask,_mskv(1)
*vscfun,_rlmx,max,_rele(1)
*if,arg1,le,0,then
  arg1=_rlmn
*endif
*if,arg2,le,0,then
  arg2=_rlmx
*endif
/com, determine how many coils/slot
/com, determine if this is in the stator or in the rotor
cmsel,,%arg4%
cmsel,r,rotor
*get,_ec_4,elem,,count
*if,_ec_4,gt,0,then
  _cncon=nconr
*else
  _cncon=ncons
*endif
cmsel,,%arg4%
nckslot=nint((arg2-arg1+1)/arg3+.1)
*dim,ckcur,,nckslot,3
_islot=0
etab,,volu
etab,js,smisc,1
smult,current,js,volu

*do,islot,arg1,arg2,arg3
  /gopr
  *msg,info,islot
  ISLOT:  %i
  cmsel,,%arg4%
  esel,r,real,,islot
  ssum
  *get,current,ssum,,item,current
  _islot=_islot+1
  *if,_cncon,eq,1,then
   _cslot=nint((islot-_rlmn+1)/_cncon)
  *else
   _cslot=(islot-(_rlmn-2))/_cncon
   _cslot=nint(_cslot-.1)
   !*if,_cncon*nint(_cslot-.1),ne,_cslot,then
   !  _cslot=nint(_cslot-.1)+1
   !*endif
  *endif
 *msg,info,islot
  ISLOT:  %i
  ckcur(_islot,1)=islot
  ckcur(_islot,2)=current
  ckcur(_islot,3)=_cslot
*enddo
islot=
cmsel,,%arg4%
nsle

*if,_mg1,eq,0,then
 /auto
 /pnum,real,1
 /num
 eplo
 /num,1
*endif

*stat,ckcur
*get,_mnu,active,,menu
/nopr
/out,ckslot,sum
*msg,info

*msg,info

*msg,info
___SUMMARY OF CURRENTS IN THE SLOTS______<
*msg,info
____ Slot____Real_____Current_______
*msg,info
_____No._____No.______(Amp-turns)___
*vwrite,ckcur(1,3),ckcur(1,1),ckcur(1,2)
(3x,f7.0,f8.0,f12.1)

*msg,info

*msg,info
The current density is retained in the element item JS
*msg,info
which can be plotted by <PLOTCURR>

/out,_data
*if,_nomsg,eq,0,then
*if,_mg1,eq,0,then
 *uili,ckslot,sum
*else
 *list,ckslot,sum
*endif
*else
/out,ckslot,sum,,append
*msg,info,cycle
 Cycle number:_____ %i
*list,ckslot,sum
*endif

:end
/gopr
/out