clear;clc;
% startup
if (exist('initDone')==0),
	% startup TOMLAB
	%addpath c:\tomlab;
	%startup;

	% add bin folder to Matlab path and initialize RTC Tools
	%addpath('../../x86-windows-vc-9.0/bin/');
	addpath('C:\Users\Rodolfo\Documents\Deltares\RTCTools\x86-windows-vc-9.0\bin\release');
	initDone = 1;
end

% initial parameter definition
id = {
'C0102';
'C0203';
}; 
input = [
50.000000;
50.000000;
];
saveParameters(id, input);

% initialize RTC Tools
RTCToolsMatlab('initialize');
RTCToolsMatlab('DA mode');

% problem definition
%Prob = conAssign('jResCalibration', [], [], [], 20*ones(1,1), 80*ones(1,1), 'Name', input, [], [], [], [], []);
%Prob.SOL.optPar(10) = 0.001;

% optimization
tic
%Result = tomRun('snopt', Prob, 2);
Cmax=80;    Cmin=20;    No=numel(input);
A=[eye(No);-eye(No)];      %matrix of inequalities
B=zeros(2*No,1);         %resultant of inequalities
for i=1:(No)
    B(i)=Cmax;           %inequalities constraints
    B(2*i)=Cmin;
end

Result = fmincon(@jResCalibration,input,A,B);
time=toc;
% Aeq=[]; beq=[]; lb=[];  ub=[];
% options=optimset('GradObj','on','GradConstr','on');
% Result=fmincon(@jResCalibration,input,A,B,Aeq,beq,lb,ub,@NoCon,options); %Optimization function

% save optimized parameters
%saveParameters(id, Result.x_k);
saveParameters(id, Result);

% close RTC Tools
RTCToolsMatlab('close');