%% Read .sol file
% Uses manual referencing within the XML as its faster than a full recursive evaluation
% If nargout == 1, only reads header (inc objective value), which is much faster for big datasets
%%
function [vars, cons] = read_sol_fast(filename)
%sol_xml = parseXML(filename); % this reads the full xml file but takes a long time. use for debugging.
fileID = fopen(filename); % instead get the DOM directly
esc=0;
while esc == 0
    junk = textscan(fileID,'%s %*[^\n]',1);
    if strcmp(strtrim(junk{1}),'<linearConstraints>')
        esc=1;
    end
end
% TODO automate which parameters are listed
%cons = textscan(fileID,'<constraint name=%s index=%s status=%s slack=%s dual=%s %*[^\n]');
cons = textscan(fileID,'<constraint name=%s index=%q slack=%q %*[^\n]');
junk = textscan(fileID,'%s %*[^\n]',2);
%vars = textscan(fileID,'<variable name=%s index=%s status=%s value=%s reducedCost=%s %*[^\n]');
vars = textscan(fileID,'<variable name=%s index=%q value=%q %*[^\n]');
fclose(fileID);

