% creat a .pts(.txt) file for ANSFOT dataexporting
% written by RAO B.,2012.05.12
clear all;
R=1.05*1000;
r=0.26*1000;
N_tht=384;N_phi=384;
tht=0:2*pi/N_tht:2*pi-2*pi/N_tht;
phi=-pi/4:2*pi/N_tht:pi/4-2*pi/N_tht;
len_tht=length(tht);len_phi=length(phi);
THT=repmat(tht,len_phi,1);
PHI=repmat(phi',1,len_tht);
xx=(R+r*cos(THT)).*cos(PHI);
yy=(R+r*cos(THT)).*sin(PHI);
zz=r*sin(THT);
cordn=zeros(len_phi*len_tht,3);
for i1=1:1:len_phi
forj1=1:1:len_tht
cordn((i1-1)*len_tht+j1,1)=xx(i1,j1);
cordn((i1-1)*len_tht+j1,2)=yy(i1,j1);
cordn((i1-1)*len_tht+j1,3)=zz(i1,j1);
end
end
fid=fopen('B_cordn_a.txt','w');
fprintf(fid,'Unit=mm\r\n');
fprintf(fid,'%f %f %f \r\n',cordn');
fclose(fid);
% open the result file from ANSOFT by excel, andsave it as B_cordn_a.xlsx
B_cordn=xlsread('B_cordn_a.xlsx');
THT1=repmat(tht',len_phi,1);
for i1=1:1:len_phi
PHI1((i1-1)*len_tht+1:i1*len_tht,1)=phi(i1);
end
% Br_cordn1(xx yy zz Bx By Bz)
Br_cordn1=B_cordn(:,4).*cos(THT1).*cos(PHI1)+B_cordn(:,5).*cos(THT1).*sin(PHI1)+B_cordn(:,6).*sin(THT1);
Btht_cordn1=-B_cordn(:,4).*sin(THT1).*cos(PHI1)-B_cordn(:,5).*sin(THT1).*sin(PHI1)+B_cordn(:,6).*cos(THT1);
Bphi_cordn1=-B_cordn(:,4).*sin(PHI1)+B_cordn(:,5).*cos(PHI1);
Br_cordn=(reshape(Br_cordn1,len_tht,len_phi))';
Btht_cordn=(reshape(Btht_cordn1,len_tht,len_phi))';
Bphi_cordn=(reshape(Bphi_cordn1,len_tht,len_phi))';