Giter Club home page Giter Club logo

gmtmex's Introduction

GMT/MEX - GMT API for MATLAB

Extended Docs

https://github.com/GenericMappingTools/gmtmex/wiki

Introduction

The GMT MATLAB interface makes it possible to access all GMT modules from MATLAB. Users of MATLAB can write MATLAB scripts that call upon GMT modules to do any of the things GMT normally can do, and return the results (grids, data-tables, CPTs, text-files, and even final images via psconvert) to MATLAB variables. MATLAB matrices can be given as input to GMT modules. Examples below will give you the general idea.

Installing

Windows

The Windows installers come already with the gmtmex.mexw64|32 and gmt.m files necessary run the MEX. Only make sure that the GMT6.4 binary dir is either in the Windows path (the installer does that for you) and in the MATLAB path (you have to do it yourself). If you want to (re)build the MEX file yourself, see the compile_mex.bat in the source SVN repository.

macOS

We have successfully built the MATLAB interface under macOS. However, due to the way MATLAB handles shared libraries it is a delicate process, with several caveats. This may change over time as we work with MathWorks to straighten out the kinks. The following works:

  • Install the GMT macOS Bundle
  • Run the gmt_prepmex.sh script in the bundle's share/tools directory. This will duplicate the GMT 6.4 installation into /opt/gmt and re-baptize all the shared libraries.
  • Use gmtswitch to make /opt/gmt the current active GMT version
  • Checkout the gmtmex project via git into some directory, i.e.,
    git clone https://github.com/GenericMappingTools/gmtmex.git
    
  • In gmtmex/, run autoconf then configure --enable-matlab (and maybe --enable-debug) is you can help debug things.
  • Run make which builds the gmtmex.mexmaci64 (x86_64) or gmtmex.mexmaca64 (arm64). This executable is accessed by the gmt.m script.
  • Set your MATLAB path so these two can be found (or copy them to a suitable directory).
  • Make sure your gmt.conf file has the entry GMT_CUSTOM_LIBS=/opt/gmt/lib/gmt/plugins/supplements.so.

You can also build your own bundle (see CMakeLists.txt in main GMT directory). The above works with UNIX installations from fink or HomeBrew but fails for us if under MacPorts (then, MATLAB will complain about wrong shared HDF5 library and we crash). If you wish to help debug in XCode then see the gmtmex wiki for more details. While the latest 2023b MATLAB version works with XCode 14, earlier versions may require an older Xcode version. We used the 2023b MATLAB version to build the interface.

Unix/Linux

Preliminary experiments indicate we will have to fight the shared library dilemma here as well. Volunteers on Linux wishing to run the GMT MATLAB interface are needed to make progress.

Using

The MATLAB wrapper was designed to work in a way the closest as possible to the command line version and yet to provide all the facilities of the MATLAB IDE (the ML command line desktop). In this sense, all GMT options are put in a single text string that is passed, plus the data itself when it applies, to the gmt() command. For example to reproduce the CookBook example of an Hemisphere map using a Azimuthal projection

gmt('pscoast -Rg -JA280/30/3.5i -Bg -Dc -A1000 -Gnavy -P > GMT_lambert_az_hemi.ps')

but that is not particularly interesting as after all we could do the exact same thing on the a shell command line. Things start to get interesting when we can send data in and out from MATLAB to GMT. So, consider the following example

t = rand(100,3) * 150;
G = gmt('surface -R0/150/0/150 -I1', t);

Here we just created a random data 100x3 matrix and told GMT to grid it using it's program surface. Note how the syntax follows closely the standard usage but we sent the data to be interpolated (the t matrix) as the second argument to the gmt() function. And on return we got the G variable that is a structure holding the grid and it's metadata. See the grid struct for the details of its members.

Imagining that we want to plot that random data art, we can do it with a call to grdimage, like

gmt('grdimage -JX8c -Ba -P -Cblue,red > crap_img.ps', G)

