plus_struct.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  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. /*
  22. * Routines for reading and writing Dig+ structures.
  23. * return 0 on success, -1 on failure of whatever kind
  24. * if you dont want it written out, then dont call these routines
  25. * ie check for deleted status before calling a write routine
  26. * in as much as it would be nice to hide that code in here,
  27. * this is a library routine and we chose to make it dependent on
  28. * as few external files as possible
  29. */
  30. /* These routines assume ptr->alloc_lines is valid
  31. * Make sure it is initialized before calling
  32. */
  33. /*
  34. * Internally, my default variables for lines/areas/nodes/isles are type
  35. * plus_t which is typedefed as short. This limits the current version
  36. * to no more than 32K lines, nodes etc. (excluding points)
  37. * All in the name of future expansion, I have converted these values to
  38. * longs in the dig_plus data file.
  39. *
  40. * NOTE: 3.10 changes plus_t to ints.
  41. * This assumes that any reasonable machine will use 4 bytes to
  42. * store an int. The mapdev code is not guaranteed to work if
  43. * plus_t is changed to a type that is larger than an int.
  44. */
  45. int dig_Rd_P_node(struct Plus_head *Plus, int n, GVFILE * fp)
  46. {
  47. int cnt, n_edges;
  48. P_NODE *ptr;
  49. G_debug(3, "dig_Rd_P_node()");
  50. if (0 >= dig__fread_port_P(&cnt, 1, fp))
  51. return (-1);
  52. if (cnt == 0) { /* dead */
  53. G_debug(3, " node is dead");
  54. Plus->Node[n] = NULL;
  55. return 0;
  56. }
  57. ptr = dig_alloc_node();
  58. ptr->n_lines = cnt;
  59. if (dig_node_alloc_line(ptr, ptr->n_lines) == -1)
  60. return -1;
  61. if (ptr->n_lines) {
  62. if (0 >= dig__fread_port_P(ptr->lines, ptr->n_lines, fp))
  63. return (-1);
  64. if (0 >= dig__fread_port_F(ptr->angles, ptr->n_lines, fp))
  65. return (-1);
  66. }
  67. if (Plus->with_z)
  68. if (0 >= dig__fread_port_P(&n_edges, 1, fp)) /* reserved for edges */
  69. return (-1);
  70. /* here will be edges */
  71. if (0 >= dig__fread_port_D(&(ptr->x), 1, fp))
  72. return (-1);
  73. if (0 >= dig__fread_port_D(&(ptr->y), 1, fp))
  74. return (-1);
  75. if (Plus->with_z) {
  76. if (0 >= dig__fread_port_D(&(ptr->z), 1, fp))
  77. return (-1);
  78. }
  79. else
  80. ptr->z = 0;
  81. Plus->Node[n] = ptr;
  82. return (0);
  83. }
  84. int dig_Wr_P_node(struct Plus_head *Plus, int n, GVFILE * fp)
  85. {
  86. int i, n_edges = 0;
  87. P_NODE *ptr;
  88. G_debug(3, "dig_Wr_P_node()");
  89. ptr = Plus->Node[n];
  90. /* If NULL i.e. dead write just 0 instead of number of lines */
  91. if (ptr == NULL) {
  92. G_debug(3, " node is dead -> write 0 only");
  93. i = 0;
  94. if (0 >= dig__fwrite_port_P(&i, 1, fp))
  95. return (-1);
  96. return 0;
  97. }
  98. if (0 >= dig__fwrite_port_P(&(ptr->n_lines), 1, fp))
  99. return (-1);
  100. if (ptr->n_lines) {
  101. if (0 >= dig__fwrite_port_P(ptr->lines, ptr->n_lines, fp))
  102. return (-1);
  103. if (0 >= dig__fwrite_port_F(ptr->angles, ptr->n_lines, fp))
  104. return (-1);
  105. }
  106. if (Plus->with_z)
  107. if (0 >= dig__fwrite_port_P(&n_edges, 1, fp)) /* reserved for edges */
  108. return (-1);
  109. /* here will be edges */
  110. if (0 >= dig__fwrite_port_D(&(ptr->x), 1, fp))
  111. return (-1);
  112. if (0 >= dig__fwrite_port_D(&(ptr->y), 1, fp))
  113. return (-1);
  114. if (Plus->with_z)
  115. if (0 >= dig__fwrite_port_D(&(ptr->z), 1, fp))
  116. return (-1);
  117. return (0);
  118. }
  119. int dig_Rd_P_line(struct Plus_head *Plus, int n, GVFILE * fp)
  120. {
  121. int n_edges, vol;
  122. char tp;
  123. P_LINE *ptr;
  124. P_NODE *Node;
  125. G_debug(3, "dig_Rd_P_line()");
  126. if (0 >= dig__fread_port_C(&tp, 1, fp))
  127. return (-1);
  128. if (tp == 0) { /* dead */
  129. G_debug(3, " line is dead");
  130. Plus->Line[n] = NULL;
  131. return 0;
  132. }
  133. ptr = dig_alloc_line();
  134. ptr->type = dig_type_from_store(tp);
  135. G_debug(5, " line type %d -> %d", tp, ptr->type);
  136. if (0 >= dig__fread_port_L(&(ptr->offset), 1, fp))
  137. return (-1);
  138. /* First node */
  139. if (ptr->type & (GV_POINTS | GV_LINES | GV_KERNEL))
  140. if (0 >= dig__fread_port_P(&(ptr->N1), 1, fp))
  141. return -1;
  142. /* Second node, for points/centroids not needed */
  143. if (ptr->type & (GV_LINE | GV_BOUNDARY)) {
  144. if (0 >= dig__fread_port_P(&(ptr->N2), 1, fp))
  145. return -1;
  146. }
  147. else if (ptr->type & (GV_POINTS | GV_KERNEL))
  148. ptr->N2 = ptr->N1;
  149. /* left area for boundary, area for centroid */
  150. if (ptr->type & (GV_BOUNDARY | GV_CENTROID))
  151. if (0 >= dig__fread_port_P(&(ptr->left), 1, fp))
  152. return -1;
  153. /* right area */
  154. if (ptr->type & GV_BOUNDARY)
  155. if (0 >= dig__fread_port_P(&(ptr->right), 1, fp))
  156. return -1;
  157. if ((ptr->type & GV_FACE) && Plus->with_z) { /* reserved for face edges */
  158. if (0 >= dig__fread_port_I(&n_edges, 1, fp))
  159. return -1;
  160. /* here will be list of edges */
  161. /* left / right volume */
  162. if (0 >= dig__fread_port_P(&vol, 1, fp))
  163. return -1;
  164. if (0 >= dig__fread_port_P(&vol, 1, fp))
  165. return -1;
  166. }
  167. if ((ptr->type & GV_KERNEL) && Plus->with_z) /* reserved for kernel (volume number) */
  168. if (0 >= dig__fread_port_P(&vol, 1, fp))
  169. return -1;
  170. /* Bounding box */
  171. if (ptr->type & (GV_LINE | GV_BOUNDARY | GV_FACE)) {
  172. if (0 >= dig__fread_port_D(&(ptr->N), 1, fp))
  173. return -1;
  174. if (0 >= dig__fread_port_D(&(ptr->S), 1, fp))
  175. return -1;
  176. if (0 >= dig__fread_port_D(&(ptr->E), 1, fp))
  177. return -1;
  178. if (0 >= dig__fread_port_D(&(ptr->W), 1, fp))
  179. return -1;
  180. if (Plus->with_z) {
  181. if (0 >= dig__fread_port_D(&(ptr->T), 1, fp))
  182. return -1;
  183. if (0 >= dig__fread_port_D(&(ptr->B), 1, fp))
  184. return -1;
  185. }
  186. else {
  187. ptr->T = 0.0;
  188. ptr->B = 0.0;
  189. }
  190. }
  191. else {
  192. Node = Plus->Node[ptr->N1];
  193. ptr->N = Node->y;
  194. ptr->S = Node->y;
  195. ptr->E = Node->x;
  196. ptr->W = Node->x;
  197. ptr->T = Node->z;
  198. ptr->B = Node->z;
  199. }
  200. Plus->Line[n] = ptr;
  201. return (0);
  202. }
  203. int dig_Wr_P_line(struct Plus_head *Plus, int n, GVFILE * fp)
  204. {
  205. int n_edges = 0, vol = 0;
  206. char ch;
  207. P_LINE *ptr;
  208. G_debug(4, "dig_Wr_P_line() line = %d", n);
  209. ptr = Plus->Line[n];
  210. /* If NULL i.e. dead write just 0 instead of type */
  211. if (ptr == NULL) {
  212. G_debug(3, " line is dead -> write 0 only");
  213. ch = 0;
  214. if (0 >= dig__fwrite_port_C(&ch, 1, fp))
  215. return (-1);
  216. return 0;
  217. }
  218. ch = (char)dig_type_to_store(ptr->type);
  219. G_debug(5, " line type %d -> %d", ptr->type, ch);
  220. if (0 >= dig__fwrite_port_C(&ch, 1, fp))
  221. return (-1);
  222. if (0 >= dig__fwrite_port_L(&(ptr->offset), 1, fp))
  223. return (-1);
  224. /* First node */
  225. if (ptr->type & (GV_POINTS | GV_LINES | GV_KERNEL))
  226. if (0 >= dig__fwrite_port_P(&(ptr->N1), 1, fp))
  227. return (-1);
  228. /* Second node, for points/centroids not needed */
  229. if (ptr->type & (GV_LINE | GV_BOUNDARY))
  230. if (0 >= dig__fwrite_port_P(&(ptr->N2), 1, fp))
  231. return (-1);
  232. /* left area for boundary, area for centroid */
  233. if (ptr->type & (GV_BOUNDARY | GV_CENTROID))
  234. if (0 >= dig__fwrite_port_P(&(ptr->left), 1, fp))
  235. return (-1);
  236. /* right area */
  237. if (ptr->type & GV_BOUNDARY)
  238. if (0 >= dig__fwrite_port_P(&(ptr->right), 1, fp))
  239. return (-1);
  240. if ((ptr->type & GV_FACE) && Plus->with_z) { /* reserved for face */
  241. if (0 >= dig__fwrite_port_I(&n_edges, 1, fp))
  242. return (-1);
  243. /* here will be list of edges */
  244. /* left / right volume */
  245. if (0 >= dig__fwrite_port_P(&vol, 1, fp))
  246. return (-1);
  247. if (0 >= dig__fwrite_port_P(&vol, 1, fp))
  248. return (-1);
  249. }
  250. if ((ptr->type & GV_KERNEL) && Plus->with_z) /* reserved for kernel (volume number) */
  251. if (0 >= dig__fwrite_port_P(&vol, 1, fp))
  252. return (-1);
  253. /* Bounding box */
  254. if (ptr->type & (GV_LINE | GV_BOUNDARY | GV_FACE)) {
  255. if (0 >= dig__fwrite_port_D(&(ptr->N), 1, fp))
  256. return (-1);
  257. if (0 >= dig__fwrite_port_D(&(ptr->S), 1, fp))
  258. return (-1);
  259. if (0 >= dig__fwrite_port_D(&(ptr->E), 1, fp))
  260. return (-1);
  261. if (0 >= dig__fwrite_port_D(&(ptr->W), 1, fp))
  262. return (-1);
  263. if (Plus->with_z) {
  264. if (0 >= dig__fwrite_port_D(&(ptr->T), 1, fp))
  265. return (-1);
  266. if (0 >= dig__fwrite_port_D(&(ptr->B), 1, fp))
  267. return (-1);
  268. }
  269. }
  270. return (0);
  271. }
  272. int dig_Rd_P_area(struct Plus_head *Plus, int n, GVFILE * fp)
  273. {
  274. int cnt;
  275. P_AREA *ptr;
  276. #ifdef GDEBUG
  277. G_debug(3, "dig_Rd_P_area(): n = %d", n);
  278. #endif
  279. if (0 >= dig__fread_port_P(&cnt, 1, fp))
  280. return (-1);
  281. if (cnt == 0) { /* dead */
  282. Plus->Area[n] = NULL;
  283. return 0;
  284. }
  285. ptr = dig_alloc_area();
  286. /* lines */
  287. ptr->n_lines = cnt;
  288. if (dig_area_alloc_line(ptr, ptr->n_lines) == -1)
  289. return -1;
  290. if (ptr->n_lines)
  291. if (0 >= dig__fread_port_P(ptr->lines, ptr->n_lines, fp))
  292. return -1;
  293. /* isles */
  294. if (0 >= dig__fread_port_P(&(ptr->n_isles), 1, fp))
  295. return -1;
  296. if (dig_area_alloc_isle(ptr, ptr->n_isles) == -1)
  297. return -1;
  298. if (ptr->n_isles)
  299. if (0 >= dig__fread_port_P(ptr->isles, ptr->n_isles, fp))
  300. return -1;
  301. /* centroid */
  302. if (0 >= dig__fread_port_P(&(ptr->centroid), 1, fp))
  303. return -1;
  304. if (0 >= dig__fread_port_D(&(ptr->N), 1, fp))
  305. return -1;
  306. if (0 >= dig__fread_port_D(&(ptr->S), 1, fp))
  307. return -1;
  308. if (0 >= dig__fread_port_D(&(ptr->E), 1, fp))
  309. return -1;
  310. if (0 >= dig__fread_port_D(&(ptr->W), 1, fp))
  311. return -1;
  312. if (Plus->with_z) {
  313. if (0 >= dig__fread_port_D(&(ptr->T), 1, fp))
  314. return -1;
  315. if (0 >= dig__fread_port_D(&(ptr->B), 1, fp))
  316. return -1;
  317. }
  318. else {
  319. ptr->T = 0.0;
  320. ptr->B = 0.0;
  321. }
  322. Plus->Area[n] = ptr;
  323. return (0);
  324. }
  325. int dig_Wr_P_area(struct Plus_head *Plus, int n, GVFILE * fp)
  326. {
  327. int i;
  328. P_AREA *ptr;
  329. ptr = Plus->Area[n];
  330. /* If NULL i.e. dead write just 0 instead of number of lines */
  331. if (ptr == NULL) {
  332. i = 0;
  333. if (0 >= dig__fwrite_port_P(&i, 1, fp))
  334. return (-1);
  335. return 0;
  336. }
  337. /* lines */
  338. if (0 >= dig__fwrite_port_P(&(ptr->n_lines), 1, fp))
  339. return (-1);
  340. if (ptr->n_lines)
  341. if (0 >= dig__fwrite_port_P(ptr->lines, ptr->n_lines, fp))
  342. return -1;
  343. /* isles */
  344. if (0 >= dig__fwrite_port_P(&(ptr->n_isles), 1, fp))
  345. return (-1);
  346. if (ptr->n_isles)
  347. if (0 >= dig__fwrite_port_P(ptr->isles, ptr->n_isles, fp))
  348. return -1;
  349. /* centroid */
  350. if (0 >= dig__fwrite_port_P(&(ptr->centroid), 1, fp))
  351. return (-1);
  352. if (0 >= dig__fwrite_port_D(&(ptr->N), 1, fp))
  353. return (-1);
  354. if (0 >= dig__fwrite_port_D(&(ptr->S), 1, fp))
  355. return (-1);
  356. if (0 >= dig__fwrite_port_D(&(ptr->E), 1, fp))
  357. return (-1);
  358. if (0 >= dig__fwrite_port_D(&(ptr->W), 1, fp))
  359. return (-1);
  360. if (Plus->with_z) {
  361. if (0 >= dig__fwrite_port_D(&(ptr->T), 1, fp))
  362. return (-1);
  363. if (0 >= dig__fwrite_port_D(&(ptr->B), 1, fp))
  364. return (-1);
  365. }
  366. return (0);
  367. }
  368. int dig_Rd_P_isle(struct Plus_head *Plus, int n, GVFILE * fp)
  369. {
  370. int cnt;
  371. P_ISLE *ptr;
  372. #ifdef GDEBUG
  373. G_debug(3, "dig_Rd_P_isle()");
  374. #endif
  375. if (0 >= dig__fread_port_P(&cnt, 1, fp))
  376. return (-1);
  377. if (cnt == 0) { /* dead */
  378. Plus->Isle[n] = NULL;
  379. return 0;
  380. }
  381. ptr = dig_alloc_isle();
  382. /* lines */
  383. ptr->n_lines = cnt;
  384. if (dig_isle_alloc_line(ptr, ptr->n_lines) == -1)
  385. return -1;
  386. if (ptr->n_lines)
  387. if (0 >= dig__fread_port_P(ptr->lines, ptr->n_lines, fp))
  388. return -1;
  389. /* area */
  390. if (0 >= dig__fread_port_P(&(ptr->area), 1, fp))
  391. return -1;
  392. if (0 >= dig__fread_port_D(&(ptr->N), 1, fp))
  393. return -1;
  394. if (0 >= dig__fread_port_D(&(ptr->S), 1, fp))
  395. return -1;
  396. if (0 >= dig__fread_port_D(&(ptr->E), 1, fp))
  397. return -1;
  398. if (0 >= dig__fread_port_D(&(ptr->W), 1, fp))
  399. return -1;
  400. if (Plus->with_z) {
  401. if (0 >= dig__fread_port_D(&(ptr->T), 1, fp))
  402. return -1;
  403. if (0 >= dig__fread_port_D(&(ptr->B), 1, fp))
  404. return -1;
  405. }
  406. else {
  407. ptr->T = 0.0;
  408. ptr->B = 0.0;
  409. }
  410. Plus->Isle[n] = ptr;
  411. return (0);
  412. }
  413. int dig_Wr_P_isle(struct Plus_head *Plus, int n, GVFILE * fp)
  414. {
  415. int i;
  416. P_ISLE *ptr;
  417. ptr = Plus->Isle[n];
  418. /* If NULL i.e. dead write just 0 instead of number of lines */
  419. if (ptr == NULL) {
  420. i = 0;
  421. if (0 >= dig__fwrite_port_P(&i, 1, fp))
  422. return (-1);
  423. return 0;
  424. }
  425. /* lines */
  426. if (0 >= dig__fwrite_port_P(&(ptr->n_lines), 1, fp))
  427. return (-1);
  428. if (ptr->n_lines)
  429. if (0 >= dig__fwrite_port_P(ptr->lines, ptr->n_lines, fp))
  430. return -1;
  431. /* area */
  432. if (0 >= dig__fwrite_port_P(&(ptr->area), 1, fp))
  433. return (-1);
  434. if (0 >= dig__fwrite_port_D(&(ptr->N), 1, fp))
  435. return (-1);
  436. if (0 >= dig__fwrite_port_D(&(ptr->S), 1, fp))
  437. return (-1);
  438. if (0 >= dig__fwrite_port_D(&(ptr->E), 1, fp))
  439. return (-1);
  440. if (0 >= dig__fwrite_port_D(&(ptr->W), 1, fp))
  441. return (-1);
  442. if (Plus->with_z) {
  443. if (0 >= dig__fwrite_port_D(&(ptr->T), 1, fp))
  444. return (-1);
  445. if (0 >= dig__fwrite_port_D(&(ptr->B), 1, fp))
  446. return (-1);
  447. }
  448. return (0);
  449. }
  450. /*
  451. \return -1 error
  452. \return 0 OK
  453. */
  454. int dig_Rd_Plus_head(GVFILE * fp, struct Plus_head *ptr)
  455. {
  456. unsigned char buf[5];
  457. int byte_order;
  458. dig_rewind(fp);
  459. /* bytes 1 - 5 */
  460. if (0 >= dig__fread_port_C(buf, 5, fp))
  461. return (-1);
  462. ptr->Version_Major = buf[0];
  463. ptr->Version_Minor = buf[1];
  464. ptr->Back_Major = buf[2];
  465. ptr->Back_Minor = buf[3];
  466. byte_order = buf[4];
  467. G_debug(2,
  468. "Topo header: file version %d.%d , supported from GRASS version %d.%d",
  469. ptr->Version_Major, ptr->Version_Minor, ptr->Back_Major,
  470. ptr->Back_Minor);
  471. G_debug(2, " byte order %d", byte_order);
  472. /* check version numbers */
  473. if (ptr->Version_Major > GV_TOPO_VER_MAJOR ||
  474. ptr->Version_Minor > GV_TOPO_VER_MINOR) {
  475. /* The file was created by GRASS library with higher version than this one */
  476. if (ptr->Back_Major > GV_TOPO_VER_MAJOR ||
  477. ptr->Back_Minor > GV_TOPO_VER_MINOR) {
  478. /* This version of GRASS lib is lower than the oldest which can read this format */
  479. G_fatal_error
  480. ("Topology format version %d.%d is not supported by this release."
  481. " Try to rebuild topology or upgrade GRASS.",
  482. ptr->Version_Major, ptr->Version_Minor);
  483. return (-1);
  484. }
  485. G_warning
  486. ("Your GRASS version does not fully support topology format %d.%d of the vector."
  487. " Consider to rebuild topology or upgrade GRASS.",
  488. ptr->Version_Major, ptr->Version_Minor);
  489. }
  490. dig_init_portable(&(ptr->port), byte_order);
  491. dig_set_cur_port(&(ptr->port));
  492. /* bytes 6 - 9 : header size */
  493. if (0 >= dig__fread_port_L(&(ptr->head_size), 1, fp))
  494. return (-1);
  495. G_debug(2, " header size %ld", ptr->head_size);
  496. /* byte 10 : dimension 2D or 3D */
  497. if (0 >= dig__fread_port_C(buf, 1, fp))
  498. return (-1);
  499. ptr->with_z = buf[0];
  500. G_debug(2, " with_z %d", ptr->with_z);
  501. /* bytes 11 - 58 : bound box */
  502. if (0 >= dig__fread_port_D(&(ptr->box.N), 1, fp))
  503. return (-1);
  504. if (0 >= dig__fread_port_D(&(ptr->box.S), 1, fp))
  505. return (-1);
  506. if (0 >= dig__fread_port_D(&(ptr->box.E), 1, fp))
  507. return (-1);
  508. if (0 >= dig__fread_port_D(&(ptr->box.W), 1, fp))
  509. return (-1);
  510. if (0 >= dig__fread_port_D(&(ptr->box.T), 1, fp))
  511. return (-1);
  512. if (0 >= dig__fread_port_D(&(ptr->box.B), 1, fp))
  513. return (-1);
  514. /* bytes 59 - 86 : number of structures */
  515. if (0 >= dig__fread_port_P(&(ptr->n_nodes), 1, fp))
  516. return (-1);
  517. if (0 >= dig__fread_port_P(&(ptr->n_edges), 1, fp))
  518. return (-1);
  519. if (0 >= dig__fread_port_P(&(ptr->n_lines), 1, fp))
  520. return (-1);
  521. if (0 >= dig__fread_port_P(&(ptr->n_areas), 1, fp))
  522. return (-1);
  523. if (0 >= dig__fread_port_P(&(ptr->n_isles), 1, fp))
  524. return (-1);
  525. if (0 >= dig__fread_port_P(&(ptr->n_volumes), 1, fp))
  526. return (-1);
  527. if (0 >= dig__fread_port_P(&(ptr->n_holes), 1, fp))
  528. return (-1);
  529. /* bytes 87 - 110 : number of line types */
  530. if (0 >= dig__fread_port_P(&(ptr->n_plines), 1, fp))
  531. return (-1);
  532. if (0 >= dig__fread_port_P(&(ptr->n_llines), 1, fp))
  533. return (-1);
  534. if (0 >= dig__fread_port_P(&(ptr->n_blines), 1, fp))
  535. return (-1);
  536. if (0 >= dig__fread_port_P(&(ptr->n_clines), 1, fp))
  537. return (-1);
  538. if (0 >= dig__fread_port_P(&(ptr->n_flines), 1, fp))
  539. return (-1);
  540. if (0 >= dig__fread_port_P(&(ptr->n_klines), 1, fp))
  541. return (-1);
  542. /* bytes 111 - 138 : Offset */
  543. if (0 >= dig__fread_port_L(&(ptr->Node_offset), 1, fp))
  544. return (-1);
  545. if (0 >= dig__fread_port_L(&(ptr->Edge_offset), 1, fp))
  546. return (-1);
  547. if (0 >= dig__fread_port_L(&(ptr->Line_offset), 1, fp))
  548. return (-1);
  549. if (0 >= dig__fread_port_L(&(ptr->Area_offset), 1, fp))
  550. return (-1);
  551. if (0 >= dig__fread_port_L(&(ptr->Isle_offset), 1, fp))
  552. return (-1);
  553. if (0 >= dig__fread_port_L(&(ptr->Volume_offset), 1, fp))
  554. return (-1);
  555. if (0 >= dig__fread_port_L(&(ptr->Hole_offset), 1, fp))
  556. return (-1);
  557. /* bytes 139 - 142 : Coor size and time */
  558. if (0 >= dig__fread_port_L(&(ptr->coor_size), 1, fp))
  559. return (-1);
  560. G_debug(2, " coor size %ld", ptr->coor_size);
  561. dig_fseek(fp, ptr->head_size, SEEK_SET);
  562. return (0);
  563. }
  564. int dig_Wr_Plus_head(GVFILE * fp, struct Plus_head *ptr)
  565. {
  566. unsigned char buf[10];
  567. long length = 142;
  568. dig_rewind(fp);
  569. dig_set_cur_port(&(ptr->port));
  570. /* bytes 1 - 5 */
  571. buf[0] = GV_TOPO_VER_MAJOR;
  572. buf[1] = GV_TOPO_VER_MINOR;
  573. buf[2] = GV_TOPO_EARLIEST_MAJOR;
  574. buf[3] = GV_TOPO_EARLIEST_MINOR;
  575. buf[4] = ptr->port.byte_order;
  576. if (0 >= dig__fwrite_port_C(buf, 5, fp))
  577. return (-1);
  578. /* bytes 6 - 9 : header size */
  579. if (0 >= dig__fwrite_port_L(&length, 1, fp))
  580. return (0);
  581. /* byte 10 : dimension 2D or 3D */
  582. buf[0] = ptr->with_z;
  583. if (0 >= dig__fwrite_port_C(buf, 1, fp))
  584. return (0);
  585. /* bytes 11 - 58 : bound box */
  586. if (0 >= dig__fwrite_port_D(&(ptr->box.N), 1, fp))
  587. return (-1);
  588. if (0 >= dig__fwrite_port_D(&(ptr->box.S), 1, fp))
  589. return (-1);
  590. if (0 >= dig__fwrite_port_D(&(ptr->box.E), 1, fp))
  591. return (-1);
  592. if (0 >= dig__fwrite_port_D(&(ptr->box.W), 1, fp))
  593. return (-1);
  594. if (0 >= dig__fwrite_port_D(&(ptr->box.T), 1, fp))
  595. return (-1);
  596. if (0 >= dig__fwrite_port_D(&(ptr->box.B), 1, fp))
  597. return (-1);
  598. /* bytes 59 - 86 : number of structures */
  599. if (0 >= dig__fwrite_port_P(&(ptr->n_nodes), 1, fp))
  600. return (-1);
  601. if (0 >= dig__fwrite_port_P(&(ptr->n_edges), 1, fp))
  602. return (-1);
  603. if (0 >= dig__fwrite_port_P(&(ptr->n_lines), 1, fp))
  604. return (-1);
  605. if (0 >= dig__fwrite_port_P(&(ptr->n_areas), 1, fp))
  606. return (-1);
  607. if (0 >= dig__fwrite_port_P(&(ptr->n_isles), 1, fp))
  608. return (-1);
  609. if (0 >= dig__fwrite_port_P(&(ptr->n_volumes), 1, fp))
  610. return (-1);
  611. if (0 >= dig__fwrite_port_P(&(ptr->n_holes), 1, fp))
  612. return (-1);
  613. /* bytes 87 - 110 : number of line types */
  614. if (0 >= dig__fwrite_port_P(&(ptr->n_plines), 1, fp))
  615. return (-1);
  616. if (0 >= dig__fwrite_port_P(&(ptr->n_llines), 1, fp))
  617. return (-1);
  618. if (0 >= dig__fwrite_port_P(&(ptr->n_blines), 1, fp))
  619. return (-1);
  620. if (0 >= dig__fwrite_port_P(&(ptr->n_clines), 1, fp))
  621. return (-1);
  622. if (0 >= dig__fwrite_port_P(&(ptr->n_flines), 1, fp))
  623. return (-1);
  624. if (0 >= dig__fwrite_port_P(&(ptr->n_klines), 1, fp))
  625. return (-1);
  626. /* bytes 111 - 138 : Offset */
  627. if (0 >= dig__fwrite_port_L(&(ptr->Node_offset), 1, fp))
  628. return (-1);
  629. if (0 >= dig__fwrite_port_L(&(ptr->Edge_offset), 1, fp))
  630. return (-1);
  631. if (0 >= dig__fwrite_port_L(&(ptr->Line_offset), 1, fp))
  632. return (-1);
  633. if (0 >= dig__fwrite_port_L(&(ptr->Area_offset), 1, fp))
  634. return (-1);
  635. if (0 >= dig__fwrite_port_L(&(ptr->Isle_offset), 1, fp))
  636. return (-1);
  637. if (0 >= dig__fwrite_port_L(&(ptr->Volume_offset), 1, fp))
  638. return (-1);
  639. if (0 >= dig__fwrite_port_L(&(ptr->Hole_offset), 1, fp))
  640. return (-1);
  641. /* bytes 139 - 142 : Coor size and time */
  642. if (0 >= dig__fwrite_port_L(&(ptr->coor_size), 1, fp))
  643. return (-1);
  644. G_debug(2, "topo body offset %ld", dig_ftell(fp));
  645. return (0);
  646. }