GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
plus_struct.c
Go to the documentation of this file.
1 /*
2  ****************************************************************************
3  *
4  * MODULE: Vector library
5  *
6  * AUTHOR(S): Dave Gerdes, CERL.
7  * Update to GRASS 5.7 Radim Blazek.
8  *
9  * PURPOSE: Lower level functions for reading/writing/manipulating vectors.
10  *
11  * COPYRIGHT: (C) 2001 by the GRASS Development Team
12  *
13  * This program is free software under the GNU General Public
14  * License (>=v2). Read the file COPYING that comes with GRASS
15  * for details.
16  *
17  *****************************************************************************/
18 #include <sys/types.h>
19 #include <string.h>
20 #include <grass/vector.h>
21 #include <grass/glocale.h>
22 #include <grass/version.h>
23 /*
24  * Routines for reading and writing Dig+ structures.
25  * return 0 on success, -1 on failure of whatever kind
26  * if you don't want it written out, then don't call these routines
27  * ie check for deleted status before calling a write routine
28  * in as much as it would be nice to hide that code in here,
29  * this is a library routine and we chose to make it dependent on
30  * as few external files as possible
31  */
32 
33 /* These routines assume ptr->alloc_lines is valid
34  * Make sure it is initialized before calling
35  */
36 
37 /*
38  * Internally, my default variables for lines/areas/nodes/isles are type
39  * plus_t which is typedefed as short. This limits the current version
40  * to no more than 32K lines, nodes etc. (excluding points)
41  * All in the name of future expansion, I have converted these values to
42  * longs in the dig_plus data file.
43  *
44  * NOTE: 3.10 changes plus_t to ints.
45  * This assumes that any reasonable machine will use 4 bytes to
46  * store an int. The mapdev code is not guaranteed to work if
47  * plus_t is changed to a type that is larger than an int.
48  */
49 
50 int dig_Rd_P_node(struct Plus_head *Plus, int n, struct gvfile * fp)
51 {
52  int cnt, n_edges;
53  struct P_node *ptr;
54 
55  G_debug(4, "dig_Rd_P_node()");
56 
57  if (0 >= dig__fread_port_P(&cnt, 1, fp))
58  return (-1);
59 
60  if (cnt == 0) { /* dead */
61  G_debug(4, " node is dead");
62  Plus->Node[n] = NULL;
63  return 0;
64  }
65 
66  ptr = dig_alloc_node();
67  ptr->n_lines = cnt;
68 
69  if (dig_node_alloc_line(ptr, ptr->n_lines) == -1)
70  return -1;
71 
72  if (ptr->n_lines) {
73  if (0 >= dig__fread_port_P(ptr->lines, ptr->n_lines, fp))
74  return (-1);
75  if (0 >= dig__fread_port_F(ptr->angles, ptr->n_lines, fp))
76  return (-1);
77  }
78 
79  if (Plus->with_z)
80  if (0 >= dig__fread_port_P(&n_edges, 1, fp)) /* reserved for edges */
81  return (-1);
82 
83  /* here will be edges */
84 
85  if (0 >= dig__fread_port_D(&(ptr->x), 1, fp))
86  return (-1);
87  if (0 >= dig__fread_port_D(&(ptr->y), 1, fp))
88  return (-1);
89 
90  if (Plus->with_z) {
91  if (0 >= dig__fread_port_D(&(ptr->z), 1, fp))
92  return (-1);
93  }
94  else
95  ptr->z = 0;
96 
97 
98  Plus->Node[n] = ptr;
99 
100  return (0);
101 }
102 
103 int dig_Wr_P_node(struct Plus_head *Plus, int n, struct gvfile * fp)
104 {
105  int i, n_edges = 0;
106  struct P_node *ptr;
107 
108  G_debug(4, "dig_Wr_P_node()");
109  ptr = Plus->Node[n];
110 
111  /* If NULL i.e. dead write just 0 instead of number of lines */
112  if (ptr == NULL) {
113  G_debug(4, " node is dead -> write 0 only");
114  i = 0;
115  if (0 >= dig__fwrite_port_P(&i, 1, fp))
116  return (-1);
117  return 0;
118  }
119 
120  if (0 >= dig__fwrite_port_P(&(ptr->n_lines), 1, fp))
121  return (-1);
122 
123  if (ptr->n_lines) {
124  if (0 >= dig__fwrite_port_P(ptr->lines, ptr->n_lines, fp))
125  return (-1);
126  if (0 >= dig__fwrite_port_F(ptr->angles, ptr->n_lines, fp))
127  return (-1);
128  }
129 
130  if (Plus->with_z)
131  if (0 >= dig__fwrite_port_P(&n_edges, 1, fp)) /* reserved for edges */
132  return (-1);
133 
134  /* here will be edges */
135 
136  if (0 >= dig__fwrite_port_D(&(ptr->x), 1, fp))
137  return (-1);
138  if (0 >= dig__fwrite_port_D(&(ptr->y), 1, fp))
139  return (-1);
140 
141  if (Plus->with_z)
142  if (0 >= dig__fwrite_port_D(&(ptr->z), 1, fp))
143  return (-1);
144 
145  return (0);
146 }
147 
148 int dig_Rd_P_line(struct Plus_head *Plus, int n, struct gvfile * fp)
149 {
150  int n_edges;
151  char tp;
152  struct P_line *ptr;
153 
154  G_debug(4, "dig_Rd_P_line()");
155 
156  if (0 >= dig__fread_port_C(&tp, 1, fp))
157  return (-1);
158 
159  if (tp == 0) { /* dead */
160  G_debug(4, " line is dead");
161  Plus->Line[n] = NULL;
162  return 0;
163  }
164 
165  ptr = dig_alloc_line();
166 
167  /* type */
168  ptr->type = dig_type_from_store(tp);
169  G_debug(5, " line type %d -> %d", tp, ptr->type);
170 
171  /* offset */
172  if (0 >= dig__fread_port_O(&(ptr->offset), 1, fp, Plus->off_t_size))
173  return (-1);
174 
175  if (ptr->type == GV_POINT) {
176  ptr->topo = NULL;
177  }
178  else {
179  ptr->topo = dig_alloc_topo(ptr->type);
180  }
181 
182  /* centroids */
183  if (ptr->type & GV_CENTROID) {
184  struct P_topo_c *topo = (struct P_topo_c *)ptr->topo;
185 
186  if (0 >= dig__fread_port_P(&(topo->area), 1, fp))
187  return -1;
188  }
189  /* lines */
190  else if (ptr->type & GV_LINE) {
191  struct P_topo_l *topo = (struct P_topo_l *)ptr->topo;
192 
193  if (0 >= dig__fread_port_P(&(topo->N1), 1, fp))
194  return -1;
195  if (0 >= dig__fread_port_P(&(topo->N2), 1, fp))
196  return -1;
197  }
198  /* boundaries */
199  else if (ptr->type & GV_BOUNDARY) {
200  struct P_topo_b *topo = (struct P_topo_b *)ptr->topo;
201 
202  if (0 >= dig__fread_port_P(&(topo->N1), 1, fp))
203  return -1;
204  if (0 >= dig__fread_port_P(&(topo->N2), 1, fp))
205  return -1;
206  if (0 >= dig__fread_port_P(&(topo->left), 1, fp))
207  return -1;
208  if (0 >= dig__fread_port_P(&(topo->right), 1, fp))
209  return -1;
210  }
211  /* faces */
212  else if ((ptr->type & GV_FACE) && Plus->with_z) { /* reserved for face edges */
213  struct P_topo_f *topo = (struct P_topo_f *)ptr->topo;
214 
215  if (0 >= dig__fread_port_I(&n_edges, 1, fp))
216  return -1;
217 
218  /* here will be list of edges */
219 
220  /* left / right volume */
221  if (0 >= dig__fread_port_P(&(topo->left), 1, fp))
222  return -1;
223  if (0 >= dig__fread_port_P(&(topo->left), 1, fp))
224  return -1;
225  }
226  /* kernels */
227  else if ((ptr->type & GV_KERNEL) && Plus->with_z) { /* reserved for kernel (volume number) */
228  struct P_topo_k *topo = (struct P_topo_k *)ptr->topo;
229 
230  if (0 >= dig__fread_port_P(&(topo->volume), 1, fp))
231  return -1;
232  }
233 
234  Plus->Line[n] = ptr;
235 
236  return (0);
237 }
238 
239 int dig_Wr_P_line(struct Plus_head *Plus, int n, struct gvfile * fp)
240 {
241  int n_edges = 0;
242  char ch;
243  struct P_line *ptr;
244 
245  G_debug(4, "dig_Wr_P_line() line = %d", n);
246 
247  ptr = Plus->Line[n];
248 
249  /* if NULL i.e. dead write just 0 instead of type */
250  if (ptr == NULL) {
251  G_debug(4, " line is dead -> write 0 only");
252  ch = 0;
253  if (0 >= dig__fwrite_port_C(&ch, 1, fp))
254  return (-1);
255  return 0;
256  }
257 
258  /* type */
259  ch = (char)dig_type_to_store(ptr->type);
260  G_debug(5, " line type %d -> %d", ptr->type, ch);
261  if (0 >= dig__fwrite_port_C(&ch, 1, fp))
262  return (-1);
263 
264  /* offset */
265  if (0 >= dig__fwrite_port_O(&(ptr->offset), 1, fp, Plus->off_t_size))
266  return (-1);
267 
268  if (!ptr->topo)
269  return (0);
270 
271  /* nothing else for points */
272 
273  /* centroids */
274  if (ptr->type & GV_CENTROID) {
275  struct P_topo_c *topo = (struct P_topo_c *)ptr->topo;
276 
277  if (0 >= dig__fwrite_port_P(&(topo->area), 1, fp))
278  return (-1);
279  }
280  /* lines */
281  else if (ptr->type & GV_LINE) {
282  struct P_topo_l *topo = (struct P_topo_l *)ptr->topo;
283 
284  if (0 >= dig__fwrite_port_P(&(topo->N1), 1, fp))
285  return (-1);
286  if (0 >= dig__fwrite_port_P(&(topo->N2), 1, fp))
287  return (-1);
288  }
289  /* boundaries */
290  else if (ptr->type & GV_BOUNDARY) {
291  struct P_topo_b *topo = (struct P_topo_b *)ptr->topo;
292 
293  if (0 >= dig__fwrite_port_P(&(topo->N1), 1, fp))
294  return (-1);
295  if (0 >= dig__fwrite_port_P(&(topo->N2), 1, fp))
296  return (-1);
297  if (0 >= dig__fwrite_port_P(&(topo->left), 1, fp))
298  return (-1);
299  if (0 >= dig__fwrite_port_P(&(topo->right), 1, fp))
300  return (-1);
301  }
302  /* faces */
303  else if ((ptr->type & GV_FACE) && Plus->with_z) { /* reserved for face */
304  struct P_topo_f *topo = (struct P_topo_f *)ptr->topo;
305 
306  if (0 >= dig__fwrite_port_I(&n_edges, 1, fp))
307  return (-1);
308 
309  /* here will be list of edges */
310 
311  /* left / right volume / hole */
312  if (0 >= dig__fwrite_port_P(&(topo->left), 1, fp))
313  return (-1);
314  if (0 >= dig__fwrite_port_P(&(topo->right), 1, fp))
315  return (-1);
316  }
317  /* kernels */
318  else if ((ptr->type & GV_KERNEL) && Plus->with_z) { /* reserved for kernel (volume number) */
319  struct P_topo_k *topo = (struct P_topo_k *)ptr->topo;
320 
321  /* volume */
322  if (0 >= dig__fwrite_port_P(&(topo->volume), 1, fp))
323  return (-1);
324  }
325 
326  return (0);
327 }
328 
329 int dig_Rd_P_area(struct Plus_head *Plus, int n, struct gvfile * fp)
330 {
331  int cnt;
332  struct P_area *ptr;
333 
334  G_debug(4, "dig_Rd_P_area(): n = %d", n);
335 
336  if (0 >= dig__fread_port_P(&cnt, 1, fp))
337  return (-1);
338 
339  if (cnt == 0) { /* dead */
340  Plus->Area[n] = NULL;
341  return 0;
342  }
343 
344  ptr = dig_alloc_area();
345 
346  /* boundaries */
347  ptr->n_lines = cnt;
348 
349  if (dig_area_alloc_line(ptr, ptr->n_lines) == -1)
350  return -1;
351 
352  if (ptr->n_lines)
353  if (0 >= dig__fread_port_P(ptr->lines, ptr->n_lines, fp))
354  return -1;
355 
356  /* isles */
357  if (0 >= dig__fread_port_P(&(ptr->n_isles), 1, fp))
358  return -1;
359 
360  if (dig_area_alloc_isle(ptr, ptr->n_isles) == -1)
361  return -1;
362 
363  if (ptr->n_isles)
364  if (0 >= dig__fread_port_P(ptr->isles, ptr->n_isles, fp))
365  return -1;
366 
367  /* centroid */
368  if (0 >= dig__fread_port_P(&(ptr->centroid), 1, fp))
369  return -1;
370 
371  Plus->Area[n] = ptr;
372 
373  return (0);
374 }
375 
376 int dig_Wr_P_area(struct Plus_head *Plus, int n, struct gvfile * fp)
377 {
378  int i;
379  struct P_area *ptr;
380 
381  ptr = Plus->Area[n];
382 
383  /* If NULL i.e. dead write just 0 instead of number of lines */
384  if (ptr == NULL) {
385  i = 0;
386  if (0 >= dig__fwrite_port_P(&i, 1, fp))
387  return (-1);
388  return 0;
389  }
390 
391  /* boundaries */
392  if (0 >= dig__fwrite_port_P(&(ptr->n_lines), 1, fp))
393  return (-1);
394 
395  if (ptr->n_lines)
396  if (0 >= dig__fwrite_port_P(ptr->lines, ptr->n_lines, fp))
397  return -1;
398 
399  /* isles */
400  if (0 >= dig__fwrite_port_P(&(ptr->n_isles), 1, fp))
401  return (-1);
402 
403  if (ptr->n_isles)
404  if (0 >= dig__fwrite_port_P(ptr->isles, ptr->n_isles, fp))
405  return -1;
406 
407  /* centroid */
408  if (0 >= dig__fwrite_port_P(&(ptr->centroid), 1, fp))
409  return (-1);
410 
411  return (0);
412 }
413 
414 int dig_Rd_P_isle(struct Plus_head *Plus, int n, struct gvfile * fp)
415 {
416  int cnt;
417  struct P_isle *ptr;
418 
419  G_debug(4, "dig_Rd_P_isle()");
420 
421  if (0 >= dig__fread_port_P(&cnt, 1, fp))
422  return (-1);
423 
424  if (cnt == 0) { /* dead */
425  Plus->Isle[n] = NULL;
426  return 0;
427  }
428 
429  ptr = dig_alloc_isle();
430 
431  /* boundaries */
432  ptr->n_lines = cnt;
433 
434  if (dig_isle_alloc_line(ptr, ptr->n_lines) == -1)
435  return -1;
436 
437  if (ptr->n_lines)
438  if (0 >= dig__fread_port_P(ptr->lines, ptr->n_lines, fp))
439  return -1;
440 
441  /* area */
442  if (0 >= dig__fread_port_P(&(ptr->area), 1, fp))
443  return -1;
444 
445  Plus->Isle[n] = ptr;
446 
447  return (0);
448 }
449 
450 int dig_Wr_P_isle(struct Plus_head *Plus, int n, struct gvfile * fp)
451 {
452  int i;
453  struct P_isle *ptr;
454 
455  ptr = Plus->Isle[n];
456 
457  /* If NULL i.e. dead write just 0 instead of number of lines */
458  if (ptr == NULL) {
459  i = 0;
460  if (0 >= dig__fwrite_port_P(&i, 1, fp))
461  return (-1);
462  return 0;
463  }
464 
465  /* lines */
466  if (0 >= dig__fwrite_port_P(&(ptr->n_lines), 1, fp))
467  return (-1);
468 
469  if (ptr->n_lines)
470  if (0 >= dig__fwrite_port_P(ptr->lines, ptr->n_lines, fp))
471  return -1;
472 
473  /* area */
474  if (0 >= dig__fwrite_port_P(&(ptr->area), 1, fp))
475  return (-1);
476 
477  return (0);
478 }
479 
480 /*!
481  \brief Read Plus_head from file
482 
483  \param fp pointer to gvfile structure
484  \param[in,out] ptr pointer to Plus_head structure
485 
486  \return -1 error
487  \return 0 OK
488 */
489 int dig_Rd_Plus_head(struct gvfile * fp, struct Plus_head *ptr)
490 {
491  unsigned char buf[5];
492  int byte_order;
493 
494  dig_rewind(fp);
495 
496  /* bytes 1 - 5 */
497  if (0 >= dig__fread_port_C((char *)buf, 5, fp))
498  return (-1);
499  ptr->version.topo.major = buf[0];
500  ptr->version.topo.minor = buf[1];
501  ptr->version.topo.back_major = buf[2];
502  ptr->version.topo.back_minor = buf[3];
503  byte_order = buf[4];
504 
505  G_debug(2,
506  "Topo header: file version %d.%d , supported from GRASS version %d.%d",
508  ptr->version.topo.back_minor);
509 
510  G_debug(2, " byte order %d", byte_order);
511 
512  /* check version numbers */
513  if (ptr->version.topo.major > GV_TOPO_VER_MAJOR ||
515  /* The file was created by GRASS library with higher version than this one */
516 
519  /* This version of GRASS lib is lower than the oldest which can read this format */
520  G_debug(1, "Topology format version %d.%d",
521  ptr->version.topo.major, ptr->version.topo.minor);
523  (_("This version of GRASS (%d.%d) is too old to read this topology format."
524  " Try to rebuild topology or upgrade GRASS to at least version %d."),
526  return (-1);
527  }
528 
529  G_warning(_("Your GRASS version does not fully support topology format %d.%d of the vector."
530  " Consider to rebuild topology or upgrade GRASS."),
531  ptr->version.topo.major, ptr->version.topo.minor);
532  }
533  if (ptr->version.topo.major < GV_TOPO_VER_MAJOR ||
534  (ptr->version.topo.major == GV_TOPO_VER_MAJOR &&
536  /* The file was created by GRASS library with lower version than this one */
537 
538  /* This version of GRASS lib can not read this old format */
539  G_warning(_("Old topology format version %d.%d is not supported by this release."
540  " Try to rebuild topology using v.build or v.build.all module."),
541  ptr->version.topo.major, ptr->version.topo.minor);
542  return (-1);
543  }
544 
545  /* init Port_info structure and set as default */
546  dig_init_portable(&(ptr->port), byte_order);
547  dig_set_cur_port(&(ptr->port));
548 
549  /* bytes 6 - 9 : header size */
550  if (0 >= dig__fread_port_L(&(ptr->head_size), 1, fp))
551  return (-1);
552  G_debug(2, " header size %ld", ptr->head_size);
553 
554  /* determine required offset size from header size */
555  /* this is not safe in case new fields get added in later versions */
556  /* better: add a new field with off_t_size after byte_order? */
557  if (ptr->head_size >= 142 + 32) /* keep in sync with dig_Wr_Plus_head() */
558  ptr->off_t_size = 8;
559  else
560  ptr->off_t_size = 4;
561 
562  if (sizeof(off_t) < ptr->off_t_size) {
563  G_warning(_("Vector exceeds supported file size limit"));
564  return (-1);
565  }
566 
567  G_debug(2, "topo off_t size = %d", ptr->off_t_size);
568 
569  /* byte 10 : dimension 2D or 3D */
570  if (0 >= dig__fread_port_C((char *)buf, 1, fp))
571  return (-1);
572  ptr->with_z = buf[0];
573  G_debug(2, " with_z %d", ptr->with_z);
574 
575  /* bytes 11 - 58 : bound box */
576  if (0 >= dig__fread_port_D(&(ptr->box.N), 1, fp))
577  return (-1);
578  if (0 >= dig__fread_port_D(&(ptr->box.S), 1, fp))
579  return (-1);
580  if (0 >= dig__fread_port_D(&(ptr->box.E), 1, fp))
581  return (-1);
582  if (0 >= dig__fread_port_D(&(ptr->box.W), 1, fp))
583  return (-1);
584  if (0 >= dig__fread_port_D(&(ptr->box.T), 1, fp))
585  return (-1);
586  if (0 >= dig__fread_port_D(&(ptr->box.B), 1, fp))
587  return (-1);
588 
589  /* bytes 59 - 86 : number of structures */
590  if (0 >= dig__fread_port_P(&(ptr->n_nodes), 1, fp))
591  return (-1);
592  if (0 >= dig__fread_port_P(&(ptr->n_edges), 1, fp))
593  return (-1);
594  if (0 >= dig__fread_port_P(&(ptr->n_lines), 1, fp))
595  return (-1);
596  if (0 >= dig__fread_port_P(&(ptr->n_areas), 1, fp))
597  return (-1);
598  if (0 >= dig__fread_port_P(&(ptr->n_isles), 1, fp))
599  return (-1);
600  if (0 >= dig__fread_port_P(&(ptr->n_volumes), 1, fp))
601  return (-1);
602  if (0 >= dig__fread_port_P(&(ptr->n_holes), 1, fp))
603  return (-1);
604 
605  /* bytes 87 - 110 : number of line types */
606  if (0 >= dig__fread_port_P(&(ptr->n_plines), 1, fp))
607  return (-1);
608  if (0 >= dig__fread_port_P(&(ptr->n_llines), 1, fp))
609  return (-1);
610  if (0 >= dig__fread_port_P(&(ptr->n_blines), 1, fp))
611  return (-1);
612  if (0 >= dig__fread_port_P(&(ptr->n_clines), 1, fp))
613  return (-1);
614  if (0 >= dig__fread_port_P(&(ptr->n_flines), 1, fp))
615  return (-1);
616  if (0 >= dig__fread_port_P(&(ptr->n_klines), 1, fp))
617  return (-1);
618 
619  /* bytes 111 - 138 : Offset */
620  if (0 >= dig__fread_port_O(&(ptr->Node_offset), 1, fp, ptr->off_t_size))
621  return (-1);
622  if (0 >= dig__fread_port_O(&(ptr->Edge_offset), 1, fp, ptr->off_t_size))
623  return (-1);
624  if (0 >= dig__fread_port_O(&(ptr->Line_offset), 1, fp, ptr->off_t_size))
625  return (-1);
626  if (0 >= dig__fread_port_O(&(ptr->Area_offset), 1, fp, ptr->off_t_size))
627  return (-1);
628  if (0 >= dig__fread_port_O(&(ptr->Isle_offset), 1, fp, ptr->off_t_size))
629  return (-1);
630  if (0 >= dig__fread_port_O(&(ptr->Volume_offset), 1, fp, ptr->off_t_size))
631  return (-1);
632  if (0 >= dig__fread_port_O(&(ptr->Hole_offset), 1, fp, ptr->off_t_size))
633  return (-1);
634 
635  /* bytes 139 - 142 : Coor size and time */
636  if (0 >= dig__fread_port_O(&(ptr->coor_size), 1, fp, ptr->off_t_size))
637  return (-1);
638 
639  G_debug(2, " coor size %"PRI_OFF_T, ptr->coor_size);
640 
641  dig_fseek(fp, ptr->head_size, SEEK_SET);
642 
643  return (0);
644 }
645 
646 int dig_Wr_Plus_head(struct gvfile * fp, struct Plus_head *ptr)
647 {
648  unsigned char buf[10];
649  long length = 142;
650 
651  dig_rewind(fp);
652  dig_set_cur_port(&(ptr->port));
653 
654  /* bytes 1 - 5 */
655  buf[0] = GV_TOPO_VER_MAJOR;
656  buf[1] = GV_TOPO_VER_MINOR;
657  buf[2] = GV_TOPO_EARLIEST_MAJOR;
658  buf[3] = GV_TOPO_EARLIEST_MINOR;
659  buf[4] = ptr->port.byte_order;
660  if (0 >= dig__fwrite_port_C((char *)buf, 5, fp))
661  return (-1);
662 
663  /* determine required offset size from coor file size */
664  if (ptr->coor_size > (off_t)PORT_LONG_MAX) {
665  /* can only happen when sizeof(off_t) == 8 */
666  ptr->off_t_size = 8;
667  }
668  else
669  ptr->off_t_size = 4;
670 
671  /* add a new field with off_t_size after byte_order? */
672 
673  /* adjust header size for large files */
674  if (ptr->off_t_size == 8) {
675  /* 7 offset values and coor file size: add 8 * 4 */
676  length += 32;
677  }
678 
679  /* bytes 6 - 9 : header size */
680  if (0 >= dig__fwrite_port_L(&length, 1, fp))
681  return (0);
682 
683  /* byte 10 : dimension 2D or 3D */
684  buf[0] = ptr->with_z;
685  if (0 >= dig__fwrite_port_C((char *)buf, 1, fp))
686  return (0);
687 
688  /* bytes 11 - 58 : bound box */
689  if (0 >= dig__fwrite_port_D(&(ptr->box.N), 1, fp))
690  return (-1);
691  if (0 >= dig__fwrite_port_D(&(ptr->box.S), 1, fp))
692  return (-1);
693  if (0 >= dig__fwrite_port_D(&(ptr->box.E), 1, fp))
694  return (-1);
695  if (0 >= dig__fwrite_port_D(&(ptr->box.W), 1, fp))
696  return (-1);
697  if (0 >= dig__fwrite_port_D(&(ptr->box.T), 1, fp))
698  return (-1);
699  if (0 >= dig__fwrite_port_D(&(ptr->box.B), 1, fp))
700  return (-1);
701 
702  /* bytes 59 - 86 : number of structures */
703  if (0 >= dig__fwrite_port_P(&(ptr->n_nodes), 1, fp))
704  return (-1);
705  if (0 >= dig__fwrite_port_P(&(ptr->n_edges), 1, fp))
706  return (-1);
707  if (0 >= dig__fwrite_port_P(&(ptr->n_lines), 1, fp))
708  return (-1);
709  if (0 >= dig__fwrite_port_P(&(ptr->n_areas), 1, fp))
710  return (-1);
711  if (0 >= dig__fwrite_port_P(&(ptr->n_isles), 1, fp))
712  return (-1);
713  if (0 >= dig__fwrite_port_P(&(ptr->n_volumes), 1, fp))
714  return (-1);
715  if (0 >= dig__fwrite_port_P(&(ptr->n_holes), 1, fp))
716  return (-1);
717 
718  /* bytes 87 - 110 : number of line types */
719  if (0 >= dig__fwrite_port_P(&(ptr->n_plines), 1, fp))
720  return (-1);
721  if (0 >= dig__fwrite_port_P(&(ptr->n_llines), 1, fp))
722  return (-1);
723  if (0 >= dig__fwrite_port_P(&(ptr->n_blines), 1, fp))
724  return (-1);
725  if (0 >= dig__fwrite_port_P(&(ptr->n_clines), 1, fp))
726  return (-1);
727  if (0 >= dig__fwrite_port_P(&(ptr->n_flines), 1, fp))
728  return (-1);
729  if (0 >= dig__fwrite_port_P(&(ptr->n_klines), 1, fp))
730  return (-1);
731 
732  /* bytes 111 - 138 : Offset */
733  if (0 >= dig__fwrite_port_O(&(ptr->Node_offset), 1, fp, ptr->off_t_size))
734  return (-1);
735  if (0 >= dig__fwrite_port_O(&(ptr->Edge_offset), 1, fp, ptr->off_t_size))
736  return (-1);
737  if (0 >= dig__fwrite_port_O(&(ptr->Line_offset), 1, fp, ptr->off_t_size))
738  return (-1);
739  if (0 >= dig__fwrite_port_O(&(ptr->Area_offset), 1, fp, ptr->off_t_size))
740  return (-1);
741  if (0 >= dig__fwrite_port_O(&(ptr->Isle_offset), 1, fp, ptr->off_t_size))
742  return (-1);
743  if (0 >= dig__fwrite_port_O(&(ptr->Volume_offset), 1, fp, ptr->off_t_size))
744  return (-1);
745  if (0 >= dig__fwrite_port_O(&(ptr->Hole_offset), 1, fp, ptr->off_t_size))
746  return (-1);
747 
748  /* bytes 139 - 142 : Coor size and time */
749  if (0 >= dig__fwrite_port_O(&(ptr->coor_size), 1, fp, ptr->off_t_size))
750  return (-1);
751 
752  G_debug(2, "topo body offset %"PRI_OFF_T, dig_ftell(fp));
753 
754  return (0);
755 }
int dig__fwrite_port_P(const plus_t *, size_t, struct gvfile *)
Write plus_t to the Portable Vector Format.
Definition: portable.c:871
plus_t n_areas
Current number of areas.
Definition: dig_structs.h:951
plus_t right
Volume number to the right, negative for hole.
Definition: dig_structs.h:1557
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
off_t coor_size
Size of coor file.
Definition: dig_structs.h:1161
if(!(yy_init))
Definition: sqlp.yy.c:775
plus_t area
Area number, negative for duplicate centroid.
Definition: dig_structs.h:1537
void dig_rewind(struct gvfile *file)
Rewind file position.
Definition: file.c:87
#define GV_TOPO_VER_MAJOR
Definition: dig_defines.h:151
#define GV_TOPO_VER_MINOR
Definition: dig_defines.h:152
void dig_init_portable(struct Port_info *, int)
Set Port_info structure to byte order of file.
Definition: portable.c:905
plus_t n_klines
Current number of kernels.
Definition: dig_structs.h:922
double W
West.
Definition: dig_structs.h:82
int dig__fwrite_port_I(const int *, size_t, struct gvfile *)
Write integers to the Portable Vector Format.
Definition: portable.c:758
plus_t n_holes
Current number of holes.
Definition: dig_structs.h:967
off_t offset
Offset in coor file for line.
Definition: dig_structs.h:1593
int dig_type_to_store(int)
Convert type to store type.
off_t Area_offset
Offset of array of areas in topo file.
Definition: dig_structs.h:1033
struct P_isle * dig_alloc_isle()
Allocate new isle structure.
Definition: struct_alloc.c:301
int back_major
Earliest version that can use this data format (major)
Definition: dig_structs.h:284
Vector geometry.
Definition: dig_structs.h:1574
int dig__fwrite_port_C(const char *, size_t, struct gvfile *)
Write chars to the Portable Vector Format.
Definition: portable.c:890
struct P_line ** Line
Array of vector geometries.
Definition: dig_structs.h:887
off_t Isle_offset
Offset of array of isles in topo file.
Definition: dig_structs.h:1037
int dig__fread_port_I(int *, size_t, struct gvfile *)
Read integers from the Portable Vector Format.
Definition: portable.c:343
struct P_area * dig_alloc_area()
Allocate new area structure.
Definition: struct_alloc.c:266
int dig_Wr_P_line(struct Plus_head *Plus, int n, struct gvfile *fp)
Definition: plus_struct.c:239
int dig_Wr_P_isle(struct Plus_head *Plus, int n, struct gvfile *fp)
Definition: plus_struct.c:450
int dig_Rd_P_node(struct Plus_head *Plus, int n, struct gvfile *fp)
Definition: plus_struct.c:50
int with_z
2D/3D vector data
Definition: dig_structs.h:802
int dig__fread_port_C(char *, size_t, struct gvfile *)
Read chars from the Portable Vector Format.
Definition: portable.c:509
Isle (topology) info.
Definition: dig_structs.h:1646
plus_t n_plines
Current number of points.
Definition: dig_structs.h:902
plus_t right
Area number to the right, negative for isle.
Definition: dig_structs.h:1526
struct P_area ** Area
Array of areas.
Definition: dig_structs.h:891
struct P_node ** Node
Array of nodes.
Definition: dig_structs.h:883
double x
X coordinate.
Definition: dig_structs.h:1453
void * dig_alloc_topo(char)
Allocate new topo struct.
Definition: struct_alloc.c:145
#define GV_CENTROID
Definition: dig_defines.h:185
plus_t n_lines
Number of attached lines (size of lines, angle)
Definition: dig_structs.h:1472
plus_t left
Area number to the left, negative for isle.
Definition: dig_structs.h:1522
int dig_Wr_P_area(struct Plus_head *Plus, int n, struct gvfile *fp)
Definition: plus_struct.c:376
#define PORT_LONG_MAX
Definition: dig_defines.h:70
int dig__fread_port_L(long *, size_t, struct gvfile *)
Read longs from the Portable Vector Format.
Definition: portable.c:260
off_t Line_offset
Offset of array of vector geometries in topo file.
Definition: dig_structs.h:1029
double E
East.
Definition: dig_structs.h:78
#define PRI_OFF_T
Definition: gis.h:69
struct P_isle ** Isle
Array of isles.
Definition: dig_structs.h:895
plus_t * lines
List of connected lines.
Definition: dig_structs.h:1479
plus_t * isles
1st generation interior islands
Definition: dig_structs.h:1640
#define GRASS_VERSION_MINOR
Definition: version.h:3
plus_t n_isles
Current number of isles.
Definition: dig_structs.h:955
plus_t centroid
Number of first centroid within area.
Definition: dig_structs.h:1628
#define NULL
Definition: ccmath.h:32
#define GV_TOPO_EARLIEST_MAJOR
Definition: dig_defines.h:162
plus_t n_lines
Number of boundary lines.
Definition: dig_structs.h:1651
plus_t N1
Start node.
Definition: dig_structs.h:1514
#define GV_POINT
Feature types used in memory on run time (may change)
Definition: dig_defines.h:182
off_t Volume_offset
Offset of array of volumes in topo file.
Definition: dig_structs.h:1041
off_t dig_ftell(struct gvfile *file)
Get struct gvfile position.
Definition: file.c:36
plus_t N2
End node.
Definition: dig_structs.h:1503
int dig__fwrite_port_F(const float *, size_t, struct gvfile *)
Write floats to the Portable Vector Format.
Definition: portable.c:596
int dig__fwrite_port_O(const off_t *, size_t, struct gvfile *, size_t)
Write off_ts to the Portable Vector Format.
Definition: portable.c:636
plus_t n_lines
Current number of lines.
Definition: dig_structs.h:947
int dig_Rd_P_line(struct Plus_head *Plus, int n, struct gvfile *fp)
Definition: plus_struct.c:148
#define GRASS_VERSION_MAJOR
Definition: version.h:2
struct Port_info port
Portability information.
Definition: dig_structs.h:845
#define GV_LINE
Definition: dig_defines.h:183
double N
North.
Definition: dig_structs.h:70
plus_t N1
Start node.
Definition: dig_structs.h:1499
off_t Hole_offset
Offset of array of holes in topo file.
Definition: dig_structs.h:1045
char type
Line type.
Definition: dig_structs.h:1586
double z
Z coordinate (used only for 3D data)
Definition: dig_structs.h:1461
off_t Edge_offset
Offset of array of edges in topo file.
Definition: dig_structs.h:1025
Centroid topology.
Definition: dig_structs.h:1532
int off_t_size
Offset size.
Definition: dig_structs.h:817
plus_t * lines
List of boundary lines.
Definition: dig_structs.h:1621
#define GV_FACE
Definition: dig_defines.h:186
Basic topology-related info.
Definition: dig_structs.h:784
off_t Node_offset
Offset of array of nodes in topo file.
Definition: dig_structs.h:1021
int major
Current version (major)
Definition: dig_structs.h:280
Line topology.
Definition: dig_structs.h:1494
void * topo
Topology info.
Definition: dig_structs.h:1599
int dig_type_from_store(int)
Convert type from store type.
float * angles
List of angles of connected lines.
Definition: dig_structs.h:1488
Boundary topology.
Definition: dig_structs.h:1509
struct P_line * dig_alloc_line()
Allocate new line structure.
Definition: struct_alloc.c:127
#define GV_BOUNDARY
Definition: dig_defines.h:184
plus_t * lines
List of boundary lines.
Definition: dig_structs.h:1662
double B
Bottom.
Definition: dig_structs.h:90
struct Version_info topo
Version info for topology file.
Definition: dig_structs.h:789
int dig_node_alloc_line(struct P_node *, int)
Allocate space in P_node struct.
Definition: struct_alloc.c:69
struct P_node * dig_alloc_node()
Allocate new node structure.
Definition: struct_alloc.c:30
Topological feature - node.
Definition: dig_structs.h:1448
double T
Top.
Definition: dig_structs.h:86
struct bound_box box
Bounding box of features.
Definition: dig_structs.h:877
plus_t n_flines
Current number of faces.
Definition: dig_structs.h:918
plus_t n_isles
Number of islands inside.
Definition: dig_structs.h:1632
plus_t left
Volume number to the left, negative for hole.
Definition: dig_structs.h:1553
Face topology.
Definition: dig_structs.h:1543
double y
Y coordinate.
Definition: dig_structs.h:1457
int dig_area_alloc_isle(struct P_area *, int)
Allocate space in P_area for add new isles.
Definition: struct_alloc.c:445
int byte_order
File byte order.
Definition: dig_structs.h:191
plus_t n_llines
Current number of lines.
Definition: dig_structs.h:906
int dig__fread_port_F(float *, size_t, struct gvfile *)
Read floats from the Portable Vector Format.
Definition: portable.c:123
Area (topology) info.
Definition: dig_structs.h:1605
Kernel topology.
Definition: dig_structs.h:1563
int dig__fread_port_O(off_t *, size_t, struct gvfile *, size_t)
Read off_ts from the Portable Vector Format.
Definition: portable.c:167
int dig_area_alloc_line(struct P_area *, int)
allocate space in P_area for add new lines
Definition: struct_alloc.c:419
int dig_Rd_P_isle(struct Plus_head *Plus, int n, struct gvfile *fp)
Definition: plus_struct.c:414
void G_warning(const char *,...) __attribute__((format(printf
double S
South.
Definition: dig_structs.h:74
int dig_Rd_P_area(struct Plus_head *Plus, int n, struct gvfile *fp)
Definition: plus_struct.c:329
int dig__fread_port_P(plus_t *, size_t, struct gvfile *)
Read plus_t from the Portable Vector Format.
Definition: portable.c:535
#define _(str)
Definition: glocale.h:10
int dig_Wr_P_node(struct Plus_head *Plus, int n, struct gvfile *fp)
Definition: plus_struct.c:103
plus_t n_clines
Current number of centroids.
Definition: dig_structs.h:914
int dig_isle_alloc_line(struct P_isle *, int)
Allocate space in P_isle for add new lines.
Definition: struct_alloc.c:471
plus_t volume
Volume number, negative for duplicate kernel.
Definition: dig_structs.h:1568
long head_size
Topo header size.
Definition: dig_structs.h:824
int minor
Current version (minor)
Definition: dig_structs.h:282
int dig_set_cur_port(struct Port_info *)
Set current Port_info structure.
Definition: portable.c:1001
int dig__fwrite_port_L(const long *, size_t, struct gvfile *)
Write longs to the Portable Vector Format.
Definition: portable.c:702
int back_minor
Earliest version that can use this data format (minor)
Definition: dig_structs.h:286
int dig_Wr_Plus_head(struct gvfile *fp, struct Plus_head *ptr)
Definition: plus_struct.c:646
plus_t n_blines
Current number of boundaries.
Definition: dig_structs.h:910
File definition.
Definition: dig_structs.h:96
plus_t N2
End node.
Definition: dig_structs.h:1518
plus_t n_lines
Number of boundary lines.
Definition: dig_structs.h:1610
plus_t area
Area it exists w/in, if any.
Definition: dig_structs.h:1669
int G_debug(int, const char *,...) __attribute__((format(printf
plus_t n_edges
Current number of edges.
Definition: dig_structs.h:943
int dig_fseek(struct gvfile *file, off_t offset, int whence)
Set struct gvfile position.
Definition: file.c:60
int dig_Rd_Plus_head(struct gvfile *fp, struct Plus_head *ptr)
Read Plus_head from file.
Definition: plus_struct.c:489
#define GV_KERNEL
Definition: dig_defines.h:187
struct Plus_head::@9 version
Backward compatibility version info.
int dig__fwrite_port_D(const double *, size_t, struct gvfile *)
Write doubles to the Portable Vector Format.
Definition: portable.c:557
plus_t n_volumes
Current number of volumes.
Definition: dig_structs.h:963
#define GV_TOPO_EARLIEST_MINOR
Definition: dig_defines.h:163
plus_t n_nodes
Current number of topological features derived from vector geometries.
Definition: dig_structs.h:939
int dig__fread_port_D(double *, size_t, struct gvfile *)
Read doubles from the Portable Vector Format.
Definition: portable.c:79