Note that we now sent the G grid as argument instead of the -G gridname that we would have used in the command line. But for readability we could well had left the -G option in command string. E.g:

gmt('grdimage -JX8c -Ba -P -Cblue,red -G > crap_img.ps', G)

While for this particular case it makes no difference to use or not the -G, because there is only one input, the same does not hold true when we have more than one. For example, we can run the same example but compute the CPT separately.

cpt = gmt('grd2cpt -Cblue,red', G);
gmt('grdimage -JX8c -Ba -P -C -G > crap_img.ps', G, cpt)

Now we had to explicitly write the -C & -G (well, actually we could have omitted the -G because it's a mandatory input but that would make the things more confusing). Note also the order of the input data variables. It is crucial that any required (primary) input data objects (for grdimage that is the grid) are given before any optional (secondary) input data objects (here, that is the CPT object). The same is true for modules that return more than one item: List the required output object first followed by optional ones.

To illustrate another aspect on the importance of the order of input data let us see how to plot a sine curve made of colored filled circles.

x = linspace(-pi, pi)';            % The *xx* var
seno = sin(x);                     % *yy*
xyz  = [x seno seno];              % Duplicate *yy* so that it can be colored
cpt  = gmt('makecpt -T-1/1/0.1');  % Create a CPT
gmt('psxy -R-3.2/3.2/-1.1/1.1 -JX12c -Sc0.1c -C -P -Ba > seno.ps', xyz, cpt)

The point here is that we had to give xyz, cpt and not cpt, xyz (which would error) because optional input data associated with an option letter always comes after the required input.

To plot text strings we send in the input data wrapped in a cell array. Example:

lines = {'5 6 Some label', '6 7 Another label'};
gmt('pstext -R0/10/0/10 -JM6i -Bafg -F+f18p -P > text.ps', lines)

and we get back text info in cell arrays as well. Using the G grid computed above we can run gmtinfo on it

info = gmt('info', G)

At the end of an GMT session work we call the internal functions that will do the house keeping of freeing no longer needed memory. We do that with this command:

gmt('destroy')

So that's basically how it works. When numeric data have to be sent in to GMT we use MATLAB variables holding the data in matrices or structures or cell arrays, depending on data type. On return we get the computed result stored in variables that we gave as output arguments. Things only complicate a little more for the cases where we can have more than one input or output arguments, since the order or the arguments matter (Remember the rule: primary first, secondary second). The file gallery.m, that reproduces the examples in the Gallery section of the GMT documentation, has many (not so trivial) examples on usage of the MEX GMT API.

gmtmex's People

Contributors

joa-quim avatar leouieda avatar paulwessel avatar remkos avatar seisman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

gmtmex's Issues

GMT-MEX API is failed when using grdimage

Hello,

I tried to use GMT-MEX API on MacOS 10.13 with MATLAB R2018b. When I execute these commands, it reports the error message as following,

t = rand(100,3) * 150;
G = gmt('surface -R0/150/0/150 -I1', t);
gmt('grdimage -JX8c -Ba -P -Cblue,red -G > crap_img.ps', G)
[Session Matlab (2)]: Error returned from GMT API: GMT_OBJECT_NOT_FOUND (59)
Error using gmtmex
GMT: Failure to open virtual file
Error in gmt (line 33)
	[varargout{1:nargout}] = gmtmex (cmd, varargin{:});

The GMT version on my laptop is 6.0.0_c1a5c7c. Would you help me fix this problem?

With Regards,
Chi-Yu Chiu

grdcut -N on larger region results in no grid extension

Hello everyone,

Description of the problem

I am trying to extend a grid onto a new region, including but exceeding the original boundaries, using grdcut with the -N option.
However, the returned grid structure retains the original region unchanged: no nan-padding occurs.

Full script that generated the error

This minimal example reproduces the issue:

region_0 = [-5, 5, -10, 10];
n_el = [21, 41];

x = linspace(region_0(1), region_0(2), n_el(1));
y = linspace(region_0(3), region_0(4), n_el(2));
inc = [x(2) - x(1), y(2) - y(1)];
z = ones(length(y), length(x));
header = [region_0, min(z(:)), max(z(:)), 0, inc];

G_0 = gmt('wrapgrid', z, header);

region_1 = [-6, 6, -11, 11];
G_1 = gmt(['grdcut -Vd -N -R', sprintf('%g/%g/%g/%g', region_1)], G_0);

assert(all(region_1 == G_1.range(1:4)))

This also fails with fill values other than nan, e.g. -N0.

G_1 region is left unchanged, still equal to G_0 extents:

>> G_0.range
ans =    -5     5   -10    10     1     1
>> G_1.range
ans =    -5     5   -10    10     1     1

Writing G_0 to file and calling gmt grdcut -N outside Matlab, from the shell, the nan-fill extension works as expected.

Full error message

grdcut [DEBUG]: Got regular w/e/s/n for region (-6/6/-11/11)
grdcut [INFORMATION]: Processing input grid
grdcut [DEBUG]: Set_Object for family: 1
grdcut [INFORMATION]: Cartesian input grid
grdcut [INFORMATION]: Requested subset exceeds data domain on the left side - nodes in the extra area will be initialized to -nan(ind)
grdcut [INFORMATION]: Requested subset exceeds data domain on the right side - nodes in the extra area will be initialized to -nan(ind)
grdcut [INFORMATION]: Requested subset exceeds data domain on the bottom side - nodes in the extra area will be initialized to -nan(ind)
grdcut [INFORMATION]: Requested subset exceeds data domain on the top side - nodes in the extra area will be initialized to -nan(ind)
grdcut [DEBUG]: Set_Object for family: 1
grdcut [INFORMATION]: Cartesian input grid
grdcut [DEBUG]: gmtapi_expand_headerpad: No pad adjustment needed
grdcut [DEBUG]: Chosen boundary condition for all edges: natural
grdcut [INFORMATION]: gmt_grd_BC_set: Set boundary condition for all edges: natural
grdcut [INFORMATION]: gmt_grd_BC_set: Set boundary condition for left   edge: natural
grdcut [INFORMATION]: gmt_grd_BC_set: Set boundary condition for right  edge: natural
grdcut [INFORMATION]: gmt_grd_BC_set: Set boundary condition for bottom edge: natural
grdcut [INFORMATION]: gmt_grd_BC_set: Set boundary condition for top    edge: natural
grdcut [DEBUG]: Object ID 17 : Registered Grid Memory Reference f3c22b56c0 as an Input resource with geometry Surface [n_objects = 3]
grdcut [DEBUG]: Successfully duplicated a Grid
==> 3 API Objects at end of GMT_Duplicate_Data
--------------------------------------------------------
K.. ID RESOURCE.... FAMILY.... ACTUAL.... DIR... S O M L
--------------------------------------------------------
* 0 15   f3c22bfe30 Grid       Grid       Input  0 Y N 0
* 1 16   f3c22bfbc0 Grid       Grid       Output 0 Y Y 0
* 2 17   f3c22b56c0 Grid       Grid       Input  0 Y N 1
--------------------------------------------------------
grdcut [INFORMATION]: File spec:	W E S N dx dy n_columns n_rows:
grdcut [INFORMATION]: Old:grdcut [INFORMATION]: 	-5	5	-10	10	0.5	0.5	21	41
grdcut [INFORMATION]: New:grdcut [INFORMATION]: 	-6	6	-11	11	0.5	0.5	25	45
grdcut [DEBUG]: GMT_Write_Data: Writing Grid to memory object 16 from object 17 which transfers ownership
grdcut [DEBUG]: gmtapi_begin_io: Output resource access is now enabled [container]
grdcut [DEBUG]: gmtapi_export_data: Messenger dummy output container for object 16 [item 1] freed and set resource=data=NULL
grdcut [DEBUG]: gmtapi_export_grid: Passed ID = 16 and mode = 0
grdcut [INFORMATION]: Referencing grid data to GMT_GRID memory location
grdcut [DEBUG]: Chosen boundary condition for all edges: natural
grdcut [INFORMATION]: gmt_grd_BC_set: Set boundary condition for all edges: natural
grdcut [INFORMATION]: gmt_grd_BC_set: Set boundary condition for left   edge: natural
grdcut [INFORMATION]: gmt_grd_BC_set: Set boundary condition for right  edge: natural
grdcut [INFORMATION]: gmt_grd_BC_set: Set boundary condition for bottom edge: natural
grdcut [INFORMATION]: gmt_grd_BC_set: Set boundary condition for top    edge: natural
grdcut [DEBUG]: GMT_End_IO: Output resource access is now disabled
grdcut [DEBUG]: Set_Object for family: 1
==> 3 API Objects at end of GMT_Write_Data
--------------------------------------------------------
K.. ID RESOURCE.... FAMILY.... ACTUAL.... DIR... S O M L
--------------------------------------------------------
* 0 15   f3c22bfe30 Grid       Grid       Input  0 Y N 0
* 1 16   f3c22b56c0 Grid       Grid       Output 2 Y N 0
* 2 17   f3c22b56c0 Grid       Grid       Input  0 N N 1
--------------------------------------------------------
==> 3 API Objects at end of GMTAPI_Garbage_Collection entry
--------------------------------------------------------
K.. ID RESOURCE.... FAMILY.... ACTUAL.... DIR... S O M L
--------------------------------------------------------
* 0 15   f3c22bfe30 Grid       Grid       Input  0 Y N 0
* 1 16   f3c22b56c0 Grid       Grid       Output 2 Y N 0
* 2 17   f3c22b56c0 Grid       Grid       Input  0 N N 1
--------------------------------------------------------
grdcut [DEBUG]: gmtlib_unregister_io: Unregistering object no 17 [n_objects = 2]
==> 2 API Objects at end of GMTAPI_Garbage_Collection exit
--------------------------------------------------------
K.. ID RESOURCE.... FAMILY.... ACTUAL.... DIR... S O M L
--------------------------------------------------------
* 0 15   f3c22bfe30 Grid       Grid       Input  0 Y N 0
* 1 16   f3c22b56c0 Grid       Grid       Output 2 Y N 0
--------------------------------------------------------

System information

  • Operating system: Windows 10
  • Version of GMT: 6.4.0
  • Version of GMTMex: 2.1.0

Inability to free what GMT_Encode_Options return

Description of the problem

Since I am building GMT with DEBUG and MEM_DEBUG I get messages upon module exit if there were memory leaks. WHen I quit MATLAB after testing gmtmex I may get many of these, probably one for each module call:

Matlab [WARNING]: Memory not freed first allocated in gmt_api.c:12781(GMT_Encode_Options) (ID = 141): 0.141 kb [144 bytes]

The problem is that gmtmex.c does not bother to free the info structure array returned by GMT_Encode_Options. OK, so two issues:

  1. That array is allocated with GMT_memory and thus is tracked by GMT's garbage man
  2. The API has no way of calling GMT_free since all it has is GMT_Destroy_Data which would not work on some random array.

I think the solution is:

  1. Let GMT_Encode_Options allocate directly with malloc/realloc and not GMT_memory
  2. Let gmtmex.c clean up after itself.

OK with you @joa-quim ?

calling pstext using a cell array makes MATLAB crash

Description of the problem

I'm using the gmtmex of MATLAB-API. I encountered a calling problem that made MATLAB crash.
I've tried different ways of putting data into a cell array according to the paper (Wessel and Luis, 2017). This is the code:

 txt = {[110, 30], 'CIRCULAR'};
 gmt(['pstext -R -J -O >> ' outfn '.ps'], txt{1, :});

this code didn't make MATLAB crash ever. (see the complete code following)

Full script that generated the error

However, it throw an ERROR message:

" pstext [ERROR]: Text record line 0 is NULL! Skipped but this is trouble)".

outfn = 'ex2HL_arrows'; % must single quotaion

gmt('pscoast -R70/150/0/60 -JM15c -Ba -A4000 -N1 -W0.25p,black -K > ex2HL_arrows.ps')
%% plot 12 Cartesian vectors with different lengths
x = linspace(109, 109, 12)';
y = linspace(30, 50, 12)';
direction = zeros(size(x));
length = linspace(0.5, 1.5, 12)';
% Cartesian vectors (v) with red pen and fill (+g, +p), vector head at
% end (+e), and 40 degree angle (+a) with no indentation for vector head (+h)
style = 'v0.2c+e+a40+gred+h0+p1p,red';
vector = [x y direction length];
% gmt('psxy', ['-R20/60/-180/0 -JM12c -W1p,red -S' style  ' > ' outfn '.ps'], vector);
gmt(['psxy -R -J -Ba -W1p,red -S' style ' -K -O >> ' outfn '.ps'], vector);


%% plot 7 math angle arcs with different radii
num = 7;
x = linspace(95, 95, num)'; % x coordinates of the center
y = linspace( 37, 37, num)';  %# y coordinates of the center
radius = 1.8 - 0.2 * (0 : num - 1)';%  # radius
startdir = linspace(90, 90, num)';  % #start direction in degrees
stopdir = 180 + 40 * (0 : num - 1)';  %# stop direction in degrees
%# data for circular vectors
data = [x y radius startdir stopdir];
arcstyle = 'm0.5c+ea';  %# Circular vector (m) with an arrow at end
gmt(['psxy -R -J -Gred3 -W1.5p,black -S' arcstyle ' -K -O >> ' outfn '.ps'], data)


%% plot geographic vectors using endpoints
PEK = [116.41, 39.9]; % Peking
XAN = [108.9, 34.3];  % Xi'an
XJG = [87.62, 43.79]; % XinJiang
KMG = [102.71, 25.04]; % KunMing
% `=` means geographic vectors.
% With the modifier '+s', the input data should contain coordinates of start
% and end points
style = '=0.5c+s+e+a30+gblue+h0.5+p1p,blue';
data = [[PEK  XAN]; [PEK  XJG]; [PEK  KMG]];
gmt(['psxy -R -J -S' style ' -W1.0p,blue -K -O >> ' outfn '.ps'], data);
txt = {[110, 30], 'CIRCULAR'};
%gmt(['pstext -R -J -F+f13p,Helvetica-Bold,red -O >> ' outfn '.ps'], txt);
gmt(['pstext -R -J -O >> ' outfn '.ps'], txt(1, :));

gmt(['psconvert -A -Tg -E600 ' outfn '.ps']);
gmt(['psconvert -A -Tgf ' outfn '.ps']);
gmt('destroy');
open([outfn '.pdf']);




Full error message

 pstext [ERROR]: Text record line 0 is NULL! Skipped but this is trouble)

