1 | function [previous_LT_Lib,LT_lib_mean,LT_lib_by_quarter,N_lib_valid,N_lib_valid_first_sort,N_lib_valid_second_sort,LT_DCCT,index_seuil_1,index_seuil_2,Time_history,DCCT_history]=... |
---|
2 | get_LT(bpm_group,BPM_index,N_samples,previous_LT_Lib,LT_lib_mean,LT_lib_by_quarter,N_lib_valid,... |
---|
3 | N_lib_valid_first_sort,N_lib_valid_second_sort,LT_DCCT,seuil_1,seuil_2,NLib2valid,Time_history,DCCT_history) |
---|
4 | |
---|
5 | historic_size=size(LT_lib_mean,2); |
---|
6 | N_BPM=tango_group_size(bpm_group); |
---|
7 | |
---|
8 | tic |
---|
9 | h=now; |
---|
10 | fprintf('********* %s ***********\n',datestr(h)) |
---|
11 | attr_list={'current','lifeTime'}; |
---|
12 | result_DCCT=tango_read_attributes2('ANS/DG/DCCT-CTRL',attr_list); |
---|
13 | |
---|
14 | [LT_lib,is_valid,valid_samples]=duree_vie(bpm_group,N_samples); |
---|
15 | valid_Nb=size(find(is_valid),2); |
---|
16 | fprintf('%d Libera have long enough buffer, averaged size is %1.0f\n',valid_Nb,mean(valid_samples)) |
---|
17 | N_lib_valid=circshift(N_lib_valid',-1)'; |
---|
18 | N_lib_valid(historic_size)=valid_Nb; |
---|
19 | |
---|
20 | |
---|
21 | %first sort |
---|
22 | for j=1:N_BPM |
---|
23 | if is_valid(j) |
---|
24 | LT_Lib_valid(j)=LT_lib(j); |
---|
25 | else |
---|
26 | LT_Lib_valid(j)=previous_LT_Lib(j); |
---|
27 | %LT_Lib_valid(j)=0; |
---|
28 | end |
---|
29 | end |
---|
30 | previous_LT_Lib=LT_Lib_valid; |
---|
31 | ma1=mean(LT_Lib_valid); |
---|
32 | seuil_1_high=(1+seuil_1)*ma1; |
---|
33 | seuil_1_low=(1-seuil_1)*ma1; |
---|
34 | fover=find(LT_Lib_valid>seuil_1_high); |
---|
35 | funder=find(LT_Lib_valid<seuil_1_low); |
---|
36 | f=[fover,funder];fs=sort(f); |
---|
37 | for j=1:length(fs) |
---|
38 | rido=fs(j); |
---|
39 | LT_Lib_valid(rido-j+1)=[]; |
---|
40 | end; |
---|
41 | fprintf('%d Libera remaining after first sort\n',size(LT_Lib_valid,2)) |
---|
42 | N_lib_valid_first_sort=circshift(N_lib_valid_first_sort',-1)'; |
---|
43 | N_lib_valid_first_sort(historic_size)=size(LT_Lib_valid,2); |
---|
44 | |
---|
45 | %second sort |
---|
46 | ma2=mean(LT_Lib_valid); |
---|
47 | seuil_2_high=(1+seuil_2)*ma2; |
---|
48 | seuil_2_low=(1-seuil_2)*ma2; |
---|
49 | fover=find(LT_Lib_valid>seuil_2_high); |
---|
50 | funder=find(LT_Lib_valid<seuil_2_low); |
---|
51 | f=[fover,funder];fs=sort(f); |
---|
52 | for j=1:length(fs) |
---|
53 | rido=fs(j); |
---|
54 | LT_Lib_valid(rido-j+1)=[]; |
---|
55 | end; |
---|
56 | fprintf('%d Libera remaining after second sort\n',size(LT_Lib_valid,2)) |
---|
57 | fprintf('LT with Libera= %d \n',mean(LT_Lib_valid)) |
---|
58 | N_lib_valid_second_sort=circshift(N_lib_valid_second_sort',-1)'; |
---|
59 | N_lib_valid_second_sort(historic_size)=size(LT_Lib_valid,2); |
---|
60 | LT_lib_mean=circshift(LT_lib_mean',-1)'; |
---|
61 | for i=1:4 |
---|
62 | LT_lib_by_quarter(i,:)=circshift(LT_lib_by_quarter(i,:)',-1)'; |
---|
63 | end |
---|
64 | |
---|
65 | if size(LT_Lib_valid,2)<NLib2valid |
---|
66 | LT_lib_mean(historic_size)=LT_lib_mean(historic_size-1); |
---|
67 | LT_lib_by_quarter(:,historic_size)=LT_lib_by_quarter(:,historic_size-1); |
---|
68 | else |
---|
69 | LT_lib_mean(historic_size)=mean(LT_Lib_valid); |
---|
70 | quarter_size=floor(N_lib_valid_second_sort(historic_size)/4); |
---|
71 | for i=1:4 |
---|
72 | LT_lib_by_quarter(i,historic_size)=mean(LT_Lib_valid(quarter_size*(i-1)+1:quarter_size*(i))); |
---|
73 | end |
---|
74 | end |
---|
75 | |
---|
76 | LT_DCCT=circshift(LT_DCCT',-1)'; |
---|
77 | LT_DCCT(historic_size)=result_DCCT(2).value; |
---|
78 | |
---|
79 | DCCT_history=circshift(DCCT_history',-1)'; |
---|
80 | DCCT_history(historic_size)=result_DCCT(1).value; |
---|
81 | |
---|
82 | Time_history=circshift(Time_history',-1)'; |
---|
83 | Time_history(historic_size)=h; |
---|
84 | |
---|
85 | |
---|
86 | index_over=find(previous_LT_Lib>seuil_2_high); |
---|
87 | index_under=find(previous_LT_Lib<seuil_2_low); |
---|
88 | index_seuil_2=[index_over index_under]; |
---|
89 | index_over=find(previous_LT_Lib>seuil_1_high); |
---|
90 | index_under=find(previous_LT_Lib<seuil_1_low); |
---|
91 | index_seuil_1=[index_over index_under]; |
---|
92 | |
---|
93 | |
---|
94 | |
---|
95 | %figure(2) |
---|
96 | |
---|
97 | % subplot(3,1,1) |
---|
98 | % plot(LT_lib,'bo','LineWidth',2) |
---|
99 | % xlabel('BPM Number') |
---|
100 | % ylabel('Hours') |
---|
101 | % title('Last LT measurment for each Libera') |
---|
102 | % hold on |
---|
103 | % ma1(1:N_BPM)=ma1; |
---|
104 | % plot(BPM_index,ma1,'r') |
---|
105 | % index_over=find(LT_lib>seuil_2_high); |
---|
106 | % index_under=find(LT_lib<seuil_2_low); |
---|
107 | % index_seuil2=[index_over index_under]; |
---|
108 | % plot(index_seuil2,LT_lib(index_seuil2),'gx','LineWidth',3,'MarkerSize',20) |
---|
109 | % ma2(1:N_BPM)=ma2; |
---|
110 | % plot(BPM_index,ma2,'g') |
---|
111 | % index_over=find(LT_lib>seuil_1_high); |
---|
112 | % index_under=find(LT_lib<seuil_1_low); |
---|
113 | % index_seuil_1=[index_over index_under]; |
---|
114 | % plot(index_seuil_1,LT_lib(index_seuil_1),'rx','LineWidth',3,'MarkerSize',20) |
---|
115 | % plot(BPM_index,LT_lib_mean(historic_size),'b'); |
---|
116 | % hold off |
---|
117 | % [Y,I]=sort(LT_lib(index_seuil_1)); |
---|
118 | % for k=1:1:size(index_seuil_1,2) |
---|
119 | % %fprintf('%s: %3.1f hours\n',dev_list{index(I(k))},Y(k)); |
---|
120 | % end |
---|
121 | % subplot(3,1,2) |
---|
122 | % plot(N_lib_valid,'b') |
---|
123 | % hold on |
---|
124 | % plot(N_lib_valid_first_sort,'r') |
---|
125 | % plot(N_lib_valid_second_sort,'g') |
---|
126 | % hold off |
---|
127 | % legend('valid buffer length','first sort','second sort') |
---|
128 | % title('History of valid Libera measurments number') |
---|
129 | % subplot(3,1,3) |
---|
130 | % plot(LT_lib_mean) |
---|
131 | % hold on |
---|
132 | % % plot(LT_Lib_by_quarter(:,1),'c--') |
---|
133 | % % plot(LT_Lib_by_quarter(:,2),'m--') |
---|
134 | % % plot(LT_Lib_by_quarter(:,3),'y--') |
---|
135 | % % plot(LT_Lib_by_quarter(:,4),'k--') |
---|
136 | % |
---|
137 | % % plot(LT_DCCT_instant,'r') |
---|
138 | % plot(LT_DCCT,'c') |
---|
139 | % hold off |
---|
140 | % grid on |
---|
141 | % %legend('Libera all','Libera quart 1','Libera quart 2','Libera quart 3','Libera quart 4','DCCT') |
---|
142 | % legend('Libera all','DCCT') |
---|
143 | % ylabel('Hours') |
---|
144 | % title('Lifetime History') |
---|
145 | % t=toc; |
---|
146 | % fprintf('processing time = %2.1f s\n',t) |
---|
147 | |
---|
148 | |
---|