add result button making plot
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
function run_case_plot(config, results, action_id)
|
||||
%RUN_CASE_PLOT Run a legacy plot script for the current case/results.
|
||||
|
||||
arguments
|
||||
config (1,1) struct
|
||||
results (1,1) struct
|
||||
action_id
|
||||
end
|
||||
|
||||
if isempty(fieldnames(results))
|
||||
error('run_case_plot:NoResults', 'No results are available for plotting.');
|
||||
end
|
||||
|
||||
project_root = fileparts(fileparts(fileparts(mfilename('fullpath'))));
|
||||
source_case_folder = resolve_source_case_folder(project_root, config.meta);
|
||||
if isempty(source_case_folder) || ~isfolder(source_case_folder)
|
||||
error('run_case_plot:MissingCaseFolder', ...
|
||||
'Cannot resolve source case folder for case %s.', string(config.meta.case_id));
|
||||
end
|
||||
|
||||
old_dir = pwd;
|
||||
cleanup_obj = onCleanup(@() cd(old_dir)); %#ok<NASGU>
|
||||
addpath(genpath(project_root));
|
||||
cd(source_case_folder);
|
||||
|
||||
action_id = lower(string(action_id));
|
||||
|
||||
switch action_id
|
||||
case "plot_well_response"
|
||||
plotWellResponse(results.Times, results.Wellpara);
|
||||
case "plot_2d_layer"
|
||||
assert_plot_function_exists('plot_2D_layer');
|
||||
plot_2D_layer(default_time_step(results), default_layer(results.r), results.r, results.OutputRs, default_plot_type(config));
|
||||
case "plot_3d_distribution"
|
||||
assert_plot_function_exists('plot_3D_dis');
|
||||
plot_3D_dis(default_time_step(results), results.r, results.OutputRs, default_plot_type(config));
|
||||
case "plot_sp_dp"
|
||||
assert_plot_function_exists('plot_SP_DP');
|
||||
plot_SP_DP(default_layer(results.r), results.r);
|
||||
case "plot_perm"
|
||||
assert_plot_function_exists('plot_perm');
|
||||
plot_perm(default_layer(results.r), results.r);
|
||||
otherwise
|
||||
error('run_case_plot:UnsupportedAction', ...
|
||||
'Unsupported plot action: %s', string(action_id));
|
||||
end
|
||||
end
|
||||
|
||||
function source_case_folder = resolve_source_case_folder(project_root, meta_config)
|
||||
source_case_folder = meta_config.source_case_folder;
|
||||
if isfolder(source_case_folder)
|
||||
return;
|
||||
end
|
||||
|
||||
case_id = lower(string(meta_config.case_id));
|
||||
case_num = sscanf(char(case_id), 'case%d');
|
||||
if isempty(case_num)
|
||||
source_case_folder = '';
|
||||
return;
|
||||
end
|
||||
|
||||
folder_candidates = dir(fullfile(project_root, sprintf('*%d-*', case_num)));
|
||||
folder_candidates = folder_candidates([folder_candidates.isdir]);
|
||||
if isempty(folder_candidates)
|
||||
source_case_folder = '';
|
||||
else
|
||||
source_case_folder = fullfile(project_root, folder_candidates(1).name);
|
||||
end
|
||||
end
|
||||
|
||||
function idx = default_time_step(results)
|
||||
if isfield(results, 'OutputRs') && ~isempty(results.OutputRs)
|
||||
idx = numel(results.OutputRs);
|
||||
else
|
||||
idx = 1;
|
||||
end
|
||||
end
|
||||
|
||||
function k = default_layer(r)
|
||||
k = 1;
|
||||
if isfield(r, 'nz') && ~isempty(r.nz)
|
||||
k = min(1, r.nz);
|
||||
end
|
||||
end
|
||||
|
||||
function type = default_plot_type(config)
|
||||
switch config.model.flow_model
|
||||
case 1
|
||||
type = 1;
|
||||
case 2
|
||||
type = 1;
|
||||
case 3
|
||||
type = 1;
|
||||
otherwise
|
||||
type = 1;
|
||||
end
|
||||
end
|
||||
|
||||
function assert_plot_function_exists(function_name)
|
||||
if exist(function_name, 'file') ~= 2
|
||||
error('run_case_plot:MissingPlotFunction', ...
|
||||
'Plot function not found in current case folder: %s', function_name);
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user