update to gmt6 and change to cmake

This commit is contained in:
张壹 2021-01-10 14:49:37 +08:00
parent ad5ad5cee3
commit f97b2c3ef8
19 changed files with 60 additions and 60 deletions

View File

@ -2,12 +2,14 @@ cmake_minimum_required(VERSION 3.15.2 FATAL_ERROR)
project(GMT_API_EX VERSION 0.1.0 LANGUAGES CXX) project(GMT_API_EX VERSION 0.1.0 LANGUAGES CXX)
include_directories("/usr/local/include/gmt") include_directories(/usr/local/include/gmt)
find_library(${GMT_LIB} gmt "/usr/local/lib") find_library(GMT_LIB gmt /usr/local/lib)
macro(add_example name file) macro(add_example name file)
add_executable(${name} ${file}.cpp) add_executable(${name} ${file}.cpp)
target_link_libraries(${name} PUBLIC ${GMT_LIB}) target_link_libraries(${name} PUBLIC ${GMT_LIB})
endmacro() endmacro()
add_example(ex1 example1/gridding) add_example(ex1 src/gridding)
add_example(ex2 src/plot_grid)
add_example(ex3 src/plot_memory)

View File

@ -8,10 +8,15 @@ For those who wants to know more, please go to [GMT_site](https://www.generic-ma
## What are these examples? ## What are these examples?
* **example1**: call a GMT module to gridding a table data. * **griding**: call a GMT module to griding a table data.
* **example2**: read a grid file and call GMT modules to plot the grid to an image file. * **plot_grid**: read a grid file and call GMT modules to plot the grid to an image file.
* **example3**: create a GMT grid container and call GMT modules to plot the grid to an image file. * **plot_memory**: create a GMT grid container and call GMT modules to plot the grid to an image file.
## How to run the examples? ## How to run the examples?
Simply go to a example folder and run the `compile.sh`. Compile the executables and then run sequentially.
```shell
mkdir build && cd build && cmake .. && make
```

View File

@ -1,11 +1,11 @@
%!PS-Adobe-3.0 %!PS-Adobe-3.0
%%BoundingBox: 0 0 159 156 %%BoundingBox: 0 0 159 156
%%HiResBoundingBox: 0 0 158.8500 155.9520 %%HiResBoundingBox: 0 0 158.8500 155.9520
%%Title: GMT v6.0.0 [64-bit] Document from grdimage %%Title: GMT v6.1.1 [64-bit] Document from grdimage
%%Creator: GMT6 %%Creator: GMT6
%%For: unknown %%For: unknown
%%DocumentNeededResources: font Helvetica Times-Roman %%DocumentNeededResources: font Helvetica Times-Roman
%%CreationDate: Fri Sep 4 10:11:40 2020 %%CreationDate: Sun Jan 10 14:45:17 2021
%%LanguageLevel: 2 %%LanguageLevel: 2
%%DocumentData: Clean7Bit %%DocumentData: Clean7Bit
%%Orientation: Portrait %%Orientation: Portrait
@ -654,7 +654,8 @@ V 0.06 0.06 scale
/PSL_page_xsize 9917 def /PSL_page_xsize 9917 def
/PSL_page_ysize 14033 def /PSL_page_ysize 14033 def
/PSL_plot_completion {} def /PSL_plot_completion {} def
/PSL_movie_completion {} def /PSL_movie_label_completion {} def
/PSL_movie_prog_indicator_completion {} def
%PSL_End_Header %PSL_End_Header
gsave gsave
0 A 0 A
@ -662,12 +663,12 @@ FQ
O0 O0
1800 1800 TM 1800 1800 TM
% PostScript produced by: % PostScript produced by:
%@GMT: gmt grdimage @GMTAPI@-000000 -R0/1000/0/1000 -Cuser.cpt '-Bxag+lx (m)' '-Byag+ly (m)' -JX1.5i/1.5i -X1.5i -Y1.5i -K -P --MAP_FRAME_AXES=WesNZ user.ps %@GMT: gmt grdimage @GMTAPI@-S-I-G-G-G-N-000000 -R0/1000/0/1000 -C../data/ex2.cpt '-Bxag+lx (m)' '-Byag+ly (m)' -JX1.5i/1.5i -X1.5i -Y1.5i -K -P --MAP_FRAME_AXES=WesNZ ../data/ex2.ps
%@PROJ: xy 0.00000000 1000.00000000 0.00000000 1000.00000000 0.000 1000.000 0.000 1000.000 +xy %@PROJ: xy 0.00000000 1000.00000000 0.00000000 1000.00000000 0.000 1000.000 0.000 1000.000 +xy
%%BeginObject PSL_Layer_1 %%BeginObject PSL_Layer_1
0 setlinecap 0 setlinecap
0 setlinejoin 0 setlinejoin
3.32551 setmiterlimit 3.32550952342 setmiterlimit
clipsave clipsave
0 0 M 0 0 M
1800 0 D 1800 0 D
@ -953,6 +954,7 @@ N 1440 1783 M 0 34 D S
N 1783 1800 M 34 0 D S N 1783 1800 M 34 0 D S
N 1800 1783 M 0 34 D S N 1800 1783 M 0 34 D S
PSL_cliprestore PSL_cliprestore
/PSL_slant_y 0 def
2 setlinecap 2 setlinecap
N 0 1800 M 0 -1800 D S N 0 1800 M 0 -1800 D S
/PSL_A0_y 17 def /PSL_A0_y 17 def
@ -964,8 +966,8 @@ N 0 1080 M -17 0 D S
N 0 1440 M -17 0 D S N 0 1440 M -17 0 D S
N 0 1800 M -17 0 D S N 0 1800 M -17 0 D S
PSL_font_encode 4 get 0 eq {ISOLatin1+_Encoding /Times-Roman /Times-Roman PSL_reencode PSL_font_encode 4 1 put} if PSL_font_encode 4 get 0 eq {ISOLatin1+_Encoding /Times-Roman /Times-Roman PSL_reencode PSL_font_encode 4 1 put} if
/PSL_AH0 0
/MM {neg exch M} def /MM {neg exch M} def
/PSL_AH0 0
175 F4 175 F4
(0) sw mx (0) sw mx
(200) sw mx (200) sw mx
@ -1024,8 +1026,8 @@ N 720 0 M 0 17 D S
N 1080 0 M 0 17 D S N 1080 0 M 0 17 D S
N 1440 0 M 0 17 D S N 1440 0 M 0 17 D S
N 1800 0 M 0 17 D S N 1800 0 M 0 17 D S
/PSL_AH0 0
/MM {M} def /MM {M} def
/PSL_AH0 0
(0) sh mx (0) sh mx
(200) sh mx (200) sh mx
(400) sh mx (400) sh mx
@ -1059,12 +1061,12 @@ FQ
O0 O0
0 0 TM 0 0 TM
% PostScript produced by: % PostScript produced by:
%@GMT: gmt psscale -Dx0.1i/-0.2i+w1.3i/0.05i+h -Cuser.cpt -Bxa -By+lm -O >user.ps %@GMT: gmt psscale -Dx0.1i/-0.2i+w1.3i/0.05i+h -C../data/ex2.cpt -Bxa -By+lm -O >../data/ex2.ps
%@PROJ: xy -668.08288574 -39.34982681 0.00000000 0.05000000 -668.083 -39.350 0.000 0.050 +xy %@PROJ: xy -668.08288574 -39.34982681 0.00000000 0.05000000 -668.083 -39.350 0.000 0.050 +xy
%%BeginObject PSL_Layer_2 %%BeginObject PSL_Layer_2
0 setlinecap 0 setlinecap
0 setlinejoin 0 setlinejoin
3.32551 setmiterlimit 3.32550952342 setmiterlimit
120 -240 T 120 -240 T
4 W 4 W
V N 0 0 T 1560 60 scale /DeviceRGB setcolorspace V N 0 0 T 1560 60 scale /DeviceRGB setcolorspace
@ -1097,8 +1099,8 @@ N 0 0 M 1560 0 D S
N 169 0 M 0 -17 D S N 169 0 M 0 -17 D S
N 665 0 M 0 -17 D S N 665 0 M 0 -17 D S
N 1161 0 M 0 -17 D S N 1161 0 M 0 -17 D S
/PSL_AH0 0
/MM {neg M} def /MM {neg M} def
/PSL_AH0 0
PSL_font_encode 4 get 0 eq {ISOLatin1+_Encoding /Times-Roman /Times-Roman PSL_reencode PSL_font_encode 4 1 put} if PSL_font_encode 4 get 0 eq {ISOLatin1+_Encoding /Times-Roman /Times-Roman PSL_reencode PSL_font_encode 4 1 put} if
175 F4 175 F4
(-600) sh mx (-600) sh mx
@ -1118,7 +1120,8 @@ def
-120 240 T -120 240 T
%%EndObject %%EndObject
grestore grestore
PSL_movie_completion /PSL_movie_completion {} def PSL_movie_label_completion /PSL_movie_label_completion {} def
PSL_movie_prog_indicator_completion /PSL_movie_prog_indicator_completion {} def
%PSL_Begin_Trailer %PSL_Begin_Trailer
%%PageTrailer %%PageTrailer
U U

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 42 KiB

View File

@ -1,11 +1,11 @@
%!PS-Adobe-3.0 %!PS-Adobe-3.0
%%BoundingBox: 0 0 146 156 %%BoundingBox: 0 0 146 156
%%HiResBoundingBox: 0 0 145.7280 155.9520 %%HiResBoundingBox: 0 0 145.7280 155.9520
%%Title: GMT v6.0.0 [64-bit] Document from grdimage %%Title: GMT v6.1.1 [64-bit] Document from grdimage
%%Creator: GMT6 %%Creator: GMT6
%%For: unknown %%For: unknown
%%DocumentNeededResources: font Helvetica Times-Roman %%DocumentNeededResources: font Helvetica Times-Roman
%%CreationDate: Fri Sep 4 10:14:23 2020 %%CreationDate: Sun Jan 10 14:45:19 2021
%%LanguageLevel: 2 %%LanguageLevel: 2
%%DocumentData: Clean7Bit %%DocumentData: Clean7Bit
%%Orientation: Portrait %%Orientation: Portrait
@ -654,7 +654,8 @@ V 0.06 0.06 scale
/PSL_page_xsize 9917 def /PSL_page_xsize 9917 def
/PSL_page_ysize 14033 def /PSL_page_ysize 14033 def
/PSL_plot_completion {} def /PSL_plot_completion {} def
/PSL_movie_completion {} def /PSL_movie_label_completion {} def
/PSL_movie_prog_indicator_completion {} def
%PSL_End_Header %PSL_End_Header
gsave gsave
0 A 0 A
@ -662,12 +663,12 @@ FQ
O0 O0
600 600 TM 600 600 TM
% PostScript produced by: % PostScript produced by:
%@GMT: gmt grdimage @GMTAPI@-000000 -R0/100/0/80 -Cuser.cpt '-Bxag+lx (m)' '-Byag+ly (m)' -JX1.5i/1.5i -X0.5i -Y0.5i -K -P --MAP_FRAME_AXES=WesNZ user.ps %@GMT: gmt grdimage @GMTAPI@-S-I-G-G-G-N-000000 -R0/100/0/80 -C../data/ex3.cpt '-Bxag+lx (m)' '-Byag+ly (m)' -JX1.5i/1.5i -X0.5i -Y0.5i -K -P --MAP_FRAME_AXES=WesNZ ../data/ex3.ps
%@PROJ: xy 0.00000000 100.00000000 0.00000000 80.00000000 0.000 100.000 0.000 80.000 +xy %@PROJ: xy 0.00000000 100.00000000 0.00000000 80.00000000 0.000 100.000 0.000 80.000 +xy
%%BeginObject PSL_Layer_1 %%BeginObject PSL_Layer_1
0 setlinecap 0 setlinecap
0 setlinejoin 0 setlinejoin
3.32551 setmiterlimit 3.32550952342 setmiterlimit
clipsave clipsave
0 0 M 0 0 M
1800 0 D 1800 0 D
@ -862,6 +863,7 @@ N 1440 1783 M 0 34 D S
N 1783 1800 M 34 0 D S N 1783 1800 M 34 0 D S
N 1800 1783 M 0 34 D S N 1800 1783 M 0 34 D S
PSL_cliprestore PSL_cliprestore
/PSL_slant_y 0 def
2 setlinecap 2 setlinecap
N 0 1800 M 0 -1800 D S N 0 1800 M 0 -1800 D S
/PSL_A0_y 17 def /PSL_A0_y 17 def
@ -872,8 +874,8 @@ N 0 900 M -17 0 D S
N 0 1350 M -17 0 D S N 0 1350 M -17 0 D S
N 0 1800 M -17 0 D S N 0 1800 M -17 0 D S
PSL_font_encode 4 get 0 eq {ISOLatin1+_Encoding /Times-Roman /Times-Roman PSL_reencode PSL_font_encode 4 1 put} if PSL_font_encode 4 get 0 eq {ISOLatin1+_Encoding /Times-Roman /Times-Roman PSL_reencode PSL_font_encode 4 1 put} if
/PSL_AH0 0
/MM {neg exch M} def /MM {neg exch M} def
/PSL_AH0 0
175 F4 175 F4
(0) sw mx (0) sw mx
(20) sw mx (20) sw mx
@ -928,8 +930,8 @@ N 720 0 M 0 17 D S
N 1080 0 M 0 17 D S N 1080 0 M 0 17 D S
N 1440 0 M 0 17 D S N 1440 0 M 0 17 D S
N 1800 0 M 0 17 D S N 1800 0 M 0 17 D S
/PSL_AH0 0
/MM {M} def /MM {M} def
/PSL_AH0 0
(0) sh mx (0) sh mx
(20) sh mx (20) sh mx
(40) sh mx (40) sh mx
@ -963,12 +965,12 @@ FQ
O0 O0
0 0 TM 0 0 TM
% PostScript produced by: % PostScript produced by:
%@GMT: gmt psscale -Dx0.1i/-0.2i+w1.3i/0.05i+h -Cuser.cpt -Bxa -By+lm -O >user.ps %@GMT: gmt psscale -Dx0.1i/-0.2i+w1.3i/0.05i+h -C../data/ex3.cpt -Bxa -By+lm -O >../data/ex3.ps
%@PROJ: xy 0.00000000 8000.00000000 0.00000000 0.05000000 0.000 8000.000 0.000 0.050 +xy %@PROJ: xy 0.00000000 8000.00000000 0.00000000 0.05000000 0.000 8000.000 0.000 0.050 +xy
%%BeginObject PSL_Layer_2 %%BeginObject PSL_Layer_2
0 setlinecap 0 setlinecap
0 setlinejoin 0 setlinejoin
3.32551 setmiterlimit 3.32550952342 setmiterlimit
120 -240 T 120 -240 T
4 W 4 W
V N 0 0 T 1560 60 scale /DeviceRGB setcolorspace V N 0 0 T 1560 60 scale /DeviceRGB setcolorspace
@ -1004,8 +1006,8 @@ N 390 0 M 0 -17 D S
N 780 0 M 0 -17 D S N 780 0 M 0 -17 D S
N 1170 0 M 0 -17 D S N 1170 0 M 0 -17 D S
N 1560 0 M 0 -17 D S N 1560 0 M 0 -17 D S
/PSL_AH0 0
/MM {neg M} def /MM {neg M} def
/PSL_AH0 0
PSL_font_encode 4 get 0 eq {ISOLatin1+_Encoding /Times-Roman /Times-Roman PSL_reencode PSL_font_encode 4 1 put} if PSL_font_encode 4 get 0 eq {ISOLatin1+_Encoding /Times-Roman /Times-Roman PSL_reencode PSL_font_encode 4 1 put} if
175 F4 175 F4
(0) sh mx (0) sh mx
@ -1031,7 +1033,8 @@ def
-120 240 T -120 240 T
%%EndObject %%EndObject
grestore grestore
PSL_movie_completion /PSL_movie_completion {} def PSL_movie_label_completion /PSL_movie_label_completion {} def
PSL_movie_prog_indicator_completion /PSL_movie_prog_indicator_completion {} def
%PSL_Begin_Trailer %PSL_Begin_Trailer
%%PageTrailer %%PageTrailer
U U

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -1,6 +0,0 @@
#!/bin/bash
inc=`gmt-config --cflags`
lib=`gmt-config --libs`
g++ gridding.cpp $inc $lib -o gridding
#./gridding

View File

@ -1,4 +0,0 @@
# GMT 6 Session common arguments shelf
BEGIN GMT 6.1.1
R 0/1000/0/1000
END

Binary file not shown.

View File

@ -1,6 +0,0 @@
#!/bin/bash
inc=`gmt-config --cflags`
lib=`gmt-config --libs`
g++ plot_grid.cpp $inc $lib -o plot_grid
./plot_grid

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +0,0 @@
#!/bin/bash
inc=`gmt-config --cflags`
lib=`gmt-config --libs`
g++ plot_memory.cpp $inc $lib -o plot_memory
./plot_memory

Binary file not shown.

View File

@ -1,11 +1,12 @@
#include "gmt.h" #include "gmt.h"
#include "iostream" #include "iostream"
#include "string" #include "string"
#include "unistd.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
std::string table_name = "table.txt"; std::string table_name = "../data/table.txt";
std::string grid_name = "table.nc"; std::string grid_name = "../data/table.nc";
// Initiate a new GMT session // Initiate a new GMT session
void *API = GMT_Create_Session("gridding_example", 2U, 0, NULL); void *API = GMT_Create_Session("gridding_example", 2U, 0, NULL);
@ -44,5 +45,13 @@ int main(int argc, char *argv[])
// end the GMT session // end the GMT session
GMT_Destroy_Session(API); GMT_Destroy_Session(API);
// if exist, delete
std::string hist_file = "gmt.history";
std::string conf_file = "gmt.conf";
if (!access(hist_file.c_str(), F_OK))
remove(hist_file.c_str());
if (!access(conf_file.c_str(), F_OK))
remove(conf_file.c_str());
return 0; return 0;
} }

