/out,s_ind,out
/com, s_ind.mac  3/6/99
!  computes the inductance matrix  based on the winding which has already been
!  been constructed by b_wndsc.mac  which corresponds to a specified 
!  winding file. 
!
!  This macro does NOT move the rotor and and does not connect the rotor to the stator
!
!  arg1 = electrical angle (degrees)
!  arg2 = peak current (A)
!
!  Output:
!   The inductance matrix is stored in the array INDUC
/com, apply the currents to the coil
_mg1=1
fini
/prep7
alls
bfedel,all,all,all
fini
/solu
_mg1=1
ld_coil,arg1,arg2
/out,s_ind,out,,append

*if,_err,ne,0,then
  /nerr
  /out
  *msg,info
  The data for the winding is missing-regenerate the winding.
  /out,s_ind,out,,append
  /nerr,0,1e4
*endif

*if,_err,ne,0,:end
!
/com, solve for the operating point solution
/out,s_ind,out,,append
_nomsg=1

 ll_matrix=1
 mvpsol
 ll_matrix=

_nomsg=
/out,s_ind,out,,append

!
/COM, Using the data from b_wndsc.mac and ld_coil to 
/com, construct the input for lmatrix
!  _mx_ph =number of phases from b_wndsc.mac
!  _cphc  = factor for each phase from ld_coil
*set,ccurr
*dim,ccurr,,_mx_ph
*set,induc
!*dim,induc,,_mx_ph
*dim,induc,,_mx_ph,_mx_ph
*set,ph_
*dim,ph_a,char,7
ph_a(1)='ph_1','ph_2','ph_3','ph_4','ph_5','ph_6','ph_7'
*do,_i1,1,_mx_ph
 _tname=_ph_n(_i1)
 cmsel,,%_tname%
 cm,%ph_a(_i1)%,elem
 ccurr(_i1)=_cphc(_i1)*arg2
*enddo
*stat,ccurr

esel,all
esel,u,ename,,36
nsle
csys,1
*get,thmin,node,,mnloc,y
*get,thmax,node,,mxloc,y
_delth=abs(thmax-thmin)
facsym=nint(360/_delth)
csys
fini
/solu
esel,all
nsle
_mg1=1
l_matrix,facsym,'ph_','ccurr','induc'
/out,s_ind,out,,append
:end
_mg1=0
/out