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;
}
|