2
#include <grass/glocale.h>
4
#include "local_proto.h"
6
FILTER *get_filter(char *name, int *nfilters, char *title)
22
count = *nfilters = 0;
25
fd = fopen(name, "r");
27
G_fatal_error(_("Cannot open filter file '%s'"), name);
30
while (fgets(buf, sizeof buf, fd)) {
32
if (*buf == '#' || *buf == 0)
35
if (sscanf(buf, "%s %[^\n]", label, temp) == 2) {
37
if (strcmp(label, "TITLE") == 0) {
45
if (sscanf(buf, "MATRIX %d", &n) == 1) {
47
G_fatal_error(_("Illegal filter matrix size specified"));
50
G_fatal_error(_("Even filter matrix size specified"));
54
filter = (FILTER *) G_realloc(filter, count * sizeof(FILTER));
55
f = &filter[count - 1];
65
f->matrix = (DCELL **) G_malloc(n * sizeof(DCELL *));
66
for (row = 0; row < n; row++)
67
f->matrix[row] = (DCELL *) G_malloc(n * sizeof(DCELL));
69
for (row = 0; row < n; row++)
70
for (col = 0; col < n; col++)
71
if (fscanf(fd, "%lf", &f->matrix[row][col]) != 1) {
72
G_fatal_error(_("Illegal filter matrix"));
76
if (sscanf(buf, "DIVISOR %lf", &div) == 1)
77
if (sscanf(buf, "%s", label) == 1 &&
78
strcmp(label, "DIVISOR") == 0) {
80
G_fatal_error(_("Filter file format error"));
83
G_fatal_error(_("Duplicate filter divisor specified"));
86
if (sscanf(buf, "DIVISOR %lf", &div) == 1) {
89
f->dmatrix = f->matrix;
93
f->dmatrix = (DCELL **) G_malloc(f->size * sizeof(DCELL *));
94
for (row = 0; row < f->size; row++)
96
(DCELL *) G_malloc(f->size * sizeof(DCELL));
98
for (row = 0; row < f->size; row++)
99
for (col = 0; col < f->size; col++)
100
if (fscanf(fd, "%lf", &f->dmatrix[row][col]) != 1) {
101
G_fatal_error(_("Illegal divisor matrix"));
105
if (sscanf(buf, "TYPE %s", temp) == 1) {
107
G_fatal_error(_("Filter file format error"));
110
G_fatal_error(_("Duplicate filter type specified"));
112
if (strcmp(temp, "P") == 0)
114
else if (strcmp(temp, "S") == 0)
115
f->type = SEQUENTIAL;
117
G_fatal_error(_("Illegal filter type specified"));
122
if (sscanf(buf, "START %s", temp) == 1) {
124
G_fatal_error(_("Filter file format error"));
127
G_fatal_error(_("Duplicate filter start specified"));
129
if (strcmp(temp, "UL") == 0)
131
/* disable any other starting corner until the rest of
132
* this program handles them properly
135
G_warning(_("Filter start %s ignored, using UL"), temp);
137
/* disable these others
138
else if (strcmp (temp, "UR") == 0)
140
else if (strcmp (temp, "LL") == 0)
142
else if (strcmp (temp, "LR") == 0)
146
ERROR ("illegal filter type specified");
153
/* other lines are ignored */
157
G_fatal_error(_("Illegal filter file format"));