Skip to content
Snippets Groups Projects
Commit 98756d05 authored by Nicola Vigano's avatar Nicola Vigano
Browse files

gtOarGetStats: fixed bug with matlab 2016a

parent afe2a0e8
No related branches found
No related tags found
No related merge requests found
function statsTable = gtOarGetStats(IDs, vars) function stats_table = gtOarGetStats(IDs, vars)
% GTOARGETSTATS Gets Oar stats for the given job IDs % GTOARGETSTATS Gets Oar stats for the given job IDs
% ------------------------------------------------------------------------- % -------------------------------------------------------------------------
% statsTable = gtOarGetStats(IDs, vars) % statsTable = gtOarGetStats(IDs, vars)
...@@ -65,12 +65,11 @@ function statsTable = gtOarGetStats(IDs, vars) ...@@ -65,12 +65,11 @@ function statsTable = gtOarGetStats(IDs, vars)
vars = newVars; vars = newVars;
end end
num_vars = numel(vars);
if (isempty(IDs)) if (isempty(IDs))
statsTable(1, :) = vars(:); stats_table(1, :) = vars(:);
statsTable(2, :) = cellfun(@(x){[]}, vars(:)); stats_table(2, :) = cellfun(@(x){[]}, vars(:));
statsTable = struct(statsTable{:}); stats_table = struct(stats_table{:});
return; return;
end end
...@@ -79,41 +78,52 @@ function statsTable = gtOarGetStats(IDs, vars) ...@@ -79,41 +78,52 @@ function statsTable = gtOarGetStats(IDs, vars)
% Getting the output % Getting the output
[~, output] = system(jobsStr); [~, output] = system(jobsStr);
[stats_table, incomplete_logs] = parse_oar_output(vars, output);
if (incomplete_logs)
fprintf('\nIncomplete logs for jobs: %s\n\n', sprintf(' %d', IDs));
end
end
function [stats_table, incomplete_logs] = parse_oar_output(vars, output)
num_vars = numel(vars);
% Now we chop the input: % Now we chop the input:
jobsBlocks = regexp(output(1:end-1), '\n\n', 'split'); jobsBlocks = regexp(output(1:end-1), '\n\n', 'split');
statsTable = cell(2, num_vars+1); stats_table = cell(2, num_vars+1);
incomplete_logs = false; incomplete_logs = false;
% Now extract info from the output of 'oarstat' % Now extract info from the output of 'oarstat'
if (~isempty(statsTable)) if (~isempty(stats_table))
stat_id = regexp(jobsBlocks, 'Job_Id: (?<Job_Id>.*?)\n', 'names', 'once'); stat_id = regexp(jobsBlocks, 'Job_Id: (?<Job_Id>.*?)\n', 'names', 'once');
stat_id = [stat_id{:}]; stat_id = [stat_id{:}];
statsTable{1, 1} = 'Job_Id'; stats_table{1, 1} = 'Job_Id';
statsTable{2, 1} = arrayfun(@(x){str2double(x.('Job_Id'))}, stat_id); stats_table{2, 1} = arrayfun(@(x){str2double(x.('Job_Id'))}, stat_id);
for ii_v = 1:num_vars for ii_v = 1:num_vars
stat = regexp(jobsBlocks, [vars{ii_v} ' = (?<' vars{ii_v} '>.*?)\n'], 'names', 'once'); stat = regexp(jobsBlocks, [vars{ii_v} ' = (?<' vars{ii_v} '>.*?)\n'], 'names', 'once');
for ii_c = numel(stat):-1:1 for ii_c = numel(stat):-1:1
stat_struct(ii_c).(vars{ii_v}) = stat{ii_c}.(vars{ii_v}); if (~isempty(stat{ii_c}))
stat_struct(ii_c).(vars{ii_v}) = stat{ii_c}.(vars{ii_v});
else
stat_struct(ii_c).(vars{ii_v}) = '';
end
end end
stat = stat_struct; stat = stat_struct;
statsTable{1, ii_v+1} = vars{ii_v}; stats_table{1, ii_v+1} = vars{ii_v};
statsTable{2, ii_v+1} = {stat.(vars{ii_v})}; stats_table{2, ii_v+1} = {stat.(vars{ii_v})};
if (isempty(statsTable{2, ii_v+1})) if (isempty(stats_table{2, ii_v+1}))
warning('gtOarGetStats:no_such_stat', ... warning('gtOarGetStats:no_such_stat', ...
[ 'The stat "%s" is not reported in the output from ' ... [ 'The stat "%s" is not reported in the output from ' ...
'oarstat. This might create further errors.\n'], ... 'oarstat. This might create further errors.\n'], ...
vars{ii_v}); vars{ii_v});
incomplete_logs = true; incomplete_logs = true;
statsTable{2, ii_v+1} = cell(1, numel(stat_id)); stats_table{2, ii_v+1} = cell(1, numel(stat_id));
end end
end end
statsTable = struct(statsTable{:}); stats_table = struct(stats_table{:});
end end
end
if (incomplete_logs)
fprintf('\nIncomplete logs for jobs: %s\n\n', sprintf(' %d', IDs));
end
end % end of function
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment