File: exec.c

package info (click to toggle)
grass 8.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 277,040 kB
  • sloc: ansic: 460,798; python: 227,732; cpp: 42,026; sh: 11,262; makefile: 7,007; xml: 3,637; sql: 968; lex: 520; javascript: 484; yacc: 450; asm: 387; perl: 157; sed: 25; objc: 6; ruby: 4
file content (89 lines) | stat: -rw-r--r-- 2,339 bytes parent folder | download | duplicates (2)
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
/* CMD mode from Bob Covill 2001
 * exec.c --
 *
 * Loop through all files to be rectified and do the retification.
 * Handles things like support files.
 *
 * small fixes: MN
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#include "global.h"

int exec_rectify(struct Image_Group *group, int *ref_list, char *extension,
                 char *interp_method, int order)
{
    char *name;
    char *mapset;
    char *result;
    char *type = "raster";
    int n;
    struct Colors colr;
    struct Categories cats;
    struct History hist;
    int colr_ok, cats_ok;
    time_t start_time, rectify_time;

    Rast_set_output_window(&target_window);
    G_message("-----------------------------------------------");

    /* rectify each file */
    for (n = 0; n < group->ref.nfiles; n++) {
        if (!ref_list[n])
            continue;

        name = group->ref.file[n].name;
        mapset = group->ref.file[n].mapset;

        /* generate out name, add extension to output */
        result =
            G_malloc(strlen(group->ref.file[n].name) + strlen(extension) + 1);
        strcpy(result, group->ref.file[n].name);
        strcat(result, extension);

        select_current_env();

        cats_ok = Rast_read_cats(name, mapset, &cats) >= 0;
        colr_ok = Rast_read_colors(name, mapset, &colr) > 0;

        /* Initialize History */
        if (Rast_read_history(name, mapset, &hist) < 0)
            Rast_short_history(result, type, &hist);

        time(&start_time);

        if (rectify(group, name, mapset, result, order, interp_method)) {
            select_target_env();

            if (cats_ok) {
                Rast_write_cats(result, &cats);
                Rast_free_cats(&cats);
            }
            if (colr_ok) {
                Rast_write_colors(result, G_mapset(), &colr);
                Rast_free_colors(&colr);
            }
            /* Write out History */
            Rast_command_history(&hist);
            Rast_write_history(result, &hist);

            select_current_env();
            time(&rectify_time);
            report(rectify_time - start_time, 1);
        }
        else
            report(0, 0);

        G_free(result);
    }

    return 0;
}