GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 <string.h>
19 #include <grass/gis.h>
20 #include <grass/Vect.h>
21 #include <grass/version.h>
22 
23 /*
24  * Routines for reading and writing Dig+ structures.
25  * return 0 on success, -1 on failure of whatever kind
26  * if you dont want it written out, then dont 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, GVFILE * fp)
51 {
52  int cnt, n_edges;
53  P_NODE *ptr;
54 
55  G_debug(3, "dig_Rd_P_node()");
56 
57 
58  if (0 >= dig__fread_port_P(&cnt, 1, fp))
59  return (-1);
60 
61  if (cnt == 0) { /* dead */
62  G_debug(3, " node is dead");
63  Plus->Node[n] = NULL;
64  return 0;
65  }
66 
67  ptr = dig_alloc_node();
68  ptr->n_lines = cnt;
69 
70  if (dig_node_alloc_line(ptr, ptr->n_lines) == -1)
71  return -1;
72 
73  if (ptr->n_lines) {
74  if (0 >= dig__fread_port_P(ptr->lines, ptr->n_lines, fp))
75  return (-1);
76  if (0 >= dig__fread_port_F(ptr->angles, ptr->n_lines, fp))
77  return (-1);
78  }
79 
80  if (Plus->with_z)
81  if (0 >= dig__fread_port_P(&n_edges, 1, fp)) /* reserved for edges */
82  return (-1);
83 
84  /* here will be edges */
85 
86  if (0 >= dig__fread_port_D(&(ptr->x), 1, fp))
87  return (-1);
88  if (0 >= dig__fread_port_D(&(ptr->y), 1, fp))
89  return (-1);
90 
91  if (Plus->with_z) {
92  if (0 >= dig__fread_port_D(&(ptr->z), 1, fp))
93  return (-1);
94  }
95  else
96  ptr->z = 0;
97 
98 
99  Plus->Node[n] = ptr;
100 
101  return (0);
102 }
103 
104 int dig_Wr_P_node(struct Plus_head *Plus, int n, GVFILE * fp)
105 {
106  int i, n_edges = 0;
107  P_NODE *ptr;
108 
109  G_debug(3, "dig_Wr_P_node()");
110  ptr = Plus->Node[n];
111 
112  /* If NULL i.e. dead write just 0 instead of number of lines */
113  if (ptr == NULL) {
114  G_debug(3, " node is dead -> write 0 only");
115  i = 0;
116  if (0 >= dig__fwrite_port_P(&i, 1, fp))
117  return (-1);
118  return 0;
119  }
120 
121  if (0 >= dig__fwrite_port_P(&(ptr->n_lines), 1, fp))
122  return (-1);
123 
124  if (ptr->n_lines) {
125  if (0 >= dig__fwrite_port_P(ptr->lines, ptr->n_lines, fp))
126  return (-1);
127  if (0 >= dig__fwrite_port_F(ptr->angles, ptr->n_lines, fp))
128  return (-1);
129  }
130 
131  if (Plus->with_z)
132  if (0 >= dig__fwrite_port_P(&n_edges, 1, fp)) /* reserved for edges */
133  return (-1);
134 
135  /* here will be edges */
136 
137  if (0 >= dig__fwrite_port_D(&(ptr->x), 1, fp))
138  return (-1);
139  if (0 >= dig__fwrite_port_D(&(ptr->y), 1, fp))
140  return (-1);
141 
142  if (Plus->with_z)
143  if (0 >= dig__fwrite_port_D(&(ptr->z), 1, fp))
144  return (-1);
145 
146  return (0);
147 }
148 
149 int dig_Rd_P_line(struct Plus_head *Plus, int n, GVFILE * fp)
150 {
151  int n_edges, vol;
152  char tp;
153  P_LINE *ptr;
154  P_NODE *Node;
155 
156  G_debug(3, "dig_Rd_P_line()");
157 
158  if (0 >= dig__fread_port_C(&tp, 1, fp))
159  return (-1);
160 
161  if (tp == 0) { /* dead */
162  G_debug(3, " line is dead");
163  Plus->Line[n] = NULL;
164  return 0;
165  }
166 
167  ptr = dig_alloc_line();
168 
169  ptr->type = dig_type_from_store(tp);
170  G_debug(5, " line type %d -> %d", tp, ptr->type);
171 
172  if (0 >= dig__fread_port_L(&(ptr->offset), 1, fp))
173  return (-1);
174 
175  /* First node */
176  if (ptr->type & (GV_POINTS | GV_LINES | GV_KERNEL))
177  if (0 >= dig__fread_port_P(&(ptr->N1), 1, fp))
178  return -1;
179 
180  /* Second node, for points/centroids not needed */
181  if (ptr->type & (GV_LINE | GV_BOUNDARY)) {
182  if (0 >= dig__fread_port_P(&(ptr->N2), 1, fp))
183  return -1;
184  }
185  else if (ptr->type & (GV_POINTS | GV_KERNEL))
186  ptr->N2 = ptr->N1;
187 
188  /* left area for boundary, area for centroid */
189  if (ptr->type & (GV_BOUNDARY | GV_CENTROID))
190  if (0 >= dig__fread_port_P(&(ptr->left), 1, fp))
191  return -1;
192 
193  /* right area */
194  if (ptr->type & GV_BOUNDARY)
195  if (0 >= dig__fread_port_P(&(ptr->right), 1, fp))
196  return -1;
197 
198  if ((ptr->type & GV_FACE) && Plus->with_z) { /* reserved for face edges */
199  if (0 >= dig__fread_port_I(&n_edges, 1, fp))
200  return -1;
201 
202  /* here will be list of edges */
203 
204  /* left / right volume */
205  if (0 >= dig__fread_port_P(&vol, 1, fp))
206  return -1;
207  if (0 >= dig__fread_port_P(&vol, 1, fp))
208  return -1;
209  }
210 
211  if ((ptr->type & GV_KERNEL) && Plus->with_z) /* reserved for kernel (volume number) */
212  if (0 >= dig__fread_port_P(&vol, 1, fp))
213  return -1;
214 
215  /* Bounding box */
216  if (ptr->type & (GV_LINE | GV_BOUNDARY | GV_FACE)) {
217  if (0 >= dig__fread_port_D(&(ptr->N), 1, fp))
218  return -1;
219  if (0 >= dig__fread_port_D(&(ptr->S), 1, fp))
220  return -1;
221  if (0 >= dig__fread_port_D(&(ptr->E), 1, fp))
222  return -1;
223  if (0 >= dig__fread_port_D(&(ptr->W), 1, fp))
224  return -1;
225 
226  if (Plus->with_z) {
227  if (0 >= dig__fread_port_D(&(ptr->T), 1, fp))
228  return -1;
229  if (0 >= dig__fread_port_D(&(ptr->B), 1, fp))
230  return -1;
231  }
232  else {
233  ptr->T = 0.0;
234  ptr->B = 0.0;
235  }
236  }
237  else {
238  Node = Plus->Node[ptr->N1];
239  ptr->N = Node->y;
240  ptr->S = Node->y;
241  ptr->E = Node->x;
242  ptr->W = Node->x;
243  ptr->T = Node->z;
244  ptr->B = Node->z;
245  }
246 
247  Plus->Line[n] = ptr;
248  return (0);
249 }
250 
251 int dig_Wr_P_line(struct Plus_head *Plus, int n, GVFILE * fp)
252 {
253  int n_edges = 0, vol = 0;
254  char ch;
255  P_LINE *ptr;
256 
257  G_debug(4, "dig_Wr_P_line() line = %d", n);
258 
259  ptr = Plus->Line[n];
260 
261  /* If NULL i.e. dead write just 0 instead of type */
262  if (ptr == NULL) {
263  G_debug(3, " line is dead -> write 0 only");
264  ch = 0;
265  if (0 >= dig__fwrite_port_C(&ch, 1, fp))
266  return (-1);
267  return 0;
268  }
269 
270  ch = (char)dig_type_to_store(ptr->type);
271  G_debug(5, " line type %d -> %d", ptr->type, ch);
272  if (0 >= dig__fwrite_port_C(&ch, 1, fp))
273  return (-1);
274  if (0 >= dig__fwrite_port_L(&(ptr->offset), 1, fp))
275  return (-1);
276 
277  /* First node */
278  if (ptr->type & (GV_POINTS | GV_LINES | GV_KERNEL))
279  if (0 >= dig__fwrite_port_P(&(ptr->N1), 1, fp))
280  return (-1);
281 
282  /* Second node, for points/centroids not needed */
283  if (ptr->type & (GV_LINE | GV_BOUNDARY))
284  if (0 >= dig__fwrite_port_P(&(ptr->N2), 1, fp))
285  return (-1);
286 
287  /* left area for boundary, area for centroid */
288  if (ptr->type & (GV_BOUNDARY | GV_CENTROID))
289  if (0 >= dig__fwrite_port_P(&(ptr->left), 1, fp))
290  return (-1);
291 
292  /* right area */
293  if (ptr->type & GV_BOUNDARY)
294  if (0 >= dig__fwrite_port_P(&(ptr->right), 1, fp))
295  return (-1);
296 
297  if ((ptr->type & GV_FACE) && Plus->with_z) { /* reserved for face */
298  if (0 >= dig__fwrite_port_I(&n_edges, 1, fp))
299  return (-1);
300 
301  /* here will be list of edges */
302 
303  /* left / right volume */
304  if (0 >= dig__fwrite_port_P(&vol, 1, fp))
305  return (-1);
306  if (0 >= dig__fwrite_port_P(&vol, 1, fp))
307  return (-1);
308  }
309 
310  if ((ptr->type & GV_KERNEL) && Plus->with_z) /* reserved for kernel (volume number) */
311  if (0 >= dig__fwrite_port_P(&vol, 1, fp))
312  return (-1);
313 
314  /* Bounding box */
315  if (ptr->type & (GV_LINE | GV_BOUNDARY | GV_FACE)) {
316  if (0 >= dig__fwrite_port_D(&(ptr->N), 1, fp))
317  return (-1);
318  if (0 >= dig__fwrite_port_D(&(ptr->S), 1, fp))
319  return (-1);
320  if (0 >= dig__fwrite_port_D(&(ptr->E), 1, fp))
321  return (-1);
322  if (0 >= dig__fwrite_port_D(&(ptr->W), 1, fp))
323  return (-1);
324 
325  if (Plus->with_z) {
326  if (0 >= dig__fwrite_port_D(&(ptr->T), 1, fp))
327  return (-1);
328  if (0 >= dig__fwrite_port_D(&(ptr->B), 1, fp))
329  return (-1);
330  }
331  }
332 
333  return (0);
334 }
335 
336 int dig_Rd_P_area(struct Plus_head *Plus, int n, GVFILE * fp)
337 {
338  int cnt;
339  P_AREA *ptr;
340 
341 #ifdef GDEBUG
342  G_debug(3, "dig_Rd_P_area(): n = %d", n);
343 #endif
344 
345  if (0 >= dig__fread_port_P(&cnt, 1, fp))
346  return (-1);
347 
348  if (cnt == 0) { /* dead */
349  Plus->Area[n] = NULL;
350  return 0;
351  }
352 
353  ptr = dig_alloc_area();
354 
355  /* lines */
356  ptr->n_lines = cnt;
357 
358  if (dig_area_alloc_line(ptr, ptr->n_lines) == -1)
359  return -1;
360 
361  if (ptr->n_lines)
362  if (0 >= dig__fread_port_P(ptr->lines, ptr->n_lines, fp))
363  return -1;
364 
365  /* isles */
366  if (0 >= dig__fread_port_P(&(ptr->n_isles), 1, fp))
367  return -1;
368 
369  if (dig_area_alloc_isle(ptr, ptr->n_isles) == -1)
370  return -1;
371 
372  if (ptr->n_isles)
373  if (0 >= dig__fread_port_P(ptr->isles, ptr->n_isles, fp))
374  return -1;
375 
376  /* centroid */
377  if (0 >= dig__fread_port_P(&(ptr->centroid), 1, fp))
378  return -1;
379 
380  if (0 >= dig__fread_port_D(&(ptr->N), 1, fp))
381  return -1;
382  if (0 >= dig__fread_port_D(&(ptr->S), 1, fp))
383  return -1;
384  if (0 >= dig__fread_port_D(&(ptr->E), 1, fp))
385  return -1;
386  if (0 >= dig__fread_port_D(&(ptr->W), 1, fp))
387  return -1;
388 
389  if (Plus->with_z) {
390  if (0 >= dig__fread_port_D(&(ptr->T), 1, fp))
391  return -1;
392  if (0 >= dig__fread_port_D(&(ptr->B), 1, fp))
393  return -1;
394  }
395  else {
396  ptr->T = 0.0;
397  ptr->B = 0.0;
398  }
399 
400  Plus->Area[n] = ptr;
401 
402  return (0);
403 }
404 
405 int dig_Wr_P_area(struct Plus_head *Plus, int n, GVFILE * fp)
406 {
407  int i;
408  P_AREA *ptr;
409 
410  ptr = Plus->Area[n];
411 
412  /* If NULL i.e. dead write just 0 instead of number of lines */
413  if (ptr == NULL) {
414  i = 0;
415  if (0 >= dig__fwrite_port_P(&i, 1, fp))
416  return (-1);
417  return 0;
418  }
419 
420  /* lines */
421  if (0 >= dig__fwrite_port_P(&(ptr->n_lines), 1, fp))
422  return (-1);
423 
424  if (ptr->n_lines)
425  if (0 >= dig__fwrite_port_P(ptr->lines, ptr->n_lines, fp))
426  return -1;
427 
428  /* isles */
429  if (0 >= dig__fwrite_port_P(&(ptr->n_isles), 1, fp))
430  return (-1);
431 
432  if (ptr->n_isles)
433  if (0 >= dig__fwrite_port_P(ptr->isles, ptr->n_isles, fp))
434  return -1;
435 
436  /* centroid */
437  if (0 >= dig__fwrite_port_P(&(ptr->centroid), 1, fp))
438  return (-1);
439 
440  if (0 >= dig__fwrite_port_D(&(ptr->N), 1, fp))
441  return (-1);
442  if (0 >= dig__fwrite_port_D(&(ptr->S), 1, fp))
443  return (-1);
444  if (0 >= dig__fwrite_port_D(&(ptr->E), 1, fp))
445  return (-1);
446  if (0 >= dig__fwrite_port_D(&(ptr->W), 1, fp))
447  return (-1);
448 
449  if (Plus->with_z) {
450  if (0 >= dig__fwrite_port_D(&(ptr->T), 1, fp))
451  return (-1);
452  if (0 >= dig__fwrite_port_D(&(ptr->B), 1, fp))
453  return (-1);
454  }
455 
456  return (0);
457 }
458 
459 int dig_Rd_P_isle(struct Plus_head *Plus, int n, GVFILE * fp)
460 {
461  int cnt;
462  P_ISLE *ptr;
463 
464 #ifdef GDEBUG
465  G_debug(3, "dig_Rd_P_isle()");
466 #endif
467 
468  if (0 >= dig__fread_port_P(&cnt, 1, fp))
469  return (-1);
470 
471  if (cnt == 0) { /* dead */
472  Plus->Isle[n] = NULL;
473  return 0;
474  }
475 
476  ptr = dig_alloc_isle();
477 
478  /* lines */
479  ptr->n_lines = cnt;
480 
481  if (dig_isle_alloc_line(ptr, ptr->n_lines) == -1)
482  return -1;
483 
484  if (ptr->n_lines)
485  if (0 >= dig__fread_port_P(ptr->lines, ptr->n_lines, fp))
486  return -1;
487 
488  /* area */
489  if (0 >= dig__fread_port_P(&(ptr->area), 1, fp))
490  return -1;
491 
492  if (0 >= dig__fread_port_D(&(ptr->N), 1, fp))
493  return -1;
494  if (0 >= dig__fread_port_D(&(ptr->S), 1, fp))
495  return -1;
496  if (0 >= dig__fread_port_D(&(ptr->E), 1, fp))
497  return -1;
498  if (0 >= dig__fread_port_D(&(ptr->W), 1, fp))
499  return -1;
500 
501  if (Plus->with_z) {
502  if (0 >= dig__fread_port_D(&(ptr->T), 1, fp))
503  return -1;
504  if (0 >= dig__fread_port_D(&(ptr->B), 1, fp))
505  return -1;
506  }
507  else {
508  ptr->T = 0.0;
509  ptr->B = 0.0;
510  }
511 
512  Plus->Isle[n] = ptr;
513 
514  return (0);
515 }
516 
517 int dig_Wr_P_isle(struct Plus_head *Plus, int n, GVFILE * fp)
518 {
519  int i;
520  P_ISLE *ptr;
521 
522  ptr = Plus->Isle[n];
523 
524  /* If NULL i.e. dead write just 0 instead of number of lines */
525  if (ptr == NULL) {
526  i = 0;
527  if (0 >= dig__fwrite_port_P(&i, 1, fp))
528  return (-1);
529  return 0;
530  }
531 
532  /* lines */
533  if (0 >= dig__fwrite_port_P(&(ptr->n_lines), 1, fp))
534  return (-1);
535 
536  if (ptr->n_lines)
537  if (0 >= dig__fwrite_port_P(ptr->lines, ptr->n_lines, fp))
538  return -1;
539 
540  /* area */
541  if (0 >= dig__fwrite_port_P(&(ptr->area), 1, fp))
542  return (-1);
543 
544  if (0 >= dig__fwrite_port_D(&(ptr->N), 1, fp))
545  return (-1);
546  if (0 >= dig__fwrite_port_D(&(ptr->S), 1, fp))
547  return (-1);
548  if (0 >= dig__fwrite_port_D(&(ptr->E), 1, fp))
549  return (-1);
550  if (0 >= dig__fwrite_port_D(&(ptr->W), 1, fp))
551  return (-1);
552 
553  if (Plus->with_z) {
554  if (0 >= dig__fwrite_port_D(&(ptr->T), 1, fp))
555  return (-1);
556  if (0 >= dig__fwrite_port_D(&(ptr->B), 1, fp))
557  return (-1);
558  }
559 
560  return (0);
561 }
562 
563 /*
564  \return -1 error
565  \return 0 OK
566  */
567 int dig_Rd_Plus_head(GVFILE * fp, struct Plus_head *ptr)
568 {
569  unsigned char buf[5];
570  int byte_order;
571 
572  dig_rewind(fp);
573 
574  /* bytes 1 - 5 */
575  if (0 >= dig__fread_port_C(buf, 5, fp))
576  return (-1);
577  ptr->Version_Major = buf[0];
578  ptr->Version_Minor = buf[1];
579  ptr->Back_Major = buf[2];
580  ptr->Back_Minor = buf[3];
581  byte_order = buf[4];
582 
583  G_debug(2,
584  "Topo header: file version %d.%d , supported from GRASS version %d.%d",
585  ptr->Version_Major, ptr->Version_Minor, ptr->Back_Major,
586  ptr->Back_Minor);
587 
588  G_debug(2, " byte order %d", byte_order);
589 
590  /* check version numbers */
591  if (ptr->Version_Major > GV_TOPO_VER_MAJOR ||
592  ptr->Version_Minor > GV_TOPO_VER_MINOR) {
593  /* The file was created by GRASS library with higher version than this one */
594 
595  if (ptr->Back_Major > GV_TOPO_VER_MAJOR ||
596  ptr->Back_Minor > GV_TOPO_VER_MINOR) {
597  /* This version of GRASS lib is lower than the oldest which can read this format */
598  G_debug(1, "Topology format version %d.%d",
599  ptr->Version_Major, ptr->Version_Minor);
601  ("This version of GRASS (%d.%d) is too old to read this topology format."
602  " Try to rebuild topology or upgrade GRASS to at least version %d.",
603  GRASS_VERSION_MAJOR, GRASS_VERSION_MINOR, GRASS_VERSION_MAJOR + 1);
604  return (-1);
605  }
606 
607  G_warning
608  ("Your GRASS version does not fully support topology format %d.%d of the vector."
609  " Consider to rebuild topology or upgrade GRASS.",
610  ptr->Version_Major, ptr->Version_Minor);
611  }
612 
613  dig_init_portable(&(ptr->port), byte_order);
614  dig_set_cur_port(&(ptr->port));
615 
616  /* bytes 6 - 9 : header size */
617  if (0 >= dig__fread_port_L(&(ptr->head_size), 1, fp))
618  return (-1);
619  G_debug(2, " header size %ld", ptr->head_size);
620 
621  /* byte 10 : dimension 2D or 3D */
622  if (0 >= dig__fread_port_C(buf, 1, fp))
623  return (-1);
624  ptr->with_z = buf[0];
625  G_debug(2, " with_z %d", ptr->with_z);
626 
627  /* bytes 11 - 58 : bound box */
628  if (0 >= dig__fread_port_D(&(ptr->box.N), 1, fp))
629  return (-1);
630  if (0 >= dig__fread_port_D(&(ptr->box.S), 1, fp))
631  return (-1);
632  if (0 >= dig__fread_port_D(&(ptr->box.E), 1, fp))
633  return (-1);
634  if (0 >= dig__fread_port_D(&(ptr->box.W), 1, fp))
635  return (-1);
636  if (0 >= dig__fread_port_D(&(ptr->box.T), 1, fp))
637  return (-1);
638  if (0 >= dig__fread_port_D(&(ptr->box.B), 1, fp))
639  return (-1);
640 
641  /* bytes 59 - 86 : number of structures */
642  if (0 >= dig__fread_port_P(&(ptr->n_nodes), 1, fp))
643  return (-1);
644  if (0 >= dig__fread_port_P(&(ptr->n_edges), 1, fp))
645  return (-1);
646  if (0 >= dig__fread_port_P(&(ptr->n_lines), 1, fp))
647  return (-1);
648  if (0 >= dig__fread_port_P(&(ptr->n_areas), 1, fp))
649  return (-1);
650  if (0 >= dig__fread_port_P(&(ptr->n_isles), 1, fp))
651  return (-1);
652  if (0 >= dig__fread_port_P(&(ptr->n_volumes), 1, fp))
653  return (-1);
654  if (0 >= dig__fread_port_P(&(ptr->n_holes), 1, fp))
655  return (-1);
656 
657  /* bytes 87 - 110 : number of line types */
658  if (0 >= dig__fread_port_P(&(ptr->n_plines), 1, fp))
659  return (-1);
660  if (0 >= dig__fread_port_P(&(ptr->n_llines), 1, fp))
661  return (-1);
662  if (0 >= dig__fread_port_P(&(ptr->n_blines), 1, fp))
663  return (-1);
664  if (0 >= dig__fread_port_P(&(ptr->n_clines), 1, fp))
665  return (-1);
666  if (0 >= dig__fread_port_P(&(ptr->n_flines), 1, fp))
667  return (-1);
668  if (0 >= dig__fread_port_P(&(ptr->n_klines), 1, fp))
669  return (-1);
670 
671  /* bytes 111 - 138 : Offset */
672  if (0 >= dig__fread_port_L(&(ptr->Node_offset), 1, fp))
673  return (-1);
674  if (0 >= dig__fread_port_L(&(ptr->Edge_offset), 1, fp))
675  return (-1);
676  if (0 >= dig__fread_port_L(&(ptr->Line_offset), 1, fp))
677  return (-1);
678  if (0 >= dig__fread_port_L(&(ptr->Area_offset), 1, fp))
679  return (-1);
680  if (0 >= dig__fread_port_L(&(ptr->Isle_offset), 1, fp))
681  return (-1);
682  if (0 >= dig__fread_port_L(&(ptr->Volume_offset), 1, fp))
683  return (-1);
684  if (0 >= dig__fread_port_L(&(ptr->Hole_offset), 1, fp))
685  return (-1);
686 
687  /* bytes 139 - 142 : Coor size and time */
688  if (0 >= dig__fread_port_L(&(ptr->coor_size), 1, fp))
689  return (-1);
690 
691  G_debug(2, " coor size %ld", ptr->coor_size);
692 
693  dig_fseek(fp, ptr->head_size, SEEK_SET);
694 
695  return (0);
696 }
697 
698 int dig_Wr_Plus_head(GVFILE * fp, struct Plus_head *ptr)
699 {
700  unsigned char buf[10];
701  long length = 142;
702 
703  dig_rewind(fp);
704  dig_set_cur_port(&(ptr->port));
705 
706  /* bytes 1 - 5 */
707  buf[0] = GV_TOPO_VER_MAJOR;
708  buf[1] = GV_TOPO_VER_MINOR;
709  buf[2] = GV_TOPO_EARLIEST_MAJOR;
710  buf[3] = GV_TOPO_EARLIEST_MINOR;
711  buf[4] = ptr->port.byte_order;
712  if (0 >= dig__fwrite_port_C(buf, 5, fp))
713  return (-1);
714 
715  /* bytes 6 - 9 : header size */
716  if (0 >= dig__fwrite_port_L(&length, 1, fp))
717  return (0);
718 
719  /* byte 10 : dimension 2D or 3D */
720  buf[0] = ptr->with_z;
721  if (0 >= dig__fwrite_port_C(buf, 1, fp))
722  return (0);
723 
724  /* bytes 11 - 58 : bound box */
725  if (0 >= dig__fwrite_port_D(&(ptr->box.N), 1, fp))
726  return (-1);
727  if (0 >= dig__fwrite_port_D(&(ptr->box.S), 1, fp))
728  return (-1);
729  if (0 >= dig__fwrite_port_D(&(ptr->box.E), 1, fp))
730  return (-1);
731  if (0 >= dig__fwrite_port_D(&(ptr->box.W), 1, fp))
732  return (-1);
733  if (0 >= dig__fwrite_port_D(&(ptr->box.T), 1, fp))
734  return (-1);
735  if (0 >= dig__fwrite_port_D(&(ptr->box.B), 1, fp))
736  return (-1);
737 
738  /* bytes 59 - 86 : number of structures */
739  if (0 >= dig__fwrite_port_P(&(ptr->n_nodes), 1, fp))
740  return (-1);
741  if (0 >= dig__fwrite_port_P(&(ptr->n_edges), 1, fp))
742  return (-1);
743  if (0 >= dig__fwrite_port_P(&(ptr->n_lines), 1, fp))
744  return (-1);
745  if (0 >= dig__fwrite_port_P(&(ptr->n_areas), 1, fp))
746  return (-1);
747  if (0 >= dig__fwrite_port_P(&(ptr->n_isles), 1, fp))
748  return (-1);
749  if (0 >= dig__fwrite_port_P(&(ptr->n_volumes), 1, fp))
750  return (-1);
751  if (0 >= dig__fwrite_port_P(&(ptr->n_holes), 1, fp))
752  return (-1);
753 
754  /* bytes 87 - 110 : number of line types */
755  if (0 >= dig__fwrite_port_P(&(ptr->n_plines), 1, fp))
756  return (-1);
757  if (0 >= dig__fwrite_port_P(&(ptr->n_llines), 1, fp))
758  return (-1);
759  if (0 >= dig__fwrite_port_P(&(ptr->n_blines), 1, fp))
760  return (-1);
761  if (0 >= dig__fwrite_port_P(&(ptr->n_clines), 1, fp))
762  return (-1);
763  if (0 >= dig__fwrite_port_P(&(ptr->n_flines), 1, fp))
764  return (-1);
765  if (0 >= dig__fwrite_port_P(&(ptr->n_klines), 1, fp))
766  return (-1);
767 
768  /* bytes 111 - 138 : Offset */
769  if (0 >= dig__fwrite_port_L(&(ptr->Node_offset), 1, fp))
770  return (-1);
771  if (0 >= dig__fwrite_port_L(&(ptr->Edge_offset), 1, fp))
772  return (-1);
773  if (0 >= dig__fwrite_port_L(&(ptr->Line_offset), 1, fp))
774  return (-1);
775  if (0 >= dig__fwrite_port_L(&(ptr->Area_offset), 1, fp))
776  return (-1);
777  if (0 >= dig__fwrite_port_L(&(ptr->Isle_offset), 1, fp))
778  return (-1);
779  if (0 >= dig__fwrite_port_L(&(ptr->Volume_offset), 1, fp))
780  return (-1);
781  if (0 >= dig__fwrite_port_L(&(ptr->Hole_offset), 1, fp))
782  return (-1);
783 
784  /* bytes 139 - 142 : Coor size and time */
785  if (0 >= dig__fwrite_port_L(&(ptr->coor_size), 1, fp))
786  return (-1);
787 
788  G_debug(2, "topo body offset %ld", dig_ftell(fp));
789 
790  return (0);
791 }
int dig_area_alloc_isle(P_AREA *area, int add)
Definition: struct_alloc.c:325
int dig_Wr_Plus_head(GVFILE *fp, struct Plus_head *ptr)
Definition: plus_struct.c:698
int dig_set_cur_port(struct Port_info *port)
Definition: portable.c:640
int dig__fread_port_P(plus_t *buf, int cnt, GVFILE *fp)
Definition: portable.c:359
P_NODE * dig_alloc_node()
Definition: struct_alloc.c:40
Definition: index.h:56
int dig__fwrite_port_D(double *buf, int cnt, GVFILE *fp)
Definition: portable.c:370
int dig_Rd_P_area(struct Plus_head *Plus, int n, GVFILE *fp)
Definition: plus_struct.c:336
void dig_init_portable(struct Port_info *port, int byte_order)
Definition: portable.c:568
int dig_Wr_P_line(struct Plus_head *Plus, int n, GVFILE *fp)
Definition: plus_struct.c:251
int dig__fread_port_L(long *buf, int cnt, GVFILE *fp)
Definition: portable.c:137
int dig_Rd_P_node(struct Plus_head *Plus, int n, GVFILE *fp)
Definition: plus_struct.c:50
int dig_node_alloc_line(P_NODE *node, int add)
Definition: struct_alloc.c:63
int dig_Wr_P_isle(struct Plus_head *Plus, int n, GVFILE *fp)
Definition: plus_struct.c:517
int dig_Rd_Plus_head(GVFILE *fp, struct Plus_head *ptr)
Definition: plus_struct.c:567
int dig__fwrite_port_I(int *buf, int cnt, GVFILE *fp)
Definition: portable.c:465
int dig_fseek(GVFILE *file, long offset, int whence)
Set GVFILE position.
Definition: file.c:60
P_ISLE * dig_alloc_isle()
Definition: struct_alloc.c:211
int dig_area_alloc_line(P_AREA *area, int add)
Definition: struct_alloc.c:303
int dig_Rd_P_isle(struct Plus_head *Plus, int n, GVFILE *fp)
Definition: plus_struct.c:459
int dig__fwrite_port_P(plus_t *buf, int cnt, GVFILE *fp)
Definition: portable.c:552
int GV_LINES
Definition: vdigit/main.py:24
int dig__fwrite_port_L(long *buf, int cnt, GVFILE *fp)
Definition: portable.c:422
int dig_type_from_store(int stype)
Convert type from store type.
int dig__fread_port_D(double *buf, int cnt, GVFILE *fp)
Definition: portable.c:75
int dig__fread_port_F(float *buf, int cnt, GVFILE *fp)
Definition: portable.c:106
int dig_isle_alloc_line(P_ISLE *isle, int add)
Definition: struct_alloc.c:348
P_LINE * dig_alloc_line()
Definition: struct_alloc.c:110
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition: g3drange.c:62
P_AREA * dig_alloc_area()
Definition: struct_alloc.c:189
int dig__fread_port_C(char *buf, int cnt, GVFILE *fp)
Definition: portable.c:347
return NULL
Definition: dbfopen.c:1394
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int dig_type_to_store(int type)
Convert type to store type.
int dig_Rd_P_line(struct Plus_head *Plus, int n, GVFILE *fp)
Definition: plus_struct.c:149
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51
void dig_rewind(GVFILE *file)
Rewind GVFILE position.
Definition: file.c:85
int dig__fwrite_port_F(float *buf, int cnt, GVFILE *fp)
Definition: portable.c:396
int dig__fwrite_port_C(char *buf, int cnt, GVFILE *fp)
Definition: portable.c:558
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
long dig_ftell(GVFILE *file)
Get GVFILE position.
Definition: file.c:36
int dig_Wr_P_node(struct Plus_head *Plus, int n, GVFILE *fp)
Definition: plus_struct.c:104
int dig_Wr_P_area(struct Plus_head *Plus, int n, GVFILE *fp)
Definition: plus_struct.c:405
int n
Definition: dataquad.c:291
int dig__fread_port_I(int *buf, int cnt, GVFILE *fp)
Definition: portable.c:207