-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_model
More file actions
executable file
·128 lines (122 loc) · 4.8 KB
/
run_model
File metadata and controls
executable file
·128 lines (122 loc) · 4.8 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/csh
if (${#argv} < 3) then
echo "Use: run_model model_name scenario_name segment_id [module=all,land,river] [step=all,prep,run,link,analyze] [plugin=all,01_...]"
echo "Optional Environment Variables:"
set mr = `pwd`
echo " - MODEL_ROOT (required): the full path to the model executable. Default = pwd ($mr)"
echo " - IGNORE_PROBLEMS (0/1 optional): Proceed regardless of errors, i.e. ignore 'problem' file creation."
exit 1
endif
# @todo: dynamically find meta_model_root, i.e., this code base
if (! $?META_MODEL_ROOT ) then
set META_MODEL_ROOT="/opt/model/meta_model"
endif
set IGNORE_PROBLEMS = 0
# Get params from command arguments
# and set up list of modules and steps to run
source $META_MODEL_ROOT/model_get_args
echo $run_steps
#echo "Debug: args done"
# set a couple defaults that can e overriden by the model
set all_modules = ( land river )
set all_run_steps = ( prep run link analyze )
# Load meta-model configuration
setenv MODEL_ROOT "$MODEL_ROOT"
if ( -f $META_MODEL_ROOT/models/$model/model_config ) then
echo "Calling model_config with modules = $modules"
source $META_MODEL_ROOT/models/$model/model_config
else
echo "Error: Can not find model configuration file $META_MODEL_ROOT/models/$model/model_config"
echo "Exiting"
exit 1
endif
if ( $modules == "all" ) then
set modules = ( $all_modules )
endif
if ( $run_steps == "all" ) then
set run_steps = ( $all_run_steps )
endif
echo "Beginning Run model=$model, scenario=$scenario, segment=$segment, work_path=$work_path, modules=$modules, run_steps=$run_steps,script=$script"
install -d $work_path # insure that the work directory is in place
# todo: set up places to look for plugins in various trees such as MODEL_ROOT
set model_plugins=$META_MODEL_ROOT/models/$model
setenv MODEL_BIN "$MODEL_BIN"
setenv META_MODEL_ROOT "$META_MODEL_ROOT"
echo "setting MODEL to $model"
setenv MODEL "$model"
# IF we start seeing erorrs WRT START_YEAR or END_YEAR uncomment these:
#setenv START_YEAR "$START_YEAR"
#setenv END_YEAR "$END_YEAR"
setenv modules "$modules" # makes it available to sourced scripts
# iterate through different component of the model execution cycle
if ( -d $model_plugins ) then
foreach module ( $modules )
# todo: put checks in to see if this module is enabled in the run
foreach step ( $run_steps )
setenv module "$module"
setenv step "$step"
set script_path = "$model_plugins/$module/$step"
if ( -d $script_path ) then
if ( $script == "all" ) then
set plugins = `ls $script_path`
else
set plugins = `ls $script_path/*$script*`
endif
if ( $cleanup == 0 ) then
# override cleanup
else
# use logic to guess cleanup
if ( $script == "all" ) then
set cleanup = 1 # normal run, remove temp dir afterwards if completes OK
else
set cleanup = 0 # step by step run, do not remove temp dir afterwards
endif
endif
if ( ! ( "$plugins" == "" ) ) then
foreach plugin ( $plugins )
# in case we had a wildcard match script passed in
# we insure just the base name here. if it is already basename form
# it will return un-changed
set plugin = `basename $plugin`
echo "Running: $model_plugins/$module/$step/$plugin $scenario $segment $work_path"
$model_plugins/$module/$step/$plugin $scenario $segment $work_path
if ( -f $work_path/problem ) then
if ( ! ( $IGNORE_PROBLEMS ) ) then
echo "Error: Problem found in step $model => $module / $step / $plugin "
echo " See $work_path/problem "
exit 1
else
mv $work_path/problem $work_path/problem.${step}.${plugin}
echo "Warning: Problem found in step $model => $module / $step / $plugin "
echo " Continuing, though this should be checked. "
echo " See $work_path/problem.${step}.${plugin}"
endif
endif
end
else
echo "No model plugins found in $model_plugins/$module/$step/"
endif
else
echo "No step $step found in $model/$module"
endif
end
end
if ( -f $work_path/problem ) then
continue
else
echo "Model run for $segment / $scenario completed without errors."
if ( $cleanup == 1 ) then
if ( "$work_path" == "" ) then
echo "Work path $work_path is unset, cannot remove files"
else
echo "Removing work path $work_path"
rm -Rf $work_path
endif
else
echo "Model cleanup NOT performed. You will need to manually remove temp dir $work_path"
endif
endif
else
echo "No model definitions found for model type $model in $META_MODEL_ROOT/models"
endif
exit 0