98 lines
3.7 KiB
C++
98 lines
3.7 KiB
C++
/********************************************************
|
|
* ██████╗ ██████╗████████╗██╗
|
|
* ██╔════╝ ██╔════╝╚══██╔══╝██║
|
|
* ██║ ███╗██║ ██║ ██║
|
|
* ██║ ██║██║ ██║ ██║
|
|
* ╚██████╔╝╚██████╗ ██║ ███████╗
|
|
* ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝
|
|
* 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 <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.
|
|
******************************************************/
|
|
|
|
#include "../lib/core/macro.h"
|
|
#include "../lib/graphic/gnuplot.h"
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
gctl::gnuplot gt;
|
|
|
|
//one line test
|
|
//gt.send("set terminal dumb");
|
|
//gt.send("plot [-pi/2:pi] cos(x),-(sin(x) > sin(x+1) ? sin(x) : sin(x+1))");
|
|
|
|
//buffer test (bessel animation)
|
|
/*
|
|
gt.to_buffer();
|
|
gt.send("set terminal gif animate delay 10 size 600,400");
|
|
gt.send("set output 'bessel.gif'");
|
|
gt.send("set palette rgb 3,9,9");
|
|
gt.send("unset key; unset colorbox; unset border; unset tics");
|
|
gt.send("set lmargin at screen 0.03");
|
|
gt.send("set bmargin at screen 0");
|
|
gt.send("set rmargin at screen 0.97");
|
|
gt.send("set tmargin at screen 1");
|
|
gt.send("set parametric", true);
|
|
gt.send("bessel(x,t) = besj0(x) * cos(2*pi*t)");
|
|
gt.send("n = 6 # number of zeros");
|
|
gt.send("k = (n*pi-1.0/4*pi)");
|
|
gt.send("u_0 = k + 1/(8*k) - 31/(384*k)**3 + 3779/(15360*k)**5");
|
|
gt.send("set urange [0:u_0]");
|
|
gt.send("set vrange[0:1.5*pi]");
|
|
gt.send("set cbrange [-1:1]");
|
|
gt.send("set zrange[-1:1]");
|
|
gt.send("set isosamples 200,100");
|
|
gt.send("set pm3d depthorder");
|
|
gt.send("set view 40,200");
|
|
|
|
std::string cmd;
|
|
for (float t = 0.0f; t < 2.0f; t += 0.02f)
|
|
{
|
|
cmd = "splot u*sin(v),u*cos(v),bessel(u," + std::to_string(t) + ") w pm3d ls 1";
|
|
gt.send(cmd);
|
|
}
|
|
gt.send("set output");
|
|
|
|
gt.save_buffer("bessel");
|
|
gt.send_buffer();
|
|
*/
|
|
|
|
//data test
|
|
std::vector<double> x(101);
|
|
std::vector<double> y1(101);
|
|
std::vector<double> y2(101);
|
|
for (size_t i = 0; i < 101; i++)
|
|
{
|
|
x[i] = -1.0*GCTL_Pi + 2.0*GCTL_Pi*i/100.0;
|
|
y1[i] = sin(x[i]);
|
|
y2[i] = cos(x[i]);
|
|
}
|
|
|
|
std::vector<std::vector<double> > data;
|
|
data.push_back(x);
|
|
data.push_back(y1);
|
|
data.push_back(y2);
|
|
|
|
gt.to_buffer();
|
|
gt.send_data("$Data", data);
|
|
gt.send("plot $Data using 1:2 with lines title 'y1', '' using 1:3 with lines title 'y2'");
|
|
gt.save_buffer("sin_cos");
|
|
gt.send_buffer();
|
|
return 0;
|
|
}
|