Skip to content

Commit a2029c6

Browse files
committed
Update to GMT 6
1 parent ed2516e commit a2029c6

12 files changed

+277
-102
lines changed

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,9 @@ include (ConfigCMake)
5959

6060
# Find UNIX commands
6161
include (FindUnixCommands)
62-
#find_program (SVN svn)
6362

6463
# Add subdirectories
6564
add_subdirectory (src)
66-
#add_subdirectory (cmake/dist) # make distribution bundles (always last)
6765
get_property(GMT_CUSTOM_LIB_PATH TARGET customlib PROPERTY LOCATION)
6866
GET_FILENAME_COMPONENT (GMT_CUSTOM_LIB_NAME ${GMT_CUSTOM_LIB_PATH} NAME)
6967

README.TXT

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
# $Id$
2-
31
This README file explains the various steps you must take to design
42
and successfully build a custom plugin library that can be accessed
53
via the main gmt executable, just like the standard and official
64
supplemental GMT modules. It is required that you have installed
75
GMT >= 6 and made it your active GMT version before proceeding.
86

9-
Paul Wessel, March 10, 2018
7+
Paul Wessel, March 8, 2020
108

119
1. Decide what your plugin library name should be. This is a short
1210
single word that determines the plugin name, e.g., "custom".
@@ -16,12 +14,13 @@ Paul Wessel, March 10, 2018
1614
working modules in src. Model your code after those templates.
1715
Set the THIS_MODULE_LIB parameter in your modules to <TAG> and supply
1816
reasonable settings to THIS_MODULE_KEYS (see API documentation for the
19-
GMT_Encode_Options function for more details).
17+
GMT_Encode_Options function for more details). Also set THIS_MODULE_NEEDS
18+
and THIS_MODULE_OPTIONS.
2019
4. Add all your modules filenames to CUSTOM_PROGS_SRCS in src/CMakeLists.txt
2120
and set the string for LIB_STRING to match your plugin's key purpose.
2221
5. Create required glue source code automatically by running the GMT script
23-
gmt_make_custom_code.sh <TAG>
24-
in the src directory (see GMT's share/tools for gmt_make_custom_code.sh)
22+
$(gmt --show-sharedir)/tools/gmt_make_module_src.sh <TAG>
23+
in your module src directory.
2524
6. In cmake, make ConfigUser.cmake by copying the template and make any edits.
2625
7. Create a build directory in the top level directory, cd into build,
2726
and run "cmake .." (see README.CMake for more details).

src/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# $Id$
33
#
4-
# Copyright (c) 1991-2017 by P. Wessel, W. H. F. Smith, R. Scharroo, J. Luis, and F. Wobbe
4+
# Copyright (c) 1991-2020 by the GMT Team (https://www.generic-mapping-tools.org/team.html)
55
# See LICENSE.TXT file for copying and redistribution conditions.
66
#
77
# This program is free software; you can redistribute it and/or modify
@@ -13,7 +13,7 @@
1313
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414
# GNU Lesser General Public License for more details.
1515
#
16-
# Contact info: gmt.soest.hawaii.edu
16+
# Contact info: www.generic-mapping-tools.org
1717
#-------------------------------------------------------------------------------
1818
#
1919
# 1. To modify the cmake process: Customize your cmake/ConfigUser.cmake file

src/custom_version.h.in

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/*
2-
* $Id$
32
*
4-
* Copyright (c) 1991-2017 by P. Wessel, W. H. F. Smith, R. Scharroo,
5-
* F. Wobbe, and J. Luis
3+
* Copyright (c) 1991-2020 by the GMT Team (https://www.generic-mapping-tools.org/team.html)
64
*
75
* See LICENSE.TXT file for copying and redistribution conditions.
86
*
@@ -15,7 +13,7 @@
1513
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1614
* GNU Lesser General Public License for more details.
1715
*
18-
* Contact info: gmt.soest.hawaii.edu
16+
* Contact info: www.generic-mapping-tools.org
1917
*/
2018

2119
#pragma once

src/gmt_custom_module.c

Lines changed: 66 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,103 @@
1-
/* $Id$
2-
*
3-
* Copyright (c) 2016-2018 by pwessel
1+
/*
2+
* Copyright (c) 2012-2020 by the GMT Team (https://www.generic-mapping-tools.org/team.html)
43
* See LICENSE.TXT file for copying and redistribution conditions.
54
*/
65

7-
/* gmt_custom_module.c populates the local array g_custom_module
8-
* with parameters such as name, group, purpose and keys strings.
6+
/* gmt_custom_module.c populates the external array of GMT custom with
7+
* module parameters such as name, group, purpose and keys strings.
98
* This file also contains the following convenience functions to
109
* display all module purposes or just list their names:
1110
*
12-
* void gmt_custom_module_show_all (void *API);
11+
* void gmt_custom_module_show_all (struct GMTAPI_CTRL *API);
1312
* void gmt_custom_module_list_all (void *API);
1413
*
1514
* These functions may be called by gmt --help and gmt --show-modules
1615
*
16+
* Developers of external APIs for accessing GMT modules will use this
17+
* function indirectly via GMT_Encode_Options to retrieve option keys
18+
* needed for module arg processing:
19+
*
20+
* char * gmt_custom_module_keys (void *API, const char *module);
21+
*
1722
* DO NOT edit this file directly! Regenerate the file by running
18-
* gmt_make_custom_code.sh
23+
* gmt_make_module_src.sh custom
1924
*/
20-
2125
#include "gmt.h"
22-
#include "gmt_custom_module.h"
23-
#include <string.h>
24-
25-
#ifndef gmt_M_unused
26+
#include "gmt_notposix.h" /* Non-POSIX extensions */
2627
#define gmt_M_unused(x) (void)(x)
27-
#endif
28+
#define GMT_LEN256 256
29+
#include "gmt_supplements_module.h"
30+
#include <string.h>
2831

29-
/* Sorted array with information for all custom modules */
32+
/* Sorted array with information for all GMT custom modules */
3033

3134
/* name, library, and purpose for each module */
3235
struct Gmt_moduleinfo {
33-
const char *name; /* Program name */
36+
const char *mname; /* Program (modern) name */
37+
const char *cname; /* Program (classic) name */
3438
const char *component; /* Component (core, supplement, custom) */
3539
const char *purpose; /* Program purpose */
3640
const char *keys; /* Program option info for external APIs */
3741
};
3842

43+
static int sort_on_classic (const void *vA, const void *vB) {
44+
const struct Gmt_moduleinfo *A = vA, *B = vB;
45+
if (A == NULL) return +1; /* Get the NULL entry to the end */
46+
if (B == NULL) return -1; /* Get the NULL entry to the end */
47+
return strcmp(A->cname, B->cname);
48+
}
49+
3950
static struct Gmt_moduleinfo g_custom_module[] = {
40-
{"gmtaverage", "custom", "Block average (x,y,z) data tables by mean, median, or mode estimation", "<DI,>DO,RG-"},
41-
{"gmtmercmap", "custom", "Make a Mercator color map from ETOPO 1, 2, or 5 arc min global relief grids", "CCi,>XO,RG-"},
42-
{"gmtparser", "custom", "Demonstrate parsing of input data, defaults, and options", ""},
43-
{"grdfourier", "custom", "Create a grid, add a spike, filter it in frequency domain, and write output", "<GI,GGO,RG-"},
44-
{NULL, NULL, NULL, NULL} /* last element == NULL detects end of array */
51+
{"gmtaverage", "gmtaverage", "custom", , "Block average (x,y,z) data tables by mean, median, or mode estimation"},
52+
{"gmtmercmap", "gmtmercmap", "custom", , },
53+
{"gmtparser", "gmtparser", "custom", , },
54+
{"grdfourier", "grdfourier", "custom", , },
55+
{NULL, NULL, NULL, NULL, NULL} /* last element == NULL detects end of array */
4556
};
4657

4758
/* Pretty print all GMT custom module names and their purposes for gmt --help */
4859
void gmt_custom_module_show_all (void *V_API) {
4960
unsigned int module_id = 0;
50-
char message[256] = {""};
51-
GMT_Message (V_API, GMT_TIME_NONE, "\n=== " "GMT custom: Tools for the custom project" " ===\n");
52-
while (g_custom_module[module_id].name != NULL) {
61+
char message[GMT_LEN256];
62+
GMT_Message (V_API, GMT_TIME_NONE, "\n=== GMT custom: The custom modules of the Generic Mapping Tools ===\n");
63+
while (g_custom_module[module_id].cname != NULL) {
5364
if (module_id == 0 || strcmp (g_custom_module[module_id-1].component, g_custom_module[module_id].component)) {
5465
/* Start of new supplemental group */
55-
sprintf (message, "\nModule name: Purpose of %s module:\n", g_custom_module[module_id].component);
66+
snprintf (message, GMT_LEN256, "\nModule name: Purpose of %s module:\n", g_custom_module[module_id].component);
5667
GMT_Message (V_API, GMT_TIME_NONE, message);
5768
GMT_Message (V_API, GMT_TIME_NONE, "----------------------------------------------------------------\n");
5869
}
59-
sprintf (message, "%-16s %s\n",
60-
g_custom_module[module_id].name, g_custom_module[module_id].purpose);
61-
GMT_Message (V_API, GMT_TIME_NONE, message);
70+
snprintf (message, GMT_LEN256, "%-16s %s\n",
71+
g_custom_module[module_id].mname, g_custom_module[module_id].purpose);
72+
GMT_Message (V_API, GMT_TIME_NONE, message);
6273
++module_id;
6374
}
6475
}
6576

6677
/* Produce single list on stdout of all GMT custom module names for gmt --show-modules */
67-
void gmt_custom_module_list_all (void *API) {
78+
void gmt_custom_module_list_all (void *V_API) {
6879
unsigned int module_id = 0;
69-
gmt_M_unused(API);
70-
while (g_custom_module[module_id].name != NULL) {
71-
printf ("%s\n", g_custom_module[module_id].name);
80+
gmt_M_unused(V_API);
81+
while (g_custom_module[module_id].cname != NULL) {
82+
printf ("%s\n", g_custom_module[module_id].mname);
83+
++module_id;
84+
}
85+
}
86+
87+
/* Produce single list on stdout of all GMT custom module names for gmt --show-classic [i.e., classic mode names] */
88+
void gmt_custom_module_classic_all (void *V_API) {
89+
unsigned int module_id = 0;
90+
size_t n_modules = 0;
91+
gmt_M_unused(V_API);
92+
93+
while (g_custom_module[n_modules].cname != NULL) /* Count the modules */
94+
++n_modules;
95+
96+
/* Sort array on classic names since original array is sorted on modern names */
97+
qsort (g_custom_module, n_modules, sizeof (struct Gmt_moduleinfo), sort_on_classic);
98+
99+
while (g_custom_module[module_id].cname != NULL) {
100+
printf ("%s\n", g_custom_module[module_id].cname);
72101
++module_id;
73102
}
74103
}
@@ -78,9 +107,9 @@ const char *gmt_custom_module_keys (void *API, char *candidate) {
78107
int module_id = 0;
79108
gmt_M_unused(API);
80109

81-
/* Match actual_name against g_module[module_id].name */
82-
while (g_custom_module[module_id].name != NULL &&
83-
strcmp (candidate, g_custom_module[module_id].name))
110+
/* Match actual_name against g_module[module_id].cname */
111+
while (g_custom_module[module_id].cname != NULL &&
112+
strcmp (candidate, g_custom_module[module_id].cname))
84113
++module_id;
85114

86115
/* Return Module keys or NULL */
@@ -92,9 +121,9 @@ const char *gmt_custom_module_group (void *API, char *candidate) {
92121
int module_id = 0;
93122
gmt_M_unused(API);
94123

95-
/* Match actual_name against g_module[module_id].name */
96-
while (g_custom_module[module_id].name != NULL &&
97-
strcmp (candidate, g_custom_module[module_id].name))
124+
/* Match actual_name against g_module[module_id].cname */
125+
while (g_custom_module[module_id].cname != NULL &&
126+
strcmp (candidate, g_custom_module[module_id].cname))
98127
++module_id;
99128

100129
/* Return Module keys or NULL */

src/gmt_custom_module.c.orig

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/* $Id$
2+
*
3+
* Copyright (c) 2016-2018 by pwessel
4+
* See LICENSE.TXT file for copying and redistribution conditions.
5+
*/
6+
7+
/* gmt_custom_module.c populates the local array g_custom_module
8+
* with parameters such as name, group, purpose and keys strings.
9+
* This file also contains the following convenience functions to
10+
* display all module purposes or just list their names:
11+
*
12+
* void gmt_custom_module_show_all (void *API);
13+
* void gmt_custom_module_list_all (void *API);
14+
*
15+
* These functions may be called by gmt --help and gmt --show-modules
16+
*
17+
* DO NOT edit this file directly! Regenerate the file by running
18+
* gmt_make_custom_code.sh
19+
*/
20+
21+
#include "gmt.h"
22+
#include "gmt_custom_module.h"
23+
#include <string.h>
24+
25+
#ifndef gmt_M_unused
26+
#define gmt_M_unused(x) (void)(x)
27+
#endif
28+
29+
/* Sorted array with information for all custom modules */
30+
31+
/* name, library, and purpose for each module */
32+
struct Gmt_moduleinfo {
33+
const char *name; /* Program name */
34+
const char *component; /* Component (core, supplement, custom) */
35+
const char *purpose; /* Program purpose */
36+
const char *keys; /* Program option info for external APIs */
37+
};
38+
39+
static struct Gmt_moduleinfo g_custom_module[] = {
40+
{"gmtaverage", "custom", "Block average (x,y,z) data tables by mean, median, or mode estimation", "<DI,>DO,RG-"},
41+
{"gmtmercmap", "custom", "Make a Mercator color map from ETOPO 1, 2, or 5 arc min global relief grids", "CCi,>XO,RG-"},
42+
{"gmtparser", "custom", "Demonstrate parsing of input data, defaults, and options", ""},
43+
{"grdfourier", "custom", "Create a grid, add a spike, filter it in frequency domain, and write output", "<GI,GGO,RG-"},
44+
{NULL, NULL, NULL, NULL} /* last element == NULL detects end of array */
45+
};
46+
47+
/* Pretty print all GMT custom module names and their purposes for gmt --help */
48+
void gmt_custom_module_show_all (void *V_API) {
49+
unsigned int module_id = 0;
50+
char message[256] = {""};
51+
GMT_Message (V_API, GMT_TIME_NONE, "\n=== " "GMT custom: Tools for the custom project" " ===\n");
52+
while (g_custom_module[module_id].name != NULL) {
53+
if (module_id == 0 || strcmp (g_custom_module[module_id-1].component, g_custom_module[module_id].component)) {
54+
/* Start of new supplemental group */
55+
sprintf (message, "\nModule name: Purpose of %s module:\n", g_custom_module[module_id].component);
56+
GMT_Message (V_API, GMT_TIME_NONE, message);
57+
GMT_Message (V_API, GMT_TIME_NONE, "----------------------------------------------------------------\n");
58+
}
59+
sprintf (message, "%-16s %s\n",
60+
g_custom_module[module_id].name, g_custom_module[module_id].purpose);
61+
GMT_Message (V_API, GMT_TIME_NONE, message);
62+
++module_id;
63+
}
64+
}
65+
66+
/* Produce single list on stdout of all GMT custom module names for gmt --show-modules */
67+
void gmt_custom_module_list_all (void *API) {
68+
unsigned int module_id = 0;
69+
gmt_M_unused(API);
70+
while (g_custom_module[module_id].name != NULL) {
71+
printf ("%s\n", g_custom_module[module_id].name);
72+
++module_id;
73+
}
74+
}
75+
76+
/* Lookup module id by name, return option keys pointer (for external API developers) */
77+
const char *gmt_custom_module_keys (void *API, char *candidate) {
78+
int module_id = 0;
79+
gmt_M_unused(API);
80+
81+
/* Match actual_name against g_module[module_id].name */
82+
while (g_custom_module[module_id].name != NULL &&
83+
strcmp (candidate, g_custom_module[module_id].name))
84+
++module_id;
85+
86+
/* Return Module keys or NULL */
87+
return (g_custom_module[module_id].keys);
88+
}
89+
90+
/* Lookup module id by name, return group char name (for external API developers) */
91+
const char *gmt_custom_module_group (void *API, char *candidate) {
92+
int module_id = 0;
93+
gmt_M_unused(API);
94+
95+
/* Match actual_name against g_module[module_id].name */
96+
while (g_custom_module[module_id].name != NULL &&
97+
strcmp (candidate, g_custom_module[module_id].name))
98+
++module_id;
99+
100+
/* Return Module keys or NULL */
101+
return (g_custom_module[module_id].component);
102+
}

src/gmt_custom_module.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
/* $Id$
2-
*
3-
* Copyright (c) 2016-2018 by pwessel
1+
/*
2+
* Copyright (c) 2012-2020 by the GMT Team (https://www.generic-mapping-tools.org/team.html)
43
* See LICENSE.TXT file for copying and redistribution conditions.
54
*/
65

76
/* gmt_custom_module.h declares the prototypes for custom module functions
87
* and the array that contains custom GMT module parameters such as name
98
* and purpose strings.
10-
* DO NOT edit this file directly! Regenerate the file by running
11-
* gmt_make_custom_code.sh
9+
* DO NOT edit this file directly! Regenerate thee file by running
10+
* gmt_make_module_src.sh custom
1211
*/
1312

1413
#pragma once
15-
#ifndef _GMT_CUSTOM_MODULE_H
16-
#define _GMT_CUSTOM_MODULE_H
14+
#ifndef GMT_CUSTOM_MODULE_H
15+
#define GMT_CUSTOM_MODULE_H
1716

1817
#ifdef __cplusplus /* Basic C++ support */
1918
extern "C" {
@@ -30,13 +29,17 @@ EXTERN_MSC int GMT_grdfourier (void *API, int mode, void *args);
3029

3130
/* Pretty print all modules in the GMT custom library and their purposes */
3231
EXTERN_MSC void gmt_custom_module_show_all (void *API);
33-
/* List all modules in the GMT custom library to stdout */
32+
/* List all modern modules in the GMT custom library to stdout */
3433
EXTERN_MSC void gmt_custom_module_list_all (void *API);
34+
/* List all classic modules in the GMT custom library to stdout */
35+
EXTERN_MSC void gmt_custom_module_classic_all (void *API);
3536
/* Function called by GMT_Encode_Options so developers can get information about a module */
36-
EXTERN_MSC const char * gmt_custom_module_info (void *API, char *candidate);
37+
EXTERN_MSC const char * gmt_custom_module_keys (void *API, char *candidate);
38+
/* Function returns name of group that module belongs to (core, spotter, etc.) */
39+
EXTERN_MSC const char * gmt_custom_module_group (void *API, char *candidate);
3740

3841
#ifdef __cplusplus
3942
}
4043
#endif
4144

42-
#endif /* !_GMT_CUSTOM_MODULE_H */
45+
#endif /* !GMT_CUSTOM_MODULE_H */

0 commit comments

Comments
 (0)