File: cat.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 (95 lines) | stat: -rw-r--r-- 2,284 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
/* ***************************************************************
 * *
 * * MODULE:       v.digit
 * * 
 * * AUTHOR(S):    Radim Blazek
 * *               
 * * PURPOSE:      Edit vector
 * *              
 * * COPYRIGHT:    (C) 2001 by the GRASS Development Team
 * *
 * *               This program is free software under the 
 * *               GNU General Public License (>=v2). 
 * *               Read the file COPYING that comes with GRASS
 * *               for details.
 * *
 * **************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gis.h"
#include "colors.h"
#include "raster.h"
#include "display.h"
#include "global.h"
#include "proto.h"


/* Init cats */
void
cat_init ( void )
{
    int i, line, nlines;
    struct line_cats *Cats;

    G_debug (2, "cat_init()" );
    Cats = Vect_new_cats_struct (); 
    
    /* Max cats */
    nMaxFieldCat = 0;
    aMaxFieldCat = 10; /* allocated space */
    MaxFieldCat = (void *) G_malloc ( (aMaxFieldCat) * sizeof(int) * 2 ); 

    /* Read the map and set maximum categories */
    nlines = Vect_get_num_lines ( &Map );
    for ( line = 1; line <= nlines; line++ ) {
	Vect_read_line ( &Map, NULL, Cats, line ); 
	for ( i = 0; i < Cats->n_cats; i++ ) {
	    if ( (cat_max_get(Cats->field[i])) < Cats->cat[i] ) {
		cat_max_set(Cats->field[i],Cats->cat[i]);
	    }
	}
    }
}

/* get maximum cat for field */
int
cat_max_get ( int field )
{
    int i;
    
    G_debug (2, "cat_max_get() field = %d", field );

    for ( i = 0; i < nMaxFieldCat; i++ ) {
	if ( MaxFieldCat[i][0] == field ) {
	    return (MaxFieldCat[i][1]);
	}
    }

    return 0;
}
    
/* set maximum cat for field */
void
cat_max_set ( int field, int cat)
{
    int i;
    
    G_debug (2, "cat_max_set() field = %d cat = %d", field, cat );

    for ( i = 0; i < nMaxFieldCat; i++ ) {
	if ( MaxFieldCat[i][0] == field ) {
	    MaxFieldCat[i][1] = cat;
	    return;
	}
    }
    /* Field not found -> add new */
    if ( nMaxFieldCat == aMaxFieldCat ) {
        aMaxFieldCat += 10;
        MaxFieldCat = (void *) G_realloc ( MaxFieldCat, (aMaxFieldCat) * sizeof(int) * 2 );
    }
    MaxFieldCat[nMaxFieldCat][0] = field;
    MaxFieldCat[nMaxFieldCat][1] = cat;
    nMaxFieldCat++;
}