GRASS Programmer's Manual
6.4.2(2012)
|
00001 /* 00002 **************************************************************************** 00003 * 00004 * MODULE: Vector library 00005 * 00006 * AUTHOR(S): Dave Gerdes, CERL. 00007 * Update to GRASS 5.7 Radim Blazek. 00008 * 00009 * PURPOSE: Lower level functions for reading/writing/manipulating vectors. 00010 * 00011 * COPYRIGHT: (C) 2001 by the GRASS Development Team 00012 * 00013 * This program is free software under the GNU General Public 00014 * License (>=v2). Read the file COPYING that comes with GRASS 00015 * for details. 00016 * 00017 *****************************************************************************/ 00018 #include <string.h> 00019 #include <grass/gis.h> 00020 #include <grass/Vect.h> 00021 00022 /* 00023 * Routines for reading and writing Dig+ structures. 00024 * return 0 on success, -1 on failure of whatever kind 00025 * if you dont want it written out, then dont call these routines 00026 * ie check for deleted status before calling a write routine 00027 * in as much as it would be nice to hide that code in here, 00028 * this is a library routine and we chose to make it dependent on 00029 * as few external files as possible 00030 */ 00031 00032 /* These routines assume ptr->alloc_lines is valid 00033 * Make sure it is initialized before calling 00034 */ 00035 00036 /* 00037 * Internally, my default variables for lines/areas/nodes/isles are type 00038 * plus_t which is typedefed as short. This limits the current version 00039 * to no more than 32K lines, nodes etc. (excluding points) 00040 * All in the name of future expansion, I have converted these values to 00041 * longs in the dig_plus data file. 00042 * 00043 * NOTE: 3.10 changes plus_t to ints. 00044 * This assumes that any reasonable machine will use 4 bytes to 00045 * store an int. The mapdev code is not guaranteed to work if 00046 * plus_t is changed to a type that is larger than an int. 00047 */ 00048 00049 int dig_Rd_P_node(struct Plus_head *Plus, int n, GVFILE * fp) 00050 { 00051 int cnt, n_edges; 00052 P_NODE *ptr; 00053 00054 G_debug(3, "dig_Rd_P_node()"); 00055 00056 00057 if (0 >= dig__fread_port_P(&cnt, 1, fp)) 00058 return (-1); 00059 00060 if (cnt == 0) { /* dead */ 00061 G_debug(3, " node is dead"); 00062 Plus->Node[n] = NULL; 00063 return 0; 00064 } 00065 00066 ptr = dig_alloc_node(); 00067 ptr->n_lines = cnt; 00068 00069 if (dig_node_alloc_line(ptr, ptr->n_lines) == -1) 00070 return -1; 00071 00072 if (ptr->n_lines) { 00073 if (0 >= dig__fread_port_P(ptr->lines, ptr->n_lines, fp)) 00074 return (-1); 00075 if (0 >= dig__fread_port_F(ptr->angles, ptr->n_lines, fp)) 00076 return (-1); 00077 } 00078 00079 if (Plus->with_z) 00080 if (0 >= dig__fread_port_P(&n_edges, 1, fp)) /* reserved for edges */ 00081 return (-1); 00082 00083 /* here will be edges */ 00084 00085 if (0 >= dig__fread_port_D(&(ptr->x), 1, fp)) 00086 return (-1); 00087 if (0 >= dig__fread_port_D(&(ptr->y), 1, fp)) 00088 return (-1); 00089 00090 if (Plus->with_z) { 00091 if (0 >= dig__fread_port_D(&(ptr->z), 1, fp)) 00092 return (-1); 00093 } 00094 else 00095 ptr->z = 0; 00096 00097 00098 Plus->Node[n] = ptr; 00099 00100 return (0); 00101 } 00102 00103 int dig_Wr_P_node(struct Plus_head *Plus, int n, GVFILE * fp) 00104 { 00105 int i, n_edges = 0; 00106 P_NODE *ptr; 00107 00108 G_debug(3, "dig_Wr_P_node()"); 00109 ptr = Plus->Node[n]; 00110 00111 /* If NULL i.e. dead write just 0 instead of number of lines */ 00112 if (ptr == NULL) { 00113 G_debug(3, " node is dead -> write 0 only"); 00114 i = 0; 00115 if (0 >= dig__fwrite_port_P(&i, 1, fp)) 00116 return (-1); 00117 return 0; 00118 } 00119 00120 if (0 >= dig__fwrite_port_P(&(ptr->n_lines), 1, fp)) 00121 return (-1); 00122 00123 if (ptr->n_lines) { 00124 if (0 >= dig__fwrite_port_P(ptr->lines, ptr->n_lines, fp)) 00125 return (-1); 00126 if (0 >= dig__fwrite_port_F(ptr->angles, ptr->n_lines, fp)) 00127 return (-1); 00128 } 00129 00130 if (Plus->with_z) 00131 if (0 >= dig__fwrite_port_P(&n_edges, 1, fp)) /* reserved for edges */ 00132 return (-1); 00133 00134 /* here will be edges */ 00135 00136 if (0 >= dig__fwrite_port_D(&(ptr->x), 1, fp)) 00137 return (-1); 00138 if (0 >= dig__fwrite_port_D(&(ptr->y), 1, fp)) 00139 return (-1); 00140 00141 if (Plus->with_z) 00142 if (0 >= dig__fwrite_port_D(&(ptr->z), 1, fp)) 00143 return (-1); 00144 00145 return (0); 00146 } 00147 00148 int dig_Rd_P_line(struct Plus_head *Plus, int n, GVFILE * fp) 00149 { 00150 int n_edges, vol; 00151 char tp; 00152 P_LINE *ptr; 00153 P_NODE *Node; 00154 00155 G_debug(3, "dig_Rd_P_line()"); 00156 00157 if (0 >= dig__fread_port_C(&tp, 1, fp)) 00158 return (-1); 00159 00160 if (tp == 0) { /* dead */ 00161 G_debug(3, " line is dead"); 00162 Plus->Line[n] = NULL; 00163 return 0; 00164 } 00165 00166 ptr = dig_alloc_line(); 00167 00168 ptr->type = dig_type_from_store(tp); 00169 G_debug(5, " line type %d -> %d", tp, ptr->type); 00170 00171 if (0 >= dig__fread_port_L(&(ptr->offset), 1, fp)) 00172 return (-1); 00173 00174 /* First node */ 00175 if (ptr->type & (GV_POINTS | GV_LINES | GV_KERNEL)) 00176 if (0 >= dig__fread_port_P(&(ptr->N1), 1, fp)) 00177 return -1; 00178 00179 /* Second node, for points/centroids not needed */ 00180 if (ptr->type & (GV_LINE | GV_BOUNDARY)) { 00181 if (0 >= dig__fread_port_P(&(ptr->N2), 1, fp)) 00182 return -1; 00183 } 00184 else if (ptr->type & (GV_POINTS | GV_KERNEL)) 00185 ptr->N2 = ptr->N1; 00186 00187 /* left area for boundary, area for centroid */ 00188 if (ptr->type & (GV_BOUNDARY | GV_CENTROID)) 00189 if (0 >= dig__fread_port_P(&(ptr->left), 1, fp)) 00190 return -1; 00191 00192 /* right area */ 00193 if (ptr->type & GV_BOUNDARY) 00194 if (0 >= dig__fread_port_P(&(ptr->right), 1, fp)) 00195 return -1; 00196 00197 if ((ptr->type & GV_FACE) && Plus->with_z) { /* reserved for face edges */ 00198 if (0 >= dig__fread_port_I(&n_edges, 1, fp)) 00199 return -1; 00200 00201 /* here will be list of edges */ 00202 00203 /* left / right volume */ 00204 if (0 >= dig__fread_port_P(&vol, 1, fp)) 00205 return -1; 00206 if (0 >= dig__fread_port_P(&vol, 1, fp)) 00207 return -1; 00208 } 00209 00210 if ((ptr->type & GV_KERNEL) && Plus->with_z) /* reserved for kernel (volume number) */ 00211 if (0 >= dig__fread_port_P(&vol, 1, fp)) 00212 return -1; 00213 00214 /* Bounding box */ 00215 if (ptr->type & (GV_LINE | GV_BOUNDARY | GV_FACE)) { 00216 if (0 >= dig__fread_port_D(&(ptr->N), 1, fp)) 00217 return -1; 00218 if (0 >= dig__fread_port_D(&(ptr->S), 1, fp)) 00219 return -1; 00220 if (0 >= dig__fread_port_D(&(ptr->E), 1, fp)) 00221 return -1; 00222 if (0 >= dig__fread_port_D(&(ptr->W), 1, fp)) 00223 return -1; 00224 00225 if (Plus->with_z) { 00226 if (0 >= dig__fread_port_D(&(ptr->T), 1, fp)) 00227 return -1; 00228 if (0 >= dig__fread_port_D(&(ptr->B), 1, fp)) 00229 return -1; 00230 } 00231 else { 00232 ptr->T = 0.0; 00233 ptr->B = 0.0; 00234 } 00235 } 00236 else { 00237 Node = Plus->Node[ptr->N1]; 00238 ptr->N = Node->y; 00239 ptr->S = Node->y; 00240 ptr->E = Node->x; 00241 ptr->W = Node->x; 00242 ptr->T = Node->z; 00243 ptr->B = Node->z; 00244 } 00245 00246 Plus->Line[n] = ptr; 00247 return (0); 00248 } 00249 00250 int dig_Wr_P_line(struct Plus_head *Plus, int n, GVFILE * fp) 00251 { 00252 int n_edges = 0, vol = 0; 00253 char ch; 00254 P_LINE *ptr; 00255 00256 G_debug(4, "dig_Wr_P_line() line = %d", n); 00257 00258 ptr = Plus->Line[n]; 00259 00260 /* If NULL i.e. dead write just 0 instead of type */ 00261 if (ptr == NULL) { 00262 G_debug(3, " line is dead -> write 0 only"); 00263 ch = 0; 00264 if (0 >= dig__fwrite_port_C(&ch, 1, fp)) 00265 return (-1); 00266 return 0; 00267 } 00268 00269 ch = (char)dig_type_to_store(ptr->type); 00270 G_debug(5, " line type %d -> %d", ptr->type, ch); 00271 if (0 >= dig__fwrite_port_C(&ch, 1, fp)) 00272 return (-1); 00273 if (0 >= dig__fwrite_port_L(&(ptr->offset), 1, fp)) 00274 return (-1); 00275 00276 /* First node */ 00277 if (ptr->type & (GV_POINTS | GV_LINES | GV_KERNEL)) 00278 if (0 >= dig__fwrite_port_P(&(ptr->N1), 1, fp)) 00279 return (-1); 00280 00281 /* Second node, for points/centroids not needed */ 00282 if (ptr->type & (GV_LINE | GV_BOUNDARY)) 00283 if (0 >= dig__fwrite_port_P(&(ptr->N2), 1, fp)) 00284 return (-1); 00285 00286 /* left area for boundary, area for centroid */ 00287 if (ptr->type & (GV_BOUNDARY | GV_CENTROID)) 00288 if (0 >= dig__fwrite_port_P(&(ptr->left), 1, fp)) 00289 return (-1); 00290 00291 /* right area */ 00292 if (ptr->type & GV_BOUNDARY) 00293 if (0 >= dig__fwrite_port_P(&(ptr->right), 1, fp)) 00294 return (-1); 00295 00296 if ((ptr->type & GV_FACE) && Plus->with_z) { /* reserved for face */ 00297 if (0 >= dig__fwrite_port_I(&n_edges, 1, fp)) 00298 return (-1); 00299 00300 /* here will be list of edges */ 00301 00302 /* left / right volume */ 00303 if (0 >= dig__fwrite_port_P(&vol, 1, fp)) 00304 return (-1); 00305 if (0 >= dig__fwrite_port_P(&vol, 1, fp)) 00306 return (-1); 00307 } 00308 00309 if ((ptr->type & GV_KERNEL) && Plus->with_z) /* reserved for kernel (volume number) */ 00310 if (0 >= dig__fwrite_port_P(&vol, 1, fp)) 00311 return (-1); 00312 00313 /* Bounding box */ 00314 if (ptr->type & (GV_LINE | GV_BOUNDARY | GV_FACE)) { 00315 if (0 >= dig__fwrite_port_D(&(ptr->N), 1, fp)) 00316 return (-1); 00317 if (0 >= dig__fwrite_port_D(&(ptr->S), 1, fp)) 00318 return (-1); 00319 if (0 >= dig__fwrite_port_D(&(ptr->E), 1, fp)) 00320 return (-1); 00321 if (0 >= dig__fwrite_port_D(&(ptr->W), 1, fp)) 00322 return (-1); 00323 00324 if (Plus->with_z) { 00325 if (0 >= dig__fwrite_port_D(&(ptr->T), 1, fp)) 00326 return (-1); 00327 if (0 >= dig__fwrite_port_D(&(ptr->B), 1, fp)) 00328 return (-1); 00329 } 00330 } 00331 00332 return (0); 00333 } 00334 00335 int dig_Rd_P_area(struct Plus_head *Plus, int n, GVFILE * fp) 00336 { 00337 int cnt; 00338 P_AREA *ptr; 00339 00340 #ifdef GDEBUG 00341 G_debug(3, "dig_Rd_P_area(): n = %d", n); 00342 #endif 00343 00344 if (0 >= dig__fread_port_P(&cnt, 1, fp)) 00345 return (-1); 00346 00347 if (cnt == 0) { /* dead */ 00348 Plus->Area[n] = NULL; 00349 return 0; 00350 } 00351 00352 ptr = dig_alloc_area(); 00353 00354 /* lines */ 00355 ptr->n_lines = cnt; 00356 00357 if (dig_area_alloc_line(ptr, ptr->n_lines) == -1) 00358 return -1; 00359 00360 if (ptr->n_lines) 00361 if (0 >= dig__fread_port_P(ptr->lines, ptr->n_lines, fp)) 00362 return -1; 00363 00364 /* isles */ 00365 if (0 >= dig__fread_port_P(&(ptr->n_isles), 1, fp)) 00366 return -1; 00367 00368 if (dig_area_alloc_isle(ptr, ptr->n_isles) == -1) 00369 return -1; 00370 00371 if (ptr->n_isles) 00372 if (0 >= dig__fread_port_P(ptr->isles, ptr->n_isles, fp)) 00373 return -1; 00374 00375 /* centroid */ 00376 if (0 >= dig__fread_port_P(&(ptr->centroid), 1, fp)) 00377 return -1; 00378 00379 if (0 >= dig__fread_port_D(&(ptr->N), 1, fp)) 00380 return -1; 00381 if (0 >= dig__fread_port_D(&(ptr->S), 1, fp)) 00382 return -1; 00383 if (0 >= dig__fread_port_D(&(ptr->E), 1, fp)) 00384 return -1; 00385 if (0 >= dig__fread_port_D(&(ptr->W), 1, fp)) 00386 return -1; 00387 00388 if (Plus->with_z) { 00389 if (0 >= dig__fread_port_D(&(ptr->T), 1, fp)) 00390 return -1; 00391 if (0 >= dig__fread_port_D(&(ptr->B), 1, fp)) 00392 return -1; 00393 } 00394 else { 00395 ptr->T = 0.0; 00396 ptr->B = 0.0; 00397 } 00398 00399 Plus->Area[n] = ptr; 00400 00401 return (0); 00402 } 00403 00404 int dig_Wr_P_area(struct Plus_head *Plus, int n, GVFILE * fp) 00405 { 00406 int i; 00407 P_AREA *ptr; 00408 00409 ptr = Plus->Area[n]; 00410 00411 /* If NULL i.e. dead write just 0 instead of number of lines */ 00412 if (ptr == NULL) { 00413 i = 0; 00414 if (0 >= dig__fwrite_port_P(&i, 1, fp)) 00415 return (-1); 00416 return 0; 00417 } 00418 00419 /* lines */ 00420 if (0 >= dig__fwrite_port_P(&(ptr->n_lines), 1, fp)) 00421 return (-1); 00422 00423 if (ptr->n_lines) 00424 if (0 >= dig__fwrite_port_P(ptr->lines, ptr->n_lines, fp)) 00425 return -1; 00426 00427 /* isles */ 00428 if (0 >= dig__fwrite_port_P(&(ptr->n_isles), 1, fp)) 00429 return (-1); 00430 00431 if (ptr->n_isles) 00432 if (0 >= dig__fwrite_port_P(ptr->isles, ptr->n_isles, fp)) 00433 return -1; 00434 00435 /* centroid */ 00436 if (0 >= dig__fwrite_port_P(&(ptr->centroid), 1, fp)) 00437 return (-1); 00438 00439 if (0 >= dig__fwrite_port_D(&(ptr->N), 1, fp)) 00440 return (-1); 00441 if (0 >= dig__fwrite_port_D(&(ptr->S), 1, fp)) 00442 return (-1); 00443 if (0 >= dig__fwrite_port_D(&(ptr->E), 1, fp)) 00444 return (-1); 00445 if (0 >= dig__fwrite_port_D(&(ptr->W), 1, fp)) 00446 return (-1); 00447 00448 if (Plus->with_z) { 00449 if (0 >= dig__fwrite_port_D(&(ptr->T), 1, fp)) 00450 return (-1); 00451 if (0 >= dig__fwrite_port_D(&(ptr->B), 1, fp)) 00452 return (-1); 00453 } 00454 00455 return (0); 00456 } 00457 00458 int dig_Rd_P_isle(struct Plus_head *Plus, int n, GVFILE * fp) 00459 { 00460 int cnt; 00461 P_ISLE *ptr; 00462 00463 #ifdef GDEBUG 00464 G_debug(3, "dig_Rd_P_isle()"); 00465 #endif 00466 00467 if (0 >= dig__fread_port_P(&cnt, 1, fp)) 00468 return (-1); 00469 00470 if (cnt == 0) { /* dead */ 00471 Plus->Isle[n] = NULL; 00472 return 0; 00473 } 00474 00475 ptr = dig_alloc_isle(); 00476 00477 /* lines */ 00478 ptr->n_lines = cnt; 00479 00480 if (dig_isle_alloc_line(ptr, ptr->n_lines) == -1) 00481 return -1; 00482 00483 if (ptr->n_lines) 00484 if (0 >= dig__fread_port_P(ptr->lines, ptr->n_lines, fp)) 00485 return -1; 00486 00487 /* area */ 00488 if (0 >= dig__fread_port_P(&(ptr->area), 1, fp)) 00489 return -1; 00490 00491 if (0 >= dig__fread_port_D(&(ptr->N), 1, fp)) 00492 return -1; 00493 if (0 >= dig__fread_port_D(&(ptr->S), 1, fp)) 00494 return -1; 00495 if (0 >= dig__fread_port_D(&(ptr->E), 1, fp)) 00496 return -1; 00497 if (0 >= dig__fread_port_D(&(ptr->W), 1, fp)) 00498 return -1; 00499 00500 if (Plus->with_z) { 00501 if (0 >= dig__fread_port_D(&(ptr->T), 1, fp)) 00502 return -1; 00503 if (0 >= dig__fread_port_D(&(ptr->B), 1, fp)) 00504 return -1; 00505 } 00506 else { 00507 ptr->T = 0.0; 00508 ptr->B = 0.0; 00509 } 00510 00511 Plus->Isle[n] = ptr; 00512 00513 return (0); 00514 } 00515 00516 int dig_Wr_P_isle(struct Plus_head *Plus, int n, GVFILE * fp) 00517 { 00518 int i; 00519 P_ISLE *ptr; 00520 00521 ptr = Plus->Isle[n]; 00522 00523 /* If NULL i.e. dead write just 0 instead of number of lines */ 00524 if (ptr == NULL) { 00525 i = 0; 00526 if (0 >= dig__fwrite_port_P(&i, 1, fp)) 00527 return (-1); 00528 return 0; 00529 } 00530 00531 /* lines */ 00532 if (0 >= dig__fwrite_port_P(&(ptr->n_lines), 1, fp)) 00533 return (-1); 00534 00535 if (ptr->n_lines) 00536 if (0 >= dig__fwrite_port_P(ptr->lines, ptr->n_lines, fp)) 00537 return -1; 00538 00539 /* area */ 00540 if (0 >= dig__fwrite_port_P(&(ptr->area), 1, fp)) 00541 return (-1); 00542 00543 if (0 >= dig__fwrite_port_D(&(ptr->N), 1, fp)) 00544 return (-1); 00545 if (0 >= dig__fwrite_port_D(&(ptr->S), 1, fp)) 00546 return (-1); 00547 if (0 >= dig__fwrite_port_D(&(ptr->E), 1, fp)) 00548 return (-1); 00549 if (0 >= dig__fwrite_port_D(&(ptr->W), 1, fp)) 00550 return (-1); 00551 00552 if (Plus->with_z) { 00553 if (0 >= dig__fwrite_port_D(&(ptr->T), 1, fp)) 00554 return (-1); 00555 if (0 >= dig__fwrite_port_D(&(ptr->B), 1, fp)) 00556 return (-1); 00557 } 00558 00559 return (0); 00560 } 00561 00562 /* 00563 \return -1 error 00564 \return 0 OK 00565 */ 00566 int dig_Rd_Plus_head(GVFILE * fp, struct Plus_head *ptr) 00567 { 00568 unsigned char buf[5]; 00569 int byte_order; 00570 00571 dig_rewind(fp); 00572 00573 /* bytes 1 - 5 */ 00574 if (0 >= dig__fread_port_C(buf, 5, fp)) 00575 return (-1); 00576 ptr->Version_Major = buf[0]; 00577 ptr->Version_Minor = buf[1]; 00578 ptr->Back_Major = buf[2]; 00579 ptr->Back_Minor = buf[3]; 00580 byte_order = buf[4]; 00581 00582 G_debug(2, 00583 "Topo header: file version %d.%d , supported from GRASS version %d.%d", 00584 ptr->Version_Major, ptr->Version_Minor, ptr->Back_Major, 00585 ptr->Back_Minor); 00586 00587 G_debug(2, " byte order %d", byte_order); 00588 00589 /* check version numbers */ 00590 if (ptr->Version_Major > GV_TOPO_VER_MAJOR || 00591 ptr->Version_Minor > GV_TOPO_VER_MINOR) { 00592 /* The file was created by GRASS library with higher version than this one */ 00593 00594 if (ptr->Back_Major > GV_TOPO_VER_MAJOR || 00595 ptr->Back_Minor > GV_TOPO_VER_MINOR) { 00596 /* This version of GRASS lib is lower than the oldest which can read this format */ 00597 G_fatal_error 00598 ("Topology format version %d.%d is not supported by this release." 00599 " Try to rebuild topology or upgrade GRASS.", 00600 ptr->Version_Major, ptr->Version_Minor); 00601 return (-1); 00602 } 00603 00604 G_warning 00605 ("Your GRASS version does not fully support topology format %d.%d of the vector." 00606 " Consider to rebuild topology or upgrade GRASS.", 00607 ptr->Version_Major, ptr->Version_Minor); 00608 } 00609 00610 dig_init_portable(&(ptr->port), byte_order); 00611 dig_set_cur_port(&(ptr->port)); 00612 00613 /* bytes 6 - 9 : header size */ 00614 if (0 >= dig__fread_port_L(&(ptr->head_size), 1, fp)) 00615 return (-1); 00616 G_debug(2, " header size %ld", ptr->head_size); 00617 00618 /* byte 10 : dimension 2D or 3D */ 00619 if (0 >= dig__fread_port_C(buf, 1, fp)) 00620 return (-1); 00621 ptr->with_z = buf[0]; 00622 G_debug(2, " with_z %d", ptr->with_z); 00623 00624 /* bytes 11 - 58 : bound box */ 00625 if (0 >= dig__fread_port_D(&(ptr->box.N), 1, fp)) 00626 return (-1); 00627 if (0 >= dig__fread_port_D(&(ptr->box.S), 1, fp)) 00628 return (-1); 00629 if (0 >= dig__fread_port_D(&(ptr->box.E), 1, fp)) 00630 return (-1); 00631 if (0 >= dig__fread_port_D(&(ptr->box.W), 1, fp)) 00632 return (-1); 00633 if (0 >= dig__fread_port_D(&(ptr->box.T), 1, fp)) 00634 return (-1); 00635 if (0 >= dig__fread_port_D(&(ptr->box.B), 1, fp)) 00636 return (-1); 00637 00638 /* bytes 59 - 86 : number of structures */ 00639 if (0 >= dig__fread_port_P(&(ptr->n_nodes), 1, fp)) 00640 return (-1); 00641 if (0 >= dig__fread_port_P(&(ptr->n_edges), 1, fp)) 00642 return (-1); 00643 if (0 >= dig__fread_port_P(&(ptr->n_lines), 1, fp)) 00644 return (-1); 00645 if (0 >= dig__fread_port_P(&(ptr->n_areas), 1, fp)) 00646 return (-1); 00647 if (0 >= dig__fread_port_P(&(ptr->n_isles), 1, fp)) 00648 return (-1); 00649 if (0 >= dig__fread_port_P(&(ptr->n_volumes), 1, fp)) 00650 return (-1); 00651 if (0 >= dig__fread_port_P(&(ptr->n_holes), 1, fp)) 00652 return (-1); 00653 00654 /* bytes 87 - 110 : number of line types */ 00655 if (0 >= dig__fread_port_P(&(ptr->n_plines), 1, fp)) 00656 return (-1); 00657 if (0 >= dig__fread_port_P(&(ptr->n_llines), 1, fp)) 00658 return (-1); 00659 if (0 >= dig__fread_port_P(&(ptr->n_blines), 1, fp)) 00660 return (-1); 00661 if (0 >= dig__fread_port_P(&(ptr->n_clines), 1, fp)) 00662 return (-1); 00663 if (0 >= dig__fread_port_P(&(ptr->n_flines), 1, fp)) 00664 return (-1); 00665 if (0 >= dig__fread_port_P(&(ptr->n_klines), 1, fp)) 00666 return (-1); 00667 00668 /* bytes 111 - 138 : Offset */ 00669 if (0 >= dig__fread_port_L(&(ptr->Node_offset), 1, fp)) 00670 return (-1); 00671 if (0 >= dig__fread_port_L(&(ptr->Edge_offset), 1, fp)) 00672 return (-1); 00673 if (0 >= dig__fread_port_L(&(ptr->Line_offset), 1, fp)) 00674 return (-1); 00675 if (0 >= dig__fread_port_L(&(ptr->Area_offset), 1, fp)) 00676 return (-1); 00677 if (0 >= dig__fread_port_L(&(ptr->Isle_offset), 1, fp)) 00678 return (-1); 00679 if (0 >= dig__fread_port_L(&(ptr->Volume_offset), 1, fp)) 00680 return (-1); 00681 if (0 >= dig__fread_port_L(&(ptr->Hole_offset), 1, fp)) 00682 return (-1); 00683 00684 /* bytes 139 - 142 : Coor size and time */ 00685 if (0 >= dig__fread_port_L(&(ptr->coor_size), 1, fp)) 00686 return (-1); 00687 00688 G_debug(2, " coor size %ld", ptr->coor_size); 00689 00690 dig_fseek(fp, ptr->head_size, SEEK_SET); 00691 00692 return (0); 00693 } 00694 00695 int dig_Wr_Plus_head(GVFILE * fp, struct Plus_head *ptr) 00696 { 00697 unsigned char buf[10]; 00698 long length = 142; 00699 00700 dig_rewind(fp); 00701 dig_set_cur_port(&(ptr->port)); 00702 00703 /* bytes 1 - 5 */ 00704 buf[0] = GV_TOPO_VER_MAJOR; 00705 buf[1] = GV_TOPO_VER_MINOR; 00706 buf[2] = GV_TOPO_EARLIEST_MAJOR; 00707 buf[3] = GV_TOPO_EARLIEST_MINOR; 00708 buf[4] = ptr->port.byte_order; 00709 if (0 >= dig__fwrite_port_C(buf, 5, fp)) 00710 return (-1); 00711 00712 /* bytes 6 - 9 : header size */ 00713 if (0 >= dig__fwrite_port_L(&length, 1, fp)) 00714 return (0); 00715 00716 /* byte 10 : dimension 2D or 3D */ 00717 buf[0] = ptr->with_z; 00718 if (0 >= dig__fwrite_port_C(buf, 1, fp)) 00719 return (0); 00720 00721 /* bytes 11 - 58 : bound box */ 00722 if (0 >= dig__fwrite_port_D(&(ptr->box.N), 1, fp)) 00723 return (-1); 00724 if (0 >= dig__fwrite_port_D(&(ptr->box.S), 1, fp)) 00725 return (-1); 00726 if (0 >= dig__fwrite_port_D(&(ptr->box.E), 1, fp)) 00727 return (-1); 00728 if (0 >= dig__fwrite_port_D(&(ptr->box.W), 1, fp)) 00729 return (-1); 00730 if (0 >= dig__fwrite_port_D(&(ptr->box.T), 1, fp)) 00731 return (-1); 00732 if (0 >= dig__fwrite_port_D(&(ptr->box.B), 1, fp)) 00733 return (-1); 00734 00735 /* bytes 59 - 86 : number of structures */ 00736 if (0 >= dig__fwrite_port_P(&(ptr->n_nodes), 1, fp)) 00737 return (-1); 00738 if (0 >= dig__fwrite_port_P(&(ptr->n_edges), 1, fp)) 00739 return (-1); 00740 if (0 >= dig__fwrite_port_P(&(ptr->n_lines), 1, fp)) 00741 return (-1); 00742 if (0 >= dig__fwrite_port_P(&(ptr->n_areas), 1, fp)) 00743 return (-1); 00744 if (0 >= dig__fwrite_port_P(&(ptr->n_isles), 1, fp)) 00745 return (-1); 00746 if (0 >= dig__fwrite_port_P(&(ptr->n_volumes), 1, fp)) 00747 return (-1); 00748 if (0 >= dig__fwrite_port_P(&(ptr->n_holes), 1, fp)) 00749 return (-1); 00750 00751 /* bytes 87 - 110 : number of line types */ 00752 if (0 >= dig__fwrite_port_P(&(ptr->n_plines), 1, fp)) 00753 return (-1); 00754 if (0 >= dig__fwrite_port_P(&(ptr->n_llines), 1, fp)) 00755 return (-1); 00756 if (0 >= dig__fwrite_port_P(&(ptr->n_blines), 1, fp)) 00757 return (-1); 00758 if (0 >= dig__fwrite_port_P(&(ptr->n_clines), 1, fp)) 00759 return (-1); 00760 if (0 >= dig__fwrite_port_P(&(ptr->n_flines), 1, fp)) 00761 return (-1); 00762 if (0 >= dig__fwrite_port_P(&(ptr->n_klines), 1, fp)) 00763 return (-1); 00764 00765 /* bytes 111 - 138 : Offset */ 00766 if (0 >= dig__fwrite_port_L(&(ptr->Node_offset), 1, fp)) 00767 return (-1); 00768 if (0 >= dig__fwrite_port_L(&(ptr->Edge_offset), 1, fp)) 00769 return (-1); 00770 if (0 >= dig__fwrite_port_L(&(ptr->Line_offset), 1, fp)) 00771 return (-1); 00772 if (0 >= dig__fwrite_port_L(&(ptr->Area_offset), 1, fp)) 00773 return (-1); 00774 if (0 >= dig__fwrite_port_L(&(ptr->Isle_offset), 1, fp)) 00775 return (-1); 00776 if (0 >= dig__fwrite_port_L(&(ptr->Volume_offset), 1, fp)) 00777 return (-1); 00778 if (0 >= dig__fwrite_port_L(&(ptr->Hole_offset), 1, fp)) 00779 return (-1); 00780 00781 /* bytes 139 - 142 : Coor size and time */ 00782 if (0 >= dig__fwrite_port_L(&(ptr->coor_size), 1, fp)) 00783 return (-1); 00784 00785 G_debug(2, "topo body offset %ld", dig_ftell(fp)); 00786 00787 return (0); 00788 }