~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/rst/interp_float/resout2d.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
#include <stdio.h>
17
17
#include <math.h>
 
18
 
18
19
#include <grass/gis.h>
 
20
#include <grass/raster.h>
19
21
#include <grass/bitmap.h>
20
22
#include <grass/linkm.h>
21
 
 
22
23
#include <grass/interpf.h>
23
 
 
 
24
#include <grass/glocale.h>
24
25
 
25
26
/* output cell maps for elevation, aspect, slope and curvatures */
26
27
 
 
28
static void do_history(const char *name, const char *input,
 
29
                       const struct interp_params *params)
 
30
{
 
31
    struct History hist;
 
32
 
 
33
    Rast_short_history(name, "raster", &hist);
 
34
    if (params->elev)
 
35
        Rast_append_format_history(&hist, "The elevation map is %s",
 
36
                                   params->elev);
 
37
 
 
38
    Rast_format_history(&hist, HIST_DATSRC_1, "raster map %s", input);
 
39
 
 
40
    Rast_write_history(name, &hist);
 
41
 
 
42
    Rast_free_history(&hist);
 
43
}
 
44
 
27
45
int IL_resample_output_2d(struct interp_params *params, double zmin, double zmax,       /* min,max input z-values */
28
46
                          double zminac, double zmaxac, /* min,max interpolated values */
29
47
                          double c1min, double c1max, double c2min, double c2max, double gmin, double gmax, double ertot,       /* total interplating func. error */
41
59
    int cf1 = 0, cf2 = 0, cf3 = 0, cf4 = 0, cf5 = 0, cf6 = 0;   /* cell file descriptors */
42
60
    int nrows, ncols;           /* current region rows and columns */
43
61
    int i;                      /* loop counter */
44
 
    char *mapset;
 
62
    const char *mapset;
45
63
    float dat1, dat2;
46
64
    struct Colors colors, colors2;
47
65
    double value1, value2;
48
 
    struct History hist, hist1, hist2, hist3, hist4, hist5;
 
66
    struct History hist;
49
67
    struct _Color_Rule_ *rule;
50
 
    char *maps, *type;
 
68
    const char *maps;
51
69
    int cond1, cond2;
52
 
 
 
70
    CELL val1, val2;
 
71
    
53
72
    cond2 = ((params->pcurv != NULL) ||
54
73
             (params->tcurv != NULL) || (params->mcurv != NULL));
55
74
    cond1 = ((params->slope != NULL) || (params->aspect != NULL) || cond2);
56
75
 
57
76
    /* change region to output cell file region */
58
 
    fprintf(stderr,
59
 
            "Temporarily changing the region to desired resolution...\n");
60
 
    if (G_set_window(outhd) < 0) {
61
 
        fprintf(stderr, "Cannot set region to output region!\n");
62
 
        return -1;
63
 
    }
 
77
    G_verbose_message(_("Temporarily changing the region to desired resolution..."));
 
78
    Rast_set_output_window(outhd);
64
79
    mapset = G_mapset();
65
80
 
66
 
    cell1 = G_allocate_f_raster_buf();
67
 
 
68
 
    if (params->elev != NULL) {
69
 
        cf1 = G_open_fp_cell_new(params->elev);
70
 
        if (cf1 < 0) {
71
 
            fprintf(stderr, "unable to create raster map %s\n", params->elev);
72
 
            return -1;
73
 
        }
74
 
    }
75
 
 
76
 
    if (params->slope != NULL) {
77
 
        cf2 = G_open_fp_cell_new(params->slope);
78
 
        if (cf2 < 0) {
79
 
            fprintf(stderr, "unable to create raster map %s\n",
80
 
                    params->slope);
81
 
            return -1;
82
 
        }
83
 
    }
84
 
 
85
 
    if (params->aspect != NULL) {
86
 
        cf3 = G_open_fp_cell_new(params->aspect);
87
 
        if (cf3 < 0) {
88
 
            fprintf(stderr, "unable to create raster map %s\n",
89
 
                    params->aspect);
90
 
            return -1;
91
 
        }
92
 
    }
93
 
 
94
 
    if (params->pcurv != NULL) {
95
 
        cf4 = G_open_fp_cell_new(params->pcurv);
96
 
        if (cf4 < 0) {
97
 
            fprintf(stderr, "unable to create raster map %s\n",
98
 
                    params->pcurv);
99
 
            return -1;
100
 
        }
101
 
    }
102
 
 
103
 
    if (params->tcurv != NULL) {
104
 
        cf5 = G_open_fp_cell_new(params->tcurv);
105
 
        if (cf5 < 0) {
106
 
            fprintf(stderr, "unable to create raster map %s\n",
107
 
                    params->tcurv);
108
 
            return -1;
109
 
        }
110
 
    }
111
 
 
112
 
    if (params->mcurv != NULL) {
113
 
        cf6 = G_open_fp_cell_new(params->mcurv);
114
 
        if (cf6 < 0) {
115
 
            fprintf(stderr, "unable to create raster map %s\n",
116
 
                    params->mcurv);
117
 
            return -1;
118
 
        }
119
 
    }
 
81
    cell1 = Rast_allocate_f_output_buf();
 
82
 
 
83
    if (params->elev)
 
84
        cf1 = Rast_open_fp_new(params->elev);
 
85
 
 
86
    if (params->slope)
 
87
        cf2 = Rast_open_fp_new(params->slope);
 
88
 
 
89
    if (params->aspect)
 
90
        cf3 = Rast_open_fp_new(params->aspect);
 
91
 
 
92
    if (params->pcurv)
 
93
        cf4 = Rast_open_fp_new(params->pcurv);
 
94
 
 
95
    if (params->tcurv)
 
96
        cf5 = Rast_open_fp_new(params->tcurv);
 
97
 
 
98
    if (params->mcurv)
 
99
        cf6 = Rast_open_fp_new(params->mcurv);
120
100
 
121
101
    nrows = outhd->rows;
122
102
    if (nrows != params->nsizr) {
123
 
        fprintf(stderr, "first change your rows number(%d) to %d!\n",
124
 
                nrows, params->nsizr);
 
103
        G_warning(_("First change your rows number(%d) to %d"),
 
104
                  nrows, params->nsizr);
125
105
        return -1;
126
106
    }
127
107
 
128
108
    ncols = outhd->cols;
129
109
    if (ncols != params->nsizc) {
130
 
        fprintf(stderr, "first change your rows number(%d) to %d!\n",
131
 
                ncols, params->nsizc);
 
110
        G_warning(_("First change your columns number(%d) to %d"),
 
111
                  ncols, params->nsizr);
132
112
        return -1;
133
113
    }
134
114
 
135
115
    if (params->elev != NULL) {
136
 
        fseek(params->Tmp_fd_z, 0L, 0); /* seek to the beginning */
 
116
        G_fseek(params->Tmp_fd_z, 0L, 0);       /* seek to the beginning */
137
117
        for (i = 0; i < params->nsizr; i++) {
138
118
            /* seek to the right row */
139
 
            if (fseek(params->Tmp_fd_z, (long)
140
 
                      ((params->nsizr - 1 -
141
 
                        i) * params->nsizc * sizeof(FCELL)), 0) == -1) {
142
 
                fprintf(stderr, "cannot fseek to the right spot\n");
143
 
                return -1;
144
 
            }
 
119
            G_fseek(params->Tmp_fd_z, (off_t) (params->nsizr - 1 - i) *
 
120
                    params->nsizc * sizeof(FCELL), 0);
145
121
            fread(cell1, sizeof(FCELL), params->nsizc, params->Tmp_fd_z);
146
 
            if (G_put_f_raster_row(cf1, cell1) < 0) {
147
 
                fprintf(stderr, "cannot write file\n");
148
 
                return -1;
149
 
            }
 
122
            Rast_put_f_row(cf1, cell1);
150
123
        }
151
124
    }
152
125
 
153
126
    if (params->slope != NULL) {
154
 
        fseek(params->Tmp_fd_dx, 0L, 0);        /* seek to the beginning */
 
127
        G_fseek(params->Tmp_fd_dx, 0L, 0);      /* seek to the beginning */
155
128
        for (i = 0; i < params->nsizr; i++) {
156
129
            /* seek to the right row */
157
 
            if (fseek(params->Tmp_fd_dx, (long)
158
 
                      ((params->nsizr - 1 -
159
 
                        i) * params->nsizc * sizeof(FCELL)), 0) == -1) {
160
 
                fprintf(stderr, "cannot fseek to the right spot\n");
161
 
                return -1;
162
 
            }
 
130
            G_fseek(params->Tmp_fd_dx, (off_t) (params->nsizr - 1 - i) *
 
131
                    params->nsizc * sizeof(FCELL), 0);
163
132
            fread(cell1, sizeof(FCELL), params->nsizc, params->Tmp_fd_dx);
164
133
            /*
165
134
             * for (ii==0;ii<params->nsizc;ii++) { fprintf(stderr,"ii=%d ",ii);
166
135
             * fprintf(stderr,"%f ",cell1[ii]); }
167
136
             * fprintf(stderr,"params->nsizc=%d \n",params->nsizc);
168
137
             */
169
 
            if (G_put_f_raster_row(cf2, cell1) < 0) {
170
 
                fprintf(stderr, "cannot write file\n");
171
 
                return -1;
172
 
            }
 
138
            Rast_put_f_row(cf2, cell1);
173
139
        }
174
140
    }
175
141
 
176
142
    if (params->aspect != NULL) {
177
 
        fseek(params->Tmp_fd_dy, 0L, 0);        /* seek to the beginning */
 
143
        G_fseek(params->Tmp_fd_dy, 0L, 0);      /* seek to the beginning */
178
144
        for (i = 0; i < params->nsizr; i++) {
179
145
            /* seek to the right row */
180
 
            if (fseek(params->Tmp_fd_dy, (long)
181
 
                      ((params->nsizr - 1 -
182
 
                        i) * params->nsizc * sizeof(FCELL)), 0) == -1) {
183
 
                fprintf(stderr, "cannot fseek to the right spot\n");
184
 
                return -1;
185
 
            }
 
146
            G_fseek(params->Tmp_fd_dy, (off_t) (params->nsizr - 1 - i) *
 
147
                    params->nsizc * sizeof(FCELL), 0);
186
148
            fread(cell1, sizeof(FCELL), params->nsizc, params->Tmp_fd_dy);
187
 
            if (G_put_f_raster_row(cf3, cell1) < 0) {
188
 
                fprintf(stderr, "cannot write file\n");
189
 
                return -1;
190
 
            }
 
149
            Rast_put_f_row(cf3, cell1);
191
150
        }
192
151
    }
193
152
 
194
153
    if (params->pcurv != NULL) {
195
 
        fseek(params->Tmp_fd_xx, 0L, 0);        /* seek to the beginning */
 
154
        G_fseek(params->Tmp_fd_xx, 0L, 0);      /* seek to the beginning */
196
155
        for (i = 0; i < params->nsizr; i++) {
197
156
            /* seek to the right row */
198
 
            if (fseek(params->Tmp_fd_xx, (long)
199
 
                      ((params->nsizr - 1 -
200
 
                        i) * params->nsizc * sizeof(FCELL)), 0) == -1) {
201
 
                fprintf(stderr, "cannot fseek to the right spot\n");
202
 
                return -1;
203
 
            }
 
157
            G_fseek(params->Tmp_fd_xx, (off_t) (params->nsizr - 1 - i) *
 
158
                    params->nsizc * sizeof(FCELL), 0);
204
159
            fread(cell1, sizeof(FCELL), params->nsizc, params->Tmp_fd_xx);
205
 
            if (G_put_f_raster_row(cf4, cell1) < 0) {
206
 
                fprintf(stderr, "cannot write file\n");
207
 
                return -1;
208
 
            }
 
160
            Rast_put_f_row(cf4, cell1);
209
161
        }
210
162
    }
211
163
 
212
164
    if (params->tcurv != NULL) {
213
 
        fseek(params->Tmp_fd_yy, 0L, 0);        /* seek to the beginning */
 
165
        G_fseek(params->Tmp_fd_yy, 0L, 0);      /* seek to the beginning */
214
166
        for (i = 0; i < params->nsizr; i++) {
215
167
            /* seek to the right row */
216
 
            if (fseek(params->Tmp_fd_yy, (long)
217
 
                      ((params->nsizr - 1 -
218
 
                        i) * params->nsizc * sizeof(FCELL)), 0) == -1) {
219
 
                fprintf(stderr, "cannot fseek to the right spot\n");
220
 
                return -1;
221
 
            }
 
168
            G_fseek(params->Tmp_fd_yy, (off_t) (params->nsizr - 1 - i) *
 
169
                    params->nsizc * sizeof(FCELL), 0);
222
170
            fread(cell1, sizeof(FCELL), params->nsizc, params->Tmp_fd_yy);
223
 
            if (G_put_f_raster_row(cf5, cell1) < 0) {
224
 
                fprintf(stderr, "cannot write file\n");
225
 
                return -1;
226
 
            }
 
171
            Rast_put_f_row(cf5, cell1);
227
172
        }
228
173
    }
229
174
 
230
175
    if (params->mcurv != NULL) {
231
 
        fseek(params->Tmp_fd_xy, 0L, 0);        /* seek to the beginning */
 
176
        G_fseek(params->Tmp_fd_xy, 0L, 0);      /* seek to the beginning */
232
177
        for (i = 0; i < params->nsizr; i++) {
233
178
            /* seek to the right row */
234
 
            if (fseek(params->Tmp_fd_xy, (long)
235
 
                      ((params->nsizr - 1 -
236
 
                        i) * params->nsizc * sizeof(FCELL)), 0) == -1) {
237
 
                fprintf(stderr, "cannot fseek to the right spot\n");
238
 
                return -1;
239
 
            }
 
179
            G_fseek(params->Tmp_fd_xy, (off_t) (params->nsizr - 1 - i) *
 
180
                    params->nsizc * sizeof(FCELL), 0);
240
181
            fread(cell1, sizeof(FCELL), params->nsizc, params->Tmp_fd_xy);
241
 
            if (G_put_f_raster_row(cf6, cell1) < 0) {
242
 
                fprintf(stderr, "cannot write file\n");
243
 
                return -1;
244
 
            }
 
182
            Rast_put_f_row(cf6, cell1);
245
183
        }
246
184
    }
247
185
 
248
186
    if (cf1)
249
 
        G_close_cell(cf1);
 
187
        Rast_close(cf1);
250
188
    if (cf2)
251
 
        G_close_cell(cf2);
 
189
        Rast_close(cf2);
252
190
    if (cf3)
253
 
        G_close_cell(cf3);
 
191
        Rast_close(cf3);
254
192
    if (cf4)
255
 
        G_close_cell(cf4);
 
193
        Rast_close(cf4);
256
194
    if (cf5)
257
 
        G_close_cell(cf5);
 
195
        Rast_close(cf5);
258
196
    if (cf6)
259
 
        G_close_cell(cf6);
 
197
        Rast_close(cf6);
260
198
 
261
199
    /* write colormaps and history for output cell files */
262
200
    /* colortable for elevations */
264
202
 
265
203
    if (params->elev != NULL) {
266
204
        if (maps == NULL) {
267
 
            fprintf(stderr, "file [%s] not found\n", input);
 
205
            G_warning(_("Raster map <%s> not found"), input);
268
206
            return -1;
269
207
        }
270
 
        G_init_colors(&colors2);
 
208
        Rast_init_colors(&colors2);
271
209
        /*
272
 
         * G_mark_colors_as_fp(&colors2);
 
210
         * Rast_mark_colors_as_fp(&colors2);
273
211
         */
274
212
 
275
 
        if (G_read_colors(input, maps, &colors) >= 0) {
 
213
        if (Rast_read_colors(input, maps, &colors) >= 0) {
276
214
            if (colors.modular.rules) {
277
215
                rule = colors.modular.rules;
278
216
 
282
220
                for (; rule; rule = rule->prev) {
283
221
                    value1 = rule->low.value * params->zmult;
284
222
                    value2 = rule->high.value * params->zmult;
285
 
                    G_add_modular_d_raster_color_rule(&value1, rule->low.red,
 
223
                    Rast_add_modular_d_color_rule(&value1, rule->low.red,
286
224
                                                      rule->low.grn,
287
225
                                                      rule->low.blu, &value2,
288
226
                                                      rule->high.red,
301
239
                for (; rule; rule = rule->prev) {
302
240
                    value1 = rule->low.value * params->zmult;
303
241
                    value2 = rule->high.value * params->zmult;
304
 
                    G_add_d_raster_color_rule(&value1, rule->low.red,
 
242
                    Rast_add_d_color_rule(&value1, rule->low.red,
305
243
                                              rule->low.grn, rule->low.blu,
306
244
                                              &value2, rule->high.red,
307
245
                                              rule->high.grn, rule->high.blu,
312
250
            maps = NULL;
313
251
            maps = G_find_file("cell", params->elev, "");
314
252
            if (maps == NULL) {
315
 
                fprintf(stderr, "file [%s] not found\n", params->elev);
 
253
                G_warning(_("Raster map <%s> not found"), params->elev);
316
254
                return -1;
317
255
            }
318
256
 
319
 
            if (G_write_colors(params->elev, maps, &colors2) < 0) {
320
 
                fprintf(stderr, "Cannot write color table\n");
321
 
                return -1;
322
 
            }
323
 
            G_quantize_fp_map_range(params->elev, mapset,
 
257
            Rast_write_colors(params->elev, maps, &colors2);
 
258
            Rast_quantize_fp_map_range(params->elev, mapset,
324
259
                                    zminac - 0.5, zmaxac + 0.5,
325
260
                                    (CELL) (zminac - 0.5),
326
261
                                    (CELL) (zmaxac + 0.5));
327
262
        }
328
263
        else
329
 
            fprintf(stderr,
330
 
                    "No color table for input file -- will not create color table\n");
 
264
            G_warning(_("No color table for input raster map -- will not create color table"));
331
265
    }
332
266
 
333
267
    /* colortable for slopes */
334
268
    if (cond1 & (!params->deriv)) {
335
 
        G_init_colors(&colors);
336
 
        G_add_color_rule(0, 255, 255, 255, 2, 255, 255, 0, &colors);
337
 
        G_add_color_rule(2, 255, 255, 0, 5, 0, 255, 0, &colors);
338
 
        G_add_color_rule(5, 0, 255, 0, 10, 0, 255, 255, &colors);
339
 
        G_add_color_rule(10, 0, 255, 255, 15, 0, 0, 255, &colors);
340
 
        G_add_color_rule(15, 0, 0, 255, 30, 255, 0, 255, &colors);
341
 
        G_add_color_rule(30, 255, 0, 255, 50, 255, 0, 0, &colors);
342
 
        G_add_color_rule(50, 255, 0, 0, 90, 0, 0, 0, &colors);
 
269
        Rast_init_colors(&colors);
 
270
        val1 = 0;
 
271
        val2 = 2;
 
272
        Rast_add_c_color_rule(&val1, 255, 255, 255, &val2, 255, 255, 0, &colors);
 
273
        val1 = 2;
 
274
        val2 = 5;
 
275
        Rast_add_c_color_rule(&val1, 255, 255, 0, &val2, 0, 255, 0, &colors);
 
276
        val1 = 5;
 
277
        val2 = 10;
 
278
        Rast_add_c_color_rule(&val1, 0, 255, 0, &val2, 0, 255, 255, &colors);
 
279
        val1 = 10;
 
280
        val2 = 15;
 
281
        Rast_add_c_color_rule(&val1, 0, 255, 255, &val2, 0, 0, 255, &colors);
 
282
        val1 = 15;
 
283
        val2 = 30;
 
284
        Rast_add_c_color_rule(&val1, 0, 0, 255, &val2, 255, 0, 255, &colors);
 
285
        val1 = 30;
 
286
        val2 = 50;
 
287
        Rast_add_c_color_rule(&val1, 255, 0, 255, &val2, 255, 0, 0, &colors);
 
288
        val1 = 50;
 
289
        val2 = 90;
 
290
        Rast_add_c_color_rule(&val1, 255, 0, 0, &val2, 0, 0, 0, &colors);
343
291
 
344
292
        if (params->slope != NULL) {
345
293
            maps = NULL;
346
294
            maps = G_find_file("cell", params->slope, "");
347
295
            if (maps == NULL) {
348
 
                fprintf(stderr, "file [%s] not found\n", params->slope);
 
296
                G_warning(_("Raster map <%s> not found"), params->slope);
349
297
                return -1;
350
298
            }
351
 
            G_write_colors(params->slope, maps, &colors);
352
 
            G_quantize_fp_map_range(params->slope, mapset, 0., 90., 0, 90);
353
 
 
354
 
            type = "raster";
355
 
            G_short_history(params->slope, type, &hist1);
356
 
            if (params->elev != NULL)
357
 
                sprintf(hist1.edhist[0], "The elevation map is %s",
358
 
                        params->elev);
359
 
 
360
 
            sprintf(hist1.datsrc_1, "raster map %s", input);
361
 
            hist1.edlinecnt = 1;
362
 
 
363
 
            G_write_history(params->slope, &hist1);
 
299
            Rast_write_colors(params->slope, maps, &colors);
 
300
            Rast_quantize_fp_map_range(params->slope, mapset, 0., 90., 0, 90);
 
301
 
 
302
            do_history(params->slope, input, params);
364
303
        }
365
304
 
366
305
        /* colortable for aspect */
367
 
        G_init_colors(&colors);
368
 
        G_add_color_rule(0, 255, 255, 255, 0, 255, 255, 255, &colors);
369
 
        G_add_color_rule(1, 255, 255, 0, 90, 0, 255, 0, &colors);
370
 
        G_add_color_rule(90, 0, 255, 0, 180, 0, 255, 255, &colors);
371
 
        G_add_color_rule(180, 0, 255, 255, 270, 255, 0, 0, &colors);
372
 
        G_add_color_rule(270, 255, 0, 0, 360, 255, 255, 0, &colors);
 
306
        Rast_init_colors(&colors);
 
307
        val1 = 0;
 
308
        val2 = 0;
 
309
        Rast_add_c_color_rule(&val1, 255, 255, 255, &val2, 255, 255, 255, &colors);
 
310
        val1 = 1;
 
311
        val2 = 90;
 
312
        Rast_add_c_color_rule(&val1, 255, 255, 0, &val2, 0, 255, 0, &colors);
 
313
        val1 = 90;
 
314
        val2 = 180;
 
315
        Rast_add_c_color_rule(&val1, 0, 255, 0, &val2, 0, 255, 255, &colors);
 
316
        val1 = 180;
 
317
        val2 = 270;
 
318
        Rast_add_c_color_rule(&val1, 0, 255, 255, &val2, 255, 0, 0, &colors);
 
319
        val1 = 270;
 
320
        val2 = 360;
 
321
        Rast_add_c_color_rule(&val1, 255, 0, 0, &val2, 255, 255, 0, &colors);
373
322
 
374
323
        if (params->aspect != NULL) {
375
324
            maps = NULL;
376
325
            maps = G_find_file("cell", params->aspect, "");
377
326
            if (maps == NULL) {
378
 
                fprintf(stderr, "file [%s] not found\n", params->aspect);
 
327
                G_warning(_("Raster map <%s> not found"), params->aspect);
379
328
                return -1;
380
329
            }
381
 
            G_write_colors(params->aspect, maps, &colors);
382
 
            G_quantize_fp_map_range(params->aspect, mapset, 0., 360., 0, 360);
383
 
 
384
 
            type = "raster";
385
 
            G_short_history(params->aspect, type, &hist2);
386
 
            if (params->elev != NULL)
387
 
                sprintf(hist2.edhist[0], "The elevation map is %s",
388
 
                        params->elev);
389
 
 
390
 
            sprintf(hist2.datsrc_1, "raster map %s", input);
391
 
            hist2.edlinecnt = 1;
392
 
 
393
 
            G_write_history(params->aspect, &hist2);
 
330
            Rast_write_colors(params->aspect, maps, &colors);
 
331
            Rast_quantize_fp_map_range(params->aspect, mapset, 0., 360., 0, 360);
 
332
 
 
333
            do_history(params->aspect, input, params);
394
334
        }
395
335
 
396
336
        /* colortable for curvatures */
397
337
        if (cond2) {
398
 
            G_init_colors(&colors);
 
338
            Rast_init_colors(&colors);
399
339
 
400
340
            dat1 = (FCELL) amin1(c1min, c2min);
401
341
            dat2 = (FCELL) - 0.01;
402
342
 
403
 
            G_add_f_raster_color_rule(&dat1, 50, 0, 155,
 
343
            Rast_add_f_color_rule(&dat1, 50, 0, 155,
404
344
                                      &dat2, 0, 0, 255, &colors);
405
345
            dat1 = dat2;
406
346
            dat2 = (FCELL) - 0.001;
407
 
            G_add_f_raster_color_rule(&dat1, 0, 0, 255,
 
347
            Rast_add_f_color_rule(&dat1, 0, 0, 255,
408
348
                                      &dat2, 0, 127, 255, &colors);
409
349
            dat1 = dat2;
410
350
            dat2 = (FCELL) - 0.00001;
411
 
            G_add_f_raster_color_rule(&dat1, 0, 127, 255,
 
351
            Rast_add_f_color_rule(&dat1, 0, 127, 255,
412
352
                                      &dat2, 0, 255, 255, &colors);
413
353
            dat1 = dat2;
414
354
            dat2 = (FCELL) 0.00;
415
 
            G_add_f_raster_color_rule(&dat1, 0, 255, 255,
 
355
            Rast_add_f_color_rule(&dat1, 0, 255, 255,
416
356
                                      &dat2, 200, 255, 200, &colors);
417
357
            dat1 = dat2;
418
358
            dat2 = (FCELL) 0.00001;
419
 
            G_add_f_raster_color_rule(&dat1, 200, 255, 200,
 
359
            Rast_add_f_color_rule(&dat1, 200, 255, 200,
420
360
                                      &dat2, 255, 255, 0, &colors);
421
361
            dat1 = dat2;
422
362
            dat2 = (FCELL) 0.001;
423
 
            G_add_f_raster_color_rule(&dat1, 255, 255, 0,
 
363
            Rast_add_f_color_rule(&dat1, 255, 255, 0,
424
364
                                      &dat2, 255, 127, 0, &colors);
425
365
            dat1 = dat2;
426
366
            dat2 = (FCELL) 0.01;
427
 
            G_add_f_raster_color_rule(&dat1, 255, 127, 0,
 
367
            Rast_add_f_color_rule(&dat1, 255, 127, 0,
428
368
                                      &dat2, 255, 0, 0, &colors);
429
369
            dat1 = dat2;
430
370
            dat2 = (FCELL) amax1(c1max, c2max);
431
 
            G_add_f_raster_color_rule(&dat1, 255, 0, 0,
 
371
            Rast_add_f_color_rule(&dat1, 255, 0, 0,
432
372
                                      &dat2, 155, 0, 20, &colors);
433
373
            maps = NULL;
434
374
            if (params->pcurv != NULL) {
435
375
                maps = G_find_file("cell", params->pcurv, "");
436
376
                if (maps == NULL) {
437
 
                    fprintf(stderr, "file [%s] not found\n", params->pcurv);
 
377
                    G_warning(_("Raster map <%s> not found"), params->pcurv);
438
378
                    return -1;
439
379
                }
440
 
                G_write_colors(params->pcurv, maps, &colors);
 
380
                Rast_write_colors(params->pcurv, maps, &colors);
441
381
 
442
382
                fprintf(stderr, "color map written\n");
443
383
 
444
 
                G_quantize_fp_map_range(params->pcurv, mapset,
 
384
                Rast_quantize_fp_map_range(params->pcurv, mapset,
445
385
                                        dat1, dat2,
446
386
                                        (CELL) (dat1 * MULT),
447
387
                                        (CELL) (dat2 * MULT));
448
 
                type = "raster";
449
 
                G_short_history(params->pcurv, type, &hist3);
450
 
                if (params->elev != NULL)
451
 
                    sprintf(hist3.edhist[0], "The elevation map is %s",
452
 
                            params->elev);
453
 
 
454
 
                sprintf(hist3.datsrc_1, "raster map %s", input);
455
 
                hist3.edlinecnt = 1;
456
 
 
457
 
                G_write_history(params->pcurv, &hist3);
 
388
                do_history(params->pcurv, input, params);
458
389
            }
459
390
 
460
391
            if (params->tcurv != NULL) {
461
392
                maps = NULL;
462
393
                maps = G_find_file("cell", params->tcurv, "");
463
394
                if (maps == NULL) {
464
 
                    fprintf(stderr, "file [%s] not found\n", params->tcurv);
 
395
                    G_warning(_("Raster map <%s> not found"), params->tcurv);
465
396
                    return -1;
466
397
                }
467
 
                G_write_colors(params->tcurv, maps, &colors);
468
 
                G_quantize_fp_map_range(params->tcurv, mapset,
 
398
                Rast_write_colors(params->tcurv, maps, &colors);
 
399
                Rast_quantize_fp_map_range(params->tcurv, mapset,
469
400
                                        dat1, dat2, (CELL) (dat1 * MULT),
470
401
                                        (CELL) (dat2 * MULT));
471
402
 
472
 
                type = "raster";
473
 
                G_short_history(params->tcurv, type, &hist4);
474
 
                if (params->elev != NULL)
475
 
                    sprintf(hist4.edhist[0], "The elevation map is %s",
476
 
                            params->elev);
477
 
 
478
 
                sprintf(hist4.datsrc_1, "raster map %s", input);
479
 
                hist4.edlinecnt = 1;
480
 
 
481
 
                G_write_history(params->tcurv, &hist4);
 
403
                do_history(params->tcurv, input, params);
482
404
            }
483
405
 
484
406
            if (params->mcurv != NULL) {
485
407
                maps = NULL;
486
408
                maps = G_find_file("cell", params->mcurv, "");
487
409
                if (maps == NULL) {
488
 
                    fprintf(stderr, "file [%s] not found\n", params->mcurv);
 
410
                    G_warning(_("Raster map <%s> not found"), params->mcurv);
489
411
                    return -1;
490
412
                }
491
 
                G_write_colors(params->mcurv, maps, &colors);
492
 
                G_quantize_fp_map_range(params->mcurv, mapset,
 
413
                Rast_write_colors(params->mcurv, maps, &colors);
 
414
                Rast_quantize_fp_map_range(params->mcurv, mapset,
493
415
                                        dat1, dat2,
494
416
                                        (CELL) (dat1 * MULT),
495
417
                                        (CELL) (dat2 * MULT));
496
418
 
497
 
                type = "raster";
498
 
                G_short_history(params->mcurv, type, &hist5);
499
 
                if (params->elev != NULL)
500
 
                    sprintf(hist5.edhist[0], "The elevation map is %s",
501
 
                            params->elev);
502
 
 
503
 
                sprintf(hist5.datsrc_1, "raster map %s", input);
504
 
                hist5.edlinecnt = 1;
505
 
 
506
 
                G_write_history(params->mcurv, &hist5);
 
419
                do_history(params->mcurv, input, params);
507
420
            }
508
421
        }
509
422
    }
510
423
 
511
424
    if (params->elev != NULL) {
512
 
        maps = G_find_file("cell", params->elev, "");
513
 
        if (maps == NULL) {
514
 
            fprintf(stderr, "file [%s] not found \n", params->elev);
 
425
        if (!G_find_file2("cell", params->elev, "")) {
 
426
            G_warning(_("Raster map <%s> not found"), params->elev);
515
427
            return -1;
516
428
        }
517
 
        G_short_history(params->elev, "raster", &hist);
 
429
 
 
430
        Rast_short_history(params->elev, "raster", &hist);
518
431
 
519
432
        if (smooth != NULL)
520
 
            sprintf(hist.edhist[0], "tension=%f, smoothing=%s",
521
 
                    params->fi * 1000. / (*dnorm), smooth);
 
433
            Rast_append_format_history(
 
434
                &hist, "tension=%f, smoothing=%s",
 
435
                params->fi * 1000. / (*dnorm), smooth);
522
436
        else
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);
530
 
 
531
 
        sprintf(hist.datsrc_1, "raster map %s", input);
532
 
 
533
 
        hist.edlinecnt = 5;
534
 
 
535
 
        G_write_history(params->elev, &hist);
536
 
    }
537
 
 
538
 
    /* change region to initial region */
539
 
    fprintf(stderr, "Changing the region back to initial...\n");
540
 
    if (G_set_window(winhd) < 0) {
541
 
        fprintf(stderr, "Cannot set region to back to initial region!\n");
542
 
        return -1;
543
 
    }
 
437
            Rast_append_format_history(
 
438
                &hist, "tension=%f", params->fi * 1000. / (*dnorm));
 
439
 
 
440
        Rast_append_format_history(
 
441
            &hist, "dnorm=%f, zmult=%f", *dnorm, params->zmult);
 
442
        Rast_append_format_history(
 
443
            &hist, "KMAX=%d, KMIN=%d, errtotal=%f", params->kmax,
 
444
            params->kmin, sqrt(ertot / n_points));
 
445
        Rast_append_format_history(
 
446
            &hist, "zmin_data=%f, zmax_data=%f", zmin, zmax);
 
447
        Rast_append_format_history(
 
448
            &hist, "zmin_int=%f, zmax_int=%f", zminac, zmaxac);
 
449
 
 
450
        Rast_format_history(&hist, HIST_DATSRC_1, "raster map %s", input);
 
451
 
 
452
        Rast_write_history(params->elev, &hist);
 
453
 
 
454
        Rast_free_history(&hist);
 
455
    }
 
456
 
 
457
/* change region to initial region */
 
458
    G_verbose_message(_("Changing the region back to initial..."));
 
459
    Rast_set_output_window(winhd);
544
460
 
545
461
    return 1;
546
462
}