View File

@ -6,8 +6,8 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
std::string cpt_file = "user.cpt"; std::string cpt_file = "../data/ex2.cpt";
std::string ps_file = "user.ps"; std::string ps_file = "../data/ex2.ps";
// Initiate a new GMT session // Initiate a new GMT session
// you need to destroy the session later // you need to destroy the session later
@ -15,7 +15,7 @@ int main(int argc, char *argv[])
struct GMT_GRID *G = reinterpret_cast<GMT_GRID*>( struct GMT_GRID *G = reinterpret_cast<GMT_GRID*>(
GMT_Read_Data (API, GMT_IS_GRID, GMT_IS_FILE, GMT_IS_SURFACE, GMT_Read_Data (API, GMT_IS_GRID, GMT_IS_FILE, GMT_IS_SURFACE,
GMT_READ_NORMAL, NULL, "table.nc", NULL)); GMT_READ_NORMAL, NULL, "../data/table.nc", NULL));
// start the plotting // start the plotting
// 1. set GMT defaults // 1. set GMT defaults
@ -33,7 +33,7 @@ MAP_ANNOT_OFFSET_PRIMARY=2.5p";
GMT_Call_Module (API, "gmtset", GMT_MODULE_CMD, (char*) args_defaults.c_str()); GMT_Call_Module (API, "gmtset", GMT_MODULE_CMD, (char*) args_defaults.c_str());
// load the grid to a virtual file for plotting // load the grid to a virtual file for plotting
char grid_name[GMT_STR16] = {""}; char grid_name[GMT_VF_LEN] = {""};
GMT_Open_VirtualFile (API, GMT_IS_GRID, GMT_IS_SURFACE, GMT_IN, G, grid_name); GMT_Open_VirtualFile (API, GMT_IS_GRID, GMT_IS_SURFACE, GMT_IN, G, grid_name);
// get string type of grid name // get string type of grid name
std::string grid_name_str = grid_name; std::string grid_name_str = grid_name;

View File

@ -6,8 +6,8 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
std::string cpt_file = "user.cpt"; std::string cpt_file = "../data/ex3.cpt";
std::string ps_file = "user.ps"; std::string ps_file = "../data/ex3.ps";
// Initiate a new GMT session // Initiate a new GMT session
// you need to destroy the session later // you need to destroy the session later
@ -62,7 +62,7 @@ MAP_ANNOT_OFFSET_PRIMARY=2.5p";
GMT_Call_Module (API, "gmtset", GMT_MODULE_CMD, (char*) args_defaults.c_str()); GMT_Call_Module (API, "gmtset", GMT_MODULE_CMD, (char*) args_defaults.c_str());
// load the grid to a virtual file for plotting // load the grid to a virtual file for plotting
char grid_name[GMT_STR16] = {""}; char grid_name[GMT_VF_LEN] = {""};
GMT_Open_VirtualFile (API, GMT_IS_GRID, GMT_IS_SURFACE, GMT_IN, G, grid_name); GMT_Open_VirtualFile (API, GMT_IS_GRID, GMT_IS_SURFACE, GMT_IN, G, grid_name);
// get string type of grid name // get string type of grid name
std::string grid_name_str = grid_name; std::string grid_name_str = grid_name;