Skip to content

Commit 8d44ca8

Browse files
committed
1.7.3 runProb now possible from CLI
1 parent 206c8a1 commit 8d44ca8

11 files changed

Lines changed: 671 additions & 140 deletions

File tree

CODE/cdsapi-0.2.5/example-glaciers.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

CODE/conf_points.m

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,25 @@
216216
points = get(cdp.points_table, 'Data');
217217

218218
figure; hold on; xlabel('Longitude'); ylabel('Latitude');
219+
220+
x = [points{:,3}];
221+
y = [points{:,2}];
222+
xx = [min(x), max(x)];
223+
yy = [min(y), max(y)];
224+
xE = 0.25*(max(x)-min(x));
225+
yE = 0.25*(max(y)-min(y));
226+
227+
plot(xx(1)-xE, yy(1)-yE, '.k', 'MarkerSize', 0.1);
228+
plot(xx(2)+xE, yy(2)+yE, '.k', 'MarkerSize', 0.1);
229+
plot_openstreetmap('scale', 2);
230+
219231
for i = 1:size(points,1)
220232
plot(points{i,3}, points{i,2}, 'or', 'MarkerSize', 7, 'MarkerEdgeColor', 'k', 'MarkerFaceColor', 'r');
221233
text(points{i,3}, points{i,2}, [' \leftarrow ', points{i,1}]);
222234
end
223235

224-
plot_google_map('maptype','terrain', 'MapScale', 1);
236+
% plot_google_map('maptype','terrain', 'MapScale', 1);
237+
225238
set(gca, 'Layer', 'top');
226239

227240
% Load button

CODE/dependencies/plot_google_map.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,13 @@
446446
end
447447

448448
try
449-
urlwrite(url,filepath);
449+
websave(url,filepath);
450450
catch % error downloading map
451-
warning(['Unable to download map form Google Servers.\n' ...
452-
'Matlab error was: %s\n\n' ...
453-
'Possible reasons: missing write permissions, no network connection, quota exceeded, or some other error.\n' ...
454-
'Consider using an API key if quota problems persist.\n\n' ...
455-
'To debug, try pasting the following URL in your browser, which may result in a more informative error:\n%s'], lasterr, url);
451+
% warning(['Unable to download map form Google Servers.\n' ...
452+
% 'Matlab error was: %s\n\n' ...
453+
% 'Possible reasons: missing write permissions, no network connection, quota exceeded, or some other error.\n' ...
454+
% 'Consider using an API key if quota problems persist.\n\n' ...
455+
% 'To debug, try pasting the following URL in your browser, which may result in a more informative error:\n%s'], lasterr, url);
456456
varargout{1} = [];
457457
varargout{2} = [];
458458
varargout{3} = [];

CODE/dwind/process_wind.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ function process_wind(varargin)
139139
stor(i).LAT = ncread(fullfile(in_path, fl(i).name), 'latitude');
140140
stor(i).LON = ncread(fullfile(in_path, fl(i).name), 'longitude');
141141

142+
stor(i).LON(stor(i).LON<0) = 360-abs(stor(i).LON);
142143
% Find vent coordinates
143144
if i==1
144145
if length(stor(i).LAT) == 1 || length(stor(i).LON) == 1
@@ -161,9 +162,10 @@ function process_wind(varargin)
161162

162163
% Do some tests to see if the timestamp is correct
163164
time = cat(1,stor.time);
164-
minTime = stor(1).time(1);
165-
maxTime = stor(i).time(end);
166-
165+
% minTime = stor(1).time(1);
166+
% maxTime = stor(i).time(end);
167+
minTime = min(time);
168+
maxTime = max(time);
167169

168170
% Check if the maximum time from downloaded data is equal to the
169171
% theoretical maximum time based on the time dimension

CODE/gvp/GVP_Eruption_Results.xls

Lines changed: 172 additions & 0 deletions
Large diffs are not rendered by default.

CODE/gvp/gvp.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,14 @@
301301
'Callback', @PREP_DATA);
302302

303303
function ws(~,~)
304-
web http://www.volcano.si.edu/search_volcano.cfm -browser
304+
web http://volcano.si.edu/search_volcano.cfm -browser
305305

306306
function download_data(~, ~)
307307
global gvp stor htmldata
308308

309309
volcano_code = get(gvp.top_code, 'String');
310310

311-
websave('tmp.html', ['http://www.volcano.si.edu/volcano.cfm?vn=', volcano_code]);
311+
websave('tmp.html', ['http://volcano.si.edu/volcano.cfm?vn=', volcano_code]);
312312

313313
% Use htmlTableToCell function to retrieve table from html
314314
tables.idTableBy.plaintextPreceedingTable = '<table class="DivTable" title="Eruption history table for this volcano">';

