GRASS Programmer's Manual
6.4.2(2012)
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
imagery/alloc.c
Go to the documentation of this file.
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <grass/imagery.h>
4
5
6
void
*
I_malloc
(
size_t
n)
7
{
8
void
*
b
;
9
10
b = G_malloc(n);
11
12
return
b
;
13
}
14
15
16
void
*
I_realloc
(
void
*
b
,
size_t
n)
17
{
18
b = G_realloc(b, n);
19
20
return
b
;
21
}
22
23
24
int
I_free
(
void
*
b
)
25
{
26
if
((
char
*)b !=
NULL
)
27
G_free
(b);
28
29
return
0;
30
}
31
32
33
double
**
I_alloc_double2
(
int
a,
int
b
)
34
{
35
double
**x;
36
int
i;
37
38
x = (
double
**)
I_malloc
((a + 1) *
sizeof
(
double
*));
39
40
for
(i = 0; i < a; i++) {
41
int
n;
42
43
x[i] = (
double
*)
I_malloc
(b *
sizeof
(
double
));
44
45
for
(n = 0; n <
b
; n++)
46
x[i][n] = 0;
47
}
48
x[a] =
NULL
;
49
50
return
x;
51
}
52
53
54
int
*
I_alloc_int
(
int
a)
55
{
56
int
*x;
57
int
i;
58
59
x = (
int
*)
I_malloc
(a *
sizeof
(
int
));
60
61
for
(i = 0; i < a; i++)
62
x[i] = 0;
63
64
return
x;
65
}
66
67
int
**
I_alloc_int2
(
int
a,
int
b
)
68
{
69
int
**x;
70
int
i, n;
71
72
x = (
int
**)
I_malloc
((a + 1) *
sizeof
(
int
*));
73
74
for
(i = 0; i < a; i++) {
75
x[i] = (
int
*)
I_malloc
(b *
sizeof
(
int
));
76
77
for
(n = 0; n <
b
; n++)
78
x[i][n] = 0;
79
}
80
x[a] =
NULL
;
81
82
return
x;
83
}
84
85
86
int
I_free_int2
(
int
**x)
87
{
88
int
i;
89
90
if
(x !=
NULL
) {
91
for
(i = 0; x[i] !=
NULL
; i++)
92
G_free
(x[i]);
93
G_free
(x);
94
}
95
96
return
0;
97
}
98
99
100
int
I_free_double2
(
double
**x)
101
{
102
int
i;
103
104
if
(x !=
NULL
) {
105
for
(i = 0; x[i] !=
NULL
; i++)
106
G_free
(x[i]);
107
G_free
(x);
108
}
109
110
return
0;
111
}
112
113
114
double
***
I_alloc_double3
(
int
a,
int
b
,
int
c)
115
{
116
double
***x;
117
int
i, n;
118
119
x = (
double
***)G_malloc((a + 1) *
sizeof
(
double
**));
120
121
for
(i = 0; i < a; i++) {
122
x[i] =
I_alloc_double2
(b, c);
123
if
(x[i] ==
NULL
) {
124
for
(n = 0; n < i; n++)
125
G_free
(x[n]);
126
G_free
(x);
127
128
return
(
double
***)
NULL
;
129
}
130
}
131
x[a] =
NULL
;
132
133
return
x;
134
}
135
136
137
int
I_free_double3
(
double
***x)
138
{
139
int
i;
140
141
if
(x !=
NULL
) {
142
for
(i = 0; x[i] !=
NULL
; i++)
143
I_free_double2
(x[i]);
144
G_free
(x);
145
}
146
147
return
0;
148
}
lib
imagery
alloc.c
Generated on Wed Jun 6 2012 14:04:18 for GRASS Programmer's Manual by
1.8.1