/out,pl_emf,out
/com, pl_emf.mac   3/7/02
/com, plots coil EMFS versus elctrical angle after a curve fit is performed to the coillinkages
/com, versus electrical angle. A maxium of 6 phases are plotted.

_err=0
*get,_temf,parm,coil_lnk,type
*if,_temf,ne,2,then
 /out
 /nerr
 *msg,error
 The coil linkage data is not defined. Possible cause is that the <ROT_CURR>&
 hasnot been used yet. No action
 /out,pl_emf,out,,append
 _err=1
*endif
*if,_mx_ph,le,0,then
/out
 /nerr
 *msg,error
 The data for the winding is missing. The data has been deleted or the winding has not&
 been generated. The winding needs to be regenerated. No action
 /out,pl_emf,out,,append
 _err=1
*endif
/nerr,0,1e5


*if,_err,gt,0,:end



*set,_mcoit
*dim,_mcoit,table,51,_mx_ph
_mcoit(0,0)=1e-6
*do,_im1,1,_mx_ph
  _mcoit(0,_im1)=_im1
*enddo

fini
 /prep7
 *do,_ip1,1,_mx_ph
 /com, compute the EMF from the data stored in coillink table
 /gopr

 *set,_coiltab
 *dim,_coiltab,,_dim,2
 !  load the data from the array _bh into the FITEM
 cmsel,,stator
 csys,1
 *get,_thmx,node,,mxloc,y
 *get,_thmn,node,,mnloc,y
 _deltaa=_thmx-_thmn
 perfac=nint(360/_deltaa)
 _inumpt=_numcp

 *vfun,_coiltab(1,1),copy,coil_lnk(1,0)      !   12/2/96   
 *vfun,_coiltab(1,2),copy,coil_lnk(1,_ip1)
 _inumpt=_dim
 *vscfun,_maxang,max,_coiltab(1,1)

 *stat,_coiltab
 fini
 /prep7
 csys
 cm,_c_k,kp
 ksel,all
 lsel,none
 *get,_kpmx,kp,,num,max
 _kpmx=_kpmx+1
 k,_kpmx,_coiltab(1,1),_coiltab(1,2)
 k,_kpmx+1,_coiltab(_inumpt,1),_coiltab(_inumpt,2)

 flst,2,2,3
 fitem,2,_kpmx
 fitem,2,_kpmx+1

 flst,3,_inumpt-2,8

 *do,_i1,2,_inumpt-1
  fitem,3,_coiltab(_i1,1),_coiltab(_i1,2),0
 *enddo

 bsplin,P51X,P51X

 *get,cl_spl,line,,num,max
 *get,_mxh,line,cl_spl,leng

 _inumpt=51  !   number of points 
  _c_fract=-1/(_inumpt-1)
 *set,_coit1
 *dim,_coit1,table,_inumpt,2
 _coit1(0,0)=1e-6
 _coit1(0,1)=1
 _coit1(0,2)=2

 *get,_mxh,line,cl_spl,leng
 *do,_i2,1,_inumpt
  _c_fract=_c_fract+1/(_inumpt-1)
  _coit11=lx(cl_spl,_c_fract)
  _coit10=ly(cl_spl,_c_fract)
  _ex_t=0
  *if,_coit11,gt,_maxang,then
    _mxlen=_i2
    _ex_t=1
  *endif
  _coit1(_i2,0)=_coit11
  _coit1(_i2,1)=_coit10
  *msg,info,_i2,_coit11,_coit10,_c_fract
  _i2,_coit11,_coit10:  %i  %g  %g  _c_fract: %g
  *if,_ex_t,eq,1,exit
 *enddo
  parsave,all,temp1,par
 !ldel,cl_spl,cl_spl,1,1
 *if,_ex_t,eq,1,then
  *set,_t_arr
  *dim,_t_arr,table,_mxlen
  *vlen,_mxlen
  *vfunc,_t_arr(1,0),copy,_coit1(1,0)
  *vlen,_mxlen
  *vfunc,_t_arr(1,1),copy,_coit1(1,1)
  *set,_coit1
  *dim,_coit1,table,_mxlen,2
  _coit1(0,0)=1e-6
  _coit1(0,1)=1
  _coit1(0,2)=2
  *vfunc,_coit1(1,0),copy,_t_arr(1,0)
  *vfunc,_coit1(1,1),copy,_t_arr(1,1)
 *endif
 _angfac=3.141593/180
 _angfac1=(npole/2)/_angfac          !   4/15/01
 *voper,_coit1(1,0),_coit1(1,0),mult,_angfac
 *voper,_coit1(1,2),_coit1(1,1),der1,_coit1(1,0)
 emffac=-2*3.141593*_hfreq*perfac
 *voper,_coit1(1,2),_coit1(1,2),mult,emffac
 *voper,_coit1(1,0),_coit1(1,0),mult,_angfac1
 *vscfun,_emfmx,max,_coit1(1,2)
 *vscfun,_emfmn,min,_coit1(1,2)

 *vfunc,_mcoit(1,_ip1),copy,_coit1(1,2)
*enddo

 /!xran,arg1*(npole/2),arg2*(npole/2)
 /xran
 /axlab,y,EMF (V)
 /axlab,x,Electrical Deg.
 /title, %mname%  EMF Versus Electrical Angle
 /anno,dele
 /num
*if,_mx_ph,eq,3,then
 *vplo,_coit1(1,0),_mcoit(1,1),2,3
*elseif,_mx_ph,eq,2,then
 *vplo,_coit1(1,0),_mcoit(1,1),2
*elseif,_mx_ph,eq,4,then
 *vplo,_coit1(1,0),_mcoit(1,1),2,3,4
*elseif,_mx_ph,eq,5,then
 *vplo,_coit1(1,0),_mcoit(1,1),2,3,4,5
*elseif,_mx_ph,eq,6,then
 *vplo,_coit1(1,0),_mcoit(1,1),2,3,4,5,6
*else
 *vplo,_coit1(1,0),_mcoit(1,1)
*endif

fini
/post1

:end
/out