/* Write spatial index */ int dig_write_cidx(GVFILE * fp, struct Plus_head *plus) { int i; dig_set_cur_port(&(plus->cidx_port)); dig_rewind(fp); dig_write_cidx_head(fp, plus); /* Write category-type-id for each field */ for (i = 0; i < plus->n_cidx; i++) { int j; struct Cat_index *ci; ci = &(plus->cidx[i]); ci->offset = dig_ftell(fp); /* convert type */ for (j = 0; j < ci->n_cats; j++) ci->cat[j][1] = dig_type_to_store(ci->cat[j][1]); if (0 >= dig__fwrite_port_I((int *)ci->cat, 3 * ci->n_cats, fp)) return (-1); /* Return back */ for (j = 0; j < ci->n_cats; j++) ci->cat[j][1] = dig_type_from_store(ci->cat[j][1]); } dig_write_cidx_head(fp, plus); /* rewrite with offsets */ return 0; }
int dig_Wr_P_line(struct Plus_head *Plus, int n, struct gvfile * fp) { int n_edges = 0; char ch; struct P_line *ptr; G_debug(4, "dig_Wr_P_line() line = %d", n); ptr = Plus->Line[n]; /* if NULL i.e. dead write just 0 instead of type */ if (ptr == NULL) { G_debug(4, " line is dead -> write 0 only"); ch = 0; if (0 >= dig__fwrite_port_C(&ch, 1, fp)) return (-1); return 0; } /* type */ ch = (char)dig_type_to_store(ptr->type); G_debug(5, " line type %d -> %d", ptr->type, ch); if (0 >= dig__fwrite_port_C(&ch, 1, fp)) return (-1); /* offset */ if (0 >= dig__fwrite_port_O(&(ptr->offset), 1, fp, Plus->off_t_size)) return (-1); if (!ptr->topo) return (0); /* nothing else for points */ /* centroids */ if (ptr->type & GV_CENTROID) { struct P_topo_c *topo = (struct P_topo_c *)ptr->topo; if (0 >= dig__fwrite_port_P(&(topo->area), 1, fp)) return (-1); } /* lines */ else if (ptr->type & GV_LINE) { struct P_topo_l *topo = (struct P_topo_l *)ptr->topo; if (0 >= dig__fwrite_port_P(&(topo->N1), 1, fp)) return (-1); if (0 >= dig__fwrite_port_P(&(topo->N2), 1, fp)) return (-1); } /* boundaries */ else if (ptr->type & GV_BOUNDARY) { struct P_topo_b *topo = (struct P_topo_b *)ptr->topo; if (0 >= dig__fwrite_port_P(&(topo->N1), 1, fp)) return (-1); if (0 >= dig__fwrite_port_P(&(topo->N2), 1, fp)) return (-1); if (0 >= dig__fwrite_port_P(&(topo->left), 1, fp)) return (-1); if (0 >= dig__fwrite_port_P(&(topo->right), 1, fp)) return (-1); } /* faces */ else if ((ptr->type & GV_FACE) && Plus->with_z) { /* reserved for face */ struct P_topo_f *topo = (struct P_topo_f *)ptr->topo; if (0 >= dig__fwrite_port_I(&n_edges, 1, fp)) return (-1); /* here will be list of edges */ /* left / right volume / hole */ if (0 >= dig__fwrite_port_P(&(topo->left), 1, fp)) return (-1); if (0 >= dig__fwrite_port_P(&(topo->right), 1, fp)) return (-1); } /* kernels */ else if ((ptr->type & GV_KERNEL) && Plus->with_z) { /* reserved for kernel (volume number) */ struct P_topo_k *topo = (struct P_topo_k *)ptr->topo; /* volume */ if (0 >= dig__fwrite_port_P(&(topo->volume), 1, fp)) return (-1); } return (0); }
int dig_write_cidx_head(GVFILE * fp, struct Plus_head *plus) { int i; unsigned char buf[5]; long length = 9; G_debug(3, "dig_write_cidx_head()"); dig_rewind(fp); dig_set_cur_port(&(plus->cidx_port)); /* Head of header */ /* bytes 1 - 5 */ buf[0] = GV_CIDX_VER_MAJOR; buf[1] = GV_CIDX_VER_MINOR; buf[2] = GV_CIDX_EARLIEST_MAJOR; buf[3] = GV_CIDX_EARLIEST_MINOR; buf[4] = plus->cidx_port.byte_order; if (0 >= dig__fwrite_port_C(buf, 5, fp)) return (-1); /* bytes 6 - 9 : header size */ if (0 >= dig__fwrite_port_L(&length, 1, fp)) return (0); /* Body of header - info about all fields */ /* Number of fields */ if (0 >= dig__fwrite_port_I(&(plus->n_cidx), 1, fp)) return (-1); for (i = 0; i < plus->n_cidx; i++) { int t; struct Cat_index *ci; ci = &(plus->cidx[i]); G_debug(3, "cidx %d head offset: %ld", i, dig_ftell(fp)); /* Field number */ if (0 >= dig__fwrite_port_I(&(ci->field), 1, fp)) return (-1); /* Number of categories */ if (0 >= dig__fwrite_port_I(&(ci->n_cats), 1, fp)) return (-1); /* Number of unique categories */ if (0 >= dig__fwrite_port_I(&(ci->n_ucats), 1, fp)) return (-1); /* Number of types */ if (0 >= dig__fwrite_port_I(&(ci->n_types), 1, fp)) return (-1); /* Types */ for (t = 0; t < ci->n_types; t++) { int wtype; /* type */ wtype = dig_type_to_store(ci->type[t][0]); if (0 >= dig__fwrite_port_I(&wtype, 1, fp)) return (-1); /* number of items */ if (0 >= dig__fwrite_port_I(&(ci->type[t][1]), 1, fp)) return (-1); } /* Offset */ if (0 >= dig__fwrite_port_L(&(ci->offset), 1, fp)) return (0); G_debug(3, "cidx %d offset: %ld", i, ci->offset); } G_debug(3, "cidx body offset %ld", dig_ftell(fp)); return (0); }
int dig_write_cidx_head(struct gvfile * fp, struct Plus_head *plus) { int i; unsigned char buf[5]; long length = 9; G_debug(3, "dig_write_cidx_head()"); dig_rewind(fp); dig_set_cur_port(&(plus->cidx_port)); /* Head of header */ /* bytes 1 - 5 */ buf[0] = GV_CIDX_VER_MAJOR; buf[1] = GV_CIDX_VER_MINOR; buf[2] = GV_CIDX_EARLIEST_MAJOR; buf[3] = GV_CIDX_EARLIEST_MINOR; buf[4] = plus->cidx_port.byte_order; if (0 >= dig__fwrite_port_C((const char *)buf, 5, fp)) return (-1); /* get required offset size */ if (plus->off_t_size == 0) { /* should not happen, topo is written first */ if (plus->coor_size > (off_t)PORT_LONG_MAX) plus->off_t_size = 8; else plus->off_t_size = 4; } /* bytes 6 - 9 : header size */ if (0 >= dig__fwrite_port_L(&length, 1, fp)) return (0); /* Body of header - info about all fields */ /* Number of fields */ if (0 >= dig__fwrite_port_I(&(plus->n_cidx), 1, fp)) return (-1); for (i = 0; i < plus->n_cidx; i++) { int t; struct Cat_index *ci; ci = &(plus->cidx[i]); G_debug(3, "cidx %d head offset: %"PRI_OFF_T, i, dig_ftell(fp)); /* Field number */ if (0 >= dig__fwrite_port_I(&(ci->field), 1, fp)) return (-1); /* Number of categories */ if (0 >= dig__fwrite_port_I(&(ci->n_cats), 1, fp)) return (-1); /* Number of unique categories */ if (0 >= dig__fwrite_port_I(&(ci->n_ucats), 1, fp)) return (-1); /* Number of types */ if (0 >= dig__fwrite_port_I(&(ci->n_types), 1, fp)) return (-1); /* Types */ for (t = 0; t < ci->n_types; t++) { int wtype; /* type */ wtype = dig_type_to_store(ci->type[t][0]); if (0 >= dig__fwrite_port_I(&wtype, 1, fp)) return (-1); /* number of items */ if (0 >= dig__fwrite_port_I(&(ci->type[t][1]), 1, fp)) return (-1); } /* Offset */ if (0 >= dig__fwrite_port_O(&(ci->offset), 1, fp, plus->off_t_size)) return (0); G_debug(3, "cidx %d offset: %"PRI_OFF_T, i, ci->offset); } G_debug(3, "cidx body offset %"PRI_OFF_T, dig_ftell(fp)); return (0); }