System information

  • Operating system: Win10
  • Version of GMT: gmt 6.3
  • Version of GMTMex: gmt6.3
  • MATLAB version: 2021b

我在安装gmtmex时,Matlab显示mex错误

Description of the problem
我在安装gmtmex时,Matlab显示mex错误

图像2022-9-14 23 33

Full script that generated the error

PASTE CODE HERE

Full error message

PASTE ERROR MESSAGE HERE

System information

  • Operating system:
  • Version of GMT:
  • Version of GMTMex:

Shrink gmtmex.c by growing gmtmex_parser.c to be included in GMT core

Description of the desired feature

The gmtmex.extension library with the mexFunction needs to be built using the user's MATLAB version. Hence, we want to move as much of the code in gmtmex.c into the gmtmex_parser.c as possible to keep things simple. It seems to me that the ultimate mexFunction would just be something like this:

#include "gmtmex.h"
void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
	gmt_mexfunction (nlhs, plus, nrhs, prhs);
	return;
}

Does gmtmex.c really need more in it, @joa-quim if we just place the rest in gmt_mexfunction and stick in the gmtmex_parser.c in libgmt?

Error with psconvert on Example 2 Profilling

Description of the problem

I started using the GMTMEX on a windows computer. I start by running the examples from The GMT/MATLAB Toolbox 2017 paper. They all run as described except, for example 2 . When running the following line of code

