function J= p15_plant_cost(t1)
% 12.5.2014, 6.5.2016 (v2), J. Gaspar

if nargin<1
    t1= 13;
end
global p15_plant_tf
tf= 15;
if ~isempty(p15_plant_tf)
    tf= p15_plant_tf;
end

assignin('base', 'p15_plant_t1', t1);
[t,x,y]= sim('p15_plant', [0 p15_plant_tf]);
J= -y(end,1);


% -------------- debug / display:
global p15_plant_animation
if nargout<1 || (~isempty(p15_plant_animation) && p15_plant_animation)
    plot(t, y(:,[2 1]), '.-')
    title(sprintf('Input commutation at t=%.2f [yr]', t1));
    legend('input', 'merit J', 'Location', 'NorthWest')
    xlabel('time [years]');
    grid on
    if p15_plant_animation==2, drawnow; end
end
