1
/* ***************************************************************
5
* * AUTHOR(S): Radim Blazek
7
* * PURPOSE: Edit vector
9
* * COPYRIGHT: (C) 2001 by the GRASS Development Team
11
* * This program is free software under the
12
* * GNU General Public License (>=v2).
13
* * Read the file COPYING that comes with GRASS
16
* **************************************************************/
20
#include <grass/gis.h>
21
#include <grass/colors.h>
22
#include <grass/raster.h>
23
#include <grass/display.h>
32
struct line_cats *Cats;
34
G_debug(2, "cat_init()");
35
Cats = Vect_new_cats_struct();
39
aMaxFieldCat = 10; /* allocated space */
40
MaxFieldCat = (void *)G_malloc((aMaxFieldCat) * sizeof(int) * 2);
42
/* Read the map and set maximum categories */
43
nlines = Vect_get_num_lines(&Map);
44
for (line = 1; line <= nlines; line++) {
45
Vect_read_line(&Map, NULL, Cats, line);
46
for (i = 0; i < Cats->n_cats; i++) {
47
if ((cat_max_get(Cats->field[i])) < Cats->cat[i]) {
48
cat_max_set(Cats->field[i], Cats->cat[i]);
54
/* get maximum cat for field */
55
int cat_max_get(int field)
59
G_debug(2, "cat_max_get() field = %d", field);
61
for (i = 0; i < nMaxFieldCat; i++) {
62
if (MaxFieldCat[i][0] == field) {
63
return (MaxFieldCat[i][1]);
70
/* set maximum cat for field */
71
void cat_max_set(int field, int cat)
75
G_debug(2, "cat_max_set() field = %d cat = %d", field, cat);
77
for (i = 0; i < nMaxFieldCat; i++) {
78
if (MaxFieldCat[i][0] == field) {
79
MaxFieldCat[i][1] = cat;
83
/* Field not found -> add new */
84
if (nMaxFieldCat == aMaxFieldCat) {
87
(void *)G_realloc(MaxFieldCat, (aMaxFieldCat) * sizeof(int) * 2);
89
MaxFieldCat[nMaxFieldCat][0] = field;
90
MaxFieldCat[nMaxFieldCat][1] = cat;