I = gmt ('psconvert -TG -P -E300 -A', P);

I get the following error.

Full error message

psconvert [ERROR]: System call [@"C:\Program Files\gs\gs10.01.1\bin\gswin64c.exe" -q -dNOSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox -DPSL_no_pagefill -dMaxBitmap=2147483647 -dUseFastColor=true "C:\Users\pdq\AppData\Local\Temp/psconvert_stream_13184.ps" 2> "./psconvert_13184c.bb"] returned error 1.
GMT: Module return with failure while executing the command
psconvert -TG -P -E300 -A
Error using gmtmex
GMT: exiting

I install the latest gs version, before I had the 9.2 version and I had the same error.

Full script that generated the error
Here is the full matlab script

clear; clc; close all
% Read in relief grid and Japan trench location
G = gmt ('read -Tg JP.nc');
T = gmt ('read -Td JP.txt');
% Take gradient in N45E direction to be used for illumination
intens = gmt ('grdgradient -Nt0.8 -A90', G);
% Sample grid along profiles normal to the trench
[profiles, stack] = gmt ('grdtrack -G -C300k/1k/25k -Sm+s+a', T, G);
% Evaluate an asymmetrical color palette with hinge at sealevel
C = gmt ('makecpt', '-Cgeo -T-8000/2000');
% Make the GMT plot
P = gmt ('grdimage', ['-R141/147/35/42 -JM6i -P -Baf -BWSne -I -K -C ' ...
    '--FORMAT_GEO_MAP=dddF'], G, intens, C);
