3737%}
3838
3939
40- function runProb
40+ function runProb_cmd( varargin )
4141% Check that you are located in the correct folder!
4242if ~exist(fullfile(pwd , ' tephraProb.m' ), ' file' )
4343 errordlg(sprintf(' You are located in the folder:\n%s\n In Matlab, please navigate to the root of the TephraProb\n folder, i.e. where tephraProb.m is located. and try again.' , pwd ), ' ' )
4747global 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 });
5357end
5458
5559if isfield(data , ' testrun' ) && isfield(data , ' long_lasting' )
530534% 1: Load run
531535global t
532536load(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
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 ;
549556end
550557
551558function load_data(~, ~, ~)
@@ -647,55 +654,90 @@ function data_gui(tab_data)
647654uiwait(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