1 | function Update_InVacID(SESSION,CellName,SSType,UndType,TableName,SufUndName) |
---|
2 | % SESSION: Folder where the data are stored: must be created previously |
---|
3 | % CellName: name of the cell in the SR: for ex. ANS-C11 |
---|
4 | % SSType: Type of Straight Section: C or M or L |
---|
5 | % UndType: Type of ID: U18 (CRYO), U20, U24 or WSV50 |
---|
6 | % TableName : Name of the FF Table: for ex. FF_SIXS.txt. This table must |
---|
7 | % previously exists, otherwise use GenerateFFtableWithZeros which creates a |
---|
8 | % FF tables containing zeros with exponential step |
---|
9 | % SufUndName is the suffix which indicates the position of the ID in the |
---|
10 | % Straight Section: SufUndName can be: |
---|
11 | % '': when no other ID is installed in the SS |
---|
12 | % '.1','.2' ...: when the ID is installed at the position 1,2 ... |
---|
13 | % Example: Update_InVacID('SESSION_24_01_10','ANS-C11','M','U24','FF_PROXIMA2.txt','') |
---|
14 | % Example: Update_InVacID('SESSION_24_01_10','ANS-C07','C','U20','FF_GALAXIES.txt','') |
---|
15 | % Example: Update_InVacID('SESSION_26_06_10','ANS-C03','C','WSV50','FF_PSICHE.txt','') |
---|
16 | % Example: Update_InVacID('SESSION_23_09_11','ANS-C13','L','U18','FF_TOMO.txt','.1') |
---|
17 | % Example: Update_InVacID('SESSION_06_11_11','ANS-C13','L','U20','FF_NANO.txt','.2') |
---|
18 | |
---|
19 | global CHE |
---|
20 | global CHS |
---|
21 | global CVE |
---|
22 | global CVS |
---|
23 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
24 | % PARAMETERS |
---|
25 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
26 | getx % avoid NaN Values due to Timeout BPMs reading |
---|
27 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
28 | % READ THE CORRECTORS CURRENT IN THE PREVIOUS FF TABLE |
---|
29 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
30 | UndNameAndPath=['/usr/Local/configFiles/InsertionFFTables/' CellName '-' UndType '/' TableName] |
---|
31 | ID_param=importdata(UndNameAndPath); |
---|
32 | param_length=length(ID_param); |
---|
33 | t0=10; % time between points |
---|
34 | |
---|
35 | % ID_param(i,j): |
---|
36 | % ID_param(1,j): line corresponding to the gap for any value of j |
---|
37 | % ID_param(2,j): line corresponding to CHE for any value of j |
---|
38 | % ID_param(3,j): line corresponding to CVE for any value of j |
---|
39 | % ID_param(4,j): line corresponding to CHS for any value of j |
---|
40 | % ID_param(5,j): line corresponding to CVS for any value of j |
---|
41 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
42 | % ATTRIBUTE OF THE INSERTION DEVICE |
---|
43 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
44 | idDevServGap=[CellName '/ei/' SSType '-' UndType SufUndName '/gap'] |
---|
45 | idDevServCHE=[CellName '/ei/' SSType '-' UndType SufUndName '_CHAN1']; |
---|
46 | idDevServCVE=[CellName '/ei/' SSType '-' UndType SufUndName '_CHAN2']; |
---|
47 | idDevServCHS=[CellName '/ei/' SSType '-' UndType SufUndName '_CHAN3']; |
---|
48 | idDevServCVS=[CellName '/ei/' SSType '-' UndType SufUndName '_CHAN4']; |
---|
49 | |
---|
50 | str1 = strrep(TableName, 'FF', UndType); |
---|
51 | UndName=strrep(str1, '.txt', '') |
---|
52 | GrpGMIUndFolder =['/home/operateur/GrpGMI/' UndName] |
---|
53 | GrpGMIUndFolderAndSessionName=[GrpGMIUndFolder '/' SESSION] |
---|
54 | PathAndBckgFileName=[GrpGMIUndFolder '/' SESSION '/Bckg'] |
---|
55 | Date=datestr(clock,'mmm-dd-yyyy HH:MM:SS') |
---|
56 | %Position_SourceX=[CellName '/DG/CALC-SD' SSType '-POSITION-ANGLE/positionX']; |
---|
57 | %Position_SourceZ=[CellName '/DG/CALC-SD' SSType '-POSITION-ANGLE/positionZ']; |
---|
58 | Orbit=idMeasElecBeamUnd(UndName, 0,PathAndBckgFileName, 0, 0); |
---|
59 | fprintf('%s\t %s\t %s\t %s\t %s\n','ENTREFER','CHE [A]', 'CHS [A]', 'CVE [A]', 'CVS [A]'); |
---|
60 | |
---|
61 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
62 | % FEEDFORWARD TABLE CONSTRUCTION |
---|
63 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
64 | for j=param_length:-1:1 |
---|
65 | |
---|
66 | UndFileName=[GrpGMIUndFolderAndSessionName '_' Num2Str(1000*ID_param(1,j))]; |
---|
67 | writeattribute(idDevServGap,ID_param(1,j)); |
---|
68 | pause(t0) |
---|
69 | idSetCurrentSync(idDevServCHE, ID_param(2,j), 0.01); |
---|
70 | idSetCurrentSync(idDevServCVE, ID_param(3,j), 0.01); |
---|
71 | idSetCurrentSync(idDevServCHS, ID_param(4,j), 0.01); |
---|
72 | idSetCurrentSync(idDevServCVS, ID_param(5,j), 0.01); |
---|
73 | pause(t0) |
---|
74 | Orbit=idMeasElecBeamUnd(UndName, 0,UndFileName, 0, 0); |
---|
75 | Result=InVac_CalculateCorrCur(UndName,UndFileName, PathAndBckgFileName); |
---|
76 | NewCHE(j)=ID_param(2,j)+CHE; |
---|
77 | NewCVE(j)=ID_param(3,j)+CVE; |
---|
78 | NewCHS(j)=ID_param(4,j)+CHS; |
---|
79 | NewCVS(j)=ID_param(5,j)+CVS; |
---|
80 | |
---|
81 | fprintf('%8.4f\t %8.4f\t %8.4f\t %8.4f\t %8.4f\n',ID_param(1,j),NewCHE(j), NewCHS(j), NewCVE(j), NewCVS(j)); |
---|
82 | idSetCurrentSync(idDevServCHE, NewCHE(j), 0.01); |
---|
83 | idSetCurrentSync(idDevServCHS, NewCHS(j), 0.01); |
---|
84 | idSetCurrentSync(idDevServCVE, NewCVE(j), 0.01); |
---|
85 | idSetCurrentSync(idDevServCVS, NewCVS(j), 0.01); |
---|
86 | pause(t0) |
---|
87 | end |
---|
88 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
89 | % SAVE THE NEW FEEDFORWARD TABLE |
---|
90 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
91 | Date=datestr(clock,'mmm-dd-yyyy HH:MM:SS') |
---|
92 | fidNew= fopen([GrpGMIUndFolder '/' SESSION '/' UndName '_' Date '.txt'], 'w'); |
---|
93 | for j=1:param_length |
---|
94 | fprintf(fidNew,'%8.4f\t',ID_param(1,j)); |
---|
95 | end |
---|
96 | fprintf(fidNew,'\n'); |
---|
97 | |
---|
98 | |
---|
99 | % The order of storage of corrector values must be CHE, CHS, CVE, CVS. But in the Device Server CVE and CHS are reversed |
---|
100 | for j=1:param_length |
---|
101 | fprintf(fidNew,'%8.4f\t',NewCHE(j)); |
---|
102 | end |
---|
103 | fprintf(fidNew,'\n'); |
---|
104 | |
---|
105 | for j=1:param_length |
---|
106 | fprintf(fidNew,'%8.4f\t',NewCVE(j)); |
---|
107 | end |
---|
108 | fprintf(fidNew,'\n'); |
---|
109 | |
---|
110 | for j=1:param_length |
---|
111 | fprintf(fidNew,'%8.4f\t',NewCHS(j)); |
---|
112 | end |
---|
113 | fprintf(fidNew,'\n'); |
---|
114 | |
---|
115 | for j=1:param_length |
---|
116 | fprintf(fidNew,'%8.4f\t',NewCVS(j)); |
---|
117 | end |
---|
118 | fprintf(fidNew,'\n'); |
---|
119 | |
---|
120 | copyfile([GrpGMIUndFolder '/' SESSION '/' UndName '_' Date '.txt'] ,['/usr/Local/configFiles/InsertionFFTables/' CellName '-' UndType '/FF.txt']) |
---|
121 | copyfile([GrpGMIUndFolder '/' SESSION '/' UndName '_' Date '.txt'] ,['/usr/Local/configFiles/InsertionFFTables/' CellName '-' UndType '/FF_' Date '.txt']) |
---|
122 | |
---|
123 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
124 | % GAP OPENING |
---|
125 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
126 | for j=1:param_length |
---|
127 | writeattribute(idDevServGap,ID_param(1,j)); |
---|
128 | pause(t0) |
---|
129 | idSetCurrentSync(idDevServCHE, NewCHE(j), 0.01); |
---|
130 | idSetCurrentSync(idDevServCHS, NewCHS(j), 0.01); |
---|
131 | idSetCurrentSync(idDevServCVE, NewCVE(j), 0.01); |
---|
132 | idSetCurrentSync(idDevServCVS, NewCVS(j), 0.01); |
---|
133 | end |
---|
134 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
135 | |
---|
136 | fclose(fidNew); |
---|
137 | end |
---|