          

%  Basquin_mean_correction.m  ver 1.0  by Tom Irvine

function[iflag,damage]=Basquin_mean_correction(mc,mean_stress,aux_stress,m,n,mx,A,ratio,CC,s)

                iflag=0;

                D=0;
                ssa=0;
                ssr=0;
                
                for i=1:m
                %
                   Se=s(i);
                   
                   if(mc>1)
                      ratio(i)=abs(mean_stress(i))/aux_stress;
                   end
                %
                %%%%%%%%%%%%%%%%%%%%%%%%%
                %
                   C=1;
                %
                   if(mc==2) % Gerber Ultimate Stress 
                        C=1-(ratio(i)^2);
                   end
                   if(mc==3) % Goodman Ultimate Stress 
                        C=1- ratio(i);  
                   end
                   if(mc==4) % Morrow True Fracture
                        C=1- ratio(i);     
                   end
                   if(mc==5) % Soderberg Yield Stress
                        C=1-ratio(i);   
                   end
                   
                   if(abs(C)>1)
                       iflag=1;
                       C=1;
                   end
                   
                %
                   Se=Se/C;
                %
                %%%%%%%%%%%%%%%%%%%%%%%%%
                %
                
                    CC(i)=C;
                  
                    D=D+n(i)*Se^mx;
                    
                    ssa=ssa+Se^mx;      
                    ssr=ssr+(2*Se)^mx;    
                    
                %    
                end

                damage=D/A;