00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdlib.h>
00022 #include <grass/Vect.h>
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 P_NODE *
00043 dig_alloc_node ( ){
00044 P_NODE *Node;
00045
00046 Node = (P_NODE *) malloc ( sizeof(P_NODE) );
00047 if (Node == NULL) return NULL;
00048
00049 Node->n_lines = 0;
00050 Node->alloc_lines = 0;
00051 Node->lines = NULL;
00052 Node->angles = NULL;
00053
00054 return (Node);
00055 }
00056
00057
00058
00059
00060
00061
00062
00063
00064 int
00065 dig_node_alloc_line ( P_NODE * node, int add) {
00066 int num;
00067 char *p;
00068
00069 G_debug (3, "dig_node_alloc_line(): add = %d", add);
00070
00071 num = node->n_lines + add;
00072
00073 p = realloc ( node->lines, num * sizeof(plus_t) );
00074 if ( p == NULL ) return -1;
00075 node->lines = (plus_t *) p;
00076
00077 p = realloc ( node->angles, num * sizeof(float) );
00078 if ( p == NULL ) return -1;
00079 node->angles = (float *) p;
00080
00081 node->alloc_lines = num;
00082 return (0);
00083 }
00084
00085
00086
00087
00088
00089
00090
00091
00092 int
00093 dig_alloc_nodes ( struct Plus_head *Plus, int add) {
00094 int size;
00095 char *p;
00096
00097 size = Plus->alloc_nodes + 1 + add;
00098 p = realloc ( Plus->Node, size * sizeof(P_NODE *) );
00099 if ( p == NULL ) return -1;
00100
00101 Plus->Node = (P_NODE **) p;
00102 Plus->alloc_nodes = size - 1;
00103
00104 return (0);
00105 }
00106
00107
00108 P_LINE *
00109 dig_alloc_line ( ){
00110 P_LINE *Line;
00111
00112 Line = (P_LINE *) malloc ( sizeof(P_LINE) );
00113 if (Line == NULL) return NULL;
00114
00115 return (Line);
00116 }
00117
00118
00119
00120
00121
00122
00123
00124 int
00125 dig_alloc_lines ( struct Plus_head *Plus, int add) {
00126 int size;
00127 char *p;
00128
00129 size = Plus->alloc_lines + 1 + add;
00130 p = realloc ( Plus->Line, size * sizeof(P_LINE *) );
00131 if ( p == NULL ) return -1;
00132
00133 Plus->Line = (P_LINE **) p;
00134 Plus->alloc_lines = size - 1;
00135
00136 return (0);
00137 }
00138
00139
00140
00141
00142
00143
00144
00145 int
00146 dig_alloc_areas ( struct Plus_head *Plus, int add) {
00147 int size;
00148 char *p;
00149
00150 size = Plus->alloc_areas + 1 + add;
00151 p = realloc ( Plus->Area, size * sizeof(P_AREA *) );
00152 if ( p == NULL ) return -1;
00153
00154 Plus->Area = (P_AREA **) p;
00155 Plus->alloc_areas = size - 1;
00156
00157 return (0);
00158 }
00159
00160
00161
00162
00163
00164
00165
00166 int
00167 dig_alloc_isles ( struct Plus_head *Plus, int add) {
00168 int size;
00169 char *p;
00170
00171 G_debug (3, "dig_alloc_isle():");
00172 size = Plus->alloc_isles + 1 + add;
00173 p = realloc ( Plus->Isle, size * sizeof(P_ISLE *) );
00174 if ( p == NULL ) return -1;
00175
00176 Plus->Isle = (P_ISLE **) p;
00177 Plus->alloc_isles = size - 1;
00178
00179 return (0);
00180 }
00181
00182
00183 P_AREA *
00184 dig_alloc_area (){
00185 P_AREA *Area;
00186
00187 Area = (P_AREA *) malloc ( sizeof(P_AREA) );
00188 if (Area == NULL) return NULL;
00189
00190 Area->n_lines = 0;
00191 Area->alloc_lines = 0;
00192 Area->lines = NULL;
00193
00194 Area->alloc_isles = 0;
00195 Area->n_isles = 0;
00196 Area->isles = NULL;
00197
00198 Area->centroid = 0;
00199
00200 return (Area);
00201 }
00202
00203
00204 P_ISLE *
00205 dig_alloc_isle ()
00206 {
00207 P_ISLE *Isle;
00208
00209 Isle = (P_ISLE *) malloc ( sizeof(P_ISLE) );
00210 if (Isle == NULL) return NULL;
00211
00212 Isle->n_lines = 0;
00213 Isle->alloc_lines = 0;
00214 Isle->lines = NULL;
00215
00216 Isle->area = 0;
00217
00218 return (Isle);
00219 }
00220
00221
00222
00223
00224
00225 int
00226 dig_alloc_points (
00227 struct line_pnts *points,
00228 int num)
00229 {
00230 int alloced;
00231 char *p;
00232
00233 alloced = points->alloc_points;
00234
00235 if (!(p =
00236 dig__alloc_space (num, &alloced, 50, (char *) points->x,
00237 sizeof (double))))
00238 {
00239 return (dig_out_of_memory ());
00240 }
00241 points->x = (double *) p;
00242
00243 alloced = points->alloc_points;
00244
00245 if (!(p =
00246 dig__alloc_space (num, &alloced, 50, (char *) points->y,
00247 sizeof (double))))
00248 {
00249 return (dig_out_of_memory ());
00250 }
00251 points->y = (double *) p;
00252
00253 alloced = points->alloc_points;
00254
00255 if (!(p =
00256 dig__alloc_space (num, &alloced, 50, (char *) points->z,
00257 sizeof (double))))
00258 {
00259 return (dig_out_of_memory ());
00260 }
00261 points->z = (double *) p;
00262
00263 points->alloc_points = alloced;
00264 return (0);
00265 }
00266
00267
00268
00269
00270
00271 int
00272 dig_alloc_cats (
00273 struct line_cats *cats,
00274 int num)
00275 {
00276 int alloced;
00277 char *p;
00278
00279
00280 alloced = cats->alloc_cats;
00281 if (!(p =
00282 dig__alloc_space (num, &alloced, 1, (int *) cats->field,
00283 sizeof (int))))
00284 {
00285 return (dig_out_of_memory ());
00286 }
00287 cats->field = (int *) p;
00288
00289 alloced = cats->alloc_cats;
00290 if (!(p =
00291 dig__alloc_space (num, &alloced, 1, (int *) cats->cat,
00292 sizeof (int))))
00293 {
00294 return (dig_out_of_memory ());
00295 }
00296 cats->cat = (int *) p;
00297
00298 cats->alloc_cats = alloced;
00299 return (0);
00300 }
00301
00302
00303
00304
00305
00306
00307 int
00308 dig_area_alloc_line ( P_AREA * area, int add) {
00309 int num;
00310 char *p;
00311
00312 num = area->alloc_lines + add;
00313
00314 p = realloc ( area->lines, num * sizeof(plus_t) );
00315 if ( p == NULL ) return -1;
00316 area->lines = (plus_t *) p;
00317
00318 area->alloc_lines = num;
00319
00320 return (0);
00321 }
00322
00323
00324
00325
00326
00327
00328 int
00329 dig_area_alloc_isle ( P_AREA * area, int add) {
00330 int num;
00331 char *p;
00332
00333 G_debug (5, "dig_area_alloc_isle(): add = %d", add );
00334 num = area->alloc_isles + add;
00335
00336 p = realloc ( area->isles, num * sizeof(plus_t) );
00337 if ( p == NULL ) return -1;
00338 area->isles = (plus_t *) p;
00339
00340 area->alloc_isles = num;
00341 return (0);
00342 }
00343
00344
00345
00346
00347
00348
00349
00350 int
00351 dig_isle_alloc_line (
00352 P_ISLE * isle,
00353 int add)
00354 {
00355 int num;
00356 char *p;
00357
00358 G_debug (3, "dig_isle_alloc_line():");
00359 num = isle->alloc_lines + add;
00360
00361 p = realloc ( isle->lines, num * sizeof(plus_t) );
00362 if ( p == NULL ) return -1;
00363 isle->lines = (plus_t *) p;
00364
00365 isle->alloc_lines = num;
00366
00367 return (0);
00368 }
00369
00370
00371
00372
00373 int
00374 dig_out_of_memory ()
00375 {
00376 fprintf (stderr, "OUT OF MEMORY!\n");
00377 return (-1);
00378 }
00379