P = gmt ('pscoast', ['-R -J -O -K -W0.25p -Dh ' ...
    '-LjTR+w200k+u+f+c38:30N+o0.5i/0.2i -F+gwhite+p0.5p']);
% Use first and last point of each profile and create a polygon of the area
A = gmt('convert', '-Ef -T', profiles);
B = gmt('convert', '-El -T -Is', profiles);
area = gmt ('catsegment', [A B]); % Join the two segments
P = gmt ('psxy', '-R -J -O -K -Ggreen@85', area);
P = gmt ('psxy -R -J -O -K -W2p+v0.3c+gred+p0.25p+bc+ec', T);
P = gmt ('psxy -R -J -O -K -W0.5p,red+v0.25c+p0.25p+bt+et', profiles);
P = gmt ('psscale', ['-R -J -O -DjBL+w3i/0.1i+h+o0.3i/0.4i -C -W0.001 ' ...
    '-F+gwhite+p0.5p+i0.25p -Bxaf -By+l"km"'], C);

I = gmt ('psconvert -TG -P -E300 -A', P); % Windows Version

figure(1); clf
h = imshow (I.image); set (h, 'AlphaData', I.alpha)
% Figure 1 shows the stacked relief profiles across the trench
figure(2); clf; hold on
for k=1:length(profiles)
    plot (profiles(k).data(:,3), profiles(k).data(:,5))
