function stop = optimplot_tracefit(x,optimValues,state)

global ntimes Product_vector Time_vector Time_mat
global s1_cons s2_cons 
global trace lasttrace

stop = false;
switch state
    case 'init'
    case 'iter'        
            % The 'iter' case is  called during the zeroth iteration.

             Product_sim_vector = bi_uni_fit(x,Time_vector);
             product_mat = reshape(Product_vector,ntimes,s1_cons,s2_cons);              
             calc_product_mat = reshape(Product_sim_vector,ntimes,s1_cons,s2_cons); 
             
             plot(Time_mat(:,1),product_mat(:,:,trace),'+')
             colors = get(gca,'ColorOrder');
             colors = [colors ; colors(1:3,:)];
             xlabel('Time (s)  ')
             ylabel('[Product]  ')
             hold on
                       
             for ntrace = 1:lasttrace
             plot(Time_mat(:,1),calc_product_mat(:,ntrace,trace),'-','Color', colors(ntrace,:));
             end
             hold off
             
    case 'done'
    otherwise
end
end

