genericmappingtools / gmtmex Goto Github PK
View Code? Open in Web Editor NEWGMT API for MATLAB
Home Page: https://github.com/GenericMappingTools/gmtmex/wiki
License: GNU Lesser General Public License v2.1
GMT API for MATLAB
Home Page: https://github.com/GenericMappingTools/gmtmex/wiki
License: GNU Lesser General Public License v2.1
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?
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;
^~~~~~~~
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
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:
I think the solution is:
OK with you @joa-quim ?
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
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
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?
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
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:
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
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
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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.