CODE/runProb.m

Lines changed: 96 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
%}
3838

3939

40-
function runProb
40+
function runProb_cmd(varargin)
4141
% Check that you are located in the correct folder!
4242
if ~exist(fullfile(pwd, 'tephraProb.m'), 'file')
4343
errordlg(sprintf('You are located in the folder:\n%s\nIn Matlab, please navigate to the root of the TephraProb\nfolder, i.e. where tephraProb.m is located. and try again.', pwd), ' ')
@@ -47,9 +47,13 @@
4747
global data % Global variable
4848

4949
% Retrieve data from storage
50-
state = prepare_data(0);
51-
if state == 0
52-
return
50+
if nargin == 0
51+
state = prepare_data(0);
52+
if state == 0
53+
return
54+
end
55+
else
56+
state = prepare_data(varargin{1});
5357
end
5458

5559
if isfield(data, 'testrun') && isfield(data, 'long_lasting')
@@ -530,7 +534,7 @@
530534
% 1: Load run
531535
global t
532536
load(fullfile('VAR','tephraProb.mat')); % Load the description of each variable -> tab
533-
if mode == 1 % If in load mode
537+
if ~isstruct(mode) && mode == 1 % If in load mode
534538
uiopen('*.mat'); % Load previous run -> data
535539
if ~exist('data', 'var')
536540
return
@@ -543,9 +547,12 @@
543547
set(t.tab, 'Data', [data.var, data.ini, data.dsc]);
544548
end
545549

546-
elseif mode == 0
550+
elseif ~isstruct(mode) && mode == 0
547551
data_gui([tab.var, tab.ini, tab.dsc]);
548552
state = 1;
553+
else
554+
test_param('cmd','dummy',mode)
555+
state = 1;
549556
end
550557

551558
function load_data(~, ~, ~)
@@ -647,55 +654,90 @@ function data_gui(tab_data)
647654
uiwait(t.fig);
648655

649656
% Test input parameters
650-
function test_param(~, ~, t)
651-
uiresume(t.fig);
652-
global data % Define global variable
653-
data = struct; % Create a new structure storing all data
654-
tmp = get(t.tab, 'Data'); % Retrieve data table
655-
656-
% Go through input parameters
657-
for i = 1:size(tmp, 1)
658-
% If line is not empty (i.e. separator)
659-
if ~isempty(tmp{i,1}) && ~isempty(tmp{i,2}) && ~isempty(tmp{i,3})
660-
if isnan(str2double(tmp{i,2})) % If cell is a string
661-
data.(tmp{i,1}) = tmp{i,2}; % = setfield(data, tmp{i,1}, tmp{i,2});
662-
else
663-
% Else convert it to double
664-
data.(tmp{i,1}) = str2double(tmp{i,2});
665-
%data = setfield(data, tmp{i,1}, str2double(tmp{i,2}));
666-
end
667-
end
668-
end
657+
function test_param(cl, ~, t)
658+
global data
669659

670-
errchk = 0;
671-
warnstr = 'The following problems were identified:\n';
672-
if ~exist(data.grid_pth, 'file')
673-
warnstr = strcat(warnstr, '- The path to the grid file does not exist\n'); errchk = 1;
674-
elseif ~isdir(data.wind_pth)
675-
warnstr = strcat(warnstr, '- The path to the wind files does not exist\n'); errchk = 1;
676-
elseif data.max_ht < data.min_ht
677-
warnstr = strcat(warnstr, '- The maximum plume height is lower than the minimum plume height\n'); errchk = 1;
678-
elseif data.max_mass < data.min_mass
679-
warnstr = strcat(warnstr, '- The maximum mass is lower than the minimum mass\n'); errchk = 1;
680-
elseif data.max_dur < data.min_dur
681-
warnstr = strcat(warnstr, '- The maximum duration is lower than the minimum duration\n'); errchk = 1;
682-
elseif data.min_phi < data.max_phi
683-
warnstr = strcat(warnstr, '- The max_phi variable represents the coarsest material, i.e. the smallest number in phi units\n'); errchk = 1;
684-
elseif data.max_med_phi < data.min_med_phi
685-
warnstr = strcat(warnstr, '- The maximum median phi is lower than the minimum median phi\n'); errchk = 1;
686-
elseif data.max_std_phi < data.min_std_phi
687-
warnstr = strcat(warnstr, '- The maximum std phi is lower than the minimum std phi\n'); errchk = 1;
688-
elseif data.max_agg < data.min_agg
689-
warnstr = strcat(warnstr, '- The maximum aggregation coefficient is lower than the minimum maggregation coefficient\n'); errchk = 1;
690-
end
660+
if strcmp(cl,'cmd')
661+
data = t;
691662

