source: MML/trunk/machine/SOLEIL/StorageRing/insertions/Update_InVacID.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: 6.1 KB
Line 
1function 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%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26getx % avoid NaN Values due to Timeout BPMs reading
27%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28% READ THE CORRECTORS CURRENT IN THE PREVIOUS FF TABLE
29%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30UndNameAndPath=['/usr/Local/configFiles/InsertionFFTables/' CellName '-' UndType '/' TableName]
31ID_param=importdata(UndNameAndPath);
32param_length=length(ID_param);
33t0=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%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44idDevServGap=[CellName '/ei/' SSType '-' UndType SufUndName '/gap']
45idDevServCHE=[CellName '/ei/' SSType '-' UndType SufUndName '_CHAN1'];
46idDevServCVE=[CellName '/ei/' SSType '-' UndType SufUndName '_CHAN2'];
47idDevServCHS=[CellName '/ei/' SSType '-' UndType SufUndName '_CHAN3'];
48idDevServCVS=[CellName '/ei/' SSType '-' UndType SufUndName '_CHAN4'];
49
50str1 = strrep(TableName, 'FF', UndType);
51UndName=strrep(str1, '.txt', '')
52GrpGMIUndFolder =['/home/operateur/GrpGMI/' UndName]
53GrpGMIUndFolderAndSessionName=[GrpGMIUndFolder '/' SESSION]
54PathAndBckgFileName=[GrpGMIUndFolder '/' SESSION '/Bckg']
55Date=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'];
58Orbit=idMeasElecBeamUnd(UndName, 0,PathAndBckgFileName, 0, 0);
59fprintf('%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%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64for 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)
87end
88%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89% SAVE THE NEW FEEDFORWARD TABLE
90%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91Date=datestr(clock,'mmm-dd-yyyy HH:MM:SS')
92fidNew= fopen([GrpGMIUndFolder '/' SESSION '/' UndName '_' Date '.txt'], 'w');
93for j=1:param_length
94 fprintf(fidNew,'%8.4f\t',ID_param(1,j));   
95end   
96fprintf(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
100for j=1:param_length
101 fprintf(fidNew,'%8.4f\t',NewCHE(j));   
102end   
103fprintf(fidNew,'\n');
104
105for j=1:param_length
106 fprintf(fidNew,'%8.4f\t',NewCVE(j));   
107end   
108fprintf(fidNew,'\n');
109
110for j=1:param_length
111 fprintf(fidNew,'%8.4f\t',NewCHS(j));   
112end   
113fprintf(fidNew,'\n');
114
115for j=1:param_length
116 fprintf(fidNew,'%8.4f\t',NewCVS(j));   
117end   
118fprintf(fidNew,'\n');
119
120copyfile([GrpGMIUndFolder '/' SESSION '/' UndName '_' Date '.txt'] ,['/usr/Local/configFiles/InsertionFFTables/' CellName '-' UndType '/FF.txt'])
121copyfile([GrpGMIUndFolder '/' SESSION '/' UndName '_' Date '.txt'] ,['/usr/Local/configFiles/InsertionFFTables/' CellName '-' UndType '/FF_' Date '.txt'])
122
123%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124% GAP OPENING
125%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126for 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);
133end
134%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135
136fclose(fidNew);
137end
Note: See TracBrowser for help on using the repository browser.