1 /*
2 * Include file defining macros, functions and structures used in gshhg.c
3 *
4 * Copyright (c) 1996-2021 by the GMT Team (https://www.generic-mapping-tools.org/team.html)
5 * See LICENSE.TXT file for copying and redistribution conditions.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; version 3 or any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * Contact info: www.generic-mapping-tools.org
17 *
18 * 12-APR-2016. For use with GSHHG version 2.3.5
19 */
20
21 /*!
22 * \file gmt_gshhg.h
23 * \brief Include file defining macros, functions and structures used in gshhg.c
24 */
25
26 #ifndef _GMT_GSHHG
27 #define _GMT_GSHHG
28 #include "gmt_config.h"
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <math.h>
34
35 #include "gmt_notposix.h"
36
37 #include "gmt_common_byteswap.h"
38
39 #include "gshhg.h" /* The definition of the GSHHG header structure */
40
41 #ifndef M_PI
42 #define M_PI 3.14159265358979323846
43 #endif
44
45 #ifndef SEEK_CUR /* For really ancient systems */
46 #define SEEK_CUR 1
47 #endif
48
49 #define GSHHG_MAXPOL 200000 /* Should never need to allocate more than this many polygons */
50
51 #define GSHHG_STRUCT_N_MEMBERS 11
52 /*! byteswap all members of GSHHG struct */
bswap_GSHHG_struct(struct GSHHG_HEADER * h)53 static inline void bswap_GSHHG_struct (struct GSHHG_HEADER *h) {
54 uint32_t unsigned32[GSHHG_STRUCT_N_MEMBERS];
55 uint32_t n;
56
57 /* since all members are 32 bit words: */
58 memcpy (&unsigned32, h, sizeof(struct GSHHG_HEADER));
59
60 for (n = 0; n < GSHHG_STRUCT_N_MEMBERS; ++n)
61 unsigned32[n] = bswap32 (unsigned32[n]);
62
63 memcpy (h, &unsigned32, sizeof(struct GSHHG_HEADER));
64 }
65
66 /*! byteswap members of GSHHG_POINT struct */
bswap_POINT_struct(struct GSHHG_POINT * p)67 static inline void bswap_POINT_struct (struct GSHHG_POINT *p) {
68 uint32_t unsigned32;
69 memcpy (&unsigned32, &p->x, sizeof(uint32_t));
70 unsigned32 = bswap32 (unsigned32);
71 memcpy (&p->x, &unsigned32, sizeof(uint32_t));
72 memcpy (&unsigned32, &p->y, sizeof(uint32_t));
73 unsigned32 = bswap32 (unsigned32);
74 memcpy (&p->y, &unsigned32, sizeof(uint32_t));
75 }
76
77 #endif /* _GMT_GSHHG */
78