2
* r.topmodel: simulates TOPMODEL based on TMOD9502.FOR.
4
* TMOD9502.FOR Author: Keith Beven <k.beven@lancaster.ac.uk>
5
* http://www.es.lancs.ac.uk/hfdg/topmodel.html
7
* Copyright (C) 2000 by the GRASS Development Team
8
* Author: Huidae Cho <grass4u@gmail.com>
9
* Hydro Laboratory, Kyungpook National University
12
* This program is free software under the GPL (>=v2)
13
* Read the file COPYING coming with GRASS for details.
2
/****************************************************************************
6
* AUTHOR(S): Huidae Cho <grass4u gmail.com>, Hydro Laboratory,
7
* Kyungpook National University
8
* Based on TMOD9502.FOR by Keith Beven <k.beven lancaster.ac.uk>
10
* PURPOSE: Simulates TOPMODEL.
12
* COPYRIGHT: (C) 2000-2014 by the GRASS Development Team
14
* This program is free software under the GNU General Public
15
* License (>=v2). Read the file COPYING that comes with GRASS
18
*****************************************************************************/
19
22
#include <stdlib.h>
23
#include <grass/gis.h>
20
24
#include <grass/glocale.h>
21
25
#include "global.h"
24
27
int main(int argc, char **argv)
27
29
struct GModule *module;
35
struct Option *topidx;
36
struct Option *nidxclass;
37
struct Option *idxstats;
38
32
struct Option *params;
33
struct Option *topidxstats;
39
34
struct Option *input;
40
35
struct Option *output;
42
36
struct Option *timestep;
43
struct Option *idxclass;
37
struct Option *topidxclass;
38
struct Option *topidx;
39
struct Option *ntopidxclasses;
40
struct Option *outtopidxstats;
44
struct Flag *preprocess;
51
47
/* Initialize GRASS and parse command line */
52
48
G_gisinit(argv[0]);
54
50
module = G_define_module();
55
module->keywords = _("raster, hydrology");
51
G_add_keyword(_("raster"));
52
G_add_keyword(_("hydrology"));
56
53
module->description =
57
54
_("Simulates TOPMODEL which is a physically based hydrologic model.");
59
56
/* Parameter definitions */
60
param.basin = G_define_option();
61
param.basin->key = "basin";
62
param.basin->description =
63
_("(i) Basin map created by r.water.outlet (MASK)");
64
param.basin->type = TYPE_STRING;
65
param.basin->required = NO;
66
param.basin->gisprompt = "old,cell,raster";
68
param.elev = G_define_option();
69
param.elev->key = "elevation";
70
param.elev->description = _("(i) Elevation map");
71
param.elev->type = TYPE_STRING;
72
param.elev->required = NO;
73
param.elev->gisprompt = "old,cell,raster";
75
param.fill = G_define_option();
76
param.fill->key = "depressionless";
77
param.fill->description = _("(o) Depressionless elevation map");
78
param.fill->type = TYPE_STRING;
79
param.fill->required = NO;
80
param.fill->gisprompt = "new,cell,raster";
82
param.dir = G_define_option();
83
param.dir->key = "direction";
84
param.dir->description =
85
_("(o) Direction map for depressionless elevation map");
86
param.dir->type = TYPE_STRING;
87
param.dir->required = NO;
88
param.dir->gisprompt = "new,cell,raster";
90
param.belev = G_define_option();
91
param.belev->key = "belevation";
92
param.belev->description = _("(o/i) Basin elevation map (MASK applied)");
93
param.belev->type = TYPE_STRING;
94
param.belev->required = NO;
95
param.belev->gisprompt = "new,cell,raster";
97
param.topidx = G_define_option();
98
param.topidx->key = "topidx";
99
param.topidx->description =
100
_("(o) Topographic index ln(a/tanB) map (MASK applied)");
101
param.topidx->type = TYPE_STRING;
102
param.topidx->required = NO;
103
param.topidx->gisprompt = "new,cell,raster";
105
param.nidxclass = G_define_option();
106
param.nidxclass->key = "nidxclass";
107
param.nidxclass->description =
108
_("(i) Number of topographic index classes");
109
param.nidxclass->type = TYPE_INTEGER;
110
param.nidxclass->required = NO;
111
param.nidxclass->answer = "30";
113
param.idxstats = G_define_option();
114
param.idxstats->key = "idxstats";
115
param.idxstats->description =
116
_("(o/i) Topographic index statistics file");
117
param.idxstats->type = TYPE_STRING;
118
param.idxstats->required = YES;
120
param.params = G_define_option();
121
param.params->key = "parameters";
122
param.params->description = _("(i) TOPMODEL Parameters file");
123
param.params->type = TYPE_STRING;
124
param.params->required = YES;
126
param.input = G_define_option();
127
param.input->key = "input";
128
param.input->description =
129
_("(i) Rainfall and potential evapotranspiration data file");
130
param.input->type = TYPE_STRING;
131
param.input->required = YES;
133
param.output = G_define_option();
134
param.output->key = "output";
135
param.output->description = _("(o) Output file");
136
param.output->type = TYPE_STRING;
137
param.output->required = YES;
139
param.Qobs = G_define_option();
140
param.Qobs->key = "Qobs";
141
param.Qobs->description = _("(i) OPTIONAL Observed flow file");
142
param.Qobs->type = TYPE_STRING;
143
param.Qobs->required = NO;
145
param.timestep = G_define_option();
146
param.timestep->key = "timestep";
147
param.timestep->description =
148
_("(i) OPTIONAL Output for given time step");
149
param.timestep->type = TYPE_INTEGER;
150
param.timestep->required = NO;
152
param.idxclass = G_define_option();
153
param.idxclass->key = "idxclass";
154
param.idxclass->description =
155
_("(i) OPTIONAL Output for given topographic index class");
156
param.idxclass->type = TYPE_INTEGER;
157
param.idxclass->required = NO;
160
/* Flag definitions */
161
flag.input = G_define_flag();
162
flag.input->key = 'i';
163
flag.input->description = _("Input data given for (o/i)");
57
params.params = G_define_standard_option(G_OPT_F_INPUT);
58
params.params->key = "parameters";
59
params.params->description = _("Name of TOPMODEL parameters file");
61
params.topidxstats = G_define_standard_option(G_OPT_F_INPUT);
62
params.topidxstats->key = "topidxstats";
63
params.topidxstats->description =
64
_("Name of topographic index statistics file");
66
params.input = G_define_standard_option(G_OPT_F_INPUT);
67
params.input->description =
68
_("Name of rainfall and potential evapotranspiration data file");
70
params.output = G_define_standard_option(G_OPT_F_OUTPUT);
71
params.output->description = _("Name for output file");
73
params.timestep = G_define_option();
74
params.timestep->key = "timestep";
75
params.timestep->label = _("Time step");
76
params.timestep->description = _("Generate output for this time step");
77
params.timestep->type = TYPE_INTEGER;
78
params.timestep->required = NO;
80
params.topidxclass = G_define_option();
81
params.topidxclass->key = "topidxclass";
82
params.topidxclass->label = _("Topographic index class");
83
params.topidxclass->description =
84
_("Generate output for this topographic index class");
85
params.topidxclass->type = TYPE_INTEGER;
86
params.topidxclass->required = NO;
88
params.topidx = G_define_standard_option(G_OPT_R_INPUT);
89
params.topidx->key = "topidx";
90
params.topidx->label =
91
_("Name of input topographic index raster map");
92
params.topidx->description =
93
_("Must be clipped to the catchment boundary. Used for generating outtopidxstats");
94
params.topidx->required = NO;
95
params.topidx->guisection = _("Preprocess");
97
params.ntopidxclasses = G_define_option();
98
params.ntopidxclasses->key = "ntopidxclasses";
99
params.ntopidxclasses->label = _("Number of topographic index classes");
100
params.ntopidxclasses->description =
101
_("Used for generating outtopidxstats");
102
params.ntopidxclasses->type = TYPE_INTEGER;
103
params.ntopidxclasses->required = NO;
104
params.ntopidxclasses->answer = "30";
105
params.ntopidxclasses->guisection = _("Preprocess");
107
params.outtopidxstats = G_define_standard_option(G_OPT_F_OUTPUT);
108
params.outtopidxstats->key = "outtopidxstats";
109
params.outtopidxstats->label =
110
_("Name for output topographic index statistics file");
111
params.outtopidxstats->description =
112
_("Requires topidx and ntopidxclasses");
113
params.outtopidxstats->required = NO;
114
params.outtopidxstats->guisection = _("Preprocess");
116
flags.preprocess = G_define_flag();
117
flags.preprocess->key = 'p';
118
flags.preprocess->description =
119
_("Preprocess only and stop after generating outtopidxstats");
120
flags.preprocess->suppress_required = YES;
165
122
if (G_parser(argc, argv))
166
123
exit(EXIT_FAILURE);
168
/* Store given parameters and flags */
169
map.basin = param.basin->answer;
170
map.elev = param.elev->answer;
171
map.belev = param.belev->answer;
172
map.fill = param.fill->answer;
173
map.dir = param.dir->answer;
174
map.topidx = param.topidx->answer;
175
file.idxstats = param.idxstats->answer;
176
file.params = param.params->answer;
177
file.input = param.input->answer;
178
file.output = param.output->answer;
179
file.Qobs = param.Qobs->answer;
181
misc.nidxclass = atoi(param.nidxclass->answer);
183
if (!param.timestep->answer)
184
param.timestep->answer = "0";
185
if (!param.idxclass->answer)
186
param.idxclass->answer = "0";
188
misc.timestep = atoi(param.timestep->answer);
189
misc.idxclass = atoi(param.idxclass->answer);
191
flg.input = flag.input->answer;
192
flg.overwr = module->overwrite;
195
gisbase = G_gisbase();
199
/* Check run conditions */
203
/* Adjust cell header */
206
/* Create required maps */
125
/* Store given parameters */
126
file.params = params.params->answer;
127
file.topidxstats = params.topidxstats->answer;
128
file.input = params.input->answer;
129
file.output = params.output->answer;
131
if (!params.timestep->answer)
132
params.timestep->answer = "0";
133
misc.timestep = atoi(params.timestep->answer);
135
if (!params.topidxclass->answer)
136
params.topidxclass->answer = "0";
137
misc.topidxclass = atoi(params.topidxclass->answer);
139
if (params.topidx->answer && params.outtopidxstats->answer) {
142
char *outtopidxstats;
144
topidx = params.topidx->answer;
145
ntopidxclasses = atoi(params.ntopidxclasses->answer);
146
outtopidxstats = params.outtopidxstats->answer;
148
if (ntopidxclasses <= 1)
149
G_fatal_error(_("%s must be greater than 1"), "ntopidxclasses");
151
create_topidxstats(topidx, ntopidxclasses, outtopidxstats);
152
} else if (params.topidx->answer) {
153
G_warning(_("Ignoring %s because %s is not specified"),
154
params.topidx->key, params.outtopidxstats->key);
155
} else if (params.outtopidxstats->answer) {
156
G_warning(_("Ignoring %s because %s is not specified"),
157
params.outtopidxstats->key, params.topidx->key);
215
/* Read required files */
218
/* Implement TOPMODEL */
160
if (flags.preprocess->answer)