gctl/lib/graphic/gmt.h

120 lines
4.2 KiB
C
Raw Normal View History

2025-02-08 21:04:59 +08:00
/********************************************************
*
*
*
*
*
*
* Geophysical Computational Tools & Library (GCTL)
*
* Copyright (c) 2023 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 <http://www.gnu.org/licenses/>.
*
* 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.
******************************************************/
#ifndef _GCTL_GMT_H
#define _GCTL_GMT_H
#include <vector>
#include <exception>
#include <stdexcept>
#include <ctime>
#include "gmt/gmt.h"
#include "../utility/stream.h"
#include "../core/array.h"
2025-02-09 13:12:55 +08:00
#include "../io/netcdf_io.h"
2025-02-08 21:04:59 +08:00
#ifndef GMT_VF_LEN
#define GMT_VF_LEN 16
#endif
namespace gctl
{
/**
* @brief gmt命令管道库
*/
class gmt
{
public:
/**
* @brief Construct a new gmt object
*/
gmt();
// destructor
virtual ~gmt();
/**
* @brief Start a session.
*
* @param pic_name Output picture name.
* @param pic_type Output picture type. Multiple types can be specified by comma.
* @param name Session name.
*/
void begin_session(const std::string& pic_name, const std::string& pic_type = "eps",
const std::string& name = "gctl_gmt_session");
/**
* @brief Destroy a session object
*
* @param show Whether to show the result after finish the plotting.
2025-02-09 13:12:55 +08:00
* @param clear_tmp Whether to clear the temporary files.
2025-02-08 21:04:59 +08:00
*/
2025-02-09 13:12:55 +08:00
void end_session(bool show = false, bool clear_tmp = true);
2025-02-08 21:04:59 +08:00
/**
* @brief Save the session to a file.
*
* @param filename File name.
*/
void save_session(const std::string& filename);
/**
* @brief Call a GMT module.
*
* @param module Name of the module.
* @param cmd Module command.
*/
2025-02-09 13:12:55 +08:00
void call_module(const std::string& module, const std::string& cmd);
2025-02-08 21:04:59 +08:00
/**
2025-02-09 13:12:55 +08:00
* @brief Create a temporary grid file that could be used for plotting.
*
2025-02-08 21:04:59 +08:00
* @param data Data array.
* @param xnum Number of data points in x direction.
* @param ynum Number of data points in y direction.
2025-02-09 13:12:55 +08:00
* @param xmin minimal x coordinate of the data.
* @param dx increment of x coordinate of the data.
* @param ymin minimal y coordinate of the data.
* @param dy increment of y coordinate of the data.
2025-02-08 21:04:59 +08:00
* @return Name of the virtual grid which could be used for plotting.
*/
2025-02-09 13:12:55 +08:00
std::string create_grid(const array<double> &data, int xnum, int ynum,
double xmin, double dx, double ymin, double dy);
2025-02-08 21:04:59 +08:00
private:
gmt(gmt const&) = delete;
void operator=(gmt const&) = delete;
2025-02-09 13:12:55 +08:00
bool seesion_ok_;
2025-02-08 21:04:59 +08:00
void* GMT_API_;
2025-02-09 13:12:55 +08:00
std::string session_name_;
2025-02-08 21:04:59 +08:00
std::vector<std::string> buffer_;
2025-02-09 13:12:55 +08:00
std::vector<std::string> tmpfiles_;
2025-02-08 21:04:59 +08:00
};
};
#endif // _GCTL_GMT_H