crash randomly in a loop
Bug Description
crash randomly in a loop (for span =4.2)
Steps to reproduce
//see below: call matriceR_MB_LB("Reel",[4:0.1:5],"ResultMainBeam")
function [ResultBeam] = matriceR_MB_LB(category,listportee,typ)
ResultBeam=[];
msg_mat=typ+category +" Calculation of "+ string(length(listportee)) +" spans from "+ string(listportee(1))+" to "+string(listportee(length(listportee)))+" m"
winId2=waitbar(msg_mat);
ndigits=2;
s=0;
L_dyn=listportee;
ResultBeam(1,:) = listportee;
ResultBeam(2,:) =round2(dynfactor(L_dyn,0,"eleve"),ndigits+1);
if category == "Reel" then
//[MatConvoi,MatWagon] = createMatConvoi_portee(100)
MatConvoi=[1.52 3.32 9.52 11.32 13.64 14.74 15.94 17.04 23.64 24.74 25.94 27.04 29.46 31.26 46.12 47.92; 165. 165. 165. 165. 160. 160. 160. 160. 160. 160. 160. 160. 120. 120. 120. 120.; 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
MatWagon=[]
if isempty(MatWagon) then train="NO";M4=[] else train="YES" end
end;
pascalcul=0.1;
pasavancement=0.01;
listcategoty_tot=cat(2,"A","B")
test1=or(category ==listcategoty_tot)
for portee=listportee
msg_mat2="span "+ string(s+1) +" = "+string(portee)+" m";
waitbar(s/(length(listportee)),[msg_mat,msg_mat2],winId2);
timing_init=toc();
s = s+1
if typ=="ResultMainBeam" then
portee_tot=portee
else
portee_tot=listportee_tot(s)
end
if test1 then
MatConvoi = LoadModel(portee_tot, category);
elseif category == "Reel" then
if train=="YES" then [MatConvoi,MatWagon] = createMatConvoi_portee(portee) end
else //elseif category ~= "Reel" then
messagebox("NO correct category "+category+" of train to calculate","warning","warning");
abort
end
[MatConvoi,long_convoi] = DecalMat(MatConvoi);
MatConvoi2 = MatConvoi;
if typ=="ResultLongBeam" then MatConvoi2(2,:)=MatConvoi2(2,:)*0.5; end
MatResultM=[];
MatResultT=[];
MatResultR=[];
res = 1;
if train=="YES" then
[MatWagon,long_convoi4] = DecalMat(MatWagon)
M4=flipdim(MatWagon, 2);
M4(1,:)=abs(M4(1,:));
[M4,long_convoi4] = DecalMat(M4)
end
M3=flipdim(MatConvoi2, 2);
M3(1,:)=abs(M3(1,:));
[M3,long_convoi3] = DecalMat(M3)
if ~isempty(MatWagon) && MatWagon == M4 then
if round3((long_convoi4-portee_tot)/2,ndigits)>=0 then
avancementtot = round3(long_convoi-long_convoi4,ndigits)+round3(portee_tot,ndigits)+round3((long_convoi4-portee_tot)/2,ndigits)+pasavancement;
if typ=="ResultLongBeam" then avancementtot=avancementtot+round3(portee/2,ndigits) end
else
avancementtot = round3(long_convoi-long_convoi4,ndigits)+round3(portee_tot,ndigits)+round3((long_convoi4)/2,ndigits)+pasavancement;
end
elseif MatConvoi2 == M3 then
avancementtot = round3(long_convoi/2,ndigits)+round3(portee_tot/2,ndigits)+pasavancement;
else
avancementtot = long_convoi+portee_tot
end
tt=0
for t=tt:pasavancement:avancementtot
if typ=="ResultMainBeam" then
result_temp = M_T_Stat_quick3(MatConvoi2, portee, pascalcul);
result_temp_REAC=[];
else
[result_temp,result_temp_REAC] = M_T_HYPER(MatConvoi2,[portee,portee,portee],pascalcul);
end
sizetemp=size(result_temp, "c");
sizeresult=size(MatResultM, "c");
matmax=max(sizetemp,sizeresult);
if sizetemp > sizeresult then
MatResultM=resize_matrix(MatResultM, -1, matmax);
MatResultT=resize_matrix(MatResultT, -1, matmax);
elseif sizetemp < sizeresult then
result_temp=resize_matrix(result_temp, -1, matmax);
end
MatResultM(res,:)=result_temp(2,:);
MatResultT(res,:)=result_temp(3,:);
MatResultR(res,:)=result_temp_REAC(1,:);
res = res+1;
MatConvoi2(1,:)=MatConvoi2(1,:)+pasavancement;
end
ResultBeam(3,s) = round3(max(MatResultM),ndigits);
ResultBeam(4,s) = max(round3(abs(min(MatResultT)),ndigits),round3(max(MatResultT),ndigits));
if typ=="ResultLongBeam" then ResultBeam(5,s) = round3(max(MatResultR),ndigits); end
timing(s)=toc()-timing_init
end
ResultBeam = ResultBeam;
close(winId2);
endfunction
function [M] = M_T_Stat_quick3(MatxiFi, L, pascalcul)
Mat = gsort(MatxiFi, 'lc','i');
if or(Mat(1,:) <=0) || or(Mat(1,:)+Mat(3,:) >=L) then Mat=clean(SuppMat(round2(Mat,3), L)) end
if or(Mat(1,:) <=0) || or(Mat(1,:)+Mat(3,:) >=L) then Mat=clean(SuppMat(round2(Mat,3), L)) end
Mat=CleanMat_P_P(Mat)
n = size(Mat,"c");
R1 = 0; Rtot = 0;
i = 1;
while i <= n
if Mat(3,i)==0 then
R1 = R1 + (L -Mat(1,i))*Mat(2,i)/L;
Rtot = Rtot + Mat(2,i);
else
R1 = R1 + Mat(2,i)*Mat(3,i)*(Mat(3,i)+2*(L -Mat(1,i)-Mat(3,i)))/(2*L);
Rtot = Rtot + Mat(2,i)*Mat(3,i);
end
i = i+1;
end
R2 = Rtot-R1;
Mat_M_T_temp = [0;0;R1];
Mat_M_T_tempP=[]
j = 2;
jj=2
x_tempMat=[0]
q_tempMat=[]
for z=1:n
for ii=1:2
x_tempMat(jj)=Mat(1,z)+(ii-1)*Mat(3,z)
jj=jj+1
end
end
x_tempMat = unique(x_tempMat)
x_tempold=0
for x_temp=x_tempMat'
if x_temp>0 then
Mx_temp = 0; Tx_temp = 0;q_tempMattemp=0;
k=1
while k <= n & Mat(1,k) <= x_temp
if Mat(3,k)==0 then
Mx_temp = Mx_temp + (x_temp-Mat(1,k))*Mat(2,k);
Tx_temp = Tx_temp + Mat(2,k);
if Mat(1,k) == x_temp then
Mat_M_T_tempP(1,j) = x_temp-0.001;
Mat_M_T_tempP(2,j) = R1*x_temp - Mx_temp;
Mat_M_T_tempP(3,j) = R1 - Tx_temp+Mat(2,k);
end
else
x1=Mat(1,k)//x1=max(Mat(1,k),0)
x2=min(Mat(1,k)+Mat(3,k),x_temp)
P=(x2-x1)*Mat(2,k)
posP=x1+(x2-x1)/2
Mx_temp = Mx_temp + (x_temp-posP)*P;
Tx_temp = Tx_temp + P;
if Mat(1,k)+Mat(3,k)>x_tempold & Mat(1,k) < x_temp then
q_tempMattemp=q_tempMattemp+Mat(2,k)
end
end
k = k+1;
end
Mat_M_T_temp(1,j) = x_temp;
Mat_M_T_temp(2,j) = R1*x_temp - Mx_temp;
Mat_M_T_temp(3,j) = R1 - Tx_temp;
q_tempMat(j-1)=q_tempMattemp
j = j+1;
end
x_tempold=x_temp
end
Mat_M_T_temp(:,j)=[L;0;-R2]
Mat_M_T_temp2 = unique(cat(2,Mat_M_T_tempP,Mat_M_T_temp),"c")
if Mat_M_T_temp2(:,1) == 0 then Mat_M_T_temp2(:,1)=[] end
graph=0
if graph==1 || max(q_tempMat)~=0 then //on ne rentre pas dans ce if => le bug n'est pas là
Mat_M_T=[]
m=1
Mat_M_T_tempP=resize_matrix(Mat_M_T_tempP, 3, size(Mat_M_T_temp,"c"))
for q_temp=q_tempMat'
if q_temp ~= 0 then
position=round3(x_tempMat(m),2):pascalcul:round3(x_tempMat(m+1),2)
if round3(position(size(position,"c")),2) == round3(x_tempMat(m+1),2) then
position=resize_matrix(position,-1,size(position,"c")-1)
end
vectx=position-x_tempMat(m)
R1temp=q_temp*(x_tempMat(m+1)-x_tempMat(m))/2
Mx_temp = R1temp*vectx - q_temp*prod([vectx;vectx],1)/2
Tx_temp = R1temp - q_temp*vectx
Mat_M_T_lin=Mat_M_T_temp(2,m)+(Mat_M_T_temp(2,m+1)-Mat_M_T_temp(2,m))/(Mat_M_T_temp(1,m+1)-Mat_M_T_temp(1,m))*vectx
if Mat_M_T_tempP(3,m+1) ~= 0 then
T_temp=Mat_M_T_tempP(3,m+1)
else
T_temp=Mat_M_T_temp(3,m+1)
end
Mat_M_T_lin_T=Mat_M_T_temp(3,m)+(T_temp-Mat_M_T_temp(3,m))/(Mat_M_T_temp(1,m+1)-Mat_M_T_temp(1,m))*vectx
Mat_M_T_linTemp=position
Mat_M_T_linTemp(2,:)= Mat_M_T_lin + Mx_temp
Mat_M_T_linTemp(3,:)= Mat_M_T_lin_T
Mat_M_T=cat(2,Mat_M_T,Mat_M_T_linTemp)
end
m=m+1
end
Mat_M_T = unique(cat(2,Mat_M_T,Mat_M_T_temp2),"c")
else
Mat_M_T = Mat_M_T_temp2
end
Mat_M_T = unique(cat(2,[0;0;R1],Mat_M_T),"c")
M = round2(Mat_M_T(:,:),3);
endfunction
function [number_out] = round2(number_in,ndigits)
n = round((number_in)*10^(ndigits))
number_out = strtod(string(n*10^(-ndigits)));
endfunction
function [number_out] = round3(number_in,ndigits)
n = string(round((number_in)*10^(ndigits)))
if length(n)>ndigits then
n2=strsplit(n,[length(n)-ndigits])
number_out = strtod(strcat(n2,"."));
elseif length(n)==ndigits then
number_out = strtod(strcat([".",n]));
elseif length(n)<ndigits then
number_out = strtod(strcat([".",string(zeros(1,ndigits-length(n))),n]));
end
endfunction
function [phi] = dynfactor(Lphi,speedkmh,state)
if min(Lphi)<4||max(Lphi)>100 then
messagebox("the Lphi must between 4 and 100. the dynamic factor should be determined by a dynamic analysis in accordance with EN1991-2 §6.4.6")
abort
end
n0max = 94.76*Lphi.^(-0.748);
n1=zeros(1,length(Lphi))
n2=n1; n4=n1; n5=n1;
n1(Lphi>=4)=1
n2(Lphi<=20)=1
n3=n1.*n2
n3=n3.*80./Lphi
n4(Lphi>20)=1
n5(Lphi<=100)=1
n6=n4.*n5
n6=n6.*23.58.*Lphi.^(-0.592)
n0min=n3+n6
a = dynfactor2(Lphi,speedkmh,state,n0min);
b = dynfactor2(Lphi,speedkmh,state,n0max);
phi = max(a,b);
endfunction
function [phi] = dynfactor2(Lphi,speedkmh,state,n0)
if speedkmh > 200 then
messagebox("the speed is > 200km/h. the dynamic factor should be determined by a dynamic analysis in accordance with EN1991-2 §6.4.6")
abort
else
v = speedkmh/3.6; //[m/s]
if v<= 22 then
alpha = v/22;
else
alpha = 1;
end
K = v./(2*Lphi.*n0)
n1=zeros(1,length(Lphi))
n3=n1
n1(K < 0.76)=1
n2=n1.*K./(1-K+K.^4)
n3(K >= 0.76)=1.325
phi1=n2+n3
phi2 = alpha/100*(56*exp(-(Lphi/10).^2)+50*(Lphi.*n0/80-1).*exp(-(Lphi/20).^2))
phi2(phi2<0)=0
if state == "standard" then phi = 1 + phi1 + phi2; //for standard maintenance!!!!
elseif state == "eleve" then phi = 1 + phi1 + 0.5*phi2; //for eleve maintenance!!!!
else disp("error, the maintenance parameter has to be either ""standard"" for standard maintenance or ""eleve"" for carefully maintained track");
end
end
endfunction
function [MatOUT] = SuppMat(MatIN, L_in)
MatOUT = []
sizeMatIN = size(MatIN, "c");
k_out =1;
for k_in = 1:sizeMatIN
if MatIN(3,k_in)==0 then
if MatIN(1,k_in) > 0 & MatIN(1,k_in) < L_in then
MatOUT(:,k_out) = MatIN(:,k_in);
k_out = k_out +1;
end
else
if MatIN(1,k_in)+MatIN(3,k_in) > 0 & MatIN(1,k_in) < L_in then
MatOUT(:,k_out) = MatIN(:,k_in);
MatOUT(1,k_out) = max(MatIN(1,k_in),0)
MatOUT(3,k_out) = min(MatIN(1,k_in)+MatIN(3,k_in),L_in)-MatOUT(1,k_out)
k_out = k_out +1;
end
end
end
endfunction
function [MatOUT] = CleanMat(MatIN)
MatOUT = [];
sizeMatIN = size(MatIN, "c");
i_out =1;
for i_in = 1:sizeMatIN
if MatIN(2,i_in) ~= 0 then
MatOUT(:,i_out) = MatIN(:,i_in);
i_out = i_out +1;
end
end
endfunction
function [MatOUT,L_conv] = DecalMat(MatIN)
xi_max = max(max(MatIN(1,:),MatIN(1,:)+MatIN(3,:)))
xi_min = min(MatIN(1,:))
L_conv = xi_max - xi_min
MatOUT=MatIN
MatOUT(1,:) = MatIN(1,:) - xi_max
endfunction
function [MatOUT] = CleanMat2lin(MatIN)
MatOUT = [];
sizeMatIN = size(MatIN, "c");
i_out =1;
for i_in = 1:sizeMatIN
if MatIN(3,i_in) ~= 0 then
MatOUT(:,i_out) = MatIN(:,i_in);
i_out = i_out +1;
end
end
endfunction
function [MatOUT] = CleanMat_P_P(MatIN)
MatOUT = [];
MatIN = gsort(MatIN, 'lc','i')
sizeMatIN = size(MatIN, "c");
for i_in = 1:sizeMatIN-1
if MatIN(3,i_in) == 0 & MatIN(3,i_in+1) == 0 then
if MatIN(1,i_in) == MatIN(1,i_in+1) then
MatIN(2,i_in) = MatIN(2,i_in)+MatIN(2,i_in+1);
MatIN(2,i_in+1)=0;
i_in = i_in +1;
end
end
end
MatIN=CleanMat(MatIN)
MatOUT = MatIN;
endfunction
matriceR_MB_LB("Reel",[4:0.1:5],"ResultMainBeam")
What is the expected correct behavior?
no crash
Error log
I have no log
crash probably for 4.2
Edited by Vincent COUVERT