diff --git a/.gitignore b/.gitignore
index e257658..f0bbcbb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,34 +1,3 @@
-# ---> C++
-# Prerequisites
-*.d
-
-# Compiled Object files
-*.slo
-*.lo
-*.o
-*.obj
-
-# Precompiled Headers
-*.gch
-*.pch
-
-# Compiled Dynamic libraries
-*.so
-*.dylib
-*.dll
-
-# Fortran module files
-*.mod
-*.smod
-
-# Compiled Static libraries
-*.lai
-*.la
-*.a
-*.lib
-
-# Executables
-*.exe
-*.out
-*.app
-
+.DS_Store
+build/
+.vscode/
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..7f61dc1
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,40 @@
+cmake_minimum_required(VERSION 3.15.2)
+# 设置项目名称与语言
+project(GCTL_GRAPHIC VERSION 1.0)
+# 添加配置配件编写的函数
+include(CMakePackageConfigHelpers)
+
+option(GCTL_GRAPHIC_GMT "Use the GMT library" ON)
+option(GCTL_GRAPHIC_MATHGL "Use the MathGL2 library" ON)
+
+message(STATUS "Platform: " ${CMAKE_HOST_SYSTEM_NAME})
+message(STATUS "Install prefix: " ${CMAKE_INSTALL_PREFIX})
+message(STATUS "Processor: " ${CMAKE_HOST_SYSTEM_PROCESSOR})
+message(STATUS "[GCTL_GRAPHIC] Use the GMT library: " ${GCTL_GRAPHIC_GMT})
+message(STATUS "[GCTL_GRAPHIC] Use the MathGL2 library: " ${GCTL_GRAPHIC_MATHGL})
+
+find_package(GCTL REQUIRED)
+message(STATUS "Found GCTL")
+include_directories(${GCTL_INC_DIR})
+
+if(GCTL_GRAPHIC_GMT)
+ find_package(GMT REQUIRED)
+ message(STATUS "Found GMT")
+ include_directories(${GMT_INC_DIR})
+endif()
+
+if(GCTL_GRAPHIC_MATHGL)
+ find_package(MathGL2 REQUIRED FLTK)
+ message(STATUS "MathGL2 Version: " ${MathGL2_VERSION})
+ include_directories(${MathGL2_INCLUDE_DIRS})
+endif()
+
+# 加入一个头文件配置,让cmake对源码进行操作
+configure_file(
+ "${PROJECT_SOURCE_DIR}/config.h.in"
+ "${PROJECT_SOURCE_DIR}/lib/graphic/gctl_graphic_config.h"
+ )
+
+# 添加库源文件地址
+add_subdirectory(lib)
+add_subdirectory(example)
\ No newline at end of file
diff --git a/GCTL_GRAPHICConfig.cmake.in b/GCTL_GRAPHICConfig.cmake.in
new file mode 100644
index 0000000..796a4ab
--- /dev/null
+++ b/GCTL_GRAPHICConfig.cmake.in
@@ -0,0 +1,41 @@
+@PACKAGE_INIT@
+
+set(@PROJECT_NAME@_VERSION "@PROJECT_VERSION@")
+set_and_check(@PROJECT_NAME@_INSTALL_PREFIX "${PACKAGE_PREFIX_DIR}")
+set_and_check(@PROJECT_NAME@_INC_DIR "${PACKAGE_PREFIX_DIR}/include")
+set_and_check(@PROJECT_NAME@_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")
+set_and_check(@PROJECT_NAME@_LIB_DIR "${PACKAGE_PREFIX_DIR}/lib")
+set_and_check(@PROJECT_NAME@_LIBRARY_DIR "${PACKAGE_PREFIX_DIR}/lib")
+
+set(@PROJECT_NAME@_LIB gctl_graphic)
+set(@PROJECT_NAME@_LIBRARY gctl_graphic)
+
+set(@PROJECT_NAME@_GMT @GCTL_GRAPHIC_GMT@)
+set(@PROJECT_NAME@_MATHGL @GCTL_GRAPHIC_MATHGL@)
+
+message(STATUS "[GCTL_GRAPHIC] Use the GMT library: " @GCTL_GRAPHIC_GMT@)
+message(STATUS "[GCTL_GRAPHIC] Use the mathGL library: " @GCTL_GRAPHIC_MATHGL@)
+
+if(NOT GCTL_FOUND)
+ find_package(GCTL REQUIRED)
+ include_directories(${GCTL_INC_DIR})
+endif()
+
+if(@PROJECT_NAME@_GMT)
+ if(NOT GMT_FOUND)
+ find_package(GMT REQUIRED)
+ include_directories(${GMT_INC_DIR})
+ endif()
+endif()
+
+if(@PROJECT_NAME@_MATHGL)
+ if(NOT MathGL2_FOUND)
+ find_package(MathGL2 REQUIRED FLTK)
+ include_directories(${MathGL2_INCLUDE_DIRS})
+ endif()
+endif()
+
+# include target information
+include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
+
+check_required_components(@PROJECT_NAME@)
\ No newline at end of file
diff --git a/config.h.in b/config.h.in
new file mode 100644
index 0000000..bbd8851
--- /dev/null
+++ b/config.h.in
@@ -0,0 +1,2 @@
+#cmakedefine GCTL_GRAPHIC_GMT
+#cmakedefine GCTL_GRAPHIC_MATHGL
\ No newline at end of file
diff --git a/doc/GMT/GMTConfig.cmake b/doc/GMT/GMTConfig.cmake
new file mode 100644
index 0000000..f33221c
--- /dev/null
+++ b/doc/GMT/GMTConfig.cmake
@@ -0,0 +1,23 @@
+macro(set_and_check _var _file)
+ set(${_var} "${_file}")
+ if(NOT EXISTS "${_file}")
+ message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
+ endif()
+endmacro()
+
+# change the following options as needed
+set(GMT_VERSION "6.0.0")
+
+if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin")
+ set_and_check(GMT_INC_DIR "/opt/homebrew/include")
+ set_and_check(GMT_LIB_DIR "/opt/homebrew/lib")
+
+elseif(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux")
+ set_and_check(GMT_INC_DIR "/usr/include")
+ set_and_check(GMT_LIB_DIR "/usr/lib/x86_64-linux-gnu")
+
+else()
+ message(FATAL_ERROR "Unset operation system for GMT. Please edit the GMTConfig.cmake file.")
+endif()
+
+set(GMT_LIB gmt)
\ No newline at end of file
diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt
new file mode 100644
index 0000000..e20a0ef
--- /dev/null
+++ b/example/CMakeLists.txt
@@ -0,0 +1,23 @@
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
+set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
+
+macro(add_example name switch)
+ if(${switch})
+ # 添加可执行程序名称
+ add_executable(${name} ${name}.cpp)
+ # 设置安装后的动态库调用地址
+ set_target_properties(${name} PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
+ set_target_properties(${name} PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
+ target_link_libraries(${name} PRIVATE ${GCTL_LIB})
+ target_link_libraries(${name} PRIVATE gctl_graphic)
+ endif()
+endmacro()
+
+if(${GCTL_GRAPHIC_GMT})
+ add_example(JX_single_ex ON)
+endif()
+
+if(${GCTL_GRAPHIC_MATHGL})
+ add_example(mathgl_plot_ex ON)
+ add_example(mathgl_dens_ex ON)
+endif()
\ No newline at end of file
diff --git a/example/JX_single_ex.cpp b/example/JX_single_ex.cpp
new file mode 100644
index 0000000..db7999f
--- /dev/null
+++ b/example/JX_single_ex.cpp
@@ -0,0 +1,49 @@
+/********************************************************
+ * ██████╗ ██████╗████████╗██╗
+ * ██╔════╝ ██╔════╝╚══██╔══╝██║
+ * ██║ ███╗██║ ██║ ██║
+ * ██║ ██║██║ ██║ ██║
+ * ╚██████╔╝╚██████╗ ██║ ███████╗
+ * ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
+ * Geophysical Computational Tools & Library (GCTL)
+ *
+ * Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
+ *
+ * GCTL is distributed under a dual licensing scheme. You can redistribute
+ * it and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either version 2
+ * of the License, or (at your option) any later version. You should have
+ * received a copy of the GNU Lesser General Public License along with this
+ * program. If not, see .
+ *
+ * If the terms and conditions of the LGPL v.2. would prevent you from using
+ * the GCTL, please consider the option to obtain a commercial license for a
+ * fee. These licenses are offered by the GCTL's original author. As a rule,
+ * licenses are provided "as-is", unlimited in time for a one time fee. Please
+ * send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
+ * to include some description of your company and the realm of its activities.
+ * Also add information on how to contact you by electronic and paper mail.
+ ******************************************************/
+
+#include "../lib/graphic.h"
+
+int main(int argc, char const *argv[])
+{
+ gctl::array data(51*41);
+
+ double dist;
+ for (int i = 0; i < 51; ++i)
+ {
+ for (int j = 0; j < 41; ++j)
+ {
+ dist = sqrt((j-20)*(j-20) + (i-25)*(i-25));
+ data[j+i*41] = sin(dist/GCTL_Pi);
+ }
+ }
+
+ gctl::gmt_JX_single pic;
+ pic.show_command();
+ pic.set_command("psconvert", "-A -TG -E300");
+ pic.plot("gmt_plot_ex", data, 0, 40, 0, 50, 41, 51);
+ return 0;
+}
diff --git a/example/mathgl_dens_ex.cpp b/example/mathgl_dens_ex.cpp
new file mode 100644
index 0000000..e9d135c
--- /dev/null
+++ b/example/mathgl_dens_ex.cpp
@@ -0,0 +1,53 @@
+/********************************************************
+ * ██████╗ ██████╗████████╗██╗
+ * ██╔════╝ ██╔════╝╚══██╔══╝██║
+ * ██║ ███╗██║ ██║ ██║
+ * ██║ ██║██║ ██║ ██║
+ * ╚██████╔╝╚██████╗ ██║ ███████╗
+ * ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
+ * Geophysical Computational Tools & Library (GCTL)
+ *
+ * Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
+ *
+ * GCTL is distributed under a dual licensing scheme. You can redistribute
+ * it and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either version 2
+ * of the License, or (at your option) any later version. You should have
+ * received a copy of the GNU Lesser General Public License along with this
+ * program. If not, see .
+ *
+ * If the terms and conditions of the LGPL v.2. would prevent you from using
+ * the GCTL, please consider the option to obtain a commercial license for a
+ * fee. These licenses are offered by the GCTL's original author. As a rule,
+ * licenses are provided "as-is", unlimited in time for a one time fee. Please
+ * send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
+ * to include some description of your company and the realm of its activities.
+ * Also add information on how to contact you by electronic and paper mail.
+ ******************************************************/
+
+#include "../lib/graphic.h"
+
+#define NUM 101
+
+int main(int argc, char const *argv[])
+{
+ gctl::array x(NUM), y(NUM), z(NUM*NUM);
+ gctl::sequence(x, -2.0*GCTL_Pi, 0.04*GCTL_Pi);
+ gctl::sequence(y, -2.0*GCTL_Pi, 0.04*GCTL_Pi);
+
+ for (size_t i = 0; i < NUM; i++)
+ {
+ for (size_t j = 0; j < NUM; j++)
+ {
+ z[j + i*NUM] = sin(sqrt(x[j]*x[j] + y[i]*y[i]));
+ }
+ }
+
+ gctl::mathgl_dens plt;
+ plt.range(-2.0*GCTL_Pi, 2.0*GCTL_Pi, -2.0*GCTL_Pi, 2.0*GCTL_Pi);
+ plt.demension(NUM, NUM);
+ plt.add_dens(z, "sin");
+ plt.plot();
+
+ return 0;
+}
diff --git a/example/mathgl_plot_ex.cpp b/example/mathgl_plot_ex.cpp
new file mode 100644
index 0000000..228b589
--- /dev/null
+++ b/example/mathgl_plot_ex.cpp
@@ -0,0 +1,48 @@
+/********************************************************
+ * ██████╗ ██████╗████████╗██╗
+ * ██╔════╝ ██╔════╝╚══██╔══╝██║
+ * ██║ ███╗██║ ██║ ██║
+ * ██║ ██║██║ ██║ ██║
+ * ╚██████╔╝╚██████╗ ██║ ███████╗
+ * ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
+ * Geophysical Computational Tools & Library (GCTL)
+ *
+ * Copyright (c) 2022 Yi Zhang (yizhang-geo@zju.edu.cn)
+ *
+ * GCTL is distributed under a dual licensing scheme. You can redistribute
+ * it and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either version 2
+ * of the License, or (at your option) any later version. You should have
+ * received a copy of the GNU Lesser General Public License along with this
+ * program. If not, see .
+ *
+ * If the terms and conditions of the LGPL v.2. would prevent you from using
+ * the GCTL, please consider the option to obtain a commercial license for a
+ * fee. These licenses are offered by the GCTL's original author. As a rule,
+ * licenses are provided "as-is", unlimited in time for a one time fee. Please
+ * send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
+ * to include some description of your company and the realm of its activities.
+ * Also add information on how to contact you by electronic and paper mail.
+ ******************************************************/
+
+#include "../lib/graphic.h"
+
+#define NUM 101
+
+int main(int argc, char const *argv[])
+{
+ gctl::array x(NUM), y(NUM);
+
+ gctl::sequence(x, -2.0*GCTL_Pi, 0.04*GCTL_Pi);
+ for (size_t i = 0; i < NUM; i++)
+ {
+ y[i] = sin(x[i]);
+ }
+
+ gctl::mathgl_plot plt;
+ plt.init_axis(x, "time (s)");
+ plt.add_profile(y, "single (db)");
+ plt.plot();
+
+ return 0;
+}
diff --git a/installer b/installer
new file mode 100755
index 0000000..fee79e7
--- /dev/null
+++ b/installer
@@ -0,0 +1,54 @@
+#!/bin/bash
+
+if [[ $# == 0 || ${1} == "help" ]]; then
+ echo "Compiles executables/libraries and maintains installed files. Two tools 'Cmake' and 'stow' are empolyed here. For more information, see https://cmake.org and https://www.gnu.org/software/stow/."
+ echo ""
+ echo "School of Earth Sciences, Zhejiang University"
+ echo "Yi Zhang (yizhang-geo@zju.edu.cn)"
+ echo ""
+ echo "Usage: ./config.sh [option] [Cmake options]"
+ echo ""
+ echo "Options:"
+ echo "(1) configure: Configure Cmake project(s). This option could take extra Cmake options as in