18 #include <grass/gis.h>
19 #include <grass/bitmap.h>
20 #include <grass/linkm.h>
22 #include <grass/interpf.h>
28 double zminac,
double zmaxac,
29 double c1min,
double c1max,
double c2min,
double c2max,
double gmin,
double gmax,
double ertot,
31 double *dnorm,
struct Cell_head *outhd,
32 struct Cell_head *winhd,
33 char *smooth,
int n_points)
41 int cf1 = 0, cf2 = 0, cf3 = 0, cf4 = 0, cf5 = 0, cf6 = 0;
46 struct Colors colors, colors2;
47 double value1, value2;
48 struct History hist, hist1, hist2, hist3, hist4, hist5;
49 struct _Color_Rule_ *
rule;
59 "Temporarily changing the region to desired resolution...\n");
61 fprintf(stderr,
"Cannot set region to output region!\n");
71 fprintf(stderr,
"unable to create raster map %s\n", params->
elev);
79 fprintf(stderr,
"unable to create raster map %s\n",
88 fprintf(stderr,
"unable to create raster map %s\n",
97 fprintf(stderr,
"unable to create raster map %s\n",
106 fprintf(stderr,
"unable to create raster map %s\n",
115 fprintf(stderr,
"unable to create raster map %s\n",
122 if (nrows != params->
nsizr) {
123 fprintf(stderr,
"first change your rows number(%d) to %d!\n",
124 nrows, params->
nsizr);
129 if (ncols != params->
nsizc) {
130 fprintf(stderr,
"first change your rows number(%d) to %d!\n",
131 ncols, params->
nsizc);
137 for (i = 0; i < params->
nsizr; i++) {
140 ((params->
nsizr - 1 -
141 i) * params->
nsizc *
sizeof(FCELL)), 0) == -1) {
142 fprintf(stderr,
"cannot fseek to the right spot\n");
145 fread(cell1,
sizeof(FCELL), params->
nsizc, params->
Tmp_fd_z);
147 fprintf(stderr,
"cannot write file\n");
155 for (i = 0; i < params->
nsizr; i++) {
158 ((params->
nsizr - 1 -
159 i) * params->
nsizc *
sizeof(FCELL)), 0) == -1) {
160 fprintf(stderr,
"cannot fseek to the right spot\n");
170 fprintf(stderr,
"cannot write file\n");
178 for (i = 0; i < params->
nsizr; i++) {
181 ((params->
nsizr - 1 -
182 i) * params->
nsizc *
sizeof(FCELL)), 0) == -1) {
183 fprintf(stderr,
"cannot fseek to the right spot\n");
188 fprintf(stderr,
"cannot write file\n");
196 for (i = 0; i < params->
nsizr; i++) {
199 ((params->
nsizr - 1 -
200 i) * params->
nsizc *
sizeof(FCELL)), 0) == -1) {
201 fprintf(stderr,
"cannot fseek to the right spot\n");
206 fprintf(stderr,
"cannot write file\n");
214 for (i = 0; i < params->
nsizr; i++) {
217 ((params->
nsizr - 1 -
218 i) * params->
nsizc *
sizeof(FCELL)), 0) == -1) {
219 fprintf(stderr,
"cannot fseek to the right spot\n");
224 fprintf(stderr,
"cannot write file\n");
232 for (i = 0; i < params->
nsizr; i++) {
235 ((params->
nsizr - 1 -
236 i) * params->
nsizc *
sizeof(FCELL)), 0) == -1) {
237 fprintf(stderr,
"cannot fseek to the right spot\n");
242 fprintf(stderr,
"cannot write file\n");
267 fprintf(stderr,
"file [%s] not found\n", input);
276 if (colors.modular.rules) {
277 rule = colors.modular.rules;
282 for (; rule; rule = rule->prev) {
283 value1 = rule->low.value * params->
zmult;
284 value2 = rule->high.value * params->
zmult;
287 rule->low.blu, &value2,
295 if (colors.fixed.rules) {
296 rule = colors.fixed.rules;
301 for (; rule; rule = rule->prev) {
302 value1 = rule->low.value * params->
zmult;
303 value2 = rule->high.value * params->
zmult;
305 rule->low.grn, rule->low.blu,
306 &value2, rule->high.red,
307 rule->high.grn, rule->high.blu,
315 fprintf(stderr,
"file [%s] not found\n", params->
elev);
320 fprintf(stderr,
"Cannot write color table\n");
324 zminac - 0.5, zmaxac + 0.5,
325 (CELL) (zminac - 0.5),
326 (CELL) (zmaxac + 0.5));
330 "No color table for input file -- will not create color table\n");
334 if (cond1 & (!params->
deriv)) {
348 fprintf(stderr,
"file [%s] not found\n", params->
slope);
357 sprintf(hist1.edhist[0],
"The elevation map is %s",
360 sprintf(hist1.datsrc_1,
"raster map %s", input);
378 fprintf(stderr,
"file [%s] not found\n", params->
aspect);
387 sprintf(hist2.edhist[0],
"The elevation map is %s",
390 sprintf(hist2.datsrc_1,
"raster map %s", input);
400 dat1 = (FCELL)
amin1(c1min, c2min);
401 dat2 = (FCELL) - 0.01;
404 &dat2, 0, 0, 255, &colors);
406 dat2 = (FCELL) - 0.001;
408 &dat2, 0, 127, 255, &colors);
410 dat2 = (FCELL) - 0.00001;
412 &dat2, 0, 255, 255, &colors);
416 &dat2, 200, 255, 200, &colors);
418 dat2 = (FCELL) 0.00001;
420 &dat2, 255, 255, 0, &colors);
422 dat2 = (FCELL) 0.001;
424 &dat2, 255, 127, 0, &colors);
428 &dat2, 255, 0, 0, &colors);
430 dat2 = (FCELL)
amax1(c1max, c2max);
432 &dat2, 155, 0, 20, &colors);
437 fprintf(stderr,
"file [%s] not found\n", params->
pcurv);
442 fprintf(stderr,
"color map written\n");
446 (CELL) (dat1 *
MULT),
447 (CELL) (dat2 * MULT));
451 sprintf(hist3.edhist[0],
"The elevation map is %s",
454 sprintf(hist3.datsrc_1,
"raster map %s", input);
464 fprintf(stderr,
"file [%s] not found\n", params->
tcurv);
469 dat1, dat2, (CELL) (dat1 *
MULT),
470 (CELL) (dat2 * MULT));
475 sprintf(hist4.edhist[0],
"The elevation map is %s",
478 sprintf(hist4.datsrc_1,
"raster map %s", input);
488 fprintf(stderr,
"file [%s] not found\n", params->
mcurv);
494 (CELL) (dat1 *
MULT),
495 (CELL) (dat2 * MULT));
500 sprintf(hist5.edhist[0],
"The elevation map is %s",
503 sprintf(hist5.datsrc_1,
"raster map %s", input);
514 fprintf(stderr,
"file [%s] not found \n", params->
elev);
520 sprintf(hist.edhist[0],
"tension=%f, smoothing=%s",
521 params->
fi * 1000. / (*dnorm), smooth);
523 sprintf(hist.edhist[0],
"tension=%f",
524 params->
fi * 1000. / (*dnorm));
525 sprintf(hist.edhist[1],
"dnorm=%f, zmult=%f", *dnorm, params->
zmult);
526 sprintf(hist.edhist[2],
"KMAX=%d, KMIN=%d, errtotal=%f", params->
kmax,
527 params->
kmin, sqrt(ertot / n_points));
528 sprintf(hist.edhist[3],
"zmin_data=%f, zmax_data=%f", zmin, zmax);
529 sprintf(hist.edhist[4],
"zmin_int=%f, zmax_int=%f", zminac, zmaxac);
531 sprintf(hist.datsrc_1,
"raster map %s", input);
539 fprintf(stderr,
"Changing the region back to initial...\n");
541 fprintf(stderr,
"Cannot set region to back to initial region!\n");
char * G_mapset(void)
current mapset name
int G_write_colors(const char *name, const char *mapset, struct Colors *colors)
write map layer color table
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
int G_short_history(const char *name, const char *type, struct History *hist)
initialize history structure
int G_open_fp_cell_new(const char *name)
Opens new fcell file in a database.
int G_add_d_raster_color_rule(const DCELL *val1, int r1, int g1, int b1, const DCELL *val2, int r2, int g2, int b2, struct Colors *colors)
Adds the floating-point rule (DCELL version)
int G_close_cell(int fd)
close a raster map
FCELL * G_allocate_f_raster_buf(void)
Allocates memory for a raster map of type FCELL.
int G_set_window(struct Cell_head *window)
Establishes 'window' as the current working window.
double amax1(double, double)
int G_read_colors(const char *name, const char *mapset, struct Colors *colors)
read map layer color table
int G_write_history(const char *name, struct History *hist)
write raster history file
int G_add_f_raster_color_rule(const FCELL *cat1, int r1, int g1, int b1, const FCELL *cat2, int r2, int g2, int b2, struct Colors *colors)
Adds the floating-point rule (FCELL version)
double amin1(double, double)
int IL_resample_output_2d(struct interp_params *, double, double, double, double, double, double, double, double, double, double, double, char *, double *, struct Cell_head *, struct Cell_head *, char *, int)
int G_add_color_rule(CELL cat1, int r1, int g1, int b1, CELL cat2, int r2, int g2, int b2, struct Colors *colors)
Set colors rules.
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. returns the mapset name whe...
int G_add_modular_d_raster_color_rule(const DCELL *val1, int r1, int g1, int b1, const DCELL *val2, int r2, int g2, int b2, struct Colors *colors)
Add modular color rule (DCELL version)
int G_quantize_fp_map_range(const char *name, const char *mapset, DCELL d_min, DCELL d_max, CELL min, CELL max)
Writes the f_quant file for the raster map name with one rule. The rule is generated using the floati...
int G_put_f_raster_row(int fd, const FCELL *buf)