Challenge: I want to collect all files I regularly use in a folder and use in gmt scripts without having to supply full/relative paths - just filename. The datadir
variable sounds promising. But…
-
How do you set the datadir
variable? This is an environment variable, right?
$ gmt --show-datadir
Not set
or
$ gmt-config --datadir
Not set
-
I’ve been looking in the docs, but I can’t see any definite place for where I can look up all environment variables used by gmt and that can be set. Any know where, if it exists?
Edit:
In ConfigUserAdvancedTemplate.cmake
I see
# Set share installation path [share or share/gmt${GMT_INSTALL_NAME_SUFFIX}]:
#set (GMT_DATADIR "share/gmt")
But assuming this really is the share dir and has nothing to do with the datadir that you get from --show-datadir
;
$ gmt --show-sharedir
/usr/local/share
Suggest you look at the description of DIR variables in the manual: https://docs.generic-mapping-tools.org/dev/cookbook/features.html#directory-parameters
The simplest sokution may be to place files in your ~/.gmt directory
1 Like
Exactly what I was looking for.
Thanks @biggle1856!
Setting GMT_DATADIR=path
does what I want.
A bit curious how this relates to the datadir in,
$ gmt --show-datadir
Not set
OK, a little debugging exercise, without really using the debugger but just the fantastic VisualStudioCode search search capabilities.
Looking at gmt.c we easily find
/* Show share directory */
else if (!strncmp (argv[arg_n], "--show-datadir", 14U)) {
if (api_ctrl->GMT->session.DATADIR == NULL)
fprintf(stdout, "Not set\n");
next, I search for all occurrences of GMT->session.DATADIR
in entire GMT source code and see this one in particular in gmt_init.c
if ((this_c = getenv ("GMT_DATADIR")) != NULL) { /* GMT_DATADIR was set */
if (strchr (this_c, ',') || strchr (this_c, PATH_SEPARATOR)) {
/* A list of directories [not checked for validity here] */
GMT->session.DATADIR = strdup (this_c);
so, yes, if GMT_DATADIR
is set as an environment variable you can put your files there. This is documented somewhere (didn’t search) and I also remember there was another one more tailored to store grids.
1 Like
Thanks @Joaquim for sharing. I tried grep -rn "datadir" *
…
If I set GMT_DATADIR
, should this path show up in gmt --show-datadir
?
Looking at gmt.c, it seems like it’s related to sessions, and it also refers to share directory:
/* Show share directory */
else if (!strncmp (argv[arg_n], "--show-datadir", 14U)) {
if (api_ctrl->GMT->session.DATADIR == NULL)
fprintf(stdout, "Not set\n");
else
fprintf(stdout, "%s\n", api_ctrl->GMT->session.DATADIR);
status = GMT_NOERROR;
}
Yes it should.
session
is the structure field name where the path variable is stored. Internal stuff.
Compare that with the results of a global search in VSC