24#include <grass/raster.h>
25#include <grass/bitmap.h>
26#include <grass/linkm.h>
27#include <grass/interpf.h>
28#include <grass/glocale.h>
32static void do_history(
const char *
name,
int vect,
const char *input,
37 Rast_short_history(
name,
"raster", &hist);
39 Rast_append_format_history(&hist,
"The elevation map is %s",
41 Rast_format_history(&hist, HIST_DATSRC_1,
"%s %s",
42 vect ?
"vector map" :
"site file",
45 Rast_command_history(&hist);
46 Rast_write_history(
name, &hist);
50 Rast_free_history(&hist);
60 struct Cell_head *cellhd,
61 double zmin,
double zmax,
62 double zminac,
double zmaxac,
63 double c1min,
double c1max,
64 double c2min,
double c2max,
65 double gmin,
double gmax,
69 int dtens,
int vect,
int n_points
73 int cf1 = -1, cf2 = -1, cf3 = -1, cf4 = -1, cf5 = -1, cf6 = -1;
81 const char *mapset =
NULL;
90 Rast_set_window(cellhd);
92 cell1 = Rast_allocate_f_buf();
98 cf1 = Rast_open_new(params->
elev, FCELL_TYPE);
101 cf2 = Rast_open_new(params->
slope, FCELL_TYPE);
104 cf3 = Rast_open_new(params->
aspect, FCELL_TYPE);
107 cf4 = Rast_open_new(params->
pcurv, FCELL_TYPE);
110 cf5 = Rast_open_new(params->
tcurv, FCELL_TYPE);
113 cf6 = Rast_open_new(params->
mcurv, FCELL_TYPE);
115 nrows = cellhd->rows;
116 if (nrows != params->
nsizr) {
117 G_warning(_(
"First change your rows number to nsizr! %d %d"),
118 nrows, params->
nsizr);
122 ncols = cellhd->cols;
123 if (ncols != params->
nsizc) {
124 G_warning(_(
"First change your cols number to nsizc %d %d"),
125 ncols, params->
nsizc);
131 for (i = 0; i < params->
nsizr; i++) {
134 params->
nsizc *
sizeof(FCELL), 0);
135 ii = fread(cell1,
sizeof(FCELL), params->
nsizc, params->
Tmp_fd_z);
140 Rast_put_f_row(cf1, cell1);
147 for (i = 0; i < params->
nsizr; i++) {
150 params->
nsizc *
sizeof(FCELL), 0);
152 Rast_put_f_row(cf2, cell1);
158 for (i = 0; i < params->
nsizr; i++) {
161 params->
nsizc *
sizeof(FCELL), 0);
163 Rast_put_f_row(cf3, cell1);
169 for (i = 0; i < params->
nsizr; i++) {
172 params->
nsizc *
sizeof(FCELL), 0);
174 Rast_put_f_row(cf4, cell1);
180 for (i = 0; i < params->
nsizr; i++) {
183 params->
nsizc *
sizeof(FCELL), 0);
185 Rast_put_f_row(cf5, cell1);
191 for (i = 0; i < params->
nsizr; i++) {
194 params->
nsizc *
sizeof(FCELL), 0);
196 Rast_put_f_row(cf6, cell1);
215 Rast_init_colors(&colors);
216 zstep = (FCELL) (zmaxac - zminac) / 5.;
217 for (i = 1; i <= 5; i++) {
218 data1 = (FCELL) (zminac + (i - 1) * zstep);
219 data2 = (FCELL) (zminac + i * zstep);
222 Rast_add_f_color_rule(&data1, 0, 191, 191,
223 &data2, 0, 255, 0, &colors);
226 Rast_add_f_color_rule(&data1, 0, 255, 0,
227 &data2, 255, 255, 0, &colors);
230 Rast_add_f_color_rule(&data1, 255, 255, 0,
231 &data2, 255, 127, 0, &colors);
234 Rast_add_f_color_rule(&data1, 255, 127, 0,
235 &data2, 191, 127, 63, &colors);
238 Rast_add_f_color_rule(&data1, 191, 127, 63,
239 &data2, 200, 200, 200, &colors);
246 if (mapset ==
NULL) {
250 Rast_write_colors(params->
elev, mapset, &colors);
251 Rast_quantize_fp_map_range(params->
elev, mapset,
252 (DCELL) zminac - 0.5, (DCELL) zmaxac + 0.5,
253 (CELL) (zminac - 0.5), (CELL) (zmaxac + 0.5));
258 if (!params->
deriv) {
264 Rast_init_colors(&colors);
267 Rast_add_c_color_rule(&val1, 255, 255, 255, &val2, 255, 255, 0, &colors);
270 Rast_add_c_color_rule(&val1, 255, 255, 0, &val2, 0, 255, 0, &colors);
273 Rast_add_c_color_rule(&val1, 0, 255, 0, &val2, 0, 255, 255, &colors);
276 Rast_add_c_color_rule(&val1, 0, 255, 255, &val2, 0, 0, 255, &colors);
279 Rast_add_c_color_rule(&val1, 0, 0, 255, &val2, 255, 0, 255, &colors);
282 Rast_add_c_color_rule(&val1, 255, 0, 255, &val2, 255, 0, 0, &colors);
285 Rast_add_c_color_rule(&val1, 255, 0, 0, &val2, 0, 0, 0, &colors);
288 Rast_init_colors(&colors);
289 dat1 = (FCELL) - 5.0;
291 dat2 = (FCELL) - 0.1;
292 Rast_add_f_color_rule(&dat1, 127, 0, 255,
293 &dat2, 0, 0, 255, &colors);
295 dat2 = (FCELL) - 0.01;
296 Rast_add_f_color_rule(&dat1, 0, 0, 255,
297 &dat2, 0, 127, 255, &colors);
299 dat2 = (FCELL) - 0.001;
300 Rast_add_f_color_rule(&dat1, 0, 127, 255,
301 &dat2, 0, 255, 255, &colors);
304 Rast_add_f_color_rule(&dat1, 0, 255, 255,
305 &dat2, 200, 255, 200, &colors);
307 dat2 = (FCELL) 0.001;
308 Rast_add_f_color_rule(&dat1, 200, 255, 200,
309 &dat2, 255, 255, 0, &colors);
312 Rast_add_f_color_rule(&dat1, 255, 255, 0,
313 &dat2, 255, 127, 0, &colors);
316 Rast_add_f_color_rule(&dat1, 255, 127, 0,
317 &dat2, 255, 0, 0, &colors);
321 Rast_add_f_color_rule(&dat1, 255, 0, 0,
322 &dat2, 255, 0, 200, &colors);
327 if (mapset ==
NULL) {
331 Rast_write_colors(params->
slope, mapset, &colors);
332 Rast_quantize_fp_map_range(params->
slope, mapset, 0., 90., 0, 90);
334 do_history(params->
slope, vect, input, params);
338 if (!params->
deriv) {
339 Rast_init_colors(&colors);
342 Rast_add_c_color_rule(&val1, 255, 255, 255, &val2, 255, 255, 255, &colors);
345 Rast_add_c_color_rule(&val1, 255, 255, 0, &val2, 0, 255, 0, &colors);
348 Rast_add_c_color_rule(&val1, 0, 255, 0, &val2, 0, 255, 255, &colors);
351 Rast_add_c_color_rule(&val1, 0, 255, 255, &val2, 255, 0, 0, &colors);
354 Rast_add_c_color_rule(&val1, 255, 0, 0, &val2, 255, 255, 0, &colors);
357 Rast_init_colors(&colors);
358 dat1 = (FCELL) - 5.0;
360 dat2 = (FCELL) - 0.1;
361 Rast_add_f_color_rule(&dat1, 127, 0, 255,
362 &dat2, 0, 0, 255, &colors);
364 dat2 = (FCELL) - 0.01;
365 Rast_add_f_color_rule(&dat1, 0, 0, 255,
366 &dat2, 0, 127, 255, &colors);
368 dat2 = (FCELL) - 0.001;
369 Rast_add_f_color_rule(&dat1, 0, 127, 255,
370 &dat2, 0, 255, 255, &colors);
373 Rast_add_f_color_rule(&dat1, 0, 255, 255,
374 &dat2, 200, 255, 200, &colors);
376 dat2 = (FCELL) 0.001;
377 Rast_add_f_color_rule(&dat1, 200, 255, 200,
378 &dat2, 255, 255, 0, &colors);
381 Rast_add_f_color_rule(&dat1, 255, 255, 0,
382 &dat2, 255, 127, 0, &colors);
385 Rast_add_f_color_rule(&dat1, 255, 127, 0,
386 &dat2, 255, 0, 0, &colors);
390 Rast_add_f_color_rule(&dat1, 255, 0, 0,
391 &dat2, 255, 0, 200, &colors);
396 if (mapset ==
NULL) {
400 Rast_write_colors(params->
aspect, mapset, &colors);
401 Rast_quantize_fp_map_range(params->
aspect, mapset, 0., 360., 0, 360);
403 do_history(params->
aspect, vect, input, params);
408 Rast_init_colors(&colors);
409 dat1 = (FCELL)
amin1(c1min, c2min);
411 dat2 = (FCELL) - 0.01;
412 Rast_add_f_color_rule(&dat1, 127, 0, 255,
413 &dat2, 0, 0, 255, &colors);
415 dat2 = (FCELL) - 0.001;
416 Rast_add_f_color_rule(&dat1, 0, 0, 255,
417 &dat2, 0, 127, 255, &colors);
419 dat2 = (FCELL) - 0.00001;
420 Rast_add_f_color_rule(&dat1, 0, 127, 255,
421 &dat2, 0, 255, 255, &colors);
424 Rast_add_f_color_rule(&dat1, 0, 255, 255,
425 &dat2, 200, 255, 200, &colors);
427 dat2 = (FCELL) 0.00001;
428 Rast_add_f_color_rule(&dat1, 200, 255, 200,
429 &dat2, 255, 255, 0, &colors);
431 dat2 = (FCELL) 0.001;
432 Rast_add_f_color_rule(&dat1, 255, 255, 0,
433 &dat2, 255, 127, 0, &colors);
436 Rast_add_f_color_rule(&dat1, 255, 127, 0,
437 &dat2, 255, 0, 0, &colors);
439 dat2 = (FCELL)
amax1(c1max, c2max);
441 Rast_add_f_color_rule(&dat1, 255, 0, 0,
442 &dat2, 255, 0, 200, &colors);
446 if (mapset ==
NULL) {
450 Rast_write_colors(params->
pcurv, mapset, &colors);
451 Rast_quantize_fp_map_range(params->
pcurv, mapset, dat1, dat2,
452 (CELL) (dat1 *
MULT),
453 (CELL) (dat2 *
MULT));
455 do_history(params->
pcurv, vect, input, params);
460 if (mapset ==
NULL) {
464 Rast_write_colors(params->
tcurv, mapset, &colors);
465 Rast_quantize_fp_map_range(params->
tcurv, mapset, dat1, dat2,
466 (CELL) (dat1 *
MULT),
467 (CELL) (dat2 *
MULT));
469 do_history(params->
tcurv, vect, input, params);
474 if (mapset ==
NULL) {
478 Rast_write_colors(params->
mcurv, mapset, &colors);
479 Rast_quantize_fp_map_range(params->
mcurv, mapset, dat1, dat2,
480 (CELL) (dat1 *
MULT),
481 (CELL) (dat2 *
MULT));
483 do_history(params->
mcurv, vect, input, params);
490 if (mapset ==
NULL) {
495 Rast_short_history(params->
elev, type, &hist);
505 if (params->
rsm == -1)
506 Rast_append_format_history(
507 &hist,
"giventension=%f, smoothing att=%d",
508 params->
fi * 1000. / dnorm, params->
smatt);
510 Rast_append_format_history(
511 &hist,
"giventension=%f, smoothing=%f",
512 params->
fi * 1000. / dnorm, params->
rsm);
515 if (params->
rsm == -1)
516 Rast_append_format_history(
517 &hist,
"tension=%f, smoothing att=%d",
518 params->
fi * 1000. / dnorm, params->
smatt);
520 Rast_append_format_history(
521 &hist,
"tension=%f, smoothing=%f",
522 params->
fi, params->
rsm);
525 Rast_append_format_history(
526 &hist,
"dnorm=%f, dmin=%f, zmult=%f",
537 Rast_append_format_history(
538 &hist,
"segmax=%d, npmin=%d, rmsdevi=%f",
539 params->
kmax, params->
kmin, sqrt(ertot / n_points));
541 Rast_append_format_history(
542 &hist,
"zmin_data=%f, zmax_data=%f", zmin, zmax);
543 Rast_append_format_history(
544 &hist,
"zmin_int=%f, zmax_int=%f", zminac, zmaxac);
547 Rast_append_format_history(
548 &hist,
"theta=%f, scalex=%f", params->
theta,
551 Rast_format_history(&hist, HIST_DATSRC_1,
"%s %s",
552 vect ?
"vector map" :
"site file",
555 Rast_command_history(&hist);
556 Rast_write_history(params->
elev, &hist);
560 Rast_free_history(&hist);
const char * G_find_file(const char *element, char *name, const char *mapset)
Searches for a file from the mapset search list or in a specified mapset.
void G_warning(const char *msg,...)
Print a warning message to stderr.
void G_fseek(FILE *fp, off_t offset, int whence)
Change the file position of the stream.
double amin1(double, double)
double amax1(double, double)
int IL_output_2d(struct interp_params *params, struct Cell_head *cellhd, double zmin, double zmax, double zminac, double zmaxac, double c1min, double c1max, double c2min, double c2max, double gmin, double gmax, double ertot, char *input, double dnorm, int dtens, int vect, int n_points)
int G_write_raster_timestamp(const char *name, const struct TimeStamp *ts)
Write timestamp of raster map.