end
plot (stack.data(:,1), stack.data(:,2), 'LineWidth', 3)
xlabel('Distance (km)'); ylabel ('Depth (m)')
title ('Japan Trench Profiles'); xlim ([-150 150]); grid on

System information

  • Operating system: Windows 10
  • Version of GMT: GMT 6.4
  • Version of GMTMex: Not sure of this, but I am assuming the latest from the GMT 6.4 version

Version /gmt/opt is not listed among recognized GMT versions

Description of the problem

I installed the GMT latest vesrsion and have matlab on my Mac. Now I want to install the GMT API for matlab. After installation of gmt_prepmex.sh, it gives me following error on next step. Please help

Version /gmt/opt is not listed among recognized GMT versions.
Run gmtswitch -help for more information

System information

  • Operating system: Mac
  • Version of GMT: 5.4.4 (r20314)
  • Version of GMTMex: Don't know how to get this info

Compilation warnings on Linux

Description of the problem

gmtmex.c: In function ‘mexFunction’:
gmtmex.c:213:3: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
   if (!pPersistent || (API = (void *)pPersistent[0]) == NULL)
   ^~
gmtmex.c:215:4: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
    mexAtExit(force_Destroy_Session); /* Register an exit function. */
    ^~~~~~~~~
gcc -I/home/runner/work/gmtmex/gmt-install-dir/include/gmt -I/usr/include/octave-4.2.2/octave -O2 -Wall -m64 -fPIC -fno-strict-aliasing -std=c99 -DGMT_OCTMEX -I/home/runner/work/gmtmex/gmt-install-dir/include/gmt -c gmtmex_parser.c
gmtmex_parser.c: In function ‘gmtmex_palette_init’:
gmtmex_parser.c:1106:44: warning: variable ‘minmax’ set but not used [-Wunused-but-set-variable]
   double *colormap = NULL, *range = NULL, *minmax = NULL, *alpha = NULL, *bfn = NULL, *hinge = NULL, *cpt = NULL, *cyclic = NULL;
                                            ^~~~~~
