plus_struct.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  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 dependant 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
  46. dig_Rd_P_node (
  47. struct Plus_head *Plus,
  48. int n,
  49. GVFILE * fp)
  50. {
  51. int cnt, n_edges;
  52. P_NODE *ptr;
  53. G_debug (3, "dig_Rd_P_node()");
  54. if (0 >= dig__fread_port_P (&cnt, 1, fp))
  55. return (-1);
  56. if ( cnt == 0 ) { /* dead */
  57. G_debug (3, " node is dead");
  58. Plus->Node[n] = NULL ;
  59. return 0;
  60. }
  61. ptr = dig_alloc_node();
  62. ptr->n_lines = cnt;
  63. if ( dig_node_alloc_line ( ptr, ptr->n_lines) == -1)
  64. return -1;
  65. if (ptr->n_lines) {
  66. if (0 >= dig__fread_port_P (ptr->lines, ptr->n_lines, fp))
  67. return (-1);
  68. if (0 >= dig__fread_port_F (ptr->angles, ptr->n_lines, fp))
  69. return (-1);
  70. }
  71. if ( Plus->with_z )
  72. if (0 >= dig__fread_port_P (&n_edges, 1, fp)) /* reserved for edges */
  73. return (-1);
  74. /* here will be edges */
  75. if (0 >= dig__fread_port_D (&(ptr->x), 1, fp))
  76. return (-1);
  77. if (0 >= dig__fread_port_D (&(ptr->y), 1, fp))
  78. return (-1);
  79. if ( Plus->with_z ) {
  80. if (0 >= dig__fread_port_D (&(ptr->z), 1, fp))
  81. return (-1);
  82. } else
  83. ptr->z = 0;
  84. Plus->Node[n] = ptr;
  85. return (0);
  86. }
  87. int
  88. dig_Wr_P_node (
  89. struct Plus_head *Plus,
  90. int n,
  91. GVFILE * fp)
  92. {
  93. int i, n_edges = 0;
  94. P_NODE *ptr;
  95. G_debug (3, "dig_Wr_P_node()");
  96. ptr = Plus->Node[n];
  97. /* If NULL i.e. dead write just 0 instead of number of lines */
  98. if ( ptr == NULL ) {
  99. G_debug (3, " node is dead -> write 0 only");
  100. i = 0;
  101. if (0 >= dig__fwrite_port_P (&i, 1, fp))
  102. return (-1);
  103. return 0;
  104. }
  105. if (0 >= dig__fwrite_port_P (&(ptr->n_lines), 1, fp))
  106. return (-1);
  107. if (ptr->n_lines)
  108. {
  109. if (0 >= dig__fwrite_port_P (ptr->lines, ptr->n_lines, fp))
  110. return (-1);
  111. if (0 >= dig__fwrite_port_F (ptr->angles, ptr->n_lines, fp))
  112. return (-1);
  113. }
  114. if ( Plus->with_z )
  115. if (0 >= dig__fwrite_port_P (&n_edges, 1, fp)) /* reserved for edges */
  116. return (-1);
  117. /* here will be edges */
  118. if (0 >= dig__fwrite_port_D (&(ptr->x), 1, fp))
  119. return (-1);
  120. if (0 >= dig__fwrite_port_D (&(ptr->y), 1, fp))
  121. return (-1);
  122. if ( Plus->with_z )
  123. if (0 >= dig__fwrite_port_D (&(ptr->z), 1, fp))
  124. return (-1);
  125. return (0);
  126. }
  127. int
  128. dig_Rd_P_line ( struct Plus_head *Plus, int n, GVFILE * fp)
  129. {
  130. int n_edges, vol;
  131. char tp;
  132. P_LINE *ptr;
  133. P_NODE *Node;
  134. G_debug (3, "dig_Rd_P_line()");
  135. if (0 >= dig__fread_port_C (&tp, 1, fp))
  136. return (-1);
  137. if ( tp == 0 ) { /* dead */
  138. G_debug (3, " line is dead");
  139. Plus->Line[n] = NULL ;
  140. return 0;
  141. }
  142. ptr = dig_alloc_line();
  143. ptr->type = dig_type_from_store ( tp );
  144. G_debug (5, " line type %d -> %d", tp, ptr->type);
  145. if (0 >= dig__fread_port_L (&(ptr->offset), 1, fp)) return (-1);
  146. /* First node */
  147. if ( ptr->type & ( GV_POINTS | GV_LINES | GV_KERNEL ) )
  148. if (0 >= dig__fread_port_P (&(ptr->N1), 1, fp)) return -1;
  149. /* Second node, for points/centroids not needed */
  150. if ( ptr->type & (GV_LINE | GV_BOUNDARY ) ) {
  151. if (0 >= dig__fread_port_P (&(ptr->N2), 1, fp)) return -1;
  152. } else if ( ptr->type & (GV_POINTS | GV_KERNEL ) )
  153. ptr->N2 = ptr->N1;
  154. /* left area for boundary, area for centroid */
  155. if ( ptr->type & (GV_BOUNDARY | GV_CENTROID) )
  156. if (0 >= dig__fread_port_P (&(ptr->left), 1, fp)) return -1;
  157. /* right area */
  158. if ( ptr->type & GV_BOUNDARY )
  159. if (0 >= dig__fread_port_P (&(ptr->right), 1, fp)) return -1;
  160. if ( (ptr->type & GV_FACE) && Plus->with_z ) { /* reserved for face edges */
  161. if (0 >= dig__fread_port_I (&n_edges, 1, fp)) return -1;
  162. /* here will be list of edges */
  163. /* left / right volume */
  164. if (0 >= dig__fread_port_P (&vol, 1, fp)) return -1;
  165. if (0 >= dig__fread_port_P (&vol, 1, fp)) 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)) return -1;
  169. /* Bounding box */
  170. if ( ptr->type & (GV_LINE | GV_BOUNDARY | GV_FACE ) ) {
  171. if (0 >= dig__fread_port_D (&(ptr->N), 1, fp)) return -1;
  172. if (0 >= dig__fread_port_D (&(ptr->S), 1, fp)) return -1;
  173. if (0 >= dig__fread_port_D (&(ptr->E), 1, fp)) return -1;
  174. if (0 >= dig__fread_port_D (&(ptr->W), 1, fp)) return -1;
  175. if ( Plus->with_z ) {
  176. if (0 >= dig__fread_port_D (&(ptr->T), 1, fp)) return -1;
  177. if (0 >= dig__fread_port_D (&(ptr->B), 1, fp)) return -1;
  178. } else {
  179. ptr->T = 0.0;
  180. ptr->B = 0.0;
  181. }
  182. } else {
  183. Node = Plus->Node[ptr->N1];
  184. ptr->N = Node->y;
  185. ptr->S = Node->y;
  186. ptr->E = Node->x;
  187. ptr->W = Node->x;
  188. ptr->T = Node->z;
  189. ptr->B = Node->z;
  190. }
  191. Plus->Line[n] = ptr;
  192. return (0);
  193. }
  194. int
  195. dig_Wr_P_line (
  196. struct Plus_head *Plus,
  197. int n,
  198. GVFILE * fp)
  199. {
  200. int n_edges = 0, vol = 0;
  201. char ch;
  202. P_LINE *ptr;
  203. G_debug (4, "dig_Wr_P_line() line = %d", n);
  204. ptr = Plus->Line[n];
  205. /* If NULL i.e. dead write just 0 instead of type */
  206. if ( ptr == NULL ) {
  207. G_debug (3, " line is dead -> write 0 only");
  208. ch = 0;
  209. if (0 >= dig__fwrite_port_C (&ch, 1, fp)) return (-1);
  210. return 0;
  211. }
  212. ch = (char) dig_type_to_store ( ptr->type );
  213. G_debug (5, " line type %d -> %d", ptr->type, ch);
  214. if (0 >= dig__fwrite_port_C (&ch, 1, fp)) return (-1);
  215. if (0 >= dig__fwrite_port_L (&(ptr->offset), 1, fp)) return (-1);
  216. /* First node */
  217. if ( ptr->type & ( GV_POINTS | GV_LINES | GV_KERNEL ) )
  218. if (0 >= dig__fwrite_port_P (&(ptr->N1), 1, fp)) return (-1);
  219. /* Second node, for points/centroids not needed */
  220. if ( ptr->type & (GV_LINE | GV_BOUNDARY ) )
  221. if (0 >= dig__fwrite_port_P (&(ptr->N2), 1, fp)) return (-1);
  222. /* left area for boundary, area for centroid */
  223. if ( ptr->type & (GV_BOUNDARY | GV_CENTROID) )
  224. if (0 >= dig__fwrite_port_P (&(ptr->left), 1, fp)) return (-1);
  225. /* right area */
  226. if ( ptr->type & GV_BOUNDARY )
  227. if (0 >= dig__fwrite_port_P (&(ptr->right), 1, fp)) return (-1);
  228. if ( (ptr->type & GV_FACE) && Plus->with_z ) { /* reserved for face */
  229. if (0 >= dig__fwrite_port_I (&n_edges, 1, fp)) return (-1);
  230. /* here will be list of edges */
  231. /* left / right volume */
  232. if (0 >= dig__fwrite_port_P (&vol, 1, fp)) return (-1);
  233. if (0 >= dig__fwrite_port_P (&vol, 1, fp)) return (-1);
  234. }
  235. if ( (ptr->type & GV_KERNEL) && Plus->with_z ) /* reserved for kernel (volume number) */
  236. if (0 >= dig__fwrite_port_P (&vol, 1, fp)) return (-1);
  237. /* Bounding box */
  238. if ( ptr->type & (GV_LINE | GV_BOUNDARY | GV_FACE ) ) {
  239. if (0 >= dig__fwrite_port_D (&(ptr->N), 1, fp)) return (-1);
  240. if (0 >= dig__fwrite_port_D (&(ptr->S), 1, fp)) return (-1);
  241. if (0 >= dig__fwrite_port_D (&(ptr->E), 1, fp)) return (-1);
  242. if (0 >= dig__fwrite_port_D (&(ptr->W), 1, fp)) return (-1);
  243. if ( Plus->with_z ) {
  244. if (0 >= dig__fwrite_port_D (&(ptr->T), 1, fp)) return (-1);
  245. if (0 >= dig__fwrite_port_D (&(ptr->B), 1, fp)) return (-1);
  246. }
  247. }
  248. return (0);
  249. }
  250. int
  251. dig_Rd_P_area (
  252. struct Plus_head *Plus,
  253. int n,
  254. GVFILE * fp)
  255. {
  256. int cnt;
  257. P_AREA *ptr;
  258. #ifdef GDEBUG
  259. G_debug (3, "dig_Rd_P_area(): n = %d", n );
  260. #endif
  261. if (0 >= dig__fread_port_P (&cnt, 1, fp))
  262. return (-1);
  263. if ( cnt == 0 ) { /* dead */
  264. Plus->Area[n] = NULL ;
  265. return 0;
  266. }
  267. ptr = dig_alloc_area();
  268. /* lines */
  269. ptr->n_lines = cnt;
  270. if ( dig_area_alloc_line ( ptr, ptr->n_lines) == -1) return -1;
  271. if (ptr->n_lines)
  272. if (0 >= dig__fread_port_P (ptr->lines, ptr->n_lines, fp)) return -1;
  273. /* isles */
  274. if (0 >= dig__fread_port_P (&(ptr->n_isles), 1, fp)) return -1;
  275. if ( dig_area_alloc_isle ( ptr, ptr->n_isles) == -1) return -1;
  276. if (ptr->n_isles)
  277. if (0 >= dig__fread_port_P (ptr->isles, ptr->n_isles, fp)) return -1;
  278. /* centroid */
  279. if (0 >= dig__fread_port_P (&(ptr->centroid), 1, fp)) return -1;
  280. if (0 >= dig__fread_port_D (&(ptr->N), 1, fp)) return -1;
  281. if (0 >= dig__fread_port_D (&(ptr->S), 1, fp)) return -1;
  282. if (0 >= dig__fread_port_D (&(ptr->E), 1, fp)) return -1;
  283. if (0 >= dig__fread_port_D (&(ptr->W), 1, fp)) return -1;
  284. if ( Plus->with_z ) {
  285. if (0 >= dig__fread_port_D (&(ptr->T), 1, fp)) return -1;
  286. if (0 >= dig__fread_port_D (&(ptr->B), 1, fp)) return -1;
  287. } else {
  288. ptr->T = 0.0;
  289. ptr->B = 0.0;
  290. }
  291. Plus->Area[n] = ptr;
  292. return (0);
  293. }
  294. int
  295. dig_Wr_P_area ( struct Plus_head *Plus,
  296. int n,
  297. GVFILE * fp)
  298. {
  299. int i;
  300. P_AREA *ptr;
  301. ptr = Plus->Area[n];
  302. /* If NULL i.e. dead write just 0 instead of number of lines */
  303. if ( ptr == NULL ) {
  304. i = 0;
  305. if (0 >= dig__fwrite_port_P (&i, 1, fp)) return (-1);
  306. return 0;
  307. }
  308. /* lines */
  309. if (0 >= dig__fwrite_port_P (&(ptr->n_lines), 1, fp)) return (-1);
  310. if (ptr->n_lines)
  311. if (0 >= dig__fwrite_port_P (ptr->lines, ptr->n_lines, fp)) return -1;
  312. /* isles */
  313. if (0 >= dig__fwrite_port_P (&(ptr->n_isles), 1, fp)) return (-1);
  314. if (ptr->n_isles)
  315. if (0 >= dig__fwrite_port_P (ptr->isles, ptr->n_isles, fp)) return -1;
  316. /* centroid */
  317. if (0 >= dig__fwrite_port_P (&(ptr->centroid), 1, fp)) return (-1);
  318. if (0 >= dig__fwrite_port_D (&(ptr->N), 1, fp)) return (-1);
  319. if (0 >= dig__fwrite_port_D (&(ptr->S), 1, fp)) return (-1);
  320. if (0 >= dig__fwrite_port_D (&(ptr->E), 1, fp)) return (-1);
  321. if (0 >= dig__fwrite_port_D (&(ptr->W), 1, fp)) return (-1);
  322. if ( Plus->with_z ) {
  323. if (0 >= dig__fwrite_port_D (&(ptr->T), 1, fp)) return (-1);
  324. if (0 >= dig__fwrite_port_D (&(ptr->B), 1, fp)) return (-1);
  325. }
  326. return (0);
  327. }
  328. int
  329. dig_Rd_P_isle ( struct Plus_head *Plus,
  330. int n,
  331. GVFILE * fp)
  332. {
  333. int cnt;
  334. P_ISLE *ptr;
  335. #ifdef GDEBUG
  336. G_debug (3, "dig_Rd_P_isle()");
  337. #endif
  338. if (0 >= dig__fread_port_P (&cnt, 1, fp))
  339. return (-1);
  340. if ( cnt == 0 ) { /* dead */
  341. Plus->Isle[n] = NULL ;
  342. return 0;
  343. }
  344. ptr = dig_alloc_isle();
  345. /* lines */
  346. ptr->n_lines = cnt;
  347. if ( dig_isle_alloc_line ( ptr, ptr->n_lines) == -1) return -1;
  348. if (ptr->n_lines)
  349. if (0 >= dig__fread_port_P (ptr->lines, ptr->n_lines, fp)) return -1;
  350. /* area */
  351. if (0 >= dig__fread_port_P (&(ptr->area), 1, fp)) return -1;
  352. if (0 >= dig__fread_port_D (&(ptr->N), 1, fp)) return -1;
  353. if (0 >= dig__fread_port_D (&(ptr->S), 1, fp)) return -1;
  354. if (0 >= dig__fread_port_D (&(ptr->E), 1, fp)) return -1;
  355. if (0 >= dig__fread_port_D (&(ptr->W), 1, fp)) return -1;
  356. if ( Plus->with_z ) {
  357. if (0 >= dig__fread_port_D (&(ptr->T), 1, fp)) return -1;
  358. if (0 >= dig__fread_port_D (&(ptr->B), 1, fp)) return -1;
  359. } else {
  360. ptr->T = 0.0;
  361. ptr->B = 0.0;
  362. }
  363. Plus->Isle[n] = ptr;
  364. return (0);
  365. }
  366. int
  367. dig_Wr_P_isle (
  368. struct Plus_head *Plus,
  369. int n,
  370. GVFILE * fp)
  371. {
  372. int i;
  373. P_ISLE *ptr;
  374. ptr = Plus->Isle[n];
  375. /* If NULL i.e. dead write just 0 instead of number of lines */
  376. if ( ptr == NULL ) {
  377. i = 0;
  378. if (0 >= dig__fwrite_port_P (&i, 1, fp)) return (-1);
  379. return 0;
  380. }
  381. /* lines */
  382. if (0 >= dig__fwrite_port_P (&(ptr->n_lines), 1, fp)) return (-1);
  383. if (ptr->n_lines)
  384. if (0 >= dig__fwrite_port_P (ptr->lines, ptr->n_lines, fp)) return -1;
  385. /* area */
  386. if (0 >= dig__fwrite_port_P (&(ptr->area), 1, fp)) return (-1);
  387. if (0 >= dig__fwrite_port_D (&(ptr->N), 1, fp)) return (-1);
  388. if (0 >= dig__fwrite_port_D (&(ptr->S), 1, fp)) return (-1);
  389. if (0 >= dig__fwrite_port_D (&(ptr->E), 1, fp)) return (-1);
  390. if (0 >= dig__fwrite_port_D (&(ptr->W), 1, fp)) return (-1);
  391. if ( Plus->with_z ) {
  392. if (0 >= dig__fwrite_port_D (&(ptr->T), 1, fp)) return (-1);
  393. if (0 >= dig__fwrite_port_D (&(ptr->B), 1, fp)) return (-1);
  394. }
  395. return (0);
  396. }
  397. /*
  398. \return -1 error
  399. \return 0 OK
  400. */
  401. int
  402. dig_Rd_Plus_head ( GVFILE * fp,
  403. struct Plus_head *ptr)
  404. {
  405. unsigned char buf[5];
  406. int byte_order;
  407. dig_rewind (fp);
  408. /* bytes 1 - 5 */
  409. if (0 >= dig__fread_port_C (buf, 5, fp)) return (-1);
  410. ptr->Version_Major = buf[0];
  411. ptr->Version_Minor = buf[1];
  412. ptr->Back_Major = buf[2];
  413. ptr->Back_Minor = buf[3];
  414. byte_order = buf[4];
  415. G_debug (2, "Topo header: file version %d.%d , supported from GRASS version %d.%d",
  416. ptr->Version_Major, ptr->Version_Minor, ptr->Back_Major, ptr->Back_Minor );
  417. G_debug (2, " byte order %d", byte_order );
  418. /* check version numbers */
  419. if ( ptr->Version_Major > GV_TOPO_VER_MAJOR || ptr->Version_Minor > GV_TOPO_VER_MINOR ) {
  420. /* The file was created by GRASS library with higher version than this one */
  421. if ( ptr->Back_Major > GV_TOPO_VER_MAJOR || ptr->Back_Minor > GV_TOPO_VER_MINOR ) {
  422. /* This version of GRASS lib is lower than the oldest which can read this format */
  423. G_fatal_error ( "Topology format version %d.%d is not supported by this release."
  424. " Try to rebuild topology or upgrade GRASS.",
  425. ptr->Version_Major, ptr->Version_Minor);
  426. return (-1);
  427. }
  428. G_warning ( "Your GRASS version does not fully support topology format %d.%d of the vector."
  429. " Consider to rebuild topology or upgrade GRASS.",
  430. ptr->Version_Major, ptr->Version_Minor );
  431. }
  432. dig_init_portable ( &(ptr->port), byte_order);
  433. dig_set_cur_port ( &(ptr->port) );
  434. /* bytes 6 - 9 : header size */
  435. if (0 >= dig__fread_port_L (&(ptr->head_size), 1, fp)) return (-1);
  436. G_debug (2, " header size %ld", ptr->head_size );
  437. /* byte 10 : dimension 2D or 3D */
  438. if (0 >= dig__fread_port_C (buf, 1, fp)) return (-1);
  439. ptr->with_z = buf[0];
  440. G_debug (2, " with_z %d", ptr->with_z );
  441. /* bytes 11 - 58 : bound box */
  442. if (0 >= dig__fread_port_D (&(ptr->box.N), 1, fp)) return (-1);
  443. if (0 >= dig__fread_port_D (&(ptr->box.S), 1, fp)) return (-1);
  444. if (0 >= dig__fread_port_D (&(ptr->box.E), 1, fp)) return (-1);
  445. if (0 >= dig__fread_port_D (&(ptr->box.W), 1, fp)) return (-1);
  446. if (0 >= dig__fread_port_D (&(ptr->box.T), 1, fp)) return (-1);
  447. if (0 >= dig__fread_port_D (&(ptr->box.B), 1, fp)) return (-1);
  448. /* bytes 59 - 86 : number of structures */
  449. if (0 >= dig__fread_port_P (&(ptr->n_nodes), 1, fp)) return (-1);
  450. if (0 >= dig__fread_port_P (&(ptr->n_edges), 1, fp)) return (-1);
  451. if (0 >= dig__fread_port_P (&(ptr->n_lines), 1, fp)) return (-1);
  452. if (0 >= dig__fread_port_P (&(ptr->n_areas), 1, fp)) return (-1);
  453. if (0 >= dig__fread_port_P (&(ptr->n_isles), 1, fp)) return (-1);
  454. if (0 >= dig__fread_port_P (&(ptr->n_volumes), 1, fp)) return (-1);
  455. if (0 >= dig__fread_port_P (&(ptr->n_holes), 1, fp)) return (-1);
  456. /* bytes 87 - 110 : number of line types */
  457. if (0 >= dig__fread_port_P (&(ptr->n_plines), 1, fp)) return (-1);
  458. if (0 >= dig__fread_port_P (&(ptr->n_llines), 1, fp)) return (-1);
  459. if (0 >= dig__fread_port_P (&(ptr->n_blines), 1, fp)) return (-1);
  460. if (0 >= dig__fread_port_P (&(ptr->n_clines), 1, fp)) return (-1);
  461. if (0 >= dig__fread_port_P (&(ptr->n_flines), 1, fp)) return (-1);
  462. if (0 >= dig__fread_port_P (&(ptr->n_klines), 1, fp)) return (-1);
  463. /* bytes 111 - 138 : Offset */
  464. if (0 >= dig__fread_port_L (&(ptr->Node_offset), 1, fp)) return (-1);
  465. if (0 >= dig__fread_port_L (&(ptr->Edge_offset), 1, fp)) return (-1);
  466. if (0 >= dig__fread_port_L (&(ptr->Line_offset), 1, fp)) return (-1);
  467. if (0 >= dig__fread_port_L (&(ptr->Area_offset), 1, fp)) return (-1);
  468. if (0 >= dig__fread_port_L (&(ptr->Isle_offset), 1, fp)) return (-1);
  469. if (0 >= dig__fread_port_L (&(ptr->Volume_offset), 1, fp)) return (-1);
  470. if (0 >= dig__fread_port_L (&(ptr->Hole_offset), 1, fp)) return (-1);
  471. /* bytes 139 - 142 : Coor size and time */
  472. if (0 >= dig__fread_port_L (&(ptr->coor_size), 1, fp)) return (-1);
  473. G_debug (2, " coor size %ld", ptr->coor_size );
  474. dig_fseek ( fp, ptr->head_size, SEEK_SET );
  475. return (0);
  476. }
  477. int
  478. dig_Wr_Plus_head ( GVFILE * fp,
  479. struct Plus_head *ptr)
  480. {
  481. unsigned char buf[10];
  482. long length = 142;
  483. dig_rewind (fp);
  484. dig_set_cur_port (&(ptr->port));
  485. /* bytes 1 - 5 */
  486. buf[0] = GV_TOPO_VER_MAJOR;
  487. buf[1] = GV_TOPO_VER_MINOR;
  488. buf[2] = GV_TOPO_EARLIEST_MAJOR;
  489. buf[3] = GV_TOPO_EARLIEST_MINOR;
  490. buf[4] = ptr->port.byte_order;
  491. if (0 >= dig__fwrite_port_C (buf, 5, fp)) return (-1);
  492. /* bytes 6 - 9 : header size */
  493. if (0 >= dig__fwrite_port_L ( &length, 1, fp)) return (0);
  494. /* byte 10 : dimension 2D or 3D */
  495. buf[0] = ptr->with_z;
  496. if (0 >= dig__fwrite_port_C ( buf, 1, fp)) return (0);
  497. /* bytes 11 - 58 : bound box */
  498. if (0 >= dig__fwrite_port_D (&(ptr->box.N), 1, fp)) return (-1);
  499. if (0 >= dig__fwrite_port_D (&(ptr->box.S), 1, fp)) return (-1);
  500. if (0 >= dig__fwrite_port_D (&(ptr->box.E), 1, fp)) return (-1);
  501. if (0 >= dig__fwrite_port_D (&(ptr->box.W), 1, fp)) return (-1);
  502. if (0 >= dig__fwrite_port_D (&(ptr->box.T), 1, fp)) return (-1);
  503. if (0 >= dig__fwrite_port_D (&(ptr->box.B), 1, fp)) return (-1);
  504. /* bytes 59 - 86 : number of structures */
  505. if (0 >= dig__fwrite_port_P (&(ptr->n_nodes), 1, fp)) return (-1);
  506. if (0 >= dig__fwrite_port_P (&(ptr->n_edges), 1, fp)) return (-1);
  507. if (0 >= dig__fwrite_port_P (&(ptr->n_lines), 1, fp)) return (-1);
  508. if (0 >= dig__fwrite_port_P (&(ptr->n_areas), 1, fp)) return (-1);
  509. if (0 >= dig__fwrite_port_P (&(ptr->n_isles), 1, fp)) return (-1);
  510. if (0 >= dig__fwrite_port_P (&(ptr->n_volumes), 1, fp)) return (-1);
  511. if (0 >= dig__fwrite_port_P (&(ptr->n_holes), 1, fp)) return (-1);
  512. /* bytes 87 - 110 : number of line types */
  513. if (0 >= dig__fwrite_port_P (&(ptr->n_plines), 1, fp)) return (-1);
  514. if (0 >= dig__fwrite_port_P (&(ptr->n_llines), 1, fp)) return (-1);
  515. if (0 >= dig__fwrite_port_P (&(ptr->n_blines), 1, fp)) return (-1);
  516. if (0 >= dig__fwrite_port_P (&(ptr->n_clines), 1, fp)) return (-1);
  517. if (0 >= dig__fwrite_port_P (&(ptr->n_flines), 1, fp)) return (-1);
  518. if (0 >= dig__fwrite_port_P (&(ptr->n_klines), 1, fp)) return (-1);
  519. /* bytes 111 - 138 : Offset */
  520. if (0 >= dig__fwrite_port_L (&(ptr->Node_offset), 1, fp)) return (-1);
  521. if (0 >= dig__fwrite_port_L (&(ptr->Edge_offset), 1, fp)) return (-1);
  522. if (0 >= dig__fwrite_port_L (&(ptr->Line_offset), 1, fp)) return (-1);
  523. if (0 >= dig__fwrite_port_L (&(ptr->Area_offset), 1, fp)) return (-1);
  524. if (0 >= dig__fwrite_port_L (&(ptr->Isle_offset), 1, fp)) return (-1);
  525. if (0 >= dig__fwrite_port_L (&(ptr->Volume_offset), 1, fp)) return (-1);
  526. if (0 >= dig__fwrite_port_L (&(ptr->Hole_offset), 1, fp)) return (-1);
  527. /* bytes 139 - 142 : Coor size and time */
  528. if (0 >= dig__fwrite_port_L (&(ptr->coor_size), 1, fp)) return (-1);
  529. G_debug (2, "topo body offset %ld", dig_ftell( fp) );
  530. return (0);
  531. }