-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up of BMI code, add save/load run mode.
- Loading branch information
1 parent
62a2105
commit f23ad62
Showing
3 changed files
with
59 additions
and
43 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,63 @@ | ||
%%%%%%% A function to run STEMMUS_SCOPE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
function STEMMUS_SCOPE_exe(config_file, run_mode, debug) | ||
function STEMMUS_SCOPE_exe(config_file, run_mode) | ||
if ~exist('run_mode','var') | ||
runMode = "full"; | ||
else | ||
runMode = run_mode; | ||
end | ||
|
||
if exist('debug','var') | ||
debugMode = true; | ||
else | ||
debugMode = false; | ||
end | ||
|
||
% disable all warnings | ||
warning('off', 'all'); | ||
|
||
% set the variable CFG | ||
CFG = config_file; | ||
% set the variable runMode | ||
|
||
% If the runMode is "full" or was not provided, the model will run as normal | ||
if strcmp(runMode, "full") | ||
run STEMMUS_SCOPE; | ||
|
||
% In interactive mode MATLAB stays open and waits for a new command... | ||
if strcmp(runMode, "interactive") | ||
elseif strcmp(runMode, "interactive") | ||
% Define BMI required variable names: | ||
bmiVarNames = {... | ||
'ModelSettings', ... % Model settings struct | ||
'TimeStep', ... % Time step size (in seconds) | ||
'KT', ... % Index of current time step | ||
'SiteProperties', ... % Site properties (e.g. lat, lon) | ||
'fluxes', ... % Atmospheric fluxes | ||
'TT', ... % Soil temperature over depth | ||
}; %#ok | ||
|
||
% ...until finalize has been run, at which point it quits. | ||
while ~strcmp(runMode, "finalize") | ||
runMode = input("\nFinished command. Select run mode: ", "s"); | ||
if strcmp(runMode, "initialize") | strcmp(runMode, "update") | strcmp(runMode, "finalize") | ||
if debugMode | ||
disp(["Running in mode: ", runMode]); | ||
end | ||
|
||
if strcmp(runMode, "initialize") || strcmp(runMode, "update") || strcmp(runMode, "finalize") | ||
% The 'initialize', 'update' and 'finalize' run modes are dispatched to the model. | ||
run STEMMUS_SCOPE; | ||
else | ||
if debugMode | ||
disp(["Run mode '", runMode, "' not recognised. Try again"]); | ||
|
||
elseif strcmp(runMode, "save") | ||
% Save entire model state to file. This can be retrieved with the | ||
% model run mode "load", where this file is opened again. | ||
save([Output_dir, 'STEMMUS_SCOPE_full_state.mat'], "-v7.3", "-nocompression"); | ||
|
||
elseif strcmp(runMode, "load") | ||
% Load the full workspace file | ||
[~, OutputPath, ~] = io.read_config(CFG); | ||
stateFile = [OutputPath, 'STEMMUS_SCOPE_full_state.mat']; | ||
if isfile(stateFile) | ||
load(stateFile); %#ok | ||
else | ||
disp(["No file found at ", stateFile, ". Could not load file."]); | ||
end | ||
|
||
else | ||
% If the runMode is not one of the above, promt user again. | ||
disp(["Run mode '", runMode, "' not recognised. Try again"]); | ||
end | ||
end | ||
disp("Finished clean up. Quitting..."); | ||
|
||
else | ||
% run STEMMUS_SCOPE main code, in the selected run mode, and then quit. | ||
run STEMMUS_SCOPE; | ||
disp(["Run mode '", runMode, "' not recognised. The only valid modes are 'full' or 'interactive'"]); | ||
end | ||
|