-
Notifications
You must be signed in to change notification settings - Fork 6
/
STEMMUS_SCOPE_exe.m
96 lines (80 loc) · 4.03 KB
/
STEMMUS_SCOPE_exe.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
%%%%%%% A function to run STEMMUS_SCOPE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function STEMMUS_SCOPE_exe(config_file, runMode)
if ~exist('runMode', 'var')
runMode = "full";
end
% disable all warnings
warning('off', 'all');
% set the variable CFG
CFG = config_file;
bmiMode = "none";
% If the runMode is "full" or was not provided, the model will run as normal
if strcmp(runMode, "full")
run STEMMUS_SCOPE;
elseif strcmp(runMode, "bmi")
% In interactive mode MATLAB stays open and waits for a new command...
% 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
'SoilVariables', ... % Structure that includes different variables of soil moisture
'GroundwaterSettings' ... % groundwater settings including input data from MODFLOW
'gwfluxes' ... % structure that includes groundwater recharge and its individual components
'EVAP' ... % evaporation
'RWUs' ... % soil water root uptake
'RWUg' ... % groundwater root uptake
'ForcingData' ... % forcing data that includes Dunnian runoff and Hortonian runoff
'RS' ... % total surface runoff
}; %#ok
% Variables for tracking the state of the model initialization:
isInitialized = false;
isUpdated = false;
% ...until finalize has been run, at which point it quits.
while ~strcmp(bmiMode, "finalize")
bmiMode = input("\nFinished command. Select BMI mode: ", "s");
if startsWith(bmiMode, "initialize ")
% Get config file:
CFG = erase(bmiMode, "initialize ");
CFG = strtrim(CFG); % remove leading and trailing whitespace
CFG = erase(CFG, '"'); % remove quotes
bmiMode = "initialize";
run STEMMUS_SCOPE;
isInitialized = true;
elseif strcmp(bmiMode, "update")
if isInitialized
% The 'initialize', 'update' and 'finalize' run modes are dispatched to the model.
run STEMMUS_SCOPE;
isUpdated = true;
else
disp("First initialize the model before calling 'update'");
end
elseif strcmp(bmiMode, "finalize")
if isInitialized & isUpdated
run STEMMUS_SCOPE;
end
elseif strcmp(bmiMode, "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(bmiMode, "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 bmiMode is not one of the above, promt user again.
disp(["Run mode '", bmiMode, "' not recognised. Try again"]);
end
end
disp("Finished clean up. Quitting...");
else
disp(["Run mode '", runMode, "' not recognised. Valid modes are 'full' or 'bmi'"]);
end
end