gmtmex_parser.c:1106:11: warning: variable ‘colormap’ set but not used [-Wunused-but-set-variable]
   double *colormap = NULL, *range = NULL, *minmax = NULL, *alpha = NULL, *bfn = NULL, *hinge = NULL, *cpt = NULL, *cyclic = NULL;
           ^~~~~~~~

Location of gmtmex.mexw64 file

Description of the problem
I am trying to install gmtmex for MatLab in my Windows computer. However, I cannot find the gmtmex.mexw64 anywhere. Can somebody tell me how to get such file?

Building gmtmex on Linux

While searching for documentation regarding building gmtmex on Linux, I noticed that the readme was looking for volunteers. With the steps outlined below, I am able to get GMT to work with my MATLAB project on Ubuntu 18.04. I am sure there is a more elegant way of achieving this, however, I thought it best to share this solution, since it does appear to work well.

With both MATLAB R2019a and GMT Version 6.1.0_3ede8d1_2019.08.04 installed in /home, in the gmtmex directory cloned from GitHub:

  1. Built gmtmex object file as
    gcc -I$GMT_dir/include/gmt -I$MATLAB_dir/extern/include -O2 -Wall -m64 -fPIC -fno-strict-aliasing -std=c99 -DGMT_MATLAB -I$GMT_dir/include/gmt -c gmtmex.c

  2. Built gmtmex_parser object file as
    gcc -I$GMT_dir/include/gmt -I$MATLAB_dir/extern/include -O2 -Wall -m64 -fPIC -fno-strict-aliasing -std=c99 -DGMT_MATLAB -I$GMT_dir/include/gmt -c gmtmex_parser.c

  3. Compiled mex file as
    $MATLAB_dir/bin/mex -DGMT_MATLAB -I$GMT_dir/include/gmt -I/$GMT_dir/include/gmt/lib -I$MATLAB_dir/extern/include gmtmex.o gmtmex_parser.o -L$GMT_dir/lib -lgmt -L$MATLAB_dir/bin/glnxa64 -lmx -lmex -output gmtmex.mexa64

Copied over the gmt.m and generated gmtmex.mexa64 files to $GMT_dir/bin, added $GMT_dir along with subfolders to MATLAB path.

In order to prevent runtime errors associated with MATLAB not being able to find shared libraries, launch MATLAB as:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GMT_dir/lib
export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libtiff.so.5:/usr/lib/x86_64-linux-gnu/libstdc++.so.6
$MATLAB_dir/bin/matlab

I hope this proves to be helpful. Please let me know in case further tests are required.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.