692-
if errchk == 1
693-
wrn = warndlg(sprintf(warnstr), ' ');
694-
waitfor(wrn);
695-
close(t.fig);
696-
data_gui(tmp);
697663

698-
else
664+
if (data.constrain == 1 && ~isfield(data, 'min_dur')) || (data.constrain == 1 && ~isfield(data, 'max_dur'))
665+
error('You set the `constrain` parameter to 1, which requires defining `min_dur` and `max_dur`')
666+
elseif data.constrain == 0 && ~isfield(data, 'mass_sample')
667+
error('You set the `constrain` parameter to 0, which requires defining `mass_sample`')
668+
end
669+
670+
671+
if ~exist(data.grid_pth, 'file')
672+
error('The path to the grid file does not exist')
673+
elseif ~isfolder(data.wind_pth)
674+
error('The path to the wind files does not exist')
675+
elseif data.max_ht < data.min_ht
676+
error('The maximum plume height is lower than the minimum plume height')
677+
elseif data.max_mass < data.min_mass
678+
error('The maximum mass is lower than the minimum mass')
679+
elseif data.max_dur < data.min_dur
680+
error('The maximum duration is lower than the minimum duration')
681+
elseif data.min_phi < data.max_phi
682+
error('The max_phi variable represents the coarsest material, i.e. the smallest number in phi units')
683+
elseif data.max_med_phi < data.min_med_phi
684+
error('The maximum median phi is lower than the minimum median phi')
685+
elseif data.max_std_phi < data.min_std_phi
686+
error('The maximum std phi is lower than the minimum std phi')
687+
elseif data.max_agg < data.min_agg
688+
error('The maximum aggregation coefficient is lower than the minimum aggregation coefficient')
689+
end
699690
data.testrun = 1;
700-
close(t.fig);
701-
end
691+
else
692+
uiresume(t.fig);
693+
% Define global variable
694+
data = struct; % Create a new structure storing all data
695+
tmp = get(t.tab, 'Data'); % Retrieve data table
696+
697+
% Go through input parameters
698+
for i = 1:size(tmp, 1)
699+
% If line is not empty (i.e. separator)
700+
if ~isempty(tmp{i,1}) && ~isempty(tmp{i,2}) && ~isempty(tmp{i,3})
701+
if isnan(str2double(tmp{i,2})) % If cell is a string
702+
data.(tmp{i,1}) = tmp{i,2}; % = setfield(data, tmp{i,1}, tmp{i,2});
703+
else
704+
% Else convert it to double
705+
data.(tmp{i,1}) = str2double(tmp{i,2});
706+
%data = setfield(data, tmp{i,1}, str2double(tmp{i,2}));
707+
end
708+
end
709+
end
710+
711+
errchk = 0;
712+
warnstr = 'The following problems were identified:\n';
713+
if ~exist(data.grid_pth, 'file')
714+
warnstr = strcat(warnstr, '- The path to the grid file does not exist\n'); errchk = 1;
715+
elseif ~isfolder(data.wind_pth)
716+
warnstr = strcat(warnstr, '- The path to the wind files does not exist\n'); errchk = 1;
717+
elseif data.max_ht < data.min_ht
718+
warnstr = strcat(warnstr, '- The maximum plume height is lower than the minimum plume height\n'); errchk = 1;
719+
elseif data.max_mass < data.min_mass
720+
warnstr = strcat(warnstr, '- The maximum mass is lower than the minimum mass\n'); errchk = 1;
721+
elseif data.max_dur < data.min_dur
722+
warnstr = strcat(warnstr, '- The maximum duration is lower than the minimum duration\n'); errchk = 1;
723+
elseif data.min_phi < data.max_phi
724+
warnstr = strcat(warnstr, '- The max_phi variable represents the coarsest material, i.e. the smallest number in phi units\n'); errchk = 1;
725+
elseif data.max_med_phi < data.min_med_phi
726+
warnstr = strcat(warnstr, '- The maximum median phi is lower than the minimum median phi\n'); errchk = 1;
727+
elseif data.max_std_phi < data.min_std_phi
728+
warnstr = strcat(warnstr, '- The maximum std phi is lower than the minimum std phi\n'); errchk = 1;
729+
elseif data.max_agg < data.min_agg
730+
warnstr = strcat(warnstr, '- The maximum aggregation coefficient is lower than the minimum aggregation coefficient\n'); errchk = 1;
731+
end
732+
733+
if errchk == 1
734+
wrn = warndlg(sprintf(warnstr), ' ');
735+
waitfor(wrn);
736+
close(t.fig);
737+
data_gui(tmp);
738+
739+
else
740+
data.testrun = 1;
741+
close(t.fig);
742+
end
743+
end

0 commit comments

Comments
 (0)