source: MML/trunk/machine/SOLEIL/StorageRing/RadiaMapGui/SmoothRadiaMap.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 2.2 KB
Line 
1function [sx,sBx,sBz] = SmoothRadiaMap(PathName,FileName,x,Bx,Bz,Px,Pz,Lu,forder,funit)
2
3% smooth the Radia Map of interstion device, to make the data more smooth,
4% then can
5
6%% smooth the data and do spline interpolation
7
8f = 5;
9xn = (x(end)-x(1))/double((Px-1))/f;
10sx = x(1):xn:x(end);
11% smooth the Bx & By
12for i = 1:Pz
13sBx(i,:) = pchip(x,Bx(i,2:end),sx);
14sBz(i,:) = pchip(x,Bz(i,2:end),sx);
15end
16
17% the new horizontal and vertical points
18[sPz sPx] =  size(sBx);
19
20%find the extension of the file
21exid = strfind(FileName,'.');
22extension = FileName(exid:end);
23%find the main file name
24savefilename = [PathName,FileName(1:exid-1)];
25
26%%  save the data after interpolation
27fid =fopen([savefilename,'_interpolation',extension],'wt');
28%save the headlines
29fprintf(fid,'%s\n','# Author:  User');
30fprintf(fid,'%s\n',['# ',FileName,' (after smooth)']);
31fprintf(fid,'%s\n','# Undulator Length [m]');
32fprintf(fid,'%-10.4f\n',Lu);
33fprintf(fid,'%s\n','# Number of Horizontal Points');
34fprintf(fid,'%d\n',sPx);
35fprintf(fid,'%s\n','# Number of Vertical Points');
36fprintf(fid,'%d\n',sPz);
37
38
39
40%save the interploted horizontal kick
41fprintf(fid,'%s\n',['# Horizontal ',forder,' Order Kick ',funit]);
42fprintf(fid,'%s\n               ','START');
43fprintf(fid,'% 10.5e   ',sx); %the first element is non exit
44fprintf(fid,'\n');
45for i=1:Pz
46    fprintf(fid,'% 10.5e   ',[Bz(i,1),sBz(i,:)]);
47fprintf(fid,'\n');
48end
49
50%save the interploted vertical kick
51fprintf(fid,'%s\n',['# Vertical ',forder,' Order Kick ',funit]);
52fprintf(fid,'%s\n               ','START');
53fprintf(fid,'% 10.5e   ',sx); %the first element is non exit
54fprintf(fid,'\n');
55for i=1:Pz
56    fprintf(fid,'% 10.5e   ',[Bx(i,1),sBx(i,:)]);
57    fprintf(fid,'\n');
58end
59
60fclose(fid);
61
62
63% %% plot the data before and after interpolation
64%  figure(1);
65%  plot(x,Bz(:,2:end),'b-');
66%  hold on;
67%  plot(sx,sBz,'r-');
68%  xlabel('x[m]');
69%  ylabel([forder, ' horizontal kick ',funit]);
70%  legend('before smooth','after smooth');
71%  title(['spline interpolation, data is amplified by ', num2str(f)]);
72
73%   figure(2);
74%  plot(x,Bx(:,2:end),'b-');
75%  hold on;
76%  plot(sx,sBx,'r-');
77%  xlabel('x[m]');
78%  ylabel([forder, ' vertical kick ',funit]);
79%  legend('before smooth','after smooth');
80%  title(['spline interpolation, data is amplified by ', num2str(f)]);
Note: See TracBrowser for help on using the repository browser.