File: exec.c

package info (click to toggle)
grass 6.0.2-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 40,044 kB
  • ctags: 31,303
  • sloc: ansic: 321,125; tcl: 25,676; sh: 11,176; cpp: 10,098; makefile: 5,025; fortran: 1,846; yacc: 493; lex: 462; perl: 133; sed: 1
file content (136 lines) | stat: -rw-r--r-- 3,423 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* CMD mode from Bob Covill 2001 
 *
 * small fixes: MN
 *
 * Bug left: extension overwrites input name 1/2002
 */

#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 "global.h"

int exec_rectify (int order, char *extension)
/* ADDED WITH CRS MODIFICATIONS */
{
    char *name;
    char *mapset;
    char *result;
    char *type;
    int i,n;
    struct Colors colr;
    struct Categories cats;
    struct History hist;
    int colr_ok, cats_ok;
    long start_time, rectify_time, compress_time;
    char *mailfile;

/* allocate the output cell matrix */
    cell_buf = (void **) G_calloc (NROWS, sizeof(void *));
    n = NCOLS * G_raster_size(map_type);
    for (i=0; i < NROWS; i++)
    {
	cell_buf[i] = (void *) G_malloc (n);
	G_set_null_value(cell_buf[i], NCOLS, map_type);
    }


/* go into background */
    fprintf (stderr, "\nYou will receive mail when %s is complete\n",
	G_program_name());
    if (G_fork()) exit(0);

/* note: all calls to G_tempfile() should happen after the fork */

/* create a mailfile */
    mailfile = G_tempfile();
    unlink (mailfile);
    close(creat(mailfile,0666));

/* open stderr to /dev/null so all GRASS error messages will be
 * mailed to the user
 */

    freopen ("/dev/null","w",stderr);
    freopen ("/dev/null","w",stdout);

/* rectify each file */
    for (n = 0; n < ref.nfiles; n++)
    {
	if ((i = ref_list[n]) < 0)
        {
	   /* continue; */
	name   = ref.file[n].name;
	mapset = ref.file[n].mapset;
	
	/* generate out name, add extension to output */
	result = G_malloc(strlen(ref.file[n].name) + strlen(extension) + 1);
	strcpy(result, ref.file[n].name);
	strcat(result, extension);
	fprintf(stderr, "Rectified input file %s will be saved as %s\n", name, result);

	select_current_env();

	G_suppress_warnings(1);
	cats_ok = G_read_cats (name, mapset, &cats) >= 0;
	colr_ok = G_read_colors (name, mapset, &colr) > 0;

	/* Initialze History */
        type = "raster";
        G_short_history(name, type, &hist);

	G_suppress_warnings(0);

	time (&start_time);

        if (rectify (name, mapset, result, order))
	{
	    select_target_env();
	    /***
	     * This clobbers (with wrong values) head
	     * written by gislib.  99% sure it should
	     * be removed.  EGM 2002/01/03
            G_put_cellhd (result,&target_window);
	     */
	    if(cats_ok)
	    {
		G_write_cats (result, &cats);
		G_free_cats (&cats);
	    }
	    if(colr_ok)
	    {
		G_write_colors (result, G_mapset(), &colr) ;
		G_free_colors (&colr);
	    }

                /* Write out History Structure History */
                sprintf(hist.title, "%s", result);
                sprintf(hist.datsrc_1, "%s", name);
                sprintf(hist.edhist[0], "Created from: i.rectify");
		sprintf(hist.edhist[1], "Transformation order = %d", order);
                hist.edlinecnt = 2;
                G_write_history (result, &hist) ;

	    select_current_env();
	    time (&rectify_time);
	    if (compress(result))
		time (&compress_time);
	    else
		compress_time = rectify_time;
	    report (mailfile, name, mapset, result, rectify_time-start_time, compress_time-rectify_time, 1);
	}
	else
	    report (mailfile, name, mapset, result, (long)0, (long)0, 0);
    }
    }
    mail (mailfile);
    unlink (mailfile);
    G_done_msg ("Check your mail");

    return 0;
}