1 | function DeleteRadiaMapLine(PathName,FileName,x,Bx,Bz,Lu,forder,funit,deleteLnstr,str) |
---|
2 | |
---|
3 | |
---|
4 | %% find the extension of the file |
---|
5 | exid = strfind(FileName,'.'); |
---|
6 | extension = FileName(exid:end); |
---|
7 | %find the main file name |
---|
8 | savefilename = [PathName,FileName(1:exid-1)]; |
---|
9 | |
---|
10 | %% delete the lines from the data |
---|
11 | |
---|
12 | % get the size of Bx and Bz before delete |
---|
13 | [Pz Px] = size(Bx); |
---|
14 | |
---|
15 | if (strncmp(deleteLnstr,'first',5)) |
---|
16 | DLn = 1; |
---|
17 | elseif(strncmp(deleteLnstr,'last',4)&&strncmp(str,'horizontal',10)) |
---|
18 | DLn = Pz; |
---|
19 | elseif(strncmp(deleteLnstr,'last',4)&&strncmp(str,'vertical',8)) |
---|
20 | DLn = Px-1; |
---|
21 | end |
---|
22 | |
---|
23 | |
---|
24 | |
---|
25 | switch str |
---|
26 | case 'horizontal' |
---|
27 | Bx(DLn,:) =[]; |
---|
28 | Bz(DLn,:) =[]; |
---|
29 | |
---|
30 | |
---|
31 | case 'vertical' |
---|
32 | Bx(:,DLn+1) =[]; % the first colum of Bx is y cooridinates |
---|
33 | Bz(:,DLn+1) =[]; % the first colum of Bx is y cooridinates |
---|
34 | end |
---|
35 | |
---|
36 | %% get the size of Bx and Bz |
---|
37 | [Pz Px] = size(Bx); |
---|
38 | |
---|
39 | %% save the data into a file |
---|
40 | fid =fopen([savefilename,'_delete',extension],'wt'); |
---|
41 | %save the headlines |
---|
42 | fprintf(fid,'%s\n','# Author: User'); |
---|
43 | fprintf(fid,'%s\n',['# ',FileName,' after delete the line' ]); |
---|
44 | fprintf(fid,'%s\n','# Undulator Length [m]'); |
---|
45 | fprintf(fid,'%-10.2f\n',Lu); |
---|
46 | fprintf(fid,'%s\n','# Number of Horizontal Points'); |
---|
47 | fprintf(fid,'%d\n',Px); |
---|
48 | fprintf(fid,'%s\n','# Number of Vertical Points'); |
---|
49 | fprintf(fid,'%d\n',Pz); |
---|
50 | |
---|
51 | |
---|
52 | |
---|
53 | %save the interploted horizontal kick |
---|
54 | fprintf(fid,'%s\n',['# Horizontal ',forder,' Order Kick ',funit]); |
---|
55 | fprintf(fid,'%s\n','START'); |
---|
56 | fprintf(fid,' %10.5e',x); %the first element is non exit |
---|
57 | fprintf(fid,'\n'); |
---|
58 | for i=1:Pz |
---|
59 | fprintf(fid,'%10.5e ',Bz(i,:)); |
---|
60 | fprintf(fid,'\n'); |
---|
61 | end |
---|
62 | |
---|
63 | %save the interploted vertical kick |
---|
64 | fprintf(fid,'%s\n',['# Vertical ',forder,' Order Kick ',funit]); |
---|
65 | fprintf(fid,'%s\n','START'); |
---|
66 | fprintf(fid,' %10.5e',x); %the first element is non exit |
---|
67 | fprintf(fid,'\n'); |
---|
68 | for i=1:Pz |
---|
69 | fprintf(fid,'%10.5e ',Bx(i,:)); |
---|
70 | fprintf(fid,'\n'); |
---|
71 | end |
---|
72 | |
---|
73 | fclose(fid); |
---|