149
int dig_Rd_P_line(struct Plus_head *Plus, int n, GVFILE * fp)
148
int dig_Rd_P_line(struct Plus_head *Plus, int n, struct gvfile * fp)
156
G_debug(3, "dig_Rd_P_line()");
154
G_debug(4, "dig_Rd_P_line()");
158
156
if (0 >= dig__fread_port_C(&tp, 1, fp))
161
159
if (tp == 0) { /* dead */
162
G_debug(3, " line is dead");
160
G_debug(4, " line is dead");
163
161
Plus->Line[n] = NULL;
167
165
ptr = dig_alloc_line();
169
168
ptr->type = dig_type_from_store(tp);
170
169
G_debug(5, " line type %d -> %d", tp, ptr->type);
172
if (0 >= dig__fread_port_L(&(ptr->offset), 1, fp))
172
if (0 >= dig__fread_port_O(&(ptr->offset), 1, fp, Plus->off_t_size))
176
if (ptr->type & (GV_POINTS | GV_LINES | GV_KERNEL))
177
if (0 >= dig__fread_port_P(&(ptr->N1), 1, fp))
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))
185
else if (ptr->type & (GV_POINTS | GV_KERNEL))
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))
194
if (ptr->type & GV_BOUNDARY)
195
if (0 >= dig__fread_port_P(&(ptr->right), 1, fp))
198
if ((ptr->type & GV_FACE) && Plus->with_z) { /* reserved for face edges */
175
if (ptr->type == GV_POINT) {
179
ptr->topo = dig_alloc_topo(ptr->type);
183
if (ptr->type & GV_CENTROID) {
184
struct P_topo_c *topo = (struct P_topo_c *)ptr->topo;
186
if (0 >= dig__fread_port_P(&(topo->area), 1, fp))
190
else if (ptr->type & GV_LINE) {
191
struct P_topo_l *topo = (struct P_topo_l *)ptr->topo;
193
if (0 >= dig__fread_port_P(&(topo->N1), 1, fp))
195
if (0 >= dig__fread_port_P(&(topo->N2), 1, fp))
199
else if (ptr->type & GV_BOUNDARY) {
200
struct P_topo_b *topo = (struct P_topo_b *)ptr->topo;
202
if (0 >= dig__fread_port_P(&(topo->N1), 1, fp))
204
if (0 >= dig__fread_port_P(&(topo->N2), 1, fp))
206
if (0 >= dig__fread_port_P(&(topo->left), 1, fp))
208
if (0 >= dig__fread_port_P(&(topo->right), 1, fp))
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;
199
215
if (0 >= dig__fread_port_I(&n_edges, 1, fp))
202
218
/* here will be list of edges */
204
220
/* left / right volume */
205
if (0 >= dig__fread_port_P(&vol, 1, fp))
207
if (0 >= dig__fread_port_P(&vol, 1, fp))
211
if ((ptr->type & GV_KERNEL) && Plus->with_z) /* reserved for kernel (volume number) */
212
if (0 >= dig__fread_port_P(&vol, 1, fp))
216
if (ptr->type & (GV_LINE | GV_BOUNDARY | GV_FACE)) {
217
if (0 >= dig__fread_port_D(&(ptr->N), 1, fp))
219
if (0 >= dig__fread_port_D(&(ptr->S), 1, fp))
221
if (0 >= dig__fread_port_D(&(ptr->E), 1, fp))
223
if (0 >= dig__fread_port_D(&(ptr->W), 1, fp))
227
if (0 >= dig__fread_port_D(&(ptr->T), 1, fp))
229
if (0 >= dig__fread_port_D(&(ptr->B), 1, fp))
238
Node = Plus->Node[ptr->N1];
221
if (0 >= dig__fread_port_P(&(topo->left), 1, fp))
223
if (0 >= dig__fread_port_P(&(topo->left), 1, fp))
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;
230
if (0 >= dig__fread_port_P(&(topo->volume), 1, fp))
247
234
Plus->Line[n] = ptr;
251
int dig_Wr_P_line(struct Plus_head *Plus, int n, GVFILE * fp)
239
int dig_Wr_P_line(struct Plus_head *Plus, int n, struct gvfile * fp)
253
int n_edges = 0, vol = 0;
257
245
G_debug(4, "dig_Wr_P_line() line = %d", n);
259
247
ptr = Plus->Line[n];
261
/* If NULL i.e. dead write just 0 instead of type */
249
/* if NULL i.e. dead write just 0 instead of type */
262
250
if (ptr == NULL) {
263
G_debug(3, " line is dead -> write 0 only");
251
G_debug(4, " line is dead -> write 0 only");
265
253
if (0 >= dig__fwrite_port_C(&ch, 1, fp))
270
259
ch = (char)dig_type_to_store(ptr->type);
271
260
G_debug(5, " line type %d -> %d", ptr->type, ch);
272
261
if (0 >= dig__fwrite_port_C(&ch, 1, fp))
274
if (0 >= dig__fwrite_port_L(&(ptr->offset), 1, fp))
265
if (0 >= dig__fwrite_port_O(&(ptr->offset), 1, fp, Plus->off_t_size))
278
if (ptr->type & (GV_POINTS | GV_LINES | GV_KERNEL))
279
if (0 >= dig__fwrite_port_P(&(ptr->N1), 1, fp))
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))
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))
293
if (ptr->type & GV_BOUNDARY)
294
if (0 >= dig__fwrite_port_P(&(ptr->right), 1, fp))
297
if ((ptr->type & GV_FACE) && Plus->with_z) { /* reserved for face */
271
/* nothing else for points */
274
if (ptr->type & GV_CENTROID) {
275
struct P_topo_c *topo = (struct P_topo_c *)ptr->topo;
277
if (0 >= dig__fwrite_port_P(&(topo->area), 1, fp))
281
else if (ptr->type & GV_LINE) {
282
struct P_topo_l *topo = (struct P_topo_l *)ptr->topo;
284
if (0 >= dig__fwrite_port_P(&(topo->N1), 1, fp))
286
if (0 >= dig__fwrite_port_P(&(topo->N2), 1, fp))
290
else if (ptr->type & GV_BOUNDARY) {
291
struct P_topo_b *topo = (struct P_topo_b *)ptr->topo;
293
if (0 >= dig__fwrite_port_P(&(topo->N1), 1, fp))
295
if (0 >= dig__fwrite_port_P(&(topo->N2), 1, fp))
297
if (0 >= dig__fwrite_port_P(&(topo->left), 1, fp))
299
if (0 >= dig__fwrite_port_P(&(topo->right), 1, fp))
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;
298
306
if (0 >= dig__fwrite_port_I(&n_edges, 1, fp))
301
309
/* here will be list of edges */
303
/* left / right volume */
304
if (0 >= dig__fwrite_port_P(&vol, 1, fp))
311
/* left / right volume / hole */
312
if (0 >= dig__fwrite_port_P(&(topo->left), 1, fp))
306
if (0 >= dig__fwrite_port_P(&vol, 1, fp))
314
if (0 >= dig__fwrite_port_P(&(topo->right), 1, fp))
310
if ((ptr->type & GV_KERNEL) && Plus->with_z) /* reserved for kernel (volume number) */
311
if (0 >= dig__fwrite_port_P(&vol, 1, fp))
315
if (ptr->type & (GV_LINE | GV_BOUNDARY | GV_FACE)) {
316
if (0 >= dig__fwrite_port_D(&(ptr->N), 1, fp))
318
if (0 >= dig__fwrite_port_D(&(ptr->S), 1, fp))
320
if (0 >= dig__fwrite_port_D(&(ptr->E), 1, fp))
322
if (0 >= dig__fwrite_port_D(&(ptr->W), 1, fp))
326
if (0 >= dig__fwrite_port_D(&(ptr->T), 1, fp))
328
if (0 >= dig__fwrite_port_D(&(ptr->B), 1, fp))
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;
322
if (0 >= dig__fwrite_port_P(&(topo->volume), 1, fp))
336
int dig_Rd_P_area(struct Plus_head *Plus, int n, GVFILE * fp)
329
int dig_Rd_P_area(struct Plus_head *Plus, int n, struct gvfile * fp)
342
G_debug(3, "dig_Rd_P_area(): n = %d", n);
334
G_debug(4, "dig_Rd_P_area(): n = %d", n);
345
336
if (0 >= dig__fread_port_P(&cnt, 1, fp))
574
496
/* bytes 1 - 5 */
575
if (0 >= dig__fread_port_C(buf, 5, fp))
497
if (0 >= dig__fread_port_C((char *)buf, 5, fp))
577
ptr->Version_Major = buf[0];
578
ptr->Version_Minor = buf[1];
579
ptr->Back_Major = buf[2];
580
ptr->Back_Minor = buf[3];
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];
581
503
byte_order = buf[4];
584
506
"Topo header: file version %d.%d , supported from GRASS version %d.%d",
585
ptr->Version_Major, ptr->Version_Minor, ptr->Back_Major,
507
ptr->version.topo.major, ptr->version.topo.minor, ptr->version.topo.back_major,
508
ptr->version.topo.back_minor);
588
510
G_debug(2, " byte order %d", byte_order);
590
512
/* check version numbers */
591
if (ptr->Version_Major > GV_TOPO_VER_MAJOR ||
592
ptr->Version_Minor > GV_TOPO_VER_MINOR) {
513
if (ptr->version.topo.major > GV_TOPO_VER_MAJOR ||
514
ptr->version.topo.minor > GV_TOPO_VER_MINOR) {
593
515
/* The file was created by GRASS library with higher version than this one */
595
if (ptr->Back_Major > GV_TOPO_VER_MAJOR ||
596
ptr->Back_Minor > GV_TOPO_VER_MINOR) {
517
if (ptr->version.topo.back_major > GV_TOPO_VER_MAJOR ||
518
ptr->version.topo.back_minor > GV_TOPO_VER_MINOR) {
597
519
/* This version of GRASS lib is lower than the oldest which can read this format */
598
520
G_debug(1, "Topology format version %d.%d",
599
ptr->Version_Major, ptr->Version_Minor);
521
ptr->version.topo.major, ptr->version.topo.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.",
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."),
603
525
GRASS_VERSION_MAJOR, GRASS_VERSION_MINOR, GRASS_VERSION_MAJOR + 1);
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);
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);
533
if (ptr->version.topo.major < GV_TOPO_VER_MAJOR ||
534
(ptr->version.topo.major == GV_TOPO_VER_MAJOR &&
535
ptr->version.topo.minor < GV_TOPO_VER_MINOR)) {
536
/* The file was created by GRASS library with lower version than this one */
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."),
541
ptr->version.topo.major, ptr->version.topo.minor);
545
/* init Port_info structure and set as default */
613
546
dig_init_portable(&(ptr->port), byte_order);
614
547
dig_set_cur_port(&(ptr->port));
671
619
/* bytes 111 - 138 : Offset */
672
if (0 >= dig__fread_port_L(&(ptr->Node_offset), 1, fp))
674
if (0 >= dig__fread_port_L(&(ptr->Edge_offset), 1, fp))
676
if (0 >= dig__fread_port_L(&(ptr->Line_offset), 1, fp))
678
if (0 >= dig__fread_port_L(&(ptr->Area_offset), 1, fp))
680
if (0 >= dig__fread_port_L(&(ptr->Isle_offset), 1, fp))
682
if (0 >= dig__fread_port_L(&(ptr->Volume_offset), 1, fp))
684
if (0 >= dig__fread_port_L(&(ptr->Hole_offset), 1, fp))
620
if (0 >= dig__fread_port_O(&(ptr->Node_offset), 1, fp, ptr->off_t_size))
622
if (0 >= dig__fread_port_O(&(ptr->Edge_offset), 1, fp, ptr->off_t_size))
624
if (0 >= dig__fread_port_O(&(ptr->Line_offset), 1, fp, ptr->off_t_size))
626
if (0 >= dig__fread_port_O(&(ptr->Area_offset), 1, fp, ptr->off_t_size))
628
if (0 >= dig__fread_port_O(&(ptr->Isle_offset), 1, fp, ptr->off_t_size))
630
if (0 >= dig__fread_port_O(&(ptr->Volume_offset), 1, fp, ptr->off_t_size))
632
if (0 >= dig__fread_port_O(&(ptr->Hole_offset), 1, fp, ptr->off_t_size))
687
635
/* bytes 139 - 142 : Coor size and time */
688
if (0 >= dig__fread_port_L(&(ptr->coor_size), 1, fp))
636
if (0 >= dig__fread_port_O(&(ptr->coor_size), 1, fp, ptr->off_t_size))
691
G_debug(2, " coor size %ld", ptr->coor_size);
639
G_debug(2, " coor size %"PRI_OFF_T, ptr->coor_size);
693
641
dig_fseek(fp, ptr->head_size, SEEK_SET);
698
int dig_Wr_Plus_head(GVFILE * fp, struct Plus_head *ptr)
646
int dig_Wr_Plus_head(struct gvfile * fp, struct Plus_head *ptr)
700
648
unsigned char buf[10];
701
649
long length = 142;
768
732
/* bytes 111 - 138 : Offset */
769
if (0 >= dig__fwrite_port_L(&(ptr->Node_offset), 1, fp))
771
if (0 >= dig__fwrite_port_L(&(ptr->Edge_offset), 1, fp))
773
if (0 >= dig__fwrite_port_L(&(ptr->Line_offset), 1, fp))
775
if (0 >= dig__fwrite_port_L(&(ptr->Area_offset), 1, fp))
777
if (0 >= dig__fwrite_port_L(&(ptr->Isle_offset), 1, fp))
779
if (0 >= dig__fwrite_port_L(&(ptr->Volume_offset), 1, fp))
781
if (0 >= dig__fwrite_port_L(&(ptr->Hole_offset), 1, fp))
733
if (0 >= dig__fwrite_port_O(&(ptr->Node_offset), 1, fp, ptr->off_t_size))
735
if (0 >= dig__fwrite_port_O(&(ptr->Edge_offset), 1, fp, ptr->off_t_size))
737
if (0 >= dig__fwrite_port_O(&(ptr->Line_offset), 1, fp, ptr->off_t_size))
739
if (0 >= dig__fwrite_port_O(&(ptr->Area_offset), 1, fp, ptr->off_t_size))
741
if (0 >= dig__fwrite_port_O(&(ptr->Isle_offset), 1, fp, ptr->off_t_size))
743
if (0 >= dig__fwrite_port_O(&(ptr->Volume_offset), 1, fp, ptr->off_t_size))
745
if (0 >= dig__fwrite_port_O(&(ptr->Hole_offset), 1, fp, ptr->off_t_size))
784
748
/* bytes 139 - 142 : Coor size and time */
785
if (0 >= dig__fwrite_port_L(&(ptr->coor_size), 1, fp))
749
if (0 >= dig__fwrite_port_O(&(ptr->coor_size), 1, fp, ptr->off_t_size))
788
G_debug(2, "topo body offset %ld", dig_ftell(fp));
752
G_debug(2, "topo body offset %"PRI_OFF_T, dig_ftell(fp));